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