blob: 9b204040f59434ea4f00ddc43925b79ea89be4bc [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=""
19GDB_SERVER="gdbserver"
20FALSE_BIN="/system/bin/false"
21FLAGS=""
22GDB=""
23HAVE_IMAGE="y"
24HOST="n"
25INTERPRETER="n"
26INVOKE_WITH=""
27ISA=x86
28OPTIMIZE="y"
29PATCHOAT=""
30PREBUILD="y"
31QUIET="n"
32RELOCATE="y"
33USE_GDB="n"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +010034USE_JVM="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010035VERIFY="y"
36ZYGOTE=""
37MAIN=""
38
39while true; do
40 if [ "x$1" = "x--quiet" ]; then
41 QUIET="y"
42 shift
43 elif [ "x$1" = "x--lib" ]; then
44 shift
45 if [ "x$1" = "x" ]; then
46 echo "$0 missing argument to --lib" 1>&2
47 exit 1
48 fi
49 LIB="$1"
50 shift
51 elif [ "x$1" = "x-Xcompiler-option" ]; then
52 shift
53 option="$1"
54 FLAGS="${FLAGS} -Xcompiler-option $option"
55 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
56 shift
57 elif [ "x$1" = "x--runtime-option" ]; then
58 shift
59 option="$1"
60 FLAGS="${FLAGS} $option"
61 shift
62 elif [ "x$1" = "x--boot" ]; then
63 shift
64 DALVIKVM_BOOT_OPT="$1"
65 DEX2OAT_BOOT_OPT="--boot-image=${1#-Ximage:}"
66 shift
67 elif [ "x$1" = "x--no-dex2oat" ]; then
68 DEX2OAT="-Xcompiler:${FALSE_BIN}"
69 shift
70 elif [ "x$1" = "x--no-patchoat" ]; then
71 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
72 shift
73 elif [ "x$1" = "x--relocate" ]; then
74 RELOCATE="y"
75 shift
76 elif [ "x$1" = "x--no-relocate" ]; then
77 RELOCATE="n"
78 shift
79 elif [ "x$1" = "x--prebuild" ]; then
80 PREBUILD="y"
81 shift
82 elif [ "x$1" = "x--host" ]; then
83 HOST="y"
84 shift
85 elif [ "x$1" = "x--no-prebuild" ]; then
86 PREBUILD="n"
87 shift
88 elif [ "x$1" = "x--no-image" ]; then
89 HAVE_IMAGE="n"
90 shift
91 elif [ "x$1" = "x--debug" ]; then
92 DEBUGGER="y"
93 shift
94 elif [ "x$1" = "x--gdb" ]; then
95 USE_GDB="y"
96 DEV_MODE="y"
97 shift
98 elif [ "x$1" = "x--zygote" ]; then
99 ZYGOTE="-Xzygote"
100 msg "Spawning from zygote"
101 shift
102 elif [ "x$1" = "x--dev" ]; then
103 DEV_MODE="y"
104 shift
105 elif [ "x$1" = "x--interpreter" ]; then
106 INTERPRETER="y"
107 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100108 elif [ "x$1" = "x--jvm" ]; then
109 USE_JVM="y"
110 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100111 elif [ "x$1" = "x--invoke-with" ]; then
112 shift
113 if [ "x$1" = "x" ]; then
114 echo "$0 missing argument to --invoke-with" 1>&2
115 exit 1
116 fi
117 if [ "x$INVOKE_WITH" = "x" ]; then
118 INVOKE_WITH="$1"
119 else
120 INVOKE_WITH="$INVOKE_WITH $1"
121 fi
122 shift
123 elif [ "x$1" = "x--no-verify" ]; then
124 VERIFY="n"
125 shift
126 elif [ "x$1" = "x--no-optimize" ]; then
127 OPTIMIZE="n"
128 shift
129 elif [ "x$1" = "x--" ]; then
130 shift
131 break
132 elif [ "x$1" = "x--64" ]; then
133 ISA="x86_64"
134 GDB_SERVER="gdbserver64"
135 DALVIKVM="dalvikvm64"
136 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
137 shift
138 elif expr "x$1" : "x--" >/dev/null 2>&1; then
139 echo "unknown $0 option: $1" 1>&2
140 exit 1
141 else
142 break
143 fi
144done
145
146if [ "x$1" = "x" ] ; then
147 MAIN="Main"
148else
149 MAIN="$1"
150fi
151
152if [ "$ZYGOTE" = "" ]; then
153 if [ "$OPTIMIZE" = "y" ]; then
154 if [ "$VERIFY" = "y" ]; then
155 DEX_OPTIMIZE="-Xdexopt:verified"
156 else
157 DEX_OPTIMIZE="-Xdexopt:all"
158 fi
159 msg "Performing optimizations"
160 else
161 DEX_OPTIMIZE="-Xdexopt:none"
162 msg "Skipping optimizations"
163 fi
164
165 if [ "$VERIFY" = "y" ]; then
166 DEX_VERIFY=""
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100167 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100168 msg "Performing verification"
169 else
170 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100171 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100172 msg "Skipping verification"
173 fi
174fi
175
176msg "------------------------------"
177
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100178if [ "$DEBUGGER" = "y" ]; then
179 # Use this instead for ddms and connect by running 'ddms':
180 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
181 # TODO: add a separate --ddms option?
182
183 PORT=12345
184 msg "Waiting for jdb to connect:"
185 if [ "$HOST" = "n" ]; then
186 msg " adb forward tcp:$PORT tcp:$PORT"
187 fi
188 msg " jdb -attach localhost:$PORT"
189 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
190fi
191
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100192if [ "$USE_JVM" = "y" ]; then
193 ${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -classpath classes $MAIN "$@"
194 exit
195fi
196
197
198if [ "$HAVE_IMAGE" = "n" ]; then
199 BOOT_OPT="-Ximage:/system/non-existant/core.art"
200fi
201
202
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100203if [ "$USE_GDB" = "y" ]; then
204 if [ "$HOST" = "n" ]; then
205 GDB="$GDB_SERVER :5039"
206 GDB_ARGS="$DALVIKVM"
207 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...
357 LD_PRELOAD=libsigchain.so $cmdline "$@"
358 else
359 # If we are execing /bin/false we might not be on the same ISA as libsigchain.so
360 # ld.so will helpfully warn us of this. Unfortunately this messes up our error
361 # checking so we will just filter out the error with a grep.
362 LD_PRELOAD=libsigchain.so $cmdline "$@" 2>&1 | grep -v -E "^ERROR: ld\.so: object '.+\.so' from LD_PRELOAD cannot be preloaded.*: ignored\.$"
363 # Add extra detail if time out is enabled.
364 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "y" ]; then
365 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
366 fi
367 fi
368fi