blob: 18867fd03566caf6ec5a52629cde6cae1d07f248 [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 Geoffray1a58b7f2014-10-06 12:23:04 +010022FALSE_BIN="/system/bin/false"
23FLAGS=""
24GDB=""
Nicolas Geoffraybaf91022014-10-08 09:56:45 +010025GDB_ARGS=""
26GDB_SERVER="gdbserver"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010027HAVE_IMAGE="y"
28HOST="n"
29INTERPRETER="n"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080030JIT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010031INVOKE_WITH=""
32ISA=x86
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000033LIBRARY_DIRECTORY="lib"
34MAIN=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010035OPTIMIZE="y"
36PATCHOAT=""
37PREBUILD="y"
38QUIET="n"
39RELOCATE="y"
Jeff Hao207a37d2014-10-29 17:24:25 -070040SECONDARY_DEX=""
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -070041TIME_OUT="gdb" # "n" (disabled), "timeout" (use timeout), "gdb" (use gdb)
42# Value in seconds
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070043if [ "$ART_USE_READ_BARRIER" = "true" ]; then
44 TIME_OUT_VALUE=900 # 15 minutes.
45else
46 TIME_OUT_VALUE=600 # 10 minutes.
47fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010048USE_GDB="n"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +010049USE_JVM="n"
Igor Murashkin7617abd2015-07-10 18:27:47 -070050VERIFY="y" # y=yes,n=no,s=softfail
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010051ZYGOTE=""
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -070052DEX_VERIFY=""
Andreas Gampe65357032015-02-19 15:10:24 -080053USE_DEX2OAT_AND_PATCHOAT="y"
Andreas Gampe4d2ef332015-08-05 09:24:45 -070054INSTRUCTION_SET_FEATURES=""
Mathieu Chartier031768a2015-08-27 10:25:02 -070055ARGS=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010056
57while true; do
58 if [ "x$1" = "x--quiet" ]; then
59 QUIET="y"
60 shift
61 elif [ "x$1" = "x--lib" ]; then
62 shift
63 if [ "x$1" = "x" ]; then
64 echo "$0 missing argument to --lib" 1>&2
65 exit 1
66 fi
67 LIB="$1"
68 shift
Mathieu Chartier031768a2015-08-27 10:25:02 -070069 elif [ "x$1" = "x--testlib" ]; then
70 shift
71 if [ "x$1" = "x" ]; then
72 echo "$0 missing argument to --testlib" 1>&2
73 exit 1
74 fi
Mathieu Chartierde286fd2015-09-03 18:10:29 -070075 ARGS="${ARGS} $1"
Mathieu Chartier031768a2015-08-27 10:25:02 -070076 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010077 elif [ "x$1" = "x-Xcompiler-option" ]; then
78 shift
79 option="$1"
80 FLAGS="${FLAGS} -Xcompiler-option $option"
81 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
82 shift
83 elif [ "x$1" = "x--runtime-option" ]; then
84 shift
85 option="$1"
86 FLAGS="${FLAGS} $option"
87 shift
88 elif [ "x$1" = "x--boot" ]; then
89 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000090 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010091 shift
92 elif [ "x$1" = "x--no-dex2oat" ]; then
93 DEX2OAT="-Xcompiler:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -080094 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010095 shift
96 elif [ "x$1" = "x--no-patchoat" ]; then
97 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -080098 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010099 shift
100 elif [ "x$1" = "x--relocate" ]; then
101 RELOCATE="y"
102 shift
103 elif [ "x$1" = "x--no-relocate" ]; then
104 RELOCATE="n"
105 shift
106 elif [ "x$1" = "x--prebuild" ]; then
107 PREBUILD="y"
108 shift
109 elif [ "x$1" = "x--host" ]; then
110 HOST="y"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000111 ANDROID_ROOT="$ANDROID_HOST_OUT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100112 shift
113 elif [ "x$1" = "x--no-prebuild" ]; then
114 PREBUILD="n"
115 shift
116 elif [ "x$1" = "x--no-image" ]; then
117 HAVE_IMAGE="n"
118 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700119 elif [ "x$1" = "x--secondary" ]; then
120 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
Calin Juravle175dc732015-08-25 15:42:32 +0100121 # Enable cfg-append to make sure we get the dump for both dex files.
122 # (otherwise the runtime compilation of the secondary dex will overwrite
123 # the dump of the first one)
124 FLAGS="${FLAGS} -Xcompiler-option --dump-cfg-append"
125 COMPILE_FLAGS="${COMPILE_FLAGS} --dump-cfg-append"
Jeff Hao207a37d2014-10-29 17:24:25 -0700126 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100127 elif [ "x$1" = "x--debug" ]; then
128 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800129 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100130 shift
131 elif [ "x$1" = "x--gdb" ]; then
132 USE_GDB="y"
133 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800134 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100135 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700136 elif [ "x$1" = "x--gdb-arg" ]; then
137 shift
138 gdb_arg="$1"
139 GDB_ARGS="${GDB_ARGS} $gdb_arg"
140 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100141 elif [ "x$1" = "x--zygote" ]; then
142 ZYGOTE="-Xzygote"
143 msg "Spawning from zygote"
144 shift
145 elif [ "x$1" = "x--dev" ]; then
146 DEV_MODE="y"
147 shift
148 elif [ "x$1" = "x--interpreter" ]; then
149 INTERPRETER="y"
150 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800151 elif [ "x$1" = "x--jit" ]; then
152 JIT="y"
153 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100154 elif [ "x$1" = "x--jvm" ]; then
155 USE_JVM="y"
156 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100157 elif [ "x$1" = "x--invoke-with" ]; then
158 shift
159 if [ "x$1" = "x" ]; then
160 echo "$0 missing argument to --invoke-with" 1>&2
161 exit 1
162 fi
163 if [ "x$INVOKE_WITH" = "x" ]; then
164 INVOKE_WITH="$1"
165 else
166 INVOKE_WITH="$INVOKE_WITH $1"
167 fi
168 shift
169 elif [ "x$1" = "x--no-verify" ]; then
170 VERIFY="n"
171 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700172 elif [ "x$1" = "x--verify-soft-fail" ]; then
173 VERIFY="s"
174 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100175 elif [ "x$1" = "x--no-optimize" ]; then
176 OPTIMIZE="n"
177 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000178 elif [ "x$1" = "x--android-root" ]; then
179 shift
180 ANDROID_ROOT="$1"
181 shift
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700182 elif [ "x$1" = "x--instruction-set-features" ]; then
183 shift
184 INSTRUCTION_SET_FEATURES="$1"
185 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100186 elif [ "x$1" = "x--" ]; then
187 shift
188 break
189 elif [ "x$1" = "x--64" ]; then
190 ISA="x86_64"
191 GDB_SERVER="gdbserver64"
192 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000193 LIBRARY_DIRECTORY="lib64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100194 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
195 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700196 elif [ "x$1" = "x--pic-test" ]; then
197 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
198 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
199 shift
Alex Light8a0e0332015-10-26 10:11:58 -0700200 elif [ "x$1" = "x--experimental" ]; then
201 if [ "$#" -lt 2 ]; then
202 echo "missing --experimental option" 1>&2
203 exit 1
204 fi
205 EXPERIMENTAL="$EXPERIMENTAL $2"
206 shift 2
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100207 elif expr "x$1" : "x--" >/dev/null 2>&1; then
208 echo "unknown $0 option: $1" 1>&2
209 exit 1
210 else
211 break
212 fi
213done
214
Alex Light8a0e0332015-10-26 10:11:58 -0700215if [ "$USE_JVM" = "n" ]; then
216 for feature in ${EXPERIMENTAL}; do
Alex Lightfa022852015-10-28 09:13:20 -0700217 FLAGS="${FLAGS} -Xexperimental:${feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:${feature}"
Alex Light8a0e0332015-10-26 10:11:58 -0700218 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xexperimental:${feature}"
219 done
220fi
221
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100222if [ "x$1" = "x" ] ; then
223 MAIN="Main"
224else
225 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700226 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100227fi
228
229if [ "$ZYGOTE" = "" ]; then
230 if [ "$OPTIMIZE" = "y" ]; then
231 if [ "$VERIFY" = "y" ]; then
232 DEX_OPTIMIZE="-Xdexopt:verified"
233 else
234 DEX_OPTIMIZE="-Xdexopt:all"
235 fi
236 msg "Performing optimizations"
237 else
238 DEX_OPTIMIZE="-Xdexopt:none"
239 msg "Skipping optimizations"
240 fi
241
242 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100243 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100244 msg "Performing verification"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700245 elif [ "$VERIFY" = "s" ]; then
246 JVM_VERIFY_ARG="Xverify:all"
247 DEX_VERIFY="-Xverify:softfail"
248 msg "Forcing verification to be soft fail"
249 else # VERIFY = "n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100250 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100251 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100252 msg "Skipping verification"
253 fi
254fi
255
256msg "------------------------------"
257
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100258if [ "$DEBUGGER" = "y" ]; then
259 # Use this instead for ddms and connect by running 'ddms':
260 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
261 # TODO: add a separate --ddms option?
262
263 PORT=12345
264 msg "Waiting for jdb to connect:"
265 if [ "$HOST" = "n" ]; then
266 msg " adb forward tcp:$PORT tcp:$PORT"
267 fi
268 msg " jdb -attach localhost:$PORT"
269 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
270fi
271
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100272if [ "$USE_JVM" = "y" ]; then
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700273 # Xmx is necessary since we don't pass down the ART flags to JVM.
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700274 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes ${FLAGS} $MAIN $@"
275 if [ "$DEV_MODE" = "y" ]; then
276 echo $cmdline
277 fi
278 $cmdline
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100279 exit
280fi
281
282
283if [ "$HAVE_IMAGE" = "n" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000284 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000285else
286 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100287fi
288
289
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100290if [ "$USE_GDB" = "y" ]; then
291 if [ "$HOST" = "n" ]; then
292 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100293 else
294 if [ `uname` = "Darwin" ]; then
295 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700296 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100297 DALVIKVM=
298 else
299 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700300 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100301 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
302 # gdbargs="--annotate=3 $gdbargs"
303 fi
304 fi
305fi
306
307if [ "$INTERPRETER" = "y" ]; then
308 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700309 if [ "$VERIFY" = "y" ] ; then
310 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700311 elif [ "$VERIFY" = "s" ]; then
312 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
313 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
314 else # VERIFY = "n"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700315 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
316 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
317 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100318fi
319
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800320if [ "$JIT" = "y" ]; then
Sebastien Hertz155bef42015-03-09 14:57:48 +0100321 INT_OPTS="-Xusejit:true"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800322 if [ "$VERIFY" = "y" ] ; then
Mathieu Chartiere86deef2015-03-19 13:43:37 -0700323 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800324 else
325 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
326 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
327 fi
328fi
329
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100330JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
331
332if [ "$RELOCATE" = "y" ]; then
333 COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information --runtime-arg -Xnorelocate"
334 FLAGS="${FLAGS} -Xrelocate -Xcompiler-option --include-patch-information"
335 if [ "$HOST" = "y" ]; then
336 # Run test sets a fairly draconian ulimit that we will likely blow right over
337 # since we are relocating. Get the total size of the /system/framework directory
338 # in 512 byte blocks and set it as the ulimit. This should be more than enough
339 # room.
340 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
341 ulimit -S $(du -c -B512 ${ANDROID_HOST_OUT}/framework | tail -1 | cut -f1) || exit 1
342 fi
343 fi
344else
345 FLAGS="$FLAGS -Xnorelocate"
346 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
Mathieu Chartiercae2ed92015-06-09 13:02:50 -0700347 if [ "$HOST" = "y" ]; then
348 # Increase ulimit to 64MB in case we are running hprof test.
349 ulimit -S 64000 || exit 1
350 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100351fi
352
353if [ "$HOST" = "n" ]; then
354 ISA=$(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
355 if [ x"$ISA" = "x" ]; then
356 echo "Unable to determine architecture"
357 exit 1
358 fi
359fi
360
361dex2oat_cmdline="true"
362mkdir_cmdline="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
363
364if [ "$PREBUILD" = "y" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000365 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100366 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000367 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100368 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
369 --oat-file=$DEX_LOCATION/dalvik-cache/$ISA/$(echo $DEX_LOCATION/$TEST_NAME.jar/classes.dex | cut -d/ -f 2- | sed "s:/:@:g") \
370 --instruction-set=$ISA"
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700371 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
372 dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
373 fi
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700374
375 # Add in a timeout. This is important for testing the compilation/verification time of
376 # pathological cases.
377 # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
378 # now. We should try to improve this.
379 # The current value is rather arbitrary. run-tests should compile quickly.
380 if [ "$HOST" != "n" ]; then
381 # Use SIGRTMIN+2 to try to dump threads.
382 # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
383 dex2oat_cmdline="timeout -k 1m -s SIGRTMIN+2 1m ${dex2oat_cmdline}"
384 fi
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700385fi
386
387DALVIKVM_ISA_FEATURES_ARGS=""
388if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
389 DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100390fi
391
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000392dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100393 $GDB_ARGS \
394 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700395 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100396 -XXlib:$LIB \
397 $PATCHOAT \
398 $DEX2OAT \
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700399 $DALVIKVM_ISA_FEATURES_ARGS \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100400 $ZYGOTE \
401 $JNI_OPTS \
402 $INT_OPTS \
403 $DEBUGGER_OPTS \
404 $DALVIKVM_BOOT_OPT \
Mathieu Chartier031768a2015-08-27 10:25:02 -0700405 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100406
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -0800407# Remove whitespace.
408dex2oat_cmdline=$(echo $dex2oat_cmdline)
409dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100410
411if [ "$HOST" = "n" ]; then
412 adb root > /dev/null
413 adb wait-for-device
414 if [ "$QUIET" = "n" ]; then
415 adb shell rm -r $DEX_LOCATION
416 adb shell mkdir -p $DEX_LOCATION
417 adb push $TEST_NAME.jar $DEX_LOCATION
418 adb push $TEST_NAME-ex.jar $DEX_LOCATION
419 else
420 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
421 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
422 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
423 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
424 fi
425
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000426 LD_LIBRARY_PATH=
427 if [ "$ANDROID_ROOT" != "/system" ]; then
428 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
429 # so we can only use LD_LIBRARY_PATH when testing on a local
430 # installation.
431 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY
432 fi
433
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100434 # Create a script with the command. The command can get longer than the longest
435 # allowed adb command and there is no way to get the exit status from a adb shell
436 # command.
437 cmdline="cd $DEX_LOCATION && \
438 export ANDROID_DATA=$DEX_LOCATION && \
439 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000440 export ANDROID_ROOT=$ANDROID_ROOT && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100441 $mkdir_cmdline && \
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100442 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray4f7fdd22015-04-24 11:57:37 +0100443 export PATH=$ANDROID_ROOT/bin:$PATH && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100444 $dex2oat_cmdline && \
445 $dalvikvm_cmdline"
446
447 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
448 echo "$cmdline" > $cmdfile
449
450 if [ "$DEV_MODE" = "y" ]; then
451 echo $cmdline
452 fi
453
454 if [ "$QUIET" = "n" ]; then
455 adb push $cmdfile $DEX_LOCATION/cmdline.sh
456 else
457 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
458 fi
459
460 adb shell sh $DEX_LOCATION/cmdline.sh
461
462 rm -f $cmdfile
463else
464 export ANDROID_PRINTF_LOG=brief
Andreas Gampea8780822015-03-13 19:51:09 -0700465
466 # By default, and for prebuild dex2oat, we are interested in errors being logged. In dev mode
467 # we want debug messages.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100468 if [ "$DEV_MODE" = "y" ]; then
469 export ANDROID_LOG_TAGS='*:d'
470 else
Andreas Gampee4301ff2015-02-17 19:25:29 -0800471 export ANDROID_LOG_TAGS='*:e'
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100472 fi
Andreas Gampea8780822015-03-13 19:51:09 -0700473
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100474 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000475 export ANDROID_ROOT="${ANDROID_ROOT}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100476 export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
477 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
478 export PATH="$PATH:${ANDROID_ROOT}/bin"
479
David Srbeckyc9ede382015-06-20 06:03:53 +0100480 # Temporarily disable address space layout randomization (ASLR).
481 # This is needed on the host so that the linker loads core.oat at the necessary address.
482 export LD_USE_LOAD_BIAS=1
483
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100484 cmdline="$dalvikvm_cmdline"
485
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700486 if [ "$TIME_OUT" = "gdb" ]; then
487 if [ `uname` = "Darwin" ]; then
488 # Fall back to timeout on Mac.
489 TIME_OUT="timeout"
Hiroshi Yamauchic823eff2015-09-01 16:21:35 -0700490 elif [ "$ISA" = "x86" ]; then
491 # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
492 TIME_OUT="timeout"
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700493 else
494 # Check if gdb is available.
495 gdb --eval-command="quit" > /dev/null 2>&1
496 if [ $? != 0 ]; then
497 # gdb isn't available. Fall back to timeout.
498 TIME_OUT="timeout"
499 fi
500 fi
501 fi
502
503 if [ "$TIME_OUT" = "timeout" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100504 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -0800505 #
506 # Note: We use nested timeouts. The inner timeout sends SIGRTMIN+2 (usually 36) to ART, which
507 # will induce a full thread dump before abort. However, dumping threads might deadlock,
508 # so the outer timeout sends the regular SIGTERM after an additional minute to ensure
509 # termination (without dumping all threads).
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700510 TIME_PLUS_ONE=$(($TIME_OUT_VALUE + 60))
511 cmdline="timeout ${TIME_PLUS_ONE}s timeout -s SIGRTMIN+2 ${TIME_OUT_VALUE}s $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100512 fi
513
514 if [ "$DEV_MODE" = "y" ]; then
515 if [ "$PREBUILD" = "y" ]; then
516 echo "$mkdir_cmdline && $dex2oat_cmdline && $cmdline"
517 elif [ "$RELOCATE" = "y" ]; then
518 echo "$mkdir_cmdline && $cmdline"
519 else
520 echo $cmdline
521 fi
522 fi
523
524 cd $ANDROID_BUILD_TOP
525
526 $mkdir_cmdline || exit 1
Andreas Gampea8780822015-03-13 19:51:09 -0700527 $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
528
529 # For running, we must turn off logging when dex2oat or patchoat are missing. Otherwise we use
530 # the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
531 if [ "$DEV_MODE" = "y" ]; then
532 export ANDROID_LOG_TAGS='*:d'
533 elif [ "$USE_DEX2OAT_AND_PATCHOAT" = "n" ]; then
534 # All tests would log the error of failing dex2oat/patchoat. Be silent here and only
535 # log fatal events.
536 export ANDROID_LOG_TAGS='*:s'
537 else
538 # We are interested in LOG(ERROR) output.
539 export ANDROID_LOG_TAGS='*:e'
540 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100541
542 if [ "$USE_GDB" = "y" ]; then
543 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700544 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100545 else
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700546 if [ "$TIME_OUT" != "gdb" ]; then
547 trap 'kill -INT -$pid' INT
548 $cmdline "$@" 2>&1 & pid=$!
549 wait $pid
550 # Add extra detail if time out is enabled.
551 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
552 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
553 fi
554 else
555 # With a thread dump that uses gdb if a timeout.
556 trap 'kill -INT -$pid' INT
557 $cmdline "$@" 2>&1 & pid=$!
558 # Spawn a watcher process.
559 ( sleep $TIME_OUT_VALUE && \
560 echo "##### Thread dump using gdb on test timeout" && \
561 ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
562 --eval-command="call exit(124)" --eval-command=quit || \
563 kill $pid )) 2> /dev/null & watcher=$!
564 wait $pid
565 test_exit_status=$?
566 pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
567 if [ $test_exit_status = 0 ]; then
568 # The test finished normally.
569 exit 0
570 else
571 # The test failed or timed out.
572 if [ $test_exit_status = 124 ]; then
573 # The test timed out.
574 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
575 fi
576 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100577 fi
578 fi
579fi