blob: f3958662df9faf43a2641187d607375a6a707925 [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
Hiroshi Yamauchia9b296c2016-10-07 17:07:03 -070047 TIME_OUT_VALUE=2400 # 40 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=""
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -070059EXTERNAL_LOG_TAGS="n" # if y respect externally set ANDROID_LOG_TAGS.
60DRY_RUN="n" # if y prepare to run the test but don't run it.
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +000061TEST_VDEX="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010062
63while true; do
64 if [ "x$1" = "x--quiet" ]; then
65 QUIET="y"
66 shift
Alex Lightfaf90b62016-08-12 14:43:48 -070067 elif [ "x$1" = "x-O" ]; then
68 # Ignore this option.
69 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010070 elif [ "x$1" = "x--lib" ]; then
71 shift
72 if [ "x$1" = "x" ]; then
73 echo "$0 missing argument to --lib" 1>&2
74 exit 1
75 fi
76 LIB="$1"
77 shift
Alex Light97acf192016-03-17 09:59:38 -070078 elif [ "x$1" = "x--gc-stress" ]; then
79 # Give an extra 5 mins if we are gc-stress.
80 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + 300))
81 shift
Mathieu Chartier031768a2015-08-27 10:25:02 -070082 elif [ "x$1" = "x--testlib" ]; then
83 shift
84 if [ "x$1" = "x" ]; then
85 echo "$0 missing argument to --testlib" 1>&2
86 exit 1
87 fi
Mathieu Chartierde286fd2015-09-03 18:10:29 -070088 ARGS="${ARGS} $1"
Mathieu Chartier031768a2015-08-27 10:25:02 -070089 shift
David Srbecky52886112016-01-22 13:56:47 +000090 elif [ "x$1" = "x--args" ]; then
91 shift
92 if [ "x$1" = "x" ]; then
93 echo "$0 missing argument to --args" 1>&2
94 exit 1
95 fi
96 ARGS="${ARGS} $1"
97 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010098 elif [ "x$1" = "x-Xcompiler-option" ]; then
99 shift
100 option="$1"
101 FLAGS="${FLAGS} -Xcompiler-option $option"
102 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
103 shift
Alex Light7233c7e2016-07-28 10:07:45 -0700104 elif [ "x$1" = "x--android-runtime-option" ]; then
105 shift
106 option="$1"
107 ANDROID_FLAGS="${ANDROID_FLAGS} $option"
108 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100109 elif [ "x$1" = "x--runtime-option" ]; then
110 shift
111 option="$1"
112 FLAGS="${FLAGS} $option"
113 shift
114 elif [ "x$1" = "x--boot" ]; then
115 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000116 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100117 shift
118 elif [ "x$1" = "x--no-dex2oat" ]; then
119 DEX2OAT="-Xcompiler:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800120 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100121 shift
122 elif [ "x$1" = "x--no-patchoat" ]; then
123 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800124 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100125 shift
126 elif [ "x$1" = "x--relocate" ]; then
127 RELOCATE="y"
128 shift
129 elif [ "x$1" = "x--no-relocate" ]; then
130 RELOCATE="n"
131 shift
132 elif [ "x$1" = "x--prebuild" ]; then
133 PREBUILD="y"
134 shift
Richard Uhler76f5cb62016-04-04 13:30:16 -0700135 elif [ "x$1" = "x--strip-dex" ]; then
136 STRIP_DEX="y"
137 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100138 elif [ "x$1" = "x--host" ]; then
139 HOST="y"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000140 ANDROID_ROOT="$ANDROID_HOST_OUT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100141 shift
142 elif [ "x$1" = "x--no-prebuild" ]; then
143 PREBUILD="n"
144 shift
145 elif [ "x$1" = "x--no-image" ]; then
146 HAVE_IMAGE="n"
147 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700148 elif [ "x$1" = "x--secondary" ]; then
149 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
Calin Juravle175dc732015-08-25 15:42:32 +0100150 # Enable cfg-append to make sure we get the dump for both dex files.
151 # (otherwise the runtime compilation of the secondary dex will overwrite
Roland Levillainb0103ca2016-11-01 14:48:47 +0000152 # the dump of the first one).
Calin Juravle175dc732015-08-25 15:42:32 +0100153 FLAGS="${FLAGS} -Xcompiler-option --dump-cfg-append"
154 COMPILE_FLAGS="${COMPILE_FLAGS} --dump-cfg-append"
Jeff Hao207a37d2014-10-29 17:24:25 -0700155 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100156 elif [ "x$1" = "x--debug" ]; then
157 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800158 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100159 shift
160 elif [ "x$1" = "x--gdb" ]; then
161 USE_GDB="y"
162 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800163 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100164 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700165 elif [ "x$1" = "x--gdb-arg" ]; then
166 shift
167 gdb_arg="$1"
168 GDB_ARGS="${GDB_ARGS} $gdb_arg"
169 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100170 elif [ "x$1" = "x--zygote" ]; then
171 ZYGOTE="-Xzygote"
172 msg "Spawning from zygote"
173 shift
174 elif [ "x$1" = "x--dev" ]; then
175 DEV_MODE="y"
176 shift
177 elif [ "x$1" = "x--interpreter" ]; then
178 INTERPRETER="y"
179 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800180 elif [ "x$1" = "x--jit" ]; then
181 JIT="y"
182 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100183 elif [ "x$1" = "x--jvm" ]; then
184 USE_JVM="y"
185 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100186 elif [ "x$1" = "x--invoke-with" ]; then
187 shift
188 if [ "x$1" = "x" ]; then
189 echo "$0 missing argument to --invoke-with" 1>&2
190 exit 1
191 fi
192 if [ "x$INVOKE_WITH" = "x" ]; then
193 INVOKE_WITH="$1"
194 else
195 INVOKE_WITH="$INVOKE_WITH $1"
196 fi
197 shift
198 elif [ "x$1" = "x--no-verify" ]; then
199 VERIFY="n"
200 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700201 elif [ "x$1" = "x--verify-soft-fail" ]; then
202 VERIFY="s"
203 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100204 elif [ "x$1" = "x--no-optimize" ]; then
205 OPTIMIZE="n"
206 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000207 elif [ "x$1" = "x--android-root" ]; then
208 shift
209 ANDROID_ROOT="$1"
210 shift
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700211 elif [ "x$1" = "x--instruction-set-features" ]; then
212 shift
213 INSTRUCTION_SET_FEATURES="$1"
214 shift
Mathieu Chartier2576be22016-05-24 10:24:53 -0700215 elif [ "x$1" = "x--timeout" ]; then
216 shift
217 TIME_OUT_VALUE="$1"
218 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100219 elif [ "x$1" = "x--" ]; then
220 shift
221 break
222 elif [ "x$1" = "x--64" ]; then
223 ISA="x86_64"
224 GDB_SERVER="gdbserver64"
225 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000226 LIBRARY_DIRECTORY="lib64"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700227 TEST_DIRECTORY="nativetest64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100228 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
229 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700230 elif [ "x$1" = "x--pic-test" ]; then
231 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
232 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
233 shift
Alex Light8a0e0332015-10-26 10:11:58 -0700234 elif [ "x$1" = "x--experimental" ]; then
235 if [ "$#" -lt 2 ]; then
236 echo "missing --experimental option" 1>&2
237 exit 1
238 fi
239 EXPERIMENTAL="$EXPERIMENTAL $2"
240 shift 2
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700241 elif [ "x$1" = "x--external-log-tags" ]; then
242 EXTERNAL_LOG_TAGS="y"
243 shift
244 elif [ "x$1" = "x--dry-run" ]; then
245 DRY_RUN="y"
246 shift
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000247 elif [ "x$1" = "x--vdex" ]; then
248 TEST_VDEX="y"
249 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100250 elif expr "x$1" : "x--" >/dev/null 2>&1; then
251 echo "unknown $0 option: $1" 1>&2
252 exit 1
253 else
254 break
255 fi
256done
257
Alex Light8a0e0332015-10-26 10:11:58 -0700258if [ "$USE_JVM" = "n" ]; then
Alex Light7233c7e2016-07-28 10:07:45 -0700259 FLAGS="${FLAGS} ${ANDROID_FLAGS}"
Alex Light8a0e0332015-10-26 10:11:58 -0700260 for feature in ${EXPERIMENTAL}; do
Alex Lightfa022852015-10-28 09:13:20 -0700261 FLAGS="${FLAGS} -Xexperimental:${feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:${feature}"
Alex Light8a0e0332015-10-26 10:11:58 -0700262 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xexperimental:${feature}"
263 done
264fi
265
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100266if [ "x$1" = "x" ] ; then
267 MAIN="Main"
268else
269 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700270 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100271fi
272
273if [ "$ZYGOTE" = "" ]; then
274 if [ "$OPTIMIZE" = "y" ]; then
275 if [ "$VERIFY" = "y" ]; then
276 DEX_OPTIMIZE="-Xdexopt:verified"
277 else
278 DEX_OPTIMIZE="-Xdexopt:all"
279 fi
280 msg "Performing optimizations"
281 else
282 DEX_OPTIMIZE="-Xdexopt:none"
283 msg "Skipping optimizations"
284 fi
285
286 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100287 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100288 msg "Performing verification"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700289 elif [ "$VERIFY" = "s" ]; then
290 JVM_VERIFY_ARG="Xverify:all"
291 DEX_VERIFY="-Xverify:softfail"
292 msg "Forcing verification to be soft fail"
293 else # VERIFY = "n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100294 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100295 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100296 msg "Skipping verification"
297 fi
298fi
299
300msg "------------------------------"
301
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100302if [ "$DEBUGGER" = "y" ]; then
303 # Use this instead for ddms and connect by running 'ddms':
304 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
305 # TODO: add a separate --ddms option?
306
307 PORT=12345
308 msg "Waiting for jdb to connect:"
309 if [ "$HOST" = "n" ]; then
310 msg " adb forward tcp:$PORT tcp:$PORT"
311 fi
312 msg " jdb -attach localhost:$PORT"
313 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
314fi
315
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100316if [ "$USE_JVM" = "y" ]; then
Alex Light9c20a142016-08-23 15:05:12 -0700317 export LD_LIBRARY_PATH=${ANDROID_HOST_OUT}/lib64
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700318 # Xmx is necessary since we don't pass down the ART flags to JVM.
Vladimir Markoc5798bf2016-12-09 10:20:54 +0000319 # We pass the classes2 path whether it's used (src-multidex) or not.
320 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes:classes2 ${FLAGS} $MAIN $@ ${ARGS}"
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700321 if [ "$DEV_MODE" = "y" ]; then
322 echo $cmdline
323 fi
324 $cmdline
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100325 exit
326fi
327
328
329if [ "$HAVE_IMAGE" = "n" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000330 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000331else
332 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100333fi
334
335
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100336if [ "$USE_GDB" = "y" ]; then
337 if [ "$HOST" = "n" ]; then
338 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100339 else
340 if [ `uname` = "Darwin" ]; then
341 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700342 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100343 DALVIKVM=
344 else
345 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700346 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100347 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
348 # gdbargs="--annotate=3 $gdbargs"
349 fi
350 fi
351fi
352
353if [ "$INTERPRETER" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000354 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700355 if [ "$VERIFY" = "y" ] ; then
Richard Uhlerf4b34872016-04-13 11:03:46 -0700356 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=interpret-only"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700357 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700358 elif [ "$VERIFY" = "s" ]; then
Richard Uhlerf4b34872016-04-13 11:03:46 -0700359 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-at-runtime"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700360 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
361 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
362 else # VERIFY = "n"
Richard Uhlerf4b34872016-04-13 11:03:46 -0700363 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-none"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700364 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
365 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
366 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100367fi
368
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800369if [ "$JIT" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000370 INT_OPTS="-Xusejit:true"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800371 if [ "$VERIFY" = "y" ] ; then
Calin Juravle3a3e4c12016-11-28 13:02:02 +0000372 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=interpret-only"
373 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800374 else
Richard Uhlerf4b34872016-04-13 11:03:46 -0700375 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-none"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800376 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
377 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
378 fi
379fi
380
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100381JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
382
383if [ "$RELOCATE" = "y" ]; then
384 COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information --runtime-arg -Xnorelocate"
385 FLAGS="${FLAGS} -Xrelocate -Xcompiler-option --include-patch-information"
386 if [ "$HOST" = "y" ]; then
387 # Run test sets a fairly draconian ulimit that we will likely blow right over
388 # since we are relocating. Get the total size of the /system/framework directory
389 # in 512 byte blocks and set it as the ulimit. This should be more than enough
390 # room.
391 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
Alex Lightd26b7e42016-04-08 09:44:54 -0700392 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 +0100393 fi
394 fi
395else
396 FLAGS="$FLAGS -Xnorelocate"
397 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
Mathieu Chartiercae2ed92015-06-09 13:02:50 -0700398 if [ "$HOST" = "y" ]; then
399 # Increase ulimit to 64MB in case we are running hprof test.
400 ulimit -S 64000 || exit 1
401 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100402fi
403
404if [ "$HOST" = "n" ]; then
Nicolas Geoffrayd295bc82016-11-04 13:03:05 +0000405 # Need to be root to query /data/dalvik-cache
406 adb root > /dev/null
407 adb wait-for-device
408 ISA=
409 ISA_adb_invocation=
410 ISA_outcome=
411 # We iterate a few times to workaround an adb issue. b/32655576
412 for i in {1..10}; do
413 ISA_adb_invocation=$(adb shell ls -F /data/dalvik-cache)
414 ISA_outcome=$?
415 ISA=$(echo $ISA_adb_invocation | grep -Ewo "${ARCHITECTURES_PATTERN}")
416 if [ x"$ISA" != "x" ]; then
417 break;
418 fi
419 done
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100420 if [ x"$ISA" = "x" ]; then
421 echo "Unable to determine architecture"
Nicolas Geoffray8f500fa2016-11-03 11:18:48 +0000422 # Print a few things for helping diagnosing the problem.
Nicolas Geoffrayd295bc82016-11-04 13:03:05 +0000423 echo "adb invocation output: $ISA_adb_invocation"
424 echo "adb invocation outcome: $ISA_outcome"
Nicolas Geoffray8f500fa2016-11-03 11:18:48 +0000425 echo $(adb shell ls -F /data/dalvik-cache)
426 echo $(adb shell ls /data/dalvik-cache)
427 echo ${ARCHITECTURES_PATTERN}
428 echo $(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100429 exit 1
430 fi
431fi
432
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700433# Prevent test from silently falling back to interpreter in no-prebuild mode. This happens
434# when DEX_LOCATION path is too long, because vdex/odex filename is constructed by taking
435# full path to dex, stripping leading '/', appending '@classes.vdex' and changing every
436# remaining '/' into '@'.
437if [ "$HOST" = "y" ]; then
438 max_filename_size=$(getconf NAME_MAX $DEX_LOCATION)
439else
440 # There is no getconf on device, fallback to standard value. See NAME_MAX in kernel <linux/limits.h>
441 max_filename_size=255
442fi
443# Compute VDEX_NAME.
444DEX_LOCATION_STRIPPED="${DEX_LOCATION#/}"
445VDEX_NAME="${DEX_LOCATION_STRIPPED//\//@}@$TEST_NAME.jar@classes.vdex"
446if [ ${#VDEX_NAME} -gt $max_filename_size ]; then
447 echo "Dex location path too long."
448 exit 1
449fi
450
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100451dex2oat_cmdline="true"
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000452vdex_cmdline="true"
Alex Lightafb5d192016-05-24 15:57:45 -0700453mkdir_locations="${DEX_LOCATION}/dalvik-cache/$ISA"
Richard Uhler76f5cb62016-04-04 13:30:16 -0700454strip_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100455
Vladimir Markoad0c8bd2016-12-19 19:31:26 +0000456# Pick a base that will force the app image to get relocated.
457app_image="--base=0x4000 --app-image-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.art"
Jeff Haodcdc85b2015-12-04 14:06:18 -0800458
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100459if [ "$PREBUILD" = "y" ]; then
Alex Lightafb5d192016-05-24 15:57:45 -0700460 mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/oat/$ISA"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000461 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100462 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000463 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100464 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
Andreas Gampe14759242016-03-23 10:54:21 -0700465 --oat-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.odex \
Jeff Haodcdc85b2015-12-04 14:06:18 -0800466 ${app_image} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100467 --instruction-set=$ISA"
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700468 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
469 dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
470 fi
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700471
472 # Add in a timeout. This is important for testing the compilation/verification time of
473 # pathological cases.
474 # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
475 # now. We should try to improve this.
476 # The current value is rather arbitrary. run-tests should compile quickly.
477 if [ "$HOST" != "n" ]; then
478 # Use SIGRTMIN+2 to try to dump threads.
479 # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
480 dex2oat_cmdline="timeout -k 1m -s SIGRTMIN+2 1m ${dex2oat_cmdline}"
481 fi
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000482 if [ "$TEST_VDEX" = "y" ]; then
483 vdex_cmdline="${dex2oat_cmdline} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
484 fi
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700485fi
486
Richard Uhler76f5cb62016-04-04 13:30:16 -0700487if [ "$STRIP_DEX" = "y" ]; then
488 strip_cmdline="zip --quiet --delete $DEX_LOCATION/$TEST_NAME.jar classes.dex"
489fi
490
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700491DALVIKVM_ISA_FEATURES_ARGS=""
492if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
493 DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100494fi
495
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000496# java.io.tmpdir can only be set at launch time.
497TMP_DIR_OPTION=""
498if [ "$HOST" = "n" ]; then
499 TMP_DIR_OPTION="-Djava.io.tmpdir=/data/local/tmp"
500fi
501
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000502# We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
503# b/27185632
504# b/24664297
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000505dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100506 $GDB_ARGS \
507 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700508 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100509 -XXlib:$LIB \
510 $PATCHOAT \
511 $DEX2OAT \
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700512 $DALVIKVM_ISA_FEATURES_ARGS \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100513 $ZYGOTE \
514 $JNI_OPTS \
515 $INT_OPTS \
516 $DEBUGGER_OPTS \
517 $DALVIKVM_BOOT_OPT \
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000518 $TMP_DIR_OPTION \
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000519 -XX:DumpNativeStackOnSigQuit:false \
Mathieu Chartier031768a2015-08-27 10:25:02 -0700520 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100521
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -0800522# Remove whitespace.
523dex2oat_cmdline=$(echo $dex2oat_cmdline)
524dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000525vdex_cmdline=$(echo $vdex_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100526
527if [ "$HOST" = "n" ]; then
528 adb root > /dev/null
529 adb wait-for-device
530 if [ "$QUIET" = "n" ]; then
531 adb shell rm -r $DEX_LOCATION
532 adb shell mkdir -p $DEX_LOCATION
533 adb push $TEST_NAME.jar $DEX_LOCATION
534 adb push $TEST_NAME-ex.jar $DEX_LOCATION
535 else
536 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
537 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
538 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
539 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
540 fi
541
Colin Crossafd3c9e2016-09-16 13:47:21 -0700542 LD_LIBRARY_PATH=/data/$TEST_DIRECTORY/art/$ISA
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000543 if [ "$ANDROID_ROOT" != "/system" ]; then
544 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
545 # so we can only use LD_LIBRARY_PATH when testing on a local
546 # installation.
Alex Light7233c7e2016-07-28 10:07:45 -0700547 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY:$LD_LIBRARY_PATH
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000548 fi
549
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700550 PUBLIC_LIBS=libart.so:libartd.so
551
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100552 # Create a script with the command. The command can get longer than the longest
553 # allowed adb command and there is no way to get the exit status from a adb shell
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700554 # command. Dalvik cache is cleaned before running to make subsequent executions
555 # of the script follow the same runtime path.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100556 cmdline="cd $DEX_LOCATION && \
557 export ANDROID_DATA=$DEX_LOCATION && \
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700558 export ANDROID_ADDITIONAL_PUBLIC_LIBRARIES=$PUBLIC_LIBS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100559 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000560 export ANDROID_ROOT=$ANDROID_ROOT && \
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700561 rm -rf ${DEX_LOCATION}/dalvik-cache/ && \
Alex Lightafb5d192016-05-24 15:57:45 -0700562 mkdir -p ${mkdir_locations} && \
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100563 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray4f7fdd22015-04-24 11:57:37 +0100564 export PATH=$ANDROID_ROOT/bin:$PATH && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100565 $dex2oat_cmdline && \
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000566 $vdex_cmdline && \
Richard Uhler76f5cb62016-04-04 13:30:16 -0700567 $strip_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100568 $dalvikvm_cmdline"
569
570 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
571 echo "$cmdline" > $cmdfile
572
573 if [ "$DEV_MODE" = "y" ]; then
574 echo $cmdline
575 fi
576
577 if [ "$QUIET" = "n" ]; then
578 adb push $cmdfile $DEX_LOCATION/cmdline.sh
579 else
580 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
581 fi
582
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700583 if [ "$DRY_RUN" != "y" ]; then
584 adb shell sh $DEX_LOCATION/cmdline.sh
585 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100586
587 rm -f $cmdfile
588else
589 export ANDROID_PRINTF_LOG=brief
Andreas Gampea8780822015-03-13 19:51:09 -0700590
591 # By default, and for prebuild dex2oat, we are interested in errors being logged. In dev mode
592 # we want debug messages.
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700593 if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
594 if [ "$DEV_MODE" = "y" ]; then
595 export ANDROID_LOG_TAGS='*:d'
596 else
597 export ANDROID_LOG_TAGS='*:e'
598 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100599 fi
Andreas Gampea8780822015-03-13 19:51:09 -0700600
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100601 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000602 export ANDROID_ROOT="${ANDROID_ROOT}"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700603 export LD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
604 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100605 export PATH="$PATH:${ANDROID_ROOT}/bin"
606
David Srbeckyc9ede382015-06-20 06:03:53 +0100607 # Temporarily disable address space layout randomization (ASLR).
608 # This is needed on the host so that the linker loads core.oat at the necessary address.
609 export LD_USE_LOAD_BIAS=1
610
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100611 cmdline="$dalvikvm_cmdline"
612
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700613 if [ "$TIME_OUT" = "gdb" ]; then
614 if [ `uname` = "Darwin" ]; then
615 # Fall back to timeout on Mac.
616 TIME_OUT="timeout"
Hiroshi Yamauchic823eff2015-09-01 16:21:35 -0700617 elif [ "$ISA" = "x86" ]; then
618 # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
619 TIME_OUT="timeout"
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700620 else
621 # Check if gdb is available.
622 gdb --eval-command="quit" > /dev/null 2>&1
623 if [ $? != 0 ]; then
624 # gdb isn't available. Fall back to timeout.
625 TIME_OUT="timeout"
626 fi
627 fi
628 fi
629
630 if [ "$TIME_OUT" = "timeout" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100631 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -0800632 #
Andreas Gampe6fb92562016-08-01 21:53:57 -0700633 # Note: We first send SIGRTMIN+2 (usually 36) to ART, which will induce a full thread dump
634 # before abort. However, dumping threads might deadlock, so we also use the "-k"
635 # option to definitely kill the child.
636 cmdline="timeout -k 120s -s SIGRTMIN+2 ${TIME_OUT_VALUE}s $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100637 fi
638
639 if [ "$DEV_MODE" = "y" ]; then
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000640 echo "mkdir -p ${mkdir_locations} && $dex2oat_cmdline && $vdex_cmdline && $strip_cmdline && $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100641 fi
642
643 cd $ANDROID_BUILD_TOP
644
David Srbecky2e4afe82016-01-27 18:42:06 +0000645 rm -rf ${DEX_LOCATION}/dalvik-cache/
Alex Lightafb5d192016-05-24 15:57:45 -0700646 mkdir -p ${mkdir_locations} || exit 1
Andreas Gampea8780822015-03-13 19:51:09 -0700647 $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000648 $vdex_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Richard Uhler76f5cb62016-04-04 13:30:16 -0700649 $strip_cmdline || { echo "Strip failed." >&2 ; exit 3; }
Andreas Gampea8780822015-03-13 19:51:09 -0700650
651 # For running, we must turn off logging when dex2oat or patchoat are missing. Otherwise we use
652 # the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700653 if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
654 if [ "$DEV_MODE" = "y" ]; then
655 export ANDROID_LOG_TAGS='*:d'
656 elif [ "$USE_DEX2OAT_AND_PATCHOAT" = "n" ]; then
657 # All tests would log the error of failing dex2oat/patchoat. Be silent here and only
658 # log fatal events.
659 export ANDROID_LOG_TAGS='*:s'
660 else
661 # We are interested in LOG(ERROR) output.
662 export ANDROID_LOG_TAGS='*:e'
663 fi
664 fi
665
666 if [ "$DRY_RUN" = "y" ]; then
667 exit 0
Andreas Gampea8780822015-03-13 19:51:09 -0700668 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100669
670 if [ "$USE_GDB" = "y" ]; then
671 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700672 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100673 else
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700674 if [ "$TIME_OUT" != "gdb" ]; then
675 trap 'kill -INT -$pid' INT
676 $cmdline "$@" 2>&1 & pid=$!
677 wait $pid
678 # Add extra detail if time out is enabled.
679 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
680 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
681 fi
682 else
683 # With a thread dump that uses gdb if a timeout.
684 trap 'kill -INT -$pid' INT
685 $cmdline "$@" 2>&1 & pid=$!
686 # Spawn a watcher process.
687 ( sleep $TIME_OUT_VALUE && \
688 echo "##### Thread dump using gdb on test timeout" && \
689 ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
690 --eval-command="call exit(124)" --eval-command=quit || \
691 kill $pid )) 2> /dev/null & watcher=$!
692 wait $pid
693 test_exit_status=$?
694 pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
695 if [ $test_exit_status = 0 ]; then
696 # The test finished normally.
697 exit 0
698 else
699 # The test failed or timed out.
700 if [ $test_exit_status = 124 ]; then
701 # The test timed out.
702 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
703 fi
704 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100705 fi
706 fi
707fi