blob: e989e39bf35daba8702d4ab6fb10f297abe1acc9 [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"
19DEV_MODE="n"
20DEX2OAT=""
Alex Light8a0e0332015-10-26 10:11:58 -070021EXPERIMENTAL=""
Nicolas Geoffray90355fe2017-02-20 09:25:40 +000022FALSE_BIN="false"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010023FLAGS=""
Alex Light7233c7e2016-07-28 10:07:45 -070024ANDROID_FLAGS=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010025GDB=""
Nicolas Geoffraybaf91022014-10-08 09:56:45 +010026GDB_ARGS=""
27GDB_SERVER="gdbserver"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010028HAVE_IMAGE="y"
29HOST="n"
30INTERPRETER="n"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080031JIT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010032INVOKE_WITH=""
Alex Lighte06b6342017-01-05 14:37:21 -080033IS_JVMTI_TEST="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010034ISA=x86
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000035LIBRARY_DIRECTORY="lib"
Colin Crossafd3c9e2016-09-16 13:47:21 -070036TEST_DIRECTORY="nativetest"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000037MAIN=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010038OPTIMIZE="y"
39PATCHOAT=""
40PREBUILD="y"
41QUIET="n"
Nicolas Geoffray94e25db2017-01-27 14:54:28 +000042RELOCATE="n"
Richard Uhler76f5cb62016-04-04 13:30:16 -070043STRIP_DEX="n"
Jeff Hao207a37d2014-10-29 17:24:25 -070044SECONDARY_DEX=""
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -070045TIME_OUT="gdb" # "n" (disabled), "timeout" (use timeout), "gdb" (use gdb)
46# Value in seconds
Hiroshi Yamauchifd3161a2017-01-18 14:47:25 -080047if [ "$ART_USE_READ_BARRIER" != "false" ]; then
Hiroshi Yamauchia9b296c2016-10-07 17:07:03 -070048 TIME_OUT_VALUE=2400 # 40 minutes.
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070049else
Mathieu Chartier2576be22016-05-24 10:24:53 -070050 TIME_OUT_VALUE=1200 # 20 minutes.
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070051fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010052USE_GDB="n"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +010053USE_JVM="n"
Igor Murashkin7617abd2015-07-10 18:27:47 -070054VERIFY="y" # y=yes,n=no,s=softfail
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010055ZYGOTE=""
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -070056DEX_VERIFY=""
Andreas Gampe65357032015-02-19 15:10:24 -080057USE_DEX2OAT_AND_PATCHOAT="y"
Andreas Gampe4d2ef332015-08-05 09:24:45 -070058INSTRUCTION_SET_FEATURES=""
Mathieu Chartier031768a2015-08-27 10:25:02 -070059ARGS=""
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -070060EXTERNAL_LOG_TAGS="n" # if y respect externally set ANDROID_LOG_TAGS.
61DRY_RUN="n" # if y prepare to run the test but don't run it.
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +000062TEST_VDEX="n"
Alex Lighte06b6342017-01-05 14:37:21 -080063TEST_IS_NDEBUG="n"
Calin Juravle857f0582016-12-20 14:36:59 +000064APP_IMAGE="y"
Alex Light8f2c6d42017-04-10 16:27:35 -070065JVMTI_STRESS="n"
Alex Lightc38c3692017-06-27 15:45:14 -070066JVMTI_STEP_STRESS="n"
Alex Light43e935d2017-06-19 15:40:40 -070067JVMTI_FIELD_STRESS="n"
Alex Lightb7edcda2017-04-27 13:20:31 -070068JVMTI_TRACE_STRESS="n"
69JVMTI_REDEFINE_STRESS="n"
Nicolas Geoffray74981052017-01-16 17:54:09 +000070VDEX_FILTER=""
Calin Juravle13439f02017-02-21 01:17:21 -080071PROFILE="n"
Jeff Hao002b9312017-03-27 16:23:08 -070072RANDOM_PROFILE="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010073
Narayan Kamath84695ae2017-04-07 15:41:41 +010074# if "y", set -Xstacktracedir and inform the test of its location. When
75# this is set, stack trace dumps (from signal 3) will be written to a file
76# under this directory instead of stdout.
77SET_STACK_TRACE_DUMP_DIR="n"
78
Igor Murashkin271a0f82017-02-14 21:14:17 +000079# if "y", run 'sync' before dalvikvm to make sure all files from
80# build step (e.g. dex2oat) were finished writing.
81SYNC_BEFORE_RUN="n"
82
Andreas Gampe1c5b42f2017-06-15 18:20:45 -070083# When running a debug build, we want to run with all checks.
84ANDROID_FLAGS="${ANDROID_FLAGS} -XX:SlowDebug=true"
85
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010086while true; do
87 if [ "x$1" = "x--quiet" ]; then
88 QUIET="y"
89 shift
Alex Lighte06b6342017-01-05 14:37:21 -080090 elif [ "x$1" = "x--jvmti" ]; then
91 IS_JVMTI_TEST="y"
92 shift
Alex Lightfaf90b62016-08-12 14:43:48 -070093 elif [ "x$1" = "x-O" ]; then
Alex Lighte06b6342017-01-05 14:37:21 -080094 TEST_IS_NDEBUG="y"
Alex Lightfaf90b62016-08-12 14:43:48 -070095 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010096 elif [ "x$1" = "x--lib" ]; then
97 shift
98 if [ "x$1" = "x" ]; then
99 echo "$0 missing argument to --lib" 1>&2
100 exit 1
101 fi
102 LIB="$1"
103 shift
Alex Light97acf192016-03-17 09:59:38 -0700104 elif [ "x$1" = "x--gc-stress" ]; then
105 # Give an extra 5 mins if we are gc-stress.
106 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + 300))
107 shift
Mathieu Chartier031768a2015-08-27 10:25:02 -0700108 elif [ "x$1" = "x--testlib" ]; then
109 shift
110 if [ "x$1" = "x" ]; then
111 echo "$0 missing argument to --testlib" 1>&2
112 exit 1
113 fi
Mathieu Chartierde286fd2015-09-03 18:10:29 -0700114 ARGS="${ARGS} $1"
Mathieu Chartier031768a2015-08-27 10:25:02 -0700115 shift
David Srbecky52886112016-01-22 13:56:47 +0000116 elif [ "x$1" = "x--args" ]; then
117 shift
118 if [ "x$1" = "x" ]; then
119 echo "$0 missing argument to --args" 1>&2
120 exit 1
121 fi
122 ARGS="${ARGS} $1"
123 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100124 elif [ "x$1" = "x-Xcompiler-option" ]; then
125 shift
126 option="$1"
127 FLAGS="${FLAGS} -Xcompiler-option $option"
128 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
129 shift
Alex Light7233c7e2016-07-28 10:07:45 -0700130 elif [ "x$1" = "x--android-runtime-option" ]; then
131 shift
132 option="$1"
133 ANDROID_FLAGS="${ANDROID_FLAGS} $option"
134 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100135 elif [ "x$1" = "x--runtime-option" ]; then
136 shift
137 option="$1"
138 FLAGS="${FLAGS} $option"
139 shift
140 elif [ "x$1" = "x--boot" ]; then
141 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000142 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100143 shift
144 elif [ "x$1" = "x--no-dex2oat" ]; then
145 DEX2OAT="-Xcompiler:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800146 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100147 shift
148 elif [ "x$1" = "x--no-patchoat" ]; then
149 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800150 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100151 shift
152 elif [ "x$1" = "x--relocate" ]; then
153 RELOCATE="y"
154 shift
155 elif [ "x$1" = "x--no-relocate" ]; then
156 RELOCATE="n"
157 shift
158 elif [ "x$1" = "x--prebuild" ]; then
159 PREBUILD="y"
160 shift
Alex Lightb7edcda2017-04-27 13:20:31 -0700161 elif [ "x$1" = "x--jvmti-redefine-stress" ]; then
162 # APP_IMAGE doesn't really work with jvmti redefine stress
Alex Light8f2c6d42017-04-10 16:27:35 -0700163 APP_IMAGE="n"
164 JVMTI_STRESS="y"
Alex Lightb7edcda2017-04-27 13:20:31 -0700165 JVMTI_REDEFINE_STRESS="y"
166 shift
Alex Lightc38c3692017-06-27 15:45:14 -0700167 elif [ "x$1" = "x--jvmti-step-stress" ]; then
168 JVMTI_STRESS="y"
169 JVMTI_STEP_STRESS="y"
170 shift
Alex Light43e935d2017-06-19 15:40:40 -0700171 elif [ "x$1" = "x--jvmti-field-stress" ]; then
172 JVMTI_STRESS="y"
173 JVMTI_FIELD_STRESS="y"
174 shift
Alex Lightb7edcda2017-04-27 13:20:31 -0700175 elif [ "x$1" = "x--jvmti-trace-stress" ]; then
176 JVMTI_STRESS="y"
177 JVMTI_TRACE_STRESS="y"
Alex Light8f2c6d42017-04-10 16:27:35 -0700178 shift
Calin Juravle857f0582016-12-20 14:36:59 +0000179 elif [ "x$1" = "x--no-app-image" ]; then
180 APP_IMAGE="n"
181 shift
Richard Uhler76f5cb62016-04-04 13:30:16 -0700182 elif [ "x$1" = "x--strip-dex" ]; then
183 STRIP_DEX="y"
184 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100185 elif [ "x$1" = "x--host" ]; then
186 HOST="y"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000187 ANDROID_ROOT="$ANDROID_HOST_OUT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100188 shift
189 elif [ "x$1" = "x--no-prebuild" ]; then
190 PREBUILD="n"
191 shift
192 elif [ "x$1" = "x--no-image" ]; then
193 HAVE_IMAGE="n"
194 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700195 elif [ "x$1" = "x--secondary" ]; then
196 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
Calin Juravle175dc732015-08-25 15:42:32 +0100197 # Enable cfg-append to make sure we get the dump for both dex files.
198 # (otherwise the runtime compilation of the secondary dex will overwrite
Roland Levillainb0103ca2016-11-01 14:48:47 +0000199 # the dump of the first one).
Calin Juravle175dc732015-08-25 15:42:32 +0100200 FLAGS="${FLAGS} -Xcompiler-option --dump-cfg-append"
201 COMPILE_FLAGS="${COMPILE_FLAGS} --dump-cfg-append"
Jeff Hao207a37d2014-10-29 17:24:25 -0700202 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100203 elif [ "x$1" = "x--debug" ]; then
204 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800205 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100206 shift
207 elif [ "x$1" = "x--gdb" ]; then
208 USE_GDB="y"
209 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800210 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100211 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700212 elif [ "x$1" = "x--gdb-arg" ]; then
213 shift
214 gdb_arg="$1"
215 GDB_ARGS="${GDB_ARGS} $gdb_arg"
216 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100217 elif [ "x$1" = "x--zygote" ]; then
218 ZYGOTE="-Xzygote"
219 msg "Spawning from zygote"
220 shift
221 elif [ "x$1" = "x--dev" ]; then
222 DEV_MODE="y"
223 shift
224 elif [ "x$1" = "x--interpreter" ]; then
225 INTERPRETER="y"
226 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800227 elif [ "x$1" = "x--jit" ]; then
228 JIT="y"
229 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100230 elif [ "x$1" = "x--jvm" ]; then
231 USE_JVM="y"
232 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100233 elif [ "x$1" = "x--invoke-with" ]; then
234 shift
235 if [ "x$1" = "x" ]; then
236 echo "$0 missing argument to --invoke-with" 1>&2
237 exit 1
238 fi
239 if [ "x$INVOKE_WITH" = "x" ]; then
240 INVOKE_WITH="$1"
241 else
242 INVOKE_WITH="$INVOKE_WITH $1"
243 fi
244 shift
245 elif [ "x$1" = "x--no-verify" ]; then
246 VERIFY="n"
247 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700248 elif [ "x$1" = "x--verify-soft-fail" ]; then
249 VERIFY="s"
250 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100251 elif [ "x$1" = "x--no-optimize" ]; then
252 OPTIMIZE="n"
253 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000254 elif [ "x$1" = "x--android-root" ]; then
255 shift
256 ANDROID_ROOT="$1"
257 shift
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700258 elif [ "x$1" = "x--instruction-set-features" ]; then
259 shift
260 INSTRUCTION_SET_FEATURES="$1"
261 shift
Mathieu Chartier2576be22016-05-24 10:24:53 -0700262 elif [ "x$1" = "x--timeout" ]; then
263 shift
264 TIME_OUT_VALUE="$1"
265 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100266 elif [ "x$1" = "x--" ]; then
267 shift
268 break
269 elif [ "x$1" = "x--64" ]; then
270 ISA="x86_64"
271 GDB_SERVER="gdbserver64"
272 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000273 LIBRARY_DIRECTORY="lib64"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700274 TEST_DIRECTORY="nativetest64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100275 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
276 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700277 elif [ "x$1" = "x--pic-test" ]; then
278 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
279 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
280 shift
Alex Light8a0e0332015-10-26 10:11:58 -0700281 elif [ "x$1" = "x--experimental" ]; then
282 if [ "$#" -lt 2 ]; then
283 echo "missing --experimental option" 1>&2
284 exit 1
285 fi
286 EXPERIMENTAL="$EXPERIMENTAL $2"
287 shift 2
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700288 elif [ "x$1" = "x--external-log-tags" ]; then
289 EXTERNAL_LOG_TAGS="y"
290 shift
291 elif [ "x$1" = "x--dry-run" ]; then
292 DRY_RUN="y"
293 shift
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000294 elif [ "x$1" = "x--vdex" ]; then
295 TEST_VDEX="y"
296 shift
Nicolas Geoffray74981052017-01-16 17:54:09 +0000297 elif [ "x$1" = "x--vdex-filter" ]; then
298 shift
299 option="$1"
300 VDEX_FILTER="--compiler-filter=$option"
301 shift
Igor Murashkin271a0f82017-02-14 21:14:17 +0000302 elif [ "x$1" = "x--sync" ]; then
303 SYNC_BEFORE_RUN="y"
304 shift
Calin Juravle13439f02017-02-21 01:17:21 -0800305 elif [ "x$1" = "x--profile" ]; then
306 PROFILE="y"
307 shift
Jeff Hao002b9312017-03-27 16:23:08 -0700308 elif [ "x$1" = "x--random-profile" ]; then
309 RANDOM_PROFILE="y"
310 shift
Narayan Kamath84695ae2017-04-07 15:41:41 +0100311 elif [ "x$1" = "x--set-stack-trace-dump-dir" ]; then
312 SET_STACK_TRACE_DUMP_DIR="y"
313 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100314 elif expr "x$1" : "x--" >/dev/null 2>&1; then
315 echo "unknown $0 option: $1" 1>&2
316 exit 1
317 else
318 break
319 fi
320done
321
Narayan Kamath84695ae2017-04-07 15:41:41 +0100322mkdir_locations=""
323
Alex Light8a0e0332015-10-26 10:11:58 -0700324if [ "$USE_JVM" = "n" ]; then
Alex Light7233c7e2016-07-28 10:07:45 -0700325 FLAGS="${FLAGS} ${ANDROID_FLAGS}"
Alex Light8a0e0332015-10-26 10:11:58 -0700326 for feature in ${EXPERIMENTAL}; do
Alex Lightfa022852015-10-28 09:13:20 -0700327 FLAGS="${FLAGS} -Xexperimental:${feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:${feature}"
Alex Light8a0e0332015-10-26 10:11:58 -0700328 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xexperimental:${feature}"
329 done
Narayan Kamath84695ae2017-04-07 15:41:41 +0100330
331 if [ "$SET_STACK_TRACE_DUMP_DIR" = "y" ]; then
332 # Note that DEX_LOCATION is used as a proxy for tmpdir throughout this
333 # file (it will be under the test specific folder).
334 mkdir_locations="${mkdir_locations} $DEX_LOCATION/stack_traces"
335 FLAGS="${FLAGS} -Xstacktracedir:$DEX_LOCATION/stack_traces"
336 ARGS="${ARGS} --stack-trace-dir $DEX_LOCATION/stack_traces"
337 fi
Alex Light8a0e0332015-10-26 10:11:58 -0700338fi
339
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100340if [ "x$1" = "x" ] ; then
341 MAIN="Main"
342else
343 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700344 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100345fi
346
347if [ "$ZYGOTE" = "" ]; then
348 if [ "$OPTIMIZE" = "y" ]; then
349 if [ "$VERIFY" = "y" ]; then
350 DEX_OPTIMIZE="-Xdexopt:verified"
351 else
352 DEX_OPTIMIZE="-Xdexopt:all"
353 fi
354 msg "Performing optimizations"
355 else
356 DEX_OPTIMIZE="-Xdexopt:none"
357 msg "Skipping optimizations"
358 fi
359
360 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100361 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100362 msg "Performing verification"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700363 elif [ "$VERIFY" = "s" ]; then
364 JVM_VERIFY_ARG="Xverify:all"
365 DEX_VERIFY="-Xverify:softfail"
366 msg "Forcing verification to be soft fail"
367 else # VERIFY = "n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100368 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100369 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100370 msg "Skipping verification"
371 fi
372fi
373
374msg "------------------------------"
375
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100376if [ "$DEBUGGER" = "y" ]; then
377 # Use this instead for ddms and connect by running 'ddms':
378 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
379 # TODO: add a separate --ddms option?
380
381 PORT=12345
382 msg "Waiting for jdb to connect:"
383 if [ "$HOST" = "n" ]; then
384 msg " adb forward tcp:$PORT tcp:$PORT"
385 fi
386 msg " jdb -attach localhost:$PORT"
387 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
388fi
389
Alex Lightfba89fe2017-01-12 16:11:02 -0800390if [ "$IS_JVMTI_TEST" = "y" ]; then
391 plugin=libopenjdkjvmtid.so
392 agent=libtiagentd.so
393 lib=tiagentd
394 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
395 agent=libtiagent.so
396 plugin=libopenjdkjvmti.so
397 lib=tiagent
398 fi
399
400 ARGS="${ARGS} ${lib}"
401 if [[ "$USE_JVM" = "y" ]]; then
402 FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${TEST_NAME},jvm"
403 else
404 FLAGS="${FLAGS} -agentpath:${agent}=${TEST_NAME},art"
405 FLAGS="${FLAGS} -Xplugin:${plugin}"
Nicolas Geoffraya0619e22016-12-20 13:57:43 +0000406 FLAGS="${FLAGS} -Xcompiler-option --debuggable"
Alex Lightfba89fe2017-01-12 16:11:02 -0800407 # Always make the compilation be debuggable.
408 COMPILE_FLAGS="${COMPILE_FLAGS} --debuggable"
409 fi
410fi
411
Alex Light8f2c6d42017-04-10 16:27:35 -0700412if [[ "$JVMTI_STRESS" = "y" ]]; then
Alex Light42151c02017-04-20 15:54:25 -0700413 plugin=libopenjdkjvmtid.so
414 agent=libtistressd.so
415 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
416 agent=libtistress.so
417 plugin=libopenjdkjvmti.so
418 fi
Alex Light8f2c6d42017-04-10 16:27:35 -0700419
Alex Lightb7edcda2017-04-27 13:20:31 -0700420 # Just give it a default start so we can always add ',' to it.
421 agent_args="jvmti-stress"
422 if [[ "$JVMTI_REDEFINE_STRESS" = "y" ]]; then
423 # We really cannot do this on RI so don't both passing it in that case.
424 if [[ "$USE_JVM" = "n" ]]; then
425 file_1=$(mktemp --tmpdir=${DEX_LOCATION})
426 file_2=$(mktemp --tmpdir=${DEX_LOCATION})
427 # TODO Remove need for DEXTER_BINARY!
428 agent_args="${agent_args},redefine,${DEXTER_BINARY},${file_1},${file_2}"
429 fi
430 fi
Alex Light43e935d2017-06-19 15:40:40 -0700431 if [[ "$JVMTI_FIELD_STRESS" = "y" ]]; then
432 agent_args="${agent_args},field"
433 fi
Alex Lightc38c3692017-06-27 15:45:14 -0700434 if [[ "$JVMTI_STEP_STRESS" = "y" ]]; then
435 agent_args="${agent_args},step"
436 fi
Alex Lightb7edcda2017-04-27 13:20:31 -0700437 if [[ "$JVMTI_TRACE_STRESS" = "y" ]]; then
438 agent_args="${agent_args},trace"
439 fi
440 # In the future add onto this;
Alex Light42151c02017-04-20 15:54:25 -0700441 if [[ "$USE_JVM" = "y" ]]; then
Alex Lightb7edcda2017-04-27 13:20:31 -0700442 FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${agent_args}"
Alex Light42151c02017-04-20 15:54:25 -0700443 else
Alex Lightb7edcda2017-04-27 13:20:31 -0700444 FLAGS="${FLAGS} -agentpath:${agent}=${agent_args}"
Alex Light8f2c6d42017-04-10 16:27:35 -0700445 if [ "$IS_JVMTI_TEST" = "n" ]; then
446 FLAGS="${FLAGS} -Xplugin:${plugin}"
447 FLAGS="${FLAGS} -Xcompiler-option --debuggable"
448 # Always make the compilation be debuggable.
449 COMPILE_FLAGS="${COMPILE_FLAGS} --debuggable"
450 fi
451 fi
452fi
453
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100454if [ "$USE_JVM" = "y" ]; then
Alex Light9c20a142016-08-23 15:05:12 -0700455 export LD_LIBRARY_PATH=${ANDROID_HOST_OUT}/lib64
Alex Light47d49b82017-07-25 14:06:34 -0700456 # Some jvmti tests are flaky without -Xint on the RI.
457 if [ "$IS_JVMTI_TEST" = "y" ]; then
458 FLAGS="${FLAGS} -Xint"
459 fi
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700460 # Xmx is necessary since we don't pass down the ART flags to JVM.
Vladimir Markoc5798bf2016-12-09 10:20:54 +0000461 # We pass the classes2 path whether it's used (src-multidex) or not.
462 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes:classes2 ${FLAGS} $MAIN $@ ${ARGS}"
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700463 if [ "$DEV_MODE" = "y" ]; then
464 echo $cmdline
465 fi
466 $cmdline
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100467 exit
468fi
469
470
471if [ "$HAVE_IMAGE" = "n" ]; then
Vladimir Markoe00e5592017-02-24 14:58:29 +0000472 if [ "${HOST}" = "y" ]; then
473 framework="${ANDROID_HOST_OUT}/framework"
474 bpath_suffix="-hostdex"
475 else
476 framework="${ANDROID_ROOT}/framework"
Nicolas Geoffray320ccca2017-03-01 10:03:08 +0000477 bpath_suffix="-testdex"
Vladimir Markoe00e5592017-02-24 14:58:29 +0000478 fi
Vladimir Markoe00e5592017-02-24 14:58:29 +0000479 bpath="${framework}/core-libart${bpath_suffix}.jar"
480 bpath="${bpath}:${framework}/core-oj${bpath_suffix}.jar"
481 bpath="${bpath}:${framework}/conscrypt${bpath_suffix}.jar"
482 bpath="${bpath}:${framework}/okhttp${bpath_suffix}.jar"
483 bpath="${bpath}:${framework}/bouncycastle${bpath_suffix}.jar"
484 # Pass down the bootclasspath
485 FLAGS="${FLAGS} -Xbootclasspath:${bpath}"
Nicolas Geoffray47e61d52017-01-31 09:13:52 +0000486 # Add 5 minutes to give some time to generate the boot image.
487 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + 300))
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000488 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000489else
490 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100491fi
492
493
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100494if [ "$USE_GDB" = "y" ]; then
495 if [ "$HOST" = "n" ]; then
496 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100497 else
498 if [ `uname` = "Darwin" ]; then
499 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700500 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100501 DALVIKVM=
502 else
503 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700504 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100505 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
506 # gdbargs="--annotate=3 $gdbargs"
507 fi
508 fi
509fi
510
511if [ "$INTERPRETER" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000512 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700513 if [ "$VERIFY" = "y" ] ; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100514 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=quicken"
515 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=quicken"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700516 elif [ "$VERIFY" = "s" ]; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100517 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=extract"
518 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=extract"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700519 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
520 else # VERIFY = "n"
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100521 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=assume-verified"
522 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=assume-verified"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700523 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
524 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100525fi
526
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800527if [ "$JIT" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000528 INT_OPTS="-Xusejit:true"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800529 if [ "$VERIFY" = "y" ] ; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100530 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=quicken"
531 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=quicken"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800532 else
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100533 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=assume-verified"
534 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=assume-verified"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800535 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
536 fi
537fi
538
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100539JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
540
Richard Uhler020c0f32017-03-14 16:23:17 +0000541COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100542if [ "$RELOCATE" = "y" ]; then
Richard Uhlerc52f3032017-03-02 13:45:45 +0000543 FLAGS="${FLAGS} -Xrelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100544else
545 FLAGS="$FLAGS -Xnorelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100546fi
547
548if [ "$HOST" = "n" ]; then
Nicolas Geoffrayd295bc82016-11-04 13:03:05 +0000549 # Need to be root to query /data/dalvik-cache
550 adb root > /dev/null
551 adb wait-for-device
552 ISA=
553 ISA_adb_invocation=
554 ISA_outcome=
555 # We iterate a few times to workaround an adb issue. b/32655576
556 for i in {1..10}; do
557 ISA_adb_invocation=$(adb shell ls -F /data/dalvik-cache)
558 ISA_outcome=$?
559 ISA=$(echo $ISA_adb_invocation | grep -Ewo "${ARCHITECTURES_PATTERN}")
560 if [ x"$ISA" != "x" ]; then
561 break;
562 fi
563 done
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100564 if [ x"$ISA" = "x" ]; then
565 echo "Unable to determine architecture"
Nicolas Geoffray8f500fa2016-11-03 11:18:48 +0000566 # Print a few things for helping diagnosing the problem.
Nicolas Geoffrayd295bc82016-11-04 13:03:05 +0000567 echo "adb invocation output: $ISA_adb_invocation"
568 echo "adb invocation outcome: $ISA_outcome"
Nicolas Geoffray8f500fa2016-11-03 11:18:48 +0000569 echo $(adb shell ls -F /data/dalvik-cache)
570 echo $(adb shell ls /data/dalvik-cache)
571 echo ${ARCHITECTURES_PATTERN}
572 echo $(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100573 exit 1
574 fi
575fi
576
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700577# Prevent test from silently falling back to interpreter in no-prebuild mode. This happens
578# when DEX_LOCATION path is too long, because vdex/odex filename is constructed by taking
579# full path to dex, stripping leading '/', appending '@classes.vdex' and changing every
580# remaining '/' into '@'.
581if [ "$HOST" = "y" ]; then
582 max_filename_size=$(getconf NAME_MAX $DEX_LOCATION)
583else
584 # There is no getconf on device, fallback to standard value. See NAME_MAX in kernel <linux/limits.h>
585 max_filename_size=255
586fi
587# Compute VDEX_NAME.
588DEX_LOCATION_STRIPPED="${DEX_LOCATION#/}"
589VDEX_NAME="${DEX_LOCATION_STRIPPED//\//@}@$TEST_NAME.jar@classes.vdex"
590if [ ${#VDEX_NAME} -gt $max_filename_size ]; then
Nicolas Geoffraybea3e312017-03-07 09:59:05 +0000591 echo "Dex location path too long:"
592 echo "$VDEX_NAME is ${#VDEX_NAME} character long, and the limit is $max_filename_size."
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700593 exit 1
594fi
595
Calin Juravle13439f02017-02-21 01:17:21 -0800596profman_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100597dex2oat_cmdline="true"
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000598vdex_cmdline="true"
Narayan Kamath84695ae2017-04-07 15:41:41 +0100599mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/dalvik-cache/$ISA"
Richard Uhler76f5cb62016-04-04 13:30:16 -0700600strip_cmdline="true"
Igor Murashkin271a0f82017-02-14 21:14:17 +0000601sync_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100602
Jeff Hao002b9312017-03-27 16:23:08 -0700603# PROFILE takes precedence over RANDOM_PROFILE, since PROFILE tests require a
604# specific profile to run properly.
605if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000606 profman_cmdline="${ANDROID_ROOT}/bin/profman \
607 --apk=$DEX_LOCATION/$TEST_NAME.jar \
Jeff Hao002b9312017-03-27 16:23:08 -0700608 --dex-location=$DEX_LOCATION/$TEST_NAME.jar"
Calin Juravle07f01df2017-04-28 19:58:01 -0700609 if [ -f $DEX_LOCATION/$TEST_NAME-ex.jar ]; then
610 profman_cmdline="${profman_cmdline} \
611 --apk=$DEX_LOCATION/$TEST_NAME-ex.jar \
612 --dex-location=$DEX_LOCATION/$TEST_NAME-ex.jar"
613 fi
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000614 COMPILE_FLAGS="${COMPILE_FLAGS} --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
615 FLAGS="${FLAGS} -Xcompiler-option --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
Jeff Hao002b9312017-03-27 16:23:08 -0700616 if [ "$PROFILE" = "y" ]; then
617 profman_cmdline="${profman_cmdline} --create-profile-from=$DEX_LOCATION/profile \
618 --reference-profile-file=$DEX_LOCATION/$TEST_NAME.prof"
619 else
620 profman_cmdline="${profman_cmdline} --generate-test-profile=$DEX_LOCATION/$TEST_NAME.prof \
621 --generate-test-profile-seed=0"
622 fi
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000623fi
624
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100625if [ "$PREBUILD" = "y" ]; then
Alex Lightafb5d192016-05-24 15:57:45 -0700626 mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/oat/$ISA"
Calin Juravle857f0582016-12-20 14:36:59 +0000627 if [ "$APP_IMAGE" = "y" ]; then
628 # Pick a base that will force the app image to get relocated.
629 app_image="--base=0x4000 --app-image-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.art"
630 fi
631
Roland Levillain6c3af162017-04-27 11:18:56 +0100632 dex2oat_binary=dex2oatd
633 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
634 dex2oat_binary=dex2oat
635 fi
636 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/$dex2oat_binary \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100637 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000638 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100639 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
Andreas Gampe14759242016-03-23 10:54:21 -0700640 --oat-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.odex \
Jeff Haodcdc85b2015-12-04 14:06:18 -0800641 ${app_image} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100642 --instruction-set=$ISA"
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700643 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
644 dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
645 fi
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700646
647 # Add in a timeout. This is important for testing the compilation/verification time of
648 # pathological cases.
649 # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
650 # now. We should try to improve this.
651 # The current value is rather arbitrary. run-tests should compile quickly.
652 if [ "$HOST" != "n" ]; then
653 # Use SIGRTMIN+2 to try to dump threads.
654 # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
Andreas Gampe43ee0542017-06-05 18:04:52 -0700655 dex2oat_cmdline="timeout -k 1m -s SIGRTMIN+2 90s ${dex2oat_cmdline} --watchdog-timeout=60000"
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700656 fi
Nicolas Geoffrayfbc4f112017-04-27 21:45:35 +0100657 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
658 vdex_cmdline="${dex2oat_cmdline} ${VDEX_FILTER} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex --output-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
659 elif [ "$TEST_VDEX" = "y" ]; then
Nicolas Geoffray74981052017-01-16 17:54:09 +0000660 vdex_cmdline="${dex2oat_cmdline} ${VDEX_FILTER} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000661 fi
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700662fi
663
Richard Uhler76f5cb62016-04-04 13:30:16 -0700664if [ "$STRIP_DEX" = "y" ]; then
665 strip_cmdline="zip --quiet --delete $DEX_LOCATION/$TEST_NAME.jar classes.dex"
666fi
667
Igor Murashkin271a0f82017-02-14 21:14:17 +0000668if [ "$SYNC_BEFORE_RUN" = "y" ]; then
669 sync_cmdline="sync"
670fi
671
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700672DALVIKVM_ISA_FEATURES_ARGS=""
673if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
674 DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100675fi
676
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000677# java.io.tmpdir can only be set at launch time.
678TMP_DIR_OPTION=""
679if [ "$HOST" = "n" ]; then
680 TMP_DIR_OPTION="-Djava.io.tmpdir=/data/local/tmp"
681fi
682
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000683# We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
684# b/27185632
685# b/24664297
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000686dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100687 $GDB_ARGS \
688 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700689 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100690 -XXlib:$LIB \
691 $PATCHOAT \
692 $DEX2OAT \
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700693 $DALVIKVM_ISA_FEATURES_ARGS \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100694 $ZYGOTE \
695 $JNI_OPTS \
696 $INT_OPTS \
697 $DEBUGGER_OPTS \
698 $DALVIKVM_BOOT_OPT \
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000699 $TMP_DIR_OPTION \
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000700 -XX:DumpNativeStackOnSigQuit:false \
Mathieu Chartier031768a2015-08-27 10:25:02 -0700701 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100702
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -0800703# Remove whitespace.
704dex2oat_cmdline=$(echo $dex2oat_cmdline)
705dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000706vdex_cmdline=$(echo $vdex_cmdline)
Calin Juravle13439f02017-02-21 01:17:21 -0800707profman_cmdline=$(echo $profman_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100708
Andreas Gampeb31a8e72017-05-16 10:30:24 -0700709# Use an empty ASAN_OPTIONS to enable defaults.
710# Note: this is required as envsetup right now exports detect_leaks=0.
711RUN_TEST_ASAN_OPTIONS=""
712
Andreas Gampe58408392017-05-16 10:45:46 -0700713# Multiple shutdown leaks. b/38341789
714if [ "x$RUN_TEST_ASAN_OPTIONS" != "x" ] ; then
715 RUN_TEST_ASAN_OPTIONS="${RUN_TEST_ASAN_OPTIONS}:"
716fi
717RUN_TEST_ASAN_OPTIONS="${RUN_TEST_ASAN_OPTIONS}detect_leaks=0"
718
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100719if [ "$HOST" = "n" ]; then
720 adb root > /dev/null
721 adb wait-for-device
722 if [ "$QUIET" = "n" ]; then
Calin Juravle24bd3f92017-05-11 00:36:53 -0700723 adb shell rm -rf $DEX_LOCATION
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100724 adb shell mkdir -p $DEX_LOCATION
725 adb push $TEST_NAME.jar $DEX_LOCATION
726 adb push $TEST_NAME-ex.jar $DEX_LOCATION
Jeff Hao002b9312017-03-27 16:23:08 -0700727 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Calin Juravle13439f02017-02-21 01:17:21 -0800728 adb push profile $DEX_LOCATION
729 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100730 else
731 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
732 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
733 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
734 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
Jeff Hao002b9312017-03-27 16:23:08 -0700735 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Calin Juravle13439f02017-02-21 01:17:21 -0800736 adb push profile $DEX_LOCATION >/dev/null 2>&1
737 fi
738
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100739 fi
740
Colin Crossafd3c9e2016-09-16 13:47:21 -0700741 LD_LIBRARY_PATH=/data/$TEST_DIRECTORY/art/$ISA
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000742 if [ "$ANDROID_ROOT" != "/system" ]; then
743 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
744 # so we can only use LD_LIBRARY_PATH when testing on a local
745 # installation.
Alex Light7233c7e2016-07-28 10:07:45 -0700746 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY:$LD_LIBRARY_PATH
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000747 fi
748
Dimitry Ivanov49c2c922017-02-14 11:06:14 -0800749 # System libraries needed by libarttestd.so
750 PUBLIC_LIBS=libart.so:libartd.so:libc++.so:libbacktrace.so:libbase.so:libnativehelper.so
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700751
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100752 # Create a script with the command. The command can get longer than the longest
753 # allowed adb command and there is no way to get the exit status from a adb shell
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700754 # command. Dalvik cache is cleaned before running to make subsequent executions
755 # of the script follow the same runtime path.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100756 cmdline="cd $DEX_LOCATION && \
Andreas Gampeb31a8e72017-05-16 10:30:24 -0700757 export ASAN_OPTIONS=$RUN_TEST_ASAN_OPTIONS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100758 export ANDROID_DATA=$DEX_LOCATION && \
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700759 export ANDROID_ADDITIONAL_PUBLIC_LIBRARIES=$PUBLIC_LIBS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100760 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000761 export ANDROID_ROOT=$ANDROID_ROOT && \
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700762 rm -rf ${DEX_LOCATION}/dalvik-cache/ && \
Alex Lightafb5d192016-05-24 15:57:45 -0700763 mkdir -p ${mkdir_locations} && \
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100764 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray4f7fdd22015-04-24 11:57:37 +0100765 export PATH=$ANDROID_ROOT/bin:$PATH && \
Calin Juravle13439f02017-02-21 01:17:21 -0800766 $profman_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100767 $dex2oat_cmdline && \
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000768 $vdex_cmdline && \
Richard Uhler76f5cb62016-04-04 13:30:16 -0700769 $strip_cmdline && \
Igor Murashkin271a0f82017-02-14 21:14:17 +0000770 $sync_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100771 $dalvikvm_cmdline"
772
773 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
774 echo "$cmdline" > $cmdfile
775
776 if [ "$DEV_MODE" = "y" ]; then
777 echo $cmdline
778 fi
779
780 if [ "$QUIET" = "n" ]; then
781 adb push $cmdfile $DEX_LOCATION/cmdline.sh
782 else
783 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
784 fi
785
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700786 if [ "$DRY_RUN" != "y" ]; then
787 adb shell sh $DEX_LOCATION/cmdline.sh
788 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100789
790 rm -f $cmdfile
791else
Calin Juravle24bd3f92017-05-11 00:36:53 -0700792 # Host run.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100793 export ANDROID_PRINTF_LOG=brief
Andreas Gampea8780822015-03-13 19:51:09 -0700794
795 # By default, and for prebuild dex2oat, we are interested in errors being logged. In dev mode
796 # we want debug messages.
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700797 if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
798 if [ "$DEV_MODE" = "y" ]; then
799 export ANDROID_LOG_TAGS='*:d'
800 else
801 export ANDROID_LOG_TAGS='*:e'
802 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100803 fi
Andreas Gampea8780822015-03-13 19:51:09 -0700804
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100805 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000806 export ANDROID_ROOT="${ANDROID_ROOT}"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700807 export LD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
808 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100809 export PATH="$PATH:${ANDROID_ROOT}/bin"
810
David Srbeckyc9ede382015-06-20 06:03:53 +0100811 # Temporarily disable address space layout randomization (ASLR).
812 # This is needed on the host so that the linker loads core.oat at the necessary address.
813 export LD_USE_LOAD_BIAS=1
814
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100815 cmdline="$dalvikvm_cmdline"
816
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700817 if [ "$TIME_OUT" = "gdb" ]; then
818 if [ `uname` = "Darwin" ]; then
819 # Fall back to timeout on Mac.
820 TIME_OUT="timeout"
Hiroshi Yamauchic823eff2015-09-01 16:21:35 -0700821 elif [ "$ISA" = "x86" ]; then
822 # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
823 TIME_OUT="timeout"
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700824 else
825 # Check if gdb is available.
826 gdb --eval-command="quit" > /dev/null 2>&1
827 if [ $? != 0 ]; then
828 # gdb isn't available. Fall back to timeout.
829 TIME_OUT="timeout"
830 fi
831 fi
832 fi
833
834 if [ "$TIME_OUT" = "timeout" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100835 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -0800836 #
Andreas Gampe6fb92562016-08-01 21:53:57 -0700837 # Note: We first send SIGRTMIN+2 (usually 36) to ART, which will induce a full thread dump
838 # before abort. However, dumping threads might deadlock, so we also use the "-k"
839 # option to definitely kill the child.
840 cmdline="timeout -k 120s -s SIGRTMIN+2 ${TIME_OUT_VALUE}s $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100841 fi
842
843 if [ "$DEV_MODE" = "y" ]; then
Calin Juravle13439f02017-02-21 01:17:21 -0800844 echo "mkdir -p ${mkdir_locations} && $profman_cmdline && $dex2oat_cmdline && $vdex_cmdline && $strip_cmdline && $sync_cmdline && $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100845 fi
846
847 cd $ANDROID_BUILD_TOP
848
Calin Juravle24bd3f92017-05-11 00:36:53 -0700849 # Make sure we delete any existing compiler artifacts.
850 # This enables tests to call the RUN script multiple times in a row
851 # without worrying about interference.
852 rm -rf ${DEX_LOCATION}/oat
David Srbecky2e4afe82016-01-27 18:42:06 +0000853 rm -rf ${DEX_LOCATION}/dalvik-cache/
Calin Juravle24bd3f92017-05-11 00:36:53 -0700854
Andreas Gampeb31a8e72017-05-16 10:30:24 -0700855 export ASAN_OPTIONS=$RUN_TEST_ASAN_OPTIONS
856
Alex Lightafb5d192016-05-24 15:57:45 -0700857 mkdir -p ${mkdir_locations} || exit 1
Calin Juravle13439f02017-02-21 01:17:21 -0800858 $profman_cmdline || { echo "Profman failed." >&2 ; exit 2; }
Andreas Gampea8780822015-03-13 19:51:09 -0700859 $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000860 $vdex_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Richard Uhler76f5cb62016-04-04 13:30:16 -0700861 $strip_cmdline || { echo "Strip failed." >&2 ; exit 3; }
Igor Murashkin271a0f82017-02-14 21:14:17 +0000862 $sync_cmdline || { echo "Sync failed." >&2 ; exit 4; }
Andreas Gampea8780822015-03-13 19:51:09 -0700863
864 # For running, we must turn off logging when dex2oat or patchoat are missing. Otherwise we use
865 # the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700866 if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
867 if [ "$DEV_MODE" = "y" ]; then
868 export ANDROID_LOG_TAGS='*:d'
869 elif [ "$USE_DEX2OAT_AND_PATCHOAT" = "n" ]; then
870 # All tests would log the error of failing dex2oat/patchoat. Be silent here and only
871 # log fatal events.
872 export ANDROID_LOG_TAGS='*:s'
873 else
874 # We are interested in LOG(ERROR) output.
875 export ANDROID_LOG_TAGS='*:e'
876 fi
877 fi
878
879 if [ "$DRY_RUN" = "y" ]; then
880 exit 0
Andreas Gampea8780822015-03-13 19:51:09 -0700881 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100882
883 if [ "$USE_GDB" = "y" ]; then
884 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700885 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100886 else
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700887 if [ "$TIME_OUT" != "gdb" ]; then
888 trap 'kill -INT -$pid' INT
889 $cmdline "$@" 2>&1 & pid=$!
890 wait $pid
891 # Add extra detail if time out is enabled.
892 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
893 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
894 fi
895 else
896 # With a thread dump that uses gdb if a timeout.
897 trap 'kill -INT -$pid' INT
898 $cmdline "$@" 2>&1 & pid=$!
899 # Spawn a watcher process.
900 ( sleep $TIME_OUT_VALUE && \
901 echo "##### Thread dump using gdb on test timeout" && \
902 ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
903 --eval-command="call exit(124)" --eval-command=quit || \
904 kill $pid )) 2> /dev/null & watcher=$!
905 wait $pid
906 test_exit_status=$?
907 pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
908 if [ $test_exit_status = 0 ]; then
909 # The test finished normally.
910 exit 0
911 else
912 # The test failed or timed out.
913 if [ $test_exit_status = 124 ]; then
914 # The test timed out.
915 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
916 fi
917 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100918 fi
919 fi
920fi