OSDN Git Service

Merge "Allow libcore and JDWP tests to be executed without JIT."
[android-x86/art.git] / test / etc / run-test-jar
1 #!/bin/bash
2 #
3 # Runner for an individual run-test.
4
5 msg() {
6     if [ "$QUIET" = "n" ]; then
7         echo "$@"
8     fi
9 }
10
11 ANDROID_ROOT="/system"
12 ARCHITECTURES_32="(arm|x86|mips|none)"
13 ARCHITECTURES_64="(arm64|x86_64|mips64|none)"
14 ARCHITECTURES_PATTERN="${ARCHITECTURES_32}"
15 BOOT_IMAGE=""
16 COMPILE_FLAGS=""
17 DALVIKVM="dalvikvm32"
18 DEBUGGER="n"
19 DEV_MODE="n"
20 DEX2OAT=""
21 EXPERIMENTAL=""
22 FALSE_BIN="/system/bin/false"
23 FLAGS=""
24 GDB=""
25 GDB_ARGS=""
26 GDB_SERVER="gdbserver"
27 HAVE_IMAGE="y"
28 HOST="n"
29 INTERPRETER="n"
30 JIT="n"
31 INVOKE_WITH=""
32 ISA=x86
33 LIBRARY_DIRECTORY="lib"
34 MAIN=""
35 OPTIMIZE="y"
36 PATCHOAT=""
37 PREBUILD="y"
38 QUIET="n"
39 RELOCATE="y"
40 STRIP_DEX="n"
41 SECONDARY_DEX=""
42 TIME_OUT="gdb"  # "n" (disabled), "timeout" (use timeout), "gdb" (use gdb)
43 # Value in seconds
44 if [ "$ART_USE_READ_BARRIER" = "true" ]; then
45   TIME_OUT_VALUE=900  # 15 minutes.
46 else
47   TIME_OUT_VALUE=600  # 10 minutes.
48 fi
49 USE_GDB="n"
50 USE_JVM="n"
51 VERIFY="y" # y=yes,n=no,s=softfail
52 ZYGOTE=""
53 DEX_VERIFY=""
54 USE_DEX2OAT_AND_PATCHOAT="y"
55 INSTRUCTION_SET_FEATURES=""
56 ARGS=""
57
58 while true; do
59     if [ "x$1" = "x--quiet" ]; then
60         QUIET="y"
61         shift
62     elif [ "x$1" = "x--lib" ]; then
63         shift
64         if [ "x$1" = "x" ]; then
65             echo "$0 missing argument to --lib" 1>&2
66             exit 1
67         fi
68         LIB="$1"
69         shift
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))
73         shift
74     elif [ "x$1" = "x--testlib" ]; then
75         shift
76         if [ "x$1" = "x" ]; then
77             echo "$0 missing argument to --testlib" 1>&2
78             exit 1
79         fi
80         ARGS="${ARGS} $1"
81         shift
82     elif [ "x$1" = "x--args" ]; then
83         shift
84         if [ "x$1" = "x" ]; then
85             echo "$0 missing argument to --args" 1>&2
86             exit 1
87         fi
88         ARGS="${ARGS} $1"
89         shift
90     elif [ "x$1" = "x-Xcompiler-option" ]; then
91         shift
92         option="$1"
93         FLAGS="${FLAGS} -Xcompiler-option $option"
94         COMPILE_FLAGS="${COMPILE_FLAGS} $option"
95         shift
96     elif [ "x$1" = "x--runtime-option" ]; then
97         shift
98         option="$1"
99         FLAGS="${FLAGS} $option"
100         shift
101     elif [ "x$1" = "x--boot" ]; then
102         shift
103         BOOT_IMAGE="$1"
104         shift
105     elif [ "x$1" = "x--no-dex2oat" ]; then
106         DEX2OAT="-Xcompiler:${FALSE_BIN}"
107         USE_DEX2OAT_AND_PATCHOAT="n"
108         shift
109     elif [ "x$1" = "x--no-patchoat" ]; then
110         PATCHOAT="-Xpatchoat:${FALSE_BIN}"
111         USE_DEX2OAT_AND_PATCHOAT="n"
112         shift
113     elif [ "x$1" = "x--relocate" ]; then
114         RELOCATE="y"
115         shift
116     elif [ "x$1" = "x--no-relocate" ]; then
117         RELOCATE="n"
118         shift
119     elif [ "x$1" = "x--prebuild" ]; then
120         PREBUILD="y"
121         shift
122     elif [ "x$1" = "x--strip-dex" ]; then
123         STRIP_DEX="y"
124         shift
125     elif [ "x$1" = "x--host" ]; then
126         HOST="y"
127         ANDROID_ROOT="$ANDROID_HOST_OUT"
128         shift
129     elif [ "x$1" = "x--no-prebuild" ]; then
130         PREBUILD="n"
131         shift
132     elif [ "x$1" = "x--no-image" ]; then
133         HAVE_IMAGE="n"
134         shift
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"
142         shift
143     elif [ "x$1" = "x--debug" ]; then
144         DEBUGGER="y"
145         TIME_OUT="n"
146         shift
147     elif [ "x$1" = "x--gdb" ]; then
148         USE_GDB="y"
149         DEV_MODE="y"
150         TIME_OUT="n"
151         shift
152     elif [ "x$1" = "x--gdb-arg" ]; then
153         shift
154         gdb_arg="$1"
155         GDB_ARGS="${GDB_ARGS} $gdb_arg"
156         shift
157     elif [ "x$1" = "x--zygote" ]; then
158         ZYGOTE="-Xzygote"
159         msg "Spawning from zygote"
160         shift
161     elif [ "x$1" = "x--dev" ]; then
162         DEV_MODE="y"
163         shift
164     elif [ "x$1" = "x--interpreter" ]; then
165         INTERPRETER="y"
166         shift
167     elif [ "x$1" = "x--jit" ]; then
168         JIT="y"
169         shift
170     elif [ "x$1" = "x--jvm" ]; then
171         USE_JVM="y"
172         shift
173     elif [ "x$1" = "x--invoke-with" ]; then
174         shift
175         if [ "x$1" = "x" ]; then
176             echo "$0 missing argument to --invoke-with" 1>&2
177             exit 1
178         fi
179         if [ "x$INVOKE_WITH" = "x" ]; then
180             INVOKE_WITH="$1"
181         else
182             INVOKE_WITH="$INVOKE_WITH $1"
183         fi
184         shift
185     elif [ "x$1" = "x--no-verify" ]; then
186         VERIFY="n"
187         shift
188     elif [ "x$1" = "x--verify-soft-fail" ]; then
189         VERIFY="s"
190         shift
191     elif [ "x$1" = "x--no-optimize" ]; then
192         OPTIMIZE="n"
193         shift
194     elif [ "x$1" = "x--android-root" ]; then
195         shift
196         ANDROID_ROOT="$1"
197         shift
198     elif [ "x$1" = "x--instruction-set-features" ]; then
199         shift
200         INSTRUCTION_SET_FEATURES="$1"
201         shift
202     elif [ "x$1" = "x--" ]; then
203         shift
204         break
205     elif [ "x$1" = "x--64" ]; then
206         ISA="x86_64"
207         GDB_SERVER="gdbserver64"
208         DALVIKVM="dalvikvm64"
209         LIBRARY_DIRECTORY="lib64"
210         ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
211         shift
212     elif [ "x$1" = "x--pic-test" ]; then
213         FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
214         COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
215         shift
216     elif [ "x$1" = "x--experimental" ]; then
217         if [ "$#" -lt 2 ]; then
218             echo "missing --experimental option" 1>&2
219             exit 1
220         fi
221         EXPERIMENTAL="$EXPERIMENTAL $2"
222         shift 2
223     elif expr "x$1" : "x--" >/dev/null 2>&1; then
224         echo "unknown $0 option: $1" 1>&2
225         exit 1
226     else
227         break
228     fi
229 done
230
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}"
235     done
236 fi
237
238 if [ "x$1" = "x" ] ; then
239   MAIN="Main"
240 else
241   MAIN="$1"
242   shift
243 fi
244
245 if [ "$ZYGOTE" = "" ]; then
246     if [ "$OPTIMIZE" = "y" ]; then
247         if [ "$VERIFY" = "y" ]; then
248             DEX_OPTIMIZE="-Xdexopt:verified"
249         else
250             DEX_OPTIMIZE="-Xdexopt:all"
251         fi
252         msg "Performing optimizations"
253     else
254         DEX_OPTIMIZE="-Xdexopt:none"
255         msg "Skipping optimizations"
256     fi
257
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"
265     else # VERIFY = "n"
266         DEX_VERIFY="-Xverify:none"
267         JVM_VERIFY_ARG="-Xverify:none"
268         msg "Skipping verification"
269     fi
270 fi
271
272 msg "------------------------------"
273
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?
278
279   PORT=12345
280   msg "Waiting for jdb to connect:"
281   if [ "$HOST" = "n" ]; then
282     msg "    adb forward tcp:$PORT tcp:$PORT"
283   fi
284   msg "    jdb -attach localhost:$PORT"
285   DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
286 fi
287
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
292     echo $cmdline
293   fi
294   $cmdline
295   exit
296 fi
297
298
299 if [ "$HAVE_IMAGE" = "n" ]; then
300     DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
301 else
302     DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
303 fi
304
305
306 if [ "$USE_GDB" = "y" ]; then
307   if [ "$HOST" = "n" ]; then
308     GDB="$GDB_SERVER :5039"
309   else
310     if [ `uname` = "Darwin" ]; then
311         GDB=lldb
312         GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
313         DALVIKVM=
314     else
315         GDB=gdb
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"
319     fi
320   fi
321 fi
322
323 if [ "$INTERPRETER" = "y" ]; then
324     INT_OPTS="-Xint"
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"
332     else # VERIFY = "n"
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"
336     fi
337 fi
338
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"
344     else
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"
348     fi
349 fi
350
351 JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
352
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
360         # room.
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
363         fi
364     fi
365 else
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
371     fi
372 fi
373
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"
378     exit 1
379   fi
380 fi
381
382 dex2oat_cmdline="true"
383 mkdir_cmdline="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
384 strip_cmdline="true"
385
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"
388
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 \
392                       $COMPILE_FLAGS \
393                       --boot-image=${BOOT_IMAGE} \
394                       --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
395                       --oat-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.odex \
396                       ${app_image} \
397                       --instruction-set=$ISA"
398   if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
399     dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
400   fi
401
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}"
411   fi
412 fi
413
414 if [ "$STRIP_DEX" = "y" ]; then
415   strip_cmdline="zip --quiet --delete $DEX_LOCATION/$TEST_NAME.jar classes.dex"
416 fi
417
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}"
421 fi
422
423 # java.io.tmpdir can only be set at launch time.
424 TMP_DIR_OPTION=""
425 if [ "$HOST" = "n" ]; then
426   TMP_DIR_OPTION="-Djava.io.tmpdir=/data/local/tmp"
427 fi
428
429 # We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
430 # b/27185632
431 # b/24664297
432 dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
433                   $GDB_ARGS \
434                   $FLAGS \
435                   $DEX_VERIFY \
436                   -XXlib:$LIB \
437                   $PATCHOAT \
438                   $DEX2OAT \
439                   $DALVIKVM_ISA_FEATURES_ARGS \
440                   $ZYGOTE \
441                   $JNI_OPTS \
442                   $INT_OPTS \
443                   $DEBUGGER_OPTS \
444                   $DALVIKVM_BOOT_OPT \
445                   $TMP_DIR_OPTION \
446                   -XX:DumpNativeStackOnSigQuit:false \
447                   -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
448
449 # Remove whitespace.
450 dex2oat_cmdline=$(echo $dex2oat_cmdline)
451 dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
452
453 if [ "$HOST" = "n" ]; then
454     adb root > /dev/null
455     adb wait-for-device
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
461     else
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
466     fi
467
468     LD_LIBRARY_PATH=
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
472       # installation.
473       LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY
474     fi
475
476     PUBLIC_LIBS=libart.so:libartd.so
477
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
480     # command.
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 && \
486              $mkdir_cmdline && \
487              export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
488              export PATH=$ANDROID_ROOT/bin:$PATH && \
489              $dex2oat_cmdline && \
490              $strip_cmdline && \
491              $dalvikvm_cmdline"
492
493     cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
494     echo "$cmdline" > $cmdfile
495
496     if [ "$DEV_MODE" = "y" ]; then
497       echo $cmdline
498     fi
499
500     if [ "$QUIET" = "n" ]; then
501       adb push $cmdfile $DEX_LOCATION/cmdline.sh
502     else
503       adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
504     fi
505
506     adb shell sh $DEX_LOCATION/cmdline.sh
507
508     rm -f $cmdfile
509 else
510     export ANDROID_PRINTF_LOG=brief
511
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'
516     else
517         export ANDROID_LOG_TAGS='*:e'
518     fi
519
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"
525
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
529
530     cmdline="$dalvikvm_cmdline"
531
532     if [ "$TIME_OUT" = "gdb" ]; then
533       if [ `uname` = "Darwin" ]; then
534         # Fall back to timeout on Mac.
535         TIME_OUT="timeout"
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.
538         TIME_OUT="timeout"
539       else
540         # Check if gdb is available.
541         gdb --eval-command="quit" > /dev/null 2>&1
542         if [ $? != 0 ]; then
543           # gdb isn't available. Fall back to timeout.
544           TIME_OUT="timeout"
545         fi
546       fi
547     fi
548
549     if [ "$TIME_OUT" = "timeout" ]; then
550       # Add timeout command if time out is desired.
551       #
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"
558     fi
559
560     if [ "$DEV_MODE" = "y" ]; then
561       echo "$mkdir_cmdline && $dex2oat_cmdline && $strip_cmdline && $cmdline"
562     fi
563
564     cd $ANDROID_BUILD_TOP
565
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; }
570
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
577         # log fatal events.
578         export ANDROID_LOG_TAGS='*:s'
579     else
580         # We are interested in LOG(ERROR) output.
581         export ANDROID_LOG_TAGS='*:e'
582     fi
583
584     if [ "$USE_GDB" = "y" ]; then
585       # When running under gdb, we cannot do piping and grepping...
586       $cmdline "$@"
587     else
588       if [ "$TIME_OUT" != "gdb" ]; then
589         trap 'kill -INT -$pid' INT
590         $cmdline "$@" 2>&1 & pid=$!
591         wait $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
595         fi
596       else
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=$!
606         wait $pid
607         test_exit_status=$?
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.
611           exit 0
612         else
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
617           fi
618         fi
619       fi
620     fi
621 fi