#!/bin/bash # Script to run ATS tests locally in Android build environment readonly DEFAULT_TMP_DIR="/tmp/ats_local_runner" readonly PREBUILTS_DIR="${ANDROID_BUILD_TOP}/tools/deviceinfra/prebuilts" readonly ATS_LOCAL_RUNNER_JAR="${PREBUILTS_DIR}/ats_local_runner_deploy.jar" readonly ATS_OLC_SERVER_JAR="${PREBUILTS_DIR}/ats_olc_server_local_mode_deploy.jar" readonly NORM='\e[0;38m' readonly LINK='\e[1;34m' # Bold, blue. For links and other emphasized text. readonly ME="$(basename "$0")" readonly HELP_MESSAGE=" ${LINK}Usage:${NORM} ${ME} [OPTIONS] ${LINK}OPTIONS${NORM} -a, --artifacts=PATH: Comma separated paths to test artifacts such as test binaries, apks, data files. Supports directory paths and file paths. -c, --test_config=PATH: Path to the test configuration. Required. -s, --serials=SERIAL: Comma separated serials to specify devices. If empty, randomly select available devices on the host. --help: Display this help and exit. " check_file() { if [[ ! -f "$1" ]]; then echo "Unable to locate $1" exit 1 fi; } check_path() { if ! type -P $1 &> /dev/null; then echo "Unable to find $1 in path." exit fi; } check_env() { if [[ -z "${ANDROID_BUILD_TOP}" ]]; then echo "Cannot run ATS test without Android build environment." exit 1 fi; check_file "${ATS_LOCAL_RUNNER_JAR}" check_file "${ATS_OLC_SERVER_JAR}" check_path adb check_path aapt check_path fastboot } main() { if [[ -z "${TEST_CONFIG}" ]]; then echo "Test config is required." exit 1 fi check_env echo "==========" echo "Launching ATS local runner..." echo "==========" local device_infra_service_flags=" \ --aapt=$(type -P aapt 2>/dev/null) \ --adb=$(type -P adb 2>/dev/null) \ --alr_olc_server_path=${ATS_OLC_SERVER_JAR} \ --fastboot=$(type -P fastboot 2>/dev/null) \ --public_dir=${DEFAULT_TMP_DIR} \ --tmp_dir_root=${DEFAULT_TMP_DIR} \ " local alr_args=("--alr_test_config=${TEST_CONFIG}" "--alr_artifact=${ARTIFACTS}" "--alr_serials=${SERIALS}") LANG=en_US.UTF-8 TEST_TMPDIR="${DEFAULT_TMP_DIR}" java \ -XX:+HeapDumpOnOutOfMemoryError --add-opens=java.base/java.lang=ALL-UNNAMED \ -DDEVICE_INFRA_SERVICE_FLAGS="${device_infra_service_flags}" \ -jar ${ATS_LOCAL_RUNNER_JAR} "${alr_args[@]}" } ARTIFACTS="" TEST_CONFIG="" SERIALS="" while [[ $# -gt 0 ]]; do case "$1" in -a=*|--artifacts=*) ARTIFACTS="${1#*=}";; -c=*|--test_config=*) TEST_CONFIG="${1#*=}";; -s=*|--serials=*) SERIALS="${1#*=}";; --help) echo -e "${HELP_MESSAGE}"; exit 0;; *) echo "Unknown argument $1"; echo -e "${HELP_MESSAGE}"; exit 1; esac shift # shift to next command done main