blob: c6c9380412a0dbdc4b303a20145c2dd01445d13c [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 Uhler76f5cb62016-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
Mathieu Chartier2576be22016-05-24 10:24:53 -070045 TIME_OUT_VALUE=1800 # 30 minutes.
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070046else
Mathieu Chartier2576be22016-05-24 10:24:53 -070047 TIME_OUT_VALUE=1200 # 20 minutes.
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070048fi
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 Uhler76f5cb62016-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
Mathieu Chartier2576be22016-05-24 10:24:53 -0700202 elif [ "x$1" = "x--timeout" ]; then
203 shift
204 TIME_OUT_VALUE="$1"
205 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100206 elif [ "x$1" = "x--" ]; then
207 shift
208 break
209 elif [ "x$1" = "x--64" ]; then
210 ISA="x86_64"
211 GDB_SERVER="gdbserver64"
212 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000213 LIBRARY_DIRECTORY="lib64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100214 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
215 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700216 elif [ "x$1" = "x--pic-test" ]; then
217 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
218 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
219 shift
Alex Light8a0e0332015-10-26 10:11:58 -0700220 elif [ "x$1" = "x--experimental" ]; then
221 if [ "$#" -lt 2 ]; then
222 echo "missing --experimental option" 1>&2
223 exit 1
224 fi
225 EXPERIMENTAL="$EXPERIMENTAL $2"
226 shift 2
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100227 elif expr "x$1" : "x--" >/dev/null 2>&1; then
228 echo "unknown $0 option: $1" 1>&2
229 exit 1
230 else
231 break
232 fi
233done
234
Alex Light8a0e0332015-10-26 10:11:58 -0700235if [ "$USE_JVM" = "n" ]; then
236 for feature in ${EXPERIMENTAL}; do
Alex Lightfa022852015-10-28 09:13:20 -0700237 FLAGS="${FLAGS} -Xexperimental:${feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:${feature}"
Alex Light8a0e0332015-10-26 10:11:58 -0700238 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xexperimental:${feature}"
239 done
240fi
241
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100242if [ "x$1" = "x" ] ; then
243 MAIN="Main"
244else
245 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700246 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100247fi
248
249if [ "$ZYGOTE" = "" ]; then
250 if [ "$OPTIMIZE" = "y" ]; then
251 if [ "$VERIFY" = "y" ]; then
252 DEX_OPTIMIZE="-Xdexopt:verified"
253 else
254 DEX_OPTIMIZE="-Xdexopt:all"
255 fi
256 msg "Performing optimizations"
257 else
258 DEX_OPTIMIZE="-Xdexopt:none"
259 msg "Skipping optimizations"
260 fi
261
262 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100263 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100264 msg "Performing verification"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700265 elif [ "$VERIFY" = "s" ]; then
266 JVM_VERIFY_ARG="Xverify:all"
267 DEX_VERIFY="-Xverify:softfail"
268 msg "Forcing verification to be soft fail"
269 else # VERIFY = "n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100270 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100271 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100272 msg "Skipping verification"
273 fi
274fi
275
276msg "------------------------------"
277
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100278if [ "$DEBUGGER" = "y" ]; then
279 # Use this instead for ddms and connect by running 'ddms':
280 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
281 # TODO: add a separate --ddms option?
282
283 PORT=12345
284 msg "Waiting for jdb to connect:"
285 if [ "$HOST" = "n" ]; then
286 msg " adb forward tcp:$PORT tcp:$PORT"
287 fi
288 msg " jdb -attach localhost:$PORT"
289 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
290fi
291
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100292if [ "$USE_JVM" = "y" ]; then
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700293 # Xmx is necessary since we don't pass down the ART flags to JVM.
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700294 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes ${FLAGS} $MAIN $@"
295 if [ "$DEV_MODE" = "y" ]; then
296 echo $cmdline
297 fi
298 $cmdline
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100299 exit
300fi
301
302
303if [ "$HAVE_IMAGE" = "n" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000304 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000305else
306 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100307fi
308
309
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100310if [ "$USE_GDB" = "y" ]; then
311 if [ "$HOST" = "n" ]; then
312 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100313 else
314 if [ `uname` = "Darwin" ]; then
315 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700316 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100317 DALVIKVM=
318 else
319 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700320 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100321 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
322 # gdbargs="--annotate=3 $gdbargs"
323 fi
324 fi
325fi
326
327if [ "$INTERPRETER" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000328 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700329 if [ "$VERIFY" = "y" ] ; then
Richard Uhlerf4b34872016-04-13 11:03:46 -0700330 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=interpret-only"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700331 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700332 elif [ "$VERIFY" = "s" ]; then
Richard Uhlerf4b34872016-04-13 11:03:46 -0700333 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-at-runtime"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700334 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
335 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
336 else # VERIFY = "n"
Richard Uhlerf4b34872016-04-13 11:03:46 -0700337 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-none"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700338 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
339 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
340 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100341fi
342
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800343if [ "$JIT" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000344 INT_OPTS="-Xusejit:true"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800345 if [ "$VERIFY" = "y" ] ; then
Richard Uhlerf4b34872016-04-13 11:03:46 -0700346 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-at-runtime"
Mathieu Chartiere86deef2015-03-19 13:43:37 -0700347 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800348 else
Richard Uhlerf4b34872016-04-13 11:03:46 -0700349 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-none"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800350 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
351 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
352 fi
353fi
354
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100355JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
356
357if [ "$RELOCATE" = "y" ]; then
358 COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information --runtime-arg -Xnorelocate"
359 FLAGS="${FLAGS} -Xrelocate -Xcompiler-option --include-patch-information"
360 if [ "$HOST" = "y" ]; then
361 # Run test sets a fairly draconian ulimit that we will likely blow right over
362 # since we are relocating. Get the total size of the /system/framework directory
363 # in 512 byte blocks and set it as the ulimit. This should be more than enough
364 # room.
365 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
Alex Lightd26b7e42016-04-08 09:44:54 -0700366 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 +0100367 fi
368 fi
369else
370 FLAGS="$FLAGS -Xnorelocate"
371 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
Mathieu Chartiercae2ed92015-06-09 13:02:50 -0700372 if [ "$HOST" = "y" ]; then
373 # Increase ulimit to 64MB in case we are running hprof test.
374 ulimit -S 64000 || exit 1
375 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100376fi
377
378if [ "$HOST" = "n" ]; then
379 ISA=$(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
380 if [ x"$ISA" = "x" ]; then
381 echo "Unable to determine architecture"
382 exit 1
383 fi
384fi
385
386dex2oat_cmdline="true"
Alex Lightafb5d192016-05-24 15:57:45 -0700387mkdir_locations="${DEX_LOCATION}/dalvik-cache/$ISA"
Richard Uhler76f5cb62016-04-04 13:30:16 -0700388strip_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100389
Mathieu Chartier92ec5942016-04-11 12:03:48 -0700390# Pick a base that will force the app image to get relocated.
391app_image="--base=0x4000 --app-image-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.art"
Jeff Haodcdc85b2015-12-04 14:06:18 -0800392
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100393if [ "$PREBUILD" = "y" ]; then
Alex Lightafb5d192016-05-24 15:57:45 -0700394 mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/oat/$ISA"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000395 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100396 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000397 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100398 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
Andreas Gampe14759242016-03-23 10:54:21 -0700399 --oat-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.odex \
Jeff Haodcdc85b2015-12-04 14:06:18 -0800400 ${app_image} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100401 --instruction-set=$ISA"
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700402 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
403 dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
404 fi
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700405
406 # Add in a timeout. This is important for testing the compilation/verification time of
407 # pathological cases.
408 # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
409 # now. We should try to improve this.
410 # The current value is rather arbitrary. run-tests should compile quickly.
411 if [ "$HOST" != "n" ]; then
412 # Use SIGRTMIN+2 to try to dump threads.
413 # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
414 dex2oat_cmdline="timeout -k 1m -s SIGRTMIN+2 1m ${dex2oat_cmdline}"
415 fi
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700416fi
417
Richard Uhler76f5cb62016-04-04 13:30:16 -0700418if [ "$STRIP_DEX" = "y" ]; then
419 strip_cmdline="zip --quiet --delete $DEX_LOCATION/$TEST_NAME.jar classes.dex"
420fi
421
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700422DALVIKVM_ISA_FEATURES_ARGS=""
423if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
424 DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100425fi
426
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000427# java.io.tmpdir can only be set at launch time.
428TMP_DIR_OPTION=""
429if [ "$HOST" = "n" ]; then
430 TMP_DIR_OPTION="-Djava.io.tmpdir=/data/local/tmp"
431fi
432
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000433# We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
434# b/27185632
435# b/24664297
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000436dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100437 $GDB_ARGS \
438 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700439 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100440 -XXlib:$LIB \
441 $PATCHOAT \
442 $DEX2OAT \
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700443 $DALVIKVM_ISA_FEATURES_ARGS \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100444 $ZYGOTE \
445 $JNI_OPTS \
446 $INT_OPTS \
447 $DEBUGGER_OPTS \
448 $DALVIKVM_BOOT_OPT \
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000449 $TMP_DIR_OPTION \
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000450 -XX:DumpNativeStackOnSigQuit:false \
Mathieu Chartier031768a2015-08-27 10:25:02 -0700451 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100452
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -0800453# Remove whitespace.
454dex2oat_cmdline=$(echo $dex2oat_cmdline)
455dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100456
457if [ "$HOST" = "n" ]; then
458 adb root > /dev/null
459 adb wait-for-device
460 if [ "$QUIET" = "n" ]; then
461 adb shell rm -r $DEX_LOCATION
462 adb shell mkdir -p $DEX_LOCATION
463 adb push $TEST_NAME.jar $DEX_LOCATION
464 adb push $TEST_NAME-ex.jar $DEX_LOCATION
465 else
466 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
467 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
468 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
469 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
470 fi
471
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000472 LD_LIBRARY_PATH=
473 if [ "$ANDROID_ROOT" != "/system" ]; then
474 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
475 # so we can only use LD_LIBRARY_PATH when testing on a local
476 # installation.
477 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY
478 fi
479
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700480 PUBLIC_LIBS=libart.so:libartd.so
481
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100482 # Create a script with the command. The command can get longer than the longest
483 # allowed adb command and there is no way to get the exit status from a adb shell
484 # command.
485 cmdline="cd $DEX_LOCATION && \
486 export ANDROID_DATA=$DEX_LOCATION && \
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700487 export ANDROID_ADDITIONAL_PUBLIC_LIBRARIES=$PUBLIC_LIBS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100488 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000489 export ANDROID_ROOT=$ANDROID_ROOT && \
Alex Lightafb5d192016-05-24 15:57:45 -0700490 mkdir -p ${mkdir_locations} && \
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100491 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray4f7fdd22015-04-24 11:57:37 +0100492 export PATH=$ANDROID_ROOT/bin:$PATH && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100493 $dex2oat_cmdline && \
Richard Uhler76f5cb62016-04-04 13:30:16 -0700494 $strip_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100495 $dalvikvm_cmdline"
496
497 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
498 echo "$cmdline" > $cmdfile
499
500 if [ "$DEV_MODE" = "y" ]; then
501 echo $cmdline
502 fi
503
504 if [ "$QUIET" = "n" ]; then
505 adb push $cmdfile $DEX_LOCATION/cmdline.sh
506 else
507 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
508 fi
509
510 adb shell sh $DEX_LOCATION/cmdline.sh
511
512 rm -f $cmdfile
513else
514 export ANDROID_PRINTF_LOG=brief
Andreas Gampea8780822015-03-13 19:51:09 -0700515
516 # By default, and for prebuild dex2oat, we are interested in errors being logged. In dev mode
517 # we want debug messages.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100518 if [ "$DEV_MODE" = "y" ]; then
519 export ANDROID_LOG_TAGS='*:d'
520 else
Andreas Gampee4301ff2015-02-17 19:25:29 -0800521 export ANDROID_LOG_TAGS='*:e'
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100522 fi
Andreas Gampea8780822015-03-13 19:51:09 -0700523
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100524 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000525 export ANDROID_ROOT="${ANDROID_ROOT}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100526 export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
527 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
528 export PATH="$PATH:${ANDROID_ROOT}/bin"
529
David Srbeckyc9ede382015-06-20 06:03:53 +0100530 # Temporarily disable address space layout randomization (ASLR).
531 # This is needed on the host so that the linker loads core.oat at the necessary address.
532 export LD_USE_LOAD_BIAS=1
533
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100534 cmdline="$dalvikvm_cmdline"
535
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700536 if [ "$TIME_OUT" = "gdb" ]; then
537 if [ `uname` = "Darwin" ]; then
538 # Fall back to timeout on Mac.
539 TIME_OUT="timeout"
Hiroshi Yamauchic823eff2015-09-01 16:21:35 -0700540 elif [ "$ISA" = "x86" ]; then
541 # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
542 TIME_OUT="timeout"
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700543 else
544 # Check if gdb is available.
545 gdb --eval-command="quit" > /dev/null 2>&1
546 if [ $? != 0 ]; then
547 # gdb isn't available. Fall back to timeout.
548 TIME_OUT="timeout"
549 fi
550 fi
551 fi
552
553 if [ "$TIME_OUT" = "timeout" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100554 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -0800555 #
Andreas Gampe6fb92562016-08-01 21:53:57 -0700556 # Note: We first send SIGRTMIN+2 (usually 36) to ART, which will induce a full thread dump
557 # before abort. However, dumping threads might deadlock, so we also use the "-k"
558 # option to definitely kill the child.
559 cmdline="timeout -k 120s -s SIGRTMIN+2 ${TIME_OUT_VALUE}s $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100560 fi
561
562 if [ "$DEV_MODE" = "y" ]; then
Alex Lightafb5d192016-05-24 15:57:45 -0700563 echo "mkdir -p ${mkdir_locations} && $dex2oat_cmdline && $strip_cmdline && $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100564 fi
565
566 cd $ANDROID_BUILD_TOP
567
David Srbecky2e4afe82016-01-27 18:42:06 +0000568 rm -rf ${DEX_LOCATION}/dalvik-cache/
Alex Lightafb5d192016-05-24 15:57:45 -0700569 mkdir -p ${mkdir_locations} || exit 1
Andreas Gampea8780822015-03-13 19:51:09 -0700570 $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Richard Uhler76f5cb62016-04-04 13:30:16 -0700571 $strip_cmdline || { echo "Strip failed." >&2 ; exit 3; }
Andreas Gampea8780822015-03-13 19:51:09 -0700572
573 # For running, we must turn off logging when dex2oat or patchoat are missing. Otherwise we use
574 # the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
575 if [ "$DEV_MODE" = "y" ]; then
576 export ANDROID_LOG_TAGS='*:d'
577 elif [ "$USE_DEX2OAT_AND_PATCHOAT" = "n" ]; then
578 # All tests would log the error of failing dex2oat/patchoat. Be silent here and only
579 # log fatal events.
580 export ANDROID_LOG_TAGS='*:s'
581 else
582 # We are interested in LOG(ERROR) output.
583 export ANDROID_LOG_TAGS='*:e'
584 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100585
586 if [ "$USE_GDB" = "y" ]; then
587 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700588 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100589 else
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700590 if [ "$TIME_OUT" != "gdb" ]; then
591 trap 'kill -INT -$pid' INT
592 $cmdline "$@" 2>&1 & pid=$!
593 wait $pid
594 # Add extra detail if time out is enabled.
595 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
596 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
597 fi
598 else
599 # With a thread dump that uses gdb if a timeout.
600 trap 'kill -INT -$pid' INT
601 $cmdline "$@" 2>&1 & pid=$!
602 # Spawn a watcher process.
603 ( sleep $TIME_OUT_VALUE && \
604 echo "##### Thread dump using gdb on test timeout" && \
605 ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
606 --eval-command="call exit(124)" --eval-command=quit || \
607 kill $pid )) 2> /dev/null & watcher=$!
608 wait $pid
609 test_exit_status=$?
610 pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
611 if [ $test_exit_status = 0 ]; then
612 # The test finished normally.
613 exit 0
614 else
615 # The test failed or timed out.
616 if [ $test_exit_status = 124 ]; then
617 # The test timed out.
618 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
619 fi
620 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100621 fi
622 fi
623fi