From 6ee3e9d1f293c2d51736b8ba053e66bd873ad232 Mon Sep 17 00:00:00 2001 From: Chase Qi Date: Wed, 22 Mar 2017 13:38:34 +0800 Subject: automated: android: set and use environmental variable ANDROID_SERIAL When ANDROID_SERIAL set, we don't need to use '-s' to specify device serial no. any more. Change-Id: Ide4951c6ab68806a6241b38c3bf001e2e4e15eab Signed-off-by: Chase Qi --- .../android/bionic-benchmarks/bionic-benchmarks.sh | 4 +- .../android/bionic-libc-tests/bionic-libc-tests.sh | 4 +- automated/android/busybox/busybox.sh | 2 +- automated/android/cts/cts-runner.py | 6 +-- automated/android/cts/cts.sh | 5 ++- automated/android/cts/cts.yaml | 6 +-- automated/android/dd-wr-speed/dd-wr-speed.sh | 10 ++--- automated/android/dd-wr-speed/dd-wr-speed.yaml | 4 +- .../linaro-android-kernel-tests.sh | 4 +- automated/lib/android-test-lib | 44 +++++++++++----------- 10 files changed, 43 insertions(+), 46 deletions(-) (limited to 'automated') diff --git a/automated/android/bionic-benchmarks/bionic-benchmarks.sh b/automated/android/bionic-benchmarks/bionic-benchmarks.sh index ae6a618..babe3df 100755 --- a/automated/android/bionic-benchmarks/bionic-benchmarks.sh +++ b/automated/android/bionic-benchmarks/bionic-benchmarks.sh @@ -66,8 +66,8 @@ initialize_adb wait_boot_completed "${TIMEOUT}" adb_push "./device-script.sh" "/data/local/tmp/" -info_msg "About to run bionic-benchmarks on device ${SN}" -adb -s "${SN}" shell /data/local/tmp/device-script.sh "${LOOPS}" 2>&1 \ +info_msg "About to run bionic-benchmarks on device ${ANDROID_SERIAL}" +adb shell /data/local/tmp/device-script.sh "${LOOPS}" 2>&1 \ | tee "${HOST_OUTPUT}"/device-run.log adb_pull "${DEVICE_OUTPUT}" "${HOST_OUTPUT}" diff --git a/automated/android/bionic-libc-tests/bionic-libc-tests.sh b/automated/android/bionic-libc-tests/bionic-libc-tests.sh index 55c7762..f2f2565 100755 --- a/automated/android/bionic-libc-tests/bionic-libc-tests.sh +++ b/automated/android/bionic-libc-tests/bionic-libc-tests.sh @@ -25,8 +25,8 @@ initialize_adb wait_boot_completed "${TIMEOUT}" adb_push "./device-script.sh" "/data/local/tmp/" -info_msg "About to run bionic-libc-tests on device ${SN}" -adb -s "${SN}" shell /data/local/tmp/device-script.sh 2>&1 \ +info_msg "About to run bionic-libc-tests on device ${ANDROID_SERIAL}" +adb shell /data/local/tmp/device-script.sh 2>&1 \ | tee "${HOST_OUTPUT}"/device-run.log adb_pull "${DEVICE_OUTPUT}" "${HOST_OUTPUT}" diff --git a/automated/android/busybox/busybox.sh b/automated/android/busybox/busybox.sh index 30141da..b36600a 100755 --- a/automated/android/busybox/busybox.sh +++ b/automated/android/busybox/busybox.sh @@ -14,7 +14,7 @@ create_out_dir "${OUTPUT}" adb_push "./device-script.sh" "/data/local/tmp/bin/" -adb -s "${SN}" shell '/data/local/tmp/bin/device-script.sh 2>&1' \ +adb shell '/data/local/tmp/bin/device-script.sh 2>&1' \ | tee "${OUTPUT}/device-stdout.log" adb_pull "/data/local/tmp/busybox/result.txt" "${OUTPUT}/" diff --git a/automated/android/cts/cts-runner.py b/automated/android/cts/cts-runner.py index 50589e3..b81b8ff 100755 --- a/automated/android/cts/cts-runner.py +++ b/automated/android/cts/cts-runner.py @@ -80,16 +80,12 @@ RESULT_FILE = '%s/result.txt' % OUTPUT CTS_STDOUT = '%s/cts-stdout.txt' % OUTPUT CTS_LOGCAT = '%s/cts-logcat.txt' % OUTPUT TEST_PARAMS = '' -SN = '' parser = argparse.ArgumentParser() parser.add_argument('-t', dest='TEST_PARAMS', required=True, help="cts test parameters") -parser.add_argument('-n', dest='SN', required=True, - help='Target device serial no.') args = parser.parse_args() TEST_PARAMS = args.TEST_PARAMS -SN = args.SN if os.path.exists(OUTPUT): suffix = datetime.datetime.now().strftime('%Y%m%d%H%M%S') @@ -127,7 +123,7 @@ while child.isalive(): subprocess.call('echo') subprocess.call(['echo', '--- line break ---']) logger.info('Checking adb connectivity...') - adb_command = "adb -s %s shell echo OK" % SN + adb_command = "adb shell echo OK" adb_check = subprocess.Popen(shlex.split(adb_command)) if adb_check.wait() != 0: subprocess.call(['adb', 'devices']) diff --git a/automated/android/cts/cts.sh b/automated/android/cts/cts.sh index 9f5bdc3..8e85d94 100755 --- a/automated/android/cts/cts.sh +++ b/automated/android/cts/cts.sh @@ -23,7 +23,7 @@ while getopts ':s:o:n:d:c:t:' opt; do case "${opt}" in s) SKIP_INSTALL="${OPTARG}" ;; o) TIMEOUT="${OPTARG}" ;; - n) SN="${OPTARG}" ;; + n) ANDROID_SERIAL="${OPTARG}" ;; d) JDK="${OPTARG}" ;; c) CTS_URL="${OPTARG}" ;; t) TEST_PARAMS="${OPTARG}" ;; @@ -80,7 +80,8 @@ if [ -d android-cts/results ]; then fi # Run CTS test. -./cts-runner.py -t "${TEST_PARAMS}" -n "${SN}" +info_msg "About to run dd speed test on device ${ANDROID_SERIAL}" +./cts-runner.py -t "${TEST_PARAMS}" # Cleanup. rm -f /etc/apt/sources.list.d/cts.list diff --git a/automated/android/cts/cts.yaml b/automated/android/cts/cts.yaml index 74e65cf..d12e149 100644 --- a/automated/android/cts/cts.yaml +++ b/automated/android/cts/cts.yaml @@ -17,8 +17,8 @@ params: SKIP_INSTALL: "false" # Specify timeout in seconds for wait_boot_completed and wait_homescreen. TIMEOUT: "300" - # Specify adb device SN if more then one device connected. - SN: "" + # Specify adb device serial no. if more then one device connected. + ANDROID_SERIAL: "" JDK: "openjdk-8-jdk-headless" # Download CTS package or copy it from local disk. # CTS_URL: "/root/android-cts/linaro/7.1_r1/android-cts-7.1_r1.zip" @@ -30,7 +30,7 @@ params: run: steps: - cd ./automated/android/cts - - ./cts.sh -s "${SKIP_INSTALL}" -o "${TIMEOUT}" -n "${SN}" -d "${JDK}" -c "${CTS_URL}" -t "${TEST_PARAMS}" + - ./cts.sh -s "${SKIP_INSTALL}" -o "${TIMEOUT}" -n "${ANDROID_SERIAL}" -d "${JDK}" -c "${CTS_URL}" -t "${TEST_PARAMS}" # Upload test log and result files to artifactorial. - cp -r ./android-cts/results ./output/ || true - cp -r ./android-cts/logs ./output/ || true diff --git a/automated/android/dd-wr-speed/dd-wr-speed.sh b/automated/android/dd-wr-speed/dd-wr-speed.sh index b094875..402a17e 100755 --- a/automated/android/dd-wr-speed/dd-wr-speed.sh +++ b/automated/android/dd-wr-speed/dd-wr-speed.sh @@ -3,7 +3,7 @@ HOST_OUTPUT="$(pwd)/output" LOCAL_DEVICE_OUTPUT="${HOST_OUTPUT}/device-output" DEVICE_OUTPUT="/data/local/tmp/dd-wr-speed" -SN="" +ANDROID_SERIAL="" BOOT_TIMEOUT="300" ITERATION="5" PARTITION="" @@ -11,7 +11,7 @@ RESULT_FILE="${HOST_OUTPUT}/result.txt" export RESULT_FILE usage() { - echo "Usage: $0 [-p ] [-i ] [-s ] [-t ]" 1>&2 + echo "Usage: $0 [-p ] [-i ] [-s ] [-t ]" 1>&2 exit 1 } @@ -24,7 +24,7 @@ while getopts ":p:i:s:t:" o; do # You may need to run dd test 4-5 times for an accurate evaluation. i) ITERATION="${OPTARG}" ;; # Specify device serial number when more than one device connected. - s) SN="${OPTARG}" ;; + s) ANDROID_SERIAL="${OPTARG}" ;; t) BOOT_TIMEOUT="${OPTARG}" ;; *) usage ;; esac @@ -91,8 +91,8 @@ detect_abi adb_push "../../bin/${abi}/busybox" "/data/local/tmp/bin/" adb_push "./device-script.sh" "/data/local/tmp/bin" -info_msg "About to run dd speed test on device ${SN}" -adb -s "${SN}" shell "echo /data/local/tmp/bin/device-script.sh ${ITERATION} ${DEVICE_OUTPUT} ${PARTITION} | su" 2>&1 | tee "${HOST_OUTPUT}/device-stdout.log" +info_msg "About to run dd speed test on device ${ANDROID_SERIAL}" +adb shell "echo /data/local/tmp/bin/device-script.sh ${ITERATION} ${DEVICE_OUTPUT} ${PARTITION} | su" 2>&1 | tee "${HOST_OUTPUT}/device-stdout.log" adb_pull "${DEVICE_OUTPUT}" "${LOCAL_DEVICE_OUTPUT}" diff --git a/automated/android/dd-wr-speed/dd-wr-speed.yaml b/automated/android/dd-wr-speed/dd-wr-speed.yaml index 3abddc2..fa4b5ee 100644 --- a/automated/android/dd-wr-speed/dd-wr-speed.yaml +++ b/automated/android/dd-wr-speed/dd-wr-speed.yaml @@ -23,12 +23,12 @@ params: ITERATION: "5" # Specify device serial number for adb connection if more than one device # connected. - SN: "" + ANDROID_SERIAL: "" # Specify timeout in seconds for wait_boot_completed BOOT_TIMEOUT: "300" run: steps: - cd ./automated/android/dd-wr-speed - - ./dd-wr-speed.sh -p "${PARTITION}" -i "${ITERATION}" -s "${SN}" -t "${BOOT_TIMEOUT}" + - ./dd-wr-speed.sh -p "${PARTITION}" -i "${ITERATION}" -s "${ANDROID_SERIAL}" -t "${BOOT_TIMEOUT}" - ../../utils/send-to-lava.sh ./output/result.txt diff --git a/automated/android/linaro-android-kernel-tests/linaro-android-kernel-tests.sh b/automated/android/linaro-android-kernel-tests/linaro-android-kernel-tests.sh index 5cb7a96..59fe540 100755 --- a/automated/android/linaro-android-kernel-tests/linaro-android-kernel-tests.sh +++ b/automated/android/linaro-android-kernel-tests/linaro-android-kernel-tests.sh @@ -16,8 +16,8 @@ wait_boot_completed "300" create_out_dir "${OUTPUT}" # Run test script. -if test -n "$(adb -s "${SN}" shell "which ${TEST_SCRIPT}")"; then - adb -s "${SN}" shell "${TEST_SCRIPT}" | tee "${LOGFILE}" +if test -n "$(adb shell "which ${TEST_SCRIPT}")"; then + adb shell "${TEST_SCRIPT}" | tee "${LOGFILE}" else warn_msg "${TEST_SCRIPT} NOT found" report_fail "test-script-existence-check" diff --git a/automated/lib/android-test-lib b/automated/lib/android-test-lib index 8677fea..3fe6831 100755 --- a/automated/lib/android-test-lib +++ b/automated/lib/android-test-lib @@ -12,26 +12,26 @@ install_latest_adb() { initialize_adb() { which lava-lxc-device-add && lava-lxc-device-add adb start-server - adb wait-for-device adb devices - if [ -z "${SN}" ]; then + if [ -z "${ANDROID_SERIAL}" ]; 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" + error_msg "More than one device or emulator found! Please set ANDROID_SERIAL from test script." elif [ "${number}" -eq 1 ]; then - SN="$(adb get-serialno)" - export SN + ANDROID_SERIAL="$(adb get-serialno)" else error_msg "Device NOT found" fi fi + export ANDROID_SERIAL + info_msg "Default adb device: ${ANDROID_SERIAL}" + adb wait-for-device - if adb -s "${SN}" shell echo "Testing adb connectivity"; then - info_msg "Connected to device ${SN} successfully" + if adb shell echo "Testing adb connectivity"; then + info_msg "Connected to device ${ANDROID_SERIAL} successfully" else - error_msg "Unable to connect to device ${SN}" + error_msg "Unable to connect to device ${ANDROID_SERIAL}" fi } @@ -50,7 +50,7 @@ wait_boot_completed() { boot_completed=false while [ "$(date +%s)" -lt "$end" ]; do - if adb -s "${SN}" shell getprop sys.boot_completed | grep "1"; then + if adb shell getprop sys.boot_completed | grep "1"; then boot_completed=true break else @@ -72,7 +72,7 @@ wait_homescreen() { homescreen_displayed=false while [ "$(date +%s)" -lt "$end" ]; do - if adb -s "${SN}" logcat -sd ActivityManager:I | grep "Displayed com.android.launcher"; then + if adb logcat -sd ActivityManager:I | grep "Displayed com.android.launcher"; then homescreen_displayed=true break else @@ -90,7 +90,7 @@ wait_homescreen() { 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')" + abi="$(adb shell uname -m | tr -d '\r')" case $abi in armv7|armv7l|armv7el|armv7lh) abi="armeabi" ;; arm64|armv8|arm64-v8a|aarch64) abi="arm64" ;; @@ -108,18 +108,18 @@ install() { file_path="$1" file_name="$(basename "${file_path}")" - if adb -s "${SN}" shell mount | grep system | grep -q ro; then + if adb 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 + adb 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 "${file_path}" "/system/bin/" + adb shell chmod 755 "/system/bin/${file_name}" } adb_push() { @@ -127,10 +127,10 @@ adb_push() { 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 shell mkdir -p "${remote}" + info_msg "Pushing ${local} to devcie ${ANDROID_SERIAL}" + adb push "${local}" "${remote}" + adb shell chmod -R 755 "${remote}" } adb_pull() { @@ -138,6 +138,6 @@ adb_pull() { remote="$1" local="$2" - info_msg "Pulling ${remote} from devcie ${SN}" - adb -s "${SN}" pull "${remote}" "${local}" + info_msg "Pulling ${remote} from devcie ${ANDROID_SERIAL}" + adb pull "${remote}" "${local}" } -- cgit v1.2.3