File: run-libcore-tests.sh

package info (click to toggle)
android-platform-art 11.0.0%2Br48-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 78,932 kB
  • sloc: cpp: 459,858; java: 163,268; asm: 22,644; python: 9,815; sh: 6,330; ansic: 4,117; xml: 2,855; perl: 77; makefile: 73
file content (322 lines) | stat: -rwxr-xr-x 9,897 bytes parent folder | download | duplicates (2)
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#!/bin/bash
#
# Copyright (C) 2014 The Android Open Source Project
#
# 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.

# Exit on errors.
set -e

if [ ! -d libcore ]; then
  echo "Script needs to be run at the root of the android tree"
  exit 1
fi

# "Root" (actually "system") directory on device (in the case of
# target testing).
android_root=${ART_TEST_ANDROID_ROOT:-/system}

function classes_jar_path {
  local var="$1"
  local suffix="jar"
  if [ -z "$ANDROID_PRODUCT_OUT" ] ; then
    local java_libraries=out/target/common/obj/JAVA_LIBRARIES
  else
    local java_libraries=${ANDROID_PRODUCT_OUT}/../../common/obj/JAVA_LIBRARIES
  fi
  echo "${java_libraries}/${var}_intermediates/classes.${suffix}"
}

function cparg {
  for var
  do
    printf -- "--classpath $(classes_jar_path "$var") ";
  done
}

function boot_classpath_arg {
  local dir="$1"
  local suffix="$2"
  shift 2
  printf -- "--vm-arg -Xbootclasspath"
  for var
  do
    printf -- ":${dir}/${var}${suffix}.jar";
  done
}

function usage {
  local me=$(basename "${BASH_SOURCE[0]}")
  (
    cat << EOF
  Usage: ${me} --mode=<mode> [options] [-- <package_to_test> ...]

  Run libcore tests using the vogar testing tool.

  Required parameters:
    --mode=device|host|jvm Specify where tests should be run.

  Optional parameters:
    --debug                Use debug version of ART (device|host only).
    --dry-run              Print vogar command-line, but do not run.
    --no-getrandom         Ignore failures from getrandom() (for kernel < 3.17).
    --no-jit               Disable JIT (device|host only).
    --Xgc:gcstress         Enable GC stress configuration (device|host only).

  The script passes unrecognized options to the command-line created for vogar.

  The script runs a hardcoded list of libcore test packages by default. The user
  may run a subset of packages by appending '--' followed by a list of package
  names.

  Examples:

    1. Run full test suite on host:
      ${me} --mode=host

    2. Run full test suite on device:
      ${me} --mode=device

    3. Run tests only from the libcore.java.lang package on device:
      ${me} --mode=device -- libcore.java.lang
EOF
  ) | sed -e 's/^  //' >&2 # Strip leading whitespace from heredoc.
}

# Packages that currently work correctly with the expectation files.
working_packages=("libcore.android.system"
                  "libcore.build"
                  "libcore.dalvik.system"
                  "libcore.java.awt"
                  "libcore.java.lang"
                  "libcore.java.math"
                  "libcore.java.text"
                  "libcore.java.util"
                  "libcore.javax.crypto"
                  "libcore.javax.net"
                  "libcore.javax.security"
                  "libcore.javax.sql"
                  "libcore.javax.xml"
                  "libcore.libcore.internal"
                  "libcore.libcore.io"
                  "libcore.libcore.net"
                  "libcore.libcore.reflect"
                  "libcore.libcore.util"
                  "libcore.libcore.timezone"
                  "libcore.sun.invoke"
                  "libcore.sun.net"
                  "libcore.sun.misc"
                  "libcore.sun.security"
                  "libcore.sun.util"
                  "libcore.xml"
                  "org.apache.harmony.annotation"
                  "org.apache.harmony.crypto"
                  "org.apache.harmony.luni"
                  "org.apache.harmony.nio"
                  "org.apache.harmony.regex"
                  "org.apache.harmony.testframework"
                  "org.apache.harmony.tests.java.io"
                  "org.apache.harmony.tests.java.lang"
                  "org.apache.harmony.tests.java.math"
                  "org.apache.harmony.tests.java.util"
                  "org.apache.harmony.tests.java.text"
                  "org.apache.harmony.tests.javax.security"
                  "tests.java.lang.String"
                  "jsr166")

# List of packages we could run, but don't have rights to revert
# changes in case of failures.
# "org.apache.harmony.security"

#
# Setup environment for running tests.
#
source build/envsetup.sh >&/dev/null # for get_build_var, setpaths
setpaths # include platform prebuilt java, javac, etc in $PATH.

# Note: This must start with the CORE_IMG_JARS in Android.common_path.mk
# because that's what we use for compiling the core.art image.
# It may contain additional modules from TEST_CORE_JARS.
BOOT_CLASSPATH_JARS="core-oj core-libart core-icu4j okhttp bouncycastle apache-xml conscrypt"

DEPS="core-tests jsr166-tests mockito-target"

for lib in $DEPS
do
  if [[ ! -f "$(classes_jar_path "$lib")" ]]; then
    echo "${lib} is missing. Before running, you must run art/tools/buildbot-build.sh"
    exit 1
  fi
done

#
# Defaults affected by command-line parsing
#

# Use JIT compiling by default.
use_jit=true

gcstress=false
debug=false
dry_run=false

# Run tests that use the getrandom() syscall? (Requires Linux 3.17+).
getrandom=true

# Execution mode specifies where to run tests (device|host|jvm).
execution_mode=""

# Default expectations file.
expectations="--expectations art/tools/libcore_failures.txt"

vogar_args=""
while [ -n "$1" ]; do
  case "$1" in
    --mode=device)
      # Use --mode=device_testdex not --mode=device for buildbot-build.sh.
      # See commit 191cae33c7c24e for more details.
      vogar_args="$vogar_args --mode=device_testdex"
      vogar_args="$vogar_args --vm-arg -Ximage:/data/art-test/core.art"
      vogar_args="$vogar_args $(boot_classpath_arg /system/framework -testdex $BOOT_CLASSPATH_JARS)"
      execution_mode="device"
      ;;
    --mode=host)
      # We explicitly give a wrong path for the image, to ensure vogar
      # will create a boot image with the default compiler. Note that
      # giving an existing image on host does not work because of
      # classpath/resources differences when compiling the boot image.
      vogar_args="$vogar_args $1 --vm-arg -Ximage:/non/existent/vogar.art"
      execution_mode="host"
      ;;
    --mode=jvm)
      vogar_args="$vogar_args $1"
      execution_mode="jvm"
      ;;
    --no-getrandom)
      getrandom=false
      ;;
    --no-jit)
      use_jit=false
      ;;
    --debug)
      vogar_args="$vogar_args --vm-arg -XXlib:libartd.so --vm-arg -XX:SlowDebug=true"
      debug=true
      ;;
    -Xgc:gcstress)
      vogar_args="$vogar_args $1"
      gcstress=true
      ;;
    --dry-run)
      dry_run=true
      ;;
    --)
      shift
      # Assume remaining elements are packages to test.
      user_packages=("$@")
      break
      ;;
    --help)
      usage
      exit 1
      ;;
    *)
      vogar_args="$vogar_args $1"
      ;;
  esac
  shift
done

if [ -z "$execution_mode" ]; then
  usage
  exit 1
fi

# Default timeout, gets overridden on device under gcstress.
timeout_secs=480

if [ $execution_mode = "device" ]; then
  # Honor environment variable ART_TEST_CHROOT.
  if [[ -n "$ART_TEST_CHROOT" ]]; then
    # Set Vogar's `--chroot` option.
    vogar_args="$vogar_args --chroot $ART_TEST_CHROOT"
    vogar_args="$vogar_args --device-dir=/tmp"
  else
    # When not using a chroot on device, set Vogar's work directory to
    # /data/local/tmp.
    vogar_args="$vogar_args --device-dir=/data/local/tmp"
  fi
  vogar_args="$vogar_args --vm-command=$android_root/bin/art"

  # Increase the timeout, as vogar cannot set individual test
  # timeout when being asked to run packages, and some tests go above
  # the default timeout.
  if $gcstress; then
    if $debug; then
      timeout_secs=1440
    else
      timeout_secs=900
    fi
  fi
fi  # $execution_mode = "device"

if [ $execution_mode = "device" -o $execution_mode = "host" ]; then
  # Add timeout to vogar command-line.
  vogar_args="$vogar_args --timeout $timeout_secs"

  # set the toolchain to use.
  vogar_args="$vogar_args --toolchain d8 --language CUR"

  # JIT settings.
  if $use_jit; then
    vogar_args="$vogar_args --vm-arg -Xcompiler-option --vm-arg --compiler-filter=quicken"
  fi
  vogar_args="$vogar_args --vm-arg -Xusejit:$use_jit"

  # gcstress may lead to timeouts, so we need dedicated expectations files for it.
  if $gcstress; then
    expectations="$expectations --expectations art/tools/libcore_gcstress_failures.txt"
    if $debug; then
      expectations="$expectations --expectations art/tools/libcore_gcstress_debug_failures.txt"
    fi
  else
    # We only run this package when user has not specified packages
    # to run and not under gcstress as it can cause timeouts. See
    # b/78228743.
    working_packages+=("libcore.libcore.icu")
  fi

  if $getrandom; then :; else
    # Ignore failures in tests that use the system calls not supported
    # on fugu (Nexus Player, kernel version Linux 3.10).
    expectations="$expectations --expectations art/tools/libcore_fugu_failures.txt"
  fi
fi

if [ ! -t 1 ] ; then
  # Suppress color codes if not attached to a terminal
  vogar_args="$vogar_args --no-color"
fi

# Override working_packages if user provided specific packages to
# test.
if [[ ${#user_packages[@]} != 0 ]] ; then
  working_packages=("${user_packages[@]}")
fi

# Run the tests using vogar.
echo "Running tests for the following test packages:"
echo ${working_packages[@]} | tr " " "\n"

cmd="vogar $vogar_args $expectations $(cparg $DEPS) ${working_packages[@]}"
echo "Running $cmd"
$dry_run || eval $cmd