From 09edc7f6fcaf627eee88ab4447c749c55ee2100c Mon Sep 17 00:00:00 2001 From: Chase Qi Date: Thu, 18 Aug 2016 13:18:50 +0800 Subject: v2: initial commit - Added utils, bin, and lib folders and related tools - Added Linux smoke test case as an example - Added test plan example that used to test test-runner Change-Id: I73693108db219cb67afc99525d80cab93f1eb9ea Signed-off-by: Chase Qi --- automated/lib/android-test-lib | 58 ++++++++++++++++++++ automated/lib/sh-test-lib | 121 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 179 insertions(+) create mode 100755 automated/lib/android-test-lib create mode 100755 automated/lib/sh-test-lib (limited to 'automated/lib') diff --git a/automated/lib/android-test-lib b/automated/lib/android-test-lib new file mode 100755 index 0000000..034b153 --- /dev/null +++ b/automated/lib/android-test-lib @@ -0,0 +1,58 @@ +#!/bin/sh + +initialize_adb() { + if [ -z "${SN}" ]; then + local 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 devices | grep -w 'device' | awk '{print $1}')" + export SN + else + error_msg "Device NOT found" + fi + fi + + adb -s "${SN}" shell ls / > /dev/null 2>&1 + if [ $? -eq 0 ]; then + info_msg "Connected to device ${SN} successfully" + else + error_msg "Unable to connect to device ${SN}" + 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() { + local file_path="$1" + local 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..." + 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}" +} + +pull_output() { + local device_output="$1" + local host_output="$2" + + info_msg "Pulling output from devcie ${SN}" + adb -s "${SN}" pull "${device_output}" "${host_output}" +} diff --git a/automated/lib/sh-test-lib b/automated/lib/sh-test-lib new file mode 100755 index 0000000..15ef4e0 --- /dev/null +++ b/automated/lib/sh-test-lib @@ -0,0 +1,121 @@ +#!/bin/sh + +LANG=C +export LANG + +error_msg() { + local msg="$1" + test -z "${msg}" && msg="Unknown error" + printf "ERROR: %s\n" "${msg}" >&2 + exit 1 +} + +warn_msg() { + local msg="$1" + test -z "${msg}" && msg="Unknown error" + printf "WARNING: %s\n" "${msg}" >&2 +} + +info_msg() { + local msg="$1" + test -z "${msg}" && msg="Unknown info" + printf "INFO: %s\n" "${msg}" >&1 +} + +check_return_fail() { + if [ $? -ne 0 ]; then + fail_test "$1" + return 0 + else + return 1 + fi +} + +fail_test() { + local reason="$1" + echo "${test}: fail - ${reason}" +} + +pass_test() { + echo "${test}: pass" +} + +check_root() { + if [ "$(id -ru)" -eq 0 ]; then + return 0 + else + return 1 + fi +} + +check_return() { + local exit_code="$?" + local test="$1" + + test -z "${test}" && warn_msg "Test name is empty" + + if [ "${exit_code}" -ne 0 ]; then + echo "${test} fail" | tee -a "${RESULT_FILE}" + return "${exit_code}" + else + echo "${test} pass" | tee -a "${RESULT_FILE}" + return 0 + fi +} + +add_metric() { + local test="$1" + local measurement="$2" + local units="$3" + + test -z "${test}" && warn_msg "Test name is empty" + test -z "${measurement}" && warn_msg "Test measurement is empty" + test -z "${units}" && warn_msg "Test units is empty" + + echo "${test} pass ${measurement} ${units}" | tee -a "${RESULT_FILE}" +} + +dist_name() { + if [ -x /usr/bin/lsb_release ]; then + dist="$(lsb_release -si)" + elif [ -f /etc/lsb-release ]; then + . /etc/lsb-release + dist="${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 +} + +install_deps() { + local pkgs="$1" + local skip_install="$2" + + if [ "${skip_install}" = "True" ] || [ "${skip_install}" = "true" ]; then + info_msg "install_deps skipped" + else + info_msg "Installing ${pkgs}" + dist_name + case "${dist}" in + Debian|Ubuntu) + apt-get update + apt-get install -y -q ${pkgs} + ;; + CentOS) + yum -e 0 -y install ${pkgs} + ;; + Fedora) + dnf -e 0 -y install ${pkgs} + ;; + Unknown) + warn_msg "Unsupported distro: package install skipped" + ;; + esac + fi +} -- cgit v1.2.3