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
17# This script runs integration tests on the TensorFlow source code
18# using a pip installation.
19#
20# Usage: integration_tests.sh [--virtualenv]
21#
22# If the flag --virtualenv is set, the script will use "python" as the Python
23# binary path. Otherwise, it will use tools/python_bin_path.sh to determine
24# the Python binary path.
25#
26# This script obeys the following environment variables (if exists):
27#   TF_BUILD_INTEG_TEST_BLACKLIST: Force skipping of specified integration tests
28#       listed in INTEG_TESTS below.
29#
30
31# List of all integration tests to run, separated by spaces
32INTEG_TESTS="ffmpeg_lib"
33
34if [[ -z "${TF_BUILD_INTEG_TEST_BLACKLIST}" ]]; then
35  TF_BUILD_INTEG_TEST_BLACKLIST=""
36fi
37echo ""
38echo "=== Integration Tests ==="
39echo "TF_BUILD_INTEG_TEST_BLACKLIST = \"${TF_BUILD_INTEG_TEST_BLACKLIST}\""
40
41# Timeout (in seconds) for each integration test
42TIMEOUT=1800
43
44INTEG_TEST_ROOT="$(mktemp -d)"
45LOGS_DIR=pip_test/integration_tests/logs
46
47# Current script directory
48SCRIPT_DIR=$( cd ${0%/*} && pwd -P )
49source "${SCRIPT_DIR}/builds_common.sh"
50
51# Helper functions
52cleanup() {
53  rm -rf $INTEG_TEST_ROOT
54}
55
56
57die() {
58  echo $@
59  cleanup
60  exit 1
61}
62
63
64# Determine the binary path for "timeout"
65TIMEOUT_BIN="timeout"
66if [[ -z "$(which ${TIMEOUT_BIN})" ]]; then
67  TIMEOUT_BIN="gtimeout"
68  if [[ -z "$(which ${TIMEOUT_BIN})" ]]; then
69    die "Unable to locate binary path for timeout command"
70  fi
71fi
72echo "Binary path for timeout: \"$(which ${TIMEOUT_BIN})\""
73
74# Avoid permission issues outside Docker containers
75umask 000
76
77mkdir -p "${LOGS_DIR}" || die "Failed to create logs directory"
78mkdir -p "${INTEG_TEST_ROOT}" || die "Failed to create test directory"
79
80if [[ "$1" == "--virtualenv" ]]; then
81  PYTHON_BIN_PATH="$(which python)"
82else
83  source tools/python_bin_path.sh
84fi
85
86if [[ -z "${PYTHON_BIN_PATH}" ]]; then
87  die "PYTHON_BIN_PATH was not provided. If this is not virtualenv, "\
88"did you run configure?"
89else
90  echo "Binary path for python: \"$PYTHON_BIN_PATH\""
91fi
92
93# Determine the TensorFlow installation path
94# pushd/popd avoids importing TensorFlow from the source directory.
95pushd /tmp > /dev/null
96TF_INSTALL_PATH=$(dirname \
97    $("${PYTHON_BIN_PATH}" -c "import tensorflow as tf; print(tf.__file__)"))
98popd > /dev/null
99
100echo "Detected TensorFlow installation path: ${TF_INSTALL_PATH}"
101
102TEST_DIR="pip_test/integration"
103mkdir -p "${TEST_DIR}" || \
104    die "Failed to create test directory: ${TEST_DIR}"
105
106# -----------------------------------------------------------
107# ffmpeg_lib_test
108test_ffmpeg_lib() {
109  # If FFmpeg is not installed then run a test that assumes it is not installed.
110  if [[ -z "$(which ffmpeg)" ]]; then
111    bazel test tensorflow/contrib/ffmpeg/default:ffmpeg_lib_uninstalled_test
112    return $?
113  else
114    bazel test tensorflow/contrib/ffmpeg/default:ffmpeg_lib_installed_test \
115        tensorflow/contrib/ffmpeg:decode_audio_op_test \
116        tensorflow/contrib/ffmpeg:encode_audio_op_test
117    return $?
118  fi
119}
120
121
122# Run the integration tests
123test_runner "integration test-on-install" \
124    "${INTEG_TESTS}" "${TF_BUILD_INTEG_TEST_BLACKLIST}" "${LOGS_DIR}"
125