1#!/usr/bin/env bash 2# Copyright 2016 The TensorFlow Authors. All Rights Reserved. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# ============================================================================== 16 17set -ex 18 19# Sanity test for the binary artifacts for the TensorFlow Java API. 20# - Unarchive 21# - Compile a trivial Java file that exercises the Java API and underlying 22# native library. 23# - Run it 24 25# Tools needed: java, javac, tar 26JAVA="${JAVA}" 27JAVAC="${JAVAC}" 28TAR="${TAR}" 29 30[ -z "${JAVA}" ] && JAVA="java" 31[ -z "${JAVAC}" ] && JAVAC="javac" 32[ -z "${TAR}" ] && TAR="tar" 33 34# bazel tests run with ${PWD} set to the root of the bazel workspace 35TARFILE="${PWD}/tensorflow/tools/lib_package/libtensorflow_jni.tar.gz" 36JAVAFILE="${PWD}/tensorflow/tools/lib_package/LibTensorFlowTest.java" 37JARFILE="${PWD}/tensorflow/java/libtensorflow.jar" 38 39cd ${TEST_TMPDIR} 40 41# Extract the archive into a subdirectory 'jni' 42mkdir jni 43${TAR} -xzf ${TARFILE} -Cjni 44 45# Compile and run the .java file 46${JAVAC} -cp ${JARFILE} -d . ${JAVAFILE} 47OUTPUT=$(${JAVA} \ 48 -cp "${JARFILE}:." \ 49 -Djava.library.path=jni \ 50 LibTensorFlowTest) 51if [ -z "${OUTPUT}" ] 52then 53 echo "Empty output, expecting version number" 54 exit 1 55fi 56