10704ebd2Sopenharmony_ci#!/bin/bash 20704ebd2Sopenharmony_ci 30704ebd2Sopenharmony_ci# Copyright (C) 2021 Huawei Device Co., Ltd. 40704ebd2Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 50704ebd2Sopenharmony_ci# you may not use this file except in compliance with the License. 60704ebd2Sopenharmony_ci# You may obtain a copy of the License at 70704ebd2Sopenharmony_ci# 80704ebd2Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 90704ebd2Sopenharmony_ci# 100704ebd2Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software 110704ebd2Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 120704ebd2Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130704ebd2Sopenharmony_ci# See the License for the specific language governing permissions and 140704ebd2Sopenharmony_ci# limitations under the License. 150704ebd2Sopenharmony_ci 160704ebd2Sopenharmony_ciset -e 170704ebd2Sopenharmony_ci 180704ebd2Sopenharmony_ciusage() 190704ebd2Sopenharmony_ci{ 200704ebd2Sopenharmony_ci echo 210704ebd2Sopenharmony_ci echo "USAGE" 220704ebd2Sopenharmony_ci echo " ./runtest.sh device=IP:PORT serial=[SERIAL_NUMBER] [module=MODULE_NAME] [test=TEST] [runonly=RUN_ONLY]" 230704ebd2Sopenharmony_ci echo " First, you must be execute stf/start.bat in the windows which connected a device." 240704ebd2Sopenharmony_ci echo " target_platform : TARGET_PLATFORM the target platform, such as phone or ivi; Default to phone" 250704ebd2Sopenharmony_ci echo " device : IP:PORT the host ip:port of the connected device." 260704ebd2Sopenharmony_ci echo " module : MODULE_NAME the module name to run. Run all modules by default." 270704ebd2Sopenharmony_ci echo " test : TEST_NAME the test name to run. Run all tests by default. This should be a FULL-QUALIFIED className or methodName." 280704ebd2Sopenharmony_ci echo " runonly : RUN_ONLY TRUE=not build, only runtest; FALSE=build and runtest. FALSE by default." 290704ebd2Sopenharmony_ci echo 300704ebd2Sopenharmony_ci exit 1 310704ebd2Sopenharmony_ci} 320704ebd2Sopenharmony_ci 330704ebd2Sopenharmony_ciparse_cmdline() 340704ebd2Sopenharmony_ci{ 350704ebd2Sopenharmony_ci echo parse_cmdline:$@ 360704ebd2Sopenharmony_ci SCRIPT_DIR=$(cd $(dirname $0); pwd) 370704ebd2Sopenharmony_ci BUILD_SCRIPT=${SCRIPT_DIR}/build.sh 380704ebd2Sopenharmony_ci BASE_HOME=${SCRIPT_DIR}/../../.. 390704ebd2Sopenharmony_ci OUT_DIR=${SCRIPT_DIR}/../../../out 400704ebd2Sopenharmony_ci TARGET_ARCH=arm64 410704ebd2Sopenharmony_ci TARGET_PLATFORM=all 420704ebd2Sopenharmony_ci BUILD_VARIANT=release 430704ebd2Sopenharmony_ci MODULE_NAME="" 440704ebd2Sopenharmony_ci DEVICE_SN="" 450704ebd2Sopenharmony_ci TEST_NAME="" 460704ebd2Sopenharmony_ci RUN_ONLY=FALSE 470704ebd2Sopenharmony_ci BUILD_PARAM="" 480704ebd2Sopenharmony_ci HATS_HOME=$SCRIPT_DIR/../../../out/$BUILD_VARIANT/suites/dcts 490704ebd2Sopenharmony_ci MODULE_INFO_FILE=$SCRIPT_DIR/../../../out/$BUILD_VARIANT/suites/dcts/testcases/module_info.list 500704ebd2Sopenharmony_ci export PATH=${BASE_HOME}/prebuilts/python/linux-x86/3.8.5/bin:$PATH 510704ebd2Sopenharmony_ci BUILD_PARAM="$BUILD_PARAM target_arch=$TARGET_ARCH variant=$BUILD_VARIANT" 520704ebd2Sopenharmony_ci 530704ebd2Sopenharmony_ci while [ -n "$1" ] 540704ebd2Sopenharmony_ci do 550704ebd2Sopenharmony_ci var="$1" 560704ebd2Sopenharmony_ci OPTIONS=$(echo ${var%%=*}) 570704ebd2Sopenharmony_ci PARAM=$(echo ${var#*=}) 580704ebd2Sopenharmony_ci case "$OPTIONS" in 590704ebd2Sopenharmony_ci target_platform) TARGET_PLATFORM="$PARAM" 600704ebd2Sopenharmony_ci BUILD_PARAM="$BUILD_PARAM target_platform=$TARGET_PLATFORM" 610704ebd2Sopenharmony_ci ;; 620704ebd2Sopenharmony_ci module) MODULE_NAME="$PARAM" 630704ebd2Sopenharmony_ci BUILD_PARAM="$BUILD_PARAM suite=$MODULE_NAME" 640704ebd2Sopenharmony_ci ;; 650704ebd2Sopenharmony_ci test) TEST_NAME="$PARAM" 660704ebd2Sopenharmony_ci ;; 670704ebd2Sopenharmony_ci device) DEVICE_SN="$DEVICE_SN;$PARAM" 680704ebd2Sopenharmony_ci ;; 690704ebd2Sopenharmony_ci runonly) RUN_ONLY=$(echo $PARAM |tr [a-z] [A-Z]) 700704ebd2Sopenharmony_ci ;; 710704ebd2Sopenharmony_ci *) usage 720704ebd2Sopenharmony_ci break;; 730704ebd2Sopenharmony_ci esac 740704ebd2Sopenharmony_ci shift 750704ebd2Sopenharmony_ci done 760704ebd2Sopenharmony_ci if [ "$DEVICE_SN" == "" ];then 770704ebd2Sopenharmony_ci usage 780704ebd2Sopenharmony_ci fi 790704ebd2Sopenharmony_ci} 800704ebd2Sopenharmony_ci 810704ebd2Sopenharmony_cido_make() 820704ebd2Sopenharmony_ci{ 830704ebd2Sopenharmony_ci cd $BASE_HOME 840704ebd2Sopenharmony_ci echo "================================" 850704ebd2Sopenharmony_ci echo "start to build" 860704ebd2Sopenharmony_ci echo "$BUILD_SCRIPT $BUILD_PARAM" 870704ebd2Sopenharmony_ci echo "================================" 880704ebd2Sopenharmony_ci 890704ebd2Sopenharmony_ci echo BUILD_PARAM= $BUILD_PARAM 900704ebd2Sopenharmony_ci $BUILD_SCRIPT $BUILD_PARAM 910704ebd2Sopenharmony_ci if [ "$?" != 0 ]; then 920704ebd2Sopenharmony_ci echo -e "\033[31mbuild error!\033[0m" 930704ebd2Sopenharmony_ci exit 1 940704ebd2Sopenharmony_ci fi 950704ebd2Sopenharmony_ci} 960704ebd2Sopenharmony_ci 970704ebd2Sopenharmony_ciget_testmodule_name() 980704ebd2Sopenharmony_ci{ 990704ebd2Sopenharmony_ci BUILD_TARGET_NAME=$1 1000704ebd2Sopenharmony_ci # map from build_target name to actual testmodule name 1010704ebd2Sopenharmony_ci test_module_name="" 1020704ebd2Sopenharmony_ci OLD_IFS=$IFS 1030704ebd2Sopenharmony_ci IFS=$'\n' 1040704ebd2Sopenharmony_ci for line in $(cat $MODULE_INFO_FILE); do 1050704ebd2Sopenharmony_ci VAR1=$(echo $line |awk -F ' ' '{print $1}') 1060704ebd2Sopenharmony_ci VAR2=$(echo $line |awk -F ' ' '{print $2}') 1070704ebd2Sopenharmony_ci if [ "$BUILD_TARGET_NAME" == "$VAR1" ] ; then 1080704ebd2Sopenharmony_ci test_module_name=$VAR2 1090704ebd2Sopenharmony_ci break 1100704ebd2Sopenharmony_ci fi 1110704ebd2Sopenharmony_ci done 1120704ebd2Sopenharmony_ci IFS=$OLD_IFS 1130704ebd2Sopenharmony_ci echo $test_module_name 1140704ebd2Sopenharmony_ci} 1150704ebd2Sopenharmony_ci 1160704ebd2Sopenharmony_cirun_test_with_xdevice() 1170704ebd2Sopenharmony_ci{ 1180704ebd2Sopenharmony_ci TC_PATH=$HATS_HOME/testcases 1190704ebd2Sopenharmony_ci RES_PATH=$HATS_HOME/resource/ 1200704ebd2Sopenharmony_ci REPORT_PATH=$HATS_HOME/xdevice_reports/$(date "+%Y.%m.%d-%H.%M.%S") 1210704ebd2Sopenharmony_ci python -m easy_install --quiet $HATS_HOME/tools/xdevice-0.0.0.tar.gz 1220704ebd2Sopenharmony_ci python -m easy_install --quiet $HATS_HOME/tools/xdevice-extension-0.0.0.tar.gz 1230704ebd2Sopenharmony_ci 1240704ebd2Sopenharmony_ci run_arguments="run dcts -tcpath $TC_PATH -respath $RES_PATH -rp $REPORT_PATH" 1250704ebd2Sopenharmony_ci if [ ! -z "$MODULE_NAME" ]; then 1260704ebd2Sopenharmony_ci run_arguments="$run_arguments -l $1" 1270704ebd2Sopenharmony_ci fi 1280704ebd2Sopenharmony_ci if [ ! -z "$TEST_NAME" ]; then 1290704ebd2Sopenharmony_ci TEST_LIST_FILE=$HATS_HOME/include_tests 1300704ebd2Sopenharmony_ci echo "$TEST_NAME" > $TEST_LIST_FILE 1310704ebd2Sopenharmony_ci run_arguments="$run_arguments -ta test-file-include-filter:$TEST_LIST_FILE" 1320704ebd2Sopenharmony_ci fi 1330704ebd2Sopenharmony_ci if [ ! -z "$DEVICE_SN" ]; then 1340704ebd2Sopenharmony_ci run_arguments="$run_arguments $(echo $DEVICE_SN | sed 's/;/-sn /')" 1350704ebd2Sopenharmony_ci fi 1360704ebd2Sopenharmony_ci 1370704ebd2Sopenharmony_ci echo $run_arguments 1380704ebd2Sopenharmony_ci cd $HATS_HOME 1390704ebd2Sopenharmony_ci python -m xdevice "$run_arguments" 1400704ebd2Sopenharmony_ci 1410704ebd2Sopenharmony_ci return $? 1420704ebd2Sopenharmony_ci} 1430704ebd2Sopenharmony_ci 1440704ebd2Sopenharmony_cirun_test() 1450704ebd2Sopenharmony_ci{ 1460704ebd2Sopenharmony_ci cd $BASE_HOME 1470704ebd2Sopenharmony_ci 1480704ebd2Sopenharmony_ci MAPPED_MODULE_NAME=$MODULE_NAME 1490704ebd2Sopenharmony_ci # map from build_target name to actual testmodule name 1500704ebd2Sopenharmony_ci if [ ! -z "$MODULE_NAME" ]; then 1510704ebd2Sopenharmony_ci MAPPED_MODULE_NAME=$(get_testmodule_name $MODULE_NAME $HATS_HOME) 1520704ebd2Sopenharmony_ci if [ ! -z "$MAPPED_MODULE_NAME" ]; then 1530704ebd2Sopenharmony_ci echo -e "\033[32mTest module name of build_target "$MODULE_NAME is" "$MAPPED_MODULE_NAME"\033[0m" 1540704ebd2Sopenharmony_ci else 1550704ebd2Sopenharmony_ci echo -e "\033[31mTest module "$MODULE_NAME" dose not exist!\033[0m" 1560704ebd2Sopenharmony_ci exit 1 1570704ebd2Sopenharmony_ci fi 1580704ebd2Sopenharmony_ci fi 1590704ebd2Sopenharmony_ci 1600704ebd2Sopenharmony_ci JSON_CONFIG_FILE=$HATS_HOME/testcases/$MAPPED_MODULE_NAME.json 1610704ebd2Sopenharmony_ci ret_code=0 1620704ebd2Sopenharmony_ci if [ -f "$JSON_CONFIG_FILE" ]; then 1630704ebd2Sopenharmony_ci echo -e "\033[32mRun $MAPPED_MODULE_NAME with xdevice ...\033[0m" 1640704ebd2Sopenharmony_ci run_test_with_xdevice $MAPPED_MODULE_NAME 1650704ebd2Sopenharmony_ci ret_code=$? 1660704ebd2Sopenharmony_ci elif [ -z "$MODULE_NAME" ]; then 1670704ebd2Sopenharmony_ci echo -e "\033[32mRun all modules with xdevice ...\033[0m" 1680704ebd2Sopenharmony_ci run_test_with_xdevice 1690704ebd2Sopenharmony_ci ret_code=$? 1700704ebd2Sopenharmony_ci else 1710704ebd2Sopenharmony_ci echo -e "\033[31mNon-xdevice module in dcts!\033[0m" 1720704ebd2Sopenharmony_ci exit 1 1730704ebd2Sopenharmony_ci fi 1740704ebd2Sopenharmony_ci 1750704ebd2Sopenharmony_ci if [ "$ret_code" != "0" ]; then 1760704ebd2Sopenharmony_ci echo -e "\033[31mFailed to run test, ret=$ret_code\033[0m" 1770704ebd2Sopenharmony_ci exit 1 1780704ebd2Sopenharmony_ci fi 1790704ebd2Sopenharmony_ci} 1800704ebd2Sopenharmony_ci 1810704ebd2Sopenharmony_ciparse_cmdline $@ 1820704ebd2Sopenharmony_ciif [ "$RUN_ONLY" == FALSE ];then 1830704ebd2Sopenharmony_ci do_make 1840704ebd2Sopenharmony_cifi 1850704ebd2Sopenharmony_cimkdir -p $OUT_DIR/$BUILD_VARIANT/suites/dcts/resource/tools 1860704ebd2Sopenharmony_cirun_test 1870704ebd2Sopenharmony_ciexit 0 188