blob: 5c0f83f70c8d83a3d26dbb8c7326adacb683cd7d [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"
40TIME_OUT_VALUE=5m
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010041USE_GDB="n"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +010042USE_JVM="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010043VERIFY="y"
44ZYGOTE=""
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -070045DEX_VERIFY=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010046
47while true; do
48 if [ "x$1" = "x--quiet" ]; then
49 QUIET="y"
50 shift
51 elif [ "x$1" = "x--lib" ]; then
52 shift
53 if [ "x$1" = "x" ]; then
54 echo "$0 missing argument to --lib" 1>&2
55 exit 1
56 fi
57 LIB="$1"
58 shift
59 elif [ "x$1" = "x-Xcompiler-option" ]; then
60 shift
61 option="$1"
62 FLAGS="${FLAGS} -Xcompiler-option $option"
63 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
64 shift
65 elif [ "x$1" = "x--runtime-option" ]; then
66 shift
67 option="$1"
68 FLAGS="${FLAGS} $option"
69 shift
70 elif [ "x$1" = "x--boot" ]; then
71 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000072 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010073 shift
74 elif [ "x$1" = "x--no-dex2oat" ]; then
75 DEX2OAT="-Xcompiler:${FALSE_BIN}"
76 shift
77 elif [ "x$1" = "x--no-patchoat" ]; then
78 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
79 shift
80 elif [ "x$1" = "x--relocate" ]; then
81 RELOCATE="y"
82 shift
83 elif [ "x$1" = "x--no-relocate" ]; then
84 RELOCATE="n"
85 shift
86 elif [ "x$1" = "x--prebuild" ]; then
87 PREBUILD="y"
88 shift
89 elif [ "x$1" = "x--host" ]; then
90 HOST="y"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +000091 ANDROID_ROOT="$ANDROID_HOST_OUT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010092 shift
93 elif [ "x$1" = "x--no-prebuild" ]; then
94 PREBUILD="n"
95 shift
96 elif [ "x$1" = "x--no-image" ]; then
97 HAVE_IMAGE="n"
98 shift
Jeff Hao207a37d2014-10-29 17:24:25 -070099 elif [ "x$1" = "x--secondary" ]; then
100 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
101 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100102 elif [ "x$1" = "x--debug" ]; then
103 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800104 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100105 shift
106 elif [ "x$1" = "x--gdb" ]; then
107 USE_GDB="y"
108 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800109 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100110 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700111 elif [ "x$1" = "x--gdb-arg" ]; then
112 shift
113 gdb_arg="$1"
114 GDB_ARGS="${GDB_ARGS} $gdb_arg"
115 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100116 elif [ "x$1" = "x--zygote" ]; then
117 ZYGOTE="-Xzygote"
118 msg "Spawning from zygote"
119 shift
120 elif [ "x$1" = "x--dev" ]; then
121 DEV_MODE="y"
122 shift
123 elif [ "x$1" = "x--interpreter" ]; then
124 INTERPRETER="y"
125 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100126 elif [ "x$1" = "x--jvm" ]; then
127 USE_JVM="y"
128 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100129 elif [ "x$1" = "x--invoke-with" ]; then
130 shift
131 if [ "x$1" = "x" ]; then
132 echo "$0 missing argument to --invoke-with" 1>&2
133 exit 1
134 fi
135 if [ "x$INVOKE_WITH" = "x" ]; then
136 INVOKE_WITH="$1"
137 else
138 INVOKE_WITH="$INVOKE_WITH $1"
139 fi
140 shift
141 elif [ "x$1" = "x--no-verify" ]; then
142 VERIFY="n"
143 shift
144 elif [ "x$1" = "x--no-optimize" ]; then
145 OPTIMIZE="n"
146 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000147 elif [ "x$1" = "x--android-root" ]; then
148 shift
149 ANDROID_ROOT="$1"
150 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100151 elif [ "x$1" = "x--" ]; then
152 shift
153 break
154 elif [ "x$1" = "x--64" ]; then
155 ISA="x86_64"
156 GDB_SERVER="gdbserver64"
157 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000158 LIBRARY_DIRECTORY="lib64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100159 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
160 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700161 elif [ "x$1" = "x--pic-test" ]; then
162 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
163 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
164 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100165 elif expr "x$1" : "x--" >/dev/null 2>&1; then
166 echo "unknown $0 option: $1" 1>&2
167 exit 1
168 else
169 break
170 fi
171done
172
173if [ "x$1" = "x" ] ; then
174 MAIN="Main"
175else
176 MAIN="$1"
177fi
178
179if [ "$ZYGOTE" = "" ]; then
180 if [ "$OPTIMIZE" = "y" ]; then
181 if [ "$VERIFY" = "y" ]; then
182 DEX_OPTIMIZE="-Xdexopt:verified"
183 else
184 DEX_OPTIMIZE="-Xdexopt:all"
185 fi
186 msg "Performing optimizations"
187 else
188 DEX_OPTIMIZE="-Xdexopt:none"
189 msg "Skipping optimizations"
190 fi
191
192 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100193 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100194 msg "Performing verification"
195 else
196 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100197 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100198 msg "Skipping verification"
199 fi
200fi
201
202msg "------------------------------"
203
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100204if [ "$DEBUGGER" = "y" ]; then
205 # Use this instead for ddms and connect by running 'ddms':
206 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
207 # TODO: add a separate --ddms option?
208
209 PORT=12345
210 msg "Waiting for jdb to connect:"
211 if [ "$HOST" = "n" ]; then
212 msg " adb forward tcp:$PORT tcp:$PORT"
213 fi
214 msg " jdb -attach localhost:$PORT"
215 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
216fi
217
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100218if [ "$USE_JVM" = "y" ]; then
219 ${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -classpath classes $MAIN "$@"
220 exit
221fi
222
223
224if [ "$HAVE_IMAGE" = "n" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000225 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000226else
227 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100228fi
229
230
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100231if [ "$USE_GDB" = "y" ]; then
232 if [ "$HOST" = "n" ]; then
233 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100234 else
235 if [ `uname` = "Darwin" ]; then
236 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700237 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100238 DALVIKVM=
239 else
240 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700241 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100242 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
243 # gdbargs="--annotate=3 $gdbargs"
244 fi
245 fi
246fi
247
248if [ "$INTERPRETER" = "y" ]; then
249 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700250 if [ "$VERIFY" = "y" ] ; then
251 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
252 else
253 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
254 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
255 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100256fi
257
258JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
259
260if [ "$RELOCATE" = "y" ]; then
261 COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information --runtime-arg -Xnorelocate"
262 FLAGS="${FLAGS} -Xrelocate -Xcompiler-option --include-patch-information"
263 if [ "$HOST" = "y" ]; then
264 # Run test sets a fairly draconian ulimit that we will likely blow right over
265 # since we are relocating. Get the total size of the /system/framework directory
266 # in 512 byte blocks and set it as the ulimit. This should be more than enough
267 # room.
268 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
269 ulimit -S $(du -c -B512 ${ANDROID_HOST_OUT}/framework | tail -1 | cut -f1) || exit 1
270 fi
271 fi
272else
273 FLAGS="$FLAGS -Xnorelocate"
274 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
275fi
276
277if [ "$HOST" = "n" ]; then
278 ISA=$(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
279 if [ x"$ISA" = "x" ]; then
280 echo "Unable to determine architecture"
281 exit 1
282 fi
283fi
284
285dex2oat_cmdline="true"
286mkdir_cmdline="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
287
288if [ "$PREBUILD" = "y" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000289 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100290 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000291 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100292 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
293 --oat-file=$DEX_LOCATION/dalvik-cache/$ISA/$(echo $DEX_LOCATION/$TEST_NAME.jar/classes.dex | cut -d/ -f 2- | sed "s:/:@:g") \
294 --instruction-set=$ISA"
295fi
296
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000297dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100298 $GDB_ARGS \
299 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700300 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100301 -XXlib:$LIB \
302 $PATCHOAT \
303 $DEX2OAT \
304 $ZYGOTE \
305 $JNI_OPTS \
306 $INT_OPTS \
307 $DEBUGGER_OPTS \
308 $DALVIKVM_BOOT_OPT \
Jeff Hao207a37d2014-10-29 17:24:25 -0700309 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100310
311
312if [ "$HOST" = "n" ]; then
313 adb root > /dev/null
314 adb wait-for-device
315 if [ "$QUIET" = "n" ]; then
316 adb shell rm -r $DEX_LOCATION
317 adb shell mkdir -p $DEX_LOCATION
318 adb push $TEST_NAME.jar $DEX_LOCATION
319 adb push $TEST_NAME-ex.jar $DEX_LOCATION
320 else
321 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
322 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
323 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
324 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
325 fi
326
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000327 LD_LIBRARY_PATH=
328 if [ "$ANDROID_ROOT" != "/system" ]; then
329 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
330 # so we can only use LD_LIBRARY_PATH when testing on a local
331 # installation.
332 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY
333 fi
334
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100335 # Create a script with the command. The command can get longer than the longest
336 # allowed adb command and there is no way to get the exit status from a adb shell
337 # command.
338 cmdline="cd $DEX_LOCATION && \
339 export ANDROID_DATA=$DEX_LOCATION && \
340 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000341 export ANDROID_ROOT=$ANDROID_ROOT && \
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000342 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100343 $mkdir_cmdline && \
344 $dex2oat_cmdline && \
345 $dalvikvm_cmdline"
346
347 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
348 echo "$cmdline" > $cmdfile
349
350 if [ "$DEV_MODE" = "y" ]; then
351 echo $cmdline
352 fi
353
354 if [ "$QUIET" = "n" ]; then
355 adb push $cmdfile $DEX_LOCATION/cmdline.sh
356 else
357 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
358 fi
359
360 adb shell sh $DEX_LOCATION/cmdline.sh
361
362 rm -f $cmdfile
363else
364 export ANDROID_PRINTF_LOG=brief
365 if [ "$DEV_MODE" = "y" ]; then
366 export ANDROID_LOG_TAGS='*:d'
367 else
368 export ANDROID_LOG_TAGS='*:s'
369 fi
370 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000371 export ANDROID_ROOT="${ANDROID_ROOT}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100372 export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
373 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
374 export PATH="$PATH:${ANDROID_ROOT}/bin"
375
376 cmdline="$dalvikvm_cmdline"
377
378 if [ "$TIME_OUT" = "y" ]; then
379 # Add timeout command if time out is desired.
380 cmdline="timeout $TIME_OUT_VALUE $cmdline"
381 fi
382
383 if [ "$DEV_MODE" = "y" ]; then
384 if [ "$PREBUILD" = "y" ]; then
385 echo "$mkdir_cmdline && $dex2oat_cmdline && $cmdline"
386 elif [ "$RELOCATE" = "y" ]; then
387 echo "$mkdir_cmdline && $cmdline"
388 else
389 echo $cmdline
390 fi
391 fi
392
393 cd $ANDROID_BUILD_TOP
394
395 $mkdir_cmdline || exit 1
396 $dex2oat_cmdline || exit 2
397
398 if [ "$USE_GDB" = "y" ]; then
399 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700400 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100401 else
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700402 $cmdline "$@" 2>&1
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100403 # Add extra detail if time out is enabled.
404 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "y" ]; then
405 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
406 fi
407 fi
408fi