aboutsummaryrefslogtreecommitdiff
path: root/tests/test_art_host.sh
blob: 537f7b4aba006533dea2a18ab56b0decd07caeda (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/bin/bash
#
# Copyright (c) 2016-2021, Linaro Ltd.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# ART Host tests.
#
# Jenkins link:
# Not used by Jenkins yet.

readonly local_path=$(dirname "$0")
source "${local_path}/../utils/utils.sh"
source "${local_path}/../utils/utils_test.sh"
source "${local_path}/../utils/utils_android.sh"
source "${local_path}/../utils/utils_android_root.sh"
source "${local_path}/../utils/utils_run.sh"

readonly timer_name="Host Test"

job_count=${JCPU_COUNT}

# shellcheck disable=SC2034
declare -A options_format=(
  ["32bit"]="false"
  ["64bit"]="false"
  ["default"]="p:set_defaults_wrapper()"
  ["dump-cfg"]=""
  ["gdb"]="false"
  ["gdb-dex2oat"]="false"
  ["gdb-dex2oat-args"]=""
  ["gcstress"]="false"
  ["gtest"]="false"
  ["help"]="p:usage()"
  ["h"]="r:&help"
  ["interpreter"]="false"
  ["isa-features"]=""
  ["jit"]="false"
  ["jobs"]=""
  ["keep-failures"]="false"
  ["keep-going"]="false"
  ["optimizing"]="false"
  ["single-test"]=""
  ["verbose"]="p:enable_verbose()"
  ["v"]="r:&verbose"
)
# shellcheck disable=SC2034
declare -A options=()

set_defaults_wrapper() {
  new_opts_string=$(set_default_options "$(declare -p options)" "host" "")
  declare -A -g options=${new_opts_string#*=}
}

validate_options() {
  # Check that at least one test has been selected.
  if ! ${options["gtest"]} && ! ${options["optimizing"]} \
      && ! ${options["interpreter"]} && ! ${options["jit"]} \
      && [[ -z ${options["single-test"]} ]]; then
    log E "Please select at least one of the \"Tests\" to be run or use --default."
    log E "See the options ( -h | --help ) for more info."
    exit 1
  fi
  # Check for conflict between bitness in test name and bitness option
  if [[ "${options["single-test"]}" = *"32" ]] && ${options["64bit"]}; then
    log E "The test name specifies to run the test in the 32-bit mode but"
    log E "'--64bit' is used. The test mode option can be omitted in this case."
    exit 1
  fi
  if [[ "${options["single-test"]}" = *"64" ]] && ${options["32bit"]}; then
    log E "The test name specifies to run the test in the 64-bit mode but"
    log E "'--32bit' is used. The test mode option can be omitted in this case."
    exit 1
  fi

  if [[ -n "${options["jobs"]}" ]] && [[ ! ${options["jobs"]} =~ ^[0-9]+$ ]]; then
    log E "The --jobs option must be followed by an integer."
    exit 1
  fi

  if [[ -n "${options["dump-cfg"]}" ]] && [[ -z "${options["single-test"]}" ]]; then
    log E "Can only dump .cfg for a single test."
    exit 1
  fi

  if [[ "${options["gdb"]}" == "true" || "${options["gdb-dex2oat"]}" == "true" ]]; then
    if [[ -z "${options["single-test"]}" ]]; then
      log E "Can only run the debugger for a single test."
      exit 1
    fi

    local -r test_name="${options["single-test"]}"
    if is_single_test_gtest "${test_name}"; then
      log E "Can't run the debugger for a gtest."
      exit 1
    fi
  fi
}

set_job_count() {
  if [[ -n "${options["jobs"]}" ]]; then
    job_count="${options["jobs"]}"
  fi
}

usage() {
  log I "$0"
  log I "This script is used to run the host Jenkins test."
  log I "By default the lunch target is inferred from the environment as"
  log I "\${TARGET_PRODUCT}-\${TARGET_BUILD_VARIANT} (as set up by the \`lunch\`"
  log I "command). If those are not defined, the default lunch target is used"
  log I "instead. (current environment's default: $(lunch_target_from_env))"
  log I " -h - help"
  log I " -v - verbose"
  log I "-------------------------------------------"
  log I "Test Modes:"
  log I " --32bit         - run 32bit tests."
  log I " --64bit         - run 64bit tests."
  log I " Not providing a test mode means to run both 32bit and 64bit tests."
  log I "-------------------------------------------"
  log I "Test Options:"
  log I " --jobs                  - a number of jobs on a target. Defaults to CPU count."
  log I " --keep-failures         - keep failing tests around (useful for debugging)."
  log I " --keep-going            - don't stop at the first failing test."
  log I " --gcstress              - use gc stress testing for run-tests."
  log I " --isa-features          - specify isa features to be used.
                                    Possible values: default, runtime, a list of comma-separated
                                    feature names. When the list is used, '-' before a feature name
                                    means the ART compiler must not use the feature for code
                                    generation."
  log I " --dump-cfg <path>       - dump .cfg to the specified host full path. Only runs for a"
  log I "                           single test"
  log I " --gdb                   - Run dalvikvm under gdb. Only runs for a single test."
  log I " --gdb-dex2oat           - Run dex2oat under lldb. Only runs for a single test."
  log I " --gdb-dex2oat-args      - Use LLDB with arguments to debug the compiler (dex2oat)
                                    Each argument needs to be separated by a semicolon."
  log I "-------------------------------------------"
  log I "Tests:"
  log I " --gtest              - run gtests."
  log I " --optimizing         - run optimizing tests."
  log I " --interpreter        - run interpreter tests."
  log I " --jit                - run jit tests."
  log I " --single-test <test> - run specified test only"
  log I "-------------------------------------------"
  log I "Default Configuration:"
  log I " --default       - default test configuration, running all sections for 32 and 64 bits"
  log I "-------------------------------------------"
  exit 0
}

argument_parser() {
  while getopts ":vh" opt; do
    case ${opt} in
      v)
        enable_verbose
        ;;
      h)
        usage
        exit 0
        ;;
      \?)
        log E "Invalid option: ${OPTARG}"
        abort
        ;;
    esac
  done
}

# Arguments:
#   ${1}: test type {run-test, single-test}
#   ${2}: test section
#   ${3}: bitness (32/64)
run_test() {
  local section_name=$2_$3
  if [[ -z "$3" ]]; then
    section_name+="32_64"
  fi

  # Check if we should skip section
  if ! ${options["$2"]}; then
    section_starter "${section_name}" "host"
    skip_section "${section_name}"
    return
  fi

  section_starter "${section_name}" "host"
  run_test_unwrapped "$1" "$2" "" "$3" "host" "${job_count}" "$(declare -p options)"
  local return_code=$?
  section_ender "${section_name}" "host" "${return_code}" "${options["keep-going"]}"
}

# Arguments
#   ${1}: bitness (32/64)
test_gtest() {
  section_starter "gtest_$1" "host"

  if ! ${options["gtest"]}; then
    skip_section "gtest_$1"
    return
  fi

  # Until the art/test.py wrapper is fixed, we need to run the test manually
  # using the --make-mode syntax.
  build/soong/soong_ui.bash --make-mode -j"${JCPU_COUNT}" "test-art-host-gtest${1}"
  local return_code=$?
  section_ender "gtest_$1" "host" "${return_code}" "${options["keep-going"]}"
}

#  Arguments
#   ${1}: bitness (32/64)
test_optimizing() {
  run_test "run-test" "optimizing" "${1}"
}

#  Arguments
#   ${1}: bitness
test_interpreter() {
  run_test "run-test" "interpreter" "${1}"
}

#  Arguments
#   ${1}: bitness (32/64)
test_jit() {
  run_test "run-test" "jit" "${1}"
}

set_environment() {
  source_android_environment_default
  set_environment_host
  setup_android_target_to_environment_or_default
  if ${options["keep-failures"]}; then
    set_environment_keep_test_failures
  fi
}

main() {
  exit_on_failure arguments_parser options_format options -- "$@"
  if [[ ! -d "${PWD}/.repo" ]]; then
    log E "Script needs to be run at the root of the android tree."
    exit 1
  fi

  # Set bitness options when they are not provided via the command line.
  # A single test name can contain the bitness at the end of its name.
  if ! ${options["32bit"]} && ! ${options["64bit"]}; then
    if [[ "${options["single-test"]}" = *"32" ]]; then
      options["32bit"]="true"
    elif [[ "${options["single-test"]}" = *"64" ]]; then
      options["64bit"]="true"
    else
      options["32bit"]="true"
      options["64bit"]="true"
    fi
  fi

  readonly options
  validate_options
  dump_options
  set_environment
  set_job_count
  start_test "${timer_name}"
  build_host

  for bits in 32 64; do
    if ! ${options["${bits}bit"]}; then
      log I "Skipping ${bits}bit tests."
      continue
    fi
    log I "Starting ${bits}bit tests."
    if [[ -n ${options["single-test"]} ]]; then
      test_single "${bits}" "host" "${job_count}" "$(declare -p options)"
      continue
    fi
    test_gtest "${bits}"
    test_optimizing "${bits}"
    test_interpreter "${bits}"
    test_jit "${bits}"
  done
  end_test "${timer_name}"
}

main "$@"