blob: f1044e86b7e38c93fdbbf5278d841ef8bb2d470a [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=""
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -070042DEX_VERIFY=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010043
44while true; do
45 if [ "x$1" = "x--quiet" ]; then
46 QUIET="y"
47 shift
48 elif [ "x$1" = "x--lib" ]; then
49 shift
50 if [ "x$1" = "x" ]; then
51 echo "$0 missing argument to --lib" 1>&2
52 exit 1
53 fi
54 LIB="$1"
55 shift
56 elif [ "x$1" = "x-Xcompiler-option" ]; then
57 shift
58 option="$1"
59 FLAGS="${FLAGS} -Xcompiler-option $option"
60 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
61 shift
62 elif [ "x$1" = "x--runtime-option" ]; then
63 shift
64 option="$1"
65 FLAGS="${FLAGS} $option"
66 shift
67 elif [ "x$1" = "x--boot" ]; then
68 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000069 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010070 shift
71 elif [ "x$1" = "x--no-dex2oat" ]; then
72 DEX2OAT="-Xcompiler:${FALSE_BIN}"
73 shift
74 elif [ "x$1" = "x--no-patchoat" ]; then
75 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
76 shift
77 elif [ "x$1" = "x--relocate" ]; then
78 RELOCATE="y"
79 shift
80 elif [ "x$1" = "x--no-relocate" ]; then
81 RELOCATE="n"
82 shift
83 elif [ "x$1" = "x--prebuild" ]; then
84 PREBUILD="y"
85 shift
86 elif [ "x$1" = "x--host" ]; then
87 HOST="y"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +000088 ANDROID_ROOT="$ANDROID_HOST_OUT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010089 shift
90 elif [ "x$1" = "x--no-prebuild" ]; then
91 PREBUILD="n"
92 shift
93 elif [ "x$1" = "x--no-image" ]; then
94 HAVE_IMAGE="n"
95 shift
96 elif [ "x$1" = "x--debug" ]; then
97 DEBUGGER="y"
98 shift
99 elif [ "x$1" = "x--gdb" ]; then
100 USE_GDB="y"
101 DEV_MODE="y"
102 shift
103 elif [ "x$1" = "x--zygote" ]; then
104 ZYGOTE="-Xzygote"
105 msg "Spawning from zygote"
106 shift
107 elif [ "x$1" = "x--dev" ]; then
108 DEV_MODE="y"
109 shift
110 elif [ "x$1" = "x--interpreter" ]; then
111 INTERPRETER="y"
112 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100113 elif [ "x$1" = "x--jvm" ]; then
114 USE_JVM="y"
115 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100116 elif [ "x$1" = "x--invoke-with" ]; then
117 shift
118 if [ "x$1" = "x" ]; then
119 echo "$0 missing argument to --invoke-with" 1>&2
120 exit 1
121 fi
122 if [ "x$INVOKE_WITH" = "x" ]; then
123 INVOKE_WITH="$1"
124 else
125 INVOKE_WITH="$INVOKE_WITH $1"
126 fi
127 shift
128 elif [ "x$1" = "x--no-verify" ]; then
129 VERIFY="n"
130 shift
131 elif [ "x$1" = "x--no-optimize" ]; then
132 OPTIMIZE="n"
133 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000134 elif [ "x$1" = "x--android-root" ]; then
135 shift
136 ANDROID_ROOT="$1"
137 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100138 elif [ "x$1" = "x--" ]; then
139 shift
140 break
141 elif [ "x$1" = "x--64" ]; then
142 ISA="x86_64"
143 GDB_SERVER="gdbserver64"
144 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000145 LIBRARY_DIRECTORY="lib64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100146 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
147 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700148 elif [ "x$1" = "x--pic-test" ]; then
149 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
150 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
151 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100152 elif expr "x$1" : "x--" >/dev/null 2>&1; then
153 echo "unknown $0 option: $1" 1>&2
154 exit 1
155 else
156 break
157 fi
158done
159
160if [ "x$1" = "x" ] ; then
161 MAIN="Main"
162else
163 MAIN="$1"
164fi
165
166if [ "$ZYGOTE" = "" ]; then
167 if [ "$OPTIMIZE" = "y" ]; then
168 if [ "$VERIFY" = "y" ]; then
169 DEX_OPTIMIZE="-Xdexopt:verified"
170 else
171 DEX_OPTIMIZE="-Xdexopt:all"
172 fi
173 msg "Performing optimizations"
174 else
175 DEX_OPTIMIZE="-Xdexopt:none"
176 msg "Skipping optimizations"
177 fi
178
179 if [ "$VERIFY" = "y" ]; then
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"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000213else
214 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100215fi
216
217
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100218if [ "$USE_GDB" = "y" ]; then
219 if [ "$HOST" = "n" ]; then
220 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100221 else
222 if [ `uname` = "Darwin" ]; then
223 GDB=lldb
224 GDB_ARGS="-- $DALVIKVM"
225 DALVIKVM=
226 else
227 GDB=gdb
228 GDB_ARGS="--args $DALVIKVM"
229 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
230 # gdbargs="--annotate=3 $gdbargs"
231 fi
232 fi
233fi
234
235if [ "$INTERPRETER" = "y" ]; then
236 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700237 if [ "$VERIFY" = "y" ] ; then
238 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
239 else
240 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
241 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
242 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100243fi
244
245JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
246
247if [ "$RELOCATE" = "y" ]; then
248 COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information --runtime-arg -Xnorelocate"
249 FLAGS="${FLAGS} -Xrelocate -Xcompiler-option --include-patch-information"
250 if [ "$HOST" = "y" ]; then
251 # Run test sets a fairly draconian ulimit that we will likely blow right over
252 # since we are relocating. Get the total size of the /system/framework directory
253 # in 512 byte blocks and set it as the ulimit. This should be more than enough
254 # room.
255 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
256 ulimit -S $(du -c -B512 ${ANDROID_HOST_OUT}/framework | tail -1 | cut -f1) || exit 1
257 fi
258 fi
259else
260 FLAGS="$FLAGS -Xnorelocate"
261 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
262fi
263
264if [ "$HOST" = "n" ]; then
265 ISA=$(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
266 if [ x"$ISA" = "x" ]; then
267 echo "Unable to determine architecture"
268 exit 1
269 fi
270fi
271
272dex2oat_cmdline="true"
273mkdir_cmdline="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
274
275if [ "$PREBUILD" = "y" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000276 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100277 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000278 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100279 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
280 --oat-file=$DEX_LOCATION/dalvik-cache/$ISA/$(echo $DEX_LOCATION/$TEST_NAME.jar/classes.dex | cut -d/ -f 2- | sed "s:/:@:g") \
281 --instruction-set=$ISA"
282fi
283
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000284dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100285 $GDB_ARGS \
286 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700287 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100288 -XXlib:$LIB \
289 $PATCHOAT \
290 $DEX2OAT \
291 $ZYGOTE \
292 $JNI_OPTS \
293 $INT_OPTS \
294 $DEBUGGER_OPTS \
295 $DALVIKVM_BOOT_OPT \
296 -cp $DEX_LOCATION/$TEST_NAME.jar $MAIN"
297
298
299if [ "$HOST" = "n" ]; then
300 adb root > /dev/null
301 adb wait-for-device
302 if [ "$QUIET" = "n" ]; then
303 adb shell rm -r $DEX_LOCATION
304 adb shell mkdir -p $DEX_LOCATION
305 adb push $TEST_NAME.jar $DEX_LOCATION
306 adb push $TEST_NAME-ex.jar $DEX_LOCATION
307 else
308 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
309 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
310 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
311 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
312 fi
313
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000314 LD_LIBRARY_PATH=
315 if [ "$ANDROID_ROOT" != "/system" ]; then
316 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
317 # so we can only use LD_LIBRARY_PATH when testing on a local
318 # installation.
319 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY
320 fi
321
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100322 # Create a script with the command. The command can get longer than the longest
323 # allowed adb command and there is no way to get the exit status from a adb shell
324 # command.
325 cmdline="cd $DEX_LOCATION && \
326 export ANDROID_DATA=$DEX_LOCATION && \
327 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000328 export ANDROID_ROOT=$ANDROID_ROOT && \
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000329 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100330 $mkdir_cmdline && \
331 $dex2oat_cmdline && \
332 $dalvikvm_cmdline"
333
334 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
335 echo "$cmdline" > $cmdfile
336
337 if [ "$DEV_MODE" = "y" ]; then
338 echo $cmdline
339 fi
340
341 if [ "$QUIET" = "n" ]; then
342 adb push $cmdfile $DEX_LOCATION/cmdline.sh
343 else
344 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
345 fi
346
347 adb shell sh $DEX_LOCATION/cmdline.sh
348
349 rm -f $cmdfile
350else
351 export ANDROID_PRINTF_LOG=brief
352 if [ "$DEV_MODE" = "y" ]; then
353 export ANDROID_LOG_TAGS='*:d'
354 else
355 export ANDROID_LOG_TAGS='*:s'
356 fi
357 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000358 export ANDROID_ROOT="${ANDROID_ROOT}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100359 export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
360 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
361 export PATH="$PATH:${ANDROID_ROOT}/bin"
362
363 cmdline="$dalvikvm_cmdline"
364
365 if [ "$TIME_OUT" = "y" ]; then
366 # Add timeout command if time out is desired.
367 cmdline="timeout $TIME_OUT_VALUE $cmdline"
368 fi
369
370 if [ "$DEV_MODE" = "y" ]; then
371 if [ "$PREBUILD" = "y" ]; then
372 echo "$mkdir_cmdline && $dex2oat_cmdline && $cmdline"
373 elif [ "$RELOCATE" = "y" ]; then
374 echo "$mkdir_cmdline && $cmdline"
375 else
376 echo $cmdline
377 fi
378 fi
379
380 cd $ANDROID_BUILD_TOP
381
382 $mkdir_cmdline || exit 1
383 $dex2oat_cmdline || exit 2
384
385 if [ "$USE_GDB" = "y" ]; then
386 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700387 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100388 else
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700389 $cmdline "$@" 2>&1
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100390 # Add extra detail if time out is enabled.
391 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "y" ]; then
392 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
393 fi
394 fi
395fi