blob: 0be5b56a764d9d4ddacfe78b60ed57009835fd87 [file] [log] [blame]
Nicolas Geoffrayb2e7e242014-11-28 14:24:28 +00001#!/bin/bash
2#
3# Copyright (C) 2014 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
Orion Hodsonaf6a15c2019-12-11 21:48:58 +000017# Exit on errors.
18set -e
19
Nicolas Geoffrayb2e7e242014-11-28 14:24:28 +000020if [ ! -d libcore ]; then
21 echo "Script needs to be run at the root of the android tree"
22 exit 1
23fi
24
Roland Levillain08f7c1d2018-05-25 15:34:41 +010025# "Root" (actually "system") directory on device (in the case of
26# target testing).
27android_root=${ART_TEST_ANDROID_ROOT:-/system}
Roland Levillain1c361882018-03-02 14:23:51 +000028
Igor Murashkin84f26322017-06-06 11:36:33 -070029function classes_jar_path {
30 local var="$1"
31 local suffix="jar"
Orion Hodsonaf6a15c2019-12-11 21:48:58 +000032 if [ -z "$ANDROID_PRODUCT_OUT" ] ; then
33 local java_libraries=out/target/common/obj/JAVA_LIBRARIES
34 else
35 local java_libraries=${ANDROID_PRODUCT_OUT}/../../common/obj/JAVA_LIBRARIES
36 fi
37 echo "${java_libraries}/${var}_intermediates/classes.${suffix}"
Igor Murashkin84f26322017-06-06 11:36:33 -070038}
39
Tobias Thiererb3ec0892016-08-03 16:13:04 +010040function cparg {
41 for var
42 do
Igor Murashkin84f26322017-06-06 11:36:33 -070043 printf -- "--classpath $(classes_jar_path "$var") ";
Tobias Thiererb3ec0892016-08-03 16:13:04 +010044 done
45}
Wojciech Staszkiewicz08cf1482015-05-21 17:31:38 +010046
Vladimir Marko91f10322018-12-07 18:04:10 +000047function boot_classpath_arg {
48 local dir="$1"
Nicolas Geoffray31e0dc22020-03-20 15:48:09 +000049 shift 1
Vladimir Marko91f10322018-12-07 18:04:10 +000050 printf -- "--vm-arg -Xbootclasspath"
51 for var
52 do
Nicolas Geoffray31e0dc22020-03-20 15:48:09 +000053 printf -- ":${dir}/${var}.jar";
Vladimir Marko91f10322018-12-07 18:04:10 +000054 done
Victor Changd20e51d2020-05-05 16:01:19 +010055 printf -- ":/apex/com.android.i18n/javalib/core-icu4j.jar:/apex/com.android.conscrypt/javalib/conscrypt.jar";
Vladimir Marko91f10322018-12-07 18:04:10 +000056}
57
Orion Hodsonaf6a15c2019-12-11 21:48:58 +000058function usage {
59 local me=$(basename "${BASH_SOURCE[0]}")
60 (
61 cat << EOF
Orion Hodson656dc822019-12-12 00:06:36 +000062 Usage: ${me} --mode=<mode> [options] [-- <package_to_test> ...]
Vladimir Marko91f10322018-12-07 18:04:10 +000063
Orion Hodsonaf6a15c2019-12-11 21:48:58 +000064 Run libcore tests using the vogar testing tool.
Wojciech Staszkiewicz08cf1482015-05-21 17:31:38 +010065
Orion Hodsonaf6a15c2019-12-11 21:48:58 +000066 Required parameters:
Orion Hodson0bbe28c2019-12-12 00:23:09 +000067 --mode=device|host|jvm Specify where tests should be run.
Nicolas Geoffrayb2e7e242014-11-28 14:24:28 +000068
Orion Hodsonaf6a15c2019-12-11 21:48:58 +000069 Optional parameters:
70 --debug Use debug version of ART (device|host only).
71 --dry-run Print vogar command-line, but do not run.
72 --no-getrandom Ignore failures from getrandom() (for kernel < 3.17).
73 --no-jit Disable JIT (device|host only).
Orion Hodson37f49452020-11-10 14:35:31 +000074 --gcstress Enable GC stress configuration (device|host only).
Orion Hodsonaf6a15c2019-12-11 21:48:58 +000075
76 The script passes unrecognized options to the command-line created for vogar.
77
Orion Hodson656dc822019-12-12 00:06:36 +000078 The script runs a hardcoded list of libcore test packages by default. The user
79 may run a subset of packages by appending '--' followed by a list of package
80 names.
81
Orion Hodsonaf6a15c2019-12-11 21:48:58 +000082 Examples:
83
84 1. Run full test suite on host:
85 ${me} --mode=host
86
87 2. Run full test suite on device:
88 ${me} --mode=device
Orion Hodson656dc822019-12-12 00:06:36 +000089
90 3. Run tests only from the libcore.java.lang package on device:
91 ${me} --mode=device -- libcore.java.lang
Orion Hodsonaf6a15c2019-12-11 21:48:58 +000092EOF
93 ) | sed -e 's/^ //' >&2 # Strip leading whitespace from heredoc.
94}
Roland Levillainafd6f9e2016-01-11 15:51:00 +000095
Nicolas Geoffrayc3837e42014-12-03 11:30:26 +000096# Packages that currently work correctly with the expectation files.
Roland Levillaind2f8ce12019-06-19 17:50:32 +010097working_packages=("libcore.android.system"
Roland Levillain9e189072019-06-19 17:51:08 +010098 "libcore.build"
Roland Levillaind2f8ce12019-06-19 17:50:32 +010099 "libcore.dalvik.system"
Roland Levillainb06e0ad2019-06-19 19:07:57 +0100100 "libcore.java.awt"
David Brazdil598b2202015-02-24 10:12:06 +0000101 "libcore.java.lang"
Nicolas Geoffrayc3837e42014-12-03 11:30:26 +0000102 "libcore.java.math"
David Brazdil598b2202015-02-24 10:12:06 +0000103 "libcore.java.text"
Nicolas Geoffray3cdf8182014-12-01 10:12:15 +0000104 "libcore.java.util"
David Brazdil4cd7dfd2015-02-24 13:33:01 +0000105 "libcore.javax.crypto"
Roland Levillaine0ce8bf2019-06-19 18:05:51 +0100106 "libcore.javax.net"
David Brazdil598b2202015-02-24 10:12:06 +0000107 "libcore.javax.security"
108 "libcore.javax.sql"
109 "libcore.javax.xml"
Victor Chang16f7f8e2021-02-03 17:00:24 +0000110 "libcore.libcore.icu"
Roland Levillain9b41e952019-06-19 18:20:07 +0100111 "libcore.libcore.internal"
Andreas Gampee1661362017-11-08 16:42:14 -0800112 "libcore.libcore.io"
113 "libcore.libcore.net"
114 "libcore.libcore.reflect"
115 "libcore.libcore.util"
Roland Levillainc0ce3d52019-06-19 17:26:01 +0100116 "libcore.sun.invoke"
117 "libcore.sun.net"
118 "libcore.sun.misc"
119 "libcore.sun.security"
120 "libcore.sun.util"
Roland Levillainad82a812019-06-19 18:29:32 +0100121 "libcore.xml"
Nicolas Geoffray3cdf8182014-12-01 10:12:15 +0000122 "org.apache.harmony.annotation"
David Brazdil4cd7dfd2015-02-24 13:33:01 +0000123 "org.apache.harmony.crypto"
David Brazdile2f28ad2015-02-24 10:44:29 +0000124 "org.apache.harmony.luni"
125 "org.apache.harmony.nio"
Nicolas Geoffray3cdf8182014-12-01 10:12:15 +0000126 "org.apache.harmony.regex"
David Brazdile2f28ad2015-02-24 10:44:29 +0000127 "org.apache.harmony.testframework"
128 "org.apache.harmony.tests.java.io"
Nicolas Geoffray3cdf8182014-12-01 10:12:15 +0000129 "org.apache.harmony.tests.java.lang"
Nicolas Geoffrayc3837e42014-12-03 11:30:26 +0000130 "org.apache.harmony.tests.java.math"
Nicolas Geoffray3cdf8182014-12-01 10:12:15 +0000131 "org.apache.harmony.tests.java.util"
David Brazdile2f28ad2015-02-24 10:44:29 +0000132 "org.apache.harmony.tests.java.text"
133 "org.apache.harmony.tests.javax.security"
Wojciech Staszkiewicz08cf1482015-05-21 17:31:38 +0100134 "tests.java.lang.String"
135 "jsr166")
Nicolas Geoffrayb2e7e242014-11-28 14:24:28 +0000136
Nicolas Geoffraycdcd0002015-10-31 14:47:36 +0000137# List of packages we could run, but don't have rights to revert
138# changes in case of failures.
139# "org.apache.harmony.security"
140
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000141#
142# Setup environment for running tests.
143#
144source build/envsetup.sh >&/dev/null # for get_build_var, setpaths
145setpaths # include platform prebuilt java, javac, etc in $PATH.
146
147# Note: This must start with the CORE_IMG_JARS in Android.common_path.mk
David Srbecky6355d692020-03-26 14:10:26 +0000148# because that's what we use for compiling the boot.art image.
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000149# It may contain additional modules from TEST_CORE_JARS.
Victor Changd20e51d2020-05-05 16:01:19 +0100150BOOT_CLASSPATH_JARS="core-oj core-libart okhttp bouncycastle apache-xml"
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000151
152DEPS="core-tests jsr166-tests mockito-target"
153
154for lib in $DEPS
155do
156 if [[ ! -f "$(classes_jar_path "$lib")" ]]; then
157 echo "${lib} is missing. Before running, you must run art/tools/buildbot-build.sh"
158 exit 1
159 fi
160done
161
162#
163# Defaults affected by command-line parsing
164#
165
166# Use JIT compiling by default.
167use_jit=true
168
Nicolas Geoffray622e2e22017-06-15 09:33:01 +0100169debug=false
Orion Hodson14f30022019-12-11 18:54:51 +0000170dry_run=false
Orion Hodson4a2fc8a2020-11-10 13:42:51 +0000171gcstress=false
172heap_poisoning=${ART_HEAP_POISONING:-false}
Nicolas Geoffray622e2e22017-06-15 09:33:01 +0100173
Roland Levillaind6e2c382019-09-18 16:13:48 +0100174# Run tests that use the getrandom() syscall? (Requires Linux 3.17+).
175getrandom=true
176
Orion Hodson0bbe28c2019-12-12 00:23:09 +0000177# Execution mode specifies where to run tests (device|host|jvm).
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000178execution_mode=""
Roland Levillaine4f1c512017-10-30 13:28:28 +0000179
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000180# Default expectations file.
181expectations="--expectations art/tools/libcore_failures.txt"
182
183vogar_args=""
184while [ -n "$1" ]; do
185 case "$1" in
186 --mode=device)
Nicolas Geoffray31e0dc22020-03-20 15:48:09 +0000187 vogar_args="$vogar_args --mode=device"
David Srbecky928d28e2020-04-01 17:50:51 +0100188 vogar_args="$vogar_args --vm-arg -Ximage:/apex/com.android.art/javalib/boot.art"
Nicolas Geoffray31e0dc22020-03-20 15:48:09 +0000189 vogar_args="$vogar_args $(boot_classpath_arg /apex/com.android.art/javalib $BOOT_CLASSPATH_JARS)"
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000190 execution_mode="device"
191 ;;
192 --mode=host)
193 # We explicitly give a wrong path for the image, to ensure vogar
194 # will create a boot image with the default compiler. Note that
195 # giving an existing image on host does not work because of
196 # classpath/resources differences when compiling the boot image.
197 vogar_args="$vogar_args $1 --vm-arg -Ximage:/non/existent/vogar.art"
198 execution_mode="host"
199 ;;
Orion Hodson0bbe28c2019-12-12 00:23:09 +0000200 --mode=jvm)
201 vogar_args="$vogar_args $1"
202 execution_mode="jvm"
203 ;;
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000204 --no-getrandom)
205 getrandom=false
206 ;;
207 --no-jit)
208 use_jit=false
209 ;;
210 --debug)
211 vogar_args="$vogar_args --vm-arg -XXlib:libartd.so --vm-arg -XX:SlowDebug=true"
212 debug=true
213 ;;
Orion Hodson37f49452020-11-10 14:35:31 +0000214 --gcstress)
215 vogar_args="$vogar_args --vm-arg -Xgc:gcstress"
216 gcstress=true
217 ;;
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000218 -Xgc:gcstress)
Orion Hodson37f49452020-11-10 14:35:31 +0000219 # Deprecated option for selecting gcstress (b/172923084).
220 echo "Warning: -Xgc:gcstress is deprecated, use --gcstress instead." 1>&2
221 vogar_args="$vogar_args $1" # note: requires --vm-arg before -Xgc:gcstress
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000222 gcstress=true
223 ;;
224 --dry-run)
225 dry_run=true
226 ;;
Orion Hodson656dc822019-12-12 00:06:36 +0000227 --)
228 shift
229 # Assume remaining elements are packages to test.
230 user_packages=("$@")
231 break
232 ;;
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000233 --help)
234 usage
235 exit 1
236 ;;
237 *)
238 vogar_args="$vogar_args $1"
239 ;;
240 esac
241 shift
Nicolas Geoffray9648a632015-06-15 14:35:01 +0100242done
243
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000244if [ -z "$execution_mode" ]; then
245 usage
246 exit 1
247fi
248
249# Default timeout, gets overridden on device under gcstress.
Orion Hodsondada83e2020-11-10 11:13:38 +0000250default_timeout_secs=480
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000251
252if [ $execution_mode = "device" ]; then
Roland Levillain08f7c1d2018-05-25 15:34:41 +0100253 # Honor environment variable ART_TEST_CHROOT.
254 if [[ -n "$ART_TEST_CHROOT" ]]; then
255 # Set Vogar's `--chroot` option.
256 vogar_args="$vogar_args --chroot $ART_TEST_CHROOT"
Roland Levillaine4f1c512017-10-30 13:28:28 +0000257 vogar_args="$vogar_args --device-dir=/tmp"
Roland Levillaine4f1c512017-10-30 13:28:28 +0000258 else
Roland Levillain08f7c1d2018-05-25 15:34:41 +0100259 # When not using a chroot on device, set Vogar's work directory to
260 # /data/local/tmp.
Roland Levillaine4f1c512017-10-30 13:28:28 +0000261 vogar_args="$vogar_args --device-dir=/data/local/tmp"
Roland Levillaine4f1c512017-10-30 13:28:28 +0000262 fi
Roland Levillain08f7c1d2018-05-25 15:34:41 +0100263 vogar_args="$vogar_args --vm-command=$android_root/bin/art"
Roland Levillaine4f1c512017-10-30 13:28:28 +0000264
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000265 # Increase the timeout, as vogar cannot set individual test
266 # timeout when being asked to run packages, and some tests go above
267 # the default timeout.
268 if $gcstress; then
269 if $debug; then
Orion Hodsondada83e2020-11-10 11:13:38 +0000270 default_timeout_secs=1440
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000271 else
Roland Levillain30126392021-03-31 13:16:21 +0000272 default_timeout_secs=1200
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000273 fi
Orion Hodson4a2fc8a2020-11-10 13:42:51 +0000274 elif $heap_poisoning && $debug; then
275 # Increase the timeout for heap poisoning and debug combo
276 # following ICU rewrites (b/161420453).
277 default_timeout_secs=600
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000278 fi
Orion Hodson3822f5b2020-11-10 14:19:01 +0000279elif [ $execution_mode = "host" ]; then
280 # Increase timeout for gcstress and debug combo following ICU
281 # rewrites (b/161420453).
282 if $gcstress && $debug; then
283 default_timeout_secs=600
284 fi
285fi
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000286
Orion Hodson0bbe28c2019-12-12 00:23:09 +0000287if [ $execution_mode = "device" -o $execution_mode = "host" ]; then
Orion Hodsondada83e2020-11-10 11:13:38 +0000288 # Add timeout to vogar command-line (if not explicitly present in the command-line arguments) .
289 if [[ "$vogar_args" != *" --timeout "* ]]; then
290 vogar_args="$vogar_args --timeout $default_timeout_secs"
291 fi
Nicolas Geoffrayf794ad72015-09-11 12:08:49 +0100292
Alex Lightb5a0e912020-07-23 10:54:47 -0700293 # Suppress explicit gc logs that are triggered an absurd number of times by these tests.
294 vogar_args="$vogar_args --vm-arg -XX:AlwaysLogExplicitGcs:false"
295
Orion Hodson0bbe28c2019-12-12 00:23:09 +0000296 # set the toolchain to use.
297 vogar_args="$vogar_args --toolchain d8 --language CUR"
Neil Fullerb8300fc2016-02-10 13:09:10 +0000298
Orion Hodson0bbe28c2019-12-12 00:23:09 +0000299 # JIT settings.
300 if $use_jit; then
301 vogar_args="$vogar_args --vm-arg -Xcompiler-option --vm-arg --compiler-filter=quicken"
Orion Hodson938ead32019-12-10 13:01:40 +0000302 fi
Orion Hodson0bbe28c2019-12-12 00:23:09 +0000303 vogar_args="$vogar_args --vm-arg -Xusejit:$use_jit"
Orion Hodson938ead32019-12-10 13:01:40 +0000304
Orion Hodson0bbe28c2019-12-12 00:23:09 +0000305 # gcstress may lead to timeouts, so we need dedicated expectations files for it.
306 if $gcstress; then
307 expectations="$expectations --expectations art/tools/libcore_gcstress_failures.txt"
308 if $debug; then
309 expectations="$expectations --expectations art/tools/libcore_gcstress_debug_failures.txt"
310 fi
Orion Hodson86980812020-11-03 17:10:09 +0000311
312 # Bump pause threshold as long pauses cause explicit gc logging to occur irrespective
313 # of -XX:AlwayLogExplicitGcs:false.
314 vogar_args="$vogar_args --vm-arg -XX:LongPauseLogThreshold=15" # 15 ms (default: 5ms)
Orion Hodson0bbe28c2019-12-12 00:23:09 +0000315 else
Orion Hodsona57e1032021-04-12 12:11:57 +0100316 if $debug; then
317 expectations="$expectations --expectations art/tools/libcore_debug_failures.txt"
318 fi
319
Orion Hodson0bbe28c2019-12-12 00:23:09 +0000320 # We only run this package when user has not specified packages
Victor Chang16f7f8e2021-02-03 17:00:24 +0000321 # to run and not under gcstress / debug as it can cause timeouts. See
322 # b/78228743 and b/178351808.
323 if ! $debug ; then
324 working_packages+=("libcore.highmemorytest")
325 fi
Orion Hodson0bbe28c2019-12-12 00:23:09 +0000326 fi
327
328 if $getrandom; then :; else
329 # Ignore failures in tests that use the system calls not supported
330 # on fugu (Nexus Player, kernel version Linux 3.10).
331 expectations="$expectations --expectations art/tools/libcore_fugu_failures.txt"
332 fi
Roland Levillaind6e2c382019-09-18 16:13:48 +0100333fi
334
Orion Hodsonfcd5a282019-11-18 16:34:45 +0000335if [ ! -t 1 ] ; then
336 # Suppress color codes if not attached to a terminal
337 vogar_args="$vogar_args --no-color"
338fi
339
Orion Hodson656dc822019-12-12 00:06:36 +0000340# Override working_packages if user provided specific packages to
341# test.
342if [[ ${#user_packages[@]} != 0 ]] ; then
343 working_packages=("${user_packages[@]}")
344fi
345
Nicolas Geoffrayb2e7e242014-11-28 14:24:28 +0000346# Run the tests using vogar.
Nicolas Geoffray3cdf8182014-12-01 10:12:15 +0000347echo "Running tests for the following test packages:"
348echo ${working_packages[@]} | tr " " "\n"
Nicolas Geoffray793bed32018-08-22 15:07:40 +0100349
350cmd="vogar $vogar_args $expectations $(cparg $DEPS) ${working_packages[@]}"
351echo "Running $cmd"
Orion Hodson14f30022019-12-11 18:54:51 +0000352$dry_run || eval $cmd