blob: d05b57ccb80e34e153215deb0b64eb97a0f4d3a1 [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)"
13ARCHITECTURES_64="(arm64|x86_64|none)"
14ARCHITECTURES_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=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010047
48while true; do
49 if [ "x$1" = "x--quiet" ]; then
50 QUIET="y"
51 shift
52 elif [ "x$1" = "x--lib" ]; then
53 shift
54 if [ "x$1" = "x" ]; then
55 echo "$0 missing argument to --lib" 1>&2
56 exit 1
57 fi
58 LIB="$1"
59 shift
60 elif [ "x$1" = "x-Xcompiler-option" ]; then
61 shift
62 option="$1"
63 FLAGS="${FLAGS} -Xcompiler-option $option"
64 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
65 shift
66 elif [ "x$1" = "x--runtime-option" ]; then
67 shift
68 option="$1"
69 FLAGS="${FLAGS} $option"
70 shift
71 elif [ "x$1" = "x--boot" ]; then
72 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000073 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010074 shift
75 elif [ "x$1" = "x--no-dex2oat" ]; then
76 DEX2OAT="-Xcompiler:${FALSE_BIN}"
77 shift
78 elif [ "x$1" = "x--no-patchoat" ]; then
79 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
80 shift
81 elif [ "x$1" = "x--relocate" ]; then
82 RELOCATE="y"
83 shift
84 elif [ "x$1" = "x--no-relocate" ]; then
85 RELOCATE="n"
86 shift
87 elif [ "x$1" = "x--prebuild" ]; then
88 PREBUILD="y"
89 shift
90 elif [ "x$1" = "x--host" ]; then
91 HOST="y"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +000092 ANDROID_ROOT="$ANDROID_HOST_OUT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010093 shift
94 elif [ "x$1" = "x--no-prebuild" ]; then
95 PREBUILD="n"
96 shift
97 elif [ "x$1" = "x--no-image" ]; then
98 HAVE_IMAGE="n"
99 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700100 elif [ "x$1" = "x--secondary" ]; then
101 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
102 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100103 elif [ "x$1" = "x--debug" ]; then
104 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800105 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100106 shift
107 elif [ "x$1" = "x--gdb" ]; then
108 USE_GDB="y"
109 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800110 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100111 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700112 elif [ "x$1" = "x--gdb-arg" ]; then
113 shift
114 gdb_arg="$1"
115 GDB_ARGS="${GDB_ARGS} $gdb_arg"
116 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100117 elif [ "x$1" = "x--zygote" ]; then
118 ZYGOTE="-Xzygote"
119 msg "Spawning from zygote"
120 shift
121 elif [ "x$1" = "x--dev" ]; then
122 DEV_MODE="y"
123 shift
124 elif [ "x$1" = "x--interpreter" ]; then
125 INTERPRETER="y"
126 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100127 elif [ "x$1" = "x--jvm" ]; then
128 USE_JVM="y"
129 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100130 elif [ "x$1" = "x--invoke-with" ]; then
131 shift
132 if [ "x$1" = "x" ]; then
133 echo "$0 missing argument to --invoke-with" 1>&2
134 exit 1
135 fi
136 if [ "x$INVOKE_WITH" = "x" ]; then
137 INVOKE_WITH="$1"
138 else
139 INVOKE_WITH="$INVOKE_WITH $1"
140 fi
141 shift
142 elif [ "x$1" = "x--no-verify" ]; then
143 VERIFY="n"
144 shift
145 elif [ "x$1" = "x--no-optimize" ]; then
146 OPTIMIZE="n"
147 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000148 elif [ "x$1" = "x--android-root" ]; then
149 shift
150 ANDROID_ROOT="$1"
151 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100152 elif [ "x$1" = "x--" ]; then
153 shift
154 break
155 elif [ "x$1" = "x--64" ]; then
156 ISA="x86_64"
157 GDB_SERVER="gdbserver64"
158 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000159 LIBRARY_DIRECTORY="lib64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100160 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
161 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700162 elif [ "x$1" = "x--pic-test" ]; then
163 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
164 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
165 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100166 elif expr "x$1" : "x--" >/dev/null 2>&1; then
167 echo "unknown $0 option: $1" 1>&2
168 exit 1
169 else
170 break
171 fi
172done
173
174if [ "x$1" = "x" ] ; then
175 MAIN="Main"
176else
177 MAIN="$1"
178fi
179
180if [ "$ZYGOTE" = "" ]; then
181 if [ "$OPTIMIZE" = "y" ]; then
182 if [ "$VERIFY" = "y" ]; then
183 DEX_OPTIMIZE="-Xdexopt:verified"
184 else
185 DEX_OPTIMIZE="-Xdexopt:all"
186 fi
187 msg "Performing optimizations"
188 else
189 DEX_OPTIMIZE="-Xdexopt:none"
190 msg "Skipping optimizations"
191 fi
192
193 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100194 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100195 msg "Performing verification"
196 else
197 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100198 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100199 msg "Skipping verification"
200 fi
201fi
202
203msg "------------------------------"
204
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100205if [ "$DEBUGGER" = "y" ]; then
206 # Use this instead for ddms and connect by running 'ddms':
207 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
208 # TODO: add a separate --ddms option?
209
210 PORT=12345
211 msg "Waiting for jdb to connect:"
212 if [ "$HOST" = "n" ]; then
213 msg " adb forward tcp:$PORT tcp:$PORT"
214 fi
215 msg " jdb -attach localhost:$PORT"
216 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
217fi
218
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100219if [ "$USE_JVM" = "y" ]; then
220 ${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -classpath classes $MAIN "$@"
221 exit
222fi
223
224
225if [ "$HAVE_IMAGE" = "n" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000226 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000227else
228 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100229fi
230
231
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100232if [ "$USE_GDB" = "y" ]; then
233 if [ "$HOST" = "n" ]; then
234 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100235 else
236 if [ `uname` = "Darwin" ]; then
237 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700238 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100239 DALVIKVM=
240 else
241 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700242 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100243 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
244 # gdbargs="--annotate=3 $gdbargs"
245 fi
246 fi
247fi
248
249if [ "$INTERPRETER" = "y" ]; then
250 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700251 if [ "$VERIFY" = "y" ] ; then
252 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
253 else
254 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
255 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
256 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100257fi
258
259JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
260
261if [ "$RELOCATE" = "y" ]; then
262 COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information --runtime-arg -Xnorelocate"
263 FLAGS="${FLAGS} -Xrelocate -Xcompiler-option --include-patch-information"
264 if [ "$HOST" = "y" ]; then
265 # Run test sets a fairly draconian ulimit that we will likely blow right over
266 # since we are relocating. Get the total size of the /system/framework directory
267 # in 512 byte blocks and set it as the ulimit. This should be more than enough
268 # room.
269 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
270 ulimit -S $(du -c -B512 ${ANDROID_HOST_OUT}/framework | tail -1 | cut -f1) || exit 1
271 fi
272 fi
273else
274 FLAGS="$FLAGS -Xnorelocate"
275 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
276fi
277
278if [ "$HOST" = "n" ]; then
279 ISA=$(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
280 if [ x"$ISA" = "x" ]; then
281 echo "Unable to determine architecture"
282 exit 1
283 fi
284fi
285
286dex2oat_cmdline="true"
287mkdir_cmdline="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
288
289if [ "$PREBUILD" = "y" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000290 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100291 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000292 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100293 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
294 --oat-file=$DEX_LOCATION/dalvik-cache/$ISA/$(echo $DEX_LOCATION/$TEST_NAME.jar/classes.dex | cut -d/ -f 2- | sed "s:/:@:g") \
295 --instruction-set=$ISA"
296fi
297
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000298dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100299 $GDB_ARGS \
300 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700301 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100302 -XXlib:$LIB \
303 $PATCHOAT \
304 $DEX2OAT \
305 $ZYGOTE \
306 $JNI_OPTS \
307 $INT_OPTS \
308 $DEBUGGER_OPTS \
309 $DALVIKVM_BOOT_OPT \
Jeff Hao207a37d2014-10-29 17:24:25 -0700310 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100311
312
313if [ "$HOST" = "n" ]; then
314 adb root > /dev/null
315 adb wait-for-device
316 if [ "$QUIET" = "n" ]; then
317 adb shell rm -r $DEX_LOCATION
318 adb shell mkdir -p $DEX_LOCATION
319 adb push $TEST_NAME.jar $DEX_LOCATION
320 adb push $TEST_NAME-ex.jar $DEX_LOCATION
321 else
322 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
323 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
324 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
325 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
326 fi
327
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000328 LD_LIBRARY_PATH=
329 if [ "$ANDROID_ROOT" != "/system" ]; then
330 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
331 # so we can only use LD_LIBRARY_PATH when testing on a local
332 # installation.
333 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY
334 fi
335
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100336 # Create a script with the command. The command can get longer than the longest
337 # allowed adb command and there is no way to get the exit status from a adb shell
338 # command.
339 cmdline="cd $DEX_LOCATION && \
340 export ANDROID_DATA=$DEX_LOCATION && \
341 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000342 export ANDROID_ROOT=$ANDROID_ROOT && \
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000343 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100344 $mkdir_cmdline && \
345 $dex2oat_cmdline && \
346 $dalvikvm_cmdline"
347
348 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
349 echo "$cmdline" > $cmdfile
350
351 if [ "$DEV_MODE" = "y" ]; then
352 echo $cmdline
353 fi
354
355 if [ "$QUIET" = "n" ]; then
356 adb push $cmdfile $DEX_LOCATION/cmdline.sh
357 else
358 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
359 fi
360
361 adb shell sh $DEX_LOCATION/cmdline.sh
362
363 rm -f $cmdfile
364else
365 export ANDROID_PRINTF_LOG=brief
366 if [ "$DEV_MODE" = "y" ]; then
367 export ANDROID_LOG_TAGS='*:d'
368 else
369 export ANDROID_LOG_TAGS='*:s'
370 fi
371 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000372 export ANDROID_ROOT="${ANDROID_ROOT}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100373 export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
374 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
375 export PATH="$PATH:${ANDROID_ROOT}/bin"
376
377 cmdline="$dalvikvm_cmdline"
378
379 if [ "$TIME_OUT" = "y" ]; then
380 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -0800381 #
382 # Note: We use nested timeouts. The inner timeout sends SIGRTMIN+2 (usually 36) to ART, which
383 # will induce a full thread dump before abort. However, dumping threads might deadlock,
384 # so the outer timeout sends the regular SIGTERM after an additional minute to ensure
385 # termination (without dumping all threads).
386 TIME_PLUS_ONE=$(($TIME_OUT_VALUE + 1))
387 cmdline="timeout ${TIME_PLUS_ONE}m timeout -s SIGRTMIN+2 ${TIME_OUT_VALUE}m $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100388 fi
389
390 if [ "$DEV_MODE" = "y" ]; then
391 if [ "$PREBUILD" = "y" ]; then
392 echo "$mkdir_cmdline && $dex2oat_cmdline && $cmdline"
393 elif [ "$RELOCATE" = "y" ]; then
394 echo "$mkdir_cmdline && $cmdline"
395 else
396 echo $cmdline
397 fi
398 fi
399
400 cd $ANDROID_BUILD_TOP
401
402 $mkdir_cmdline || exit 1
403 $dex2oat_cmdline || exit 2
404
405 if [ "$USE_GDB" = "y" ]; then
406 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700407 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100408 else
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700409 $cmdline "$@" 2>&1
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100410 # Add extra detail if time out is enabled.
411 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "y" ]; then
412 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
413 fi
414 fi
415fi