1#!/bin/bash 2# Copyright 2019 Huawei Technologies Co., Ltd 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 -e 18BASEPATH=$(cd "$(dirname $0)"; pwd) 19PROJECT_PATH=${BASEPATH}/../../.. 20 21# print usage message 22usage() 23{ 24 echo "Usage:" 25 echo "sh runtests.sh [-e ascend310|ascend910] [-n testcase_name] [-d n] [-t cpp|python] [-r path]" 26 echo "" 27 echo "Options:" 28 echo " -h Print usage" 29 echo " -e Device target, default is ascend310" 30 echo " -d Device ID, default is 0" 31 echo " -n Run single tesecase, default off" 32 echo " -t Type of MindSpore package to be tested, default is cpp" 33 echo " -r Path of mindspore package to be tested, default is {PROJECT_PATH}/output" 34 echo "to be continued ..." 35} 36 37checkopts() 38{ 39 DEVICE_TARGET_OPT="ascend310" 40 DEVICE_ID_OPT=0 41 TASECASE_NAME_OPT="" 42 TEST_PATH=${PROJECT_PATH}/tests/st/cpp 43 PACKAGE_PATH=${PROJECT_PATH}/output 44 PACKAGE_TYPE="cpp" 45 46 # Process the options 47 while getopts 'he:d:n:t:r:' opt 48 do 49 case "${opt}" in 50 h) 51 usage 52 exit 0 53 ;; 54 e) 55 DEVICE_TARGET_OPT=$(echo ${OPTARG} | tr '[A-Z]' '[a-z]') 56 ;; 57 d) 58 DEVICE_ID_OPT=$OPTARG 59 ;; 60 n) 61 TASECASE_NAME_OPT=$OPTARG 62 ;; 63 t) 64 if [[ "X$OPTARG" == "Xcpp" || "X$OPTARG" == "Xpython" ]]; then 65 PACKAGE_TYPE="$OPTARG" 66 else 67 echo "Invalid value ${OPTARG} for option -t" 68 usage 69 exit 1 70 fi 71 ;; 72 r) 73 PACKAGE_PATH=$OPTARG 74 echo "package path set to: ${OPTARG}" 75 ;; 76 *) 77 echo "Undefined option: ${opt}" 78 usage 79 exit 1 80 esac 81 done 82} 83checkopts "$@" 84 85cd ${TEST_PATH} 86 87# using installed or compiled whl packages, set env path by pip 88if [[ "${PACKAGE_TYPE}" == "python" ]]; then 89 MINDSPORE_PKG_PATH=`python -m pip show mindspore-ascend | grep Location | awk '{print $2"/mindspore"}' | xargs realpath` 90 if [[ "X${MINDSPORE_PKG_PATH}" == "X" ]]; then 91 MINDSPORE_PKG_PATH=${PROJECT_PATH}/build/package/mindspore: 92 fi 93elif [[ "${PACKAGE_TYPE}" == "cpp" ]]; then 94# using acl tar package, extract tar package here 95 rm -rf mindspore_ascend* 96 PACKAGE_NAME_FULL=$(find "${PACKAGE_PATH}" -name "mindspore_ascend*.tar.gz") 97 PACKAGE_NAME=${PACKAGE_NAME_FULL##*/} 98 99 tar -xzf ${PACKAGE_PATH}/${PACKAGE_NAME} 100 MINDSPORE_PKG_PATH=$(find "${TEST_PATH}" -maxdepth 1 -name "mindspore_ascend*") 101fi 102 103export LD_LIBRARY_PATH=${MINDSPORE_PKG_PATH}:${MINDSPORE_PKG_PATH}/lib:${PROJECT_PATH}/tests/st/cpp:$LD_LIBRARY_PATH 104export GLOG_v=2 105export GC_COLLECT_IN_CELL=1 106export DEVICE_ID=$DEVICE_ID_OPT 107if [[ "X$DEVICE_TARGET_OPT" == "Xascend310" ]]; then 108 export DEVICE_TARGET=Ascend310 109elif [[ "X$DEVICE_TARGET_OPT" == "Xascend910" ]]; then 110 export DEVICE_TARGET=Ascend910 111else 112 export DEVICE_TARGET=$DEVICE_TARGET_OPT 113fi 114 115if [[ "X$TASECASE_NAME_OPT" != "X" ]]; then 116 ./st_tests --gtest_filter=$TASECASE_NAME_OPT 117else 118 ./st_tests 119fi 120RET=$? 121cd - 122 123exit ${RET} 124