blob: 9b1af70733609df30c4151b8de069e49a4aec96e [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"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +000087 ANDROID_ROOT="$ANDROID_HOST_OUT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010088 shift
89 elif [ "x$1" = "x--no-prebuild" ]; then
90 PREBUILD="n"
91 shift
92 elif [ "x$1" = "x--no-image" ]; then
93 HAVE_IMAGE="n"
94 shift
95 elif [ "x$1" = "x--debug" ]; then
96 DEBUGGER="y"
97 shift
98 elif [ "x$1" = "x--gdb" ]; then
99 USE_GDB="y"
100 DEV_MODE="y"
101 shift
102 elif [ "x$1" = "x--zygote" ]; then
103 ZYGOTE="-Xzygote"
104 msg "Spawning from zygote"
105 shift
106 elif [ "x$1" = "x--dev" ]; then
107 DEV_MODE="y"
108 shift
109 elif [ "x$1" = "x--interpreter" ]; then
110 INTERPRETER="y"
111 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100112 elif [ "x$1" = "x--jvm" ]; then
113 USE_JVM="y"
114 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100115 elif [ "x$1" = "x--invoke-with" ]; then
116 shift
117 if [ "x$1" = "x" ]; then
118 echo "$0 missing argument to --invoke-with" 1>&2
119 exit 1
120 fi
121 if [ "x$INVOKE_WITH" = "x" ]; then
122 INVOKE_WITH="$1"
123 else
124 INVOKE_WITH="$INVOKE_WITH $1"
125 fi
126 shift
127 elif [ "x$1" = "x--no-verify" ]; then
128 VERIFY="n"
129 shift
130 elif [ "x$1" = "x--no-optimize" ]; then
131 OPTIMIZE="n"
132 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000133 elif [ "x$1" = "x--android-root" ]; then
134 shift
135 ANDROID_ROOT="$1"
136 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100137 elif [ "x$1" = "x--" ]; then
138 shift
139 break
140 elif [ "x$1" = "x--64" ]; then
141 ISA="x86_64"
142 GDB_SERVER="gdbserver64"
143 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000144 LIBRARY_DIRECTORY="lib64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100145 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
146 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700147 elif [ "x$1" = "x--pic-test" ]; then
148 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
149 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
150 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100151 elif expr "x$1" : "x--" >/dev/null 2>&1; then
152 echo "unknown $0 option: $1" 1>&2
153 exit 1
154 else
155 break
156 fi
157done
158
159if [ "x$1" = "x" ] ; then
160 MAIN="Main"
161else
162 MAIN="$1"
163fi
164
165if [ "$ZYGOTE" = "" ]; then
166 if [ "$OPTIMIZE" = "y" ]; then
167 if [ "$VERIFY" = "y" ]; then
168 DEX_OPTIMIZE="-Xdexopt:verified"
169 else
170 DEX_OPTIMIZE="-Xdexopt:all"
171 fi
172 msg "Performing optimizations"
173 else
174 DEX_OPTIMIZE="-Xdexopt:none"
175 msg "Skipping optimizations"
176 fi
177
178 if [ "$VERIFY" = "y" ]; then
179 DEX_VERIFY=""
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100180 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100181 msg "Performing verification"
182 else
183 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100184 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100185 msg "Skipping verification"
186 fi
187fi
188
189msg "------------------------------"
190
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100191if [ "$DEBUGGER" = "y" ]; then
192 # Use this instead for ddms and connect by running 'ddms':
193 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
194 # TODO: add a separate --ddms option?
195
196 PORT=12345
197 msg "Waiting for jdb to connect:"
198 if [ "$HOST" = "n" ]; then
199 msg " adb forward tcp:$PORT tcp:$PORT"
200 fi
201 msg " jdb -attach localhost:$PORT"
202 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
203fi
204
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100205if [ "$USE_JVM" = "y" ]; then
206 ${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -classpath classes $MAIN "$@"
207 exit
208fi
209
210
211if [ "$HAVE_IMAGE" = "n" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000212 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
213 DEX2OAT_BOOT_OPT="--boot-image=/system/non-existant/core.art"
214else
215 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
216 DEX2OAT_BOOT_OPT="--boot-image=${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100217fi
218
219
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100220if [ "$USE_GDB" = "y" ]; then
221 if [ "$HOST" = "n" ]; then
222 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100223 else
224 if [ `uname` = "Darwin" ]; then
225 GDB=lldb
226 GDB_ARGS="-- $DALVIKVM"
227 DALVIKVM=
228 else
229 GDB=gdb
230 GDB_ARGS="--args $DALVIKVM"
231 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
232 # gdbargs="--annotate=3 $gdbargs"
233 fi
234 fi
235fi
236
237if [ "$INTERPRETER" = "y" ]; then
238 INT_OPTS="-Xint"
239 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
240fi
241
242JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
243
244if [ "$RELOCATE" = "y" ]; then
245 COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information --runtime-arg -Xnorelocate"
246 FLAGS="${FLAGS} -Xrelocate -Xcompiler-option --include-patch-information"
247 if [ "$HOST" = "y" ]; then
248 # Run test sets a fairly draconian ulimit that we will likely blow right over
249 # since we are relocating. Get the total size of the /system/framework directory
250 # in 512 byte blocks and set it as the ulimit. This should be more than enough
251 # room.
252 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
253 ulimit -S $(du -c -B512 ${ANDROID_HOST_OUT}/framework | tail -1 | cut -f1) || exit 1
254 fi
255 fi
256else
257 FLAGS="$FLAGS -Xnorelocate"
258 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
259fi
260
261if [ "$HOST" = "n" ]; then
262 ISA=$(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
263 if [ x"$ISA" = "x" ]; then
264 echo "Unable to determine architecture"
265 exit 1
266 fi
267fi
268
269dex2oat_cmdline="true"
270mkdir_cmdline="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
271
272if [ "$PREBUILD" = "y" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000273 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100274 $COMPILE_FLAGS \
275 $DEX2OAT_BOOT_OPT \
276 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
277 --oat-file=$DEX_LOCATION/dalvik-cache/$ISA/$(echo $DEX_LOCATION/$TEST_NAME.jar/classes.dex | cut -d/ -f 2- | sed "s:/:@:g") \
278 --instruction-set=$ISA"
279fi
280
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000281dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100282 $GDB_ARGS \
283 $FLAGS \
284 -XXlib:$LIB \
285 $PATCHOAT \
286 $DEX2OAT \
287 $ZYGOTE \
288 $JNI_OPTS \
289 $INT_OPTS \
290 $DEBUGGER_OPTS \
291 $DALVIKVM_BOOT_OPT \
292 -cp $DEX_LOCATION/$TEST_NAME.jar $MAIN"
293
294
295if [ "$HOST" = "n" ]; then
296 adb root > /dev/null
297 adb wait-for-device
298 if [ "$QUIET" = "n" ]; then
299 adb shell rm -r $DEX_LOCATION
300 adb shell mkdir -p $DEX_LOCATION
301 adb push $TEST_NAME.jar $DEX_LOCATION
302 adb push $TEST_NAME-ex.jar $DEX_LOCATION
303 else
304 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
305 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
306 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
307 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
308 fi
309
310 # Create a script with the command. The command can get longer than the longest
311 # allowed adb command and there is no way to get the exit status from a adb shell
312 # command.
313 cmdline="cd $DEX_LOCATION && \
314 export ANDROID_DATA=$DEX_LOCATION && \
315 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000316 export ANDROID_ROOT=$ANDROID_ROOT && \
317 export LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100318 $mkdir_cmdline && \
319 $dex2oat_cmdline && \
320 $dalvikvm_cmdline"
321
322 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
323 echo "$cmdline" > $cmdfile
324
325 if [ "$DEV_MODE" = "y" ]; then
326 echo $cmdline
327 fi
328
329 if [ "$QUIET" = "n" ]; then
330 adb push $cmdfile $DEX_LOCATION/cmdline.sh
331 else
332 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
333 fi
334
335 adb shell sh $DEX_LOCATION/cmdline.sh
336
337 rm -f $cmdfile
338else
339 export ANDROID_PRINTF_LOG=brief
340 if [ "$DEV_MODE" = "y" ]; then
341 export ANDROID_LOG_TAGS='*:d'
342 else
343 export ANDROID_LOG_TAGS='*:s'
344 fi
345 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000346 export ANDROID_ROOT="${ANDROID_ROOT}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100347 export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
348 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
349 export PATH="$PATH:${ANDROID_ROOT}/bin"
350
351 cmdline="$dalvikvm_cmdline"
352
353 if [ "$TIME_OUT" = "y" ]; then
354 # Add timeout command if time out is desired.
355 cmdline="timeout $TIME_OUT_VALUE $cmdline"
356 fi
357
358 if [ "$DEV_MODE" = "y" ]; then
359 if [ "$PREBUILD" = "y" ]; then
360 echo "$mkdir_cmdline && $dex2oat_cmdline && $cmdline"
361 elif [ "$RELOCATE" = "y" ]; then
362 echo "$mkdir_cmdline && $cmdline"
363 else
364 echo $cmdline
365 fi
366 fi
367
368 cd $ANDROID_BUILD_TOP
369
370 $mkdir_cmdline || exit 1
371 $dex2oat_cmdline || exit 2
372
373 if [ "$USE_GDB" = "y" ]; then
374 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700375 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100376 else
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700377 $cmdline "$@" 2>&1
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100378 # Add extra detail if time out is enabled.
379 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "y" ]; then
380 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
381 fi
382 fi
383fi