blob: af43de3410bb4457b07e2a899f436ff08e3e4d0e [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=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010039USE_GDB="n"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +010040USE_JVM="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010041VERIFY="y"
42ZYGOTE=""
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -070043DEX_VERIFY=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010044
45while true; do
46 if [ "x$1" = "x--quiet" ]; then
47 QUIET="y"
48 shift
49 elif [ "x$1" = "x--lib" ]; then
50 shift
51 if [ "x$1" = "x" ]; then
52 echo "$0 missing argument to --lib" 1>&2
53 exit 1
54 fi
55 LIB="$1"
56 shift
57 elif [ "x$1" = "x-Xcompiler-option" ]; then
58 shift
59 option="$1"
60 FLAGS="${FLAGS} -Xcompiler-option $option"
61 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
62 shift
63 elif [ "x$1" = "x--runtime-option" ]; then
64 shift
65 option="$1"
66 FLAGS="${FLAGS} $option"
67 shift
68 elif [ "x$1" = "x--boot" ]; then
69 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000070 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010071 shift
72 elif [ "x$1" = "x--no-dex2oat" ]; then
73 DEX2OAT="-Xcompiler:${FALSE_BIN}"
74 shift
75 elif [ "x$1" = "x--no-patchoat" ]; then
76 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
77 shift
78 elif [ "x$1" = "x--relocate" ]; then
79 RELOCATE="y"
80 shift
81 elif [ "x$1" = "x--no-relocate" ]; then
82 RELOCATE="n"
83 shift
84 elif [ "x$1" = "x--prebuild" ]; then
85 PREBUILD="y"
86 shift
87 elif [ "x$1" = "x--host" ]; then
88 HOST="y"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +000089 ANDROID_ROOT="$ANDROID_HOST_OUT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010090 shift
91 elif [ "x$1" = "x--no-prebuild" ]; then
92 PREBUILD="n"
93 shift
94 elif [ "x$1" = "x--no-image" ]; then
95 HAVE_IMAGE="n"
96 shift
Jeff Hao207a37d2014-10-29 17:24:25 -070097 elif [ "x$1" = "x--secondary" ]; then
98 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
99 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100100 elif [ "x$1" = "x--debug" ]; then
101 DEBUGGER="y"
102 shift
103 elif [ "x$1" = "x--gdb" ]; then
104 USE_GDB="y"
105 DEV_MODE="y"
106 shift
107 elif [ "x$1" = "x--zygote" ]; then
108 ZYGOTE="-Xzygote"
109 msg "Spawning from zygote"
110 shift
111 elif [ "x$1" = "x--dev" ]; then
112 DEV_MODE="y"
113 shift
114 elif [ "x$1" = "x--interpreter" ]; then
115 INTERPRETER="y"
116 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100117 elif [ "x$1" = "x--jvm" ]; then
118 USE_JVM="y"
119 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100120 elif [ "x$1" = "x--invoke-with" ]; then
121 shift
122 if [ "x$1" = "x" ]; then
123 echo "$0 missing argument to --invoke-with" 1>&2
124 exit 1
125 fi
126 if [ "x$INVOKE_WITH" = "x" ]; then
127 INVOKE_WITH="$1"
128 else
129 INVOKE_WITH="$INVOKE_WITH $1"
130 fi
131 shift
132 elif [ "x$1" = "x--no-verify" ]; then
133 VERIFY="n"
134 shift
135 elif [ "x$1" = "x--no-optimize" ]; then
136 OPTIMIZE="n"
137 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000138 elif [ "x$1" = "x--android-root" ]; then
139 shift
140 ANDROID_ROOT="$1"
141 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100142 elif [ "x$1" = "x--" ]; then
143 shift
144 break
145 elif [ "x$1" = "x--64" ]; then
146 ISA="x86_64"
147 GDB_SERVER="gdbserver64"
148 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000149 LIBRARY_DIRECTORY="lib64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100150 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
151 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700152 elif [ "x$1" = "x--pic-test" ]; then
153 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
154 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
155 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100156 elif expr "x$1" : "x--" >/dev/null 2>&1; then
157 echo "unknown $0 option: $1" 1>&2
158 exit 1
159 else
160 break
161 fi
162done
163
164if [ "x$1" = "x" ] ; then
165 MAIN="Main"
166else
167 MAIN="$1"
168fi
169
170if [ "$ZYGOTE" = "" ]; then
171 if [ "$OPTIMIZE" = "y" ]; then
172 if [ "$VERIFY" = "y" ]; then
173 DEX_OPTIMIZE="-Xdexopt:verified"
174 else
175 DEX_OPTIMIZE="-Xdexopt:all"
176 fi
177 msg "Performing optimizations"
178 else
179 DEX_OPTIMIZE="-Xdexopt:none"
180 msg "Skipping optimizations"
181 fi
182
183 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100184 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100185 msg "Performing verification"
186 else
187 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100188 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100189 msg "Skipping verification"
190 fi
191fi
192
193msg "------------------------------"
194
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100195if [ "$DEBUGGER" = "y" ]; then
196 # Use this instead for ddms and connect by running 'ddms':
197 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
198 # TODO: add a separate --ddms option?
199
200 PORT=12345
201 msg "Waiting for jdb to connect:"
202 if [ "$HOST" = "n" ]; then
203 msg " adb forward tcp:$PORT tcp:$PORT"
204 fi
205 msg " jdb -attach localhost:$PORT"
206 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
207fi
208
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100209if [ "$USE_JVM" = "y" ]; then
210 ${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -classpath classes $MAIN "$@"
211 exit
212fi
213
214
215if [ "$HAVE_IMAGE" = "n" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000216 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000217else
218 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100219fi
220
221
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100222if [ "$USE_GDB" = "y" ]; then
223 if [ "$HOST" = "n" ]; then
224 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100225 else
226 if [ `uname` = "Darwin" ]; then
227 GDB=lldb
228 GDB_ARGS="-- $DALVIKVM"
229 DALVIKVM=
230 else
231 GDB=gdb
232 GDB_ARGS="--args $DALVIKVM"
233 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
234 # gdbargs="--annotate=3 $gdbargs"
235 fi
236 fi
237fi
238
239if [ "$INTERPRETER" = "y" ]; then
240 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700241 if [ "$VERIFY" = "y" ] ; then
242 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
243 else
244 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
245 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
246 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100247fi
248
249JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
250
251if [ "$RELOCATE" = "y" ]; then
252 COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information --runtime-arg -Xnorelocate"
253 FLAGS="${FLAGS} -Xrelocate -Xcompiler-option --include-patch-information"
254 if [ "$HOST" = "y" ]; then
255 # Run test sets a fairly draconian ulimit that we will likely blow right over
256 # since we are relocating. Get the total size of the /system/framework directory
257 # in 512 byte blocks and set it as the ulimit. This should be more than enough
258 # room.
259 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
260 ulimit -S $(du -c -B512 ${ANDROID_HOST_OUT}/framework | tail -1 | cut -f1) || exit 1
261 fi
262 fi
263else
264 FLAGS="$FLAGS -Xnorelocate"
265 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
266fi
267
268if [ "$HOST" = "n" ]; then
269 ISA=$(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
270 if [ x"$ISA" = "x" ]; then
271 echo "Unable to determine architecture"
272 exit 1
273 fi
274fi
275
276dex2oat_cmdline="true"
277mkdir_cmdline="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
278
279if [ "$PREBUILD" = "y" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000280 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100281 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000282 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100283 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
284 --oat-file=$DEX_LOCATION/dalvik-cache/$ISA/$(echo $DEX_LOCATION/$TEST_NAME.jar/classes.dex | cut -d/ -f 2- | sed "s:/:@:g") \
285 --instruction-set=$ISA"
286fi
287
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000288dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100289 $GDB_ARGS \
290 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700291 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100292 -XXlib:$LIB \
293 $PATCHOAT \
294 $DEX2OAT \
295 $ZYGOTE \
296 $JNI_OPTS \
297 $INT_OPTS \
298 $DEBUGGER_OPTS \
299 $DALVIKVM_BOOT_OPT \
Jeff Hao207a37d2014-10-29 17:24:25 -0700300 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100301
302
303if [ "$HOST" = "n" ]; then
304 adb root > /dev/null
305 adb wait-for-device
306 if [ "$QUIET" = "n" ]; then
307 adb shell rm -r $DEX_LOCATION
308 adb shell mkdir -p $DEX_LOCATION
309 adb push $TEST_NAME.jar $DEX_LOCATION
310 adb push $TEST_NAME-ex.jar $DEX_LOCATION
311 else
312 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
313 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
314 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
315 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
316 fi
317
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000318 LD_LIBRARY_PATH=
319 if [ "$ANDROID_ROOT" != "/system" ]; then
320 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
321 # so we can only use LD_LIBRARY_PATH when testing on a local
322 # installation.
323 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY
324 fi
325
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100326 # Create a script with the command. The command can get longer than the longest
327 # allowed adb command and there is no way to get the exit status from a adb shell
328 # command.
329 cmdline="cd $DEX_LOCATION && \
330 export ANDROID_DATA=$DEX_LOCATION && \
331 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000332 export ANDROID_ROOT=$ANDROID_ROOT && \
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000333 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100334 $mkdir_cmdline && \
335 $dex2oat_cmdline && \
336 $dalvikvm_cmdline"
337
338 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
339 echo "$cmdline" > $cmdfile
340
341 if [ "$DEV_MODE" = "y" ]; then
342 echo $cmdline
343 fi
344
345 if [ "$QUIET" = "n" ]; then
346 adb push $cmdfile $DEX_LOCATION/cmdline.sh
347 else
348 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
349 fi
350
351 adb shell sh $DEX_LOCATION/cmdline.sh
352
353 rm -f $cmdfile
354else
355 export ANDROID_PRINTF_LOG=brief
356 if [ "$DEV_MODE" = "y" ]; then
357 export ANDROID_LOG_TAGS='*:d'
358 else
359 export ANDROID_LOG_TAGS='*:s'
360 fi
361 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000362 export ANDROID_ROOT="${ANDROID_ROOT}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100363 export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
364 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
365 export PATH="$PATH:${ANDROID_ROOT}/bin"
366
367 cmdline="$dalvikvm_cmdline"
368
369 if [ "$TIME_OUT" = "y" ]; then
370 # Add timeout command if time out is desired.
371 cmdline="timeout $TIME_OUT_VALUE $cmdline"
372 fi
373
374 if [ "$DEV_MODE" = "y" ]; then
375 if [ "$PREBUILD" = "y" ]; then
376 echo "$mkdir_cmdline && $dex2oat_cmdline && $cmdline"
377 elif [ "$RELOCATE" = "y" ]; then
378 echo "$mkdir_cmdline && $cmdline"
379 else
380 echo $cmdline
381 fi
382 fi
383
384 cd $ANDROID_BUILD_TOP
385
386 $mkdir_cmdline || exit 1
387 $dex2oat_cmdline || exit 2
388
389 if [ "$USE_GDB" = "y" ]; then
390 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700391 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100392 else
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700393 $cmdline "$@" 2>&1
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100394 # Add extra detail if time out is enabled.
395 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "y" ]; then
396 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
397 fi
398 fi
399fi