blob: 04eea4e64c24acce86db4335391eefcaf92323a7 [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=""
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"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700178 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100179fi
180
181if [ "$ZYGOTE" = "" ]; then
182 if [ "$OPTIMIZE" = "y" ]; then
183 if [ "$VERIFY" = "y" ]; then
184 DEX_OPTIMIZE="-Xdexopt:verified"
185 else
186 DEX_OPTIMIZE="-Xdexopt:all"
187 fi
188 msg "Performing optimizations"
189 else
190 DEX_OPTIMIZE="-Xdexopt:none"
191 msg "Skipping optimizations"
192 fi
193
194 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100195 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100196 msg "Performing verification"
197 else
198 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100199 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100200 msg "Skipping verification"
201 fi
202fi
203
204msg "------------------------------"
205
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100206if [ "$DEBUGGER" = "y" ]; then
207 # Use this instead for ddms and connect by running 'ddms':
208 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
209 # TODO: add a separate --ddms option?
210
211 PORT=12345
212 msg "Waiting for jdb to connect:"
213 if [ "$HOST" = "n" ]; then
214 msg " adb forward tcp:$PORT tcp:$PORT"
215 fi
216 msg " jdb -attach localhost:$PORT"
217 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
218fi
219
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100220if [ "$USE_JVM" = "y" ]; then
221 ${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -classpath classes $MAIN "$@"
222 exit
223fi
224
225
226if [ "$HAVE_IMAGE" = "n" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000227 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000228else
229 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100230fi
231
232
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100233if [ "$USE_GDB" = "y" ]; then
234 if [ "$HOST" = "n" ]; then
235 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100236 else
237 if [ `uname` = "Darwin" ]; then
238 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700239 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100240 DALVIKVM=
241 else
242 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700243 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100244 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
245 # gdbargs="--annotate=3 $gdbargs"
246 fi
247 fi
248fi
249
250if [ "$INTERPRETER" = "y" ]; then
251 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700252 if [ "$VERIFY" = "y" ] ; then
253 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
254 else
255 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
256 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
257 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100258fi
259
260JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
261
262if [ "$RELOCATE" = "y" ]; then
263 COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information --runtime-arg -Xnorelocate"
264 FLAGS="${FLAGS} -Xrelocate -Xcompiler-option --include-patch-information"
265 if [ "$HOST" = "y" ]; then
266 # Run test sets a fairly draconian ulimit that we will likely blow right over
267 # since we are relocating. Get the total size of the /system/framework directory
268 # in 512 byte blocks and set it as the ulimit. This should be more than enough
269 # room.
270 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
271 ulimit -S $(du -c -B512 ${ANDROID_HOST_OUT}/framework | tail -1 | cut -f1) || exit 1
272 fi
273 fi
274else
275 FLAGS="$FLAGS -Xnorelocate"
276 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
277fi
278
279if [ "$HOST" = "n" ]; then
280 ISA=$(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
281 if [ x"$ISA" = "x" ]; then
282 echo "Unable to determine architecture"
283 exit 1
284 fi
285fi
286
287dex2oat_cmdline="true"
288mkdir_cmdline="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
289
290if [ "$PREBUILD" = "y" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000291 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100292 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000293 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100294 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
295 --oat-file=$DEX_LOCATION/dalvik-cache/$ISA/$(echo $DEX_LOCATION/$TEST_NAME.jar/classes.dex | cut -d/ -f 2- | sed "s:/:@:g") \
296 --instruction-set=$ISA"
297fi
298
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000299dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100300 $GDB_ARGS \
301 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700302 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100303 -XXlib:$LIB \
304 $PATCHOAT \
305 $DEX2OAT \
306 $ZYGOTE \
307 $JNI_OPTS \
308 $INT_OPTS \
309 $DEBUGGER_OPTS \
310 $DALVIKVM_BOOT_OPT \
Jeff Hao207a37d2014-10-29 17:24:25 -0700311 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100312
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -0800313# Remove whitespace.
314dex2oat_cmdline=$(echo $dex2oat_cmdline)
315dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100316
317if [ "$HOST" = "n" ]; then
318 adb root > /dev/null
319 adb wait-for-device
320 if [ "$QUIET" = "n" ]; then
321 adb shell rm -r $DEX_LOCATION
322 adb shell mkdir -p $DEX_LOCATION
323 adb push $TEST_NAME.jar $DEX_LOCATION
324 adb push $TEST_NAME-ex.jar $DEX_LOCATION
325 else
326 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
327 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
328 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
329 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
330 fi
331
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000332 LD_LIBRARY_PATH=
333 if [ "$ANDROID_ROOT" != "/system" ]; then
334 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
335 # so we can only use LD_LIBRARY_PATH when testing on a local
336 # installation.
337 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY
338 fi
339
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100340 # Create a script with the command. The command can get longer than the longest
341 # allowed adb command and there is no way to get the exit status from a adb shell
342 # command.
343 cmdline="cd $DEX_LOCATION && \
344 export ANDROID_DATA=$DEX_LOCATION && \
345 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000346 export ANDROID_ROOT=$ANDROID_ROOT && \
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000347 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100348 $mkdir_cmdline && \
349 $dex2oat_cmdline && \
350 $dalvikvm_cmdline"
351
352 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
353 echo "$cmdline" > $cmdfile
354
355 if [ "$DEV_MODE" = "y" ]; then
356 echo $cmdline
357 fi
358
359 if [ "$QUIET" = "n" ]; then
360 adb push $cmdfile $DEX_LOCATION/cmdline.sh
361 else
362 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
363 fi
364
365 adb shell sh $DEX_LOCATION/cmdline.sh
366
367 rm -f $cmdfile
368else
369 export ANDROID_PRINTF_LOG=brief
370 if [ "$DEV_MODE" = "y" ]; then
371 export ANDROID_LOG_TAGS='*:d'
372 else
373 export ANDROID_LOG_TAGS='*:s'
374 fi
375 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000376 export ANDROID_ROOT="${ANDROID_ROOT}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100377 export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
378 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
379 export PATH="$PATH:${ANDROID_ROOT}/bin"
380
381 cmdline="$dalvikvm_cmdline"
382
383 if [ "$TIME_OUT" = "y" ]; then
384 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -0800385 #
386 # Note: We use nested timeouts. The inner timeout sends SIGRTMIN+2 (usually 36) to ART, which
387 # will induce a full thread dump before abort. However, dumping threads might deadlock,
388 # so the outer timeout sends the regular SIGTERM after an additional minute to ensure
389 # termination (without dumping all threads).
390 TIME_PLUS_ONE=$(($TIME_OUT_VALUE + 1))
391 cmdline="timeout ${TIME_PLUS_ONE}m timeout -s SIGRTMIN+2 ${TIME_OUT_VALUE}m $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100392 fi
393
394 if [ "$DEV_MODE" = "y" ]; then
395 if [ "$PREBUILD" = "y" ]; then
396 echo "$mkdir_cmdline && $dex2oat_cmdline && $cmdline"
397 elif [ "$RELOCATE" = "y" ]; then
398 echo "$mkdir_cmdline && $cmdline"
399 else
400 echo $cmdline
401 fi
402 fi
403
404 cd $ANDROID_BUILD_TOP
405
406 $mkdir_cmdline || exit 1
407 $dex2oat_cmdline || exit 2
408
409 if [ "$USE_GDB" = "y" ]; then
410 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700411 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100412 else
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700413 $cmdline "$@" 2>&1
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100414 # Add extra detail if time out is enabled.
415 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "y" ]; then
416 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
417 fi
418 fi
419fi