aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/tools/lib_package/libtensorflow_test.sh
blob: 6430c755af96925d064f0448e27b36c70a6cf669 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env bash
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

set -ex

# Sanity test for the package C-library archive.
# - Unarchive
# - Compile a trivial C file that uses the archive
# - Run it

# Tools needed: A C-compiler and tar
CC="${CC}"
TAR="${TAR}"

[ -z "${CC}" ] && CC="/usr/bin/gcc"
[ -z "${TAR}"] && TAR="tar"

# bazel tests run with ${PWD} set to the root of the bazel workspace
TARFILE="${PWD}/tensorflow/tools/lib_package/libtensorflow.tar.gz"
CFILE="${PWD}/tensorflow/tools/lib_package/libtensorflow_test.c"

cd ${TEST_TMPDIR}

# Extract the archive into tensorflow/
mkdir tensorflow
${TAR} -xzf ${TARFILE} -Ctensorflow

# Compile the test .c file
${CC} ${CFILE} -Itensorflow/include -Ltensorflow/lib -ltensorflow -oa.out

# Execute it, with the shared library available.
# DYLD_LIBRARY_PATH is used on OS X, LD_LIBRARY_PATH on Linux.
#
# The tests for GPU require CUDA libraries to be accessible, which
# are in DYLD_LIBRARY_PATH in the test harness for OS X.
export DYLD_LIBRARY_PATH=tensorflow/lib:${DYLD_LIBRARY_PATH}
export LD_LIBRARY_PATH=tensorflow/lib:${LD_LIBRARY_PATH}
./a.out