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