blob: 631b14afc86d57797ae85eb80d974c0d18a47c13 [file] [log] [blame]
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001#!/bin/bash
2#
3# Runner for an individual run-test.
4
5msg() {
6 if [ "$QUIET" = "n" ]; then
7 echo "$@"
8 fi
9}
10
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000011ANDROID_ROOT="/system"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010012ARCHITECTURES_32="(arm|x86|mips|none)"
Andreas Gampe1a5c4062015-01-15 12:10:47 -080013ARCHITECTURES_64="(arm64|x86_64|mips64|none)"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010014ARCHITECTURES_PATTERN="${ARCHITECTURES_32}"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000015BOOT_IMAGE=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010016COMPILE_FLAGS=""
17DALVIKVM="dalvikvm32"
18DEBUGGER="n"
Alex Light0e151e72017-10-25 10:50:35 -070019WITH_AGENT=""
Alex Lightc281ba52017-10-11 11:35:55 -070020DEBUGGER_AGENT=""
21WRAP_DEBUGGER_AGENT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010022DEV_MODE="n"
23DEX2OAT=""
Alex Light8a0e0332015-10-26 10:11:58 -070024EXPERIMENTAL=""
Nicolas Geoffray90355fe2017-02-20 09:25:40 +000025FALSE_BIN="false"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010026FLAGS=""
Alex Light7233c7e2016-07-28 10:07:45 -070027ANDROID_FLAGS=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010028GDB=""
Nicolas Geoffraybaf91022014-10-08 09:56:45 +010029GDB_ARGS=""
30GDB_SERVER="gdbserver"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010031HAVE_IMAGE="y"
32HOST="n"
33INTERPRETER="n"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080034JIT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010035INVOKE_WITH=""
Alex Lighte06b6342017-01-05 14:37:21 -080036IS_JVMTI_TEST="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010037ISA=x86
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000038LIBRARY_DIRECTORY="lib"
Colin Crossafd3c9e2016-09-16 13:47:21 -070039TEST_DIRECTORY="nativetest"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000040MAIN=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010041OPTIMIZE="y"
42PATCHOAT=""
43PREBUILD="y"
44QUIET="n"
Nicolas Geoffray94e25db2017-01-27 14:54:28 +000045RELOCATE="n"
Richard Uhler76f5cb62016-04-04 13:30:16 -070046STRIP_DEX="n"
Jeff Hao207a37d2014-10-29 17:24:25 -070047SECONDARY_DEX=""
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -070048TIME_OUT="gdb" # "n" (disabled), "timeout" (use timeout), "gdb" (use gdb)
49# Value in seconds
Hiroshi Yamauchifd3161a2017-01-18 14:47:25 -080050if [ "$ART_USE_READ_BARRIER" != "false" ]; then
Hiroshi Yamauchia9b296c2016-10-07 17:07:03 -070051 TIME_OUT_VALUE=2400 # 40 minutes.
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070052else
Mathieu Chartier2576be22016-05-24 10:24:53 -070053 TIME_OUT_VALUE=1200 # 20 minutes.
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070054fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010055USE_GDB="n"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +010056USE_JVM="n"
Alex Lightc281ba52017-10-11 11:35:55 -070057USE_JVMTI="n"
Igor Murashkin7617abd2015-07-10 18:27:47 -070058VERIFY="y" # y=yes,n=no,s=softfail
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010059ZYGOTE=""
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -070060DEX_VERIFY=""
Andreas Gampe65357032015-02-19 15:10:24 -080061USE_DEX2OAT_AND_PATCHOAT="y"
Andreas Gampe4d2ef332015-08-05 09:24:45 -070062INSTRUCTION_SET_FEATURES=""
Mathieu Chartier031768a2015-08-27 10:25:02 -070063ARGS=""
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -070064EXTERNAL_LOG_TAGS="n" # if y respect externally set ANDROID_LOG_TAGS.
65DRY_RUN="n" # if y prepare to run the test but don't run it.
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +000066TEST_VDEX="n"
Alex Lighte06b6342017-01-05 14:37:21 -080067TEST_IS_NDEBUG="n"
Calin Juravle857f0582016-12-20 14:36:59 +000068APP_IMAGE="y"
Alex Light8f2c6d42017-04-10 16:27:35 -070069JVMTI_STRESS="n"
Alex Lightc38c3692017-06-27 15:45:14 -070070JVMTI_STEP_STRESS="n"
Alex Light43e935d2017-06-19 15:40:40 -070071JVMTI_FIELD_STRESS="n"
Alex Lightb7edcda2017-04-27 13:20:31 -070072JVMTI_TRACE_STRESS="n"
73JVMTI_REDEFINE_STRESS="n"
Nicolas Geoffray74981052017-01-16 17:54:09 +000074VDEX_FILTER=""
Calin Juravle13439f02017-02-21 01:17:21 -080075PROFILE="n"
Jeff Hao002b9312017-03-27 16:23:08 -070076RANDOM_PROFILE="n"
Alex Light483208d2017-09-26 09:31:17 -070077# The normal dex2oat timeout.
Shubham Ajmeraf97cbd62017-10-11 10:00:57 -070078DEX2OAT_TIMEOUT="300" # 5 mins
Alex Light483208d2017-09-26 09:31:17 -070079# The *hard* timeout where we really start trying to kill the dex2oat.
Shubham Ajmeraf97cbd62017-10-11 10:00:57 -070080DEX2OAT_RT_TIMEOUT="360" # 6 mins
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010081
Narayan Kamath84695ae2017-04-07 15:41:41 +010082# if "y", set -Xstacktracedir and inform the test of its location. When
83# this is set, stack trace dumps (from signal 3) will be written to a file
84# under this directory instead of stdout.
85SET_STACK_TRACE_DUMP_DIR="n"
86
Igor Murashkin271a0f82017-02-14 21:14:17 +000087# if "y", run 'sync' before dalvikvm to make sure all files from
88# build step (e.g. dex2oat) were finished writing.
89SYNC_BEFORE_RUN="n"
90
Andreas Gampe1c5b42f2017-06-15 18:20:45 -070091# When running a debug build, we want to run with all checks.
92ANDROID_FLAGS="${ANDROID_FLAGS} -XX:SlowDebug=true"
Andreas Gampee8f74ca2018-01-02 09:26:16 -080093# The same for dex2oatd, both prebuild and runtime-driven.
94ANDROID_FLAGS="${ANDROID_FLAGS} -Xcompiler-option --runtime-arg -Xcompiler-option -XX:SlowDebug=true"
95COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -XX:SlowDebug=true"
Andreas Gampe1c5b42f2017-06-15 18:20:45 -070096
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010097while true; do
98 if [ "x$1" = "x--quiet" ]; then
99 QUIET="y"
100 shift
Alex Light483208d2017-09-26 09:31:17 -0700101 elif [ "x$1" = "x--dex2oat-rt-timeout" ]; then
102 shift
103 if [ "x$1" = "x" ]; then
104 echo "$0 missing argument to --dex2oat-rt-timeout" 1>&2
105 exit 1
106 fi
107 DEX2OAT_RT_TIMEOUT="$1"
108 shift
109 elif [ "x$1" = "x--dex2oat-timeout" ]; then
110 shift
111 if [ "x$1" = "x" ]; then
112 echo "$0 missing argument to --dex2oat-timeout" 1>&2
113 exit 1
114 fi
115 DEX2OAT_TIMEOUT="$1"
116 shift
Alex Lighte06b6342017-01-05 14:37:21 -0800117 elif [ "x$1" = "x--jvmti" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700118 USE_JVMTI="y"
Alex Lighte06b6342017-01-05 14:37:21 -0800119 IS_JVMTI_TEST="y"
120 shift
Alex Lightfaf90b62016-08-12 14:43:48 -0700121 elif [ "x$1" = "x-O" ]; then
Alex Lighte06b6342017-01-05 14:37:21 -0800122 TEST_IS_NDEBUG="y"
Alex Lightfaf90b62016-08-12 14:43:48 -0700123 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100124 elif [ "x$1" = "x--lib" ]; then
125 shift
126 if [ "x$1" = "x" ]; then
127 echo "$0 missing argument to --lib" 1>&2
128 exit 1
129 fi
130 LIB="$1"
131 shift
Alex Light97acf192016-03-17 09:59:38 -0700132 elif [ "x$1" = "x--gc-stress" ]; then
133 # Give an extra 5 mins if we are gc-stress.
134 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + 300))
135 shift
Mathieu Chartier031768a2015-08-27 10:25:02 -0700136 elif [ "x$1" = "x--testlib" ]; then
137 shift
138 if [ "x$1" = "x" ]; then
139 echo "$0 missing argument to --testlib" 1>&2
140 exit 1
141 fi
Mathieu Chartierde286fd2015-09-03 18:10:29 -0700142 ARGS="${ARGS} $1"
Mathieu Chartier031768a2015-08-27 10:25:02 -0700143 shift
David Srbecky52886112016-01-22 13:56:47 +0000144 elif [ "x$1" = "x--args" ]; then
145 shift
146 if [ "x$1" = "x" ]; then
147 echo "$0 missing argument to --args" 1>&2
148 exit 1
149 fi
150 ARGS="${ARGS} $1"
151 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100152 elif [ "x$1" = "x-Xcompiler-option" ]; then
153 shift
154 option="$1"
155 FLAGS="${FLAGS} -Xcompiler-option $option"
156 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
157 shift
Alex Light7233c7e2016-07-28 10:07:45 -0700158 elif [ "x$1" = "x--android-runtime-option" ]; then
159 shift
160 option="$1"
161 ANDROID_FLAGS="${ANDROID_FLAGS} $option"
162 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100163 elif [ "x$1" = "x--runtime-option" ]; then
164 shift
165 option="$1"
166 FLAGS="${FLAGS} $option"
167 shift
168 elif [ "x$1" = "x--boot" ]; then
169 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000170 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100171 shift
172 elif [ "x$1" = "x--no-dex2oat" ]; then
173 DEX2OAT="-Xcompiler:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800174 USE_DEX2OAT_AND_PATCHOAT="n"
Andreas Gampe5b8a1972017-11-07 10:23:48 -0800175 PREBUILD="n" # Do not use prebuilt odex, either.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100176 shift
177 elif [ "x$1" = "x--no-patchoat" ]; then
178 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800179 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100180 shift
181 elif [ "x$1" = "x--relocate" ]; then
182 RELOCATE="y"
183 shift
184 elif [ "x$1" = "x--no-relocate" ]; then
185 RELOCATE="n"
186 shift
187 elif [ "x$1" = "x--prebuild" ]; then
188 PREBUILD="y"
189 shift
Mathieu Chartierdcd56c92017-11-20 20:30:24 -0800190 elif [ "x$1" = "x--compact-dex-level" ]; then
191 shift
192 COMPILE_FLAGS="${COMPILE_FLAGS} --compact-dex-level=$1"
193 shift
Alex Lightb7edcda2017-04-27 13:20:31 -0700194 elif [ "x$1" = "x--jvmti-redefine-stress" ]; then
195 # APP_IMAGE doesn't really work with jvmti redefine stress
Alex Lightc281ba52017-10-11 11:35:55 -0700196 USE_JVMTI="y"
Alex Light8f2c6d42017-04-10 16:27:35 -0700197 APP_IMAGE="n"
198 JVMTI_STRESS="y"
Alex Lightb7edcda2017-04-27 13:20:31 -0700199 JVMTI_REDEFINE_STRESS="y"
200 shift
Alex Lightc38c3692017-06-27 15:45:14 -0700201 elif [ "x$1" = "x--jvmti-step-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700202 USE_JVMTI="y"
Alex Lightc38c3692017-06-27 15:45:14 -0700203 JVMTI_STRESS="y"
204 JVMTI_STEP_STRESS="y"
205 shift
Alex Light43e935d2017-06-19 15:40:40 -0700206 elif [ "x$1" = "x--jvmti-field-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700207 USE_JVMTI="y"
Alex Light43e935d2017-06-19 15:40:40 -0700208 JVMTI_STRESS="y"
209 JVMTI_FIELD_STRESS="y"
210 shift
Alex Lightb7edcda2017-04-27 13:20:31 -0700211 elif [ "x$1" = "x--jvmti-trace-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700212 USE_JVMTI="y"
Alex Lightb7edcda2017-04-27 13:20:31 -0700213 JVMTI_STRESS="y"
214 JVMTI_TRACE_STRESS="y"
Alex Light8f2c6d42017-04-10 16:27:35 -0700215 shift
Calin Juravle857f0582016-12-20 14:36:59 +0000216 elif [ "x$1" = "x--no-app-image" ]; then
217 APP_IMAGE="n"
218 shift
Richard Uhler76f5cb62016-04-04 13:30:16 -0700219 elif [ "x$1" = "x--strip-dex" ]; then
220 STRIP_DEX="y"
221 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100222 elif [ "x$1" = "x--host" ]; then
223 HOST="y"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000224 ANDROID_ROOT="$ANDROID_HOST_OUT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100225 shift
226 elif [ "x$1" = "x--no-prebuild" ]; then
227 PREBUILD="n"
228 shift
229 elif [ "x$1" = "x--no-image" ]; then
230 HAVE_IMAGE="n"
231 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700232 elif [ "x$1" = "x--secondary" ]; then
233 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
Calin Juravle175dc732015-08-25 15:42:32 +0100234 # Enable cfg-append to make sure we get the dump for both dex files.
235 # (otherwise the runtime compilation of the secondary dex will overwrite
Roland Levillainb0103ca2016-11-01 14:48:47 +0000236 # the dump of the first one).
Calin Juravle175dc732015-08-25 15:42:32 +0100237 FLAGS="${FLAGS} -Xcompiler-option --dump-cfg-append"
238 COMPILE_FLAGS="${COMPILE_FLAGS} --dump-cfg-append"
Jeff Hao207a37d2014-10-29 17:24:25 -0700239 shift
Alex Light0e151e72017-10-25 10:50:35 -0700240 elif [ "x$1" = "x--with-agent" ]; then
241 shift
242 USE_JVMTI="y"
243 WITH_AGENT="$1"
244 shift
Alex Lightc281ba52017-10-11 11:35:55 -0700245 elif [ "x$1" = "x--debug-wrap-agent" ]; then
246 WRAP_DEBUGGER_AGENT="y"
247 shift
248 elif [ "x$1" = "x--debug-agent" ]; then
249 shift
250 DEBUGGER="agent"
251 USE_JVMTI="y"
252 DEBUGGER_AGENT="$1"
253 TIME_OUT="n"
254 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100255 elif [ "x$1" = "x--debug" ]; then
256 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800257 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100258 shift
259 elif [ "x$1" = "x--gdb" ]; then
260 USE_GDB="y"
261 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800262 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100263 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700264 elif [ "x$1" = "x--gdb-arg" ]; then
265 shift
266 gdb_arg="$1"
267 GDB_ARGS="${GDB_ARGS} $gdb_arg"
268 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100269 elif [ "x$1" = "x--zygote" ]; then
270 ZYGOTE="-Xzygote"
271 msg "Spawning from zygote"
272 shift
273 elif [ "x$1" = "x--dev" ]; then
274 DEV_MODE="y"
275 shift
276 elif [ "x$1" = "x--interpreter" ]; then
277 INTERPRETER="y"
278 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800279 elif [ "x$1" = "x--jit" ]; then
280 JIT="y"
281 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100282 elif [ "x$1" = "x--jvm" ]; then
283 USE_JVM="y"
284 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100285 elif [ "x$1" = "x--invoke-with" ]; then
286 shift
287 if [ "x$1" = "x" ]; then
288 echo "$0 missing argument to --invoke-with" 1>&2
289 exit 1
290 fi
291 if [ "x$INVOKE_WITH" = "x" ]; then
292 INVOKE_WITH="$1"
293 else
294 INVOKE_WITH="$INVOKE_WITH $1"
295 fi
296 shift
297 elif [ "x$1" = "x--no-verify" ]; then
298 VERIFY="n"
299 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700300 elif [ "x$1" = "x--verify-soft-fail" ]; then
301 VERIFY="s"
302 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100303 elif [ "x$1" = "x--no-optimize" ]; then
304 OPTIMIZE="n"
305 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000306 elif [ "x$1" = "x--android-root" ]; then
307 shift
308 ANDROID_ROOT="$1"
309 shift
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700310 elif [ "x$1" = "x--instruction-set-features" ]; then
311 shift
312 INSTRUCTION_SET_FEATURES="$1"
313 shift
Mathieu Chartier2576be22016-05-24 10:24:53 -0700314 elif [ "x$1" = "x--timeout" ]; then
315 shift
316 TIME_OUT_VALUE="$1"
317 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100318 elif [ "x$1" = "x--" ]; then
319 shift
320 break
321 elif [ "x$1" = "x--64" ]; then
322 ISA="x86_64"
323 GDB_SERVER="gdbserver64"
324 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000325 LIBRARY_DIRECTORY="lib64"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700326 TEST_DIRECTORY="nativetest64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100327 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
328 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700329 elif [ "x$1" = "x--pic-test" ]; then
330 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
331 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
332 shift
Alex Light8a0e0332015-10-26 10:11:58 -0700333 elif [ "x$1" = "x--experimental" ]; then
334 if [ "$#" -lt 2 ]; then
335 echo "missing --experimental option" 1>&2
336 exit 1
337 fi
338 EXPERIMENTAL="$EXPERIMENTAL $2"
339 shift 2
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700340 elif [ "x$1" = "x--external-log-tags" ]; then
341 EXTERNAL_LOG_TAGS="y"
342 shift
343 elif [ "x$1" = "x--dry-run" ]; then
344 DRY_RUN="y"
345 shift
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000346 elif [ "x$1" = "x--vdex" ]; then
347 TEST_VDEX="y"
348 shift
Nicolas Geoffray74981052017-01-16 17:54:09 +0000349 elif [ "x$1" = "x--vdex-filter" ]; then
350 shift
351 option="$1"
352 VDEX_FILTER="--compiler-filter=$option"
353 shift
Igor Murashkin271a0f82017-02-14 21:14:17 +0000354 elif [ "x$1" = "x--sync" ]; then
355 SYNC_BEFORE_RUN="y"
356 shift
Calin Juravle13439f02017-02-21 01:17:21 -0800357 elif [ "x$1" = "x--profile" ]; then
358 PROFILE="y"
359 shift
Jeff Hao002b9312017-03-27 16:23:08 -0700360 elif [ "x$1" = "x--random-profile" ]; then
361 RANDOM_PROFILE="y"
362 shift
Narayan Kamath84695ae2017-04-07 15:41:41 +0100363 elif [ "x$1" = "x--set-stack-trace-dump-dir" ]; then
364 SET_STACK_TRACE_DUMP_DIR="y"
365 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100366 elif expr "x$1" : "x--" >/dev/null 2>&1; then
367 echo "unknown $0 option: $1" 1>&2
368 exit 1
369 else
370 break
371 fi
372done
373
Narayan Kamath84695ae2017-04-07 15:41:41 +0100374mkdir_locations=""
375
Alex Light8a0e0332015-10-26 10:11:58 -0700376if [ "$USE_JVM" = "n" ]; then
Alex Light7233c7e2016-07-28 10:07:45 -0700377 FLAGS="${FLAGS} ${ANDROID_FLAGS}"
Alex Light8a0e0332015-10-26 10:11:58 -0700378 for feature in ${EXPERIMENTAL}; do
Alex Lightfa022852015-10-28 09:13:20 -0700379 FLAGS="${FLAGS} -Xexperimental:${feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:${feature}"
Alex Light8a0e0332015-10-26 10:11:58 -0700380 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xexperimental:${feature}"
381 done
Narayan Kamath84695ae2017-04-07 15:41:41 +0100382
383 if [ "$SET_STACK_TRACE_DUMP_DIR" = "y" ]; then
384 # Note that DEX_LOCATION is used as a proxy for tmpdir throughout this
385 # file (it will be under the test specific folder).
386 mkdir_locations="${mkdir_locations} $DEX_LOCATION/stack_traces"
387 FLAGS="${FLAGS} -Xstacktracedir:$DEX_LOCATION/stack_traces"
388 ARGS="${ARGS} --stack-trace-dir $DEX_LOCATION/stack_traces"
389 fi
Alex Light8a0e0332015-10-26 10:11:58 -0700390fi
391
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100392if [ "x$1" = "x" ] ; then
393 MAIN="Main"
394else
395 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700396 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100397fi
398
399if [ "$ZYGOTE" = "" ]; then
400 if [ "$OPTIMIZE" = "y" ]; then
401 if [ "$VERIFY" = "y" ]; then
402 DEX_OPTIMIZE="-Xdexopt:verified"
403 else
404 DEX_OPTIMIZE="-Xdexopt:all"
405 fi
406 msg "Performing optimizations"
407 else
408 DEX_OPTIMIZE="-Xdexopt:none"
409 msg "Skipping optimizations"
410 fi
411
412 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100413 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100414 msg "Performing verification"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700415 elif [ "$VERIFY" = "s" ]; then
416 JVM_VERIFY_ARG="Xverify:all"
417 DEX_VERIFY="-Xverify:softfail"
418 msg "Forcing verification to be soft fail"
419 else # VERIFY = "n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100420 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100421 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100422 msg "Skipping verification"
423 fi
424fi
425
426msg "------------------------------"
427
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100428if [ "$DEBUGGER" = "y" ]; then
429 # Use this instead for ddms and connect by running 'ddms':
430 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
431 # TODO: add a separate --ddms option?
432
433 PORT=12345
434 msg "Waiting for jdb to connect:"
435 if [ "$HOST" = "n" ]; then
436 msg " adb forward tcp:$PORT tcp:$PORT"
437 fi
438 msg " jdb -attach localhost:$PORT"
439 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
Alex Lightc281ba52017-10-11 11:35:55 -0700440elif [ "$DEBUGGER" = "agent" ]; then
441 PORT=12345
442 # TODO Support ddms connection and support target.
443 if [ "$HOST" = "n" ]; then
444 echo "--debug-agent not supported yet for target!"
445 exit 1
446 fi
447 AGENTPATH=${DEBUGGER_AGENT}
448 if [ "$WRAP_DEBUGGER_AGENT" = "y" ]; then
449 WRAPPROPS="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}/libwrapagentpropertiesd.so"
450 if [ "$TEST_IS_NDEBUG" = "y" ]; then
451 WRAPPROPS="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}/libwrapagentproperties.so"
452 fi
453 AGENTPATH="${WRAPPROPS}=${ANDROID_BUILD_TOP}/art/tools/libjdwp-compat.props,${AGENTPATH}"
454 fi
455 msg "Connect to localhost:$PORT"
456 DEBUGGER_OPTS="-agentpath:${AGENTPATH}=transport=dt_socket,address=$PORT,server=y,suspend=y"
457fi
458
Alex Light0e151e72017-10-25 10:50:35 -0700459if [ "x$WITH_AGENT" != "x" ]; then
460 FLAGS="${FLAGS} -agentpath:${WITH_AGENT}"
461fi
462
Alex Lightc281ba52017-10-11 11:35:55 -0700463if [ "$USE_JVMTI" = "y" ]; then
464 if [ "$USE_JVM" = "n" ]; then
465 plugin=libopenjdkjvmtid.so
466 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
467 plugin=libopenjdkjvmti.so
468 fi
Alex Light2ce6fc82017-12-18 16:42:36 -0800469 # We used to add flags here that made the runtime debuggable but that is not
470 # needed anymore since the plugin can do it for us now.
Alex Lightc281ba52017-10-11 11:35:55 -0700471 FLAGS="${FLAGS} -Xplugin:${plugin}"
Alex Lightc281ba52017-10-11 11:35:55 -0700472 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100473fi
474
Alex Lightfba89fe2017-01-12 16:11:02 -0800475if [ "$IS_JVMTI_TEST" = "y" ]; then
Alex Lightfba89fe2017-01-12 16:11:02 -0800476 agent=libtiagentd.so
477 lib=tiagentd
478 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
479 agent=libtiagent.so
Alex Lightfba89fe2017-01-12 16:11:02 -0800480 lib=tiagent
481 fi
482
483 ARGS="${ARGS} ${lib}"
484 if [[ "$USE_JVM" = "y" ]]; then
485 FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${TEST_NAME},jvm"
486 else
487 FLAGS="${FLAGS} -agentpath:${agent}=${TEST_NAME},art"
Alex Lightfba89fe2017-01-12 16:11:02 -0800488 fi
489fi
490
Alex Light8f2c6d42017-04-10 16:27:35 -0700491if [[ "$JVMTI_STRESS" = "y" ]]; then
Alex Light42151c02017-04-20 15:54:25 -0700492 agent=libtistressd.so
493 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
494 agent=libtistress.so
Alex Light42151c02017-04-20 15:54:25 -0700495 fi
Alex Light8f2c6d42017-04-10 16:27:35 -0700496
Alex Lightb7edcda2017-04-27 13:20:31 -0700497 # Just give it a default start so we can always add ',' to it.
498 agent_args="jvmti-stress"
499 if [[ "$JVMTI_REDEFINE_STRESS" = "y" ]]; then
500 # We really cannot do this on RI so don't both passing it in that case.
501 if [[ "$USE_JVM" = "n" ]]; then
Alex Lightceae9542017-09-07 13:28:00 -0700502 agent_args="${agent_args},redefine"
Alex Lightb7edcda2017-04-27 13:20:31 -0700503 fi
504 fi
Alex Light43e935d2017-06-19 15:40:40 -0700505 if [[ "$JVMTI_FIELD_STRESS" = "y" ]]; then
506 agent_args="${agent_args},field"
507 fi
Alex Lightc38c3692017-06-27 15:45:14 -0700508 if [[ "$JVMTI_STEP_STRESS" = "y" ]]; then
509 agent_args="${agent_args},step"
510 fi
Alex Lightb7edcda2017-04-27 13:20:31 -0700511 if [[ "$JVMTI_TRACE_STRESS" = "y" ]]; then
512 agent_args="${agent_args},trace"
513 fi
514 # In the future add onto this;
Alex Light42151c02017-04-20 15:54:25 -0700515 if [[ "$USE_JVM" = "y" ]]; then
Alex Lightb7edcda2017-04-27 13:20:31 -0700516 FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${agent_args}"
Alex Light42151c02017-04-20 15:54:25 -0700517 else
Alex Lightb7edcda2017-04-27 13:20:31 -0700518 FLAGS="${FLAGS} -agentpath:${agent}=${agent_args}"
Alex Light8f2c6d42017-04-10 16:27:35 -0700519 fi
520fi
521
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100522if [ "$USE_JVM" = "y" ]; then
Alex Light9c20a142016-08-23 15:05:12 -0700523 export LD_LIBRARY_PATH=${ANDROID_HOST_OUT}/lib64
Alex Light47d49b82017-07-25 14:06:34 -0700524 # Some jvmti tests are flaky without -Xint on the RI.
525 if [ "$IS_JVMTI_TEST" = "y" ]; then
526 FLAGS="${FLAGS} -Xint"
527 fi
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700528 # Xmx is necessary since we don't pass down the ART flags to JVM.
Vladimir Markoc5798bf2016-12-09 10:20:54 +0000529 # We pass the classes2 path whether it's used (src-multidex) or not.
530 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes:classes2 ${FLAGS} $MAIN $@ ${ARGS}"
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700531 if [ "$DEV_MODE" = "y" ]; then
532 echo $cmdline
533 fi
534 $cmdline
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100535 exit
536fi
537
538
539if [ "$HAVE_IMAGE" = "n" ]; then
Vladimir Markoe00e5592017-02-24 14:58:29 +0000540 if [ "${HOST}" = "y" ]; then
541 framework="${ANDROID_HOST_OUT}/framework"
542 bpath_suffix="-hostdex"
543 else
544 framework="${ANDROID_ROOT}/framework"
Nicolas Geoffray320ccca2017-03-01 10:03:08 +0000545 bpath_suffix="-testdex"
Vladimir Markoe00e5592017-02-24 14:58:29 +0000546 fi
Vladimir Markoe00e5592017-02-24 14:58:29 +0000547 bpath="${framework}/core-libart${bpath_suffix}.jar"
548 bpath="${bpath}:${framework}/core-oj${bpath_suffix}.jar"
549 bpath="${bpath}:${framework}/conscrypt${bpath_suffix}.jar"
550 bpath="${bpath}:${framework}/okhttp${bpath_suffix}.jar"
551 bpath="${bpath}:${framework}/bouncycastle${bpath_suffix}.jar"
552 # Pass down the bootclasspath
553 FLAGS="${FLAGS} -Xbootclasspath:${bpath}"
Andreas Gampe1078d152017-11-07 18:00:54 -0800554 # Disable image dex2oat - this will forbid the runtime to patch or compile an image.
555 FLAGS="${FLAGS} -Xnoimage-dex2oat"
556
557 # We'll abuse a second flag here to test different behavior. If --relocate, use the
558 # existing image - relocation will fail as patching is disallowed. If --no-relocate,
559 # pass a non-existent image - compilation will fail as dex2oat is disallowed.
560 if [ "${RELOCATE}" = "y" ] ; then
561 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
562 else
563 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
564 fi
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000565else
566 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100567fi
568
569
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100570if [ "$USE_GDB" = "y" ]; then
571 if [ "$HOST" = "n" ]; then
572 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100573 else
574 if [ `uname` = "Darwin" ]; then
575 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700576 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100577 DALVIKVM=
578 else
579 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700580 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100581 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
582 # gdbargs="--annotate=3 $gdbargs"
583 fi
584 fi
585fi
586
587if [ "$INTERPRETER" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000588 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700589 if [ "$VERIFY" = "y" ] ; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100590 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=quicken"
591 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=quicken"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700592 elif [ "$VERIFY" = "s" ]; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100593 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=extract"
594 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=extract"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700595 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
596 else # VERIFY = "n"
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100597 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=assume-verified"
598 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=assume-verified"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700599 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
600 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100601fi
602
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800603if [ "$JIT" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000604 INT_OPTS="-Xusejit:true"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800605 if [ "$VERIFY" = "y" ] ; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100606 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=quicken"
607 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=quicken"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800608 else
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100609 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=assume-verified"
610 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=assume-verified"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800611 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
612 fi
613fi
614
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100615JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
616
Richard Uhler020c0f32017-03-14 16:23:17 +0000617COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100618if [ "$RELOCATE" = "y" ]; then
Richard Uhlerc52f3032017-03-02 13:45:45 +0000619 FLAGS="${FLAGS} -Xrelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100620else
621 FLAGS="$FLAGS -Xnorelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100622fi
623
624if [ "$HOST" = "n" ]; then
Nicolas Geoffrayd295bc82016-11-04 13:03:05 +0000625 # Need to be root to query /data/dalvik-cache
626 adb root > /dev/null
627 adb wait-for-device
628 ISA=
629 ISA_adb_invocation=
630 ISA_outcome=
631 # We iterate a few times to workaround an adb issue. b/32655576
632 for i in {1..10}; do
633 ISA_adb_invocation=$(adb shell ls -F /data/dalvik-cache)
634 ISA_outcome=$?
635 ISA=$(echo $ISA_adb_invocation | grep -Ewo "${ARCHITECTURES_PATTERN}")
636 if [ x"$ISA" != "x" ]; then
637 break;
638 fi
639 done
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100640 if [ x"$ISA" = "x" ]; then
641 echo "Unable to determine architecture"
Nicolas Geoffray8f500fa2016-11-03 11:18:48 +0000642 # Print a few things for helping diagnosing the problem.
Nicolas Geoffrayd295bc82016-11-04 13:03:05 +0000643 echo "adb invocation output: $ISA_adb_invocation"
644 echo "adb invocation outcome: $ISA_outcome"
Nicolas Geoffray8f500fa2016-11-03 11:18:48 +0000645 echo $(adb shell ls -F /data/dalvik-cache)
646 echo $(adb shell ls /data/dalvik-cache)
647 echo ${ARCHITECTURES_PATTERN}
648 echo $(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100649 exit 1
650 fi
651fi
652
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700653# Prevent test from silently falling back to interpreter in no-prebuild mode. This happens
654# when DEX_LOCATION path is too long, because vdex/odex filename is constructed by taking
655# full path to dex, stripping leading '/', appending '@classes.vdex' and changing every
656# remaining '/' into '@'.
657if [ "$HOST" = "y" ]; then
658 max_filename_size=$(getconf NAME_MAX $DEX_LOCATION)
659else
660 # There is no getconf on device, fallback to standard value. See NAME_MAX in kernel <linux/limits.h>
661 max_filename_size=255
662fi
663# Compute VDEX_NAME.
664DEX_LOCATION_STRIPPED="${DEX_LOCATION#/}"
665VDEX_NAME="${DEX_LOCATION_STRIPPED//\//@}@$TEST_NAME.jar@classes.vdex"
666if [ ${#VDEX_NAME} -gt $max_filename_size ]; then
Nicolas Geoffraybea3e312017-03-07 09:59:05 +0000667 echo "Dex location path too long:"
668 echo "$VDEX_NAME is ${#VDEX_NAME} character long, and the limit is $max_filename_size."
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700669 exit 1
670fi
671
Calin Juravle13439f02017-02-21 01:17:21 -0800672profman_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100673dex2oat_cmdline="true"
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000674vdex_cmdline="true"
Narayan Kamath84695ae2017-04-07 15:41:41 +0100675mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/dalvik-cache/$ISA"
Richard Uhler76f5cb62016-04-04 13:30:16 -0700676strip_cmdline="true"
Igor Murashkin271a0f82017-02-14 21:14:17 +0000677sync_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100678
Jeff Hao002b9312017-03-27 16:23:08 -0700679# PROFILE takes precedence over RANDOM_PROFILE, since PROFILE tests require a
680# specific profile to run properly.
681if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000682 profman_cmdline="${ANDROID_ROOT}/bin/profman \
683 --apk=$DEX_LOCATION/$TEST_NAME.jar \
Jeff Hao002b9312017-03-27 16:23:08 -0700684 --dex-location=$DEX_LOCATION/$TEST_NAME.jar"
Calin Juravle6df62f72017-04-28 19:58:01 -0700685 if [ -f $DEX_LOCATION/$TEST_NAME-ex.jar ]; then
686 profman_cmdline="${profman_cmdline} \
687 --apk=$DEX_LOCATION/$TEST_NAME-ex.jar \
688 --dex-location=$DEX_LOCATION/$TEST_NAME-ex.jar"
689 fi
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000690 COMPILE_FLAGS="${COMPILE_FLAGS} --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
691 FLAGS="${FLAGS} -Xcompiler-option --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
Jeff Hao002b9312017-03-27 16:23:08 -0700692 if [ "$PROFILE" = "y" ]; then
693 profman_cmdline="${profman_cmdline} --create-profile-from=$DEX_LOCATION/profile \
694 --reference-profile-file=$DEX_LOCATION/$TEST_NAME.prof"
695 else
696 profman_cmdline="${profman_cmdline} --generate-test-profile=$DEX_LOCATION/$TEST_NAME.prof \
697 --generate-test-profile-seed=0"
698 fi
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000699fi
700
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100701if [ "$PREBUILD" = "y" ]; then
Alex Lightafb5d192016-05-24 15:57:45 -0700702 mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/oat/$ISA"
Calin Juravle857f0582016-12-20 14:36:59 +0000703 if [ "$APP_IMAGE" = "y" ]; then
704 # Pick a base that will force the app image to get relocated.
705 app_image="--base=0x4000 --app-image-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.art"
706 fi
707
Roland Levillain6c3af162017-04-27 11:18:56 +0100708 dex2oat_binary=dex2oatd
709 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
710 dex2oat_binary=dex2oat
711 fi
712 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/$dex2oat_binary \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100713 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000714 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100715 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
Andreas Gampe14759242016-03-23 10:54:21 -0700716 --oat-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.odex \
Jeff Haodcdc85b2015-12-04 14:06:18 -0800717 ${app_image} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100718 --instruction-set=$ISA"
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700719 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
720 dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
721 fi
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700722
723 # Add in a timeout. This is important for testing the compilation/verification time of
724 # pathological cases.
725 # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
726 # now. We should try to improve this.
727 # The current value is rather arbitrary. run-tests should compile quickly.
Alex Light483208d2017-09-26 09:31:17 -0700728 # Watchdog timeout is in milliseconds so add 3 '0's to the dex2oat timeout.
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700729 if [ "$HOST" != "n" ]; then
730 # Use SIGRTMIN+2 to try to dump threads.
731 # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
Alex Light483208d2017-09-26 09:31:17 -0700732 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 -0700733 fi
Nicolas Geoffrayfbc4f112017-04-27 21:45:35 +0100734 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
735 vdex_cmdline="${dex2oat_cmdline} ${VDEX_FILTER} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex --output-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
736 elif [ "$TEST_VDEX" = "y" ]; then
Nicolas Geoffray74981052017-01-16 17:54:09 +0000737 vdex_cmdline="${dex2oat_cmdline} ${VDEX_FILTER} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
Nicolas Geoffraycab65572017-04-21 17:16:44 +0100738 elif [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
739 vdex_cmdline="${dex2oat_cmdline} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex --output-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000740 fi
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700741fi
742
Richard Uhler76f5cb62016-04-04 13:30:16 -0700743if [ "$STRIP_DEX" = "y" ]; then
744 strip_cmdline="zip --quiet --delete $DEX_LOCATION/$TEST_NAME.jar classes.dex"
745fi
746
Igor Murashkin271a0f82017-02-14 21:14:17 +0000747if [ "$SYNC_BEFORE_RUN" = "y" ]; then
748 sync_cmdline="sync"
749fi
750
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700751DALVIKVM_ISA_FEATURES_ARGS=""
752if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
753 DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100754fi
755
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000756# java.io.tmpdir can only be set at launch time.
757TMP_DIR_OPTION=""
758if [ "$HOST" = "n" ]; then
759 TMP_DIR_OPTION="-Djava.io.tmpdir=/data/local/tmp"
760fi
761
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000762# We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
763# b/27185632
764# b/24664297
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000765dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100766 $GDB_ARGS \
767 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700768 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100769 -XXlib:$LIB \
770 $PATCHOAT \
771 $DEX2OAT \
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700772 $DALVIKVM_ISA_FEATURES_ARGS \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100773 $ZYGOTE \
774 $JNI_OPTS \
775 $INT_OPTS \
776 $DEBUGGER_OPTS \
777 $DALVIKVM_BOOT_OPT \
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000778 $TMP_DIR_OPTION \
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000779 -XX:DumpNativeStackOnSigQuit:false \
Mathieu Chartier031768a2015-08-27 10:25:02 -0700780 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100781
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -0800782# Remove whitespace.
783dex2oat_cmdline=$(echo $dex2oat_cmdline)
784dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000785vdex_cmdline=$(echo $vdex_cmdline)
Calin Juravle13439f02017-02-21 01:17:21 -0800786profman_cmdline=$(echo $profman_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100787
Andreas Gampeb31a8e72017-05-16 10:30:24 -0700788# Use an empty ASAN_OPTIONS to enable defaults.
789# Note: this is required as envsetup right now exports detect_leaks=0.
790RUN_TEST_ASAN_OPTIONS=""
791
Andreas Gampe58408392017-05-16 10:45:46 -0700792# Multiple shutdown leaks. b/38341789
793if [ "x$RUN_TEST_ASAN_OPTIONS" != "x" ] ; then
794 RUN_TEST_ASAN_OPTIONS="${RUN_TEST_ASAN_OPTIONS}:"
795fi
796RUN_TEST_ASAN_OPTIONS="${RUN_TEST_ASAN_OPTIONS}detect_leaks=0"
797
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100798if [ "$HOST" = "n" ]; then
799 adb root > /dev/null
800 adb wait-for-device
801 if [ "$QUIET" = "n" ]; then
Calin Juravle24bd3f92017-05-11 00:36:53 -0700802 adb shell rm -rf $DEX_LOCATION
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100803 adb shell mkdir -p $DEX_LOCATION
804 adb push $TEST_NAME.jar $DEX_LOCATION
805 adb push $TEST_NAME-ex.jar $DEX_LOCATION
Jeff Hao002b9312017-03-27 16:23:08 -0700806 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Calin Juravle13439f02017-02-21 01:17:21 -0800807 adb push profile $DEX_LOCATION
808 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100809 else
810 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
811 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
812 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
813 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
Jeff Hao002b9312017-03-27 16:23:08 -0700814 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Calin Juravle13439f02017-02-21 01:17:21 -0800815 adb push profile $DEX_LOCATION >/dev/null 2>&1
816 fi
817
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100818 fi
819
Colin Crossafd3c9e2016-09-16 13:47:21 -0700820 LD_LIBRARY_PATH=/data/$TEST_DIRECTORY/art/$ISA
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000821 if [ "$ANDROID_ROOT" != "/system" ]; then
822 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
823 # so we can only use LD_LIBRARY_PATH when testing on a local
824 # installation.
Alex Light7233c7e2016-07-28 10:07:45 -0700825 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY:$LD_LIBRARY_PATH
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000826 fi
827
Dimitry Ivanov49c2c922017-02-14 11:06:14 -0800828 # System libraries needed by libarttestd.so
829 PUBLIC_LIBS=libart.so:libartd.so:libc++.so:libbacktrace.so:libbase.so:libnativehelper.so
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700830
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100831 # Create a script with the command. The command can get longer than the longest
832 # allowed adb command and there is no way to get the exit status from a adb shell
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700833 # command. Dalvik cache is cleaned before running to make subsequent executions
834 # of the script follow the same runtime path.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100835 cmdline="cd $DEX_LOCATION && \
Andreas Gampeb31a8e72017-05-16 10:30:24 -0700836 export ASAN_OPTIONS=$RUN_TEST_ASAN_OPTIONS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100837 export ANDROID_DATA=$DEX_LOCATION && \
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700838 export ANDROID_ADDITIONAL_PUBLIC_LIBRARIES=$PUBLIC_LIBS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100839 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000840 export ANDROID_ROOT=$ANDROID_ROOT && \
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700841 rm -rf ${DEX_LOCATION}/dalvik-cache/ && \
Alex Lightafb5d192016-05-24 15:57:45 -0700842 mkdir -p ${mkdir_locations} && \
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100843 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray4f7fdd22015-04-24 11:57:37 +0100844 export PATH=$ANDROID_ROOT/bin:$PATH && \
Calin Juravle13439f02017-02-21 01:17:21 -0800845 $profman_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100846 $dex2oat_cmdline && \
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000847 $vdex_cmdline && \
Richard Uhler76f5cb62016-04-04 13:30:16 -0700848 $strip_cmdline && \
Igor Murashkin271a0f82017-02-14 21:14:17 +0000849 $sync_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100850 $dalvikvm_cmdline"
851
852 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
853 echo "$cmdline" > $cmdfile
854
855 if [ "$DEV_MODE" = "y" ]; then
856 echo $cmdline
857 fi
858
859 if [ "$QUIET" = "n" ]; then
860 adb push $cmdfile $DEX_LOCATION/cmdline.sh
861 else
862 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
863 fi
864
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700865 if [ "$DRY_RUN" != "y" ]; then
866 adb shell sh $DEX_LOCATION/cmdline.sh
867 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100868
869 rm -f $cmdfile
870else
Calin Juravle24bd3f92017-05-11 00:36:53 -0700871 # Host run.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100872 export ANDROID_PRINTF_LOG=brief
Andreas Gampea8780822015-03-13 19:51:09 -0700873
874 # By default, and for prebuild dex2oat, we are interested in errors being logged. In dev mode
875 # we want debug messages.
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700876 if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
877 if [ "$DEV_MODE" = "y" ]; then
878 export ANDROID_LOG_TAGS='*:d'
879 else
880 export ANDROID_LOG_TAGS='*:e'
881 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100882 fi
Andreas Gampea8780822015-03-13 19:51:09 -0700883
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100884 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000885 export ANDROID_ROOT="${ANDROID_ROOT}"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700886 export LD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
887 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100888 export PATH="$PATH:${ANDROID_ROOT}/bin"
889
David Srbeckyc9ede382015-06-20 06:03:53 +0100890 # Temporarily disable address space layout randomization (ASLR).
891 # This is needed on the host so that the linker loads core.oat at the necessary address.
892 export LD_USE_LOAD_BIAS=1
893
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100894 cmdline="$dalvikvm_cmdline"
895
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700896 if [ "$TIME_OUT" = "gdb" ]; then
897 if [ `uname` = "Darwin" ]; then
898 # Fall back to timeout on Mac.
899 TIME_OUT="timeout"
Hiroshi Yamauchic823eff2015-09-01 16:21:35 -0700900 elif [ "$ISA" = "x86" ]; then
901 # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
902 TIME_OUT="timeout"
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700903 else
904 # Check if gdb is available.
905 gdb --eval-command="quit" > /dev/null 2>&1
906 if [ $? != 0 ]; then
907 # gdb isn't available. Fall back to timeout.
908 TIME_OUT="timeout"
909 fi
910 fi
911 fi
912
913 if [ "$TIME_OUT" = "timeout" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100914 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -0800915 #
Andreas Gampe6fb92562016-08-01 21:53:57 -0700916 # Note: We first send SIGRTMIN+2 (usually 36) to ART, which will induce a full thread dump
917 # before abort. However, dumping threads might deadlock, so we also use the "-k"
918 # option to definitely kill the child.
919 cmdline="timeout -k 120s -s SIGRTMIN+2 ${TIME_OUT_VALUE}s $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100920 fi
921
922 if [ "$DEV_MODE" = "y" ]; then
Calin Juravle13439f02017-02-21 01:17:21 -0800923 echo "mkdir -p ${mkdir_locations} && $profman_cmdline && $dex2oat_cmdline && $vdex_cmdline && $strip_cmdline && $sync_cmdline && $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100924 fi
925
926 cd $ANDROID_BUILD_TOP
927
Calin Juravle24bd3f92017-05-11 00:36:53 -0700928 # Make sure we delete any existing compiler artifacts.
929 # This enables tests to call the RUN script multiple times in a row
930 # without worrying about interference.
931 rm -rf ${DEX_LOCATION}/oat
David Srbecky2e4afe82016-01-27 18:42:06 +0000932 rm -rf ${DEX_LOCATION}/dalvik-cache/
Calin Juravle24bd3f92017-05-11 00:36:53 -0700933
Andreas Gampeb31a8e72017-05-16 10:30:24 -0700934 export ASAN_OPTIONS=$RUN_TEST_ASAN_OPTIONS
935
Alex Lightafb5d192016-05-24 15:57:45 -0700936 mkdir -p ${mkdir_locations} || exit 1
Calin Juravle13439f02017-02-21 01:17:21 -0800937 $profman_cmdline || { echo "Profman failed." >&2 ; exit 2; }
Andreas Gampea8780822015-03-13 19:51:09 -0700938 $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000939 $vdex_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Richard Uhler76f5cb62016-04-04 13:30:16 -0700940 $strip_cmdline || { echo "Strip failed." >&2 ; exit 3; }
Igor Murashkin271a0f82017-02-14 21:14:17 +0000941 $sync_cmdline || { echo "Sync failed." >&2 ; exit 4; }
Andreas Gampea8780822015-03-13 19:51:09 -0700942
943 # For running, we must turn off logging when dex2oat or patchoat are missing. Otherwise we use
944 # the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700945 if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
946 if [ "$DEV_MODE" = "y" ]; then
947 export ANDROID_LOG_TAGS='*:d'
948 elif [ "$USE_DEX2OAT_AND_PATCHOAT" = "n" ]; then
949 # All tests would log the error of failing dex2oat/patchoat. Be silent here and only
950 # log fatal events.
951 export ANDROID_LOG_TAGS='*:s'
Andreas Gampe1078d152017-11-07 18:00:54 -0800952 elif [ "$HAVE_IMAGE" = "n" ]; then
953 # All tests would log the error of missing image. Be silent here and only log fatal
954 # events.
955 export ANDROID_LOG_TAGS='*:s'
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700956 else
957 # We are interested in LOG(ERROR) output.
958 export ANDROID_LOG_TAGS='*:e'
959 fi
960 fi
961
962 if [ "$DRY_RUN" = "y" ]; then
963 exit 0
Andreas Gampea8780822015-03-13 19:51:09 -0700964 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100965
966 if [ "$USE_GDB" = "y" ]; then
967 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700968 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100969 else
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700970 if [ "$TIME_OUT" != "gdb" ]; then
971 trap 'kill -INT -$pid' INT
972 $cmdline "$@" 2>&1 & pid=$!
973 wait $pid
974 # Add extra detail if time out is enabled.
975 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
976 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
977 fi
978 else
979 # With a thread dump that uses gdb if a timeout.
980 trap 'kill -INT -$pid' INT
981 $cmdline "$@" 2>&1 & pid=$!
982 # Spawn a watcher process.
983 ( sleep $TIME_OUT_VALUE && \
984 echo "##### Thread dump using gdb on test timeout" && \
985 ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
986 --eval-command="call exit(124)" --eval-command=quit || \
987 kill $pid )) 2> /dev/null & watcher=$!
988 wait $pid
989 test_exit_status=$?
990 pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
991 if [ $test_exit_status = 0 ]; then
992 # The test finished normally.
993 exit 0
994 else
995 # The test failed or timed out.
996 if [ $test_exit_status = 124 ]; then
997 # The test timed out.
998 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
999 fi
1000 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001001 fi
1002 fi
1003fi