blob: 0ea5d522cb22a275cad6893fd3ce1df9ed492431 [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=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010058
59while true; do
60 if [ "x$1" = "x--quiet" ]; then
61 QUIET="y"
62 shift
63 elif [ "x$1" = "x--lib" ]; then
64 shift
65 if [ "x$1" = "x" ]; then
66 echo "$0 missing argument to --lib" 1>&2
67 exit 1
68 fi
69 LIB="$1"
70 shift
Alex Light97acf192016-03-17 09:59:38 -070071 elif [ "x$1" = "x--gc-stress" ]; then
72 # Give an extra 5 mins if we are gc-stress.
73 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + 300))
74 shift
Mathieu Chartier031768a2015-08-27 10:25:02 -070075 elif [ "x$1" = "x--testlib" ]; then
76 shift
77 if [ "x$1" = "x" ]; then
78 echo "$0 missing argument to --testlib" 1>&2
79 exit 1
80 fi
Mathieu Chartierde286fd2015-09-03 18:10:29 -070081 ARGS="${ARGS} $1"
Mathieu Chartier031768a2015-08-27 10:25:02 -070082 shift
David Srbecky52886112016-01-22 13:56:47 +000083 elif [ "x$1" = "x--args" ]; then
84 shift
85 if [ "x$1" = "x" ]; then
86 echo "$0 missing argument to --args" 1>&2
87 exit 1
88 fi
89 ARGS="${ARGS} $1"
90 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010091 elif [ "x$1" = "x-Xcompiler-option" ]; then
92 shift
93 option="$1"
94 FLAGS="${FLAGS} -Xcompiler-option $option"
95 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
96 shift
Alex Light7233c7e2016-07-28 10:07:45 -070097 elif [ "x$1" = "x--android-runtime-option" ]; then
98 shift
99 option="$1"
100 ANDROID_FLAGS="${ANDROID_FLAGS} $option"
101 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100102 elif [ "x$1" = "x--runtime-option" ]; then
103 shift
104 option="$1"
105 FLAGS="${FLAGS} $option"
106 shift
107 elif [ "x$1" = "x--boot" ]; then
108 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000109 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100110 shift
111 elif [ "x$1" = "x--no-dex2oat" ]; then
112 DEX2OAT="-Xcompiler:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800113 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100114 shift
115 elif [ "x$1" = "x--no-patchoat" ]; then
116 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800117 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100118 shift
119 elif [ "x$1" = "x--relocate" ]; then
120 RELOCATE="y"
121 shift
122 elif [ "x$1" = "x--no-relocate" ]; then
123 RELOCATE="n"
124 shift
125 elif [ "x$1" = "x--prebuild" ]; then
126 PREBUILD="y"
127 shift
Richard Uhler76f5cb62016-04-04 13:30:16 -0700128 elif [ "x$1" = "x--strip-dex" ]; then
129 STRIP_DEX="y"
130 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100131 elif [ "x$1" = "x--host" ]; then
132 HOST="y"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000133 ANDROID_ROOT="$ANDROID_HOST_OUT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100134 shift
135 elif [ "x$1" = "x--no-prebuild" ]; then
136 PREBUILD="n"
137 shift
138 elif [ "x$1" = "x--no-image" ]; then
139 HAVE_IMAGE="n"
140 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700141 elif [ "x$1" = "x--secondary" ]; then
142 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
Calin Juravle175dc732015-08-25 15:42:32 +0100143 # Enable cfg-append to make sure we get the dump for both dex files.
144 # (otherwise the runtime compilation of the secondary dex will overwrite
145 # the dump of the first one)
146 FLAGS="${FLAGS} -Xcompiler-option --dump-cfg-append"
147 COMPILE_FLAGS="${COMPILE_FLAGS} --dump-cfg-append"
Jeff Hao207a37d2014-10-29 17:24:25 -0700148 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100149 elif [ "x$1" = "x--debug" ]; then
150 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800151 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100152 shift
153 elif [ "x$1" = "x--gdb" ]; then
154 USE_GDB="y"
155 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800156 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100157 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700158 elif [ "x$1" = "x--gdb-arg" ]; then
159 shift
160 gdb_arg="$1"
161 GDB_ARGS="${GDB_ARGS} $gdb_arg"
162 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100163 elif [ "x$1" = "x--zygote" ]; then
164 ZYGOTE="-Xzygote"
165 msg "Spawning from zygote"
166 shift
167 elif [ "x$1" = "x--dev" ]; then
168 DEV_MODE="y"
169 shift
170 elif [ "x$1" = "x--interpreter" ]; then
171 INTERPRETER="y"
172 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800173 elif [ "x$1" = "x--jit" ]; then
174 JIT="y"
175 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100176 elif [ "x$1" = "x--jvm" ]; then
177 USE_JVM="y"
178 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100179 elif [ "x$1" = "x--invoke-with" ]; then
180 shift
181 if [ "x$1" = "x" ]; then
182 echo "$0 missing argument to --invoke-with" 1>&2
183 exit 1
184 fi
185 if [ "x$INVOKE_WITH" = "x" ]; then
186 INVOKE_WITH="$1"
187 else
188 INVOKE_WITH="$INVOKE_WITH $1"
189 fi
190 shift
191 elif [ "x$1" = "x--no-verify" ]; then
192 VERIFY="n"
193 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700194 elif [ "x$1" = "x--verify-soft-fail" ]; then
195 VERIFY="s"
196 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100197 elif [ "x$1" = "x--no-optimize" ]; then
198 OPTIMIZE="n"
199 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000200 elif [ "x$1" = "x--android-root" ]; then
201 shift
202 ANDROID_ROOT="$1"
203 shift
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700204 elif [ "x$1" = "x--instruction-set-features" ]; then
205 shift
206 INSTRUCTION_SET_FEATURES="$1"
207 shift
Mathieu Chartier2576be22016-05-24 10:24:53 -0700208 elif [ "x$1" = "x--timeout" ]; then
209 shift
210 TIME_OUT_VALUE="$1"
211 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100212 elif [ "x$1" = "x--" ]; then
213 shift
214 break
215 elif [ "x$1" = "x--64" ]; then
216 ISA="x86_64"
217 GDB_SERVER="gdbserver64"
218 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000219 LIBRARY_DIRECTORY="lib64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100220 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
221 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700222 elif [ "x$1" = "x--pic-test" ]; then
223 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
224 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
225 shift
Alex Light8a0e0332015-10-26 10:11:58 -0700226 elif [ "x$1" = "x--experimental" ]; then
227 if [ "$#" -lt 2 ]; then
228 echo "missing --experimental option" 1>&2
229 exit 1
230 fi
231 EXPERIMENTAL="$EXPERIMENTAL $2"
232 shift 2
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100233 elif expr "x$1" : "x--" >/dev/null 2>&1; then
234 echo "unknown $0 option: $1" 1>&2
235 exit 1
236 else
237 break
238 fi
239done
240
Alex Light8a0e0332015-10-26 10:11:58 -0700241if [ "$USE_JVM" = "n" ]; then
Alex Light7233c7e2016-07-28 10:07:45 -0700242 FLAGS="${FLAGS} ${ANDROID_FLAGS}"
Alex Light8a0e0332015-10-26 10:11:58 -0700243 for feature in ${EXPERIMENTAL}; do
Alex Lightfa022852015-10-28 09:13:20 -0700244 FLAGS="${FLAGS} -Xexperimental:${feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:${feature}"
Alex Light8a0e0332015-10-26 10:11:58 -0700245 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xexperimental:${feature}"
246 done
247fi
248
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100249if [ "x$1" = "x" ] ; then
250 MAIN="Main"
251else
252 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700253 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100254fi
255
256if [ "$ZYGOTE" = "" ]; then
257 if [ "$OPTIMIZE" = "y" ]; then
258 if [ "$VERIFY" = "y" ]; then
259 DEX_OPTIMIZE="-Xdexopt:verified"
260 else
261 DEX_OPTIMIZE="-Xdexopt:all"
262 fi
263 msg "Performing optimizations"
264 else
265 DEX_OPTIMIZE="-Xdexopt:none"
266 msg "Skipping optimizations"
267 fi
268
269 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100270 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100271 msg "Performing verification"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700272 elif [ "$VERIFY" = "s" ]; then
273 JVM_VERIFY_ARG="Xverify:all"
274 DEX_VERIFY="-Xverify:softfail"
275 msg "Forcing verification to be soft fail"
276 else # VERIFY = "n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100277 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100278 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100279 msg "Skipping verification"
280 fi
281fi
282
283msg "------------------------------"
284
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100285if [ "$DEBUGGER" = "y" ]; then
286 # Use this instead for ddms and connect by running 'ddms':
287 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
288 # TODO: add a separate --ddms option?
289
290 PORT=12345
291 msg "Waiting for jdb to connect:"
292 if [ "$HOST" = "n" ]; then
293 msg " adb forward tcp:$PORT tcp:$PORT"
294 fi
295 msg " jdb -attach localhost:$PORT"
296 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
297fi
298
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100299if [ "$USE_JVM" = "y" ]; then
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700300 # Xmx is necessary since we don't pass down the ART flags to JVM.
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700301 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes ${FLAGS} $MAIN $@"
302 if [ "$DEV_MODE" = "y" ]; then
303 echo $cmdline
304 fi
305 $cmdline
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100306 exit
307fi
308
309
310if [ "$HAVE_IMAGE" = "n" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000311 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000312else
313 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100314fi
315
316
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100317if [ "$USE_GDB" = "y" ]; then
318 if [ "$HOST" = "n" ]; then
319 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100320 else
321 if [ `uname` = "Darwin" ]; then
322 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700323 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100324 DALVIKVM=
325 else
326 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700327 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100328 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
329 # gdbargs="--annotate=3 $gdbargs"
330 fi
331 fi
332fi
333
334if [ "$INTERPRETER" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000335 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700336 if [ "$VERIFY" = "y" ] ; then
Richard Uhlerf4b34872016-04-13 11:03:46 -0700337 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=interpret-only"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700338 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700339 elif [ "$VERIFY" = "s" ]; then
Richard Uhlerf4b34872016-04-13 11:03:46 -0700340 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-at-runtime"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700341 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
342 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
343 else # VERIFY = "n"
Richard Uhlerf4b34872016-04-13 11:03:46 -0700344 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-none"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700345 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
346 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
347 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100348fi
349
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800350if [ "$JIT" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000351 INT_OPTS="-Xusejit:true"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800352 if [ "$VERIFY" = "y" ] ; then
Richard Uhlerf4b34872016-04-13 11:03:46 -0700353 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-at-runtime"
Mathieu Chartiere86deef2015-03-19 13:43:37 -0700354 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800355 else
Richard Uhlerf4b34872016-04-13 11:03:46 -0700356 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-none"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800357 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
358 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
359 fi
360fi
361
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100362JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
363
364if [ "$RELOCATE" = "y" ]; then
365 COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information --runtime-arg -Xnorelocate"
366 FLAGS="${FLAGS} -Xrelocate -Xcompiler-option --include-patch-information"
367 if [ "$HOST" = "y" ]; then
368 # Run test sets a fairly draconian ulimit that we will likely blow right over
369 # since we are relocating. Get the total size of the /system/framework directory
370 # in 512 byte blocks and set it as the ulimit. This should be more than enough
371 # room.
372 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
Alex Lightd26b7e42016-04-08 09:44:54 -0700373 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 +0100374 fi
375 fi
376else
377 FLAGS="$FLAGS -Xnorelocate"
378 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
Mathieu Chartiercae2ed92015-06-09 13:02:50 -0700379 if [ "$HOST" = "y" ]; then
380 # Increase ulimit to 64MB in case we are running hprof test.
381 ulimit -S 64000 || exit 1
382 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100383fi
384
385if [ "$HOST" = "n" ]; then
386 ISA=$(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
387 if [ x"$ISA" = "x" ]; then
388 echo "Unable to determine architecture"
389 exit 1
390 fi
391fi
392
393dex2oat_cmdline="true"
Alex Lightafb5d192016-05-24 15:57:45 -0700394mkdir_locations="${DEX_LOCATION}/dalvik-cache/$ISA"
Richard Uhler76f5cb62016-04-04 13:30:16 -0700395strip_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100396
Mathieu Chartier92ec5942016-04-11 12:03:48 -0700397# Pick a base that will force the app image to get relocated.
398app_image="--base=0x4000 --app-image-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.art"
Jeff Haodcdc85b2015-12-04 14:06:18 -0800399
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100400if [ "$PREBUILD" = "y" ]; then
Alex Lightafb5d192016-05-24 15:57:45 -0700401 mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/oat/$ISA"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000402 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100403 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000404 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100405 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
Andreas Gampe14759242016-03-23 10:54:21 -0700406 --oat-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.odex \
Jeff Haodcdc85b2015-12-04 14:06:18 -0800407 ${app_image} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100408 --instruction-set=$ISA"
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700409 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
410 dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
411 fi
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700412
413 # Add in a timeout. This is important for testing the compilation/verification time of
414 # pathological cases.
415 # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
416 # now. We should try to improve this.
417 # The current value is rather arbitrary. run-tests should compile quickly.
418 if [ "$HOST" != "n" ]; then
419 # Use SIGRTMIN+2 to try to dump threads.
420 # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
421 dex2oat_cmdline="timeout -k 1m -s SIGRTMIN+2 1m ${dex2oat_cmdline}"
422 fi
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700423fi
424
Richard Uhler76f5cb62016-04-04 13:30:16 -0700425if [ "$STRIP_DEX" = "y" ]; then
426 strip_cmdline="zip --quiet --delete $DEX_LOCATION/$TEST_NAME.jar classes.dex"
427fi
428
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700429DALVIKVM_ISA_FEATURES_ARGS=""
430if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
431 DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100432fi
433
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000434# java.io.tmpdir can only be set at launch time.
435TMP_DIR_OPTION=""
436if [ "$HOST" = "n" ]; then
437 TMP_DIR_OPTION="-Djava.io.tmpdir=/data/local/tmp"
438fi
439
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000440# We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
441# b/27185632
442# b/24664297
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000443dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100444 $GDB_ARGS \
445 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700446 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100447 -XXlib:$LIB \
448 $PATCHOAT \
449 $DEX2OAT \
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700450 $DALVIKVM_ISA_FEATURES_ARGS \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100451 $ZYGOTE \
452 $JNI_OPTS \
453 $INT_OPTS \
454 $DEBUGGER_OPTS \
455 $DALVIKVM_BOOT_OPT \
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000456 $TMP_DIR_OPTION \
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000457 -XX:DumpNativeStackOnSigQuit:false \
Mathieu Chartier031768a2015-08-27 10:25:02 -0700458 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100459
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -0800460# Remove whitespace.
461dex2oat_cmdline=$(echo $dex2oat_cmdline)
462dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100463
464if [ "$HOST" = "n" ]; then
465 adb root > /dev/null
466 adb wait-for-device
467 if [ "$QUIET" = "n" ]; then
468 adb shell rm -r $DEX_LOCATION
469 adb shell mkdir -p $DEX_LOCATION
470 adb push $TEST_NAME.jar $DEX_LOCATION
471 adb push $TEST_NAME-ex.jar $DEX_LOCATION
472 else
473 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
474 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
475 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
476 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
477 fi
478
Alex Light7233c7e2016-07-28 10:07:45 -0700479 LD_LIBRARY_PATH=/data/art-test/$ISA
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000480 if [ "$ANDROID_ROOT" != "/system" ]; then
481 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
482 # so we can only use LD_LIBRARY_PATH when testing on a local
483 # installation.
Alex Light7233c7e2016-07-28 10:07:45 -0700484 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY:$LD_LIBRARY_PATH
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000485 fi
486
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700487 PUBLIC_LIBS=libart.so:libartd.so
488
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100489 # Create a script with the command. The command can get longer than the longest
490 # allowed adb command and there is no way to get the exit status from a adb shell
491 # command.
492 cmdline="cd $DEX_LOCATION && \
493 export ANDROID_DATA=$DEX_LOCATION && \
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700494 export ANDROID_ADDITIONAL_PUBLIC_LIBRARIES=$PUBLIC_LIBS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100495 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000496 export ANDROID_ROOT=$ANDROID_ROOT && \
Alex Lightafb5d192016-05-24 15:57:45 -0700497 mkdir -p ${mkdir_locations} && \
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100498 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray4f7fdd22015-04-24 11:57:37 +0100499 export PATH=$ANDROID_ROOT/bin:$PATH && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100500 $dex2oat_cmdline && \
Richard Uhler76f5cb62016-04-04 13:30:16 -0700501 $strip_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100502 $dalvikvm_cmdline"
503
504 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
505 echo "$cmdline" > $cmdfile
506
507 if [ "$DEV_MODE" = "y" ]; then
508 echo $cmdline
509 fi
510
511 if [ "$QUIET" = "n" ]; then
512 adb push $cmdfile $DEX_LOCATION/cmdline.sh
513 else
514 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
515 fi
516
517 adb shell sh $DEX_LOCATION/cmdline.sh
518
519 rm -f $cmdfile
520else
521 export ANDROID_PRINTF_LOG=brief
Andreas Gampea8780822015-03-13 19:51:09 -0700522
523 # By default, and for prebuild dex2oat, we are interested in errors being logged. In dev mode
524 # we want debug messages.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100525 if [ "$DEV_MODE" = "y" ]; then
526 export ANDROID_LOG_TAGS='*:d'
527 else
Andreas Gampee4301ff2015-02-17 19:25:29 -0800528 export ANDROID_LOG_TAGS='*:e'
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100529 fi
Andreas Gampea8780822015-03-13 19:51:09 -0700530
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100531 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000532 export ANDROID_ROOT="${ANDROID_ROOT}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100533 export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
534 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
535 export PATH="$PATH:${ANDROID_ROOT}/bin"
536
David Srbeckyc9ede382015-06-20 06:03:53 +0100537 # Temporarily disable address space layout randomization (ASLR).
538 # This is needed on the host so that the linker loads core.oat at the necessary address.
539 export LD_USE_LOAD_BIAS=1
540
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100541 cmdline="$dalvikvm_cmdline"
542
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700543 if [ "$TIME_OUT" = "gdb" ]; then
544 if [ `uname` = "Darwin" ]; then
545 # Fall back to timeout on Mac.
546 TIME_OUT="timeout"
Hiroshi Yamauchic823eff2015-09-01 16:21:35 -0700547 elif [ "$ISA" = "x86" ]; then
548 # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
549 TIME_OUT="timeout"
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700550 else
551 # Check if gdb is available.
552 gdb --eval-command="quit" > /dev/null 2>&1
553 if [ $? != 0 ]; then
554 # gdb isn't available. Fall back to timeout.
555 TIME_OUT="timeout"
556 fi
557 fi
558 fi
559
560 if [ "$TIME_OUT" = "timeout" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100561 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -0800562 #
Andreas Gampe6fb92562016-08-01 21:53:57 -0700563 # Note: We first send SIGRTMIN+2 (usually 36) to ART, which will induce a full thread dump
564 # before abort. However, dumping threads might deadlock, so we also use the "-k"
565 # option to definitely kill the child.
566 cmdline="timeout -k 120s -s SIGRTMIN+2 ${TIME_OUT_VALUE}s $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100567 fi
568
569 if [ "$DEV_MODE" = "y" ]; then
Alex Lightafb5d192016-05-24 15:57:45 -0700570 echo "mkdir -p ${mkdir_locations} && $dex2oat_cmdline && $strip_cmdline && $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100571 fi
572
573 cd $ANDROID_BUILD_TOP
574
David Srbecky2e4afe82016-01-27 18:42:06 +0000575 rm -rf ${DEX_LOCATION}/dalvik-cache/
Alex Lightafb5d192016-05-24 15:57:45 -0700576 mkdir -p ${mkdir_locations} || exit 1
Andreas Gampea8780822015-03-13 19:51:09 -0700577 $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Richard Uhler76f5cb62016-04-04 13:30:16 -0700578 $strip_cmdline || { echo "Strip failed." >&2 ; exit 3; }
Andreas Gampea8780822015-03-13 19:51:09 -0700579
580 # For running, we must turn off logging when dex2oat or patchoat are missing. Otherwise we use
581 # the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
582 if [ "$DEV_MODE" = "y" ]; then
583 export ANDROID_LOG_TAGS='*:d'
584 elif [ "$USE_DEX2OAT_AND_PATCHOAT" = "n" ]; then
585 # All tests would log the error of failing dex2oat/patchoat. Be silent here and only
586 # log fatal events.
587 export ANDROID_LOG_TAGS='*:s'
588 else
589 # We are interested in LOG(ERROR) output.
590 export ANDROID_LOG_TAGS='*:e'
591 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100592
593 if [ "$USE_GDB" = "y" ]; then
594 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700595 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100596 else
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700597 if [ "$TIME_OUT" != "gdb" ]; then
598 trap 'kill -INT -$pid' INT
599 $cmdline "$@" 2>&1 & pid=$!
600 wait $pid
601 # Add extra detail if time out is enabled.
602 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
603 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
604 fi
605 else
606 # With a thread dump that uses gdb if a timeout.
607 trap 'kill -INT -$pid' INT
608 $cmdline "$@" 2>&1 & pid=$!
609 # Spawn a watcher process.
610 ( sleep $TIME_OUT_VALUE && \
611 echo "##### Thread dump using gdb on test timeout" && \
612 ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
613 --eval-command="call exit(124)" --eval-command=quit || \
614 kill $pid )) 2> /dev/null & watcher=$!
615 wait $pid
616 test_exit_status=$?
617 pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
618 if [ $test_exit_status = 0 ]; then
619 # The test finished normally.
620 exit 0
621 else
622 # The test failed or timed out.
623 if [ $test_exit_status = 124 ]; then
624 # The test timed out.
625 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
626 fi
627 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100628 fi
629 fi
630fi