1#!/bin/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# Pip install TensorFlow and run basic test on the pip package. 17 18set -e 19set -x 20 21# Get size check function 22source tensorflow/tools/ci_build/release/common.sh 23 24function run_smoke_test() { 25 26 if [[ -z "${WHL_NAME}" ]]; then 27 echo "TF WHL path not given, unable to install and test." 28 exit 1 29 fi 30 31 # Upload the PIP package if whl test passes. 32 if [ ${IN_VENV} -eq 0 ]; then 33 VENV_TMP_DIR=$(mktemp -d) 34 35 ${PYTHON_BIN_PATH} -m pip install virtualenv 36 37 ${PYTHON_BIN_PATH} -m virtualenv -p ${PYTHON_BIN_PATH} "${VENV_TMP_DIR}" || \ 38 die "FAILED: Unable to create virtualenv" 39 40 source "${VENV_TMP_DIR}/bin/activate" || \ 41 die "FAILED: Unable to activate virtualenv " 42 fi 43 44 # install tensorflow 45 python -m pip install ${WHL_NAME} || \ 46 die "pip install (forcing to reinstall tensorflow) FAILED" 47 echo "Successfully installed pip package ${WHL_NAME}" 48 49 # Test TensorflowFlow imports 50 test_tf_imports 51 52 # Test TensorFlow whl file size 53 test_tf_whl_size ${WHL_NAME} 54 55 RESULT=$? 56 57 # Upload the PIP package if whl test passes. 58 if [ ${IN_VENV} -eq 0 ]; then 59 # Deactivate from virtualenv. 60 deactivate || source deactivate || die "FAILED: Unable to deactivate from existing virtualenv." 61 sudo rm -rf "${KOKORO_GFILE_DIR}/venv" 62 fi 63 64 return $RESULT 65} 66 67function test_tf_imports() { 68 TMP_DIR=$(mktemp -d) 69 pushd "${TMP_DIR}" 70 71 # test for basic import and perform tf.add operation. 72 RET_VAL=$(python -c "import tensorflow as tf; t1=tf.constant([1,2,3,4]); t2=tf.constant([5,6,7,8]); print(tf.add(t1,t2).shape)") 73 if ! [[ ${RET_VAL} == *'(4,)'* ]]; then 74 echo "Unexpected return value: ${RET_VALUE}" 75 echo "PIP test on virtualenv FAILED, will not upload ${WHL_NAME} package." 76 return 1 77 fi 78 79 # test basic keras is available 80 RET_VAL=$(python -c "import tensorflow as tf; print(tf.keras.__name__)") 81 if ! [[ ${RET_VAL} == *'keras.api'* ]]; then 82 echo "Unexpected return value: ${RET_VALUE}" 83 echo "PIP test on virtualenv FAILED, will not upload ${WHL_NAME} package." 84 return 1 85 fi 86 87 # similar test for estimator 88 RET_VAL=$(python -c "import tensorflow as tf; print(tf.estimator.__name__)") 89 if ! [[ ${RET_VAL} == *'tensorflow_estimator.python.estimator.api._v2.estimator'* ]]; then 90 echo "Unexpected return value: ${RET_VALUE}" 91 echo "PIP test on virtualenv FAILED, will not upload ${WHL_NAME} package." 92 return 1 93 fi 94 95 RESULT=$? 96 97 # TODO(b/210940071): Debug import order. Ignore returned errors. 98 set +e 99 python -m pip install google-cloud-bigquery 100 $(python -c "from google.cloud.bigquery_v2 import types; import tensorflow") 101 $(python -c "import tensorflow; from google.cloud.bigquery_v2 import types") 102 set -e 103 104 popd 105 return $RESULT 106} 107 108########################################################################### 109# Main 110########################################################################### 111 112IN_VENV=$(python -c 'import sys; print("1" if sys.version_info.major == 3 and sys.prefix != sys.base_prefix else "0")') 113WHL_NAME=${1} 114run_smoke_test 115