blob: 88fe661ef5a028a185da2d5b1433c759f940be06 [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=""
Alex Light7233c7e2016-07-28 10:07:45 -070024ANDROID_FLAGS=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010025GDB=""
Nicolas Geoffraybaf91022014-10-08 09:56:45 +010026GDB_ARGS=""
27GDB_SERVER="gdbserver"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010028HAVE_IMAGE="y"
29HOST="n"
30INTERPRETER="n"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080031JIT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010032INVOKE_WITH=""
33ISA=x86
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000034LIBRARY_DIRECTORY="lib"
35MAIN=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010036OPTIMIZE="y"
37PATCHOAT=""
38PREBUILD="y"
39QUIET="n"
40RELOCATE="y"
Richard Uhler76f5cb62016-04-04 13:30:16 -070041STRIP_DEX="n"
Jeff Hao207a37d2014-10-29 17:24:25 -070042SECONDARY_DEX=""
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -070043TIME_OUT="gdb" # "n" (disabled), "timeout" (use timeout), "gdb" (use gdb)
44# Value in seconds
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070045if [ "$ART_USE_READ_BARRIER" = "true" ]; then
Mathieu Chartier2576be22016-05-24 10:24:53 -070046 TIME_OUT_VALUE=1800 # 30 minutes.
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070047else
Mathieu Chartier2576be22016-05-24 10:24:53 -070048 TIME_OUT_VALUE=1200 # 20 minutes.
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070049fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010050USE_GDB="n"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +010051USE_JVM="n"
Igor Murashkin7617abd2015-07-10 18:27:47 -070052VERIFY="y" # y=yes,n=no,s=softfail
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010053ZYGOTE=""
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -070054DEX_VERIFY=""
Andreas Gampe65357032015-02-19 15:10:24 -080055USE_DEX2OAT_AND_PATCHOAT="y"
Andreas Gampe4d2ef332015-08-05 09:24:45 -070056INSTRUCTION_SET_FEATURES=""
Mathieu Chartier031768a2015-08-27 10:25:02 -070057ARGS=""
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -070058EXTERNAL_LOG_TAGS="n" # if y respect externally set ANDROID_LOG_TAGS.
59DRY_RUN="n" # if y prepare to run the test but don't run it.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010060
61while true; do
62 if [ "x$1" = "x--quiet" ]; then
63 QUIET="y"
64 shift
Alex Lightfaf90b62016-08-12 14:43:48 -070065 elif [ "x$1" = "x-O" ]; then
66 # Ignore this option.
67 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010068 elif [ "x$1" = "x--lib" ]; then
69 shift
70 if [ "x$1" = "x" ]; then
71 echo "$0 missing argument to --lib" 1>&2
72 exit 1
73 fi
74 LIB="$1"
75 shift
Alex Light97acf192016-03-17 09:59:38 -070076 elif [ "x$1" = "x--gc-stress" ]; then
77 # Give an extra 5 mins if we are gc-stress.
78 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + 300))
79 shift
Mathieu Chartier031768a2015-08-27 10:25:02 -070080 elif [ "x$1" = "x--testlib" ]; then
81 shift
82 if [ "x$1" = "x" ]; then
83 echo "$0 missing argument to --testlib" 1>&2
84 exit 1
85 fi
Mathieu Chartierde286fd2015-09-03 18:10:29 -070086 ARGS="${ARGS} $1"
Mathieu Chartier031768a2015-08-27 10:25:02 -070087 shift
David Srbecky52886112016-01-22 13:56:47 +000088 elif [ "x$1" = "x--args" ]; then
89 shift
90 if [ "x$1" = "x" ]; then
91 echo "$0 missing argument to --args" 1>&2
92 exit 1
93 fi
94 ARGS="${ARGS} $1"
95 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010096 elif [ "x$1" = "x-Xcompiler-option" ]; then
97 shift
98 option="$1"
99 FLAGS="${FLAGS} -Xcompiler-option $option"
100 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
101 shift
Alex Light7233c7e2016-07-28 10:07:45 -0700102 elif [ "x$1" = "x--android-runtime-option" ]; then
103 shift
104 option="$1"
105 ANDROID_FLAGS="${ANDROID_FLAGS} $option"
106 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100107 elif [ "x$1" = "x--runtime-option" ]; then
108 shift
109 option="$1"
110 FLAGS="${FLAGS} $option"
111 shift
112 elif [ "x$1" = "x--boot" ]; then
113 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000114 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100115 shift
116 elif [ "x$1" = "x--no-dex2oat" ]; then
117 DEX2OAT="-Xcompiler:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800118 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100119 shift
120 elif [ "x$1" = "x--no-patchoat" ]; then
121 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800122 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100123 shift
124 elif [ "x$1" = "x--relocate" ]; then
125 RELOCATE="y"
126 shift
127 elif [ "x$1" = "x--no-relocate" ]; then
128 RELOCATE="n"
129 shift
130 elif [ "x$1" = "x--prebuild" ]; then
131 PREBUILD="y"
132 shift
Richard Uhler76f5cb62016-04-04 13:30:16 -0700133 elif [ "x$1" = "x--strip-dex" ]; then
134 STRIP_DEX="y"
135 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100136 elif [ "x$1" = "x--host" ]; then
137 HOST="y"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000138 ANDROID_ROOT="$ANDROID_HOST_OUT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100139 shift
140 elif [ "x$1" = "x--no-prebuild" ]; then
141 PREBUILD="n"
142 shift
143 elif [ "x$1" = "x--no-image" ]; then
144 HAVE_IMAGE="n"
145 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700146 elif [ "x$1" = "x--secondary" ]; then
147 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
Calin Juravle175dc732015-08-25 15:42:32 +0100148 # Enable cfg-append to make sure we get the dump for both dex files.
149 # (otherwise the runtime compilation of the secondary dex will overwrite
150 # the dump of the first one)
151 FLAGS="${FLAGS} -Xcompiler-option --dump-cfg-append"
152 COMPILE_FLAGS="${COMPILE_FLAGS} --dump-cfg-append"
Jeff Hao207a37d2014-10-29 17:24:25 -0700153 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100154 elif [ "x$1" = "x--debug" ]; then
155 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800156 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100157 shift
158 elif [ "x$1" = "x--gdb" ]; then
159 USE_GDB="y"
160 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800161 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100162 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700163 elif [ "x$1" = "x--gdb-arg" ]; then
164 shift
165 gdb_arg="$1"
166 GDB_ARGS="${GDB_ARGS} $gdb_arg"
167 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100168 elif [ "x$1" = "x--zygote" ]; then
169 ZYGOTE="-Xzygote"
170 msg "Spawning from zygote"
171 shift
172 elif [ "x$1" = "x--dev" ]; then
173 DEV_MODE="y"
174 shift
175 elif [ "x$1" = "x--interpreter" ]; then
176 INTERPRETER="y"
177 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800178 elif [ "x$1" = "x--jit" ]; then
179 JIT="y"
180 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100181 elif [ "x$1" = "x--jvm" ]; then
182 USE_JVM="y"
183 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100184 elif [ "x$1" = "x--invoke-with" ]; then
185 shift
186 if [ "x$1" = "x" ]; then
187 echo "$0 missing argument to --invoke-with" 1>&2
188 exit 1
189 fi
190 if [ "x$INVOKE_WITH" = "x" ]; then
191 INVOKE_WITH="$1"
192 else
193 INVOKE_WITH="$INVOKE_WITH $1"
194 fi
195 shift
196 elif [ "x$1" = "x--no-verify" ]; then
197 VERIFY="n"
198 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700199 elif [ "x$1" = "x--verify-soft-fail" ]; then
200 VERIFY="s"
201 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100202 elif [ "x$1" = "x--no-optimize" ]; then
203 OPTIMIZE="n"
204 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000205 elif [ "x$1" = "x--android-root" ]; then
206 shift
207 ANDROID_ROOT="$1"
208 shift
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700209 elif [ "x$1" = "x--instruction-set-features" ]; then
210 shift
211 INSTRUCTION_SET_FEATURES="$1"
212 shift
Mathieu Chartier2576be22016-05-24 10:24:53 -0700213 elif [ "x$1" = "x--timeout" ]; then
214 shift
215 TIME_OUT_VALUE="$1"
216 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100217 elif [ "x$1" = "x--" ]; then
218 shift
219 break
220 elif [ "x$1" = "x--64" ]; then
221 ISA="x86_64"
222 GDB_SERVER="gdbserver64"
223 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000224 LIBRARY_DIRECTORY="lib64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100225 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
226 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700227 elif [ "x$1" = "x--pic-test" ]; then
228 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
229 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
230 shift
Alex Light8a0e0332015-10-26 10:11:58 -0700231 elif [ "x$1" = "x--experimental" ]; then
232 if [ "$#" -lt 2 ]; then
233 echo "missing --experimental option" 1>&2
234 exit 1
235 fi
236 EXPERIMENTAL="$EXPERIMENTAL $2"
237 shift 2
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700238 elif [ "x$1" = "x--external-log-tags" ]; then
239 EXTERNAL_LOG_TAGS="y"
240 shift
241 elif [ "x$1" = "x--dry-run" ]; then
242 DRY_RUN="y"
243 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100244 elif expr "x$1" : "x--" >/dev/null 2>&1; then
245 echo "unknown $0 option: $1" 1>&2
246 exit 1
247 else
248 break
249 fi
250done
251
Alex Light8a0e0332015-10-26 10:11:58 -0700252if [ "$USE_JVM" = "n" ]; then
Alex Light7233c7e2016-07-28 10:07:45 -0700253 FLAGS="${FLAGS} ${ANDROID_FLAGS}"
Alex Light8a0e0332015-10-26 10:11:58 -0700254 for feature in ${EXPERIMENTAL}; do
Alex Lightfa022852015-10-28 09:13:20 -0700255 FLAGS="${FLAGS} -Xexperimental:${feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:${feature}"
Alex Light8a0e0332015-10-26 10:11:58 -0700256 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xexperimental:${feature}"
257 done
258fi
259
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100260if [ "x$1" = "x" ] ; then
261 MAIN="Main"
262else
263 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700264 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100265fi
266
267if [ "$ZYGOTE" = "" ]; then
268 if [ "$OPTIMIZE" = "y" ]; then
269 if [ "$VERIFY" = "y" ]; then
270 DEX_OPTIMIZE="-Xdexopt:verified"
271 else
272 DEX_OPTIMIZE="-Xdexopt:all"
273 fi
274 msg "Performing optimizations"
275 else
276 DEX_OPTIMIZE="-Xdexopt:none"
277 msg "Skipping optimizations"
278 fi
279
280 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100281 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100282 msg "Performing verification"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700283 elif [ "$VERIFY" = "s" ]; then
284 JVM_VERIFY_ARG="Xverify:all"
285 DEX_VERIFY="-Xverify:softfail"
286 msg "Forcing verification to be soft fail"
287 else # VERIFY = "n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100288 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100289 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100290 msg "Skipping verification"
291 fi
292fi
293
294msg "------------------------------"
295
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100296if [ "$DEBUGGER" = "y" ]; then
297 # Use this instead for ddms and connect by running 'ddms':
298 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
299 # TODO: add a separate --ddms option?
300
301 PORT=12345
302 msg "Waiting for jdb to connect:"
303 if [ "$HOST" = "n" ]; then
304 msg " adb forward tcp:$PORT tcp:$PORT"
305 fi
306 msg " jdb -attach localhost:$PORT"
307 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
308fi
309
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100310if [ "$USE_JVM" = "y" ]; then
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700311 # Xmx is necessary since we don't pass down the ART flags to JVM.
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700312 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes ${FLAGS} $MAIN $@"
313 if [ "$DEV_MODE" = "y" ]; then
314 echo $cmdline
315 fi
316 $cmdline
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100317 exit
318fi
319
320
321if [ "$HAVE_IMAGE" = "n" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000322 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000323else
324 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100325fi
326
327
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100328if [ "$USE_GDB" = "y" ]; then
329 if [ "$HOST" = "n" ]; then
330 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100331 else
332 if [ `uname` = "Darwin" ]; then
333 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700334 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100335 DALVIKVM=
336 else
337 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700338 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100339 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
340 # gdbargs="--annotate=3 $gdbargs"
341 fi
342 fi
343fi
344
345if [ "$INTERPRETER" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000346 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700347 if [ "$VERIFY" = "y" ] ; then
Richard Uhlerf4b34872016-04-13 11:03:46 -0700348 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=interpret-only"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700349 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700350 elif [ "$VERIFY" = "s" ]; then
Richard Uhlerf4b34872016-04-13 11:03:46 -0700351 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-at-runtime"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700352 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
353 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
354 else # VERIFY = "n"
Richard Uhlerf4b34872016-04-13 11:03:46 -0700355 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-none"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700356 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
357 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
358 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100359fi
360
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800361if [ "$JIT" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000362 INT_OPTS="-Xusejit:true"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800363 if [ "$VERIFY" = "y" ] ; then
Richard Uhlerf4b34872016-04-13 11:03:46 -0700364 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-at-runtime"
Mathieu Chartiere86deef2015-03-19 13:43:37 -0700365 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800366 else
Richard Uhlerf4b34872016-04-13 11:03:46 -0700367 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-none"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800368 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
369 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
370 fi
371fi
372
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100373JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
374
375if [ "$RELOCATE" = "y" ]; then
376 COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information --runtime-arg -Xnorelocate"
377 FLAGS="${FLAGS} -Xrelocate -Xcompiler-option --include-patch-information"
378 if [ "$HOST" = "y" ]; then
379 # Run test sets a fairly draconian ulimit that we will likely blow right over
380 # since we are relocating. Get the total size of the /system/framework directory
381 # in 512 byte blocks and set it as the ulimit. This should be more than enough
382 # room.
383 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
Alex Lightd26b7e42016-04-08 09:44:54 -0700384 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 +0100385 fi
386 fi
387else
388 FLAGS="$FLAGS -Xnorelocate"
389 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
Mathieu Chartiercae2ed92015-06-09 13:02:50 -0700390 if [ "$HOST" = "y" ]; then
391 # Increase ulimit to 64MB in case we are running hprof test.
392 ulimit -S 64000 || exit 1
393 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100394fi
395
396if [ "$HOST" = "n" ]; then
397 ISA=$(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
398 if [ x"$ISA" = "x" ]; then
399 echo "Unable to determine architecture"
400 exit 1
401 fi
402fi
403
404dex2oat_cmdline="true"
Alex Lightafb5d192016-05-24 15:57:45 -0700405mkdir_locations="${DEX_LOCATION}/dalvik-cache/$ISA"
Richard Uhler76f5cb62016-04-04 13:30:16 -0700406strip_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100407
Mathieu Chartier92ec5942016-04-11 12:03:48 -0700408# Pick a base that will force the app image to get relocated.
409app_image="--base=0x4000 --app-image-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.art"
Jeff Haodcdc85b2015-12-04 14:06:18 -0800410
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100411if [ "$PREBUILD" = "y" ]; then
Alex Lightafb5d192016-05-24 15:57:45 -0700412 mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/oat/$ISA"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000413 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100414 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000415 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100416 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
Andreas Gampe14759242016-03-23 10:54:21 -0700417 --oat-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.odex \
Jeff Haodcdc85b2015-12-04 14:06:18 -0800418 ${app_image} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100419 --instruction-set=$ISA"
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700420 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
421 dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
422 fi
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700423
424 # Add in a timeout. This is important for testing the compilation/verification time of
425 # pathological cases.
426 # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
427 # now. We should try to improve this.
428 # The current value is rather arbitrary. run-tests should compile quickly.
429 if [ "$HOST" != "n" ]; then
430 # Use SIGRTMIN+2 to try to dump threads.
431 # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
432 dex2oat_cmdline="timeout -k 1m -s SIGRTMIN+2 1m ${dex2oat_cmdline}"
433 fi
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700434fi
435
Richard Uhler76f5cb62016-04-04 13:30:16 -0700436if [ "$STRIP_DEX" = "y" ]; then
437 strip_cmdline="zip --quiet --delete $DEX_LOCATION/$TEST_NAME.jar classes.dex"
438fi
439
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700440DALVIKVM_ISA_FEATURES_ARGS=""
441if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
442 DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100443fi
444
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000445# java.io.tmpdir can only be set at launch time.
446TMP_DIR_OPTION=""
447if [ "$HOST" = "n" ]; then
448 TMP_DIR_OPTION="-Djava.io.tmpdir=/data/local/tmp"
449fi
450
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000451# We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
452# b/27185632
453# b/24664297
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000454dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100455 $GDB_ARGS \
456 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700457 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100458 -XXlib:$LIB \
459 $PATCHOAT \
460 $DEX2OAT \
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700461 $DALVIKVM_ISA_FEATURES_ARGS \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100462 $ZYGOTE \
463 $JNI_OPTS \
464 $INT_OPTS \
465 $DEBUGGER_OPTS \
466 $DALVIKVM_BOOT_OPT \
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000467 $TMP_DIR_OPTION \
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000468 -XX:DumpNativeStackOnSigQuit:false \
Mathieu Chartier031768a2015-08-27 10:25:02 -0700469 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100470
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -0800471# Remove whitespace.
472dex2oat_cmdline=$(echo $dex2oat_cmdline)
473dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100474
475if [ "$HOST" = "n" ]; then
476 adb root > /dev/null
477 adb wait-for-device
478 if [ "$QUIET" = "n" ]; then
479 adb shell rm -r $DEX_LOCATION
480 adb shell mkdir -p $DEX_LOCATION
481 adb push $TEST_NAME.jar $DEX_LOCATION
482 adb push $TEST_NAME-ex.jar $DEX_LOCATION
483 else
484 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
485 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
486 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
487 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
488 fi
489
Alex Light7233c7e2016-07-28 10:07:45 -0700490 LD_LIBRARY_PATH=/data/art-test/$ISA
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000491 if [ "$ANDROID_ROOT" != "/system" ]; then
492 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
493 # so we can only use LD_LIBRARY_PATH when testing on a local
494 # installation.
Alex Light7233c7e2016-07-28 10:07:45 -0700495 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY:$LD_LIBRARY_PATH
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000496 fi
497
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700498 PUBLIC_LIBS=libart.so:libartd.so
499
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100500 # Create a script with the command. The command can get longer than the longest
501 # allowed adb command and there is no way to get the exit status from a adb shell
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700502 # command. Dalvik cache is cleaned before running to make subsequent executions
503 # of the script follow the same runtime path.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100504 cmdline="cd $DEX_LOCATION && \
505 export ANDROID_DATA=$DEX_LOCATION && \
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700506 export ANDROID_ADDITIONAL_PUBLIC_LIBRARIES=$PUBLIC_LIBS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100507 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000508 export ANDROID_ROOT=$ANDROID_ROOT && \
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700509 rm -rf ${DEX_LOCATION}/dalvik-cache/ && \
Alex Lightafb5d192016-05-24 15:57:45 -0700510 mkdir -p ${mkdir_locations} && \
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100511 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray4f7fdd22015-04-24 11:57:37 +0100512 export PATH=$ANDROID_ROOT/bin:$PATH && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100513 $dex2oat_cmdline && \
Richard Uhler76f5cb62016-04-04 13:30:16 -0700514 $strip_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100515 $dalvikvm_cmdline"
516
517 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
518 echo "$cmdline" > $cmdfile
519
520 if [ "$DEV_MODE" = "y" ]; then
521 echo $cmdline
522 fi
523
524 if [ "$QUIET" = "n" ]; then
525 adb push $cmdfile $DEX_LOCATION/cmdline.sh
526 else
527 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
528 fi
529
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700530 if [ "$DRY_RUN" != "y" ]; then
531 adb shell sh $DEX_LOCATION/cmdline.sh
532 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100533
534 rm -f $cmdfile
535else
536 export ANDROID_PRINTF_LOG=brief
Andreas Gampea8780822015-03-13 19:51:09 -0700537
538 # By default, and for prebuild dex2oat, we are interested in errors being logged. In dev mode
539 # we want debug messages.
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700540 if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
541 if [ "$DEV_MODE" = "y" ]; then
542 export ANDROID_LOG_TAGS='*:d'
543 else
544 export ANDROID_LOG_TAGS='*:e'
545 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100546 fi
Andreas Gampea8780822015-03-13 19:51:09 -0700547
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100548 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000549 export ANDROID_ROOT="${ANDROID_ROOT}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100550 export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
551 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
552 export PATH="$PATH:${ANDROID_ROOT}/bin"
553
David Srbeckyc9ede382015-06-20 06:03:53 +0100554 # Temporarily disable address space layout randomization (ASLR).
555 # This is needed on the host so that the linker loads core.oat at the necessary address.
556 export LD_USE_LOAD_BIAS=1
557
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100558 cmdline="$dalvikvm_cmdline"
559
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700560 if [ "$TIME_OUT" = "gdb" ]; then
561 if [ `uname` = "Darwin" ]; then
562 # Fall back to timeout on Mac.
563 TIME_OUT="timeout"
Hiroshi Yamauchic823eff2015-09-01 16:21:35 -0700564 elif [ "$ISA" = "x86" ]; then
565 # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
566 TIME_OUT="timeout"
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700567 else
568 # Check if gdb is available.
569 gdb --eval-command="quit" > /dev/null 2>&1
570 if [ $? != 0 ]; then
571 # gdb isn't available. Fall back to timeout.
572 TIME_OUT="timeout"
573 fi
574 fi
575 fi
576
577 if [ "$TIME_OUT" = "timeout" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100578 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -0800579 #
Andreas Gampe6fb92562016-08-01 21:53:57 -0700580 # Note: We first send SIGRTMIN+2 (usually 36) to ART, which will induce a full thread dump
581 # before abort. However, dumping threads might deadlock, so we also use the "-k"
582 # option to definitely kill the child.
583 cmdline="timeout -k 120s -s SIGRTMIN+2 ${TIME_OUT_VALUE}s $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100584 fi
585
586 if [ "$DEV_MODE" = "y" ]; then
Alex Lightafb5d192016-05-24 15:57:45 -0700587 echo "mkdir -p ${mkdir_locations} && $dex2oat_cmdline && $strip_cmdline && $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100588 fi
589
590 cd $ANDROID_BUILD_TOP
591
David Srbecky2e4afe82016-01-27 18:42:06 +0000592 rm -rf ${DEX_LOCATION}/dalvik-cache/
Alex Lightafb5d192016-05-24 15:57:45 -0700593 mkdir -p ${mkdir_locations} || exit 1
Andreas Gampea8780822015-03-13 19:51:09 -0700594 $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Richard Uhler76f5cb62016-04-04 13:30:16 -0700595 $strip_cmdline || { echo "Strip failed." >&2 ; exit 3; }
Andreas Gampea8780822015-03-13 19:51:09 -0700596
597 # For running, we must turn off logging when dex2oat or patchoat are missing. Otherwise we use
598 # the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700599 if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
600 if [ "$DEV_MODE" = "y" ]; then
601 export ANDROID_LOG_TAGS='*:d'
602 elif [ "$USE_DEX2OAT_AND_PATCHOAT" = "n" ]; then
603 # All tests would log the error of failing dex2oat/patchoat. Be silent here and only
604 # log fatal events.
605 export ANDROID_LOG_TAGS='*:s'
606 else
607 # We are interested in LOG(ERROR) output.
608 export ANDROID_LOG_TAGS='*:e'
609 fi
610 fi
611
612 if [ "$DRY_RUN" = "y" ]; then
613 exit 0
Andreas Gampea8780822015-03-13 19:51:09 -0700614 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100615
616 if [ "$USE_GDB" = "y" ]; then
617 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700618 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100619 else
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700620 if [ "$TIME_OUT" != "gdb" ]; then
621 trap 'kill -INT -$pid' INT
622 $cmdline "$@" 2>&1 & pid=$!
623 wait $pid
624 # Add extra detail if time out is enabled.
625 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
626 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
627 fi
628 else
629 # With a thread dump that uses gdb if a timeout.
630 trap 'kill -INT -$pid' INT
631 $cmdline "$@" 2>&1 & pid=$!
632 # Spawn a watcher process.
633 ( sleep $TIME_OUT_VALUE && \
634 echo "##### Thread dump using gdb on test timeout" && \
635 ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
636 --eval-command="call exit(124)" --eval-command=quit || \
637 kill $pid )) 2> /dev/null & watcher=$!
638 wait $pid
639 test_exit_status=$?
640 pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
641 if [ $test_exit_status = 0 ]; then
642 # The test finished normally.
643 exit 0
644 else
645 # The test failed or timed out.
646 if [ $test_exit_status = 124 ]; then
647 # The test timed out.
648 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
649 fi
650 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100651 fi
652 fi
653fi