diff options
author | Milosz Wasilewski <milosz.wasilewski@linaro.org> | 2017-03-17 12:55:46 +0000 |
---|---|---|
committer | Milosz Wasilewski <milosz.wasilewski@linaro.org> | 2017-03-17 12:55:46 +0000 |
commit | 8b6eb53acf81d255224bab56a5337f0660badd5a (patch) | |
tree | dea856bc51aa335a24ebc8f44cf7c0b36712e3e4 | |
parent | 0229edf9bd03ff3674c49a46f35dcba737788b4e (diff) | |
parent | e219c6c56a58d1048b3e7256937fe0940d62c208 (diff) |
Merge commit 'refs/changes/73/17973/1' of https://review.linaro.org/qa/android-apk-automation into v2v2
Change-Id: I6c515bd10173a41c7310e30a745e08b2e775231a
-rwxr-xr-x | apk-automation.sh | 57 | ||||
-rw-r--r-- | apk-automation.yaml | 39 | ||||
-rw-r--r-- | application-benchmark-host.yaml | 51 | ||||
-rw-r--r-- | application-benchmark-target.yaml | 35 | ||||
-rwxr-xr-x | common/common.sh | 35 | ||||
-rwxr-xr-x[-rw-r--r--] | common/common2.sh | 167 | ||||
-rwxr-xr-x | common/output-test-result.sh | 4 | ||||
-rwxr-xr-x[-rw-r--r--] | common/statistic_average.sh | 61 | ||||
-rw-r--r-- | lava-android-benchmark-host.yaml | 48 | ||||
-rw-r--r-- | lava-android-benchmark-target.yaml | 36 | ||||
-rwxr-xr-x | lib/android-test-lib | 143 | ||||
-rwxr-xr-x | lib/sh-test-lib | 337 |
12 files changed, 723 insertions, 290 deletions
diff --git a/apk-automation.sh b/apk-automation.sh new file mode 100755 index 0000000..e16dbfe --- /dev/null +++ b/apk-automation.sh @@ -0,0 +1,57 @@ +#!/bin/sh -e +# shellcheck disable=SC1091 +. ./lib/sh-test-lib +. ./lib/android-test-lib + +SKIP_INSTALL="false" +SN="" +BOOT_TIMEOUT="300" +OUTPUT="$(pwd)/output" +RESULT_FILE="${OUTPUT}/result.txt" +export RESULT_FILE + +TEST_NAME="linpack" +LOOP_COUNT="1" +COLLECT_STREAMLINE="false" +VERBOSE_OUTPUT="FALSE" +RECORD_STATISTICS="TRUE" +RECORD_CSV="TRUE" + +usage() { + echo "Usage: $0 [-s <true|false>] [-n <serialno>] [-o <timeout>] [-t <test_name>] [-l <loop_count>] [-m <true|false>] [-v <TRUE|FALSE>] [-r <TRUE|FALSE>] [-c <TRUE|FALSE>]" 1>&2 + exit 1 +} + +while getopts ":s:n:o:t:l:m:v:r:c:" opt; do + case "${opt}" in + s) SKIP_INSTALL="${OPTARG}" ;; + n) SN="${OPTARG}" ;; + o) BOOT_TIMEOUT="${OPTARG}" ;; + t) TEST_NAME="${OPTARG}" ;; + l) LOOP_COUNT="${OPTARG}" ;; + m) COLLECT_STREAMLINE="${OPTARG}" ;; + v) VERBOSE_OUTPUT="${OPTARG}" ;; + r) RECORD_STATISTICS="${OPTARG}" ;; + c) RECORD_CSV="${OPTARG}" ;; + *) usage ;; + esac +done + +! check_root && error_msg "Please run this script as superuser!" +if [ "${SKIP_INSTALL}" = "true" ] || [ "${SKIP_INSTALL}" = "True" ]; then + info_msg "Package installation skipped" +else + install_deps "bc curl wget zip git python-lxml python-pil python-setuptools" "${SKIP_INSTALL}" + git clone https://github.com/dtmilano/AndroidViewClient + ( + cd AndroidViewClient/ || error_msg "DIR AndroidViewClient not exists" + python setup.py install + ) +fi + +initialize_adb +adb_root +wait_boot_completed "${BOOT_TIMEOUT}" +create_out_dir "${OUTPUT}" + +./"${TEST_NAME}"/execute.sh --serial "${SN}" --loop-count "${LOOP_COUNT}" --streamline "${COLLECT_STREAMLINE}" --verbose-output "${VERBOSE_OUTPUT}" --record-statistics "${RECORD_STATISTICS}" --record-csv "${RECORD_CSV}" || true diff --git a/apk-automation.yaml b/apk-automation.yaml new file mode 100644 index 0000000..1a37bb8 --- /dev/null +++ b/apk-automation.yaml @@ -0,0 +1,39 @@ +metadata: + name: apk-automation + format: "Lava-Test-Shell Test Definition 1.0" + description: "Automated benchmarking with APKs on Android." + maintainer: + - milosz.wasilewski@linaro.org + - chase.qi@linaro.org + os: + - android + devices: + - juno + - hi6220-hikey + - x15 + scope: + - performance + +params: + SKIP_INSTALL: "false" + # Timeout for wait_boot_completed and wait_homescreen. + BOOT_TIMEOUT: "300" + # Specify adb device SN if more then one device connected. + SN: "" + TEST_NAME: "linpack" + LOOP_COUNT: "5" + COLLECT_STREAMLINE: "false" + VERBOSE_OUTPUT: "FALSE" + RECORD_STATISTICS: "TRUE" + RECORD_CSV: "TRUE" + # Specify url and token for file uploading. + URL: "https://archive.validation.linaro.org/artifacts/team/qa/" + TOKEN: "4373c97b474497dbd12373689d7d492e" +run: + steps: + - cd ./automated/android/apk-automation + - ./apk-automation.sh -s "${SKIP_INSTALL}" -o "${BOOT_TIMEOUT}" -n "${SN}" -t "${TEST_NAME}" -l "${LOOP_COUNT}" -m "${COLLECT_STREAMLINE}" -v "${VERBOSE_OUTPUT}" -r "${RECORD_STATISTICS}" -c "${RECORD_CSV}" + # Upload rawdata.zip to artifactorial. + - ../../utils/upload-to-artifactorial.sh -a "./rawdata.zip" -u "${URL}" -t "${TOKEN}" + # Send test result to LAVA. + - ../../utils/send-to-lava.sh ./output/result.txt diff --git a/application-benchmark-host.yaml b/application-benchmark-host.yaml deleted file mode 100644 index c6f309f..0000000 --- a/application-benchmark-host.yaml +++ /dev/null @@ -1,51 +0,0 @@ -metadata: - name: application-benchmark-host - format: "Lava-Test-Shell Test Definition 1.0" - description: "Wrapper for benchmarking application, will collect information - like memory, cpu, starttime when start the activity. Some parameters - can be specified for this test: - BASE_URL: based url from where application apk files can be gotten. - default is http://testdata.validation.linaro.org/apks/JavaBenchmark/pure-java-applications/ - APP_CONFIG_LIST: specify the application to be benchmarked in the form of - APK_FILE_NAME,APP_PACKAGE/ACTIVITY_NAME,APP_NICKNAME - we can sepcified multiple with space separated. If the application to be benchmarked - is a system application, we can specified NULL in the APK_FILE_NAME placeholder - LOOP_COUNT: specify the count we want to run for benchmarking. Default is 12. - the average is calculated with maximum and minimum excluded. - COLLECT_STREAMLINE: specify if streamline data will be collected. only false and true are available." - maintainer: - - yongqin.liu@linaro.org - os: - - android - scope: - - performance - devices: - - kvm - -params: - APP_CONFIG_LIST: "" - LOOP_COUNT: 13 - COLLECT_STREAMLINE: "false" - TEST_NAME: "application-benchmark" - -install: - deps: - - zip - - android-tools-adb - - android-tools-fastboot - -run: - steps: - - apt-get update -y - - apt-get install -y adb bc - - lava-wait $TEST_NAME-send-ip - - IPADDR=`awk -F '=' '{print $2}' /tmp/lava_multi_node_cache.txt` - - "./adb_connect_device.sh $IPADDR" - - adb -s $IPADDR wait-for-device - - ./application-benchmark.sh --loop-count "$LOOP_COUNT" --streamline "$COLLECT_STREAMLINE" $APP_CONFIG_LIST - - lava-sync $TEST_NAME-finished - -parse: - pattern: "(?P<test_case_id>\\S+)(?P<result>=)(?P<measurement>[\\d\\.]+)\\s+(?P<units>\\S+)" - fixupdict: - =: pass diff --git a/application-benchmark-target.yaml b/application-benchmark-target.yaml deleted file mode 100644 index f8c28b6..0000000 --- a/application-benchmark-target.yaml +++ /dev/null @@ -1,35 +0,0 @@ -metadata: - name: target-stop - format: "Lava-Test-Shell Test Definition 1.0" - description: "Wrapper for notifying the host side that target side is ready, - and waiting for the singal from host side to stop target." - maintainer: - - yongqin.liu@linaro.org - os: - - android - scope: - - functional - devices: - - juno - -params: - TEST_NAME: "application-benchmark" - -run: - steps: - - lava-test-case step1-cat-build-info --shell cat /system/build.prop - - SERIALNO=$(getprop ro.serialno) - - IPADDR=$(getprop dhcp.eth0.ipaddress) - # if serial number exists it's preferred over IP based adb connection - # This means we're on 'usb only' device with WiFi connectivity - - if [ ! -z $SERIALNO ]; then IPADDR=$SERIALNO; fi - - if [ -z $SERIALNO ] - - then - - lava-test-case step2-get-adb --shell getprop service.adb.tcp.port - - lava-test-case step3-set-adb --shell setprop service.adb.tcp.port 5555 - - lava-test-case step3-set-adb-root --shell setprop service.adb.root 1 - - lava-test-case step4-stop-adbd --shell stop adbd - - lava-test-case step5-start-adbd --shell start adbd - - fi - - lava-test-case step6-send-ip --shell lava-send application-benchmark-target-ready-send-ip ipaddr=$IPADDR - - lava-test-case step7-multinode-sync --shell lava-sync application-benchmark-stop-target diff --git a/common/common.sh b/common/common.sh index ffb9466..75ece51 100755 --- a/common/common.sh +++ b/common/common.sh @@ -1,8 +1,13 @@ #!/bin/bash +# shellcheck disable=SC2034 + +set -e local_common_file_path="${BASH_SOURCE[0]}" -local_common_parent_dir=$(cd $(dirname ${local_common_file_path}); pwd) -source ${local_common_parent_dir}/common2.sh +# shellcheck disable=SC2164 +local_common_parent_dir=$(cd "$(dirname "${local_common_file_path}")"; pwd) +# shellcheck disable=SC1090 +source "${local_common_parent_dir}/common2.sh" base_url="http://testdata.validation.linaro.org/apks/" post_install="" @@ -21,15 +26,16 @@ func_setgovernor(){ fi for cpu in $(adb shell "ls -d ${dir_sys_cpu}/cpu[0-9]*" |tr '\r' ' '); do local dir_cpu_cpufreq="${cpu}/cpufreq" - adb shell "echo ${target_governor}>${dir_cpu_cpufreq}/scaling_governor" + adb shell "echo 'echo '${target_governor}' >'${dir_cpu_cpufreq}'/scaling_governor' | su" if [ -n "${target_freq}" ]; then - adb shell "echo ${target_freq} >${dir_cpu_cpufreq}/scaling_setspeed" + adb shell "echo 'echo '${target_freq}' >'${dir_cpu_cpufreq}'/scaling_setspeed' | su" fi done } func_cleanup(){ - local target_governor=$(adb shell cat ${f_tmp_governor}) + local target_governor + target_governor=$(adb shell cat "${f_tmp_governor}") func_setgovernor "${target_governor}" adb shell rm ${f_tmp_governor} func_kill_uninstall "RotationOff.apk" "rotation.off" @@ -43,8 +49,7 @@ func_install_start_RotationAPK(){ else get_file_with_base_url "${apk_name}" "${BASE_URL}" "${D_APKS}" fi - adb shell pm list packages | grep rotation.off - if [ $? -ne 0 ]; then + if ! adb shell pm list packages | grep rotation.off; then adb install "${apk_path}" fi sleep 2 @@ -68,17 +73,20 @@ func_prepare_benchmark(){ } func_run_test_bench(){ + # shellcheck disable=SC2154 local test_script="${D_ROOT}/${loop_app_name}/vc.py" local ret if [ -f "${test_script}" ]; then local test_command="python ${test_script}" if [ -n "${var_test_command_timeout}" ]; then + # shellcheck disable=SC2086 timeout ${var_test_command_timeout} ${test_command} ret=$? if [ $ret -eq 124 ]; then - local tmp_f_name=$(basename $(mktemp -u -t timeout_screen_XXX.png)) - adb shell screencap /data/local/tmp/${tmp_f_name} - adb pull /data/local/tmp/${tmp_f_name} ${D_SCREENSHOT}/${tmp_f_name} + local tmp_f_name + tmp_f_name=$(basename "$(mktemp -u -t timeout_screen_XXX.png)") + adb shell screencap "/data/local/tmp/${tmp_f_name}" + adb pull "/data/local/tmp/${tmp_f_name}" "${D_SCREENSHOT}/${tmp_f_name}" echo "Time out to run ${test_command}: ${var_test_command_timeout}" echo "You can check ${D_SCREENSHOT}/${tmp_f_name} for reference." fi @@ -93,6 +101,7 @@ func_run_test_bench(){ func_post_uninstall_bench(){ func_post_uninstall + # shellcheck disable=SC2154 if [ -n "${post_uninstall}" ]; then ${post_uninstall} fi @@ -100,7 +109,8 @@ func_post_uninstall_bench(){ function main(){ echo "test timeout: ${timeout}" - parent_dir=$(cd ${parent_dir}; pwd) + # shellcheck disable=SC2164 + parent_dir=$(cd "${parent_dir}"; pwd) export parent_dir=${parent_dir} var_func_parse_parameters="" @@ -115,7 +125,8 @@ function main(){ var_func_pre_uninstall="${pre_uninstall}" var_func_post_uninstall="func_post_uninstall_bench" - G_APPS="${apk_file_name},${activity},$(basename ${parent_dir})" + # shellcheck disable=SC2154 + G_APPS="${apk_file_name},${activity},$(basename "${parent_dir}")" BASE_URL="${base_url}" common_main "$@" diff --git a/common/common2.sh b/common/common2.sh index 00be3d6..e0e5991 100644..100755 --- a/common/common2.sh +++ b/common/common2.sh @@ -1,14 +1,19 @@ #!/bin/bash +# shellcheck disable=SC2164 +# shellcheck disable=SC2181 + +set -e local_common2_file_path="${BASH_SOURCE[0]}" -local_common2_parent_dir=$(cd $(dirname ${local_common2_file_path}); pwd) +local_common2_parent_dir=$(cd "$(dirname "${local_common2_file_path}")"; pwd) +# shellcheck disable=SC1090 source "${local_common2_parent_dir}/statistic_average.sh" -D_ROOT=$(cd $(dirname ${local_common2_parent_dir}); pwd) +D_ROOT=$(cd "$(dirname "${local_common2_parent_dir}")"; pwd) D_RAWDATA="${D_ROOT}/rawdata" D_APKS="${D_ROOT}/apks" -F_RAWDAT_ZIP="${D_ROOT}/rawdata.zip" +F_RAWDAT_ZIP="${D_ROOT}/output/rawdata.zip" F_DMESG="${D_RAWDATA}/dmesg.log" F_LOGCAT="${D_RAWDATA}/logcat.log" @@ -35,7 +40,7 @@ BASE_URL="" ## get_file_with_base_url "${apk_apk}" "${BASE_URL}" "${D_APKS}" get_file_with_base_url(){ local remote_rel_path=$1 && shift - base_name=$(basename ${remote_rel_path}) + base_name=$(basename "${remote_rel_path}") local base_url=$1 && shift local target_dir=$1 && shift @@ -63,7 +68,7 @@ get_file_with_base_url(){ "Xscp://"*) # like scp://yongqin.liu@testdata.validation.linaro.org/home/yongqin.liu apk_url="${base_url}/${remote_rel_path}" - url_no_scp=`echo ${apk_url}|sed 's/^\s*scp\:\/\///'|sed 's/\//\:\//'` + url_no_scp=$(echo "${apk_url}" | sed 's/^\s*scp\:\/\///' | sed 's/\//\:\//') scp "${url_no_scp}" "${target_dir}/${base_name}" if [ $? -ne 0 ]; then echo "Failed to get the apk(${remote_rel_path}) with ${base_url}" @@ -78,7 +83,7 @@ get_file_with_base_url(){ fi ;; "Xhttp://"*) - wget "${base_url}/${remote_rel_path}" -O "${target_dir}/${base_name}" + wget -S --progress=dot:giga "${base_url}/${remote_rel_path}" -O "${target_dir}/${base_name}" if [ $? -ne 0 ]; then echo "Failed to get the apks with ${base_url}" return 1 @@ -105,7 +110,8 @@ kill_process(){ [ -z "${proc}" ] && return while adb shell ps | grep -q -E "\s+${proc}\s+"; do - local pid=$(adb shell ps|grep -E "\s+${proc}\s+"|awk '{print $2}') + local pid + pid=$(adb shell ps|grep -E "\s+${proc}\s+"|awk '{print $2}') if [ -n "${pid}" ]; then adb shell su 0 kill -9 "${pid}" fi @@ -152,14 +158,16 @@ __EOF__ ## wait_kill_gatord_finish "${timeout}" ## Example: ## wait_kill_gatord_finish "10" +# shellcheck disable=SC2120 wait_kill_gatord_finish(){ local gatord_timeout="${1-10}" && shift local proc="gatord" local count=1 while adb shell ps | grep -q -E "\s+${proc}\s+"; do count=$((count+1)) - if [ ${count} -gt ${gatord_timeout} ]; then - local pid=$(adb shell ps|grep -E "\s+${proc}\s+"|awk '{print $2}') + if [ "${count}" -gt "${gatord_timeout}" ]; then + local pid + pid=$(adb shell ps|grep -E "\s+${proc}\s+"|awk '{print $2}') if [ -n "${pid}" ]; then adb shell su 0 kill -9 "${pid}" sleep 2 @@ -193,10 +201,11 @@ collect_streamline_data_post(){ return fi echo "Wait gatord to finish:$(date)" + # shellcheck disable=SC2119 wait_kill_gatord_finish echo "Gatord findihed:$(date)" adb shell su 0 chown -R shell:shell data/local/tmp/streamline - adb pull /data/local/tmp/streamline/${app_name}.apc ${target_dir}/${app_name}.apc + adb pull "/data/local/tmp/streamline/${app_name}.apc" "${target_dir}/${app_name}.apc" #streamline -analyze ${capture_dir} #streamline -report -function ${apd_f} |tee ${parent_dir}/streamlineReport.txt } @@ -206,8 +215,7 @@ func_kill_uninstall(){ local app_apk=$1 && shift local app_pkg=$1 && shift if [ "X${app_apk}" != "XNULL" ];then - adb shell pm list packages | grep -q "${app_pkg}" - if [ $? -eq 0 ]; then + if adb shell pm list packages | grep -q "${app_pkg}"; then adb uninstall "${app_pkg}" fi else @@ -231,13 +239,16 @@ func_post_install(){ } func_run_test(){ + # shellcheck disable=SC2154 if [ -n "${var_test_command}" ]; then + # shellcheck disable=SC2086 timeout ${var_test_command_timeout} ${var_test_command} local ret=$? if [ $ret -eq 124 ]; then - local tmp_f_name=$(basename $(mktemp -u -t timeout_screen_XXX.png)) - adb shell screencap /data/local/tmp/${tmp_f_name} - adb pull /data/local/tmp/${tmp_f_name} ${D_SCREENSHOT}/${tmp_f_name} + local tmp_f_name + tmp_f_name="$(basename "$(mktemp -u -t timeout_screen_XXX.png)")" + adb shell screencap "/data/local/tmp/${tmp_f_name}" + adb pull "/data/local/tmp/${tmp_f_name} ${D_SCREENSHOT}/${tmp_f_name}" echo "Time out to run ${var_test_command}: ${var_test_command_timeout}" echo "You can check ${D_SCREENSHOT}/${tmp_f_name} for reference." fi @@ -250,19 +261,22 @@ func_pre_uninstall(){ collect_streamline_data_post "${loop_app_name}_${loop_count}" "${D_STREAMLINE}" # capture screen shot adb shell screencap /data/local/tmp/app_screen.png - adb pull /data/local/tmp/app_screen.png ${D_SCREENSHOT}/${loop_app_name}_${loop_count}.png + adb pull /data/local/tmp/app_screen.png "${D_SCREENSHOT}/${loop_app_name}_${loop_count}.png" } collect_raw_logcat_data(){ + # shellcheck disable=SC2129 echo "===package=${loop_app_package}, count=${loop_count} start" >> "${F_LOGCAT}" adb logcat -d -v time >> "${F_LOGCAT}" echo "===package=${loop_app_package}, count=${loop_count} end" >> "${F_LOGCAT}" + # shellcheck disable=SC2129 echo "===ackage=${loop_app_package}, count=${loop_count} start" >> "${F_LOGCAT_EVENTS}" adb logcat -d -b events -v time >> "${F_LOGCAT_EVENTS}" echo "===package=${loop_app_package}, count=${loop_count} start" >> "${F_LOGCAT_EVENTS}" } collect_raw_dmesg_data(){ + # shellcheck disable=SC2129 echo "===package=${loop_app_package}, count=${loop_count} start" >> "${F_DMESG}" adb shell dmesg >> "${F_DMESG}" echo "===package=${loop_app_package}, count=${loop_count} end" >> "${F_DMESG}" @@ -299,17 +313,23 @@ func_loop_apps_for_times(){ local loop_apps_times=$1 && shift for apk in ${loop_apps_list}; do - local loop_app_apk=$(echo $apk|cut -d, -f1) - loop_app_apk=$(basename ${loop_app_apk}) - local loop_app_start_activity=$(echo $apk|cut -d, -f2) - local loop_app_package=$(echo ${loop_app_start_activity}|cut -d\/ -f1) - local loop_app_name=$(echo $apk|cut -d, -f3) + local loop_app_apk + loop_app_apk=$(echo "${apk}" | cut -d, -f1) + loop_app_apk=$(basename "${loop_app_apk}") + local loop_app_start_activity + loop_app_start_activity=$(echo "${apk}" | cut -d, -f2) + local loop_app_package + # shellcheck disable=SC1001 + loop_app_package=$(echo "${loop_app_start_activity}" | cut -d\/ -f1) + local loop_app_name + loop_app_name=$(echo "${apk}" | cut -d, -f3) local loop_count=0 - while [ ${loop_count} -lt ${loop_apps_times} ]; do + while [ "${loop_count}" -lt "${loop_apps_times}" ]; do ## steps before install the apk, ## like clean the logcat buffer or uninstall the application first ## in case failed to uninstall last time + # shellcheck disable=SC2154 if [ -n "${var_func_pre_install}" ];then ${var_func_pre_install} else @@ -328,6 +348,7 @@ func_loop_apps_for_times(){ # run steps after install but before start the activiety # since for applications we need prepare something like configuration # so that to make the application work + # shellcheck disable=SC2154 if [ -n "${var_func_post_install}" ]; then ${var_func_post_install} else @@ -335,15 +356,17 @@ func_loop_apps_for_times(){ fi # start activity - timeout 1m adb shell am start -W -S ${loop_app_start_activity} + timeout 1m adb shell am start -W -S "${loop_app_start_activity}" # run test steps after started the activity + # shellcheck disable=SC2154 if [ -n "${var_func_run_test}" ]; then ${var_func_run_test} else func_run_test fi + # shellcheck disable=SC2154 if [ -n "${var_func_pre_uninstall}" ]; then ${var_func_pre_uninstall} else @@ -353,6 +376,7 @@ func_loop_apps_for_times(){ # uninstall or kill the app process func_kill_uninstall "${loop_app_apk}" "${loop_app_package}" + # shellcheck disable=SC2154 if [ -n "${var_func_post_uninstall}" ]; then ${var_func_post_uninstall} else @@ -367,7 +391,8 @@ func_loop_apps_for_times(){ func_get_all_apks(){ local loop_apps_list=$1 && shift for apk in ${loop_apps_list}; do - local app_apk=$(echo $apk|cut -d, -f1) + local app_apk + app_apk=$(echo "${apk}" | cut -d, -f1) app_apk=$(echo "$app_apk"|sed 's/\s*$//' |sed 's/^\s*//') if [ -z "${app_apk}" ]; then echo "Either the apk file name or NULL must be specified for one application" @@ -387,7 +412,7 @@ func_prepare_environment(){ ANDROID_SERIAL=$SERIAL export ANDROID_SERIAL else - serial=`adb get-serialno|sed 's/\r//g'` + serial=$(adb get-serialno | sed 's/\r//g') if [ "X${serial}" == "Xunknown" ]; then echo "Can not get the serial number autotically," echo "Please specify the serial number with the -s option" @@ -398,9 +423,9 @@ func_prepare_environment(){ fi export G_RECORD_LOCAL_CSV G_VERBOSE_OUTPUT - rm -fr ${D_RAWDATA} + rm -fr "${D_RAWDATA}" mkdir -p "${D_STREAMLINE}" "${D_SCREENSHOT}" "${D_APKS}" - mkdir -p $(dirname ${F_RAW_DATA_CSV}) + mkdir -p "$(dirname "${F_RAW_DATA_CSV}")" func_get_all_apks "$G_APPS"|| exit 1 @@ -410,13 +435,13 @@ func_prepare_environment(){ } func_print_usage_common(){ - echo "$(basename $0) --base-url BASE_URL [--serial serial_no] [--loop-count LOOP_COUNT] [--streamline true|false] APP_CONFIG_LIST ..." + echo "$(basename "$0") --base-url BASE_URL [--serial serial_no] [--loop-count LOOP_COUNT] [--streamline true|false] APP_CONFIG_LIST ..." echo " --serial: specify serial number for the device" echo " --base-url: specify the based url where the apks will be gotten from" echo " --loop-count: specify the number that how many times should be run for each application to get the average result, default is 12" echo " --record-csv: specify if record the result in csv format file." echo " Only record the file when TRUE is specified. Default is TRUE" - echo " --verbose-output: output the result and lava-test-case command for each test case each time it is run. Default is FALSE." + echo " --verbose-output: output the result for each test case each time it is run. Default is FALSE." echo " --record-statistics: output the statistics data as the test result. default is TRUE" echo " --streamline: specify if we need to collect the streamline data, true amd false can be specified, default is fasle" echo " APP_CONFIG_LIST: specify the configurations for each application as following format:" @@ -556,6 +581,7 @@ func_parse_parameters_common(){ ## var_func_prepare_environment ## var_func_post_test common_main(){ + # shellcheck disable=SC2154 if [ -n "${var_func_parse_parameters}" ]; then ${var_func_parse_parameters} "$@" if [ $? -ne 0 ]; then @@ -569,6 +595,7 @@ common_main(){ func_parse_parameters_common "$@" fi + # shellcheck disable=SC2154 if [ -n "${var_func_prepare_environment}" ]; then "${var_func_prepare_environment}" if [ $? -ne 0 ]; then @@ -581,6 +608,7 @@ common_main(){ func_loop_apps_for_times "${G_APPS}" "${G_LOOP_COUNT}" + # shellcheck disable=SC2154 if [ -n "${var_func_post_test}" ]; then "${var_func_post_test}" if [ $? -ne 0 ]; then @@ -592,22 +620,26 @@ common_main(){ if [ "X${G_RECORD_LOCAL_CSV}" = "XTRUE" ]; then if [ -f "${F_RAW_DATA_CSV}" ]; then - LC_ALL=C sort ${F_RAW_DATA_CSV}|tr ' ' '_'|tr -d '=' >${F_RAW_DATA_CSV}.sort - statistic ${F_RAW_DATA_CSV}.sort 2 3|tee ${F_STATISTIC_DATA_CSV} + LC_ALL=C sort "${F_RAW_DATA_CSV}" | tr ' ' '_' | tr -d '=' > "${F_RAW_DATA_CSV}".sort + statistic "${F_RAW_DATA_CSV}".sort 2 3 | tee "${F_STATISTIC_DATA_CSV}" sed -i 's/=/,/' "${F_STATISTIC_DATA_CSV}" - rm -f ${F_RAW_DATA_CSV}.sort + rm -f "${F_RAW_DATA_CSV}".sort if [ "X${G_RECORD_STATISTICS}" = "XTRUE" ] ;then G_RECORD_STATISTICS="FALSE" G_RECORD_LOCAL_CSV="FALSE" local old_record_local_csv="${G_RECORD_LOCAL_CSV}" + # shellcheck disable=SC2013 for line in $(cat "${F_STATISTIC_DATA_CSV}"); do if ! echo "$line"|grep -q ,; then continue fi - local key=$(echo $line|cut -d, -f1) - local measurement=$(echo $line|cut -d, -f2) - local units=$(echo $line|cut -d, -f3) + local key + key=$(echo "${line}" | cut -d, -f1) + local measurement + measurement=$(echo "${line}" | cut -d, -f2) + local units + units=$(echo "${line}" | cut -d, -f3) output_test_result "${key}" "pass" "${measurement}" "${units}" done G_RECORD_STATISTICS=TRUE @@ -616,19 +648,21 @@ common_main(){ fi rm -fr "${F_RAWDAT_ZIP}" - local old_pwd=$(pwd) - local d_zip_dir="$(dirname ${D_RAWDATA})" - local d_zip_name="$(basename ${D_RAWDATA})" - cd ${d_zip_dir}; + local old_pwd + old_pwd=$(pwd) + local d_zip_dir + d_zip_dir=$(dirname "${D_RAWDATA}") + local d_zip_name + d_zip_name=$(basename "${D_RAWDATA}") + cd "${d_zip_dir}" || exit zip -r "${F_RAWDAT_ZIP}" "${d_zip_name}" - cd ${old_pwd} + cd "${old_pwd}" || exit echo "Please reference the file ${F_RAWDAT_ZIP} for all the raw data." - attach_for_lava "${F_RAWDAT_ZIP}" "application/x-gzip" fi } ## Description: -## output the test result to console and add for lava-test-shell, +## output the test result to console and save them to result.txt, ## also write into one csv file for comparing manually ## Usage: ## output_test_result $test_name $result [ $measurement [ $units ] ] @@ -638,8 +672,6 @@ common_main(){ ## rawdata/final_result.csv ## G_VERBOSE_OUTPUT: when this environment variant is set to "TRUE", and only it is TRUE, ## the verbose informain about the result will be outputed -## G_RECORD_STATISTICS: only when this environment variant is set to "FALSE", -## lava-test-case will be executed to report the result to LAVA for each raw data. output_test_result(){ local test_name=$1 local result=$2 @@ -650,9 +682,8 @@ output_test_result(){ return fi local output="" - local lava_paras="" local output_csv="" - test_name=$(echo ${test_name}|tr ' ,' '_') + test_name=$(echo "${test_name}" | tr ' ,' '_') if [ -z "$units" ]; then units="points" @@ -660,53 +691,23 @@ output_test_result(){ units=$(echo ${units}|tr ' ,' '_') if [ -z "${measurement}" ]; then - output="${test_name}=${result}" - lava_paras="${test_name} --result ${result}" + output="${test_name} ${result}" else - output="${test_name}=${measurement} ${units}" - lava_paras="${test_name} --result ${result} --measurement ${measurement} --units ${units}" - ## should support units after measurement format + output="${test_name} ${result} ${measurement} ${units}" output_csv="${test_name},${measurement},${units}" fi - if [ "X${G_VERBOSE_OUTPUT}" = "XTRUE" ];then - echo "${output}" + if [ "X${G_RECORD_STATISTICS}" = "XFALSE" ]; then + echo "${output}" >> "${RESULT_FILE}" fi - local cmd="lava-test-case" - if [ "X${G_RECORD_STATISTICS}" = "XFALSE" ] && [ -n "$(which $cmd)" ];then - $cmd ${lava_paras} - elif [ "X${G_VERBOSE_OUTPUT}" = "XTRUE" ];then - echo "$cmd ${lava_paras}" + if [ "X${G_VERBOSE_OUTPUT}" = "XTRUE" ];then + echo "${output}" fi if [ "X${G_RECORD_LOCAL_CSV}" = "XTRUE" ]; then if [ -n "${output_csv}" ];then - echo "${output_csv}">>${F_RAW_DATA_CSV} + echo "${output_csv}" >> "${F_RAW_DATA_CSV}" fi fi } - -## Description: -## run lava-test-run-attach to attach the file for lava -## Usage: -## attach_for_lava "${f_path}" "$f_mime_type" -## Example: -## attach_for_lava logcat.log text/plain -## attach_for_lava rawdata.zip application/x-gzip -attach_for_lava(){ - local f_path=$1 - local f_mime_type=$2 - - if [ ! -f "${f_path}" ]; then - return - fi - if [ -z "${f_mime_type}" ]; then - f_mime_type="text/plain" - fi - local cmd="lava-test-run-attach" - - if [ -n "$(which $cmd)" ];then - ${cmd} ${f_path} ${f_mime_type} - fi -} diff --git a/common/output-test-result.sh b/common/output-test-result.sh index 517273d..3bb3366 100755 --- a/common/output-test-result.sh +++ b/common/output-test-result.sh @@ -1,7 +1,9 @@ #!/bin/bash local_common_file_path="$0" -local_common_parent_dir=$(cd $(dirname ${local_common_file_path}); pwd) +# shellcheck disable=SC2164 +local_common_parent_dir=$(cd "$(dirname "${local_common_file_path}")"; pwd) +# shellcheck disable=SC1090 source "${local_common_parent_dir}/common2.sh" output_test_result "$@" diff --git a/common/statistic_average.sh b/common/statistic_average.sh index f5bdbfb..4ccef13 100644..100755 --- a/common/statistic_average.sh +++ b/common/statistic_average.sh @@ -9,14 +9,15 @@ f_max(){ local val1=$1 local val2=$2 - [ -z "$val1" ] && echo $val2 - [ -z "$val2" ] && echo $val1 + [ -z "$val1" ] && echo "$val2" + [ -z "$val2" ] && echo "$val1" - local compare=$(echo "$val1>$val2"|bc) + local compare + compare=$(echo "$val1>$val2"|bc) if [ "X$compare" = "X1" ];then - echo $val1 + echo "$val1" else - echo $val2 + echo "$val2" fi } @@ -29,14 +30,15 @@ f_max(){ f_min(){ local val1=$1 local val2=$2 - [ -z "$val1" ] && echo $val1 - [ -z "$val2" ] && echo $val2 + [ -z "$val1" ] && echo "$val1" + [ -z "$val2" ] && echo "$val2" - local compare=$(echo "$val1<$val2"|bc) + local compare + compare=$(echo "$val1<$val2"|bc) if [ "X$compare" = "X1" ];then - echo $val1 + echo "$val1" else - echo $val2 + echo "$val2" fi } @@ -59,8 +61,10 @@ standard_deviation_error(){ deviations_sum=$(echo "${deviations_sum},${s_deviation}"|awk -F, '{printf "%.2f",$1+$2;}') count=$(echo "${count},1"|awk -F, '{printf $1+$2;}') done - local deviation=$(echo "${deviations_sum},${count}"|awk -F, '{printf "%.2f",sqrt($1/$2);}') - local std_err=$(echo "${deviation},${count}"|awk -F, '{printf "%.2f",$1/sqrt($2);}') + local deviation + deviation=$(echo "${deviations_sum},${count}"|awk -F, '{printf "%.2f",sqrt($1/$2);}') + local std_err + std_err=$(echo "${deviation},${count}"|awk -F, '{printf "%.2f",$1/sqrt($2);}') echo "${deviation},${std_err}" } ## Description: @@ -92,22 +96,27 @@ statistic(){ local new_key="" local count=0 local values="" + # shellcheck disable=SC2013 for line in $(cat "${f_data}"); do if ! echo "$line"|grep -q ,; then continue fi - new_key=$(echo $line|cut -d, -f1) - value=$(echo $line|cut -d, -f${field_no}) + new_key=$(echo "${line}" | cut -d, -f1) + value=$(echo "${line}" | cut -d, -f${field_no}) if [ "X${new_key}" = "X${old_key}" ]; then - total=$(echo ${total},${value}|awk -F, '{printf "%.2f",$1+$2;}') + total=$(echo "${total},${value}" | awk -F, '{printf "%.2f",$1+$2;}') values="${values} ${value}" count=$(echo "$count + 1"|bc) else if [ "X${old_key}" != "X" ]; then - local average=$(echo ${total},${count}|awk -F, '{printf "%.2f",$1/$2;}') - local sigma_stderr=$(standard_deviation_error "${average}" "${values}") - local sigma=$(echo ${sigma_stderr}|cut -d, -f1) - local std_err=$(echo ${sigma_stderr}|cut -d, -f2) + local average + average=$(echo "${total},${count}" | awk -F, '{printf "%.2f",$1/$2;}') + local sigma_stderr + sigma_stderr=$(standard_deviation_error "${average}" "${values}") + local sigma + sigma=$(echo "${sigma_stderr}" | cut -d, -f1) + local std_err + std_err=$(echo "${sigma_stderr}" | cut -d, -f2) if [ -z "${units}" ]; then echo "${old_key}=${average}" echo "${old_key}_sigma=${sigma}" @@ -123,15 +132,19 @@ statistic(){ old_key="${new_key}" count=1 if [ -n "${units_field_no}" ]; then - units=$(echo $line|cut -d, -f${units_field_no}) + units=$(echo "${line}" | cut -d, -f"${units_field_no}") fi fi done if [ "X${new_key}" != "X" ]; then - local average=$(echo ${total},${count}|awk -F, '{printf "%.2f",$1/$2;}') - local sigma_stderr=$(standard_deviation_error "${average}" "${values}") - local sigma=$(echo ${sigma_stderr}|cut -d, -f1) - local std_err=$(echo ${sigma_stderr}|cut -d, -f2) + local average + average=$(echo "${total},${count}" | awk -F, '{printf "%.2f",$1/$2;}') + local sigma_stderr + sigma_stderr=$(standard_deviation_error "${average}" "${values}") + local sigma + sigma=$(echo "${sigma_stderr}" | cut -d, -f1) + local std_err + std_err=$(echo "${sigma_stderr}" | cut -d, -f2) if [ -z "${units}" ]; then echo "${old_key}=${average}" echo "${old_key}_sigma=${sigma}" diff --git a/lava-android-benchmark-host.yaml b/lava-android-benchmark-host.yaml deleted file mode 100644 index b342826..0000000 --- a/lava-android-benchmark-host.yaml +++ /dev/null @@ -1,48 +0,0 @@ -metadata: - name: lava-android-benchmark-host - format: "Lava-Test-Shell Test Definition 1.0" - description: "Multinode host part for android benchmarking" - maintainer: - - milosz.wasilewski@linaro.org - os: - - android - scope: - - performance - devices: - - kvm - -install: - git-repos: - - https://github.com/mwasilew/AndroidViewClient.git - steps: - - cd AndroidViewClient/ - - python setup.py install - deps: - - git - - zip - - python-lxml - - python-pil - - python-setuptools - - android-tools-adb - - android-tools-fastboot - -params: - TEST_NAME: "geekbench" - APP_CONFIG_LIST: "" - LOOP_COUNT: 13 - COLLECT_STREAMLINE: "false" - RECORD_CSV: "TRUE" - RECORD_STATISTICS: "TRUE" - VERBOSE_OUTPUT: "FALSE" - -run: - steps: - - apt-get update -y - - apt-get install -y adb bc - - lava-wait $TEST_NAME-send-ip - - IPADDR=`awk -F '=' '{print $2}' /tmp/lava_multi_node_cache.txt` - - "./adb_connect_device.sh $IPADDR" - - adb -s $IPADDR wait-for-device - - adb -s $IPADDR shell id - - ./$TEST_NAME/execute.sh --serial $IPADDR --loop-count "$LOOP_COUNT" --streamline "$COLLECT_STREAMLINE" --verbose-output $VERBOSE_OUTPUT --record-statistics $RECORD_STATISTICS --record-csv $RECORD_CSV - - lava-sync $TEST_NAME-finished diff --git a/lava-android-benchmark-target.yaml b/lava-android-benchmark-target.yaml deleted file mode 100644 index ee542ee..0000000 --- a/lava-android-benchmark-target.yaml +++ /dev/null @@ -1,36 +0,0 @@ -metadata: - name: lava-android-benchmark-target - format: "Lava-Test-Shell Test Definition 1.0" - description: "Multinode target part for android benchmarking" - maintainer: - - milosz.wasilewski@linaro.org - os: - - android - scope: - - benchmark - devices: - - panda - - panda-es - - vexpress-a9 - - vexpress-tc2 - - juno - -params: - TEST_NAME: "geekbench" - -run: - steps: - - lava-test-case step1-cat-build-info --shell cat /system/build.prop - - lava-test-case step2-get-adb --shell getprop service.adb.tcp.port - - lava-test-case step3-set-adb --shell setprop service.adb.tcp.port 5555 - - lava-test-case step4-set-adb-root --shell setprop service.adb.root 1 - - lava-test-case step5-capture-kmsg-levels --shell 'cat /proc/sys/kernel/printk > /data/local/tmp/kmsg_levels' - - lava-test-case step6-disable-kmsg --shell echo '1 1 1 1' > /proc/sys/kernel/printk - - lava-test-case step7-stop-adbd --shell stop adbd - - lava-test-case step8-start-adbd --shell start adbd - - sleep 10 - - IPADDR=$(getprop dhcp.eth0.ipaddress) - - if [ -z $IPADDR ]; then netcfg eth0 up; netcfg eth0 dhcp; IPADDR=$(getprop dhcp.eth0.ipaddress); fi - - lava-test-case step6-send-ip --shell lava-send $TEST_NAME-send-ip ipaddr=$IPADDR - - lava-test-case step7-enable-kmsg --shell 'cat /data/local/tmp/kmsg_levels > /proc/sys/kernel/printk' - - lava-test-case step8-multinode-sync --shell lava-sync $TEST_NAME-finished diff --git a/lib/android-test-lib b/lib/android-test-lib new file mode 100755 index 0000000..8677fea --- /dev/null +++ b/lib/android-test-lib @@ -0,0 +1,143 @@ +#!/bin/sh + +install_latest_adb() { + install_deps "wget zip" + wget -S --progress=dot:giga https://dl.google.com/android/repository/platform-tools-latest-linux.zip + unzip -q platform-tools-latest-linux.zip + export PATH=$PWD/platform-tools:$PATH + which adb + adb version +} + +initialize_adb() { + which lava-lxc-device-add && lava-lxc-device-add + adb start-server + adb wait-for-device + adb devices + + if [ -z "${SN}" ]; then + number="$(adb devices | grep -wc 'device')" + if [ "${number}" -gt 1 ]; then + warn_msg "Device not specified; define SN or use '-s'" + error_msg "More than one device or emulator found" + elif [ "${number}" -eq 1 ]; then + SN="$(adb get-serialno)" + export SN + else + error_msg "Device NOT found" + fi + fi + + if adb -s "${SN}" shell echo "Testing adb connectivity"; then + info_msg "Connected to device ${SN} successfully" + else + error_msg "Unable to connect to device ${SN}" + fi +} + +adb_root() { + adb root & + sleep 10 + which lava-lxc-device-add && lava-lxc-device-add + adb wait-for-device + adb devices +} + +wait_boot_completed() { + [ "$#" -ne 1 ] && error_msg "Usage: wait_for_boot_completed timeout_in_seconds" + timeout="$1" + end=$(( $(date +%s) + timeout )) + + boot_completed=false + while [ "$(date +%s)" -lt "$end" ]; do + if adb -s "${SN}" shell getprop sys.boot_completed | grep "1"; then + boot_completed=true + break + else + sleep 3 + fi + done + + if "${boot_completed}"; then + info_msg "Target booted up completely." + else + error_msg "wait_boot_completed timed out after ${timeout} seconds" + fi +} + +wait_homescreen() { + [ "$#" -ne 1 ] && error_msg "Usage: wait_homescreen timeout_in_seconds" + timeout="$1" + end=$(( $(date +%s) + timeout )) + + homescreen_displayed=false + while [ "$(date +%s)" -lt "$end" ]; do + if adb -s "${SN}" logcat -sd ActivityManager:I | grep "Displayed com.android.launcher"; then + homescreen_displayed=true + break + else + sleep 3 + fi + done + + if "${homescreen_displayed}"; then + info_msg "Target booted to homescreen successfully." + else + error_msg "wait_homescreen timed out after ${timeout} seconds" + fi +} + +detect_abi() { + # "| tr -d '\r'" is needed here, refer to the below issue. + # https://code.google.com/p/android/issues/detail?id=2482 + abi="$(adb -s "${SN}" shell uname -m | tr -d '\r')" + case $abi in + armv7|armv7l|armv7el|armv7lh) abi="armeabi" ;; + arm64|armv8|arm64-v8a|aarch64) abi="arm64" ;; + *) error_msg "Unknown architecture" ;; + esac + info_msg "ABI: ${abi}" +} + +# install() push binary or script file to '/system/bin' so that you can run it +# without absolute/relative path. If '/system' is always read-only(like LCR), +# please use adb_push() instead to push binary or file to somewhere that 'rw' +# permission granted, like '/data/local/tmp', and run it from there. +install() { + [ "$#" -ne 1 ] && error_msg "Usage: install <file_path>" + file_path="$1" + file_name="$(basename "${file_path}")" + + if adb -s "${SN}" shell mount | grep system | grep -q ro; then + # Remounts the /system partition on the device read-write + info_msg "/system partition is read-only, remounting it read-write..." + # Because of https://bugs.linaro.org/show_bug.cgi?id=2888, this + # function wouldn't work in LAVA v2 LXC until the bug get addressed. + adb root + adb -s "${SN}" remount + fi + + info_msg "Installing ${file_name}" + adb -s "${SN}" push "${file_path}" "/system/bin/" + adb -s "${SN}" shell chmod 755 "/system/bin/${file_name}" +} + +adb_push() { + [ "$#" -ne 2 ] && error_msg "Usage: adb_push <local> <remote>" + local="$1" + remote="$2" + + adb -s "${SN}" shell mkdir -p "${remote}" + info_msg "Pushing ${local} to devcie ${SN}" + adb -s "${SN}" push "${local}" "${remote}" + adb -s "${SN}" shell chmod -R 755 "${remote}" +} + +adb_pull() { + [ "$#" -ne 2 ] && error_msg "Usage: adb_pull <remote> <local>" + remote="$1" + local="$2" + + info_msg "Pulling ${remote} from devcie ${SN}" + adb -s "${SN}" pull "${remote}" "${local}" +} diff --git a/lib/sh-test-lib b/lib/sh-test-lib new file mode 100755 index 0000000..299964d --- /dev/null +++ b/lib/sh-test-lib @@ -0,0 +1,337 @@ +#!/bin/sh + +LANG=C +export LANG + +error_msg() { + msg="$1" + [ -z "${msg}" ] && msg="Unknown error" + printf "ERROR: %s\n" "${msg}" >&2 + exit 1 +} + +warn_msg() { + msg="$1" + [ -z "${msg}" ] && msg="Unknown error" + printf "WARNING: %s\n" "${msg}" >&2 +} + +info_msg() { + msg="$1" + [ -z "${msg}" ] && msg="Unknown info" + printf "INFO: %s\n" "${msg}" >&1 +} + +check_root() { + if [ "$(id -ru)" -eq 0 ]; then + return 0 + else + return 1 + fi +} + +exit_on_fail() { + exit_code="$?" + [ "$#" -lt 1 ] && error_msg "Usage: exit_on_fail test_case [skip_list]" + test_case="$1" + skip_list="$2" + + if [ "${exit_code}" -ne 0 ]; then + echo "${test_case} fail" | tee -a "${RESULT_FILE}" + + # skip_list is a list of tests sepereated by space. This might be + # useful when exiting on prerequisite not met. + if [ -n "${skip_list}" ]; then + for i in ${skip_list}; do + echo "$i skip" | tee -a "${RESULT_FILE}" + done + fi + + # Exit normally to continue to run the following steps defined in test + # definition file. + exit 0 + else + echo "${test_case} pass" | tee -a "${RESULT_FILE}" + return 0 + fi +} + +exit_on_skip() { + exit_code="$?" + [ "$#" -lt 1 ] && error_msg "Usage: exit_on_skip test_case [msg]" + test_case="$1" + msg="$2" + + if [ "${exit_code}" -ne 0 ]; then + echo "${test_case} skip" | tee -a "${RESULT_FILE}" + + if [ -n "${msg}" ]; then + warn_msg "${msg}" + fi + + # Exit normally to continue to run the following steps defined in test + # definition file. + exit 0 + else + echo "${test_case} pass" | tee -a "${RESULT_FILE}" + return 0 + fi +} + +check_return() { + exit_code="$?" + [ "$#" -ne 1 ] && error_msg "Usage: check_return test_case" + test_case="$1" + + if [ "${exit_code}" -ne 0 ]; then + echo "${test_case} fail" | tee -a "${RESULT_FILE}" + return "${exit_code}" + else + echo "${test_case} pass" | tee -a "${RESULT_FILE}" + return 0 + fi +} + +# When shell argument "-e" set in test script, check_return and exit_on_fail +# would NOT work. run_test_case should be used instead. +run_test_case() { + [ "$#" -lt 2 ] && error_msg "Usage: run_test_case <test_command> <test_case_id> [skip_list]" + test_command="$1" + test_case_id="$2" + skip_list="$3" + + if eval "${test_command}"; then + echo "${test_case_id} pass" | tee -a "${RESULT_FILE}" + else + echo "${test_case_id} fail" | tee -a "${RESULT_FILE}" + # When skip_list isn't empty, skip the tests and exit. + if [ -n "${skip_list}" ]; then + for i in ${skip_list}; do + echo "$i skip" | tee -a "${RESULT_FILE}" + done + exit 0 + fi + fi + + return 0 +} + +report_pass() { + [ "$#" -ne 1 ] && error_msg "Usage: report_pass test_case" + test_case="$1" + echo "${test_case} pass" | tee -a "${RESULT_FILE}" +} + +report_fail() { + [ "$#" -ne 1 ] && error_msg "Usage: report_fail test_case" + test_case="$1" + echo "${test_case} fail" | tee -a "${RESULT_FILE}" +} + +add_metric() { + if [ "$#" -lt 3 ]; then + warn_msg "The number of parameters less then 3" + error_msg "Usage: add_metric test_case result measurement [units]" + fi + test_case="$1" + result="$2" + measurement="$3" + units="$4" + + echo "${test_case} ${result} ${measurement} ${units}" | tee -a "${RESULT_FILE}" +} + +detect_abi() { + abi=$(uname -m) + case "${abi}" in + armv7|armv7l|armv7el|armv7lh) abi="armeabi" ;; + arm64|armv8|arm64-v8a|aarch64) abi="arm64" ;; + *) error_msg "Unknown architecture: ${abi}" ;; + esac +} + +dist_name() { + if [ -f /etc/os-release ]; then + # shellcheck disable=SC1091 + dist=$(. /etc/os-release && echo "${ID}") + elif [ -x /usr/bin/lsb_release ]; then + dist="$(lsb_release -si)" + elif [ -f /etc/lsb-release ]; then + # shellcheck disable=SC1091 + dist="$(. /etc/lsb-release && echo "${DISTRIB_ID}")" + elif [ -f /etc/debian_version ]; then + dist="debian" + elif [ -f /etc/fedora-release ]; then + dist="fedora" + elif [ -f /etc/centos-release ]; then + dist="centos" + else + dist="unknown" + warn_msg "Unsupported distro: cannot determine distribution name" + fi + + # convert dist to lower case + dist=$(echo ${dist} | tr '[:upper:]' '[:lower:]') + case "${dist}" in + rpb*) dist="oe-rpb" ;; + esac +} + +install_deps() { + pkgs="$1" + [ -z "${pkgs}" ] && error_msg "Usage: install_deps pkgs" + # skip_install parmater is optional. + skip_install="$2" + + if [ "${skip_install}" = "True" ] || [ "${skip_install}" = "true" ]; then + info_msg "install_deps skipped" + else + ! check_root && \ + error_msg "About to install packages, please run this script as root." + info_msg "Installing ${pkgs}" + dist_name + case "${dist}" in + debian|ubuntu) + # Use the default answers for all questions. + DEBIAN_FRONTEND=noninteractive apt-get update -q -y + # shellcheck disable=SC2086 + DEBIAN_FRONTEND=noninteractive apt-get install -q -y ${pkgs} + ;; + centos) + # shellcheck disable=SC2086 + yum -e 0 -y install ${pkgs} + ;; + fedora) + # shellcheck disable=SC2086 + dnf -e 0 -y install ${pkgs} + ;; + *) + warn_msg "Unsupported distro: ${dist}! Package installation skipped." + ;; + esac + fi +} + +# Return the exit code of the first command when using pipe. +pipe0_status() { + [ "$#" -ne 2 ] && error_msg "Usage: pipe0_status cmd1 cmd2" + cmd1="$1" + cmd2="$2" + + exec 4>&1 + ret_val=$({ { eval "${cmd1}" 3>&-; echo "$?" 1>&3; } 4>&- \ + | eval "${cmd2}" 1>&4; } 3>&1) + exec 4>&- + + return "${ret_val}" +} + +validate_check_sum() { + if [ "$#" -ne 2 ]; then + warn_msg "The number of parameters should be 2" + error_msg "Usage: validate_check_sum filename known_sha256sum" + return 1 + fi + OUTPUT_FILE_NAME="$1" + SHA256SUM_CHECK="$2" + # Get sha256sum of output_file + GET_SHA256SUM=$(sha256sum "${OUTPUT_FILE_NAME}" | awk '{print $1}') + echo "GET_SHA256SUM is ${GET_SHA256SUM}" + if [ "${SHA256SUM_CHECK}" = "${GET_SHA256SUM}" ] ; then + return 0 + else + echo "checksum did not match" + return 1 + fi +} + +convert_to_mb() { + [ "$#" -ne 2 ] && error_msg "Usage: convert_to_mb value units" + if ! echo "$1" | egrep -q "^[0-9.]+$"; then + error_msg "The first argument isn't a number" + fi + value="$1" + units="$2" + + case "${units}" in + KB|kb) value=$(echo "${value}" | awk '{print $1/1024}') ;; + MB|mb) ;; + GB|gb) value=$(echo "${value}" | awk '{print $1*1024}') ;; + TB|tb) value=$(echo "${value}" | awk '{print $1*1024*1024}') ;; + *) error_msg "Unsupported units" ;; + esac + + echo "${value}" +} + +dist_info() { + if ! command -v lsb_release > /dev/null; then + dist_name + case "${dist}" in + debian|ubuntu) install_deps "lsb-release" ;; + centos|fedora) install_deps "redhat-lsb-core" ;; + *) warn_msg "Unsupported distro: dist_info skipped" + esac + fi + + # shellcheck disable=SC2034 + Release=$(lsb_release -r | awk '{print $2}') + Codename=$(lsb_release -c | awk '{print $2}') +} + +add_key() { + [ "$#" -ne 1 ] && error_msg "Usage: add_key url" + url="$1" + + ! check_root && \ + error_msg "About to use apt-key, please run this script as root." + dist_name + case "${dist}" in + debian|ubuntu) wget -O - "${url}" | apt-key add - ;; + centos|fedora) infor_msg "add_key isn't needed on ${dist}" ;; + *) warn_msg "Unsupported distro: add_key skipped" + esac +} + +add_repo() { + [ "$#" -lt 1 ] && error_msg "Usage: add_repo <url> [backports]" + url="$1" + + ! check_root && \ + error_msg "About to add a repo, please run this script as root." + dist_name + case "${dist}" in + # Detect Debian/Ubuntu codename and add repo automatically. The same url + # should work on all distributions supported by the repo. + debian|ubuntu) + dist_info + if [ -z "$2" ]; then + backports="" + elif [ "$2" = "backports" ]; then + backports="-backports" + else + echo "Usage: add_repo <url> [backports]" + error_msg "$2 is not a supported argument, should be 'backports'" + fi + echo "deb ${url} ${Codename}${backports} main" \ + >> "/etc/apt/sources.list.d/3rd-party-repo.list" + ;; + # It is not easy to amend url with distro version as its format may vary + # by repo. Test definition/plan should provide a correct repo url. + centos|fedora) + wget -O - "${url}" >> "/etc/yum.repos.d/3rd-party.repo" + ;; + *) + warn_msg "Unsupported distro: ${dist}! add_repo skipped" + ;; + esac +} + +create_out_dir() { + [ -z "$1" ] && error_msg "Usage: create_out_dir output_dir" + OUTPUT=$1 + [ -d "${OUTPUT}" ] && + mv "${OUTPUT}" "${OUTPUT}_$(date -r "${OUTPUT}" +%Y%m%d%H%M%S)" + mkdir -p "${OUTPUT}" + [ -d "${OUTPUT}" ] || error_msg "Could not create output directory ${OUTPUT}" +} |