blob: cf8db151fe02572ae599a42e08d850cfed649cfa [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 Geoffray1a58b7f2014-10-06 12:23:04 +010061
62while true; do
63 if [ "x$1" = "x--quiet" ]; then
64 QUIET="y"
65 shift
Alex Lightfaf90b62016-08-12 14:43:48 -070066 elif [ "x$1" = "x-O" ]; then
67 # Ignore this option.
68 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010069 elif [ "x$1" = "x--lib" ]; then
70 shift
71 if [ "x$1" = "x" ]; then
72 echo "$0 missing argument to --lib" 1>&2
73 exit 1
74 fi
75 LIB="$1"
76 shift
Alex Light97acf192016-03-17 09:59:38 -070077 elif [ "x$1" = "x--gc-stress" ]; then
78 # Give an extra 5 mins if we are gc-stress.
79 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + 300))
80 shift
Mathieu Chartier031768a2015-08-27 10:25:02 -070081 elif [ "x$1" = "x--testlib" ]; then
82 shift
83 if [ "x$1" = "x" ]; then
84 echo "$0 missing argument to --testlib" 1>&2
85 exit 1
86 fi
Mathieu Chartierde286fd2015-09-03 18:10:29 -070087 ARGS="${ARGS} $1"
Mathieu Chartier031768a2015-08-27 10:25:02 -070088 shift
David Srbecky52886112016-01-22 13:56:47 +000089 elif [ "x$1" = "x--args" ]; then
90 shift
91 if [ "x$1" = "x" ]; then
92 echo "$0 missing argument to --args" 1>&2
93 exit 1
94 fi
95 ARGS="${ARGS} $1"
96 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010097 elif [ "x$1" = "x-Xcompiler-option" ]; then
98 shift
99 option="$1"
100 FLAGS="${FLAGS} -Xcompiler-option $option"
101 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
102 shift
Alex Light7233c7e2016-07-28 10:07:45 -0700103 elif [ "x$1" = "x--android-runtime-option" ]; then
104 shift
105 option="$1"
106 ANDROID_FLAGS="${ANDROID_FLAGS} $option"
107 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100108 elif [ "x$1" = "x--runtime-option" ]; then
109 shift
110 option="$1"
111 FLAGS="${FLAGS} $option"
112 shift
113 elif [ "x$1" = "x--boot" ]; then
114 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000115 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100116 shift
117 elif [ "x$1" = "x--no-dex2oat" ]; then
118 DEX2OAT="-Xcompiler:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800119 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100120 shift
121 elif [ "x$1" = "x--no-patchoat" ]; then
122 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800123 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100124 shift
125 elif [ "x$1" = "x--relocate" ]; then
126 RELOCATE="y"
127 shift
128 elif [ "x$1" = "x--no-relocate" ]; then
129 RELOCATE="n"
130 shift
131 elif [ "x$1" = "x--prebuild" ]; then
132 PREBUILD="y"
133 shift
Richard Uhler76f5cb62016-04-04 13:30:16 -0700134 elif [ "x$1" = "x--strip-dex" ]; then
135 STRIP_DEX="y"
136 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100137 elif [ "x$1" = "x--host" ]; then
138 HOST="y"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000139 ANDROID_ROOT="$ANDROID_HOST_OUT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100140 shift
141 elif [ "x$1" = "x--no-prebuild" ]; then
142 PREBUILD="n"
143 shift
144 elif [ "x$1" = "x--no-image" ]; then
145 HAVE_IMAGE="n"
146 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700147 elif [ "x$1" = "x--secondary" ]; then
148 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
Calin Juravle175dc732015-08-25 15:42:32 +0100149 # Enable cfg-append to make sure we get the dump for both dex files.
150 # (otherwise the runtime compilation of the secondary dex will overwrite
Roland Levillainb0103ca2016-11-01 14:48:47 +0000151 # the dump of the first one).
Calin Juravle175dc732015-08-25 15:42:32 +0100152 FLAGS="${FLAGS} -Xcompiler-option --dump-cfg-append"
153 COMPILE_FLAGS="${COMPILE_FLAGS} --dump-cfg-append"
Jeff Hao207a37d2014-10-29 17:24:25 -0700154 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100155 elif [ "x$1" = "x--debug" ]; then
156 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800157 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100158 shift
159 elif [ "x$1" = "x--gdb" ]; then
160 USE_GDB="y"
161 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800162 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100163 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700164 elif [ "x$1" = "x--gdb-arg" ]; then
165 shift
166 gdb_arg="$1"
167 GDB_ARGS="${GDB_ARGS} $gdb_arg"
168 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100169 elif [ "x$1" = "x--zygote" ]; then
170 ZYGOTE="-Xzygote"
171 msg "Spawning from zygote"
172 shift
173 elif [ "x$1" = "x--dev" ]; then
174 DEV_MODE="y"
175 shift
176 elif [ "x$1" = "x--interpreter" ]; then
177 INTERPRETER="y"
178 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800179 elif [ "x$1" = "x--jit" ]; then
180 JIT="y"
181 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100182 elif [ "x$1" = "x--jvm" ]; then
183 USE_JVM="y"
184 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100185 elif [ "x$1" = "x--invoke-with" ]; then
186 shift
187 if [ "x$1" = "x" ]; then
188 echo "$0 missing argument to --invoke-with" 1>&2
189 exit 1
190 fi
191 if [ "x$INVOKE_WITH" = "x" ]; then
192 INVOKE_WITH="$1"
193 else
194 INVOKE_WITH="$INVOKE_WITH $1"
195 fi
196 shift
197 elif [ "x$1" = "x--no-verify" ]; then
198 VERIFY="n"
199 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700200 elif [ "x$1" = "x--verify-soft-fail" ]; then
201 VERIFY="s"
202 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100203 elif [ "x$1" = "x--no-optimize" ]; then
204 OPTIMIZE="n"
205 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000206 elif [ "x$1" = "x--android-root" ]; then
207 shift
208 ANDROID_ROOT="$1"
209 shift
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700210 elif [ "x$1" = "x--instruction-set-features" ]; then
211 shift
212 INSTRUCTION_SET_FEATURES="$1"
213 shift
Mathieu Chartier2576be22016-05-24 10:24:53 -0700214 elif [ "x$1" = "x--timeout" ]; then
215 shift
216 TIME_OUT_VALUE="$1"
217 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100218 elif [ "x$1" = "x--" ]; then
219 shift
220 break
221 elif [ "x$1" = "x--64" ]; then
222 ISA="x86_64"
223 GDB_SERVER="gdbserver64"
224 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000225 LIBRARY_DIRECTORY="lib64"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700226 TEST_DIRECTORY="nativetest64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100227 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
228 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700229 elif [ "x$1" = "x--pic-test" ]; then
230 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
231 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
232 shift
Alex Light8a0e0332015-10-26 10:11:58 -0700233 elif [ "x$1" = "x--experimental" ]; then
234 if [ "$#" -lt 2 ]; then
235 echo "missing --experimental option" 1>&2
236 exit 1
237 fi
238 EXPERIMENTAL="$EXPERIMENTAL $2"
239 shift 2
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700240 elif [ "x$1" = "x--external-log-tags" ]; then
241 EXTERNAL_LOG_TAGS="y"
242 shift
243 elif [ "x$1" = "x--dry-run" ]; then
244 DRY_RUN="y"
245 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100246 elif expr "x$1" : "x--" >/dev/null 2>&1; then
247 echo "unknown $0 option: $1" 1>&2
248 exit 1
249 else
250 break
251 fi
252done
253
Alex Light8a0e0332015-10-26 10:11:58 -0700254if [ "$USE_JVM" = "n" ]; then
Alex Light7233c7e2016-07-28 10:07:45 -0700255 FLAGS="${FLAGS} ${ANDROID_FLAGS}"
Alex Light8a0e0332015-10-26 10:11:58 -0700256 for feature in ${EXPERIMENTAL}; do
Alex Lightfa022852015-10-28 09:13:20 -0700257 FLAGS="${FLAGS} -Xexperimental:${feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:${feature}"
Alex Light8a0e0332015-10-26 10:11:58 -0700258 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xexperimental:${feature}"
259 done
260fi
261
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100262if [ "x$1" = "x" ] ; then
263 MAIN="Main"
264else
265 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700266 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100267fi
268
269if [ "$ZYGOTE" = "" ]; then
270 if [ "$OPTIMIZE" = "y" ]; then
271 if [ "$VERIFY" = "y" ]; then
272 DEX_OPTIMIZE="-Xdexopt:verified"
273 else
274 DEX_OPTIMIZE="-Xdexopt:all"
275 fi
276 msg "Performing optimizations"
277 else
278 DEX_OPTIMIZE="-Xdexopt:none"
279 msg "Skipping optimizations"
280 fi
281
282 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100283 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100284 msg "Performing verification"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700285 elif [ "$VERIFY" = "s" ]; then
286 JVM_VERIFY_ARG="Xverify:all"
287 DEX_VERIFY="-Xverify:softfail"
288 msg "Forcing verification to be soft fail"
289 else # VERIFY = "n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100290 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100291 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100292 msg "Skipping verification"
293 fi
294fi
295
296msg "------------------------------"
297
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100298if [ "$DEBUGGER" = "y" ]; then
299 # Use this instead for ddms and connect by running 'ddms':
300 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
301 # TODO: add a separate --ddms option?
302
303 PORT=12345
304 msg "Waiting for jdb to connect:"
305 if [ "$HOST" = "n" ]; then
306 msg " adb forward tcp:$PORT tcp:$PORT"
307 fi
308 msg " jdb -attach localhost:$PORT"
309 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
310fi
311
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100312if [ "$USE_JVM" = "y" ]; then
Alex Light9c20a142016-08-23 15:05:12 -0700313 export LD_LIBRARY_PATH=${ANDROID_HOST_OUT}/lib64
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700314 # Xmx is necessary since we don't pass down the ART flags to JVM.
Alex Light9c20a142016-08-23 15:05:12 -0700315 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes ${FLAGS} $MAIN $@ ${ARGS}"
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700316 if [ "$DEV_MODE" = "y" ]; then
317 echo $cmdline
318 fi
319 $cmdline
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100320 exit
321fi
322
323
324if [ "$HAVE_IMAGE" = "n" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000325 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000326else
327 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100328fi
329
330
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100331if [ "$USE_GDB" = "y" ]; then
332 if [ "$HOST" = "n" ]; then
333 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100334 else
335 if [ `uname` = "Darwin" ]; then
336 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700337 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100338 DALVIKVM=
339 else
340 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700341 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100342 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
343 # gdbargs="--annotate=3 $gdbargs"
344 fi
345 fi
346fi
347
348if [ "$INTERPRETER" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000349 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700350 if [ "$VERIFY" = "y" ] ; then
Richard Uhlerf4b34872016-04-13 11:03:46 -0700351 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=interpret-only"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700352 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700353 elif [ "$VERIFY" = "s" ]; then
Richard Uhlerf4b34872016-04-13 11:03:46 -0700354 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-at-runtime"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700355 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
356 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
357 else # VERIFY = "n"
Richard Uhlerf4b34872016-04-13 11:03:46 -0700358 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-none"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700359 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
360 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
361 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100362fi
363
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800364if [ "$JIT" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000365 INT_OPTS="-Xusejit:true"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800366 if [ "$VERIFY" = "y" ] ; then
Calin Juravlef1d92652016-11-02 12:45:18 +0000367 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-at-runtime"
368 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800369 else
Richard Uhlerf4b34872016-04-13 11:03:46 -0700370 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-none"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800371 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
372 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
373 fi
374fi
375
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100376JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
377
378if [ "$RELOCATE" = "y" ]; then
379 COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information --runtime-arg -Xnorelocate"
380 FLAGS="${FLAGS} -Xrelocate -Xcompiler-option --include-patch-information"
381 if [ "$HOST" = "y" ]; then
382 # Run test sets a fairly draconian ulimit that we will likely blow right over
383 # since we are relocating. Get the total size of the /system/framework directory
384 # in 512 byte blocks and set it as the ulimit. This should be more than enough
385 # room.
386 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
Alex Lightd26b7e42016-04-08 09:44:54 -0700387 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 +0100388 fi
389 fi
390else
391 FLAGS="$FLAGS -Xnorelocate"
392 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
Mathieu Chartiercae2ed92015-06-09 13:02:50 -0700393 if [ "$HOST" = "y" ]; then
394 # Increase ulimit to 64MB in case we are running hprof test.
395 ulimit -S 64000 || exit 1
396 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100397fi
398
399if [ "$HOST" = "n" ]; then
400 ISA=$(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
Nicolas Geoffray8f500fa2016-11-03 11:18:48 +0000401 outcome=$?
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100402 if [ x"$ISA" = "x" ]; then
403 echo "Unable to determine architecture"
Nicolas Geoffray8f500fa2016-11-03 11:18:48 +0000404 # Print a few things for helping diagnosing the problem.
405 echo "adb invocation outcome: $outcome"
406 echo $(adb shell ls -F /data/dalvik-cache)
407 echo $(adb shell ls /data/dalvik-cache)
408 echo ${ARCHITECTURES_PATTERN}
409 echo $(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100410 exit 1
411 fi
412fi
413
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700414# Prevent test from silently falling back to interpreter in no-prebuild mode. This happens
415# when DEX_LOCATION path is too long, because vdex/odex filename is constructed by taking
416# full path to dex, stripping leading '/', appending '@classes.vdex' and changing every
417# remaining '/' into '@'.
418if [ "$HOST" = "y" ]; then
419 max_filename_size=$(getconf NAME_MAX $DEX_LOCATION)
420else
421 # There is no getconf on device, fallback to standard value. See NAME_MAX in kernel <linux/limits.h>
422 max_filename_size=255
423fi
424# Compute VDEX_NAME.
425DEX_LOCATION_STRIPPED="${DEX_LOCATION#/}"
426VDEX_NAME="${DEX_LOCATION_STRIPPED//\//@}@$TEST_NAME.jar@classes.vdex"
427if [ ${#VDEX_NAME} -gt $max_filename_size ]; then
428 echo "Dex location path too long."
429 exit 1
430fi
431
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100432dex2oat_cmdline="true"
Alex Lightafb5d192016-05-24 15:57:45 -0700433mkdir_locations="${DEX_LOCATION}/dalvik-cache/$ISA"
Richard Uhler76f5cb62016-04-04 13:30:16 -0700434strip_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100435
Mathieu Chartier92ec5942016-04-11 12:03:48 -0700436# Pick a base that will force the app image to get relocated.
437app_image="--base=0x4000 --app-image-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.art"
Jeff Haodcdc85b2015-12-04 14:06:18 -0800438
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100439if [ "$PREBUILD" = "y" ]; then
Alex Lightafb5d192016-05-24 15:57:45 -0700440 mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/oat/$ISA"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000441 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100442 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000443 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100444 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
Andreas Gampe14759242016-03-23 10:54:21 -0700445 --oat-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.odex \
Jeff Haodcdc85b2015-12-04 14:06:18 -0800446 ${app_image} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100447 --instruction-set=$ISA"
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700448 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
449 dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
450 fi
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700451
452 # Add in a timeout. This is important for testing the compilation/verification time of
453 # pathological cases.
454 # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
455 # now. We should try to improve this.
456 # The current value is rather arbitrary. run-tests should compile quickly.
457 if [ "$HOST" != "n" ]; then
458 # Use SIGRTMIN+2 to try to dump threads.
459 # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
460 dex2oat_cmdline="timeout -k 1m -s SIGRTMIN+2 1m ${dex2oat_cmdline}"
461 fi
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700462fi
463
Richard Uhler76f5cb62016-04-04 13:30:16 -0700464if [ "$STRIP_DEX" = "y" ]; then
465 strip_cmdline="zip --quiet --delete $DEX_LOCATION/$TEST_NAME.jar classes.dex"
466fi
467
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700468DALVIKVM_ISA_FEATURES_ARGS=""
469if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
470 DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100471fi
472
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000473# java.io.tmpdir can only be set at launch time.
474TMP_DIR_OPTION=""
475if [ "$HOST" = "n" ]; then
476 TMP_DIR_OPTION="-Djava.io.tmpdir=/data/local/tmp"
477fi
478
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000479# We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
480# b/27185632
481# b/24664297
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000482dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100483 $GDB_ARGS \
484 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700485 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100486 -XXlib:$LIB \
487 $PATCHOAT \
488 $DEX2OAT \
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700489 $DALVIKVM_ISA_FEATURES_ARGS \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100490 $ZYGOTE \
491 $JNI_OPTS \
492 $INT_OPTS \
493 $DEBUGGER_OPTS \
494 $DALVIKVM_BOOT_OPT \
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000495 $TMP_DIR_OPTION \
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000496 -XX:DumpNativeStackOnSigQuit:false \
Mathieu Chartier031768a2015-08-27 10:25:02 -0700497 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100498
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -0800499# Remove whitespace.
500dex2oat_cmdline=$(echo $dex2oat_cmdline)
501dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100502
503if [ "$HOST" = "n" ]; then
504 adb root > /dev/null
505 adb wait-for-device
506 if [ "$QUIET" = "n" ]; then
507 adb shell rm -r $DEX_LOCATION
508 adb shell mkdir -p $DEX_LOCATION
509 adb push $TEST_NAME.jar $DEX_LOCATION
510 adb push $TEST_NAME-ex.jar $DEX_LOCATION
511 else
512 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
513 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
514 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
515 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
516 fi
517
Colin Crossafd3c9e2016-09-16 13:47:21 -0700518 LD_LIBRARY_PATH=/data/$TEST_DIRECTORY/art/$ISA
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000519 if [ "$ANDROID_ROOT" != "/system" ]; then
520 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
521 # so we can only use LD_LIBRARY_PATH when testing on a local
522 # installation.
Alex Light7233c7e2016-07-28 10:07:45 -0700523 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY:$LD_LIBRARY_PATH
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000524 fi
525
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700526 PUBLIC_LIBS=libart.so:libartd.so
527
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100528 # Create a script with the command. The command can get longer than the longest
529 # allowed adb command and there is no way to get the exit status from a adb shell
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700530 # command. Dalvik cache is cleaned before running to make subsequent executions
531 # of the script follow the same runtime path.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100532 cmdline="cd $DEX_LOCATION && \
533 export ANDROID_DATA=$DEX_LOCATION && \
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700534 export ANDROID_ADDITIONAL_PUBLIC_LIBRARIES=$PUBLIC_LIBS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100535 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000536 export ANDROID_ROOT=$ANDROID_ROOT && \
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700537 rm -rf ${DEX_LOCATION}/dalvik-cache/ && \
Alex Lightafb5d192016-05-24 15:57:45 -0700538 mkdir -p ${mkdir_locations} && \
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100539 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray4f7fdd22015-04-24 11:57:37 +0100540 export PATH=$ANDROID_ROOT/bin:$PATH && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100541 $dex2oat_cmdline && \
Richard Uhler76f5cb62016-04-04 13:30:16 -0700542 $strip_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100543 $dalvikvm_cmdline"
544
545 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
546 echo "$cmdline" > $cmdfile
547
548 if [ "$DEV_MODE" = "y" ]; then
549 echo $cmdline
550 fi
551
552 if [ "$QUIET" = "n" ]; then
553 adb push $cmdfile $DEX_LOCATION/cmdline.sh
554 else
555 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
556 fi
557
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700558 if [ "$DRY_RUN" != "y" ]; then
559 adb shell sh $DEX_LOCATION/cmdline.sh
560 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100561
562 rm -f $cmdfile
563else
564 export ANDROID_PRINTF_LOG=brief
Andreas Gampea8780822015-03-13 19:51:09 -0700565
566 # By default, and for prebuild dex2oat, we are interested in errors being logged. In dev mode
567 # we want debug messages.
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700568 if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
569 if [ "$DEV_MODE" = "y" ]; then
570 export ANDROID_LOG_TAGS='*:d'
571 else
572 export ANDROID_LOG_TAGS='*:e'
573 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100574 fi
Andreas Gampea8780822015-03-13 19:51:09 -0700575
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100576 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000577 export ANDROID_ROOT="${ANDROID_ROOT}"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700578 export LD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
579 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100580 export PATH="$PATH:${ANDROID_ROOT}/bin"
581
David Srbeckyc9ede382015-06-20 06:03:53 +0100582 # Temporarily disable address space layout randomization (ASLR).
583 # This is needed on the host so that the linker loads core.oat at the necessary address.
584 export LD_USE_LOAD_BIAS=1
585
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100586 cmdline="$dalvikvm_cmdline"
587
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700588 if [ "$TIME_OUT" = "gdb" ]; then
589 if [ `uname` = "Darwin" ]; then
590 # Fall back to timeout on Mac.
591 TIME_OUT="timeout"
Hiroshi Yamauchic823eff2015-09-01 16:21:35 -0700592 elif [ "$ISA" = "x86" ]; then
593 # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
594 TIME_OUT="timeout"
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700595 else
596 # Check if gdb is available.
597 gdb --eval-command="quit" > /dev/null 2>&1
598 if [ $? != 0 ]; then
599 # gdb isn't available. Fall back to timeout.
600 TIME_OUT="timeout"
601 fi
602 fi
603 fi
604
605 if [ "$TIME_OUT" = "timeout" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100606 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -0800607 #
Andreas Gampe6fb92562016-08-01 21:53:57 -0700608 # Note: We first send SIGRTMIN+2 (usually 36) to ART, which will induce a full thread dump
609 # before abort. However, dumping threads might deadlock, so we also use the "-k"
610 # option to definitely kill the child.
611 cmdline="timeout -k 120s -s SIGRTMIN+2 ${TIME_OUT_VALUE}s $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100612 fi
613
614 if [ "$DEV_MODE" = "y" ]; then
Alex Lightafb5d192016-05-24 15:57:45 -0700615 echo "mkdir -p ${mkdir_locations} && $dex2oat_cmdline && $strip_cmdline && $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100616 fi
617
618 cd $ANDROID_BUILD_TOP
619
David Srbecky2e4afe82016-01-27 18:42:06 +0000620 rm -rf ${DEX_LOCATION}/dalvik-cache/
Alex Lightafb5d192016-05-24 15:57:45 -0700621 mkdir -p ${mkdir_locations} || exit 1
Andreas Gampea8780822015-03-13 19:51:09 -0700622 $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Richard Uhler76f5cb62016-04-04 13:30:16 -0700623 $strip_cmdline || { echo "Strip failed." >&2 ; exit 3; }
Andreas Gampea8780822015-03-13 19:51:09 -0700624
625 # For running, we must turn off logging when dex2oat or patchoat are missing. Otherwise we use
626 # the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700627 if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
628 if [ "$DEV_MODE" = "y" ]; then
629 export ANDROID_LOG_TAGS='*:d'
630 elif [ "$USE_DEX2OAT_AND_PATCHOAT" = "n" ]; then
631 # All tests would log the error of failing dex2oat/patchoat. Be silent here and only
632 # log fatal events.
633 export ANDROID_LOG_TAGS='*:s'
634 else
635 # We are interested in LOG(ERROR) output.
636 export ANDROID_LOG_TAGS='*:e'
637 fi
638 fi
639
640 if [ "$DRY_RUN" = "y" ]; then
641 exit 0
Andreas Gampea8780822015-03-13 19:51:09 -0700642 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100643
644 if [ "$USE_GDB" = "y" ]; then
645 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700646 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100647 else
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700648 if [ "$TIME_OUT" != "gdb" ]; then
649 trap 'kill -INT -$pid' INT
650 $cmdline "$@" 2>&1 & pid=$!
651 wait $pid
652 # Add extra detail if time out is enabled.
653 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
654 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
655 fi
656 else
657 # With a thread dump that uses gdb if a timeout.
658 trap 'kill -INT -$pid' INT
659 $cmdline "$@" 2>&1 & pid=$!
660 # Spawn a watcher process.
661 ( sleep $TIME_OUT_VALUE && \
662 echo "##### Thread dump using gdb on test timeout" && \
663 ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
664 --eval-command="call exit(124)" --eval-command=quit || \
665 kill $pid )) 2> /dev/null & watcher=$!
666 wait $pid
667 test_exit_status=$?
668 pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
669 if [ $test_exit_status = 0 ]; then
670 # The test finished normally.
671 exit 0
672 else
673 # The test failed or timed out.
674 if [ $test_exit_status = 124 ]; then
675 # The test timed out.
676 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
677 fi
678 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100679 fi
680 fi
681fi