blob: a0e99d8125fa82e9c05f3efc212e4f919cc7f6f5 [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"
Colin Crossafd3c9e2016-09-16 13:47:21 -070035TEST_DIRECTORY="nativetest"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000036MAIN=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010037OPTIMIZE="y"
38PATCHOAT=""
39PREBUILD="y"
40QUIET="n"
41RELOCATE="y"
Richard Uhler76f5cb62016-04-04 13:30:16 -070042STRIP_DEX="n"
Jeff Hao207a37d2014-10-29 17:24:25 -070043SECONDARY_DEX=""
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -070044TIME_OUT="gdb" # "n" (disabled), "timeout" (use timeout), "gdb" (use gdb)
45# Value in seconds
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070046if [ "$ART_USE_READ_BARRIER" = "true" ]; then
Mathieu Chartier2576be22016-05-24 10:24:53 -070047 TIME_OUT_VALUE=1800 # 30 minutes.
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070048else
Mathieu Chartier2576be22016-05-24 10:24:53 -070049 TIME_OUT_VALUE=1200 # 20 minutes.
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070050fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010051USE_GDB="n"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +010052USE_JVM="n"
Igor Murashkin7617abd2015-07-10 18:27:47 -070053VERIFY="y" # y=yes,n=no,s=softfail
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010054ZYGOTE=""
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -070055DEX_VERIFY=""
Andreas Gampe65357032015-02-19 15:10:24 -080056USE_DEX2OAT_AND_PATCHOAT="y"
Andreas Gampe4d2ef332015-08-05 09:24:45 -070057INSTRUCTION_SET_FEATURES=""
Mathieu Chartier031768a2015-08-27 10:25:02 -070058ARGS=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010059
60while true; do
61 if [ "x$1" = "x--quiet" ]; then
62 QUIET="y"
63 shift
Alex Lightfaf90b62016-08-12 14:43:48 -070064 elif [ "x$1" = "x-O" ]; then
65 # Ignore this option.
66 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010067 elif [ "x$1" = "x--lib" ]; then
68 shift
69 if [ "x$1" = "x" ]; then
70 echo "$0 missing argument to --lib" 1>&2
71 exit 1
72 fi
73 LIB="$1"
74 shift
Alex Light97acf192016-03-17 09:59:38 -070075 elif [ "x$1" = "x--gc-stress" ]; then
76 # Give an extra 5 mins if we are gc-stress.
77 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + 300))
78 shift
Mathieu Chartier031768a2015-08-27 10:25:02 -070079 elif [ "x$1" = "x--testlib" ]; then
80 shift
81 if [ "x$1" = "x" ]; then
82 echo "$0 missing argument to --testlib" 1>&2
83 exit 1
84 fi
Mathieu Chartierde286fd2015-09-03 18:10:29 -070085 ARGS="${ARGS} $1"
Mathieu Chartier031768a2015-08-27 10:25:02 -070086 shift
David Srbecky52886112016-01-22 13:56:47 +000087 elif [ "x$1" = "x--args" ]; then
88 shift
89 if [ "x$1" = "x" ]; then
90 echo "$0 missing argument to --args" 1>&2
91 exit 1
92 fi
93 ARGS="${ARGS} $1"
94 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010095 elif [ "x$1" = "x-Xcompiler-option" ]; then
96 shift
97 option="$1"
98 FLAGS="${FLAGS} -Xcompiler-option $option"
99 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
100 shift
Alex Light7233c7e2016-07-28 10:07:45 -0700101 elif [ "x$1" = "x--android-runtime-option" ]; then
102 shift
103 option="$1"
104 ANDROID_FLAGS="${ANDROID_FLAGS} $option"
105 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100106 elif [ "x$1" = "x--runtime-option" ]; then
107 shift
108 option="$1"
109 FLAGS="${FLAGS} $option"
110 shift
111 elif [ "x$1" = "x--boot" ]; then
112 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000113 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100114 shift
115 elif [ "x$1" = "x--no-dex2oat" ]; then
116 DEX2OAT="-Xcompiler:${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--no-patchoat" ]; then
120 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800121 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100122 shift
123 elif [ "x$1" = "x--relocate" ]; then
124 RELOCATE="y"
125 shift
126 elif [ "x$1" = "x--no-relocate" ]; then
127 RELOCATE="n"
128 shift
129 elif [ "x$1" = "x--prebuild" ]; then
130 PREBUILD="y"
131 shift
Richard Uhler76f5cb62016-04-04 13:30:16 -0700132 elif [ "x$1" = "x--strip-dex" ]; then
133 STRIP_DEX="y"
134 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100135 elif [ "x$1" = "x--host" ]; then
136 HOST="y"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000137 ANDROID_ROOT="$ANDROID_HOST_OUT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100138 shift
139 elif [ "x$1" = "x--no-prebuild" ]; then
140 PREBUILD="n"
141 shift
142 elif [ "x$1" = "x--no-image" ]; then
143 HAVE_IMAGE="n"
144 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700145 elif [ "x$1" = "x--secondary" ]; then
146 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
Calin Juravle175dc732015-08-25 15:42:32 +0100147 # Enable cfg-append to make sure we get the dump for both dex files.
148 # (otherwise the runtime compilation of the secondary dex will overwrite
149 # the dump of the first one)
150 FLAGS="${FLAGS} -Xcompiler-option --dump-cfg-append"
151 COMPILE_FLAGS="${COMPILE_FLAGS} --dump-cfg-append"
Jeff Hao207a37d2014-10-29 17:24:25 -0700152 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100153 elif [ "x$1" = "x--debug" ]; then
154 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800155 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100156 shift
157 elif [ "x$1" = "x--gdb" ]; then
158 USE_GDB="y"
159 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800160 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100161 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700162 elif [ "x$1" = "x--gdb-arg" ]; then
163 shift
164 gdb_arg="$1"
165 GDB_ARGS="${GDB_ARGS} $gdb_arg"
166 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100167 elif [ "x$1" = "x--zygote" ]; then
168 ZYGOTE="-Xzygote"
169 msg "Spawning from zygote"
170 shift
171 elif [ "x$1" = "x--dev" ]; then
172 DEV_MODE="y"
173 shift
174 elif [ "x$1" = "x--interpreter" ]; then
175 INTERPRETER="y"
176 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800177 elif [ "x$1" = "x--jit" ]; then
178 JIT="y"
179 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100180 elif [ "x$1" = "x--jvm" ]; then
181 USE_JVM="y"
182 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100183 elif [ "x$1" = "x--invoke-with" ]; then
184 shift
185 if [ "x$1" = "x" ]; then
186 echo "$0 missing argument to --invoke-with" 1>&2
187 exit 1
188 fi
189 if [ "x$INVOKE_WITH" = "x" ]; then
190 INVOKE_WITH="$1"
191 else
192 INVOKE_WITH="$INVOKE_WITH $1"
193 fi
194 shift
195 elif [ "x$1" = "x--no-verify" ]; then
196 VERIFY="n"
197 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700198 elif [ "x$1" = "x--verify-soft-fail" ]; then
199 VERIFY="s"
200 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100201 elif [ "x$1" = "x--no-optimize" ]; then
202 OPTIMIZE="n"
203 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000204 elif [ "x$1" = "x--android-root" ]; then
205 shift
206 ANDROID_ROOT="$1"
207 shift
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700208 elif [ "x$1" = "x--instruction-set-features" ]; then
209 shift
210 INSTRUCTION_SET_FEATURES="$1"
211 shift
Mathieu Chartier2576be22016-05-24 10:24:53 -0700212 elif [ "x$1" = "x--timeout" ]; then
213 shift
214 TIME_OUT_VALUE="$1"
215 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100216 elif [ "x$1" = "x--" ]; then
217 shift
218 break
219 elif [ "x$1" = "x--64" ]; then
220 ISA="x86_64"
221 GDB_SERVER="gdbserver64"
222 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000223 LIBRARY_DIRECTORY="lib64"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700224 TEST_DIRECTORY="nativetest64"
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
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100238 elif expr "x$1" : "x--" >/dev/null 2>&1; then
239 echo "unknown $0 option: $1" 1>&2
240 exit 1
241 else
242 break
243 fi
244done
245
Alex Light8a0e0332015-10-26 10:11:58 -0700246if [ "$USE_JVM" = "n" ]; then
Alex Light7233c7e2016-07-28 10:07:45 -0700247 FLAGS="${FLAGS} ${ANDROID_FLAGS}"
Alex Light8a0e0332015-10-26 10:11:58 -0700248 for feature in ${EXPERIMENTAL}; do
Alex Lightfa022852015-10-28 09:13:20 -0700249 FLAGS="${FLAGS} -Xexperimental:${feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:${feature}"
Alex Light8a0e0332015-10-26 10:11:58 -0700250 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xexperimental:${feature}"
251 done
252fi
253
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100254if [ "x$1" = "x" ] ; then
255 MAIN="Main"
256else
257 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700258 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100259fi
260
261if [ "$ZYGOTE" = "" ]; then
262 if [ "$OPTIMIZE" = "y" ]; then
263 if [ "$VERIFY" = "y" ]; then
264 DEX_OPTIMIZE="-Xdexopt:verified"
265 else
266 DEX_OPTIMIZE="-Xdexopt:all"
267 fi
268 msg "Performing optimizations"
269 else
270 DEX_OPTIMIZE="-Xdexopt:none"
271 msg "Skipping optimizations"
272 fi
273
274 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100275 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100276 msg "Performing verification"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700277 elif [ "$VERIFY" = "s" ]; then
278 JVM_VERIFY_ARG="Xverify:all"
279 DEX_VERIFY="-Xverify:softfail"
280 msg "Forcing verification to be soft fail"
281 else # VERIFY = "n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100282 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100283 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100284 msg "Skipping verification"
285 fi
286fi
287
288msg "------------------------------"
289
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100290if [ "$DEBUGGER" = "y" ]; then
291 # Use this instead for ddms and connect by running 'ddms':
292 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
293 # TODO: add a separate --ddms option?
294
295 PORT=12345
296 msg "Waiting for jdb to connect:"
297 if [ "$HOST" = "n" ]; then
298 msg " adb forward tcp:$PORT tcp:$PORT"
299 fi
300 msg " jdb -attach localhost:$PORT"
301 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
302fi
303
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100304if [ "$USE_JVM" = "y" ]; then
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700305 # Xmx is necessary since we don't pass down the ART flags to JVM.
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700306 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes ${FLAGS} $MAIN $@"
307 if [ "$DEV_MODE" = "y" ]; then
308 echo $cmdline
309 fi
310 $cmdline
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100311 exit
312fi
313
314
315if [ "$HAVE_IMAGE" = "n" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000316 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000317else
318 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100319fi
320
321
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100322if [ "$USE_GDB" = "y" ]; then
323 if [ "$HOST" = "n" ]; then
324 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100325 else
326 if [ `uname` = "Darwin" ]; then
327 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700328 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100329 DALVIKVM=
330 else
331 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700332 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100333 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
334 # gdbargs="--annotate=3 $gdbargs"
335 fi
336 fi
337fi
338
339if [ "$INTERPRETER" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000340 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700341 if [ "$VERIFY" = "y" ] ; then
Richard Uhlerf4b34872016-04-13 11:03:46 -0700342 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=interpret-only"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700343 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700344 elif [ "$VERIFY" = "s" ]; then
Richard Uhlerf4b34872016-04-13 11:03:46 -0700345 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-at-runtime"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700346 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
347 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
348 else # VERIFY = "n"
Richard Uhlerf4b34872016-04-13 11:03:46 -0700349 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-none"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700350 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
351 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
352 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100353fi
354
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800355if [ "$JIT" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000356 INT_OPTS="-Xusejit:true"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800357 if [ "$VERIFY" = "y" ] ; then
Richard Uhlerf4b34872016-04-13 11:03:46 -0700358 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-at-runtime"
Mathieu Chartiere86deef2015-03-19 13:43:37 -0700359 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800360 else
Richard Uhlerf4b34872016-04-13 11:03:46 -0700361 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-none"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800362 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
363 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
364 fi
365fi
366
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100367JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
368
369if [ "$RELOCATE" = "y" ]; then
370 COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information --runtime-arg -Xnorelocate"
371 FLAGS="${FLAGS} -Xrelocate -Xcompiler-option --include-patch-information"
372 if [ "$HOST" = "y" ]; then
373 # Run test sets a fairly draconian ulimit that we will likely blow right over
374 # since we are relocating. Get the total size of the /system/framework directory
375 # in 512 byte blocks and set it as the ulimit. This should be more than enough
376 # room.
377 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
Alex Lightd26b7e42016-04-08 09:44:54 -0700378 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 +0100379 fi
380 fi
381else
382 FLAGS="$FLAGS -Xnorelocate"
383 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
Mathieu Chartiercae2ed92015-06-09 13:02:50 -0700384 if [ "$HOST" = "y" ]; then
385 # Increase ulimit to 64MB in case we are running hprof test.
386 ulimit -S 64000 || exit 1
387 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100388fi
389
390if [ "$HOST" = "n" ]; then
391 ISA=$(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
392 if [ x"$ISA" = "x" ]; then
393 echo "Unable to determine architecture"
394 exit 1
395 fi
396fi
397
398dex2oat_cmdline="true"
Alex Lightafb5d192016-05-24 15:57:45 -0700399mkdir_locations="${DEX_LOCATION}/dalvik-cache/$ISA"
Richard Uhler76f5cb62016-04-04 13:30:16 -0700400strip_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100401
Mathieu Chartier92ec5942016-04-11 12:03:48 -0700402# Pick a base that will force the app image to get relocated.
403app_image="--base=0x4000 --app-image-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.art"
Jeff Haodcdc85b2015-12-04 14:06:18 -0800404
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100405if [ "$PREBUILD" = "y" ]; then
Alex Lightafb5d192016-05-24 15:57:45 -0700406 mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/oat/$ISA"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000407 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100408 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000409 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100410 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
Andreas Gampe14759242016-03-23 10:54:21 -0700411 --oat-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.odex \
Jeff Haodcdc85b2015-12-04 14:06:18 -0800412 ${app_image} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100413 --instruction-set=$ISA"
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700414 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
415 dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
416 fi
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700417
418 # Add in a timeout. This is important for testing the compilation/verification time of
419 # pathological cases.
420 # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
421 # now. We should try to improve this.
422 # The current value is rather arbitrary. run-tests should compile quickly.
423 if [ "$HOST" != "n" ]; then
424 # Use SIGRTMIN+2 to try to dump threads.
425 # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
426 dex2oat_cmdline="timeout -k 1m -s SIGRTMIN+2 1m ${dex2oat_cmdline}"
427 fi
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700428fi
429
Richard Uhler76f5cb62016-04-04 13:30:16 -0700430if [ "$STRIP_DEX" = "y" ]; then
431 strip_cmdline="zip --quiet --delete $DEX_LOCATION/$TEST_NAME.jar classes.dex"
432fi
433
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700434DALVIKVM_ISA_FEATURES_ARGS=""
435if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
436 DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100437fi
438
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000439# java.io.tmpdir can only be set at launch time.
440TMP_DIR_OPTION=""
441if [ "$HOST" = "n" ]; then
442 TMP_DIR_OPTION="-Djava.io.tmpdir=/data/local/tmp"
443fi
444
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000445# We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
446# b/27185632
447# b/24664297
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000448dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100449 $GDB_ARGS \
450 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700451 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100452 -XXlib:$LIB \
453 $PATCHOAT \
454 $DEX2OAT \
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700455 $DALVIKVM_ISA_FEATURES_ARGS \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100456 $ZYGOTE \
457 $JNI_OPTS \
458 $INT_OPTS \
459 $DEBUGGER_OPTS \
460 $DALVIKVM_BOOT_OPT \
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000461 $TMP_DIR_OPTION \
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000462 -XX:DumpNativeStackOnSigQuit:false \
Mathieu Chartier031768a2015-08-27 10:25:02 -0700463 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100464
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -0800465# Remove whitespace.
466dex2oat_cmdline=$(echo $dex2oat_cmdline)
467dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100468
469if [ "$HOST" = "n" ]; then
470 adb root > /dev/null
471 adb wait-for-device
472 if [ "$QUIET" = "n" ]; then
473 adb shell rm -r $DEX_LOCATION
474 adb shell mkdir -p $DEX_LOCATION
475 adb push $TEST_NAME.jar $DEX_LOCATION
476 adb push $TEST_NAME-ex.jar $DEX_LOCATION
477 else
478 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
479 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
480 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
481 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
482 fi
483
Colin Crossafd3c9e2016-09-16 13:47:21 -0700484 LD_LIBRARY_PATH=/data/$TEST_DIRECTORY/art/$ISA
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000485 if [ "$ANDROID_ROOT" != "/system" ]; then
486 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
487 # so we can only use LD_LIBRARY_PATH when testing on a local
488 # installation.
Alex Light7233c7e2016-07-28 10:07:45 -0700489 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY:$LD_LIBRARY_PATH
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000490 fi
491
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700492 PUBLIC_LIBS=libart.so:libartd.so
493
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100494 # Create a script with the command. The command can get longer than the longest
495 # allowed adb command and there is no way to get the exit status from a adb shell
496 # command.
497 cmdline="cd $DEX_LOCATION && \
498 export ANDROID_DATA=$DEX_LOCATION && \
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700499 export ANDROID_ADDITIONAL_PUBLIC_LIBRARIES=$PUBLIC_LIBS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100500 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000501 export ANDROID_ROOT=$ANDROID_ROOT && \
Alex Lightafb5d192016-05-24 15:57:45 -0700502 mkdir -p ${mkdir_locations} && \
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100503 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray4f7fdd22015-04-24 11:57:37 +0100504 export PATH=$ANDROID_ROOT/bin:$PATH && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100505 $dex2oat_cmdline && \
Richard Uhler76f5cb62016-04-04 13:30:16 -0700506 $strip_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100507 $dalvikvm_cmdline"
508
509 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
510 echo "$cmdline" > $cmdfile
511
512 if [ "$DEV_MODE" = "y" ]; then
513 echo $cmdline
514 fi
515
516 if [ "$QUIET" = "n" ]; then
517 adb push $cmdfile $DEX_LOCATION/cmdline.sh
518 else
519 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
520 fi
521
522 adb shell sh $DEX_LOCATION/cmdline.sh
523
524 rm -f $cmdfile
525else
526 export ANDROID_PRINTF_LOG=brief
Andreas Gampea8780822015-03-13 19:51:09 -0700527
528 # By default, and for prebuild dex2oat, we are interested in errors being logged. In dev mode
529 # we want debug messages.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100530 if [ "$DEV_MODE" = "y" ]; then
531 export ANDROID_LOG_TAGS='*:d'
532 else
Andreas Gampee4301ff2015-02-17 19:25:29 -0800533 export ANDROID_LOG_TAGS='*:e'
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100534 fi
Andreas Gampea8780822015-03-13 19:51:09 -0700535
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100536 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000537 export ANDROID_ROOT="${ANDROID_ROOT}"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700538 export LD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
539 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100540 export PATH="$PATH:${ANDROID_ROOT}/bin"
541
David Srbeckyc9ede382015-06-20 06:03:53 +0100542 # Temporarily disable address space layout randomization (ASLR).
543 # This is needed on the host so that the linker loads core.oat at the necessary address.
544 export LD_USE_LOAD_BIAS=1
545
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100546 cmdline="$dalvikvm_cmdline"
547
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700548 if [ "$TIME_OUT" = "gdb" ]; then
549 if [ `uname` = "Darwin" ]; then
550 # Fall back to timeout on Mac.
551 TIME_OUT="timeout"
Hiroshi Yamauchic823eff2015-09-01 16:21:35 -0700552 elif [ "$ISA" = "x86" ]; then
553 # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
554 TIME_OUT="timeout"
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700555 else
556 # Check if gdb is available.
557 gdb --eval-command="quit" > /dev/null 2>&1
558 if [ $? != 0 ]; then
559 # gdb isn't available. Fall back to timeout.
560 TIME_OUT="timeout"
561 fi
562 fi
563 fi
564
565 if [ "$TIME_OUT" = "timeout" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100566 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -0800567 #
Andreas Gampe6fb92562016-08-01 21:53:57 -0700568 # Note: We first send SIGRTMIN+2 (usually 36) to ART, which will induce a full thread dump
569 # before abort. However, dumping threads might deadlock, so we also use the "-k"
570 # option to definitely kill the child.
571 cmdline="timeout -k 120s -s SIGRTMIN+2 ${TIME_OUT_VALUE}s $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100572 fi
573
574 if [ "$DEV_MODE" = "y" ]; then
Alex Lightafb5d192016-05-24 15:57:45 -0700575 echo "mkdir -p ${mkdir_locations} && $dex2oat_cmdline && $strip_cmdline && $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100576 fi
577
578 cd $ANDROID_BUILD_TOP
579
David Srbecky2e4afe82016-01-27 18:42:06 +0000580 rm -rf ${DEX_LOCATION}/dalvik-cache/
Alex Lightafb5d192016-05-24 15:57:45 -0700581 mkdir -p ${mkdir_locations} || exit 1
Andreas Gampea8780822015-03-13 19:51:09 -0700582 $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Richard Uhler76f5cb62016-04-04 13:30:16 -0700583 $strip_cmdline || { echo "Strip failed." >&2 ; exit 3; }
Andreas Gampea8780822015-03-13 19:51:09 -0700584
585 # For running, we must turn off logging when dex2oat or patchoat are missing. Otherwise we use
586 # the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
587 if [ "$DEV_MODE" = "y" ]; then
588 export ANDROID_LOG_TAGS='*:d'
589 elif [ "$USE_DEX2OAT_AND_PATCHOAT" = "n" ]; then
590 # All tests would log the error of failing dex2oat/patchoat. Be silent here and only
591 # log fatal events.
592 export ANDROID_LOG_TAGS='*:s'
593 else
594 # We are interested in LOG(ERROR) output.
595 export ANDROID_LOG_TAGS='*:e'
596 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100597
598 if [ "$USE_GDB" = "y" ]; then
599 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700600 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100601 else
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700602 if [ "$TIME_OUT" != "gdb" ]; then
603 trap 'kill -INT -$pid' INT
604 $cmdline "$@" 2>&1 & pid=$!
605 wait $pid
606 # Add extra detail if time out is enabled.
607 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
608 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
609 fi
610 else
611 # With a thread dump that uses gdb if a timeout.
612 trap 'kill -INT -$pid' INT
613 $cmdline "$@" 2>&1 & pid=$!
614 # Spawn a watcher process.
615 ( sleep $TIME_OUT_VALUE && \
616 echo "##### Thread dump using gdb on test timeout" && \
617 ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
618 --eval-command="call exit(124)" --eval-command=quit || \
619 kill $pid )) 2> /dev/null & watcher=$!
620 wait $pid
621 test_exit_status=$?
622 pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
623 if [ $test_exit_status = 0 ]; then
624 # The test finished normally.
625 exit 0
626 else
627 # The test failed or timed out.
628 if [ $test_exit_status = 124 ]; then
629 # The test timed out.
630 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
631 fi
632 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100633 fi
634 fi
635fi