3 # Runner for an individual run-test.
6 if [ "$QUIET" = "n" ]; then
11 ANDROID_ROOT="/system"
12 ARCHITECTURES_32="(arm|x86|mips|none)"
13 ARCHITECTURES_64="(arm64|x86_64|mips64|none)"
14 ARCHITECTURES_PATTERN="${ARCHITECTURES_32}"
22 FALSE_BIN="/system/bin/false"
26 GDB_SERVER="gdbserver"
33 LIBRARY_DIRECTORY="lib"
42 TIME_OUT="gdb" # "n" (disabled), "timeout" (use timeout), "gdb" (use gdb)
44 if [ "$ART_USE_READ_BARRIER" = "true" ]; then
45 TIME_OUT_VALUE=900 # 15 minutes.
47 TIME_OUT_VALUE=600 # 10 minutes.
51 VERIFY="y" # y=yes,n=no,s=softfail
54 USE_DEX2OAT_AND_PATCHOAT="y"
55 INSTRUCTION_SET_FEATURES=""
59 if [ "x$1" = "x--quiet" ]; then
62 elif [ "x$1" = "x--lib" ]; then
64 if [ "x$1" = "x" ]; then
65 echo "$0 missing argument to --lib" 1>&2
70 elif [ "x$1" = "x--gc-stress" ]; then
71 # Give an extra 5 mins if we are gc-stress.
72 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + 300))
74 elif [ "x$1" = "x--testlib" ]; then
76 if [ "x$1" = "x" ]; then
77 echo "$0 missing argument to --testlib" 1>&2
82 elif [ "x$1" = "x--args" ]; then
84 if [ "x$1" = "x" ]; then
85 echo "$0 missing argument to --args" 1>&2
90 elif [ "x$1" = "x-Xcompiler-option" ]; then
93 FLAGS="${FLAGS} -Xcompiler-option $option"
94 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
96 elif [ "x$1" = "x--runtime-option" ]; then
99 FLAGS="${FLAGS} $option"
101 elif [ "x$1" = "x--boot" ]; then
105 elif [ "x$1" = "x--no-dex2oat" ]; then
106 DEX2OAT="-Xcompiler:${FALSE_BIN}"
107 USE_DEX2OAT_AND_PATCHOAT="n"
109 elif [ "x$1" = "x--no-patchoat" ]; then
110 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
111 USE_DEX2OAT_AND_PATCHOAT="n"
113 elif [ "x$1" = "x--relocate" ]; then
116 elif [ "x$1" = "x--no-relocate" ]; then
119 elif [ "x$1" = "x--prebuild" ]; then
122 elif [ "x$1" = "x--strip-dex" ]; then
125 elif [ "x$1" = "x--host" ]; then
127 ANDROID_ROOT="$ANDROID_HOST_OUT"
129 elif [ "x$1" = "x--no-prebuild" ]; then
132 elif [ "x$1" = "x--no-image" ]; then
135 elif [ "x$1" = "x--secondary" ]; then
136 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
137 # Enable cfg-append to make sure we get the dump for both dex files.
138 # (otherwise the runtime compilation of the secondary dex will overwrite
139 # the dump of the first one)
140 FLAGS="${FLAGS} -Xcompiler-option --dump-cfg-append"
141 COMPILE_FLAGS="${COMPILE_FLAGS} --dump-cfg-append"
143 elif [ "x$1" = "x--debug" ]; then
147 elif [ "x$1" = "x--gdb" ]; then
152 elif [ "x$1" = "x--gdb-arg" ]; then
155 GDB_ARGS="${GDB_ARGS} $gdb_arg"
157 elif [ "x$1" = "x--zygote" ]; then
159 msg "Spawning from zygote"
161 elif [ "x$1" = "x--dev" ]; then
164 elif [ "x$1" = "x--interpreter" ]; then
167 elif [ "x$1" = "x--jit" ]; then
170 elif [ "x$1" = "x--jvm" ]; then
173 elif [ "x$1" = "x--invoke-with" ]; then
175 if [ "x$1" = "x" ]; then
176 echo "$0 missing argument to --invoke-with" 1>&2
179 if [ "x$INVOKE_WITH" = "x" ]; then
182 INVOKE_WITH="$INVOKE_WITH $1"
185 elif [ "x$1" = "x--no-verify" ]; then
188 elif [ "x$1" = "x--verify-soft-fail" ]; then
191 elif [ "x$1" = "x--no-optimize" ]; then
194 elif [ "x$1" = "x--android-root" ]; then
198 elif [ "x$1" = "x--instruction-set-features" ]; then
200 INSTRUCTION_SET_FEATURES="$1"
202 elif [ "x$1" = "x--" ]; then
205 elif [ "x$1" = "x--64" ]; then
207 GDB_SERVER="gdbserver64"
208 DALVIKVM="dalvikvm64"
209 LIBRARY_DIRECTORY="lib64"
210 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
212 elif [ "x$1" = "x--pic-test" ]; then
213 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
214 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
216 elif [ "x$1" = "x--experimental" ]; then
217 if [ "$#" -lt 2 ]; then
218 echo "missing --experimental option" 1>&2
221 EXPERIMENTAL="$EXPERIMENTAL $2"
223 elif expr "x$1" : "x--" >/dev/null 2>&1; then
224 echo "unknown $0 option: $1" 1>&2
231 if [ "$USE_JVM" = "n" ]; then
232 for feature in ${EXPERIMENTAL}; do
233 FLAGS="${FLAGS} -Xexperimental:${feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:${feature}"
234 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xexperimental:${feature}"
238 if [ "x$1" = "x" ] ; then
245 if [ "$ZYGOTE" = "" ]; then
246 if [ "$OPTIMIZE" = "y" ]; then
247 if [ "$VERIFY" = "y" ]; then
248 DEX_OPTIMIZE="-Xdexopt:verified"
250 DEX_OPTIMIZE="-Xdexopt:all"
252 msg "Performing optimizations"
254 DEX_OPTIMIZE="-Xdexopt:none"
255 msg "Skipping optimizations"
258 if [ "$VERIFY" = "y" ]; then
259 JVM_VERIFY_ARG="-Xverify:all"
260 msg "Performing verification"
261 elif [ "$VERIFY" = "s" ]; then
262 JVM_VERIFY_ARG="Xverify:all"
263 DEX_VERIFY="-Xverify:softfail"
264 msg "Forcing verification to be soft fail"
266 DEX_VERIFY="-Xverify:none"
267 JVM_VERIFY_ARG="-Xverify:none"
268 msg "Skipping verification"
272 msg "------------------------------"
274 if [ "$DEBUGGER" = "y" ]; then
275 # Use this instead for ddms and connect by running 'ddms':
276 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
277 # TODO: add a separate --ddms option?
280 msg "Waiting for jdb to connect:"
281 if [ "$HOST" = "n" ]; then
282 msg " adb forward tcp:$PORT tcp:$PORT"
284 msg " jdb -attach localhost:$PORT"
285 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
288 if [ "$USE_JVM" = "y" ]; then
289 # Xmx is necessary since we don't pass down the ART flags to JVM.
290 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes ${FLAGS} $MAIN $@"
291 if [ "$DEV_MODE" = "y" ]; then
299 if [ "$HAVE_IMAGE" = "n" ]; then
300 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
302 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
306 if [ "$USE_GDB" = "y" ]; then
307 if [ "$HOST" = "n" ]; then
308 GDB="$GDB_SERVER :5039"
310 if [ `uname` = "Darwin" ]; then
312 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
316 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
317 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
318 # gdbargs="--annotate=3 $gdbargs"
323 if [ "$INTERPRETER" = "y" ]; then
325 if [ "$VERIFY" = "y" ] ; then
326 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=interpret-only"
327 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
328 elif [ "$VERIFY" = "s" ]; then
329 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-at-runtime"
330 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
331 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
333 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-none"
334 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
335 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
339 if [ "$JIT" = "y" ]; then
340 INT_OPTS="-Xusejit:true"
341 if [ "$VERIFY" = "y" ] ; then
342 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-at-runtime"
343 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
345 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-none"
346 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
347 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
351 JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
353 if [ "$RELOCATE" = "y" ]; then
354 COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information --runtime-arg -Xnorelocate"
355 FLAGS="${FLAGS} -Xrelocate -Xcompiler-option --include-patch-information"
356 if [ "$HOST" = "y" ]; then
357 # Run test sets a fairly draconian ulimit that we will likely blow right over
358 # since we are relocating. Get the total size of the /system/framework directory
359 # in 512 byte blocks and set it as the ulimit. This should be more than enough
361 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
362 ulimit -S $(du -c -B512 ${ANDROID_HOST_OUT}/framework 2>/dev/null | tail -1 | cut -f1) || exit 1
366 FLAGS="$FLAGS -Xnorelocate"
367 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
368 if [ "$HOST" = "y" ]; then
369 # Increase ulimit to 64MB in case we are running hprof test.
370 ulimit -S 64000 || exit 1
374 if [ "$HOST" = "n" ]; then
375 ISA=$(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
376 if [ x"$ISA" = "x" ]; then
377 echo "Unable to determine architecture"
382 dex2oat_cmdline="true"
383 mkdir_cmdline="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
386 # Pick a base that will force the app image to get relocated.
387 app_image="--base=0x4000 --app-image-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.art"
389 if [ "$PREBUILD" = "y" ]; then
390 mkdir_cmdline="${mkdir_cmdline} && mkdir -p ${DEX_LOCATION}/oat/$ISA"
391 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
393 --boot-image=${BOOT_IMAGE} \
394 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
395 --oat-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.odex \
397 --instruction-set=$ISA"
398 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
399 dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
402 # Add in a timeout. This is important for testing the compilation/verification time of
403 # pathological cases.
404 # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
405 # now. We should try to improve this.
406 # The current value is rather arbitrary. run-tests should compile quickly.
407 if [ "$HOST" != "n" ]; then
408 # Use SIGRTMIN+2 to try to dump threads.
409 # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
410 dex2oat_cmdline="timeout -k 1m -s SIGRTMIN+2 1m ${dex2oat_cmdline}"
414 if [ "$STRIP_DEX" = "y" ]; then
415 strip_cmdline="zip --quiet --delete $DEX_LOCATION/$TEST_NAME.jar classes.dex"
418 DALVIKVM_ISA_FEATURES_ARGS=""
419 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
420 DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
423 # java.io.tmpdir can only be set at launch time.
425 if [ "$HOST" = "n" ]; then
426 TMP_DIR_OPTION="-Djava.io.tmpdir=/data/local/tmp"
429 # We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
432 dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
439 $DALVIKVM_ISA_FEATURES_ARGS \
446 -XX:DumpNativeStackOnSigQuit:false \
447 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
450 dex2oat_cmdline=$(echo $dex2oat_cmdline)
451 dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
453 if [ "$HOST" = "n" ]; then
456 if [ "$QUIET" = "n" ]; then
457 adb shell rm -r $DEX_LOCATION
458 adb shell mkdir -p $DEX_LOCATION
459 adb push $TEST_NAME.jar $DEX_LOCATION
460 adb push $TEST_NAME-ex.jar $DEX_LOCATION
462 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
463 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
464 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
465 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
469 if [ "$ANDROID_ROOT" != "/system" ]; then
470 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
471 # so we can only use LD_LIBRARY_PATH when testing on a local
473 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY
476 PUBLIC_LIBS=libart.so:libartd.so
478 # Create a script with the command. The command can get longer than the longest
479 # allowed adb command and there is no way to get the exit status from a adb shell
481 cmdline="cd $DEX_LOCATION && \
482 export ANDROID_DATA=$DEX_LOCATION && \
483 export ANDROID_ADDITIONAL_PUBLIC_LIBRARIES=$PUBLIC_LIBS && \
484 export DEX_LOCATION=$DEX_LOCATION && \
485 export ANDROID_ROOT=$ANDROID_ROOT && \
487 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
488 export PATH=$ANDROID_ROOT/bin:$PATH && \
489 $dex2oat_cmdline && \
493 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
494 echo "$cmdline" > $cmdfile
496 if [ "$DEV_MODE" = "y" ]; then
500 if [ "$QUIET" = "n" ]; then
501 adb push $cmdfile $DEX_LOCATION/cmdline.sh
503 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
506 adb shell sh $DEX_LOCATION/cmdline.sh
510 export ANDROID_PRINTF_LOG=brief
512 # By default, and for prebuild dex2oat, we are interested in errors being logged. In dev mode
513 # we want debug messages.
514 if [ "$DEV_MODE" = "y" ]; then
515 export ANDROID_LOG_TAGS='*:d'
517 export ANDROID_LOG_TAGS='*:e'
520 export ANDROID_DATA="$DEX_LOCATION"
521 export ANDROID_ROOT="${ANDROID_ROOT}"
522 export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
523 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
524 export PATH="$PATH:${ANDROID_ROOT}/bin"
526 # Temporarily disable address space layout randomization (ASLR).
527 # This is needed on the host so that the linker loads core.oat at the necessary address.
528 export LD_USE_LOAD_BIAS=1
530 cmdline="$dalvikvm_cmdline"
532 if [ "$TIME_OUT" = "gdb" ]; then
533 if [ `uname` = "Darwin" ]; then
534 # Fall back to timeout on Mac.
536 elif [ "$ISA" = "x86" ]; then
537 # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
540 # Check if gdb is available.
541 gdb --eval-command="quit" > /dev/null 2>&1
543 # gdb isn't available. Fall back to timeout.
549 if [ "$TIME_OUT" = "timeout" ]; then
550 # Add timeout command if time out is desired.
552 # Note: We use nested timeouts. The inner timeout sends SIGRTMIN+2 (usually 36) to ART, which
553 # will induce a full thread dump before abort. However, dumping threads might deadlock,
554 # so the outer timeout sends the regular SIGTERM after an additional minute to ensure
555 # termination (without dumping all threads).
556 TIME_PLUS_ONE=$(($TIME_OUT_VALUE + 60))
557 cmdline="timeout ${TIME_PLUS_ONE}s timeout -s SIGRTMIN+2 ${TIME_OUT_VALUE}s $cmdline"
560 if [ "$DEV_MODE" = "y" ]; then
561 echo "$mkdir_cmdline && $dex2oat_cmdline && $strip_cmdline && $cmdline"
564 cd $ANDROID_BUILD_TOP
566 rm -rf ${DEX_LOCATION}/dalvik-cache/
567 $mkdir_cmdline || exit 1
568 $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
569 $strip_cmdline || { echo "Strip failed." >&2 ; exit 3; }
571 # For running, we must turn off logging when dex2oat or patchoat are missing. Otherwise we use
572 # the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
573 if [ "$DEV_MODE" = "y" ]; then
574 export ANDROID_LOG_TAGS='*:d'
575 elif [ "$USE_DEX2OAT_AND_PATCHOAT" = "n" ]; then
576 # All tests would log the error of failing dex2oat/patchoat. Be silent here and only
578 export ANDROID_LOG_TAGS='*:s'
580 # We are interested in LOG(ERROR) output.
581 export ANDROID_LOG_TAGS='*:e'
584 if [ "$USE_GDB" = "y" ]; then
585 # When running under gdb, we cannot do piping and grepping...
588 if [ "$TIME_OUT" != "gdb" ]; then
589 trap 'kill -INT -$pid' INT
590 $cmdline "$@" 2>&1 & pid=$!
592 # Add extra detail if time out is enabled.
593 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
594 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
597 # With a thread dump that uses gdb if a timeout.
598 trap 'kill -INT -$pid' INT
599 $cmdline "$@" 2>&1 & pid=$!
600 # Spawn a watcher process.
601 ( sleep $TIME_OUT_VALUE && \
602 echo "##### Thread dump using gdb on test timeout" && \
603 ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
604 --eval-command="call exit(124)" --eval-command=quit || \
605 kill $pid )) 2> /dev/null & watcher=$!
608 pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
609 if [ $test_exit_status = 0 ]; then
610 # The test finished normally.
613 # The test failed or timed out.
614 if [ $test_exit_status = 124 ]; then
615 # The test timed out.
616 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2