blob: 9ecc885a623a80b4d6ba5d27f19f834968b6eb95 [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"
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"
237 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
238fi
239
240JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
241
242if [ "$RELOCATE" = "y" ]; then
243 COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information --runtime-arg -Xnorelocate"
244 FLAGS="${FLAGS} -Xrelocate -Xcompiler-option --include-patch-information"
245 if [ "$HOST" = "y" ]; then
246 # Run test sets a fairly draconian ulimit that we will likely blow right over
247 # since we are relocating. Get the total size of the /system/framework directory
248 # in 512 byte blocks and set it as the ulimit. This should be more than enough
249 # room.
250 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
251 ulimit -S $(du -c -B512 ${ANDROID_HOST_OUT}/framework | tail -1 | cut -f1) || exit 1
252 fi
253 fi
254else
255 FLAGS="$FLAGS -Xnorelocate"
256 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
257fi
258
259if [ "$HOST" = "n" ]; then
260 ISA=$(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
261 if [ x"$ISA" = "x" ]; then
262 echo "Unable to determine architecture"
263 exit 1
264 fi
265fi
266
267dex2oat_cmdline="true"
268mkdir_cmdline="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
269
270if [ "$PREBUILD" = "y" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000271 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100272 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000273 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100274 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
275 --oat-file=$DEX_LOCATION/dalvik-cache/$ISA/$(echo $DEX_LOCATION/$TEST_NAME.jar/classes.dex | cut -d/ -f 2- | sed "s:/:@:g") \
276 --instruction-set=$ISA"
277fi
278
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000279dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100280 $GDB_ARGS \
281 $FLAGS \
282 -XXlib:$LIB \
283 $PATCHOAT \
284 $DEX2OAT \
285 $ZYGOTE \
286 $JNI_OPTS \
287 $INT_OPTS \
288 $DEBUGGER_OPTS \
289 $DALVIKVM_BOOT_OPT \
290 -cp $DEX_LOCATION/$TEST_NAME.jar $MAIN"
291
292
293if [ "$HOST" = "n" ]; then
294 adb root > /dev/null
295 adb wait-for-device
296 if [ "$QUIET" = "n" ]; then
297 adb shell rm -r $DEX_LOCATION
298 adb shell mkdir -p $DEX_LOCATION
299 adb push $TEST_NAME.jar $DEX_LOCATION
300 adb push $TEST_NAME-ex.jar $DEX_LOCATION
301 else
302 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
303 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
304 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
305 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
306 fi
307
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000308 LD_LIBRARY_PATH=
309 if [ "$ANDROID_ROOT" != "/system" ]; then
310 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
311 # so we can only use LD_LIBRARY_PATH when testing on a local
312 # installation.
313 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY
314 fi
315
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100316 # Create a script with the command. The command can get longer than the longest
317 # allowed adb command and there is no way to get the exit status from a adb shell
318 # command.
319 cmdline="cd $DEX_LOCATION && \
320 export ANDROID_DATA=$DEX_LOCATION && \
321 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000322 export ANDROID_ROOT=$ANDROID_ROOT && \
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000323 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100324 $mkdir_cmdline && \
325 $dex2oat_cmdline && \
326 $dalvikvm_cmdline"
327
328 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
329 echo "$cmdline" > $cmdfile
330
331 if [ "$DEV_MODE" = "y" ]; then
332 echo $cmdline
333 fi
334
335 if [ "$QUIET" = "n" ]; then
336 adb push $cmdfile $DEX_LOCATION/cmdline.sh
337 else
338 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
339 fi
340
341 adb shell sh $DEX_LOCATION/cmdline.sh
342
343 rm -f $cmdfile
344else
345 export ANDROID_PRINTF_LOG=brief
346 if [ "$DEV_MODE" = "y" ]; then
347 export ANDROID_LOG_TAGS='*:d'
348 else
349 export ANDROID_LOG_TAGS='*:s'
350 fi
351 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000352 export ANDROID_ROOT="${ANDROID_ROOT}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100353 export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
354 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
355 export PATH="$PATH:${ANDROID_ROOT}/bin"
356
357 cmdline="$dalvikvm_cmdline"
358
359 if [ "$TIME_OUT" = "y" ]; then
360 # Add timeout command if time out is desired.
361 cmdline="timeout $TIME_OUT_VALUE $cmdline"
362 fi
363
364 if [ "$DEV_MODE" = "y" ]; then
365 if [ "$PREBUILD" = "y" ]; then
366 echo "$mkdir_cmdline && $dex2oat_cmdline && $cmdline"
367 elif [ "$RELOCATE" = "y" ]; then
368 echo "$mkdir_cmdline && $cmdline"
369 else
370 echo $cmdline
371 fi
372 fi
373
374 cd $ANDROID_BUILD_TOP
375
376 $mkdir_cmdline || exit 1
377 $dex2oat_cmdline || exit 2
378
379 if [ "$USE_GDB" = "y" ]; then
380 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700381 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100382 else
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700383 $cmdline "$@" 2>&1
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100384 # Add extra detail if time out is enabled.
385 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "y" ]; then
386 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
387 fi
388 fi
389fi