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 /lib/android-test-lib | |
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
Diffstat (limited to 'lib/android-test-lib')
-rwxr-xr-x | lib/android-test-lib | 143 |
1 files changed, 143 insertions, 0 deletions
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}" +} |