aboutsummaryrefslogtreecommitdiff
path: root/automated/lib/android-test-lib
diff options
context:
space:
mode:
authorKarsten Tausche <karsten@fairphone.com>2018-06-19 14:12:11 +0200
committerKarsten Tausche <karsten@fairphone.com>2018-12-14 13:31:17 +0100
commita1ded749850127d12f766cd5d4b281e5fe66bea8 (patch)
tree1a7fa9a19e7a39b68adb30928420233d6b96f64f /automated/lib/android-test-lib
parentc383266d50a8538e7ebad3ba53252114c52f3d8c (diff)
Hide shell variables in local function scope
This prevents unexpected side effects due to commonly used variable names, e.g., when shell functions call each other. Also make sure `install_deps` optional parameter `skip_install` is initialized. Change-Id: I0baa1c66221cc32bfe7c6da276db72f092283f81 Signed-off-by: Karsten Tausche <karsten@fairphone.com>
Diffstat (limited to 'automated/lib/android-test-lib')
-rwxr-xr-xautomated/lib/android-test-lib70
1 files changed, 45 insertions, 25 deletions
diff --git a/automated/lib/android-test-lib b/automated/lib/android-test-lib
index 37035d1..6c9e79c 100755
--- a/automated/lib/android-test-lib
+++ b/automated/lib/android-test-lib
@@ -76,10 +76,13 @@ adb_root() {
wait_boot_completed() {
[ "$#" -ne 1 ] && error_msg "Usage: wait_for_boot_completed timeout_in_seconds"
- timeout="$1"
- end=$(( $(date +%s) + timeout ))
+ # shellcheck disable=SC2039
+ local timeout="$1"
+ # shellcheck disable=SC2039
+ local end=$(( $(date +%s) + timeout ))
- boot_completed=false
+ # shellcheck disable=SC2039
+ local boot_completed=false
while [ "$(date +%s)" -lt "$end" ]; do
if adb shell getprop sys.boot_completed | grep "1"; then
boot_completed=true
@@ -111,9 +114,12 @@ wait_homescreen() {
fi
fi
- timeout="$1"
- end=$(( $(date +%s) + timeout ))
- homescreen_displayed=false
+ # shellcheck disable=SC2039
+ local timeout="$1"
+ # shellcheck disable=SC2039
+ local end=$(( $(date +%s) + timeout ))
+ # shellcheck disable=SC2039
+ local homescreen_displayed=false
while [ "$(date +%s)" -lt "$end" ]; do
if adb logcat -sd ActivityManager:I | grep "Displayed com.android.launcher"; then
homescreen_displayed=true
@@ -133,6 +139,8 @@ 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
+ # shellcheck disable=SC2039
+ local abi
abi="$(adb shell uname -m | tr -d '\r')"
case $abi in
armv7|armv7l|armv7el|armv7lh) abi="armeabi" ;;
@@ -148,7 +156,10 @@ detect_abi() {
# permission granted, like '/data/local/tmp', and run it from there.
install() {
[ "$#" -ne 1 ] && error_msg "Usage: install <file_path>"
- file_path="$1"
+ # shellcheck disable=SC2039
+ local file_path="$1"
+ # shellcheck disable=SC2039
+ local file_name
file_name="$(basename "${file_path}")"
if adb shell mount | grep system | grep -q ro; then
@@ -166,36 +177,43 @@ install() {
}
adb_push() {
- [ "$#" -ne 2 ] && error_msg "Usage: adb_push <local> <remote>"
- local="$1"
- remote="$2"
+ [ "$#" -ne 2 ] && error_msg "Usage: adb_push <local_file> <remote_file>"
+ # shellcheck disable=SC2039
+ local local_file="$1"
+ # shellcheck disable=SC2039
+ local remote_file="$2"
- adb shell mkdir -p "${remote}"
- info_msg "Pushing ${local} to devcie ${ANDROID_SERIAL}"
- adb push "${local}" "${remote}"
+ adb shell mkdir -p "${remote_file}"
+ info_msg "Pushing ${local_file} to device ${ANDROID_SERIAL}"
+ adb push "${local_file}" "${remote_file}"
# Set 755 permission on the folder/file pushed to device.
- if [ -d "${local}" ]; then
- adb shell chmod -R 755 "${remote}"
- elif [ -f "${local}" ]; then
- adb shell chmod -R 755 "$(echo "${remote}" | sed 's|/$||')/$(basename "${local}")"
+ if [ -d "${local_file}" ]; then
+ adb shell chmod -R 755 "${remote_file}"
+ elif [ -f "${local_file}" ]; then
+ adb shell chmod -R 755 "$(echo "${remote_file}" | sed 's|/$||')/$(basename "${local_file}")"
fi
}
adb_pull() {
- [ "$#" -ne 2 ] && error_msg "Usage: adb_pull <remote> <local>"
- remote="$1"
- local="$2"
+ [ "$#" -ne 2 ] && error_msg "Usage: adb_pull <remote_file> <local_file>"
+ # shellcheck disable=SC2039
+ local remote_file="$1"
+ # shellcheck disable=SC2039
+ local local_file="$2"
- info_msg "Pulling ${remote} from devcie ${ANDROID_SERIAL}"
- adb pull "${remote}" "${local}"
+ info_msg "Pulling ${remote_file} from device ${ANDROID_SERIAL}"
+ adb pull "${remote_file}" "${local_file}"
}
adb_shell_which() {
[ "$#" -ne 1 ] && error_msg "Usage: adb_shell_which <cmd>"
- cmd="$1"
+ # shellcheck disable=SC2039
+ local cmd="$1"
# Only latest version adb able to return exit code.
# Check if output of which is empty is a more reliable way.
+ # shellcheck disable=SC2039
+ local which_output
which_output="$(adb shell "echo which ${cmd} | su")"
info_msg "Output of which: *${which_output}*"
if [ -n "${which_output}" ]; then
@@ -240,8 +258,10 @@ parse_common_args() {
# AP_SSID: "${AP_SSID}"
# AP_KEY: "${AP_KEY}"
adb_join_wifi() {
- AP_SSID=$1
- AP_KEY=$2
+ # shellcheck disable=SC2039
+ local AP_SSID=$1
+ # shellcheck disable=SC2039
+ local AP_KEY=$2
if [ -z "${AP_SSID}" ] || [ -z "${AP_KEY}" ]; then
# Try to find the WIFI AP information specified by the job definition if not specified via command line
lava_test_dir="$(find /lava-* -maxdepth 0 -type d -regex '/lava-[0-9]+' 2>/dev/null | sort | tail -1)"