summaryrefslogtreecommitdiff
path: root/ats-local-runner
blob: c8958fe246b4b32e7a32be3169822e1cdcb08397 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/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} \
    --simplified_log_format=true \
    --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