blob: 59c05ecedaddf54b5973120872f706d6171bfa70 [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).
74 --Xgc:gcstress Enable GC stress configuration (device|host only).
75
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"
Roland Levillain9b41e952019-06-19 18:20:07 +0100110 "libcore.libcore.internal"
Andreas Gampee1661362017-11-08 16:42:14 -0800111 "libcore.libcore.io"
112 "libcore.libcore.net"
113 "libcore.libcore.reflect"
114 "libcore.libcore.util"
Roland Levillainda5e0412019-06-19 18:20:32 +0100115 "libcore.libcore.timezone"
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 +0100169gcstress=false
170debug=false
Orion Hodson14f30022019-12-11 18:54:51 +0000171dry_run=false
Nicolas Geoffray622e2e22017-06-15 09:33:01 +0100172
Roland Levillaind6e2c382019-09-18 16:13:48 +0100173# Run tests that use the getrandom() syscall? (Requires Linux 3.17+).
174getrandom=true
175
Orion Hodson0bbe28c2019-12-12 00:23:09 +0000176# Execution mode specifies where to run tests (device|host|jvm).
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000177execution_mode=""
Roland Levillaine4f1c512017-10-30 13:28:28 +0000178
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000179# Default expectations file.
180expectations="--expectations art/tools/libcore_failures.txt"
181
182vogar_args=""
183while [ -n "$1" ]; do
184 case "$1" in
185 --mode=device)
Nicolas Geoffray31e0dc22020-03-20 15:48:09 +0000186 vogar_args="$vogar_args --mode=device"
David Srbecky928d28e2020-04-01 17:50:51 +0100187 vogar_args="$vogar_args --vm-arg -Ximage:/apex/com.android.art/javalib/boot.art"
Nicolas Geoffray31e0dc22020-03-20 15:48:09 +0000188 vogar_args="$vogar_args $(boot_classpath_arg /apex/com.android.art/javalib $BOOT_CLASSPATH_JARS)"
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000189 execution_mode="device"
190 ;;
191 --mode=host)
192 # We explicitly give a wrong path for the image, to ensure vogar
193 # will create a boot image with the default compiler. Note that
194 # giving an existing image on host does not work because of
195 # classpath/resources differences when compiling the boot image.
196 vogar_args="$vogar_args $1 --vm-arg -Ximage:/non/existent/vogar.art"
197 execution_mode="host"
198 ;;
Orion Hodson0bbe28c2019-12-12 00:23:09 +0000199 --mode=jvm)
200 vogar_args="$vogar_args $1"
201 execution_mode="jvm"
202 ;;
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000203 --no-getrandom)
204 getrandom=false
205 ;;
206 --no-jit)
207 use_jit=false
208 ;;
209 --debug)
210 vogar_args="$vogar_args --vm-arg -XXlib:libartd.so --vm-arg -XX:SlowDebug=true"
211 debug=true
212 ;;
213 -Xgc:gcstress)
214 vogar_args="$vogar_args $1"
215 gcstress=true
216 ;;
217 --dry-run)
218 dry_run=true
219 ;;
Orion Hodson656dc822019-12-12 00:06:36 +0000220 --)
221 shift
222 # Assume remaining elements are packages to test.
223 user_packages=("$@")
224 break
225 ;;
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000226 --help)
227 usage
228 exit 1
229 ;;
230 *)
231 vogar_args="$vogar_args $1"
232 ;;
233 esac
234 shift
Nicolas Geoffray9648a632015-06-15 14:35:01 +0100235done
236
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000237if [ -z "$execution_mode" ]; then
238 usage
239 exit 1
240fi
241
242# Default timeout, gets overridden on device under gcstress.
243timeout_secs=480
244
245if [ $execution_mode = "device" ]; then
Roland Levillain08f7c1d2018-05-25 15:34:41 +0100246 # Honor environment variable ART_TEST_CHROOT.
247 if [[ -n "$ART_TEST_CHROOT" ]]; then
248 # Set Vogar's `--chroot` option.
249 vogar_args="$vogar_args --chroot $ART_TEST_CHROOT"
Roland Levillaine4f1c512017-10-30 13:28:28 +0000250 vogar_args="$vogar_args --device-dir=/tmp"
Roland Levillaine4f1c512017-10-30 13:28:28 +0000251 else
Roland Levillain08f7c1d2018-05-25 15:34:41 +0100252 # When not using a chroot on device, set Vogar's work directory to
253 # /data/local/tmp.
Roland Levillaine4f1c512017-10-30 13:28:28 +0000254 vogar_args="$vogar_args --device-dir=/data/local/tmp"
Roland Levillaine4f1c512017-10-30 13:28:28 +0000255 fi
Roland Levillain08f7c1d2018-05-25 15:34:41 +0100256 vogar_args="$vogar_args --vm-command=$android_root/bin/art"
Roland Levillaine4f1c512017-10-30 13:28:28 +0000257
Orion Hodsonaf6a15c2019-12-11 21:48:58 +0000258 # Increase the timeout, as vogar cannot set individual test
259 # timeout when being asked to run packages, and some tests go above
260 # the default timeout.
261 if $gcstress; then
262 if $debug; then
263 timeout_secs=1440
264 else
265 timeout_secs=900
266 fi
267 fi
268fi # $execution_mode = "device"
269
Orion Hodson0bbe28c2019-12-12 00:23:09 +0000270if [ $execution_mode = "device" -o $execution_mode = "host" ]; then
271 # Add timeout to vogar command-line.
272 vogar_args="$vogar_args --timeout $timeout_secs"
Nicolas Geoffrayf794ad72015-09-11 12:08:49 +0100273
Orion Hodson0bbe28c2019-12-12 00:23:09 +0000274 # set the toolchain to use.
275 vogar_args="$vogar_args --toolchain d8 --language CUR"
Neil Fullerb8300fc2016-02-10 13:09:10 +0000276
Orion Hodson0bbe28c2019-12-12 00:23:09 +0000277 # JIT settings.
278 if $use_jit; then
279 vogar_args="$vogar_args --vm-arg -Xcompiler-option --vm-arg --compiler-filter=quicken"
Orion Hodson938ead32019-12-10 13:01:40 +0000280 fi
Orion Hodson0bbe28c2019-12-12 00:23:09 +0000281 vogar_args="$vogar_args --vm-arg -Xusejit:$use_jit"
Orion Hodson938ead32019-12-10 13:01:40 +0000282
Orion Hodson0bbe28c2019-12-12 00:23:09 +0000283 # gcstress may lead to timeouts, so we need dedicated expectations files for it.
284 if $gcstress; then
285 expectations="$expectations --expectations art/tools/libcore_gcstress_failures.txt"
286 if $debug; then
287 expectations="$expectations --expectations art/tools/libcore_gcstress_debug_failures.txt"
288 fi
289 else
290 # We only run this package when user has not specified packages
291 # to run and not under gcstress as it can cause timeouts. See
292 # b/78228743.
293 working_packages+=("libcore.libcore.icu")
294 fi
295
296 if $getrandom; then :; else
297 # Ignore failures in tests that use the system calls not supported
298 # on fugu (Nexus Player, kernel version Linux 3.10).
299 expectations="$expectations --expectations art/tools/libcore_fugu_failures.txt"
300 fi
Roland Levillaind6e2c382019-09-18 16:13:48 +0100301fi
302
Orion Hodsonfcd5a282019-11-18 16:34:45 +0000303if [ ! -t 1 ] ; then
304 # Suppress color codes if not attached to a terminal
305 vogar_args="$vogar_args --no-color"
306fi
307
Orion Hodson656dc822019-12-12 00:06:36 +0000308# Override working_packages if user provided specific packages to
309# test.
310if [[ ${#user_packages[@]} != 0 ]] ; then
311 working_packages=("${user_packages[@]}")
312fi
313
Nicolas Geoffrayb2e7e242014-11-28 14:24:28 +0000314# Run the tests using vogar.
Nicolas Geoffray3cdf8182014-12-01 10:12:15 +0000315echo "Running tests for the following test packages:"
316echo ${working_packages[@]} | tr " " "\n"
Nicolas Geoffray793bed32018-08-22 15:07:40 +0100317
318cmd="vogar $vogar_args $expectations $(cparg $DEPS) ${working_packages[@]}"
319echo "Running $cmd"
Orion Hodson14f30022019-12-11 18:54:51 +0000320$dry_run || eval $cmd