blob: d2cd8ab9950b891e6b83ff013bf59c6e115f657f [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
111 elif [ "x$1" = "x--zygote" ]; then
112 ZYGOTE="-Xzygote"
113 msg "Spawning from zygote"
114 shift
115 elif [ "x$1" = "x--dev" ]; then
116 DEV_MODE="y"
117 shift
118 elif [ "x$1" = "x--interpreter" ]; then
119 INTERPRETER="y"
120 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100121 elif [ "x$1" = "x--jvm" ]; then
122 USE_JVM="y"
123 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100124 elif [ "x$1" = "x--invoke-with" ]; then
125 shift
126 if [ "x$1" = "x" ]; then
127 echo "$0 missing argument to --invoke-with" 1>&2
128 exit 1
129 fi
130 if [ "x$INVOKE_WITH" = "x" ]; then
131 INVOKE_WITH="$1"
132 else
133 INVOKE_WITH="$INVOKE_WITH $1"
134 fi
135 shift
136 elif [ "x$1" = "x--no-verify" ]; then
137 VERIFY="n"
138 shift
139 elif [ "x$1" = "x--no-optimize" ]; then
140 OPTIMIZE="n"
141 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000142 elif [ "x$1" = "x--android-root" ]; then
143 shift
144 ANDROID_ROOT="$1"
145 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100146 elif [ "x$1" = "x--" ]; then
147 shift
148 break
149 elif [ "x$1" = "x--64" ]; then
150 ISA="x86_64"
151 GDB_SERVER="gdbserver64"
152 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000153 LIBRARY_DIRECTORY="lib64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100154 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
155 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700156 elif [ "x$1" = "x--pic-test" ]; then
157 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
158 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
159 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100160 elif expr "x$1" : "x--" >/dev/null 2>&1; then
161 echo "unknown $0 option: $1" 1>&2
162 exit 1
163 else
164 break
165 fi
166done
167
168if [ "x$1" = "x" ] ; then
169 MAIN="Main"
170else
171 MAIN="$1"
172fi
173
174if [ "$ZYGOTE" = "" ]; then
175 if [ "$OPTIMIZE" = "y" ]; then
176 if [ "$VERIFY" = "y" ]; then
177 DEX_OPTIMIZE="-Xdexopt:verified"
178 else
179 DEX_OPTIMIZE="-Xdexopt:all"
180 fi
181 msg "Performing optimizations"
182 else
183 DEX_OPTIMIZE="-Xdexopt:none"
184 msg "Skipping optimizations"
185 fi
186
187 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100188 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100189 msg "Performing verification"
190 else
191 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100192 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100193 msg "Skipping verification"
194 fi
195fi
196
197msg "------------------------------"
198
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100199if [ "$DEBUGGER" = "y" ]; then
200 # Use this instead for ddms and connect by running 'ddms':
201 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
202 # TODO: add a separate --ddms option?
203
204 PORT=12345
205 msg "Waiting for jdb to connect:"
206 if [ "$HOST" = "n" ]; then
207 msg " adb forward tcp:$PORT tcp:$PORT"
208 fi
209 msg " jdb -attach localhost:$PORT"
210 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
211fi
212
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100213if [ "$USE_JVM" = "y" ]; then
214 ${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -classpath classes $MAIN "$@"
215 exit
216fi
217
218
219if [ "$HAVE_IMAGE" = "n" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000220 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000221else
222 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100223fi
224
225
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100226if [ "$USE_GDB" = "y" ]; then
227 if [ "$HOST" = "n" ]; then
228 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100229 else
230 if [ `uname` = "Darwin" ]; then
231 GDB=lldb
232 GDB_ARGS="-- $DALVIKVM"
233 DALVIKVM=
234 else
235 GDB=gdb
236 GDB_ARGS="--args $DALVIKVM"
237 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
238 # gdbargs="--annotate=3 $gdbargs"
239 fi
240 fi
241fi
242
243if [ "$INTERPRETER" = "y" ]; then
244 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700245 if [ "$VERIFY" = "y" ] ; then
246 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
247 else
248 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
249 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
250 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100251fi
252
253JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
254
255if [ "$RELOCATE" = "y" ]; then
256 COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information --runtime-arg -Xnorelocate"
257 FLAGS="${FLAGS} -Xrelocate -Xcompiler-option --include-patch-information"
258 if [ "$HOST" = "y" ]; then
259 # Run test sets a fairly draconian ulimit that we will likely blow right over
260 # since we are relocating. Get the total size of the /system/framework directory
261 # in 512 byte blocks and set it as the ulimit. This should be more than enough
262 # room.
263 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
264 ulimit -S $(du -c -B512 ${ANDROID_HOST_OUT}/framework | tail -1 | cut -f1) || exit 1
265 fi
266 fi
267else
268 FLAGS="$FLAGS -Xnorelocate"
269 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
270fi
271
272if [ "$HOST" = "n" ]; then
273 ISA=$(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
274 if [ x"$ISA" = "x" ]; then
275 echo "Unable to determine architecture"
276 exit 1
277 fi
278fi
279
280dex2oat_cmdline="true"
281mkdir_cmdline="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
282
283if [ "$PREBUILD" = "y" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000284 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100285 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000286 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100287 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
288 --oat-file=$DEX_LOCATION/dalvik-cache/$ISA/$(echo $DEX_LOCATION/$TEST_NAME.jar/classes.dex | cut -d/ -f 2- | sed "s:/:@:g") \
289 --instruction-set=$ISA"
290fi
291
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000292dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100293 $GDB_ARGS \
294 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700295 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100296 -XXlib:$LIB \
297 $PATCHOAT \
298 $DEX2OAT \
299 $ZYGOTE \
300 $JNI_OPTS \
301 $INT_OPTS \
302 $DEBUGGER_OPTS \
303 $DALVIKVM_BOOT_OPT \
Jeff Hao207a37d2014-10-29 17:24:25 -0700304 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100305
306
307if [ "$HOST" = "n" ]; then
308 adb root > /dev/null
309 adb wait-for-device
310 if [ "$QUIET" = "n" ]; then
311 adb shell rm -r $DEX_LOCATION
312 adb shell mkdir -p $DEX_LOCATION
313 adb push $TEST_NAME.jar $DEX_LOCATION
314 adb push $TEST_NAME-ex.jar $DEX_LOCATION
315 else
316 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
317 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
318 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
319 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
320 fi
321
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000322 LD_LIBRARY_PATH=
323 if [ "$ANDROID_ROOT" != "/system" ]; then
324 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
325 # so we can only use LD_LIBRARY_PATH when testing on a local
326 # installation.
327 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY
328 fi
329
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100330 # Create a script with the command. The command can get longer than the longest
331 # allowed adb command and there is no way to get the exit status from a adb shell
332 # command.
333 cmdline="cd $DEX_LOCATION && \
334 export ANDROID_DATA=$DEX_LOCATION && \
335 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000336 export ANDROID_ROOT=$ANDROID_ROOT && \
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000337 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100338 $mkdir_cmdline && \
339 $dex2oat_cmdline && \
340 $dalvikvm_cmdline"
341
342 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
343 echo "$cmdline" > $cmdfile
344
345 if [ "$DEV_MODE" = "y" ]; then
346 echo $cmdline
347 fi
348
349 if [ "$QUIET" = "n" ]; then
350 adb push $cmdfile $DEX_LOCATION/cmdline.sh
351 else
352 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
353 fi
354
355 adb shell sh $DEX_LOCATION/cmdline.sh
356
357 rm -f $cmdfile
358else
359 export ANDROID_PRINTF_LOG=brief
360 if [ "$DEV_MODE" = "y" ]; then
361 export ANDROID_LOG_TAGS='*:d'
362 else
363 export ANDROID_LOG_TAGS='*:s'
364 fi
365 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000366 export ANDROID_ROOT="${ANDROID_ROOT}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100367 export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
368 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
369 export PATH="$PATH:${ANDROID_ROOT}/bin"
370
371 cmdline="$dalvikvm_cmdline"
372
373 if [ "$TIME_OUT" = "y" ]; then
374 # Add timeout command if time out is desired.
375 cmdline="timeout $TIME_OUT_VALUE $cmdline"
376 fi
377
378 if [ "$DEV_MODE" = "y" ]; then
379 if [ "$PREBUILD" = "y" ]; then
380 echo "$mkdir_cmdline && $dex2oat_cmdline && $cmdline"
381 elif [ "$RELOCATE" = "y" ]; then
382 echo "$mkdir_cmdline && $cmdline"
383 else
384 echo $cmdline
385 fi
386 fi
387
388 cd $ANDROID_BUILD_TOP
389
390 $mkdir_cmdline || exit 1
391 $dex2oat_cmdline || exit 2
392
393 if [ "$USE_GDB" = "y" ]; then
394 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700395 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100396 else
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700397 $cmdline "$@" 2>&1
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100398 # Add extra detail if time out is enabled.
399 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "y" ]; then
400 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
401 fi
402 fi
403fi