blob: f64756b5de9c414b332a7842bf3983df56cc5457 [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=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010021FALSE_BIN="/system/bin/false"
22FLAGS=""
23GDB=""
Nicolas Geoffraybaf91022014-10-08 09:56:45 +010024GDB_ARGS=""
25GDB_SERVER="gdbserver"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010026HAVE_IMAGE="y"
27HOST="n"
28INTERPRETER="n"
29INVOKE_WITH=""
30ISA=x86
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000031LIBRARY_DIRECTORY="lib"
32MAIN=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010033OPTIMIZE="y"
34PATCHOAT=""
35PREBUILD="y"
36QUIET="n"
37RELOCATE="y"
Jeff Hao207a37d2014-10-29 17:24:25 -070038SECONDARY_DEX=""
Brian Carlstrom93d6ce52014-11-04 22:31:35 -080039TIME_OUT="y"
Andreas Gampe038bb222015-01-13 19:48:14 -080040# Value in minutes.
Mathieu Chartier8dcde232015-01-15 17:23:16 -080041TIME_OUT_VALUE=10
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010042USE_GDB="n"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +010043USE_JVM="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010044VERIFY="y"
45ZYGOTE=""
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -070046DEX_VERIFY=""
Andreas Gampe65357032015-02-19 15:10:24 -080047USE_DEX2OAT_AND_PATCHOAT="y"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010048
49while true; do
50 if [ "x$1" = "x--quiet" ]; then
51 QUIET="y"
52 shift
53 elif [ "x$1" = "x--lib" ]; then
54 shift
55 if [ "x$1" = "x" ]; then
56 echo "$0 missing argument to --lib" 1>&2
57 exit 1
58 fi
59 LIB="$1"
60 shift
61 elif [ "x$1" = "x-Xcompiler-option" ]; then
62 shift
63 option="$1"
64 FLAGS="${FLAGS} -Xcompiler-option $option"
65 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
66 shift
67 elif [ "x$1" = "x--runtime-option" ]; then
68 shift
69 option="$1"
70 FLAGS="${FLAGS} $option"
71 shift
72 elif [ "x$1" = "x--boot" ]; then
73 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000074 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010075 shift
76 elif [ "x$1" = "x--no-dex2oat" ]; then
77 DEX2OAT="-Xcompiler:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -080078 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010079 shift
80 elif [ "x$1" = "x--no-patchoat" ]; then
81 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -080082 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010083 shift
84 elif [ "x$1" = "x--relocate" ]; then
85 RELOCATE="y"
86 shift
87 elif [ "x$1" = "x--no-relocate" ]; then
88 RELOCATE="n"
89 shift
90 elif [ "x$1" = "x--prebuild" ]; then
91 PREBUILD="y"
92 shift
93 elif [ "x$1" = "x--host" ]; then
94 HOST="y"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +000095 ANDROID_ROOT="$ANDROID_HOST_OUT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010096 shift
97 elif [ "x$1" = "x--no-prebuild" ]; then
98 PREBUILD="n"
99 shift
100 elif [ "x$1" = "x--no-image" ]; then
101 HAVE_IMAGE="n"
102 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700103 elif [ "x$1" = "x--secondary" ]; then
104 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
105 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100106 elif [ "x$1" = "x--debug" ]; then
107 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800108 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100109 shift
110 elif [ "x$1" = "x--gdb" ]; then
111 USE_GDB="y"
112 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800113 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100114 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700115 elif [ "x$1" = "x--gdb-arg" ]; then
116 shift
117 gdb_arg="$1"
118 GDB_ARGS="${GDB_ARGS} $gdb_arg"
119 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100120 elif [ "x$1" = "x--zygote" ]; then
121 ZYGOTE="-Xzygote"
122 msg "Spawning from zygote"
123 shift
124 elif [ "x$1" = "x--dev" ]; then
125 DEV_MODE="y"
126 shift
127 elif [ "x$1" = "x--interpreter" ]; then
128 INTERPRETER="y"
129 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100130 elif [ "x$1" = "x--jvm" ]; then
131 USE_JVM="y"
132 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100133 elif [ "x$1" = "x--invoke-with" ]; then
134 shift
135 if [ "x$1" = "x" ]; then
136 echo "$0 missing argument to --invoke-with" 1>&2
137 exit 1
138 fi
139 if [ "x$INVOKE_WITH" = "x" ]; then
140 INVOKE_WITH="$1"
141 else
142 INVOKE_WITH="$INVOKE_WITH $1"
143 fi
144 shift
145 elif [ "x$1" = "x--no-verify" ]; then
146 VERIFY="n"
147 shift
148 elif [ "x$1" = "x--no-optimize" ]; then
149 OPTIMIZE="n"
150 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000151 elif [ "x$1" = "x--android-root" ]; then
152 shift
153 ANDROID_ROOT="$1"
154 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100155 elif [ "x$1" = "x--" ]; then
156 shift
157 break
158 elif [ "x$1" = "x--64" ]; then
159 ISA="x86_64"
160 GDB_SERVER="gdbserver64"
161 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000162 LIBRARY_DIRECTORY="lib64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100163 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
164 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700165 elif [ "x$1" = "x--pic-test" ]; then
166 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
167 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
168 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100169 elif expr "x$1" : "x--" >/dev/null 2>&1; then
170 echo "unknown $0 option: $1" 1>&2
171 exit 1
172 else
173 break
174 fi
175done
176
177if [ "x$1" = "x" ] ; then
178 MAIN="Main"
179else
180 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700181 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100182fi
183
184if [ "$ZYGOTE" = "" ]; then
185 if [ "$OPTIMIZE" = "y" ]; then
186 if [ "$VERIFY" = "y" ]; then
187 DEX_OPTIMIZE="-Xdexopt:verified"
188 else
189 DEX_OPTIMIZE="-Xdexopt:all"
190 fi
191 msg "Performing optimizations"
192 else
193 DEX_OPTIMIZE="-Xdexopt:none"
194 msg "Skipping optimizations"
195 fi
196
197 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100198 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100199 msg "Performing verification"
200 else
201 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100202 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100203 msg "Skipping verification"
204 fi
205fi
206
207msg "------------------------------"
208
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100209if [ "$DEBUGGER" = "y" ]; then
210 # Use this instead for ddms and connect by running 'ddms':
211 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
212 # TODO: add a separate --ddms option?
213
214 PORT=12345
215 msg "Waiting for jdb to connect:"
216 if [ "$HOST" = "n" ]; then
217 msg " adb forward tcp:$PORT tcp:$PORT"
218 fi
219 msg " jdb -attach localhost:$PORT"
220 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
221fi
222
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100223if [ "$USE_JVM" = "y" ]; then
224 ${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -classpath classes $MAIN "$@"
225 exit
226fi
227
228
229if [ "$HAVE_IMAGE" = "n" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000230 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000231else
232 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100233fi
234
235
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100236if [ "$USE_GDB" = "y" ]; then
237 if [ "$HOST" = "n" ]; then
238 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100239 else
240 if [ `uname` = "Darwin" ]; then
241 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700242 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100243 DALVIKVM=
244 else
245 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700246 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100247 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
248 # gdbargs="--annotate=3 $gdbargs"
249 fi
250 fi
251fi
252
253if [ "$INTERPRETER" = "y" ]; then
254 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700255 if [ "$VERIFY" = "y" ] ; then
256 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
257 else
258 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
259 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
260 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100261fi
262
263JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
264
265if [ "$RELOCATE" = "y" ]; then
266 COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information --runtime-arg -Xnorelocate"
267 FLAGS="${FLAGS} -Xrelocate -Xcompiler-option --include-patch-information"
268 if [ "$HOST" = "y" ]; then
269 # Run test sets a fairly draconian ulimit that we will likely blow right over
270 # since we are relocating. Get the total size of the /system/framework directory
271 # in 512 byte blocks and set it as the ulimit. This should be more than enough
272 # room.
273 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
274 ulimit -S $(du -c -B512 ${ANDROID_HOST_OUT}/framework | tail -1 | cut -f1) || exit 1
275 fi
276 fi
277else
278 FLAGS="$FLAGS -Xnorelocate"
279 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
280fi
281
282if [ "$HOST" = "n" ]; then
283 ISA=$(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
284 if [ x"$ISA" = "x" ]; then
285 echo "Unable to determine architecture"
286 exit 1
287 fi
288fi
289
290dex2oat_cmdline="true"
291mkdir_cmdline="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
292
293if [ "$PREBUILD" = "y" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000294 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100295 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000296 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100297 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
298 --oat-file=$DEX_LOCATION/dalvik-cache/$ISA/$(echo $DEX_LOCATION/$TEST_NAME.jar/classes.dex | cut -d/ -f 2- | sed "s:/:@:g") \
299 --instruction-set=$ISA"
300fi
301
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000302dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100303 $GDB_ARGS \
304 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700305 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100306 -XXlib:$LIB \
307 $PATCHOAT \
308 $DEX2OAT \
309 $ZYGOTE \
310 $JNI_OPTS \
311 $INT_OPTS \
312 $DEBUGGER_OPTS \
313 $DALVIKVM_BOOT_OPT \
Jeff Hao207a37d2014-10-29 17:24:25 -0700314 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100315
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -0800316# Remove whitespace.
317dex2oat_cmdline=$(echo $dex2oat_cmdline)
318dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100319
320if [ "$HOST" = "n" ]; then
321 adb root > /dev/null
322 adb wait-for-device
323 if [ "$QUIET" = "n" ]; then
324 adb shell rm -r $DEX_LOCATION
325 adb shell mkdir -p $DEX_LOCATION
326 adb push $TEST_NAME.jar $DEX_LOCATION
327 adb push $TEST_NAME-ex.jar $DEX_LOCATION
328 else
329 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
330 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
331 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
332 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
333 fi
334
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000335 LD_LIBRARY_PATH=
336 if [ "$ANDROID_ROOT" != "/system" ]; then
337 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
338 # so we can only use LD_LIBRARY_PATH when testing on a local
339 # installation.
340 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY
341 fi
342
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100343 # Create a script with the command. The command can get longer than the longest
344 # allowed adb command and there is no way to get the exit status from a adb shell
345 # command.
346 cmdline="cd $DEX_LOCATION && \
347 export ANDROID_DATA=$DEX_LOCATION && \
348 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000349 export ANDROID_ROOT=$ANDROID_ROOT && \
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000350 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100351 $mkdir_cmdline && \
352 $dex2oat_cmdline && \
353 $dalvikvm_cmdline"
354
355 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
356 echo "$cmdline" > $cmdfile
357
358 if [ "$DEV_MODE" = "y" ]; then
359 echo $cmdline
360 fi
361
362 if [ "$QUIET" = "n" ]; then
363 adb push $cmdfile $DEX_LOCATION/cmdline.sh
364 else
365 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
366 fi
367
368 adb shell sh $DEX_LOCATION/cmdline.sh
369
370 rm -f $cmdfile
371else
372 export ANDROID_PRINTF_LOG=brief
373 if [ "$DEV_MODE" = "y" ]; then
374 export ANDROID_LOG_TAGS='*:d'
Andreas Gampe65357032015-02-19 15:10:24 -0800375 elif [ "$USE_DEX2OAT_AND_PATCHOAT" = "n" ]; then
376 # All tests would log the error of failing dex2oat/patchoat. Be silent here and only
377 # log fatal events. This is the old default.
378 export ANDROID_LOG_TAGS='*:s'
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100379 else
Andreas Gampe65357032015-02-19 15:10:24 -0800380 # We are interested in LOG(ERROR) output.
Andreas Gampee4301ff2015-02-17 19:25:29 -0800381 export ANDROID_LOG_TAGS='*:e'
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100382 fi
383 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000384 export ANDROID_ROOT="${ANDROID_ROOT}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100385 export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
386 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
387 export PATH="$PATH:${ANDROID_ROOT}/bin"
388
389 cmdline="$dalvikvm_cmdline"
390
391 if [ "$TIME_OUT" = "y" ]; then
392 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -0800393 #
394 # Note: We use nested timeouts. The inner timeout sends SIGRTMIN+2 (usually 36) to ART, which
395 # will induce a full thread dump before abort. However, dumping threads might deadlock,
396 # so the outer timeout sends the regular SIGTERM after an additional minute to ensure
397 # termination (without dumping all threads).
398 TIME_PLUS_ONE=$(($TIME_OUT_VALUE + 1))
399 cmdline="timeout ${TIME_PLUS_ONE}m timeout -s SIGRTMIN+2 ${TIME_OUT_VALUE}m $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100400 fi
401
402 if [ "$DEV_MODE" = "y" ]; then
403 if [ "$PREBUILD" = "y" ]; then
404 echo "$mkdir_cmdline && $dex2oat_cmdline && $cmdline"
405 elif [ "$RELOCATE" = "y" ]; then
406 echo "$mkdir_cmdline && $cmdline"
407 else
408 echo $cmdline
409 fi
410 fi
411
412 cd $ANDROID_BUILD_TOP
413
414 $mkdir_cmdline || exit 1
415 $dex2oat_cmdline || exit 2
416
417 if [ "$USE_GDB" = "y" ]; then
418 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700419 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100420 else
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700421 $cmdline "$@" 2>&1
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100422 # Add extra detail if time out is enabled.
423 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "y" ]; then
424 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
425 fi
426 fi
427fi