1#!/bin/bash 2 3# Copyright (C) 2021 Huawei Device Co., Ltd. 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 16set -e 17 18usage() 19{ 20 echo 21 echo "USAGE" 22 echo " ./runtest.sh device=IP:PORT serial=[SERIAL_NUMBER] [module=MODULE_NAME] [test=TEST] [runonly=RUN_ONLY]" 23 echo " First, you must be execute stf/start.bat in the windows which connected a device." 24 echo " target_platform : TARGET_PLATFORM the target platform, such as phone or ivi; Default to phone" 25 echo " device : IP:PORT the host ip:port of the connected device." 26 echo " module : MODULE_NAME the module name to run. Run all modules by default." 27 echo " test : TEST_NAME the test name to run. Run all tests by default. This should be a FULL-QUALIFIED className or methodName." 28 echo " runonly : RUN_ONLY TRUE=not build, only runtest; FALSE=build and runtest. FALSE by default." 29 echo 30 exit 1 31} 32 33parse_cmdline() 34{ 35 echo parse_cmdline:$@ 36 SCRIPT_DIR=$(cd $(dirname $0); pwd) 37 BUILD_SCRIPT=${SCRIPT_DIR}/build.sh 38 BASE_HOME=${SCRIPT_DIR}/../../.. 39 OUT_DIR=${SCRIPT_DIR}/../../../out 40 TARGET_ARCH=arm64 41 TARGET_PLATFORM=all 42 BUILD_VARIANT=release 43 MODULE_NAME="" 44 DEVICE_SN="" 45 TEST_NAME="" 46 RUN_ONLY=FALSE 47 BUILD_PARAM="" 48 HATS_HOME=$SCRIPT_DIR/../../../out/$BUILD_VARIANT/suites/dcts 49 MODULE_INFO_FILE=$SCRIPT_DIR/../../../out/$BUILD_VARIANT/suites/dcts/testcases/module_info.list 50 export PATH=${BASE_HOME}/prebuilts/python/linux-x86/3.8.5/bin:$PATH 51 BUILD_PARAM="$BUILD_PARAM target_arch=$TARGET_ARCH variant=$BUILD_VARIANT" 52 53 while [ -n "$1" ] 54 do 55 var="$1" 56 OPTIONS=$(echo ${var%%=*}) 57 PARAM=$(echo ${var#*=}) 58 case "$OPTIONS" in 59 target_platform) TARGET_PLATFORM="$PARAM" 60 BUILD_PARAM="$BUILD_PARAM target_platform=$TARGET_PLATFORM" 61 ;; 62 module) MODULE_NAME="$PARAM" 63 BUILD_PARAM="$BUILD_PARAM suite=$MODULE_NAME" 64 ;; 65 test) TEST_NAME="$PARAM" 66 ;; 67 device) DEVICE_SN="$DEVICE_SN;$PARAM" 68 ;; 69 runonly) RUN_ONLY=$(echo $PARAM |tr [a-z] [A-Z]) 70 ;; 71 *) usage 72 break;; 73 esac 74 shift 75 done 76 if [ "$DEVICE_SN" == "" ];then 77 usage 78 fi 79} 80 81do_make() 82{ 83 cd $BASE_HOME 84 echo "================================" 85 echo "start to build" 86 echo "$BUILD_SCRIPT $BUILD_PARAM" 87 echo "================================" 88 89 echo BUILD_PARAM= $BUILD_PARAM 90 $BUILD_SCRIPT $BUILD_PARAM 91 if [ "$?" != 0 ]; then 92 echo -e "\033[31mbuild error!\033[0m" 93 exit 1 94 fi 95} 96 97get_testmodule_name() 98{ 99 BUILD_TARGET_NAME=$1 100 # map from build_target name to actual testmodule name 101 test_module_name="" 102 OLD_IFS=$IFS 103 IFS=$'\n' 104 for line in $(cat $MODULE_INFO_FILE); do 105 VAR1=$(echo $line |awk -F ' ' '{print $1}') 106 VAR2=$(echo $line |awk -F ' ' '{print $2}') 107 if [ "$BUILD_TARGET_NAME" == "$VAR1" ] ; then 108 test_module_name=$VAR2 109 break 110 fi 111 done 112 IFS=$OLD_IFS 113 echo $test_module_name 114} 115 116run_test_with_xdevice() 117{ 118 TC_PATH=$HATS_HOME/testcases 119 RES_PATH=$HATS_HOME/resource/ 120 REPORT_PATH=$HATS_HOME/xdevice_reports/$(date "+%Y.%m.%d-%H.%M.%S") 121 python -m easy_install --quiet $HATS_HOME/tools/xdevice-0.0.0.tar.gz 122 python -m easy_install --quiet $HATS_HOME/tools/xdevice-extension-0.0.0.tar.gz 123 124 run_arguments="run dcts -tcpath $TC_PATH -respath $RES_PATH -rp $REPORT_PATH" 125 if [ ! -z "$MODULE_NAME" ]; then 126 run_arguments="$run_arguments -l $1" 127 fi 128 if [ ! -z "$TEST_NAME" ]; then 129 TEST_LIST_FILE=$HATS_HOME/include_tests 130 echo "$TEST_NAME" > $TEST_LIST_FILE 131 run_arguments="$run_arguments -ta test-file-include-filter:$TEST_LIST_FILE" 132 fi 133 if [ ! -z "$DEVICE_SN" ]; then 134 run_arguments="$run_arguments $(echo $DEVICE_SN | sed 's/;/-sn /')" 135 fi 136 137 echo $run_arguments 138 cd $HATS_HOME 139 python -m xdevice "$run_arguments" 140 141 return $? 142} 143 144run_test() 145{ 146 cd $BASE_HOME 147 148 MAPPED_MODULE_NAME=$MODULE_NAME 149 # map from build_target name to actual testmodule name 150 if [ ! -z "$MODULE_NAME" ]; then 151 MAPPED_MODULE_NAME=$(get_testmodule_name $MODULE_NAME $HATS_HOME) 152 if [ ! -z "$MAPPED_MODULE_NAME" ]; then 153 echo -e "\033[32mTest module name of build_target "$MODULE_NAME is" "$MAPPED_MODULE_NAME"\033[0m" 154 else 155 echo -e "\033[31mTest module "$MODULE_NAME" dose not exist!\033[0m" 156 exit 1 157 fi 158 fi 159 160 JSON_CONFIG_FILE=$HATS_HOME/testcases/$MAPPED_MODULE_NAME.json 161 ret_code=0 162 if [ -f "$JSON_CONFIG_FILE" ]; then 163 echo -e "\033[32mRun $MAPPED_MODULE_NAME with xdevice ...\033[0m" 164 run_test_with_xdevice $MAPPED_MODULE_NAME 165 ret_code=$? 166 elif [ -z "$MODULE_NAME" ]; then 167 echo -e "\033[32mRun all modules with xdevice ...\033[0m" 168 run_test_with_xdevice 169 ret_code=$? 170 else 171 echo -e "\033[31mNon-xdevice module in dcts!\033[0m" 172 exit 1 173 fi 174 175 if [ "$ret_code" != "0" ]; then 176 echo -e "\033[31mFailed to run test, ret=$ret_code\033[0m" 177 exit 1 178 fi 179} 180 181parse_cmdline $@ 182if [ "$RUN_ONLY" == FALSE ];then 183 do_make 184fi 185mkdir -p $OUT_DIR/$BUILD_VARIANT/suites/dcts/resource/tools 186run_test 187exit 0 188