blob: a02fe95ef49fda644193451961be4fc345acc879 [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)"
Andreas Gampe1a5c4062015-01-15 12:10:47 -080013ARCHITECTURES_64="(arm64|x86_64|mips64|none)"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010014ARCHITECTURES_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=""
Alex Light8a0e0332015-10-26 10:11:58 -070021EXPERIMENTAL=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010022FALSE_BIN="/system/bin/false"
23FLAGS=""
24GDB=""
Nicolas Geoffraybaf91022014-10-08 09:56:45 +010025GDB_ARGS=""
26GDB_SERVER="gdbserver"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010027HAVE_IMAGE="y"
28HOST="n"
29INTERPRETER="n"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080030JIT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010031INVOKE_WITH=""
32ISA=x86
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000033LIBRARY_DIRECTORY="lib"
34MAIN=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010035OPTIMIZE="y"
36PATCHOAT=""
37PREBUILD="y"
38QUIET="n"
39RELOCATE="y"
Richard Uhler1153ae12016-04-04 13:30:16 -070040STRIP_DEX="n"
Jeff Hao207a37d2014-10-29 17:24:25 -070041SECONDARY_DEX=""
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -070042TIME_OUT="gdb" # "n" (disabled), "timeout" (use timeout), "gdb" (use gdb)
43# Value in seconds
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070044if [ "$ART_USE_READ_BARRIER" = "true" ]; then
45 TIME_OUT_VALUE=900 # 15 minutes.
46else
47 TIME_OUT_VALUE=600 # 10 minutes.
48fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010049USE_GDB="n"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +010050USE_JVM="n"
Igor Murashkin7617abd2015-07-10 18:27:47 -070051VERIFY="y" # y=yes,n=no,s=softfail
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010052ZYGOTE=""
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -070053DEX_VERIFY=""
Andreas Gampe65357032015-02-19 15:10:24 -080054USE_DEX2OAT_AND_PATCHOAT="y"
Andreas Gampe4d2ef332015-08-05 09:24:45 -070055INSTRUCTION_SET_FEATURES=""
Mathieu Chartier031768a2015-08-27 10:25:02 -070056ARGS=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010057
58while true; do
59 if [ "x$1" = "x--quiet" ]; then
60 QUIET="y"
61 shift
62 elif [ "x$1" = "x--lib" ]; then
63 shift
64 if [ "x$1" = "x" ]; then
65 echo "$0 missing argument to --lib" 1>&2
66 exit 1
67 fi
68 LIB="$1"
69 shift
Alex Light97acf192016-03-17 09:59:38 -070070 elif [ "x$1" = "x--gc-stress" ]; then
71 # Give an extra 5 mins if we are gc-stress.
72 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + 300))
73 shift
Mathieu Chartier031768a2015-08-27 10:25:02 -070074 elif [ "x$1" = "x--testlib" ]; then
75 shift
76 if [ "x$1" = "x" ]; then
77 echo "$0 missing argument to --testlib" 1>&2
78 exit 1
79 fi
Mathieu Chartierde286fd2015-09-03 18:10:29 -070080 ARGS="${ARGS} $1"
Mathieu Chartier031768a2015-08-27 10:25:02 -070081 shift
David Srbecky52886112016-01-22 13:56:47 +000082 elif [ "x$1" = "x--args" ]; then
83 shift
84 if [ "x$1" = "x" ]; then
85 echo "$0 missing argument to --args" 1>&2
86 exit 1
87 fi
88 ARGS="${ARGS} $1"
89 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010090 elif [ "x$1" = "x-Xcompiler-option" ]; then
91 shift
92 option="$1"
93 FLAGS="${FLAGS} -Xcompiler-option $option"
94 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
95 shift
96 elif [ "x$1" = "x--runtime-option" ]; then
97 shift
98 option="$1"
99 FLAGS="${FLAGS} $option"
100 shift
101 elif [ "x$1" = "x--boot" ]; then
102 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000103 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100104 shift
105 elif [ "x$1" = "x--no-dex2oat" ]; then
106 DEX2OAT="-Xcompiler:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800107 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100108 shift
109 elif [ "x$1" = "x--no-patchoat" ]; then
110 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800111 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100112 shift
113 elif [ "x$1" = "x--relocate" ]; then
114 RELOCATE="y"
115 shift
116 elif [ "x$1" = "x--no-relocate" ]; then
117 RELOCATE="n"
118 shift
119 elif [ "x$1" = "x--prebuild" ]; then
120 PREBUILD="y"
121 shift
Richard Uhler1153ae12016-04-04 13:30:16 -0700122 elif [ "x$1" = "x--strip-dex" ]; then
123 STRIP_DEX="y"
124 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100125 elif [ "x$1" = "x--host" ]; then
126 HOST="y"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000127 ANDROID_ROOT="$ANDROID_HOST_OUT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100128 shift
129 elif [ "x$1" = "x--no-prebuild" ]; then
130 PREBUILD="n"
131 shift
132 elif [ "x$1" = "x--no-image" ]; then
133 HAVE_IMAGE="n"
134 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700135 elif [ "x$1" = "x--secondary" ]; then
136 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
Calin Juravle175dc732015-08-25 15:42:32 +0100137 # Enable cfg-append to make sure we get the dump for both dex files.
138 # (otherwise the runtime compilation of the secondary dex will overwrite
139 # the dump of the first one)
140 FLAGS="${FLAGS} -Xcompiler-option --dump-cfg-append"
141 COMPILE_FLAGS="${COMPILE_FLAGS} --dump-cfg-append"
Jeff Hao207a37d2014-10-29 17:24:25 -0700142 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100143 elif [ "x$1" = "x--debug" ]; then
144 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800145 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100146 shift
147 elif [ "x$1" = "x--gdb" ]; then
148 USE_GDB="y"
149 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800150 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100151 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700152 elif [ "x$1" = "x--gdb-arg" ]; then
153 shift
154 gdb_arg="$1"
155 GDB_ARGS="${GDB_ARGS} $gdb_arg"
156 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100157 elif [ "x$1" = "x--zygote" ]; then
158 ZYGOTE="-Xzygote"
159 msg "Spawning from zygote"
160 shift
161 elif [ "x$1" = "x--dev" ]; then
162 DEV_MODE="y"
163 shift
164 elif [ "x$1" = "x--interpreter" ]; then
165 INTERPRETER="y"
166 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800167 elif [ "x$1" = "x--jit" ]; then
168 JIT="y"
169 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100170 elif [ "x$1" = "x--jvm" ]; then
171 USE_JVM="y"
172 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100173 elif [ "x$1" = "x--invoke-with" ]; then
174 shift
175 if [ "x$1" = "x" ]; then
176 echo "$0 missing argument to --invoke-with" 1>&2
177 exit 1
178 fi
179 if [ "x$INVOKE_WITH" = "x" ]; then
180 INVOKE_WITH="$1"
181 else
182 INVOKE_WITH="$INVOKE_WITH $1"
183 fi
184 shift
185 elif [ "x$1" = "x--no-verify" ]; then
186 VERIFY="n"
187 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700188 elif [ "x$1" = "x--verify-soft-fail" ]; then
189 VERIFY="s"
190 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100191 elif [ "x$1" = "x--no-optimize" ]; then
192 OPTIMIZE="n"
193 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000194 elif [ "x$1" = "x--android-root" ]; then
195 shift
196 ANDROID_ROOT="$1"
197 shift
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700198 elif [ "x$1" = "x--instruction-set-features" ]; then
199 shift
200 INSTRUCTION_SET_FEATURES="$1"
201 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100202 elif [ "x$1" = "x--" ]; then
203 shift
204 break
205 elif [ "x$1" = "x--64" ]; then
206 ISA="x86_64"
207 GDB_SERVER="gdbserver64"
208 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000209 LIBRARY_DIRECTORY="lib64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100210 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
211 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700212 elif [ "x$1" = "x--pic-test" ]; then
213 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
214 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
215 shift
Alex Light8a0e0332015-10-26 10:11:58 -0700216 elif [ "x$1" = "x--experimental" ]; then
217 if [ "$#" -lt 2 ]; then
218 echo "missing --experimental option" 1>&2
219 exit 1
220 fi
221 EXPERIMENTAL="$EXPERIMENTAL $2"
222 shift 2
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100223 elif expr "x$1" : "x--" >/dev/null 2>&1; then
224 echo "unknown $0 option: $1" 1>&2
225 exit 1
226 else
227 break
228 fi
229done
230
Alex Light8a0e0332015-10-26 10:11:58 -0700231if [ "$USE_JVM" = "n" ]; then
232 for feature in ${EXPERIMENTAL}; do
Alex Lightfa022852015-10-28 09:13:20 -0700233 FLAGS="${FLAGS} -Xexperimental:${feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:${feature}"
Alex Light8a0e0332015-10-26 10:11:58 -0700234 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xexperimental:${feature}"
235 done
236fi
237
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100238if [ "x$1" = "x" ] ; then
239 MAIN="Main"
240else
241 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700242 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100243fi
244
245if [ "$ZYGOTE" = "" ]; then
246 if [ "$OPTIMIZE" = "y" ]; then
247 if [ "$VERIFY" = "y" ]; then
248 DEX_OPTIMIZE="-Xdexopt:verified"
249 else
250 DEX_OPTIMIZE="-Xdexopt:all"
251 fi
252 msg "Performing optimizations"
253 else
254 DEX_OPTIMIZE="-Xdexopt:none"
255 msg "Skipping optimizations"
256 fi
257
258 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100259 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100260 msg "Performing verification"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700261 elif [ "$VERIFY" = "s" ]; then
262 JVM_VERIFY_ARG="Xverify:all"
263 DEX_VERIFY="-Xverify:softfail"
264 msg "Forcing verification to be soft fail"
265 else # VERIFY = "n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100266 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100267 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100268 msg "Skipping verification"
269 fi
270fi
271
272msg "------------------------------"
273
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100274if [ "$DEBUGGER" = "y" ]; then
275 # Use this instead for ddms and connect by running 'ddms':
276 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
277 # TODO: add a separate --ddms option?
278
279 PORT=12345
280 msg "Waiting for jdb to connect:"
281 if [ "$HOST" = "n" ]; then
282 msg " adb forward tcp:$PORT tcp:$PORT"
283 fi
284 msg " jdb -attach localhost:$PORT"
285 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
286fi
287
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100288if [ "$USE_JVM" = "y" ]; then
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700289 # Xmx is necessary since we don't pass down the ART flags to JVM.
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700290 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes ${FLAGS} $MAIN $@"
291 if [ "$DEV_MODE" = "y" ]; then
292 echo $cmdline
293 fi
294 $cmdline
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100295 exit
296fi
297
298
299if [ "$HAVE_IMAGE" = "n" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000300 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000301else
302 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100303fi
304
305
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100306if [ "$USE_GDB" = "y" ]; then
307 if [ "$HOST" = "n" ]; then
308 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100309 else
310 if [ `uname` = "Darwin" ]; then
311 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700312 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100313 DALVIKVM=
314 else
315 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700316 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100317 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
318 # gdbargs="--annotate=3 $gdbargs"
319 fi
320 fi
321fi
322
323if [ "$INTERPRETER" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000324 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700325 if [ "$VERIFY" = "y" ] ; then
326 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700327 elif [ "$VERIFY" = "s" ]; then
328 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
329 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
330 else # VERIFY = "n"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700331 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
332 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
333 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100334fi
335
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800336if [ "$JIT" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000337 INT_OPTS="-Xusejit:true"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800338 if [ "$VERIFY" = "y" ] ; then
Mathieu Chartiere86deef2015-03-19 13:43:37 -0700339 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
Nicolas Geoffrayc6b1b932016-03-22 09:52:40 +0000340 if [ "$PREBUILD" = "n" ]; then
341 # Make sure that if we have noprebuild we still JIT as DexClassLoader will
342 # try to compile the dex file.
343 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-at-runtime"
344 fi
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800345 else
346 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
347 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
Nicolas Geoffrayc6b1b932016-03-22 09:52:40 +0000348 if [ "$PREBUILD" = "n" ]; then
349 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-none"
350 fi
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800351 fi
352fi
353
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100354JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
355
356if [ "$RELOCATE" = "y" ]; then
357 COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information --runtime-arg -Xnorelocate"
358 FLAGS="${FLAGS} -Xrelocate -Xcompiler-option --include-patch-information"
359 if [ "$HOST" = "y" ]; then
360 # Run test sets a fairly draconian ulimit that we will likely blow right over
361 # since we are relocating. Get the total size of the /system/framework directory
362 # in 512 byte blocks and set it as the ulimit. This should be more than enough
363 # room.
364 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
Alex Lightd26b7e42016-04-08 09:44:54 -0700365 ulimit -S $(du -c -B512 ${ANDROID_HOST_OUT}/framework 2>/dev/null | tail -1 | cut -f1) || exit 1
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100366 fi
367 fi
368else
369 FLAGS="$FLAGS -Xnorelocate"
370 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
Mathieu Chartiercae2ed92015-06-09 13:02:50 -0700371 if [ "$HOST" = "y" ]; then
372 # Increase ulimit to 64MB in case we are running hprof test.
373 ulimit -S 64000 || exit 1
374 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100375fi
376
377if [ "$HOST" = "n" ]; then
378 ISA=$(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
379 if [ x"$ISA" = "x" ]; then
380 echo "Unable to determine architecture"
381 exit 1
382 fi
383fi
384
385dex2oat_cmdline="true"
386mkdir_cmdline="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
Richard Uhler1153ae12016-04-04 13:30:16 -0700387strip_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100388
Mathieu Chartier92ec5942016-04-11 12:03:48 -0700389# Pick a base that will force the app image to get relocated.
390app_image="--base=0x4000 --app-image-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.art"
Jeff Haodcdc85b2015-12-04 14:06:18 -0800391
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100392if [ "$PREBUILD" = "y" ]; then
Andreas Gampe14759242016-03-23 10:54:21 -0700393 mkdir_cmdline="${mkdir_cmdline} && mkdir -p ${DEX_LOCATION}/oat/$ISA"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000394 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100395 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000396 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100397 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
Andreas Gampe14759242016-03-23 10:54:21 -0700398 --oat-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.odex \
Jeff Haodcdc85b2015-12-04 14:06:18 -0800399 ${app_image} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100400 --instruction-set=$ISA"
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700401 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
402 dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
403 fi
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700404
405 # Add in a timeout. This is important for testing the compilation/verification time of
406 # pathological cases.
407 # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
408 # now. We should try to improve this.
409 # The current value is rather arbitrary. run-tests should compile quickly.
410 if [ "$HOST" != "n" ]; then
411 # Use SIGRTMIN+2 to try to dump threads.
412 # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
413 dex2oat_cmdline="timeout -k 1m -s SIGRTMIN+2 1m ${dex2oat_cmdline}"
414 fi
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700415fi
416
Richard Uhler1153ae12016-04-04 13:30:16 -0700417if [ "$STRIP_DEX" = "y" ]; then
418 strip_cmdline="zip --quiet --delete $DEX_LOCATION/$TEST_NAME.jar classes.dex"
419fi
420
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700421DALVIKVM_ISA_FEATURES_ARGS=""
422if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
423 DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100424fi
425
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000426# java.io.tmpdir can only be set at launch time.
427TMP_DIR_OPTION=""
428if [ "$HOST" = "n" ]; then
429 TMP_DIR_OPTION="-Djava.io.tmpdir=/data/local/tmp"
430fi
431
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000432# We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
433# b/27185632
434# b/24664297
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000435dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100436 $GDB_ARGS \
437 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700438 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100439 -XXlib:$LIB \
440 $PATCHOAT \
441 $DEX2OAT \
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700442 $DALVIKVM_ISA_FEATURES_ARGS \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100443 $ZYGOTE \
444 $JNI_OPTS \
445 $INT_OPTS \
446 $DEBUGGER_OPTS \
447 $DALVIKVM_BOOT_OPT \
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000448 $TMP_DIR_OPTION \
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000449 -XX:DumpNativeStackOnSigQuit:false \
Mathieu Chartier031768a2015-08-27 10:25:02 -0700450 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100451
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -0800452# Remove whitespace.
453dex2oat_cmdline=$(echo $dex2oat_cmdline)
454dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100455
456if [ "$HOST" = "n" ]; then
457 adb root > /dev/null
458 adb wait-for-device
459 if [ "$QUIET" = "n" ]; then
460 adb shell rm -r $DEX_LOCATION
461 adb shell mkdir -p $DEX_LOCATION
462 adb push $TEST_NAME.jar $DEX_LOCATION
463 adb push $TEST_NAME-ex.jar $DEX_LOCATION
464 else
465 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
466 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
467 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
468 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
469 fi
470
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000471 LD_LIBRARY_PATH=
472 if [ "$ANDROID_ROOT" != "/system" ]; then
473 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
474 # so we can only use LD_LIBRARY_PATH when testing on a local
475 # installation.
476 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY
477 fi
478
Dimitry Ivanov1c951922016-05-05 17:24:28 -0700479 PUBLIC_LIBS=libart.so:libartd.so
480
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100481 # Create a script with the command. The command can get longer than the longest
482 # allowed adb command and there is no way to get the exit status from a adb shell
483 # command.
484 cmdline="cd $DEX_LOCATION && \
485 export ANDROID_DATA=$DEX_LOCATION && \
Dimitry Ivanov1c951922016-05-05 17:24:28 -0700486 export ANDROID_ADDITIONAL_PUBLIC_LIBRARIES=$PUBLIC_LIBS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100487 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000488 export ANDROID_ROOT=$ANDROID_ROOT && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100489 $mkdir_cmdline && \
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100490 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray4f7fdd22015-04-24 11:57:37 +0100491 export PATH=$ANDROID_ROOT/bin:$PATH && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100492 $dex2oat_cmdline && \
Richard Uhler1153ae12016-04-04 13:30:16 -0700493 $strip_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100494 $dalvikvm_cmdline"
495
496 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
497 echo "$cmdline" > $cmdfile
498
499 if [ "$DEV_MODE" = "y" ]; then
500 echo $cmdline
501 fi
502
503 if [ "$QUIET" = "n" ]; then
504 adb push $cmdfile $DEX_LOCATION/cmdline.sh
505 else
506 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
507 fi
508
509 adb shell sh $DEX_LOCATION/cmdline.sh
510
511 rm -f $cmdfile
512else
513 export ANDROID_PRINTF_LOG=brief
Andreas Gampea8780822015-03-13 19:51:09 -0700514
515 # By default, and for prebuild dex2oat, we are interested in errors being logged. In dev mode
516 # we want debug messages.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100517 if [ "$DEV_MODE" = "y" ]; then
518 export ANDROID_LOG_TAGS='*:d'
519 else
Andreas Gampee4301ff2015-02-17 19:25:29 -0800520 export ANDROID_LOG_TAGS='*:e'
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100521 fi
Andreas Gampea8780822015-03-13 19:51:09 -0700522
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100523 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000524 export ANDROID_ROOT="${ANDROID_ROOT}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100525 export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
526 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
527 export PATH="$PATH:${ANDROID_ROOT}/bin"
528
David Srbeckyc9ede382015-06-20 06:03:53 +0100529 # Temporarily disable address space layout randomization (ASLR).
530 # This is needed on the host so that the linker loads core.oat at the necessary address.
531 export LD_USE_LOAD_BIAS=1
532
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100533 cmdline="$dalvikvm_cmdline"
534
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700535 if [ "$TIME_OUT" = "gdb" ]; then
536 if [ `uname` = "Darwin" ]; then
537 # Fall back to timeout on Mac.
538 TIME_OUT="timeout"
Hiroshi Yamauchic823eff2015-09-01 16:21:35 -0700539 elif [ "$ISA" = "x86" ]; then
540 # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
541 TIME_OUT="timeout"
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700542 else
543 # Check if gdb is available.
544 gdb --eval-command="quit" > /dev/null 2>&1
545 if [ $? != 0 ]; then
546 # gdb isn't available. Fall back to timeout.
547 TIME_OUT="timeout"
548 fi
549 fi
550 fi
551
552 if [ "$TIME_OUT" = "timeout" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100553 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -0800554 #
555 # Note: We use nested timeouts. The inner timeout sends SIGRTMIN+2 (usually 36) to ART, which
556 # will induce a full thread dump before abort. However, dumping threads might deadlock,
557 # so the outer timeout sends the regular SIGTERM after an additional minute to ensure
558 # termination (without dumping all threads).
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700559 TIME_PLUS_ONE=$(($TIME_OUT_VALUE + 60))
560 cmdline="timeout ${TIME_PLUS_ONE}s timeout -s SIGRTMIN+2 ${TIME_OUT_VALUE}s $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100561 fi
562
563 if [ "$DEV_MODE" = "y" ]; then
Richard Uhler1153ae12016-04-04 13:30:16 -0700564 echo "$mkdir_cmdline && $dex2oat_cmdline && $strip_cmdline && $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100565 fi
566
567 cd $ANDROID_BUILD_TOP
568
David Srbecky2e4afe82016-01-27 18:42:06 +0000569 rm -rf ${DEX_LOCATION}/dalvik-cache/
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100570 $mkdir_cmdline || exit 1
Andreas Gampea8780822015-03-13 19:51:09 -0700571 $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Richard Uhler1153ae12016-04-04 13:30:16 -0700572 $strip_cmdline || { echo "Strip failed." >&2 ; exit 3; }
Andreas Gampea8780822015-03-13 19:51:09 -0700573
574 # For running, we must turn off logging when dex2oat or patchoat are missing. Otherwise we use
575 # the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
576 if [ "$DEV_MODE" = "y" ]; then
577 export ANDROID_LOG_TAGS='*:d'
578 elif [ "$USE_DEX2OAT_AND_PATCHOAT" = "n" ]; then
579 # All tests would log the error of failing dex2oat/patchoat. Be silent here and only
580 # log fatal events.
581 export ANDROID_LOG_TAGS='*:s'
582 else
583 # We are interested in LOG(ERROR) output.
584 export ANDROID_LOG_TAGS='*:e'
585 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100586
587 if [ "$USE_GDB" = "y" ]; then
588 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700589 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100590 else
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700591 if [ "$TIME_OUT" != "gdb" ]; then
592 trap 'kill -INT -$pid' INT
593 $cmdline "$@" 2>&1 & pid=$!
594 wait $pid
595 # Add extra detail if time out is enabled.
596 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
597 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
598 fi
599 else
600 # With a thread dump that uses gdb if a timeout.
601 trap 'kill -INT -$pid' INT
602 $cmdline "$@" 2>&1 & pid=$!
603 # Spawn a watcher process.
604 ( sleep $TIME_OUT_VALUE && \
605 echo "##### Thread dump using gdb on test timeout" && \
606 ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
607 --eval-command="call exit(124)" --eval-command=quit || \
608 kill $pid )) 2> /dev/null & watcher=$!
609 wait $pid
610 test_exit_status=$?
611 pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
612 if [ $test_exit_status = 0 ]; then
613 # The test finished normally.
614 exit 0
615 else
616 # The test failed or timed out.
617 if [ $test_exit_status = 124 ]; then
618 # The test timed out.
619 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
620 fi
621 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100622 fi
623 fi
624fi