Home | History | Annotate | Download | only in tensorflow
      1 /* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
      2 
      3 Licensed under the Apache License, Version 2.0 (the "License");
      4 you may not use this file except in compliance with the License.
      5 You may obtain a copy of the License at
      6 
      7     http://www.apache.org/licenses/LICENSE-2.0
      8 
      9 Unless required by applicable law or agreed to in writing, software
     10 distributed under the License is distributed on an "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 See the License for the specific language governing permissions and
     13 limitations under the License.
     14 ==============================================================================*/
     15 
     16 package org.tensorflow;
     17 
     18 import static org.junit.Assert.assertTrue;
     19 import static org.junit.Assert.fail;
     20 
     21 import org.junit.Test;
     22 import org.junit.runner.RunWith;
     23 import org.junit.runners.JUnit4;
     24 
     25 /** Unit tests for {@link org.tensorflow.TensorFlow}. */
     26 @RunWith(JUnit4.class)
     27 public class TensorFlowTest {
     28   @Test
     29   public void version() {
     30     assertTrue(TensorFlow.version().length() > 0);
     31   }
     32 
     33   @Test
     34   public void registeredOpList() {
     35     // Would be nice to actually parse the output as a tensorflow.OpList protocol buffer message,
     36     // but as of May 2017, bazel support for generating Java code from protocol buffer definitions
     37     // was not sorted out. Revisit? Till then, at least exercise the code.
     38     assertTrue(TensorFlow.registeredOpList().length > 0);
     39   }
     40 
     41   @Test
     42   public void loadLibrary() {
     43     // TODO(ashankar): This tell will fail when built with --config=monolithic.
     44     // Figure out how we can ignore the test in that case.
     45     try (Graph g = new Graph()) {
     46       // Build a graph with an unrecognized operation.
     47       try {
     48         g.opBuilder("MyTest", "MyTest").build();
     49         fail("should not be able to construct graphs with unregistered ops");
     50       } catch (IllegalArgumentException e) {
     51         // expected exception
     52       }
     53 
     54       // Load the library containing the operation.
     55       byte[] opList = TensorFlow.loadLibrary("tensorflow/java/my_test_op.so");
     56       assertTrue(opList.length > 0);
     57 
     58       // Now graph building should succeed.
     59       g.opBuilder("MyTest", "MyTest").build();
     60     }
     61   }
     62 }
     63