blob: cc22e6e35310b91a6666cffb07a15828c3ea49da [file] [log] [blame]
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001#!/bin/bash
2#
3# Runner for an individual run-test.
4
Stelios Ioannou3a014e32021-06-25 15:15:32 +01005# Check how many colors the terminal can display.
6ncolors=$(tput colors 2>/dev/null)
7
8# Check that stdout is connected to a terminal and that we have at least 1 color.
9# This ensures that if the stdout is not connected to a terminal and instead
10# the stdout will be used for a log, it will not append the color characters.
11if [[ -t 1 && ${ncolors} && ${ncolors} -ge 1 ]]; then
12 bold_red="$(tput bold)$(tput setaf 1)"
13fi
14
15readonly bold_red
16
17error_msg() {
18 echo -e "${bold_red}ERROR: $@" 1>&2
19}
20
Roland Levillain72f67742019-03-06 15:48:08 +000021if [[ -z "$ANDROID_BUILD_TOP" ]]; then
Stelios Ioannou3a014e32021-06-25 15:15:32 +010022 error_msg 'ANDROID_BUILD_TOP environment variable is empty; did you forget to run `lunch`?'
Roland Levillain72f67742019-03-06 15:48:08 +000023 exit 1
24fi
25
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010026msg() {
27 if [ "$QUIET" = "n" ]; then
28 echo "$@"
29 fi
30}
31
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000032ANDROID_ROOT="/system"
Martin Stjernholme58624f2019-09-20 15:53:40 +010033ANDROID_ART_ROOT="/apex/com.android.art"
Victor Chang64611242019-07-05 16:32:41 +010034ANDROID_I18N_ROOT="/apex/com.android.i18n"
Neil Fuller26a5dd62019-03-13 15:16:35 +000035ANDROID_TZDATA_ROOT="/apex/com.android.tzdata"
Vladimir Markobe0d3cf2020-02-12 10:52:22 +000036ARCHITECTURES_32="(arm|x86|none)"
37ARCHITECTURES_64="(arm64|x86_64|none)"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010038ARCHITECTURES_PATTERN="${ARCHITECTURES_32}"
Roland Levillain72f67742019-03-06 15:48:08 +000039GET_DEVICE_ISA_BITNESS_FLAG="--32"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000040BOOT_IMAGE=""
Roland Levillain76cfe612017-10-30 13:14:28 +000041CHROOT=
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010042COMPILE_FLAGS=""
43DALVIKVM="dalvikvm32"
44DEBUGGER="n"
Alex Light54dabfb2018-09-19 16:29:09 -070045WITH_AGENT=()
Alex Lightc281ba52017-10-11 11:35:55 -070046DEBUGGER_AGENT=""
47WRAP_DEBUGGER_AGENT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010048DEV_MODE="n"
Nicolas Geoffrayb0c6cb52020-04-20 15:12:42 +010049DEX2OAT_NDEBUG_BINARY="dex2oat32"
50DEX2OAT_DEBUG_BINARY="dex2oatd32"
Alex Light8a0e0332015-10-26 10:11:58 -070051EXPERIMENTAL=""
Nicolas Geoffray90355fe2017-02-20 09:25:40 +000052FALSE_BIN="false"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010053FLAGS=""
Alex Light7233c7e2016-07-28 10:07:45 -070054ANDROID_FLAGS=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010055GDB=""
Nicolas Geoffraybaf91022014-10-08 09:56:45 +010056GDB_ARGS=""
Stelios Ioannou816b0da2021-06-03 13:25:50 +010057GDB_DEX2OAT=""
58GDB_DEX2OAT_ARGS=""
Alex Lighte4b4a182019-02-12 14:19:49 -080059GDBSERVER_DEVICE="gdbserver"
60GDBSERVER_HOST="gdbserver"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010061HAVE_IMAGE="y"
62HOST="n"
Alex Light680cbf22018-10-31 11:00:19 -070063BIONIC="n"
64CREATE_ANDROID_ROOT="n"
Alex Light20802ca2018-12-05 15:36:03 -080065USE_ZIPAPEX="n"
66ZIPAPEX_LOC=""
Alex Light6f342dd2019-03-27 17:15:42 +000067USE_EXTRACTED_ZIPAPEX="n"
68EXTRACTED_ZIPAPEX_LOC=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010069INTERPRETER="n"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080070JIT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010071INVOKE_WITH=""
Alex Lighte06b6342017-01-05 14:37:21 -080072IS_JVMTI_TEST="n"
Alex Light280e6c32020-03-03 13:52:07 -080073ADD_LIBDIR_ARGUMENTS="n"
Martin Stjernholm0d0f8df2021-04-28 16:47:01 +010074SUFFIX64=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010075ISA=x86
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000076LIBRARY_DIRECTORY="lib"
Colin Crossafd3c9e2016-09-16 13:47:21 -070077TEST_DIRECTORY="nativetest"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000078MAIN=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010079OPTIMIZE="y"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010080PREBUILD="y"
81QUIET="n"
Nicolas Geoffray94e25db2017-01-27 14:54:28 +000082RELOCATE="n"
Jeff Hao207a37d2014-10-29 17:24:25 -070083SECONDARY_DEX=""
David Srbecky352482c2019-10-16 15:59:52 +010084TIME_OUT="n" # "n" (disabled), "timeout" (use timeout), "gdb" (use gdb)
Andreas Gampe148c1602019-06-10 16:47:46 -070085TIMEOUT_DUMPER=signal_dumper
Andreas Gampe6ad30a22019-09-12 15:12:36 -070086# Values in seconds.
Martin Stjernholmcb497cf2019-09-27 18:42:55 +010087TIME_OUT_EXTRA=0
Andreas Gampe6ad30a22019-09-12 15:12:36 -070088TIME_OUT_VALUE=
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010089USE_GDB="n"
Alex Lighte4b4a182019-02-12 14:19:49 -080090USE_GDBSERVER="n"
91GDBSERVER_PORT=":5039"
Stelios Ioannou816b0da2021-06-03 13:25:50 +010092USE_GDB_DEX2OAT="n"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +010093USE_JVM="n"
Alex Lightc281ba52017-10-11 11:35:55 -070094USE_JVMTI="n"
Igor Murashkin7617abd2015-07-10 18:27:47 -070095VERIFY="y" # y=yes,n=no,s=softfail
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010096ZYGOTE=""
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -070097DEX_VERIFY=""
Andreas Gampe4d2ef332015-08-05 09:24:45 -070098INSTRUCTION_SET_FEATURES=""
Mathieu Chartier031768a2015-08-27 10:25:02 -070099ARGS=""
David Brazdilfeb22822019-02-13 21:25:57 +0000100VDEX_ARGS=""
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700101EXTERNAL_LOG_TAGS="n" # if y respect externally set ANDROID_LOG_TAGS.
102DRY_RUN="n" # if y prepare to run the test but don't run it.
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000103TEST_VDEX="n"
Nicolas Geoffray327cfcf2021-10-12 14:13:25 +0100104TEST_DEX2OAT_DM="n"
105TEST_RUNTIME_DM="n"
Alex Lighte06b6342017-01-05 14:37:21 -0800106TEST_IS_NDEBUG="n"
Calin Juravle857f0582016-12-20 14:36:59 +0000107APP_IMAGE="y"
Andreas Gampe038a1982020-03-11 23:06:42 +0000108SECONDARY_APP_IMAGE="y"
109SECONDARY_CLASS_LOADER_CONTEXT=""
110SECONDARY_COMPILATION="y"
Alex Light8f2c6d42017-04-10 16:27:35 -0700111JVMTI_STRESS="n"
Alex Lightc38c3692017-06-27 15:45:14 -0700112JVMTI_STEP_STRESS="n"
Alex Light43e935d2017-06-19 15:40:40 -0700113JVMTI_FIELD_STRESS="n"
Alex Lightb7edcda2017-04-27 13:20:31 -0700114JVMTI_TRACE_STRESS="n"
115JVMTI_REDEFINE_STRESS="n"
Calin Juravle13439f02017-02-21 01:17:21 -0800116PROFILE="n"
Jeff Hao002b9312017-03-27 16:23:08 -0700117RANDOM_PROFILE="n"
Alex Light483208d2017-09-26 09:31:17 -0700118# The normal dex2oat timeout.
Shubham Ajmeraf97cbd62017-10-11 10:00:57 -0700119DEX2OAT_TIMEOUT="300" # 5 mins
Alex Light483208d2017-09-26 09:31:17 -0700120# The *hard* timeout where we really start trying to kill the dex2oat.
Shubham Ajmeraf97cbd62017-10-11 10:00:57 -0700121DEX2OAT_RT_TIMEOUT="360" # 6 mins
Alex Light8d94ddd2019-12-18 11:13:03 -0800122CREATE_RUNNER="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100123
Igor Murashkin271a0f82017-02-14 21:14:17 +0000124# if "y", run 'sync' before dalvikvm to make sure all files from
125# build step (e.g. dex2oat) were finished writing.
126SYNC_BEFORE_RUN="n"
127
Andreas Gampe1c5b42f2017-06-15 18:20:45 -0700128# When running a debug build, we want to run with all checks.
129ANDROID_FLAGS="${ANDROID_FLAGS} -XX:SlowDebug=true"
Andreas Gampee8f74ca2018-01-02 09:26:16 -0800130# The same for dex2oatd, both prebuild and runtime-driven.
131ANDROID_FLAGS="${ANDROID_FLAGS} -Xcompiler-option --runtime-arg -Xcompiler-option -XX:SlowDebug=true"
132COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -XX:SlowDebug=true"
Andreas Gampe1c5b42f2017-06-15 18:20:45 -0700133
David Srbecky4fa07a52020-03-31 20:52:09 +0100134# Let the compiler and runtime know that we are running tests.
135COMPILE_FLAGS="${COMPILE_FLAGS} --compile-art-test"
Roland Levillainb7724c42020-04-21 16:51:54 +0100136ANDROID_FLAGS="${ANDROID_FLAGS} -Xcompiler-option --compile-art-test"
David Srbecky4fa07a52020-03-31 20:52:09 +0100137
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100138while true; do
139 if [ "x$1" = "x--quiet" ]; then
140 QUIET="y"
141 shift
Alex Light483208d2017-09-26 09:31:17 -0700142 elif [ "x$1" = "x--dex2oat-rt-timeout" ]; then
143 shift
144 if [ "x$1" = "x" ]; then
Stelios Ioannou3a014e32021-06-25 15:15:32 +0100145 error_msg "$0 missing argument to --dex2oat-rt-timeout"
Alex Light483208d2017-09-26 09:31:17 -0700146 exit 1
147 fi
148 DEX2OAT_RT_TIMEOUT="$1"
149 shift
150 elif [ "x$1" = "x--dex2oat-timeout" ]; then
151 shift
152 if [ "x$1" = "x" ]; then
Stelios Ioannou3a014e32021-06-25 15:15:32 +0100153 error_msg "$0 missing argument to --dex2oat-timeout"
Alex Light483208d2017-09-26 09:31:17 -0700154 exit 1
155 fi
156 DEX2OAT_TIMEOUT="$1"
157 shift
Alex Lighte06b6342017-01-05 14:37:21 -0800158 elif [ "x$1" = "x--jvmti" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700159 USE_JVMTI="y"
Alex Lighte06b6342017-01-05 14:37:21 -0800160 IS_JVMTI_TEST="y"
Andreas Gampe038a1982020-03-11 23:06:42 +0000161 # Secondary images block some tested behavior.
162 SECONDARY_APP_IMAGE="n"
Alex Lighte06b6342017-01-05 14:37:21 -0800163 shift
Alex Light280e6c32020-03-03 13:52:07 -0800164 elif [ "x$1" = "x--add-libdir-argument" ]; then
165 ADD_LIBDIR_ARGUMENTS="y"
166 shift
Alex Lightfaf90b62016-08-12 14:43:48 -0700167 elif [ "x$1" = "x-O" ]; then
Alex Lighte06b6342017-01-05 14:37:21 -0800168 TEST_IS_NDEBUG="y"
Alex Lightfaf90b62016-08-12 14:43:48 -0700169 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100170 elif [ "x$1" = "x--lib" ]; then
171 shift
172 if [ "x$1" = "x" ]; then
Stelios Ioannou3a014e32021-06-25 15:15:32 +0100173 error_msg "$0 missing argument to --lib"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100174 exit 1
175 fi
176 LIB="$1"
177 shift
Alex Light97acf192016-03-17 09:59:38 -0700178 elif [ "x$1" = "x--gc-stress" ]; then
David Srbecky7021c132019-10-04 12:56:22 +0100179 # Give an extra 20 mins if we are gc-stress.
180 TIME_OUT_EXTRA=$((${TIME_OUT_EXTRA} + 1200))
Alex Light97acf192016-03-17 09:59:38 -0700181 shift
Mathieu Chartier031768a2015-08-27 10:25:02 -0700182 elif [ "x$1" = "x--testlib" ]; then
183 shift
184 if [ "x$1" = "x" ]; then
Stelios Ioannou3a014e32021-06-25 15:15:32 +0100185 error_msg "$0 missing argument to --testlib"
Mathieu Chartier031768a2015-08-27 10:25:02 -0700186 exit 1
187 fi
Mathieu Chartierde286fd2015-09-03 18:10:29 -0700188 ARGS="${ARGS} $1"
Mathieu Chartier031768a2015-08-27 10:25:02 -0700189 shift
David Srbecky52886112016-01-22 13:56:47 +0000190 elif [ "x$1" = "x--args" ]; then
191 shift
192 if [ "x$1" = "x" ]; then
Stelios Ioannou3a014e32021-06-25 15:15:32 +0100193 error_msg "$0 missing argument to --args"
David Srbecky52886112016-01-22 13:56:47 +0000194 exit 1
195 fi
196 ARGS="${ARGS} $1"
197 shift
Alex Lighte2ddce32019-05-22 17:08:35 +0000198 elif [ "x$1" = "x--compiler-only-option" ]; then
199 shift
200 option="$1"
201 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
202 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100203 elif [ "x$1" = "x-Xcompiler-option" ]; then
204 shift
205 option="$1"
206 FLAGS="${FLAGS} -Xcompiler-option $option"
207 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
208 shift
Alex Light8d94ddd2019-12-18 11:13:03 -0800209 elif [ "x$1" = "x--create-runner" ]; then
210 CREATE_RUNNER="y"
211 shift
Alex Light7233c7e2016-07-28 10:07:45 -0700212 elif [ "x$1" = "x--android-runtime-option" ]; then
213 shift
214 option="$1"
215 ANDROID_FLAGS="${ANDROID_FLAGS} $option"
216 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100217 elif [ "x$1" = "x--runtime-option" ]; then
218 shift
219 option="$1"
220 FLAGS="${FLAGS} $option"
Martin Stjernholmcb497cf2019-09-27 18:42:55 +0100221 if [ "x$option" = "x-Xmethod-trace" ]; then
Martin Stjernholm30677102019-10-01 12:54:10 +0100222 # Method tracing can slow some tests down a lot, in particular
223 # 530-checker-lse2.
224 TIME_OUT_EXTRA=$((${TIME_OUT_EXTRA} + 1200))
Martin Stjernholmcb497cf2019-09-27 18:42:55 +0100225 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100226 shift
227 elif [ "x$1" = "x--boot" ]; then
228 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000229 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100230 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100231 elif [ "x$1" = "x--relocate" ]; then
232 RELOCATE="y"
233 shift
234 elif [ "x$1" = "x--no-relocate" ]; then
235 RELOCATE="n"
236 shift
237 elif [ "x$1" = "x--prebuild" ]; then
238 PREBUILD="y"
239 shift
Mathieu Chartierdcd56c92017-11-20 20:30:24 -0800240 elif [ "x$1" = "x--compact-dex-level" ]; then
241 shift
242 COMPILE_FLAGS="${COMPILE_FLAGS} --compact-dex-level=$1"
243 shift
Alex Lightb7edcda2017-04-27 13:20:31 -0700244 elif [ "x$1" = "x--jvmti-redefine-stress" ]; then
245 # APP_IMAGE doesn't really work with jvmti redefine stress
Alex Lightc281ba52017-10-11 11:35:55 -0700246 USE_JVMTI="y"
Alex Light8f2c6d42017-04-10 16:27:35 -0700247 APP_IMAGE="n"
Andreas Gampe038a1982020-03-11 23:06:42 +0000248 SECONDARY_APP_IMAGE="n"
Alex Light8f2c6d42017-04-10 16:27:35 -0700249 JVMTI_STRESS="y"
Alex Lightb7edcda2017-04-27 13:20:31 -0700250 JVMTI_REDEFINE_STRESS="y"
251 shift
Alex Lightc38c3692017-06-27 15:45:14 -0700252 elif [ "x$1" = "x--jvmti-step-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700253 USE_JVMTI="y"
Alex Lightc38c3692017-06-27 15:45:14 -0700254 JVMTI_STRESS="y"
255 JVMTI_STEP_STRESS="y"
256 shift
Alex Light43e935d2017-06-19 15:40:40 -0700257 elif [ "x$1" = "x--jvmti-field-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700258 USE_JVMTI="y"
Alex Light43e935d2017-06-19 15:40:40 -0700259 JVMTI_STRESS="y"
260 JVMTI_FIELD_STRESS="y"
261 shift
Alex Lightb7edcda2017-04-27 13:20:31 -0700262 elif [ "x$1" = "x--jvmti-trace-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700263 USE_JVMTI="y"
Alex Lightb7edcda2017-04-27 13:20:31 -0700264 JVMTI_STRESS="y"
265 JVMTI_TRACE_STRESS="y"
Alex Light8f2c6d42017-04-10 16:27:35 -0700266 shift
Calin Juravle857f0582016-12-20 14:36:59 +0000267 elif [ "x$1" = "x--no-app-image" ]; then
268 APP_IMAGE="n"
269 shift
Andreas Gampe038a1982020-03-11 23:06:42 +0000270 elif [ "x$1" = "x--no-secondary-app-image" ]; then
271 SECONDARY_APP_IMAGE="n"
272 shift
273 elif [ "x$1" = "x--secondary-class-loader-context" ]; then
274 shift
275 SECONDARY_CLASS_LOADER_CONTEXT="$1"
276 shift
277 elif [ "x$1" = "x--no-secondary-compilation" ]; then
278 SECONDARY_COMPILATION="n"
279 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100280 elif [ "x$1" = "x--host" ]; then
281 HOST="y"
Roland Levillainb59f5fb2020-02-19 16:22:48 +0000282 ANDROID_ROOT="${ANDROID_HOST_OUT}"
283 ANDROID_ART_ROOT="${ANDROID_HOST_OUT}/com.android.art"
284 ANDROID_I18N_ROOT="${ANDROID_HOST_OUT}/com.android.i18n"
285 ANDROID_TZDATA_ROOT="${ANDROID_HOST_OUT}/com.android.tzdata"
Nicolas Geoffrayb0c6cb52020-04-20 15:12:42 +0100286 # On host, we default to using the symlink, as the PREFER_32BIT
287 # configuration is the only configuration building a 32bit version of
288 # dex2oat.
289 DEX2OAT_DEBUG_BINARY="dex2oatd"
290 DEX2OAT_NDEBUG_BINARY="dex2oat"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100291 shift
Alex Light680cbf22018-10-31 11:00:19 -0700292 elif [ "x$1" = "x--bionic" ]; then
293 BIONIC="y"
294 # We need to create an ANDROID_ROOT because currently we cannot create
295 # the frameworks/libcore with linux_bionic so we need to use the normal
296 # host ones which are in a different location.
297 CREATE_ANDROID_ROOT="y"
298 shift
Alex Light6f342dd2019-03-27 17:15:42 +0000299 elif [ "x$1" = "x--runtime-extracted-zipapex" ]; then
300 shift
301 USE_EXTRACTED_ZIPAPEX="y"
302 EXTRACTED_ZIPAPEX_LOC="$1"
303 shift
Alex Light20802ca2018-12-05 15:36:03 -0800304 elif [ "x$1" = "x--runtime-zipapex" ]; then
305 shift
306 USE_ZIPAPEX="y"
307 ZIPAPEX_LOC="$1"
Alex Light907001d2019-01-17 00:16:04 +0000308 # TODO (b/119942078): Currently apex does not support
309 # symlink_preferred_arch so we will not have a dex2oatd to execute and
310 # need to manually provide
311 # dex2oatd64.
312 DEX2OAT_DEBUG_BINARY="dex2oatd64"
Alex Light20802ca2018-12-05 15:36:03 -0800313 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100314 elif [ "x$1" = "x--no-prebuild" ]; then
315 PREBUILD="n"
316 shift
317 elif [ "x$1" = "x--no-image" ]; then
318 HAVE_IMAGE="n"
319 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700320 elif [ "x$1" = "x--secondary" ]; then
321 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
Calin Juravle175dc732015-08-25 15:42:32 +0100322 # Enable cfg-append to make sure we get the dump for both dex files.
323 # (otherwise the runtime compilation of the secondary dex will overwrite
Roland Levillainb0103ca2016-11-01 14:48:47 +0000324 # the dump of the first one).
Calin Juravle175dc732015-08-25 15:42:32 +0100325 FLAGS="${FLAGS} -Xcompiler-option --dump-cfg-append"
326 COMPILE_FLAGS="${COMPILE_FLAGS} --dump-cfg-append"
Jeff Hao207a37d2014-10-29 17:24:25 -0700327 shift
Alex Light0e151e72017-10-25 10:50:35 -0700328 elif [ "x$1" = "x--with-agent" ]; then
329 shift
330 USE_JVMTI="y"
Alex Light54dabfb2018-09-19 16:29:09 -0700331 WITH_AGENT+=("$1")
Alex Light0e151e72017-10-25 10:50:35 -0700332 shift
Alex Lightc281ba52017-10-11 11:35:55 -0700333 elif [ "x$1" = "x--debug-wrap-agent" ]; then
334 WRAP_DEBUGGER_AGENT="y"
335 shift
336 elif [ "x$1" = "x--debug-agent" ]; then
337 shift
338 DEBUGGER="agent"
339 USE_JVMTI="y"
340 DEBUGGER_AGENT="$1"
341 TIME_OUT="n"
342 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100343 elif [ "x$1" = "x--debug" ]; then
Alex Lightfc588092020-01-23 15:39:08 -0800344 USE_JVMTI="y"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100345 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800346 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100347 shift
Alex Lighte4b4a182019-02-12 14:19:49 -0800348 elif [ "x$1" = "x--gdbserver-port" ]; then
349 shift
350 GDBSERVER_PORT=$1
351 shift
352 elif [ "x$1" = "x--gdbserver-bin" ]; then
353 shift
354 GDBSERVER_HOST=$1
355 GDBSERVER_DEVICE=$1
356 shift
357 elif [ "x$1" = "x--gdbserver" ]; then
358 USE_GDBSERVER="y"
359 DEV_MODE="y"
360 TIME_OUT="n"
Alex Lighte4b4a182019-02-12 14:19:49 -0800361 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100362 elif [ "x$1" = "x--gdb" ]; then
363 USE_GDB="y"
364 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800365 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100366 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700367 elif [ "x$1" = "x--gdb-arg" ]; then
368 shift
369 gdb_arg="$1"
370 GDB_ARGS="${GDB_ARGS} $gdb_arg"
371 shift
Stelios Ioannou816b0da2021-06-03 13:25:50 +0100372 elif [ "x$1" = "x--gdb-dex2oat" ]; then
373 USE_GDB_DEX2OAT="y"
374 DEV_MODE="y"
375 TIME_OUT="n"
376 shift
377 elif [ "x$1" = "x--gdb-dex2oat-args" ]; then
378 shift
379 for arg in $(echo $1 | tr ";" " "); do
380 GDB_DEX2OAT_ARGS+="$arg "
381 done
382 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100383 elif [ "x$1" = "x--zygote" ]; then
384 ZYGOTE="-Xzygote"
385 msg "Spawning from zygote"
386 shift
387 elif [ "x$1" = "x--dev" ]; then
388 DEV_MODE="y"
389 shift
390 elif [ "x$1" = "x--interpreter" ]; then
391 INTERPRETER="y"
392 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800393 elif [ "x$1" = "x--jit" ]; then
394 JIT="y"
395 shift
Nicolas Geoffrayacc56ac2018-10-09 08:45:24 +0100396 elif [ "x$1" = "x--baseline" ]; then
397 FLAGS="${FLAGS} -Xcompiler-option --baseline"
Nicolas Geoffray9b195cc2019-04-02 08:29:00 +0100398 COMPILE_FLAGS="${COMPILE_FLAGS} --baseline"
Nicolas Geoffrayacc56ac2018-10-09 08:45:24 +0100399 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100400 elif [ "x$1" = "x--jvm" ]; then
401 USE_JVM="y"
402 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100403 elif [ "x$1" = "x--invoke-with" ]; then
404 shift
405 if [ "x$1" = "x" ]; then
Stelios Ioannou3a014e32021-06-25 15:15:32 +0100406 error_msg "$0 missing argument to --invoke-with"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100407 exit 1
408 fi
409 if [ "x$INVOKE_WITH" = "x" ]; then
410 INVOKE_WITH="$1"
411 else
412 INVOKE_WITH="$INVOKE_WITH $1"
413 fi
414 shift
415 elif [ "x$1" = "x--no-verify" ]; then
416 VERIFY="n"
417 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700418 elif [ "x$1" = "x--verify-soft-fail" ]; then
419 VERIFY="s"
420 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100421 elif [ "x$1" = "x--no-optimize" ]; then
422 OPTIMIZE="n"
423 shift
Roland Levillain76cfe612017-10-30 13:14:28 +0000424 elif [ "x$1" = "x--chroot" ]; then
425 shift
426 CHROOT="$1"
427 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000428 elif [ "x$1" = "x--android-root" ]; then
429 shift
430 ANDROID_ROOT="$1"
431 shift
Victor Chang64611242019-07-05 16:32:41 +0100432 elif [ "x$1" = "x--android-i18n-root" ]; then
433 shift
434 ANDROID_I18N_ROOT="$1"
435 shift
Martin Stjernholme58624f2019-09-20 15:53:40 +0100436 elif [ "x$1" = "x--android-art-root" ]; then
Roland Levillain28076142019-01-10 16:39:25 +0000437 shift
Martin Stjernholme58624f2019-09-20 15:53:40 +0100438 ANDROID_ART_ROOT="$1"
Roland Levillain28076142019-01-10 16:39:25 +0000439 shift
Neil Fuller26a5dd62019-03-13 15:16:35 +0000440 elif [ "x$1" = "x--android-tzdata-root" ]; then
441 shift
442 ANDROID_TZDATA_ROOT="$1"
443 shift
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700444 elif [ "x$1" = "x--instruction-set-features" ]; then
445 shift
446 INSTRUCTION_SET_FEATURES="$1"
447 shift
Mathieu Chartier2576be22016-05-24 10:24:53 -0700448 elif [ "x$1" = "x--timeout" ]; then
449 shift
450 TIME_OUT_VALUE="$1"
451 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100452 elif [ "x$1" = "x--" ]; then
453 shift
454 break
455 elif [ "x$1" = "x--64" ]; then
Martin Stjernholm0d0f8df2021-04-28 16:47:01 +0100456 SUFFIX64="64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100457 ISA="x86_64"
Alex Lighte4b4a182019-02-12 14:19:49 -0800458 GDBSERVER_DEVICE="gdbserver64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100459 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000460 LIBRARY_DIRECTORY="lib64"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700461 TEST_DIRECTORY="nativetest64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100462 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
Roland Levillain72f67742019-03-06 15:48:08 +0000463 GET_DEVICE_ISA_BITNESS_FLAG="--64"
Nicolas Geoffrayb0c6cb52020-04-20 15:12:42 +0100464 DEX2OAT_NDEBUG_BINARY="dex2oat64"
465 DEX2OAT_DEBUG_BINARY="dex2oatd64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100466 shift
Alex Light8a0e0332015-10-26 10:11:58 -0700467 elif [ "x$1" = "x--experimental" ]; then
468 if [ "$#" -lt 2 ]; then
Stelios Ioannou3a014e32021-06-25 15:15:32 +0100469 error_msg "missing --experimental option"
Alex Light8a0e0332015-10-26 10:11:58 -0700470 exit 1
471 fi
472 EXPERIMENTAL="$EXPERIMENTAL $2"
473 shift 2
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700474 elif [ "x$1" = "x--external-log-tags" ]; then
475 EXTERNAL_LOG_TAGS="y"
476 shift
477 elif [ "x$1" = "x--dry-run" ]; then
478 DRY_RUN="y"
479 shift
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000480 elif [ "x$1" = "x--vdex" ]; then
481 TEST_VDEX="y"
482 shift
Nicolas Geoffray327cfcf2021-10-12 14:13:25 +0100483 elif [ "x$1" = "x--dex2oat-dm" ]; then
484 TEST_DEX2OAT_DM="y"
485 shift
486 elif [ "x$1" = "x--runtime-dm" ]; then
487 TEST_RUNTIME_DM="y"
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000488 shift
Nicolas Geoffray74981052017-01-16 17:54:09 +0000489 elif [ "x$1" = "x--vdex-filter" ]; then
490 shift
491 option="$1"
David Brazdilfeb22822019-02-13 21:25:57 +0000492 VDEX_ARGS="${VDEX_ARGS} --compiler-filter=$option"
493 shift
494 elif [ "x$1" = "x--vdex-arg" ]; then
495 shift
496 VDEX_ARGS="${VDEX_ARGS} $1"
Nicolas Geoffray74981052017-01-16 17:54:09 +0000497 shift
Igor Murashkin271a0f82017-02-14 21:14:17 +0000498 elif [ "x$1" = "x--sync" ]; then
499 SYNC_BEFORE_RUN="y"
500 shift
Calin Juravle13439f02017-02-21 01:17:21 -0800501 elif [ "x$1" = "x--profile" ]; then
502 PROFILE="y"
503 shift
Jeff Hao002b9312017-03-27 16:23:08 -0700504 elif [ "x$1" = "x--random-profile" ]; then
505 RANDOM_PROFILE="y"
506 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100507 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Stelios Ioannou3a014e32021-06-25 15:15:32 +0100508 error_msg "unknown $0 option: $1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100509 exit 1
510 else
511 break
512 fi
513done
514
Roland Levillainb59f5fb2020-02-19 16:22:48 +0000515# HACK: Force the use of `signal_dumper` on host.
Roland Levillain505e56b2019-11-20 08:49:24 +0000516if [[ "$HOST" = "y" ]]; then
517 TIME_OUT="timeout"
518fi
519
Andreas Gampe6ad30a22019-09-12 15:12:36 -0700520# If you change this, update the timeout in testrunner.py as well.
521if [ -z "$TIME_OUT_VALUE" ] ; then
522 # 10 minutes is the default.
523 TIME_OUT_VALUE=600
524
525 # For sanitized builds use a larger base.
526 # TODO: Consider sanitized target builds?
527 if [ "x$SANITIZE_HOST" != "x" ] ; then
528 TIME_OUT_VALUE=1500 # 25 minutes.
529 fi
530
Martin Stjernholmcb497cf2019-09-27 18:42:55 +0100531 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + ${TIME_OUT_EXTRA}))
Andreas Gampe6ad30a22019-09-12 15:12:36 -0700532fi
533
Andreas Gampe29bfb0c2019-09-12 15:17:43 -0700534# Escape hatch for slow hosts or devices. Accept an environment variable as a timeout factor.
535if [ ! -z "$ART_TIME_OUT_MULTIPLIER" ] ; then
Martin Stjernholm82e61e92019-09-30 02:43:18 +0000536 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} * ${ART_TIME_OUT_MULTIPLIER}))
Andreas Gampe29bfb0c2019-09-12 15:17:43 -0700537fi
538
Roland Levillain76cfe612017-10-30 13:14:28 +0000539# The DEX_LOCATION with the chroot prefix, if any.
540CHROOT_DEX_LOCATION="$CHROOT$DEX_LOCATION"
541
Roland Levillain72f67742019-03-06 15:48:08 +0000542# If running on device, determine the ISA of the device.
Roland Levillainb7724c42020-04-21 16:51:54 +0100543if [ "$HOST" = "n" -a "$USE_JVM" = "n" ]; then
Roland Levillain72f67742019-03-06 15:48:08 +0000544 ISA=$("$ANDROID_BUILD_TOP/art/test/utils/get-device-isa" "$GET_DEVICE_ISA_BITNESS_FLAG")
545fi
546
Alex Light8a0e0332015-10-26 10:11:58 -0700547if [ "$USE_JVM" = "n" ]; then
Alex Light7233c7e2016-07-28 10:07:45 -0700548 FLAGS="${FLAGS} ${ANDROID_FLAGS}"
Alex Lightbaac7e42018-06-08 15:30:11 +0000549 # we don't want to be trying to get adbconnections since the plugin might
550 # not have been built.
551 FLAGS="${FLAGS} -XjdwpProvider:none"
Alex Light8a0e0332015-10-26 10:11:58 -0700552 for feature in ${EXPERIMENTAL}; do
Alex Lightfa022852015-10-28 09:13:20 -0700553 FLAGS="${FLAGS} -Xexperimental:${feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:${feature}"
Alex Light8a0e0332015-10-26 10:11:58 -0700554 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xexperimental:${feature}"
555 done
556fi
557
Alex Light680cbf22018-10-31 11:00:19 -0700558if [ "$CREATE_ANDROID_ROOT" = "y" ]; then
559 ANDROID_ROOT=$DEX_LOCATION/android-root
560fi
561
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100562if [ "x$1" = "x" ] ; then
563 MAIN="Main"
564else
565 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700566 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100567fi
568
569if [ "$ZYGOTE" = "" ]; then
570 if [ "$OPTIMIZE" = "y" ]; then
571 if [ "$VERIFY" = "y" ]; then
572 DEX_OPTIMIZE="-Xdexopt:verified"
573 else
574 DEX_OPTIMIZE="-Xdexopt:all"
575 fi
576 msg "Performing optimizations"
577 else
578 DEX_OPTIMIZE="-Xdexopt:none"
579 msg "Skipping optimizations"
580 fi
581
582 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100583 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100584 msg "Performing verification"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700585 elif [ "$VERIFY" = "s" ]; then
586 JVM_VERIFY_ARG="Xverify:all"
587 DEX_VERIFY="-Xverify:softfail"
588 msg "Forcing verification to be soft fail"
589 else # VERIFY = "n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100590 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100591 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100592 msg "Skipping verification"
593 fi
594fi
595
596msg "------------------------------"
597
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100598if [ "$DEBUGGER" = "y" ]; then
599 # Use this instead for ddms and connect by running 'ddms':
Alex Lightfc588092020-01-23 15:39:08 -0800600 # DEBUGGER_OPTS="-XjdwpOptions=server=y,suspend=y -XjdwpProvider:adbconnection"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100601 # TODO: add a separate --ddms option?
602
603 PORT=12345
604 msg "Waiting for jdb to connect:"
605 if [ "$HOST" = "n" ]; then
606 msg " adb forward tcp:$PORT tcp:$PORT"
607 fi
608 msg " jdb -attach localhost:$PORT"
Alex Light264a4862018-01-31 16:47:58 +0000609 if [ "$USE_JVM" = "n" ]; then
Alex Lightfc588092020-01-23 15:39:08 -0800610 # Use the default libjdwp agent. Use --debug-agent to use a custom one.
611 DEBUGGER_OPTS="-agentpath:libjdwp.so=transport=dt_socket,address=$PORT,server=y,suspend=y -XjdwpProvider:internal"
Alex Light264a4862018-01-31 16:47:58 +0000612 else
613 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
614 fi
Alex Lightc281ba52017-10-11 11:35:55 -0700615elif [ "$DEBUGGER" = "agent" ]; then
616 PORT=12345
617 # TODO Support ddms connection and support target.
618 if [ "$HOST" = "n" ]; then
Stelios Ioannou3a014e32021-06-25 15:15:32 +0100619 error_msg "--debug-agent not supported yet for target!"
Alex Lightc281ba52017-10-11 11:35:55 -0700620 exit 1
621 fi
622 AGENTPATH=${DEBUGGER_AGENT}
623 if [ "$WRAP_DEBUGGER_AGENT" = "y" ]; then
624 WRAPPROPS="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}/libwrapagentpropertiesd.so"
625 if [ "$TEST_IS_NDEBUG" = "y" ]; then
626 WRAPPROPS="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}/libwrapagentproperties.so"
627 fi
628 AGENTPATH="${WRAPPROPS}=${ANDROID_BUILD_TOP}/art/tools/libjdwp-compat.props,${AGENTPATH}"
629 fi
630 msg "Connect to localhost:$PORT"
631 DEBUGGER_OPTS="-agentpath:${AGENTPATH}=transport=dt_socket,address=$PORT,server=y,suspend=y"
632fi
633
Alex Light54dabfb2018-09-19 16:29:09 -0700634for agent in "${WITH_AGENT[@]}"; do
635 FLAGS="${FLAGS} -agentpath:${agent}"
636done
Alex Light0e151e72017-10-25 10:50:35 -0700637
Alex Lightc281ba52017-10-11 11:35:55 -0700638if [ "$USE_JVMTI" = "y" ]; then
639 if [ "$USE_JVM" = "n" ]; then
640 plugin=libopenjdkjvmtid.so
641 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
642 plugin=libopenjdkjvmti.so
643 fi
Alex Light2ce6fc82017-12-18 16:42:36 -0800644 # We used to add flags here that made the runtime debuggable but that is not
645 # needed anymore since the plugin can do it for us now.
Alex Lightc281ba52017-10-11 11:35:55 -0700646 FLAGS="${FLAGS} -Xplugin:${plugin}"
Mythri Allef0d8b442021-11-03 17:28:24 +0000647
648 # For jvmti tests, set the threshold of compilation to 0, so we jit on the first
649 # use to provide better test coverage for jvmti + jit. This means we won't run
650 # the default --jit configuration but it is not too important test scenario for
651 # jvmti tests. This is art specific flag, so don't use it with jvm.
652 FLAGS="${FLAGS} -Xjitthreshold:0"
Alex Lightc281ba52017-10-11 11:35:55 -0700653 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100654fi
655
Alex Light280e6c32020-03-03 13:52:07 -0800656# Add the libdir to the argv passed to the main function.
657if [ "$ADD_LIBDIR_ARGUMENTS" = "y" ]; then
658 if [[ "$HOST" = "y" ]]; then
659 ARGS="${ARGS} ${ANDROID_HOST_OUT}/${TEST_DIRECTORY}/"
660 else
661 ARGS="${ARGS} /data/${TEST_DIRECTORY}/art/${ISA}/"
662 fi
663fi
Alex Lightfba89fe2017-01-12 16:11:02 -0800664if [ "$IS_JVMTI_TEST" = "y" ]; then
Alex Lightfba89fe2017-01-12 16:11:02 -0800665 agent=libtiagentd.so
666 lib=tiagentd
667 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
668 agent=libtiagent.so
Alex Lightfba89fe2017-01-12 16:11:02 -0800669 lib=tiagent
670 fi
671
672 ARGS="${ARGS} ${lib}"
673 if [[ "$USE_JVM" = "y" ]]; then
674 FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${TEST_NAME},jvm"
675 else
Martin Stjernholm0d0f8df2021-04-28 16:47:01 +0100676 FLAGS="${FLAGS} -agentpath:${agent}=${TEST_NAME},art"
Alex Lightfba89fe2017-01-12 16:11:02 -0800677 fi
678fi
679
Alex Light8f2c6d42017-04-10 16:27:35 -0700680if [[ "$JVMTI_STRESS" = "y" ]]; then
Alex Light42151c02017-04-20 15:54:25 -0700681 agent=libtistressd.so
682 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
683 agent=libtistress.so
Alex Light42151c02017-04-20 15:54:25 -0700684 fi
Alex Light8f2c6d42017-04-10 16:27:35 -0700685
Alex Lightb7edcda2017-04-27 13:20:31 -0700686 # Just give it a default start so we can always add ',' to it.
687 agent_args="jvmti-stress"
688 if [[ "$JVMTI_REDEFINE_STRESS" = "y" ]]; then
689 # We really cannot do this on RI so don't both passing it in that case.
690 if [[ "$USE_JVM" = "n" ]]; then
Alex Lightceae9542017-09-07 13:28:00 -0700691 agent_args="${agent_args},redefine"
Alex Lightb7edcda2017-04-27 13:20:31 -0700692 fi
693 fi
Alex Light43e935d2017-06-19 15:40:40 -0700694 if [[ "$JVMTI_FIELD_STRESS" = "y" ]]; then
695 agent_args="${agent_args},field"
696 fi
Alex Lightc38c3692017-06-27 15:45:14 -0700697 if [[ "$JVMTI_STEP_STRESS" = "y" ]]; then
698 agent_args="${agent_args},step"
699 fi
Alex Lightb7edcda2017-04-27 13:20:31 -0700700 if [[ "$JVMTI_TRACE_STRESS" = "y" ]]; then
701 agent_args="${agent_args},trace"
702 fi
703 # In the future add onto this;
Alex Light42151c02017-04-20 15:54:25 -0700704 if [[ "$USE_JVM" = "y" ]]; then
Alex Lightb7edcda2017-04-27 13:20:31 -0700705 FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${agent_args}"
Alex Light42151c02017-04-20 15:54:25 -0700706 else
Martin Stjernholm0d0f8df2021-04-28 16:47:01 +0100707 FLAGS="${FLAGS} -agentpath:${agent}=${agent_args}"
Alex Light8f2c6d42017-04-10 16:27:35 -0700708 fi
709fi
710
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100711if [ "$USE_JVM" = "y" ]; then
Alex Light9c20a142016-08-23 15:05:12 -0700712 export LD_LIBRARY_PATH=${ANDROID_HOST_OUT}/lib64
Alex Light47d49b82017-07-25 14:06:34 -0700713 # Some jvmti tests are flaky without -Xint on the RI.
714 if [ "$IS_JVMTI_TEST" = "y" ]; then
715 FLAGS="${FLAGS} -Xint"
716 fi
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700717 # Xmx is necessary since we don't pass down the ART flags to JVM.
Vladimir Markoc5798bf2016-12-09 10:20:54 +0000718 # We pass the classes2 path whether it's used (src-multidex) or not.
719 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes:classes2 ${FLAGS} $MAIN $@ ${ARGS}"
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700720 if [ "$DEV_MODE" = "y" ]; then
721 echo $cmdline
722 fi
Alex Light8d94ddd2019-12-18 11:13:03 -0800723 if [ "$CREATE_RUNNER" = "y" ]; then
724 echo "#!/bin/bash" > runit.sh
725 echo "export LD_LIBRARY_PATH=\"$LD_LIBRARY_PATH\""
Roland Levillainb15e8792020-10-28 12:20:59 +0000726 echo $cmdline >> runit.sh
Alex Light8d94ddd2019-12-18 11:13:03 -0800727 chmod u+x runit.sh
728 echo "Runnable test script written to $PWD/runit.sh"
729 else
730 $cmdline
731 fi
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100732 exit
733fi
734
Vladimir Marko0ace5632018-12-14 11:11:47 +0000735# Note: This must start with the CORE_IMG_JARS in Android.common_path.mk
David Srbecky6355d692020-03-26 14:10:26 +0000736# because that's what we use for compiling the boot.art image.
Vladimir Marko0ace5632018-12-14 11:11:47 +0000737# It may contain additional modules from TEST_CORE_JARS.
Victor Changd20e51d2020-05-05 16:01:19 +0100738bpath_modules="core-oj core-libart okhttp bouncycastle apache-xml core-icu4j conscrypt"
Nicolas Geoffray31e0dc22020-03-20 15:48:09 +0000739bpath=""
740bpath_locations=""
741bpath_separator=""
David Srbecky928d28e2020-04-01 17:50:51 +0100742bpath_prefix=""
743bpath_location_prefix=""
Ulya Trafimovich5439f052020-07-29 10:03:46 +0100744if [ "${HOST}" = "y" ]; then
David Srbecky928d28e2020-04-01 17:50:51 +0100745 bpath_prefix="${ANDROID_HOST_OUT}"
746 if [ "${ANDROID_HOST_OUT:0:${#ANDROID_BUILD_TOP}+1}" = "${ANDROID_BUILD_TOP}/" ]; then
747 bpath_location_prefix="${ANDROID_HOST_OUT:${#ANDROID_BUILD_TOP}+1}"
748 else
Stelios Ioannou3a014e32021-06-25 15:15:32 +0100749 error_msg "ANDROID_BUILD_TOP/ is not a prefix of ANDROID_HOST_OUT"\
750 "\nANDROID_BUILD_TOP=${ANDROID_BUILD_TOP}"\
751 "\nANDROID_HOST_OUT=${ANDROID_HOST_OUT}"
David Srbecky928d28e2020-04-01 17:50:51 +0100752 exit
753 fi
Vladimir Marko7a85e702018-12-03 18:47:23 +0000754fi
David Srbecky928d28e2020-04-01 17:50:51 +0100755for bpath_module in ${bpath_modules}; do
756 apex_module="com.android.art"
757 case "$bpath_module" in
758 (conscrypt) apex_module="com.android.conscrypt";;
759 (core-icu4j) apex_module="com.android.i18n";;
760 (*) apex_module="com.android.art";;
761 esac
762 bpath_jar="/apex/${apex_module}/javalib/${bpath_module}.jar"
763 bpath+="${bpath_separator}${bpath_prefix}${bpath_jar}"
764 bpath_locations+="${bpath_separator}${bpath_location_prefix}${bpath_jar}"
765 bpath_separator=":"
766done
Vladimir Marko7a85e702018-12-03 18:47:23 +0000767# Pass down the bootclasspath
768FLAGS="${FLAGS} -Xbootclasspath:${bpath}"
769FLAGS="${FLAGS} -Xbootclasspath-locations:${bpath_locations}"
770COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xbootclasspath:${bpath}"
771COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xbootclasspath-locations:${bpath_locations}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100772
773if [ "$HAVE_IMAGE" = "n" ]; then
Andreas Gampe1078d152017-11-07 18:00:54 -0800774 # Disable image dex2oat - this will forbid the runtime to patch or compile an image.
775 FLAGS="${FLAGS} -Xnoimage-dex2oat"
776
777 # We'll abuse a second flag here to test different behavior. If --relocate, use the
778 # existing image - relocation will fail as patching is disallowed. If --no-relocate,
779 # pass a non-existent image - compilation will fail as dex2oat is disallowed.
780 if [ "${RELOCATE}" = "y" ] ; then
781 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
782 else
David Srbecky6355d692020-03-26 14:10:26 +0000783 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existent/boot.art"
Andreas Gampe1078d152017-11-07 18:00:54 -0800784 fi
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000785else
786 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100787fi
788
Stelios Ioannou816b0da2021-06-03 13:25:50 +0100789if [ "$USE_GDB_DEX2OAT" = "y" ]; then
790 if [ "$HOST" = "n" ]; then
791 echo "The --gdb-dex2oat option is not yet implemented for target." >&2
792 exit 1
793 fi
794fi
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100795
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100796if [ "$USE_GDB" = "y" ]; then
Alex Lighte4b4a182019-02-12 14:19:49 -0800797 if [ "$USE_GDBSERVER" = "y" ]; then
Stelios Ioannou3a014e32021-06-25 15:15:32 +0100798 error_msg "Cannot pass both --gdb and --gdbserver at the same time!"
Alex Lighte4b4a182019-02-12 14:19:49 -0800799 exit 1
800 elif [ "$HOST" = "n" ]; then
Alex Light219420e2019-12-05 10:20:26 -0800801 # We might not have any hostname resolution if we are using a chroot.
802 GDB="$GDBSERVER_DEVICE --no-startup-with-shell 127.0.0.1$GDBSERVER_PORT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100803 else
804 if [ `uname` = "Darwin" ]; then
805 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700806 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100807 DALVIKVM=
808 else
809 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700810 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100811 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
812 # gdbargs="--annotate=3 $gdbargs"
813 fi
814 fi
Alex Lighte4b4a182019-02-12 14:19:49 -0800815elif [ "$USE_GDBSERVER" = "y" ]; then
816 if [ "$HOST" = "n" ]; then
Alex Light219420e2019-12-05 10:20:26 -0800817 # We might not have any hostname resolution if we are using a chroot.
818 GDB="$GDBSERVER_DEVICE --no-startup-with-shell 127.0.0.1$GDBSERVER_PORT"
819 else
820 GDB="$GDBSERVER_HOST $GDBSERVER_PORT"
Alex Lighte4b4a182019-02-12 14:19:49 -0800821 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100822fi
823
824if [ "$INTERPRETER" = "y" ]; then
Nicolas Geoffraya5ca8eb2018-08-24 13:39:13 +0100825 INT_OPTS="${INT_OPTS} -Xint"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100826fi
827
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800828if [ "$JIT" = "y" ]; then
Nicolas Geoffraya5ca8eb2018-08-24 13:39:13 +0100829 INT_OPTS="${INT_OPTS} -Xusejit:true"
Nicolas Geoffraya5ca8eb2018-08-24 13:39:13 +0100830else
831 INT_OPTS="${INT_OPTS} -Xusejit:false"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800832fi
833
Nicolas Geoffrayc76fbf02021-04-06 08:59:17 +0100834if [ "$INTERPRETER" = "y" ] || [ "$JIT" = "y" ]; then
835 if [ "$VERIFY" = "y" ] ; then
836 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify"
837 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify"
838 elif [ "$VERIFY" = "s" ]; then
839 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=extract"
840 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=extract"
841 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
842 else # VERIFY = "n"
843 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=assume-verified"
844 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=assume-verified"
845 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
846 fi
847fi
848
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100849JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
850
Richard Uhler020c0f32017-03-14 16:23:17 +0000851COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100852if [ "$RELOCATE" = "y" ]; then
Richard Uhlerc52f3032017-03-02 13:45:45 +0000853 FLAGS="${FLAGS} -Xrelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100854else
855 FLAGS="$FLAGS -Xnorelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100856fi
857
Alex Light680cbf22018-10-31 11:00:19 -0700858if [ "$BIONIC" = "y" ]; then
859 # This is the location that soong drops linux_bionic builds. Despite being
860 # called linux_bionic-x86 the build is actually amd64 (x86_64) only.
861 if [ ! -e "$OUT_DIR/soong/host/linux_bionic-x86" ]; then
Stelios Ioannou3a014e32021-06-25 15:15:32 +0100862 error_msg "linux_bionic-x86 target doesn't seem to have been built!"
Alex Light680cbf22018-10-31 11:00:19 -0700863 exit 1
864 fi
Andreas Gampe148c1602019-06-10 16:47:46 -0700865 # Set TIMEOUT_DUMPER manually so it works even with apex's
866 TIMEOUT_DUMPER=$OUT_DIR/soong/host/linux_bionic-x86/bin/signal_dumper
Alex Light680cbf22018-10-31 11:00:19 -0700867fi
868
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700869# Prevent test from silently falling back to interpreter in no-prebuild mode. This happens
870# when DEX_LOCATION path is too long, because vdex/odex filename is constructed by taking
871# full path to dex, stripping leading '/', appending '@classes.vdex' and changing every
872# remaining '/' into '@'.
873if [ "$HOST" = "y" ]; then
874 max_filename_size=$(getconf NAME_MAX $DEX_LOCATION)
875else
Roland Levillain2ae376f2018-01-30 11:35:11 +0000876 # There is no getconf on device, fallback to standard value.
877 # See NAME_MAX in kernel <linux/limits.h>
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700878 max_filename_size=255
879fi
880# Compute VDEX_NAME.
881DEX_LOCATION_STRIPPED="${DEX_LOCATION#/}"
882VDEX_NAME="${DEX_LOCATION_STRIPPED//\//@}@$TEST_NAME.jar@classes.vdex"
883if [ ${#VDEX_NAME} -gt $max_filename_size ]; then
Nicolas Geoffraybea3e312017-03-07 09:59:05 +0000884 echo "Dex location path too long:"
Stelios Ioannou3a014e32021-06-25 15:15:32 +0100885 error_msg "$VDEX_NAME is ${#VDEX_NAME} character long, and the limit is $max_filename_size."
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700886 exit 1
887fi
888
Ulya Trafimovich5439f052020-07-29 10:03:46 +0100889if [ "$HOST" = "y" ]; then
Roland Levillain72f67742019-03-06 15:48:08 +0000890 # On host, run binaries (`dex2oat(d)`, `dalvikvm`, `profman`) from the `bin`
891 # directory under the "Android Root" (usually `out/host/linux-x86`).
892 #
893 # TODO(b/130295968): Adjust this if/when ART host artifacts are installed
Martin Stjernholme58624f2019-09-20 15:53:40 +0100894 # under the ART root (usually `out/host/linux-x86/com.android.art`).
895 ANDROID_ART_BIN_DIR=$ANDROID_ROOT/bin
Roland Levillain72f67742019-03-06 15:48:08 +0000896else
Martin Stjernholme58624f2019-09-20 15:53:40 +0100897 # On target, run binaries (`dex2oat(d)`, `dalvikvm`, `profman`) from the ART
898 # APEX's `bin` directory. This means the linker will observe the ART APEX
899 # linker configuration file (`/apex/com.android.art/etc/ld.config.txt`) for
900 # these binaries.
901 ANDROID_ART_BIN_DIR=$ANDROID_ART_ROOT/bin
Roland Levillain72f67742019-03-06 15:48:08 +0000902fi
Alex Light20802ca2018-12-05 15:36:03 -0800903
Calin Juravle13439f02017-02-21 01:17:21 -0800904profman_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100905dex2oat_cmdline="true"
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000906vdex_cmdline="true"
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000907dm_cmdline="true"
Andreas Gampeb09abb22018-05-03 11:51:22 -0700908mkdir_locations="${DEX_LOCATION}/dalvik-cache/$ISA"
Richard Uhler76f5cb62016-04-04 13:30:16 -0700909strip_cmdline="true"
Igor Murashkin271a0f82017-02-14 21:14:17 +0000910sync_cmdline="true"
Alex Light680cbf22018-10-31 11:00:19 -0700911linkroot_cmdline="true"
912linkroot_overlay_cmdline="true"
Alex Light20802ca2018-12-05 15:36:03 -0800913setupapex_cmdline="true"
914installapex_cmdline="true"
Alex Light5e1ffcd2021-03-31 16:46:02 -0700915installapex_test_cmdline="true"
Alex Light680cbf22018-10-31 11:00:19 -0700916
917linkdirs() {
918 find "$1" -maxdepth 1 -mindepth 1 -type d | xargs -i ln -sf '{}' "$2"
Nicolas Geoffrayea55f3d2021-09-07 12:16:56 +0100919 # Also create a link for the boot image.
920 ln -sf $ANDROID_HOST_OUT/apex/art_boot_images "$2"
Alex Light680cbf22018-10-31 11:00:19 -0700921}
922
923if [ "$CREATE_ANDROID_ROOT" = "y" ]; then
924 mkdir_locations="${mkdir_locations} ${ANDROID_ROOT}"
925 linkroot_cmdline="linkdirs ${ANDROID_HOST_OUT} ${ANDROID_ROOT}"
926 if [ "${BIONIC}" = "y" ]; then
927 # TODO Make this overlay more generic.
928 linkroot_overlay_cmdline="linkdirs $OUT_DIR/soong/host/linux_bionic-x86 ${ANDROID_ROOT}"
929 fi
Nicolas Geoffrayea55f3d2021-09-07 12:16:56 +0100930 # Replace the boot image to a location expected by the runtime.
931 DALVIKVM_BOOT_OPT="-Ximage:${ANDROID_ROOT}/art_boot_images/javalib/boot.art"
Alex Light680cbf22018-10-31 11:00:19 -0700932fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100933
Alex Light20802ca2018-12-05 15:36:03 -0800934if [ "$USE_ZIPAPEX" = "y" ]; then
935 # TODO Currently this only works for linux_bionic zipapexes because those are
936 # stripped and so small enough that the ulimit doesn't kill us.
937 mkdir_locations="${mkdir_locations} $DEX_LOCATION/zipapex"
938 zip_options="-qq"
939 if [ "$DEV_MODE" = "y" ]; then
940 zip_options=""
941 fi
Alex Lightfc52ffc2019-01-31 15:48:18 -0800942 setupapex_cmdline="unzip -o -u ${zip_options} ${ZIPAPEX_LOC} apex_payload.zip -d ${DEX_LOCATION}"
943 installapex_cmdline="unzip -o -u ${zip_options} ${DEX_LOCATION}/apex_payload.zip -d ${DEX_LOCATION}/zipapex"
Martin Stjernholme58624f2019-09-20 15:53:40 +0100944 ANDROID_ART_BIN_DIR=$DEX_LOCATION/zipapex/bin
Alex Light6f342dd2019-03-27 17:15:42 +0000945elif [ "$USE_EXTRACTED_ZIPAPEX" = "y" ]; then
946 # Just symlink the zipapex binaries
Martin Stjernholme58624f2019-09-20 15:53:40 +0100947 ANDROID_ART_BIN_DIR=$DEX_LOCATION/zipapex/bin
Alex Light6f342dd2019-03-27 17:15:42 +0000948 # Force since some tests manually run this file twice.
949 ln_options=""
950 if [ "$DEV_MODE" = "y" ]; then
951 ln_options="--verbose"
952 fi
Alex Light5e1ffcd2021-03-31 16:46:02 -0700953 # If the ${RUN} is executed multiple times we don't need to recreate the link
954 installapex_test_cmdline="test -L ${DEX_LOCATION}/zipapex"
Alex Light6f342dd2019-03-27 17:15:42 +0000955 installapex_cmdline="ln -s -f ${ln_options} ${EXTRACTED_ZIPAPEX_LOC} ${DEX_LOCATION}/zipapex"
Alex Light20802ca2018-12-05 15:36:03 -0800956fi
957
Jeff Hao002b9312017-03-27 16:23:08 -0700958# PROFILE takes precedence over RANDOM_PROFILE, since PROFILE tests require a
959# specific profile to run properly.
960if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Martin Stjernholme58624f2019-09-20 15:53:40 +0100961 profman_cmdline="$ANDROID_ART_BIN_DIR/profman \
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000962 --apk=$DEX_LOCATION/$TEST_NAME.jar \
Jeff Hao002b9312017-03-27 16:23:08 -0700963 --dex-location=$DEX_LOCATION/$TEST_NAME.jar"
Andreas Gampe038a1982020-03-11 23:06:42 +0000964 if [ -f "$TEST_NAME-ex.jar" ] && [ "$SECONDARY_COMPILATION" = "y" ] ; then
Calin Juravle6df62f72017-04-28 19:58:01 -0700965 profman_cmdline="${profman_cmdline} \
966 --apk=$DEX_LOCATION/$TEST_NAME-ex.jar \
967 --dex-location=$DEX_LOCATION/$TEST_NAME-ex.jar"
968 fi
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000969 COMPILE_FLAGS="${COMPILE_FLAGS} --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
970 FLAGS="${FLAGS} -Xcompiler-option --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
Jeff Hao002b9312017-03-27 16:23:08 -0700971 if [ "$PROFILE" = "y" ]; then
972 profman_cmdline="${profman_cmdline} --create-profile-from=$DEX_LOCATION/profile \
973 --reference-profile-file=$DEX_LOCATION/$TEST_NAME.prof"
974 else
975 profman_cmdline="${profman_cmdline} --generate-test-profile=$DEX_LOCATION/$TEST_NAME.prof \
976 --generate-test-profile-seed=0"
977 fi
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000978fi
979
Stelios Ioannou816b0da2021-06-03 13:25:50 +0100980function get_prebuilt_lldb_path {
981 local CLANG_BASE="prebuilts/clang/host"
982 local CLANG_VERSION="$("$ANDROID_BUILD_TOP/build/soong/scripts/get_clang_version.py")"
983 case "$(uname -s)" in
984 Darwin)
985 local PREBUILT_NAME="darwin-x86"
986 ;;
987 Linux)
988 local PREBUILT_NAME="linux-x86"
989 ;;
990 *)
991 >&2 echo "Unknown host $(uname -s). Unsupported for debugging dex2oat with LLDB."
992 return
993 ;;
994 esac
995 local CLANG_PREBUILT_HOST_PATH="$ANDROID_BUILD_TOP/$CLANG_BASE/$PREBUILT_NAME/$CLANG_VERSION"
996 # If the clang prebuilt directory exists and the reported clang version
997 # string does not, then it is likely that the clang version reported by the
998 # get_clang_version.py script does not match the expected directory name.
999 if [ -d "${ANDROID_BUILD_TOP}/${CLANG_BASE}/${PREBUILT_NAME}" ] && \
1000 [ ! -d "${CLANG_PREBUILT_HOST_PATH}" ]; then
1001 error_msg "The prebuilt clang directory exists, but the specific clang"\
1002 "\nversion reported by get_clang_version.py does not exist in that path."\
1003 "\nPlease make sure that the reported clang version resides in the"\
1004 "\nprebuilt clang directory!"
1005 exit 1
1006 fi
1007
1008 # The lldb-server binary is a dependency of lldb.
1009 export LLDB_DEBUGSERVER_PATH="${CLANG_PREBUILT_HOST_PATH}/runtimes_ndk_cxx/x86_64/lldb-server"
1010
1011 # Set the current terminfo directory to TERMINFO so that LLDB can read the
1012 # termcap database.
1013 local terminfo_regexp_path='\/.*\/*terminfo\/'
1014 if [[ $(infocmp) =~ $terminfo_regexp_path ]] ; then
1015 export TERMINFO="${BASH_REMATCH[0]}"
1016 fi
1017
1018 prebuilt_lldb_path="$CLANG_PREBUILT_HOST_PATH/bin/lldb.sh"
1019}
1020
Andreas Gampe038a1982020-03-11 23:06:42 +00001021function write_dex2oat_cmdlines {
1022 local name="$1"
David Srbeckyb0ec6792020-02-06 20:18:17 +00001023
Andreas Gampe038a1982020-03-11 23:06:42 +00001024 local class_loader_context=""
1025 local enable_app_image=false
Calin Juravle857f0582016-12-20 14:36:59 +00001026 if [ "$APP_IMAGE" = "y" ]; then
Andreas Gampe038a1982020-03-11 23:06:42 +00001027 enable_app_image=true
Calin Juravle857f0582016-12-20 14:36:59 +00001028 fi
1029
Andreas Gampe038a1982020-03-11 23:06:42 +00001030 # If the name ends in -ex then this is a secondary dex file
1031 if [ "${name:${#name}-3}" = "-ex" ]; then
1032 # Lazily realize the default value in case DEX_LOCATION/TEST_NAME change
Vladimir Markoae96c822021-10-13 13:02:26 +01001033 if [ "x$SECONDARY_CLASS_LOADER_CONTEXT" = "x" ]; then
1034 if [ "x$SECONDARY_DEX" = "x" ]; then
1035 # Tests without `--secondary` load the "-ex" jar in a separate PathClassLoader
1036 # that is a child of the main PathClassLoader. If the class loader is constructed
1037 # in any other way, the test needs to specify the secondary CLC explicitly.
1038 SECONDARY_CLASS_LOADER_CONTEXT="PCL[];PCL[$DEX_LOCATION/$TEST_NAME.jar]"
1039 else
1040 # Tests with `--secondary` load the `-ex` jar a part of the main PathClassLoader.
1041 SECONDARY_CLASS_LOADER_CONTEXT="PCL[$DEX_LOCATION/$TEST_NAME.jar]"
1042 fi
1043 fi
Andreas Gampe038a1982020-03-11 23:06:42 +00001044 class_loader_context="'--class-loader-context=$SECONDARY_CLASS_LOADER_CONTEXT'"
1045 $enable_app_image && [ "$SECONDARY_APP_IMAGE" = "y" ] || enable_app_image=false
1046 fi
1047
1048 local app_image=""
1049 $enable_app_image && app_image="--app-image-file=$DEX_LOCATION/oat/$ISA/$name.art --resolve-startup-const-strings=true"
1050
Stelios Ioannou816b0da2021-06-03 13:25:50 +01001051 if [ "$USE_GDB_DEX2OAT" = "y" ]; then
1052 get_prebuilt_lldb_path
1053 GDB_DEX2OAT="$prebuilt_lldb_path -f"
1054 GDB_DEX2OAT_ARGS+=" -- "
1055 fi
1056
Andreas Gampe038a1982020-03-11 23:06:42 +00001057 local dex2oat_binary
Alex Light907001d2019-01-17 00:16:04 +00001058 dex2oat_binary=${DEX2OAT_DEBUG_BINARY}
Roland Levillain6c3af162017-04-27 11:18:56 +01001059 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
Alex Light907001d2019-01-17 00:16:04 +00001060 dex2oat_binary=${DEX2OAT_NDEBUG_BINARY}
Roland Levillain6c3af162017-04-27 11:18:56 +01001061 fi
Stelios Ioannou816b0da2021-06-03 13:25:50 +01001062 dex2oat_cmdline="$INVOKE_WITH $GDB_DEX2OAT \
1063 $ANDROID_ART_BIN_DIR/$dex2oat_binary \
1064 $GDB_DEX2OAT_ARGS \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001065 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +00001066 --boot-image=${BOOT_IMAGE} \
Andreas Gampe038a1982020-03-11 23:06:42 +00001067 --dex-file=$DEX_LOCATION/$name.jar \
1068 --oat-file=$DEX_LOCATION/oat/$ISA/$name.odex \
1069 "$app_image" \
David Srbecky87712da2020-01-17 15:50:02 +00001070 --generate-mini-debug-info \
Andreas Gampe038a1982020-03-11 23:06:42 +00001071 --instruction-set=$ISA \
1072 $class_loader_context"
Andreas Gampe4d2ef332015-08-05 09:24:45 -07001073 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
1074 dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
1075 fi
Andreas Gampe2ea7b702015-08-07 08:07:16 -07001076
1077 # Add in a timeout. This is important for testing the compilation/verification time of
Stelios Ioannou816b0da2021-06-03 13:25:50 +01001078 # pathological cases. We do not append a timeout when debugging dex2oat because we
1079 # do not want it to exit while debugging.
Andreas Gampe2ea7b702015-08-07 08:07:16 -07001080 # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
1081 # now. We should try to improve this.
1082 # The current value is rather arbitrary. run-tests should compile quickly.
Alex Light483208d2017-09-26 09:31:17 -07001083 # Watchdog timeout is in milliseconds so add 3 '0's to the dex2oat timeout.
Stelios Ioannou816b0da2021-06-03 13:25:50 +01001084 if [ "$HOST" != "n" ] && [ "$USE_GDB_DEX2OAT" != "y" ]; then
Andreas Gampe2ea7b702015-08-07 08:07:16 -07001085 # Use SIGRTMIN+2 to try to dump threads.
1086 # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
Alex Light483208d2017-09-26 09:31:17 -07001087 dex2oat_cmdline="timeout -k ${DEX2OAT_TIMEOUT}s -s SIGRTMIN+2 ${DEX2OAT_RT_TIMEOUT}s ${dex2oat_cmdline} --watchdog-timeout=${DEX2OAT_TIMEOUT}000"
Andreas Gampe2ea7b702015-08-07 08:07:16 -07001088 fi
Nicolas Geoffrayfbc4f112017-04-27 21:45:35 +01001089 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Andreas Gampe038a1982020-03-11 23:06:42 +00001090 vdex_cmdline="${dex2oat_cmdline} ${VDEX_ARGS} --input-vdex=$DEX_LOCATION/oat/$ISA/$name.vdex --output-vdex=$DEX_LOCATION/oat/$ISA/$name.vdex"
Nicolas Geoffrayfbc4f112017-04-27 21:45:35 +01001091 elif [ "$TEST_VDEX" = "y" ]; then
Nicolas Geoffrayc6c6a152021-03-01 13:51:22 +00001092 if [ "$VDEX_ARGS" = "" ]; then
1093 # If no arguments need to be passed, just delete the odex file so that the runtime only picks up the vdex file.
1094 vdex_cmdline="rm $DEX_LOCATION/oat/$ISA/$name.odex"
1095 else
1096 vdex_cmdline="${dex2oat_cmdline} ${VDEX_ARGS} --input-vdex=$DEX_LOCATION/oat/$ISA/$name.vdex"
1097 fi
Nicolas Geoffray327cfcf2021-10-12 14:13:25 +01001098 elif [ "$TEST_DEX2OAT_DM" = "y" ]; then
1099 vdex_cmdline="${dex2oat_cmdline} ${VDEX_ARGS} --dump-timings --dm-file=$DEX_LOCATION/oat/$ISA/$name.dm"
Calin Juravle046cecf2020-12-07 18:31:28 -08001100 dex2oat_cmdline="${dex2oat_cmdline} --copy-dex-files=false --output-vdex=$DEX_LOCATION/oat/$ISA/primary.vdex"
Andreas Gampe038a1982020-03-11 23:06:42 +00001101 dm_cmdline="zip -qj $DEX_LOCATION/oat/$ISA/$name.dm $DEX_LOCATION/oat/$ISA/primary.vdex"
Nicolas Geoffray327cfcf2021-10-12 14:13:25 +01001102 elif [ "$TEST_RUNTIME_DM" = "y" ]; then
1103 dex2oat_cmdline="${dex2oat_cmdline} --copy-dex-files=false --output-vdex=$DEX_LOCATION/oat/$ISA/primary.vdex"
1104 dm_cmdline="zip -qj $DEX_LOCATION/$name.dm $DEX_LOCATION/oat/$ISA/primary.vdex"
Andreas Gampe038a1982020-03-11 23:06:42 +00001105 fi
1106}
1107
1108# Enable mini-debug-info for JIT (if JIT is used).
1109FLAGS="$FLAGS -Xcompiler-option --generate-mini-debug-info"
1110
1111if [ "$PREBUILD" = "y" ]; then
1112 mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/oat/$ISA"
1113
1114 # "Primary".
1115 write_dex2oat_cmdlines "$TEST_NAME"
1116 dex2oat_cmdline=$(echo $dex2oat_cmdline)
1117 dm_cmdline=$(echo $dm_cmdline)
1118 vdex_cmdline=$(echo $vdex_cmdline)
1119
1120 # Enable mini-debug-info for JIT (if JIT is used).
1121 FLAGS="$FLAGS -Xcompiler-option --generate-mini-debug-info"
1122
1123 if [ -f "$TEST_NAME-ex.jar" ] && [ "$SECONDARY_COMPILATION" = "y" ] ; then
1124 # "Secondary" for test coverage.
1125
1126 # Store primary values.
1127 base_dex2oat_cmdline="$dex2oat_cmdline"
1128 base_dm_cmdline="$dm_cmdline"
1129 base_vdex_cmdline="$vdex_cmdline"
1130
1131 write_dex2oat_cmdlines "$TEST_NAME-ex"
1132 dex2oat_cmdline=$(echo $dex2oat_cmdline)
1133 dm_cmdline=$(echo $dm_cmdline)
1134 vdex_cmdline=$(echo $vdex_cmdline)
1135
1136 # Concatenate.
1137 dex2oat_cmdline="$base_dex2oat_cmdline && $dex2oat_cmdline"
1138 dm_cmdline="$base_dm_cmdline" # Only use primary dm.
1139 vdex_cmdline="$base_vdex_cmdline && $vdex_cmdline"
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +00001140 fi
Andreas Gampe4d2ef332015-08-05 09:24:45 -07001141fi
1142
Igor Murashkin271a0f82017-02-14 21:14:17 +00001143if [ "$SYNC_BEFORE_RUN" = "y" ]; then
1144 sync_cmdline="sync"
1145fi
1146
Andreas Gampe4d2ef332015-08-05 09:24:45 -07001147DALVIKVM_ISA_FEATURES_ARGS=""
1148if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
1149 DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001150fi
1151
Nicolas Geoffrayc5256042015-12-26 19:41:37 +00001152# java.io.tmpdir can only be set at launch time.
1153TMP_DIR_OPTION=""
1154if [ "$HOST" = "n" ]; then
1155 TMP_DIR_OPTION="-Djava.io.tmpdir=/data/local/tmp"
1156fi
1157
Alex Lightb8012102019-11-13 01:41:04 +00001158# The build servers have an ancient version of bash so we cannot use @Q.
1159if [ "$USE_GDBSERVER" == "y" ]; then
1160 printf -v QUOTED_DALVIKVM_BOOT_OPT "%q" "$DALVIKVM_BOOT_OPT"
1161else
1162 QUOTED_DALVIKVM_BOOT_OPT="$DALVIKVM_BOOT_OPT"
1163fi
1164
Nicolas Geoffray6ee49712018-03-30 14:39:05 +00001165# We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
1166# b/27185632
1167# b/24664297
Martin Stjernholme58624f2019-09-20 15:53:40 +01001168dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ART_BIN_DIR/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001169 $GDB_ARGS \
1170 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -07001171 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001172 -XXlib:$LIB \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001173 $DEX2OAT \
Andreas Gampe4d2ef332015-08-05 09:24:45 -07001174 $DALVIKVM_ISA_FEATURES_ARGS \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001175 $ZYGOTE \
1176 $JNI_OPTS \
1177 $INT_OPTS \
1178 $DEBUGGER_OPTS \
Alex Lightb8012102019-11-13 01:41:04 +00001179 ${QUOTED_DALVIKVM_BOOT_OPT} \
Nicolas Geoffrayc5256042015-12-26 19:41:37 +00001180 $TMP_DIR_OPTION \
Nicolas Geoffray6ee49712018-03-30 14:39:05 +00001181 -XX:DumpNativeStackOnSigQuit:false \
Mathieu Chartier031768a2015-08-27 10:25:02 -07001182 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001183
Andreas Gampe038a1982020-03-11 23:06:42 +00001184sanitize_dex2oat_cmdline() {
1185 local args=()
1186 for arg in "$@"; do
1187 if [ "$arg" = "--class-loader-context=&" ]; then
1188 arg="--class-loader-context=\&"
1189 fi
1190 args+=("$arg")
1191 done
1192 echo -n "${args[@]}"
1193}
1194
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -08001195# Remove whitespace.
Andreas Gampe038a1982020-03-11 23:06:42 +00001196dex2oat_cmdline=$(sanitize_dex2oat_cmdline $(echo $dex2oat_cmdline))
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -08001197dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +00001198dm_cmdline=$(echo $dm_cmdline)
Andreas Gampe038a1982020-03-11 23:06:42 +00001199vdex_cmdline=$(sanitize_dex2oat_cmdline $(echo $vdex_cmdline))
Calin Juravle13439f02017-02-21 01:17:21 -08001200profman_cmdline=$(echo $profman_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001201
Andreas Gampeb31a8e72017-05-16 10:30:24 -07001202# Use an empty ASAN_OPTIONS to enable defaults.
1203# Note: this is required as envsetup right now exports detect_leaks=0.
1204RUN_TEST_ASAN_OPTIONS=""
1205
Andreas Gampe58408392017-05-16 10:45:46 -07001206# Multiple shutdown leaks. b/38341789
1207if [ "x$RUN_TEST_ASAN_OPTIONS" != "x" ] ; then
1208 RUN_TEST_ASAN_OPTIONS="${RUN_TEST_ASAN_OPTIONS}:"
1209fi
1210RUN_TEST_ASAN_OPTIONS="${RUN_TEST_ASAN_OPTIONS}detect_leaks=0"
1211
Vladimir Markoa497a392018-09-26 10:52:50 +01001212# For running, we must turn off logging when dex2oat is missing. Otherwise we use
Nicolas Geoffrayf39f04c2018-03-05 15:42:11 +00001213# the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
1214if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
1215 if [ "$DEV_MODE" = "y" ]; then
1216 export ANDROID_LOG_TAGS='*:d'
Nicolas Geoffrayf39f04c2018-03-05 15:42:11 +00001217 elif [ "$HAVE_IMAGE" = "n" ]; then
1218 # All tests would log the error of missing image. Be silent here and only log fatal
1219 # events.
1220 export ANDROID_LOG_TAGS='*:s'
1221 else
1222 # We are interested in LOG(ERROR) output.
1223 export ANDROID_LOG_TAGS='*:e'
1224 fi
1225fi
1226
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001227if [ "$HOST" = "n" ]; then
1228 adb root > /dev/null
1229 adb wait-for-device
1230 if [ "$QUIET" = "n" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001231 adb shell rm -rf $CHROOT_DEX_LOCATION
1232 adb shell mkdir -p $CHROOT_DEX_LOCATION
1233 adb push $TEST_NAME.jar $CHROOT_DEX_LOCATION
1234 adb push $TEST_NAME-ex.jar $CHROOT_DEX_LOCATION
Jeff Hao002b9312017-03-27 16:23:08 -07001235 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001236 adb push profile $CHROOT_DEX_LOCATION
Calin Juravle13439f02017-02-21 01:17:21 -08001237 fi
David Brazdil7d2ec612018-01-19 14:19:59 +00001238 # Copy resource folder
1239 if [ -d res ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001240 adb push res $CHROOT_DEX_LOCATION
David Brazdil7d2ec612018-01-19 14:19:59 +00001241 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001242 else
Roland Levillain76cfe612017-10-30 13:14:28 +00001243 adb shell rm -rf $CHROOT_DEX_LOCATION >/dev/null 2>&1
1244 adb shell mkdir -p $CHROOT_DEX_LOCATION >/dev/null 2>&1
1245 adb push $TEST_NAME.jar $CHROOT_DEX_LOCATION >/dev/null 2>&1
1246 adb push $TEST_NAME-ex.jar $CHROOT_DEX_LOCATION >/dev/null 2>&1
Jeff Hao002b9312017-03-27 16:23:08 -07001247 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001248 adb push profile $CHROOT_DEX_LOCATION >/dev/null 2>&1
Calin Juravle13439f02017-02-21 01:17:21 -08001249 fi
David Brazdil7d2ec612018-01-19 14:19:59 +00001250 # Copy resource folder
1251 if [ -d res ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001252 adb push res $CHROOT_DEX_LOCATION >/dev/null 2>&1
David Brazdil7d2ec612018-01-19 14:19:59 +00001253 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001254 fi
1255
Roland Levillain72f67742019-03-06 15:48:08 +00001256 # Populate LD_LIBRARY_PATH.
1257 LD_LIBRARY_PATH=
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +00001258 if [ "$ANDROID_ROOT" != "/system" ]; then
1259 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
1260 # so we can only use LD_LIBRARY_PATH when testing on a local
1261 # installation.
Roland Levillain72f67742019-03-06 15:48:08 +00001262 LD_LIBRARY_PATH="$ANDROID_ROOT/$LIBRARY_DIRECTORY"
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +00001263 fi
Martin Stjernholm0d0f8df2021-04-28 16:47:01 +01001264
1265 # This adds libarttest(d).so to the default linker namespace when dalvikvm
1266 # is run from /apex/com.android.art/bin. Since that namespace is essentially
1267 # an alias for the com_android_art namespace, that gives libarttest(d).so
1268 # full access to the internal ART libraries.
1269 LD_LIBRARY_PATH="/data/$TEST_DIRECTORY/com.android.art/lib${SUFFIX64}:$LD_LIBRARY_PATH"
1270 if [ "$TEST_IS_NDEBUG" = "y" ]; then dlib=""; else dlib="d"; fi
1271 art_test_internal_libraries=(
1272 libartagent${dlib}.so
1273 libarttest${dlib}.so
1274 libtiagent${dlib}.so
1275 libtistress${dlib}.so
1276 )
1277 art_test_internal_libraries="${art_test_internal_libraries[*]}"
1278 NATIVELOADER_DEFAULT_NAMESPACE_LIBS="${art_test_internal_libraries// /:}"
1279 dlib=
1280 art_test_internal_libraries=
1281
Roland Levillain72f67742019-03-06 15:48:08 +00001282 # Needed to access the test's Odex files.
1283 LD_LIBRARY_PATH="$DEX_LOCATION/oat/$ISA:$LD_LIBRARY_PATH"
1284 # Needed to access the test's native libraries (see e.g. 674-hiddenapi,
1285 # which generates `libhiddenapitest_*.so` libraries in `$DEX_LOCATION`).
1286 LD_LIBRARY_PATH="$DEX_LOCATION:$LD_LIBRARY_PATH"
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +00001287
Roland Levillain72f67742019-03-06 15:48:08 +00001288 # Prepend directories to the path on device.
Martin Stjernholme58624f2019-09-20 15:53:40 +01001289 PREPEND_TARGET_PATH=$ANDROID_ART_BIN_DIR
Roland Levillain72f67742019-03-06 15:48:08 +00001290 if [ "$ANDROID_ROOT" != "/system" ]; then
1291 PREPEND_TARGET_PATH="$PREPEND_TARGET_PATH:$ANDROID_ROOT/bin"
1292 fi
1293
Andreas Gampe975d70b2019-09-11 11:00:18 -07001294 timeout_dumper_cmd=
Andreas Gampea6138082019-09-11 11:08:23 -07001295
1296 # Check whether signal_dumper is available.
1297 if [ "$TIMEOUT_DUMPER" = signal_dumper ] ; then
Andreas Gampe5d775eb2019-09-13 09:54:55 -07001298 # Chroot? Use as prefix for tests.
1299 TIMEOUT_DUMPER_PATH_PREFIX=
1300 if [ -n "$CHROOT" ]; then
1301 TIMEOUT_DUMPER_PATH_PREFIX="$CHROOT/"
1302 fi
1303
Roland Levillain52b4dc92019-09-12 11:56:52 +01001304 # Testing APEX?
Andreas Gampe5aae3db2019-09-13 10:24:57 -07001305 if adb shell "test -x ${TIMEOUT_DUMPER_PATH_PREFIX}/apex/com.android.art/bin/signal_dumper" ; then
Andreas Gampe5d775eb2019-09-13 09:54:55 -07001306 TIMEOUT_DUMPER="/apex/com.android.art/bin/signal_dumper"
1307 # Is it in /system/bin?
Andreas Gampe5aae3db2019-09-13 10:24:57 -07001308 elif adb shell "test -x ${TIMEOUT_DUMPER_PATH_PREFIX}/system/bin/signal_dumper" ; then
Andreas Gampe5d775eb2019-09-13 09:54:55 -07001309 TIMEOUT_DUMPER="/system/bin/signal_dumper"
Andreas Gampea6138082019-09-11 11:08:23 -07001310 else
Andreas Gampe5d775eb2019-09-13 09:54:55 -07001311 TIMEOUT_DUMPER=
Andreas Gampea6138082019-09-11 11:08:23 -07001312 fi
1313 else
1314 TIMEOUT_DUMPER=
1315 fi
1316
Andreas Gampe975d70b2019-09-11 11:00:18 -07001317 if [ ! -z "$TIMEOUT_DUMPER" ] ; then
1318 # Use "-l" to dump to logcat. That is convenience for the build bot crash symbolization.
Andreas Gampe38a28182019-09-13 11:36:11 -07001319 # Use exit code 124 for toybox timeout (b/141007616).
1320 timeout_dumper_cmd="${TIMEOUT_DUMPER} -l -s 15 -e 124"
Andreas Gampe975d70b2019-09-11 11:00:18 -07001321 fi
1322
1323 timeout_prefix=
1324 if [ "$TIME_OUT" = "timeout" ]; then
1325 # Add timeout command if time out is desired.
1326 #
1327 # Note: We first send SIGTERM (the timeout default, signal 15) to the signal dumper, which
1328 # will induce a full thread dump before killing the process. To ensure any issues in
1329 # dumping do not lead to a deadlock, we also use the "-k" option to definitely kill the
1330 # child.
1331 # Note: Using "--foreground" to not propagate the signal to children, i.e., the runtime.
David Srbeckya49b04f2019-09-16 14:53:15 +00001332 timeout_prefix="timeout --foreground -k 120s ${TIME_OUT_VALUE}s ${timeout_dumper_cmd} $cmdline"
Andreas Gampe975d70b2019-09-11 11:00:18 -07001333 fi
1334
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001335 # Create a script with the command. The command can get longer than the longest
1336 # allowed adb command and there is no way to get the exit status from a adb shell
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001337 # command. Dalvik cache is cleaned before running to make subsequent executions
1338 # of the script follow the same runtime path.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001339 cmdline="cd $DEX_LOCATION && \
Andreas Gampeb31a8e72017-05-16 10:30:24 -07001340 export ASAN_OPTIONS=$RUN_TEST_ASAN_OPTIONS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001341 export ANDROID_DATA=$DEX_LOCATION && \
1342 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +00001343 export ANDROID_ROOT=$ANDROID_ROOT && \
Victor Chang64611242019-07-05 16:32:41 +01001344 export ANDROID_I18N_ROOT=$ANDROID_I18N_ROOT && \
Martin Stjernholme58624f2019-09-20 15:53:40 +01001345 export ANDROID_ART_ROOT=$ANDROID_ART_ROOT && \
Neil Fuller26a5dd62019-03-13 15:16:35 +00001346 export ANDROID_TZDATA_ROOT=$ANDROID_TZDATA_ROOT && \
Nicolas Geoffrayf39f04c2018-03-05 15:42:11 +00001347 export ANDROID_LOG_TAGS=$ANDROID_LOG_TAGS && \
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001348 rm -rf ${DEX_LOCATION}/dalvik-cache/ && \
Alex Lightafb5d192016-05-24 15:57:45 -07001349 mkdir -p ${mkdir_locations} && \
Sebastien Hertz7cde48c2015-01-20 16:06:43 +01001350 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Martin Stjernholm0d0f8df2021-04-28 16:47:01 +01001351 export NATIVELOADER_DEFAULT_NAMESPACE_LIBS=$NATIVELOADER_DEFAULT_NAMESPACE_LIBS && \
Roland Levillain72f67742019-03-06 15:48:08 +00001352 export PATH=$PREPEND_TARGET_PATH:\$PATH && \
Calin Juravle13439f02017-02-21 01:17:21 -08001353 $profman_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001354 $dex2oat_cmdline && \
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +00001355 $dm_cmdline && \
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +00001356 $vdex_cmdline && \
Richard Uhler76f5cb62016-04-04 13:30:16 -07001357 $strip_cmdline && \
Igor Murashkin271a0f82017-02-14 21:14:17 +00001358 $sync_cmdline && \
David Srbeckya49b04f2019-09-16 14:53:15 +00001359 $timeout_prefix $dalvikvm_cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001360
Orion Hodsonecd94cf2020-12-03 13:58:33 +00001361 cmdfile=$(mktemp cmd-XXXX --suffix "-$TEST_NAME")
1362 echo "$cmdline" >> $cmdfile
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001363
1364 if [ "$DEV_MODE" = "y" ]; then
1365 echo $cmdline
Alex Light219420e2019-12-05 10:20:26 -08001366 if [ "$USE_GDB" = "y" ] || [ "$USE_GDBSERVER" = "y" ]; then
1367 echo "Forward ${GDBSERVER_PORT} to local port and connect GDB"
1368 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001369 fi
1370
1371 if [ "$QUIET" = "n" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001372 adb push $cmdfile $CHROOT_DEX_LOCATION/cmdline.sh
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001373 else
Roland Levillain76cfe612017-10-30 13:14:28 +00001374 adb push $cmdfile $CHROOT_DEX_LOCATION/cmdline.sh >/dev/null 2>&1
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001375 fi
1376
Alex Light722d6712018-02-12 17:41:12 +00001377 exit_status=0
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001378 if [ "$DRY_RUN" != "y" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001379 if [ -n "$CHROOT" ]; then
1380 adb shell chroot "$CHROOT" sh $DEX_LOCATION/cmdline.sh
1381 else
1382 adb shell sh $DEX_LOCATION/cmdline.sh
1383 fi
Alex Light722d6712018-02-12 17:41:12 +00001384 exit_status=$?
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001385 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001386
1387 rm -f $cmdfile
Alex Light722d6712018-02-12 17:41:12 +00001388 exit $exit_status
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001389else
Calin Juravle24bd3f92017-05-11 00:36:53 -07001390 # Host run.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001391 export ANDROID_PRINTF_LOG=brief
Andreas Gampea8780822015-03-13 19:51:09 -07001392
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001393 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +00001394 export ANDROID_ROOT="${ANDROID_ROOT}"
Victor Chang64611242019-07-05 16:32:41 +01001395 export ANDROID_I18N_ROOT="${ANDROID_I18N_ROOT}"
Martin Stjernholme58624f2019-09-20 15:53:40 +01001396 export ANDROID_ART_ROOT="${ANDROID_ART_ROOT}"
Neil Fuller26a5dd62019-03-13 15:16:35 +00001397 export ANDROID_TZDATA_ROOT="${ANDROID_TZDATA_ROOT}"
Alex Light6f342dd2019-03-27 17:15:42 +00001398 if [ "$USE_ZIPAPEX" = "y" ] || [ "$USE_EXRACTED_ZIPAPEX" = "y" ]; then
Alex Light20802ca2018-12-05 15:36:03 -08001399 # Put the zipapex files in front of the ld-library-path
Alex Lightf7f31522019-02-01 11:14:41 -08001400 export LD_LIBRARY_PATH="${ANDROID_DATA}/zipapex/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
1401 export DYLD_LIBRARY_PATH="${ANDROID_DATA}/zipapex/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
1402 else
1403 export LD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
1404 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
Alex Light20802ca2018-12-05 15:36:03 -08001405 fi
Martin Stjernholme58624f2019-09-20 15:53:40 +01001406 export PATH="$PATH:$ANDROID_ART_BIN_DIR"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001407
David Srbeckyc9ede382015-06-20 06:03:53 +01001408 # Temporarily disable address space layout randomization (ASLR).
1409 # This is needed on the host so that the linker loads core.oat at the necessary address.
1410 export LD_USE_LOAD_BIAS=1
1411
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001412 cmdline="$dalvikvm_cmdline"
1413
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001414 if [ "$TIME_OUT" = "gdb" ]; then
1415 if [ `uname` = "Darwin" ]; then
1416 # Fall back to timeout on Mac.
1417 TIME_OUT="timeout"
Hiroshi Yamauchic823eff2015-09-01 16:21:35 -07001418 elif [ "$ISA" = "x86" ]; then
1419 # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
1420 TIME_OUT="timeout"
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001421 else
1422 # Check if gdb is available.
1423 gdb --eval-command="quit" > /dev/null 2>&1
1424 if [ $? != 0 ]; then
1425 # gdb isn't available. Fall back to timeout.
1426 TIME_OUT="timeout"
1427 fi
1428 fi
1429 fi
1430
1431 if [ "$TIME_OUT" = "timeout" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001432 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -08001433 #
Andreas Gampe0df2aba2019-06-10 16:53:55 -07001434 # Note: We first send SIGTERM (the timeout default, signal 15) to the signal dumper, which
1435 # will induce a full thread dump before killing the process. To ensure any issues in
1436 # dumping do not lead to a deadlock, we also use the "-k" option to definitely kill the
1437 # child.
Andreas Gampe4bdcf5d2018-12-14 10:48:53 -08001438 # Note: Using "--foreground" to not propagate the signal to children, i.e., the runtime.
Andreas Gampe0df2aba2019-06-10 16:53:55 -07001439 cmdline="timeout --foreground -k 120s ${TIME_OUT_VALUE}s ${TIMEOUT_DUMPER} -s 15 $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001440 fi
1441
1442 if [ "$DEV_MODE" = "y" ]; then
Martin Stjernholme58624f2019-09-20 15:53:40 +01001443 for var in ANDROID_PRINTF_LOG ANDROID_DATA ANDROID_ROOT ANDROID_I18N_ROOT ANDROID_TZDATA_ROOT ANDROID_ART_ROOT LD_LIBRARY_PATH DYLD_LIBRARY_PATH PATH LD_USE_LOAD_BIAS; do
Orion Hodsonee06c5a2018-04-23 13:46:24 +01001444 echo EXPORT $var=${!var}
1445 done
Alex Light680cbf22018-10-31 11:00:19 -07001446 echo "$(declare -f linkdirs)"
Alex Light5e1ffcd2021-03-31 16:46:02 -07001447 echo "mkdir -p ${mkdir_locations} && $setupapex_cmdline && ( $installapex_test_cmdline || $installapex_cmdline ) && $linkroot_cmdline && $linkroot_overlay_cmdline && $profman_cmdline && $dex2oat_cmdline && $dm_cmdline && $vdex_cmdline && $strip_cmdline && $sync_cmdline && $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001448 fi
1449
1450 cd $ANDROID_BUILD_TOP
1451
Calin Juravle24bd3f92017-05-11 00:36:53 -07001452 # Make sure we delete any existing compiler artifacts.
1453 # This enables tests to call the RUN script multiple times in a row
1454 # without worrying about interference.
1455 rm -rf ${DEX_LOCATION}/oat
David Srbecky2e4afe82016-01-27 18:42:06 +00001456 rm -rf ${DEX_LOCATION}/dalvik-cache/
Calin Juravle24bd3f92017-05-11 00:36:53 -07001457
Andreas Gampeb31a8e72017-05-16 10:30:24 -07001458 export ASAN_OPTIONS=$RUN_TEST_ASAN_OPTIONS
1459
Alex Lightafb5d192016-05-24 15:57:45 -07001460 mkdir -p ${mkdir_locations} || exit 1
Alex Light20802ca2018-12-05 15:36:03 -08001461 $setupapex_cmdline || { echo "zipapex extraction failed." >&2 ; exit 2; }
Alex Light5e1ffcd2021-03-31 16:46:02 -07001462 $installapex_test_cmdline || $installapex_cmdline || { echo "zipapex install failed. cmd was: ${installapex_test_cmdline} || ${installapex_cmdline}." >&2; find ${mkdir_locations} -type f >&2; exit 2; }
Alex Light680cbf22018-10-31 11:00:19 -07001463 $linkroot_cmdline || { echo "create symlink android-root failed." >&2 ; exit 2; }
1464 $linkroot_overlay_cmdline || { echo "overlay android-root failed." >&2 ; exit 2; }
Calin Juravle13439f02017-02-21 01:17:21 -08001465 $profman_cmdline || { echo "Profman failed." >&2 ; exit 2; }
Andreas Gampe038a1982020-03-11 23:06:42 +00001466 eval "$dex2oat_cmdline" || { echo "Dex2oat failed." >&2 ; exit 2; }
1467 eval "$dm_cmdline" || { echo "Dex2oat failed." >&2 ; exit 2; }
1468 eval "$vdex_cmdline" || { echo "Dex2oat failed." >&2 ; exit 2; }
Richard Uhler76f5cb62016-04-04 13:30:16 -07001469 $strip_cmdline || { echo "Strip failed." >&2 ; exit 3; }
Igor Murashkin271a0f82017-02-14 21:14:17 +00001470 $sync_cmdline || { echo "Sync failed." >&2 ; exit 4; }
Andreas Gampea8780822015-03-13 19:51:09 -07001471
Alex Light8d94ddd2019-12-18 11:13:03 -08001472 if [ "$CREATE_RUNNER" = "y" ]; then
1473 echo "#!/bin/bash" > ${DEX_LOCATION}/runit.sh
1474 for var in ANDROID_PRINTF_LOG ANDROID_DATA ANDROID_ROOT ANDROID_I18N_ROOT ANDROID_TZDATA_ROOT ANDROID_ART_ROOT LD_LIBRARY_PATH DYLD_LIBRARY_PATH PATH LD_USE_LOAD_BIAS; do
1475 echo export $var="${!var}" >> ${DEX_LOCATION}/runit.sh
1476 done
Alex Light4f915d22020-01-09 17:51:25 -08001477 if [ "$DEV_MODE" = "y" ]; then
Roland Levillainb15e8792020-10-28 12:20:59 +00001478 echo $cmdline >> ${DEX_LOCATION}/runit.sh
Alex Light4f915d22020-01-09 17:51:25 -08001479 else
1480 echo 'STDERR=$(mktemp)' >> ${DEX_LOCATION}/runit.sh
1481 echo 'STDOUT=$(mktemp)' >> ${DEX_LOCATION}/runit.sh
Roland Levillainb15e8792020-10-28 12:20:59 +00001482 echo $cmdline '>${STDOUT} 2>${STDERR}' >> ${DEX_LOCATION}/runit.sh
1483 echo 'if diff ${STDOUT} $ANDROID_DATA/expected-stdout.txt; then' \
1484 >> ${DEX_LOCATION}/runit.sh
1485 echo ' rm -f ${STDOUT} ${STDERR}' >> ${DEX_LOCATION}/runit.sh
1486 echo ' exit 0' >> ${DEX_LOCATION}/runit.sh
1487 echo 'elif diff ${STDERR} $ANDROID_DATA/expected-stderr.txt; then' \
1488 >> ${DEX_LOCATION}/runit.sh
Alex Light4f915d22020-01-09 17:51:25 -08001489 echo ' rm -f ${STDOUT} ${STDERR}' >> ${DEX_LOCATION}/runit.sh
1490 echo ' exit 0' >> ${DEX_LOCATION}/runit.sh
1491 echo 'else' >> ${DEX_LOCATION}/runit.sh
1492 echo ' echo STDOUT:' >> ${DEX_LOCATION}/runit.sh
1493 echo ' cat ${STDOUT}' >> ${DEX_LOCATION}/runit.sh
1494 echo ' echo STDERR:' >> ${DEX_LOCATION}/runit.sh
1495 echo ' cat ${STDERR}' >> ${DEX_LOCATION}/runit.sh
1496 echo ' rm -f ${STDOUT} ${STDERR}' >> ${DEX_LOCATION}/runit.sh
1497 echo ' exit 1' >> ${DEX_LOCATION}/runit.sh
1498 echo 'fi' >> ${DEX_LOCATION}/runit.sh
1499 fi
Alex Light8d94ddd2019-12-18 11:13:03 -08001500 chmod u+x $DEX_LOCATION/runit.sh
1501 echo "Runnable test script written to ${DEX_LOCATION}/runit.sh"
1502 fi
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001503 if [ "$DRY_RUN" = "y" ]; then
1504 exit 0
Andreas Gampea8780822015-03-13 19:51:09 -07001505 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001506
1507 if [ "$USE_GDB" = "y" ]; then
1508 # When running under gdb, we cannot do piping and grepping...
Alex Lighte4b4a182019-02-12 14:19:49 -08001509 $cmdline "$@"
1510 elif [ "$USE_GDBSERVER" = "y" ]; then
1511 echo "Connect to $GDBSERVER_PORT"
1512 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -07001513 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001514 else
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001515 if [ "$TIME_OUT" != "gdb" ]; then
1516 trap 'kill -INT -$pid' INT
Roland Levillainb15e8792020-10-28 12:20:59 +00001517 $cmdline "$@" & pid=$!
Orion Hodson16e7e572020-10-30 09:40:41 +00001518 wait $pid
1519 exit_value=$?
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001520 # Add extra detail if time out is enabled.
Alex Light722d6712018-02-12 17:41:12 +00001521 if [ $exit_value = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001522 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
1523 fi
Alex Light722d6712018-02-12 17:41:12 +00001524 exit $exit_value
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001525 else
1526 # With a thread dump that uses gdb if a timeout.
1527 trap 'kill -INT -$pid' INT
Roland Levillainb15e8792020-10-28 12:20:59 +00001528 $cmdline "$@" & pid=$!
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001529 # Spawn a watcher process.
1530 ( sleep $TIME_OUT_VALUE && \
1531 echo "##### Thread dump using gdb on test timeout" && \
1532 ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
1533 --eval-command="call exit(124)" --eval-command=quit || \
1534 kill $pid )) 2> /dev/null & watcher=$!
1535 wait $pid
1536 test_exit_status=$?
1537 pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
1538 if [ $test_exit_status = 0 ]; then
1539 # The test finished normally.
1540 exit 0
1541 else
1542 # The test failed or timed out.
1543 if [ $test_exit_status = 124 ]; then
1544 # The test timed out.
1545 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
1546 fi
Alex Light722d6712018-02-12 17:41:12 +00001547 exit $test_exit_status
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001548 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001549 fi
1550 fi
1551fi