blob: bf790065f341194e1c5a69a496e447f1ca405a8c [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"
38USE_GDB="n"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +010039USE_JVM="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010040VERIFY="y"
41ZYGOTE=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010042
43while true; do
44 if [ "x$1" = "x--quiet" ]; then
45 QUIET="y"
46 shift
47 elif [ "x$1" = "x--lib" ]; then
48 shift
49 if [ "x$1" = "x" ]; then
50 echo "$0 missing argument to --lib" 1>&2
51 exit 1
52 fi
53 LIB="$1"
54 shift
55 elif [ "x$1" = "x-Xcompiler-option" ]; then
56 shift
57 option="$1"
58 FLAGS="${FLAGS} -Xcompiler-option $option"
59 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
60 shift
61 elif [ "x$1" = "x--runtime-option" ]; then
62 shift
63 option="$1"
64 FLAGS="${FLAGS} $option"
65 shift
66 elif [ "x$1" = "x--boot" ]; then
67 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000068 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010069 shift
70 elif [ "x$1" = "x--no-dex2oat" ]; then
71 DEX2OAT="-Xcompiler:${FALSE_BIN}"
72 shift
73 elif [ "x$1" = "x--no-patchoat" ]; then
74 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
75 shift
76 elif [ "x$1" = "x--relocate" ]; then
77 RELOCATE="y"
78 shift
79 elif [ "x$1" = "x--no-relocate" ]; then
80 RELOCATE="n"
81 shift
82 elif [ "x$1" = "x--prebuild" ]; then
83 PREBUILD="y"
84 shift
85 elif [ "x$1" = "x--host" ]; then
86 HOST="y"
87 shift
88 elif [ "x$1" = "x--no-prebuild" ]; then
89 PREBUILD="n"
90 shift
91 elif [ "x$1" = "x--no-image" ]; then
92 HAVE_IMAGE="n"
93 shift
94 elif [ "x$1" = "x--debug" ]; then
95 DEBUGGER="y"
96 shift
97 elif [ "x$1" = "x--gdb" ]; then
98 USE_GDB="y"
99 DEV_MODE="y"
100 shift
101 elif [ "x$1" = "x--zygote" ]; then
102 ZYGOTE="-Xzygote"
103 msg "Spawning from zygote"
104 shift
105 elif [ "x$1" = "x--dev" ]; then
106 DEV_MODE="y"
107 shift
108 elif [ "x$1" = "x--interpreter" ]; then
109 INTERPRETER="y"
110 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100111 elif [ "x$1" = "x--jvm" ]; then
112 USE_JVM="y"
113 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100114 elif [ "x$1" = "x--invoke-with" ]; then
115 shift
116 if [ "x$1" = "x" ]; then
117 echo "$0 missing argument to --invoke-with" 1>&2
118 exit 1
119 fi
120 if [ "x$INVOKE_WITH" = "x" ]; then
121 INVOKE_WITH="$1"
122 else
123 INVOKE_WITH="$INVOKE_WITH $1"
124 fi
125 shift
126 elif [ "x$1" = "x--no-verify" ]; then
127 VERIFY="n"
128 shift
129 elif [ "x$1" = "x--no-optimize" ]; then
130 OPTIMIZE="n"
131 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000132 elif [ "x$1" = "x--android-root" ]; then
133 shift
134 ANDROID_ROOT="$1"
135 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100136 elif [ "x$1" = "x--" ]; then
137 shift
138 break
139 elif [ "x$1" = "x--64" ]; then
140 ISA="x86_64"
141 GDB_SERVER="gdbserver64"
142 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000143 LIBRARY_DIRECTORY="lib64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100144 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
145 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700146 elif [ "x$1" = "x--pic-test" ]; then
147 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
148 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
149 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100150 elif expr "x$1" : "x--" >/dev/null 2>&1; then
151 echo "unknown $0 option: $1" 1>&2
152 exit 1
153 else
154 break
155 fi
156done
157
158if [ "x$1" = "x" ] ; then
159 MAIN="Main"
160else
161 MAIN="$1"
162fi
163
164if [ "$ZYGOTE" = "" ]; then
165 if [ "$OPTIMIZE" = "y" ]; then
166 if [ "$VERIFY" = "y" ]; then
167 DEX_OPTIMIZE="-Xdexopt:verified"
168 else
169 DEX_OPTIMIZE="-Xdexopt:all"
170 fi
171 msg "Performing optimizations"
172 else
173 DEX_OPTIMIZE="-Xdexopt:none"
174 msg "Skipping optimizations"
175 fi
176
177 if [ "$VERIFY" = "y" ]; then
178 DEX_VERIFY=""
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100179 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100180 msg "Performing verification"
181 else
182 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100183 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100184 msg "Skipping verification"
185 fi
186fi
187
188msg "------------------------------"
189
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100190if [ "$DEBUGGER" = "y" ]; then
191 # Use this instead for ddms and connect by running 'ddms':
192 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
193 # TODO: add a separate --ddms option?
194
195 PORT=12345
196 msg "Waiting for jdb to connect:"
197 if [ "$HOST" = "n" ]; then
198 msg " adb forward tcp:$PORT tcp:$PORT"
199 fi
200 msg " jdb -attach localhost:$PORT"
201 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
202fi
203
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100204if [ "$USE_JVM" = "y" ]; then
205 ${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -classpath classes $MAIN "$@"
206 exit
207fi
208
209
210if [ "$HAVE_IMAGE" = "n" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000211 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
212 DEX2OAT_BOOT_OPT="--boot-image=/system/non-existant/core.art"
213else
214 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
215 DEX2OAT_BOOT_OPT="--boot-image=${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100216fi
217
218
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100219if [ "$USE_GDB" = "y" ]; then
220 if [ "$HOST" = "n" ]; then
221 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100222 else
223 if [ `uname` = "Darwin" ]; then
224 GDB=lldb
225 GDB_ARGS="-- $DALVIKVM"
226 DALVIKVM=
227 else
228 GDB=gdb
229 GDB_ARGS="--args $DALVIKVM"
230 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
231 # gdbargs="--annotate=3 $gdbargs"
232 fi
233 fi
234fi
235
236if [ "$INTERPRETER" = "y" ]; then
237 INT_OPTS="-Xint"
238 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
239fi
240
241JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
242
243if [ "$RELOCATE" = "y" ]; then
244 COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information --runtime-arg -Xnorelocate"
245 FLAGS="${FLAGS} -Xrelocate -Xcompiler-option --include-patch-information"
246 if [ "$HOST" = "y" ]; then
247 # Run test sets a fairly draconian ulimit that we will likely blow right over
248 # since we are relocating. Get the total size of the /system/framework directory
249 # in 512 byte blocks and set it as the ulimit. This should be more than enough
250 # room.
251 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
252 ulimit -S $(du -c -B512 ${ANDROID_HOST_OUT}/framework | tail -1 | cut -f1) || exit 1
253 fi
254 fi
255else
256 FLAGS="$FLAGS -Xnorelocate"
257 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
258fi
259
260if [ "$HOST" = "n" ]; then
261 ISA=$(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
262 if [ x"$ISA" = "x" ]; then
263 echo "Unable to determine architecture"
264 exit 1
265 fi
266fi
267
268dex2oat_cmdline="true"
269mkdir_cmdline="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
270
271if [ "$PREBUILD" = "y" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000272 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100273 $COMPILE_FLAGS \
274 $DEX2OAT_BOOT_OPT \
275 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
276 --oat-file=$DEX_LOCATION/dalvik-cache/$ISA/$(echo $DEX_LOCATION/$TEST_NAME.jar/classes.dex | cut -d/ -f 2- | sed "s:/:@:g") \
277 --instruction-set=$ISA"
278fi
279
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000280dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100281 $GDB_ARGS \
282 $FLAGS \
283 -XXlib:$LIB \
284 $PATCHOAT \
285 $DEX2OAT \
286 $ZYGOTE \
287 $JNI_OPTS \
288 $INT_OPTS \
289 $DEBUGGER_OPTS \
290 $DALVIKVM_BOOT_OPT \
291 -cp $DEX_LOCATION/$TEST_NAME.jar $MAIN"
292
293
294if [ "$HOST" = "n" ]; then
295 adb root > /dev/null
296 adb wait-for-device
297 if [ "$QUIET" = "n" ]; then
298 adb shell rm -r $DEX_LOCATION
299 adb shell mkdir -p $DEX_LOCATION
300 adb push $TEST_NAME.jar $DEX_LOCATION
301 adb push $TEST_NAME-ex.jar $DEX_LOCATION
302 else
303 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
304 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
305 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
306 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
307 fi
308
309 # Create a script with the command. The command can get longer than the longest
310 # allowed adb command and there is no way to get the exit status from a adb shell
311 # command.
312 cmdline="cd $DEX_LOCATION && \
313 export ANDROID_DATA=$DEX_LOCATION && \
314 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000315 export ANDROID_ROOT=$ANDROID_ROOT && \
316 export LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100317 $mkdir_cmdline && \
318 $dex2oat_cmdline && \
319 $dalvikvm_cmdline"
320
321 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
322 echo "$cmdline" > $cmdfile
323
324 if [ "$DEV_MODE" = "y" ]; then
325 echo $cmdline
326 fi
327
328 if [ "$QUIET" = "n" ]; then
329 adb push $cmdfile $DEX_LOCATION/cmdline.sh
330 else
331 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
332 fi
333
334 adb shell sh $DEX_LOCATION/cmdline.sh
335
336 rm -f $cmdfile
337else
338 export ANDROID_PRINTF_LOG=brief
339 if [ "$DEV_MODE" = "y" ]; then
340 export ANDROID_LOG_TAGS='*:d'
341 else
342 export ANDROID_LOG_TAGS='*:s'
343 fi
344 export ANDROID_DATA="$DEX_LOCATION"
345 export ANDROID_ROOT="${ANDROID_HOST_OUT}"
346 export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
347 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
348 export PATH="$PATH:${ANDROID_ROOT}/bin"
349
350 cmdline="$dalvikvm_cmdline"
351
352 if [ "$TIME_OUT" = "y" ]; then
353 # Add timeout command if time out is desired.
354 cmdline="timeout $TIME_OUT_VALUE $cmdline"
355 fi
356
357 if [ "$DEV_MODE" = "y" ]; then
358 if [ "$PREBUILD" = "y" ]; then
359 echo "$mkdir_cmdline && $dex2oat_cmdline && $cmdline"
360 elif [ "$RELOCATE" = "y" ]; then
361 echo "$mkdir_cmdline && $cmdline"
362 else
363 echo $cmdline
364 fi
365 fi
366
367 cd $ANDROID_BUILD_TOP
368
369 $mkdir_cmdline || exit 1
370 $dex2oat_cmdline || exit 2
371
372 if [ "$USE_GDB" = "y" ]; then
373 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700374 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100375 else
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700376 $cmdline "$@" 2>&1
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100377 # Add extra detail if time out is enabled.
378 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "y" ]; then
379 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
380 fi
381 fi
382fi