blob: f1b6132e94174af03e8f45bc9aebd09183bdbea9 [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 Geoffray90355fe2017-02-20 09:25:40 +000022FALSE_BIN="false"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010023FLAGS=""
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=""
Alex Lighte06b6342017-01-05 14:37:21 -080033IS_JVMTI_TEST="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010034ISA=x86
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000035LIBRARY_DIRECTORY="lib"
Colin Crossafd3c9e2016-09-16 13:47:21 -070036TEST_DIRECTORY="nativetest"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000037MAIN=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010038OPTIMIZE="y"
39PATCHOAT=""
40PREBUILD="y"
41QUIET="n"
Nicolas Geoffray94e25db2017-01-27 14:54:28 +000042RELOCATE="n"
Richard Uhler76f5cb62016-04-04 13:30:16 -070043STRIP_DEX="n"
Jeff Hao207a37d2014-10-29 17:24:25 -070044SECONDARY_DEX=""
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -070045TIME_OUT="gdb" # "n" (disabled), "timeout" (use timeout), "gdb" (use gdb)
46# Value in seconds
Hiroshi Yamauchifd3161a2017-01-18 14:47:25 -080047if [ "$ART_USE_READ_BARRIER" != "false" ]; then
Hiroshi Yamauchia9b296c2016-10-07 17:07:03 -070048 TIME_OUT_VALUE=2400 # 40 minutes.
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070049else
Mathieu Chartier2576be22016-05-24 10:24:53 -070050 TIME_OUT_VALUE=1200 # 20 minutes.
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070051fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010052USE_GDB="n"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +010053USE_JVM="n"
Igor Murashkin7617abd2015-07-10 18:27:47 -070054VERIFY="y" # y=yes,n=no,s=softfail
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010055ZYGOTE=""
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -070056DEX_VERIFY=""
Andreas Gampe65357032015-02-19 15:10:24 -080057USE_DEX2OAT_AND_PATCHOAT="y"
Andreas Gampe4d2ef332015-08-05 09:24:45 -070058INSTRUCTION_SET_FEATURES=""
Mathieu Chartier031768a2015-08-27 10:25:02 -070059ARGS=""
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -070060EXTERNAL_LOG_TAGS="n" # if y respect externally set ANDROID_LOG_TAGS.
61DRY_RUN="n" # if y prepare to run the test but don't run it.
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +000062TEST_VDEX="n"
Alex Lighte06b6342017-01-05 14:37:21 -080063TEST_IS_NDEBUG="n"
Calin Juravle857f0582016-12-20 14:36:59 +000064APP_IMAGE="y"
Nicolas Geoffray74981052017-01-16 17:54:09 +000065VDEX_FILTER=""
Calin Juravle13439f02017-02-21 01:17:21 -080066PROFILE="n"
Jeff Hao002b9312017-03-27 16:23:08 -070067RANDOM_PROFILE="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010068
Igor Murashkin271a0f82017-02-14 21:14:17 +000069# if "y", run 'sync' before dalvikvm to make sure all files from
70# build step (e.g. dex2oat) were finished writing.
71SYNC_BEFORE_RUN="n"
72
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010073while true; do
74 if [ "x$1" = "x--quiet" ]; then
75 QUIET="y"
76 shift
Alex Lighte06b6342017-01-05 14:37:21 -080077 elif [ "x$1" = "x--jvmti" ]; then
78 IS_JVMTI_TEST="y"
79 shift
Alex Lightfaf90b62016-08-12 14:43:48 -070080 elif [ "x$1" = "x-O" ]; then
Alex Lighte06b6342017-01-05 14:37:21 -080081 TEST_IS_NDEBUG="y"
Alex Lightfaf90b62016-08-12 14:43:48 -070082 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010083 elif [ "x$1" = "x--lib" ]; then
84 shift
85 if [ "x$1" = "x" ]; then
86 echo "$0 missing argument to --lib" 1>&2
87 exit 1
88 fi
89 LIB="$1"
90 shift
Alex Light97acf192016-03-17 09:59:38 -070091 elif [ "x$1" = "x--gc-stress" ]; then
92 # Give an extra 5 mins if we are gc-stress.
93 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + 300))
94 shift
Mathieu Chartier031768a2015-08-27 10:25:02 -070095 elif [ "x$1" = "x--testlib" ]; then
96 shift
97 if [ "x$1" = "x" ]; then
98 echo "$0 missing argument to --testlib" 1>&2
99 exit 1
100 fi
Mathieu Chartierde286fd2015-09-03 18:10:29 -0700101 ARGS="${ARGS} $1"
Mathieu Chartier031768a2015-08-27 10:25:02 -0700102 shift
David Srbecky52886112016-01-22 13:56:47 +0000103 elif [ "x$1" = "x--args" ]; then
104 shift
105 if [ "x$1" = "x" ]; then
106 echo "$0 missing argument to --args" 1>&2
107 exit 1
108 fi
109 ARGS="${ARGS} $1"
110 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100111 elif [ "x$1" = "x-Xcompiler-option" ]; then
112 shift
113 option="$1"
114 FLAGS="${FLAGS} -Xcompiler-option $option"
115 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
116 shift
Alex Light7233c7e2016-07-28 10:07:45 -0700117 elif [ "x$1" = "x--android-runtime-option" ]; then
118 shift
119 option="$1"
120 ANDROID_FLAGS="${ANDROID_FLAGS} $option"
121 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100122 elif [ "x$1" = "x--runtime-option" ]; then
123 shift
124 option="$1"
125 FLAGS="${FLAGS} $option"
126 shift
127 elif [ "x$1" = "x--boot" ]; then
128 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000129 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100130 shift
131 elif [ "x$1" = "x--no-dex2oat" ]; then
132 DEX2OAT="-Xcompiler:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800133 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100134 shift
135 elif [ "x$1" = "x--no-patchoat" ]; then
136 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800137 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100138 shift
139 elif [ "x$1" = "x--relocate" ]; then
140 RELOCATE="y"
141 shift
142 elif [ "x$1" = "x--no-relocate" ]; then
143 RELOCATE="n"
144 shift
145 elif [ "x$1" = "x--prebuild" ]; then
146 PREBUILD="y"
147 shift
Calin Juravle857f0582016-12-20 14:36:59 +0000148 elif [ "x$1" = "x--no-app-image" ]; then
149 APP_IMAGE="n"
150 shift
Richard Uhler76f5cb62016-04-04 13:30:16 -0700151 elif [ "x$1" = "x--strip-dex" ]; then
152 STRIP_DEX="y"
153 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100154 elif [ "x$1" = "x--host" ]; then
155 HOST="y"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000156 ANDROID_ROOT="$ANDROID_HOST_OUT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100157 shift
158 elif [ "x$1" = "x--no-prebuild" ]; then
159 PREBUILD="n"
160 shift
161 elif [ "x$1" = "x--no-image" ]; then
162 HAVE_IMAGE="n"
163 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700164 elif [ "x$1" = "x--secondary" ]; then
165 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
Calin Juravle175dc732015-08-25 15:42:32 +0100166 # Enable cfg-append to make sure we get the dump for both dex files.
167 # (otherwise the runtime compilation of the secondary dex will overwrite
Roland Levillainb0103ca2016-11-01 14:48:47 +0000168 # the dump of the first one).
Calin Juravle175dc732015-08-25 15:42:32 +0100169 FLAGS="${FLAGS} -Xcompiler-option --dump-cfg-append"
170 COMPILE_FLAGS="${COMPILE_FLAGS} --dump-cfg-append"
Jeff Hao207a37d2014-10-29 17:24:25 -0700171 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100172 elif [ "x$1" = "x--debug" ]; then
173 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800174 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100175 shift
176 elif [ "x$1" = "x--gdb" ]; then
177 USE_GDB="y"
178 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800179 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100180 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700181 elif [ "x$1" = "x--gdb-arg" ]; then
182 shift
183 gdb_arg="$1"
184 GDB_ARGS="${GDB_ARGS} $gdb_arg"
185 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100186 elif [ "x$1" = "x--zygote" ]; then
187 ZYGOTE="-Xzygote"
188 msg "Spawning from zygote"
189 shift
190 elif [ "x$1" = "x--dev" ]; then
191 DEV_MODE="y"
192 shift
193 elif [ "x$1" = "x--interpreter" ]; then
194 INTERPRETER="y"
195 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800196 elif [ "x$1" = "x--jit" ]; then
197 JIT="y"
198 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100199 elif [ "x$1" = "x--jvm" ]; then
200 USE_JVM="y"
201 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100202 elif [ "x$1" = "x--invoke-with" ]; then
203 shift
204 if [ "x$1" = "x" ]; then
205 echo "$0 missing argument to --invoke-with" 1>&2
206 exit 1
207 fi
208 if [ "x$INVOKE_WITH" = "x" ]; then
209 INVOKE_WITH="$1"
210 else
211 INVOKE_WITH="$INVOKE_WITH $1"
212 fi
213 shift
214 elif [ "x$1" = "x--no-verify" ]; then
215 VERIFY="n"
216 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700217 elif [ "x$1" = "x--verify-soft-fail" ]; then
218 VERIFY="s"
219 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100220 elif [ "x$1" = "x--no-optimize" ]; then
221 OPTIMIZE="n"
222 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000223 elif [ "x$1" = "x--android-root" ]; then
224 shift
225 ANDROID_ROOT="$1"
226 shift
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700227 elif [ "x$1" = "x--instruction-set-features" ]; then
228 shift
229 INSTRUCTION_SET_FEATURES="$1"
230 shift
Mathieu Chartier2576be22016-05-24 10:24:53 -0700231 elif [ "x$1" = "x--timeout" ]; then
232 shift
233 TIME_OUT_VALUE="$1"
234 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100235 elif [ "x$1" = "x--" ]; then
236 shift
237 break
238 elif [ "x$1" = "x--64" ]; then
239 ISA="x86_64"
240 GDB_SERVER="gdbserver64"
241 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000242 LIBRARY_DIRECTORY="lib64"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700243 TEST_DIRECTORY="nativetest64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100244 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
245 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700246 elif [ "x$1" = "x--pic-test" ]; then
247 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
248 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
249 shift
Alex Light8a0e0332015-10-26 10:11:58 -0700250 elif [ "x$1" = "x--experimental" ]; then
251 if [ "$#" -lt 2 ]; then
252 echo "missing --experimental option" 1>&2
253 exit 1
254 fi
255 EXPERIMENTAL="$EXPERIMENTAL $2"
256 shift 2
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700257 elif [ "x$1" = "x--external-log-tags" ]; then
258 EXTERNAL_LOG_TAGS="y"
259 shift
260 elif [ "x$1" = "x--dry-run" ]; then
261 DRY_RUN="y"
262 shift
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000263 elif [ "x$1" = "x--vdex" ]; then
264 TEST_VDEX="y"
265 shift
Nicolas Geoffray74981052017-01-16 17:54:09 +0000266 elif [ "x$1" = "x--vdex-filter" ]; then
267 shift
268 option="$1"
269 VDEX_FILTER="--compiler-filter=$option"
270 shift
Igor Murashkin271a0f82017-02-14 21:14:17 +0000271 elif [ "x$1" = "x--sync" ]; then
272 SYNC_BEFORE_RUN="y"
273 shift
Calin Juravle13439f02017-02-21 01:17:21 -0800274 elif [ "x$1" = "x--profile" ]; then
275 PROFILE="y"
276 shift
Jeff Hao002b9312017-03-27 16:23:08 -0700277 elif [ "x$1" = "x--random-profile" ]; then
278 RANDOM_PROFILE="y"
279 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100280 elif expr "x$1" : "x--" >/dev/null 2>&1; then
281 echo "unknown $0 option: $1" 1>&2
282 exit 1
283 else
284 break
285 fi
286done
287
Alex Light8a0e0332015-10-26 10:11:58 -0700288if [ "$USE_JVM" = "n" ]; then
Alex Light7233c7e2016-07-28 10:07:45 -0700289 FLAGS="${FLAGS} ${ANDROID_FLAGS}"
Alex Light8a0e0332015-10-26 10:11:58 -0700290 for feature in ${EXPERIMENTAL}; do
Alex Lightfa022852015-10-28 09:13:20 -0700291 FLAGS="${FLAGS} -Xexperimental:${feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:${feature}"
Alex Light8a0e0332015-10-26 10:11:58 -0700292 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xexperimental:${feature}"
293 done
294fi
295
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100296if [ "x$1" = "x" ] ; then
297 MAIN="Main"
298else
299 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700300 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100301fi
302
303if [ "$ZYGOTE" = "" ]; then
304 if [ "$OPTIMIZE" = "y" ]; then
305 if [ "$VERIFY" = "y" ]; then
306 DEX_OPTIMIZE="-Xdexopt:verified"
307 else
308 DEX_OPTIMIZE="-Xdexopt:all"
309 fi
310 msg "Performing optimizations"
311 else
312 DEX_OPTIMIZE="-Xdexopt:none"
313 msg "Skipping optimizations"
314 fi
315
316 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100317 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100318 msg "Performing verification"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700319 elif [ "$VERIFY" = "s" ]; then
320 JVM_VERIFY_ARG="Xverify:all"
321 DEX_VERIFY="-Xverify:softfail"
322 msg "Forcing verification to be soft fail"
323 else # VERIFY = "n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100324 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100325 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100326 msg "Skipping verification"
327 fi
328fi
329
330msg "------------------------------"
331
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100332if [ "$DEBUGGER" = "y" ]; then
333 # Use this instead for ddms and connect by running 'ddms':
334 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
335 # TODO: add a separate --ddms option?
336
337 PORT=12345
338 msg "Waiting for jdb to connect:"
339 if [ "$HOST" = "n" ]; then
340 msg " adb forward tcp:$PORT tcp:$PORT"
341 fi
342 msg " jdb -attach localhost:$PORT"
343 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
344fi
345
Alex Lightfba89fe2017-01-12 16:11:02 -0800346if [ "$IS_JVMTI_TEST" = "y" ]; then
347 plugin=libopenjdkjvmtid.so
348 agent=libtiagentd.so
349 lib=tiagentd
350 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
351 agent=libtiagent.so
352 plugin=libopenjdkjvmti.so
353 lib=tiagent
354 fi
355
356 ARGS="${ARGS} ${lib}"
357 if [[ "$USE_JVM" = "y" ]]; then
358 FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${TEST_NAME},jvm"
359 else
360 FLAGS="${FLAGS} -agentpath:${agent}=${TEST_NAME},art"
361 FLAGS="${FLAGS} -Xplugin:${plugin}"
Nicolas Geoffraya0619e22016-12-20 13:57:43 +0000362 FLAGS="${FLAGS} -Xcompiler-option --debuggable"
Alex Lightfba89fe2017-01-12 16:11:02 -0800363 # Always make the compilation be debuggable.
364 COMPILE_FLAGS="${COMPILE_FLAGS} --debuggable"
365 fi
366fi
367
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100368if [ "$USE_JVM" = "y" ]; then
Alex Light9c20a142016-08-23 15:05:12 -0700369 export LD_LIBRARY_PATH=${ANDROID_HOST_OUT}/lib64
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700370 # Xmx is necessary since we don't pass down the ART flags to JVM.
Vladimir Markoc5798bf2016-12-09 10:20:54 +0000371 # We pass the classes2 path whether it's used (src-multidex) or not.
372 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes:classes2 ${FLAGS} $MAIN $@ ${ARGS}"
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700373 if [ "$DEV_MODE" = "y" ]; then
374 echo $cmdline
375 fi
376 $cmdline
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100377 exit
378fi
379
380
381if [ "$HAVE_IMAGE" = "n" ]; then
Vladimir Markoe00e5592017-02-24 14:58:29 +0000382 if [ "${HOST}" = "y" ]; then
383 framework="${ANDROID_HOST_OUT}/framework"
384 bpath_suffix="-hostdex"
385 else
386 framework="${ANDROID_ROOT}/framework"
Nicolas Geoffray320ccca2017-03-01 10:03:08 +0000387 bpath_suffix="-testdex"
Vladimir Markoe00e5592017-02-24 14:58:29 +0000388 fi
Vladimir Markoe00e5592017-02-24 14:58:29 +0000389 bpath="${framework}/core-libart${bpath_suffix}.jar"
390 bpath="${bpath}:${framework}/core-oj${bpath_suffix}.jar"
391 bpath="${bpath}:${framework}/conscrypt${bpath_suffix}.jar"
392 bpath="${bpath}:${framework}/okhttp${bpath_suffix}.jar"
393 bpath="${bpath}:${framework}/bouncycastle${bpath_suffix}.jar"
394 # Pass down the bootclasspath
395 FLAGS="${FLAGS} -Xbootclasspath:${bpath}"
Nicolas Geoffray47e61d52017-01-31 09:13:52 +0000396 # Add 5 minutes to give some time to generate the boot image.
397 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + 300))
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000398 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000399else
400 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100401fi
402
403
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100404if [ "$USE_GDB" = "y" ]; then
405 if [ "$HOST" = "n" ]; then
406 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100407 else
408 if [ `uname` = "Darwin" ]; then
409 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700410 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100411 DALVIKVM=
412 else
413 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700414 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100415 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
416 # gdbargs="--annotate=3 $gdbargs"
417 fi
418 fi
419fi
420
421if [ "$INTERPRETER" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000422 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700423 if [ "$VERIFY" = "y" ] ; then
Richard Uhlerf4b34872016-04-13 11:03:46 -0700424 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=interpret-only"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700425 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700426 elif [ "$VERIFY" = "s" ]; then
Richard Uhlerf4b34872016-04-13 11:03:46 -0700427 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-at-runtime"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700428 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
429 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
430 else # VERIFY = "n"
Richard Uhlerf4b34872016-04-13 11:03:46 -0700431 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-none"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700432 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
433 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
434 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100435fi
436
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800437if [ "$JIT" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000438 INT_OPTS="-Xusejit:true"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800439 if [ "$VERIFY" = "y" ] ; then
Calin Juravle09665582016-12-20 14:00:48 +0000440 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=interpret-only"
441 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800442 else
Richard Uhlerf4b34872016-04-13 11:03:46 -0700443 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-none"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800444 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
445 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
446 fi
447fi
448
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100449JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
450
Richard Uhler020c0f32017-03-14 16:23:17 +0000451COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100452if [ "$RELOCATE" = "y" ]; then
Richard Uhlerc52f3032017-03-02 13:45:45 +0000453 FLAGS="${FLAGS} -Xrelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100454else
455 FLAGS="$FLAGS -Xnorelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100456fi
457
458if [ "$HOST" = "n" ]; then
Nicolas Geoffrayd295bc82016-11-04 13:03:05 +0000459 # Need to be root to query /data/dalvik-cache
460 adb root > /dev/null
461 adb wait-for-device
462 ISA=
463 ISA_adb_invocation=
464 ISA_outcome=
465 # We iterate a few times to workaround an adb issue. b/32655576
466 for i in {1..10}; do
467 ISA_adb_invocation=$(adb shell ls -F /data/dalvik-cache)
468 ISA_outcome=$?
469 ISA=$(echo $ISA_adb_invocation | grep -Ewo "${ARCHITECTURES_PATTERN}")
470 if [ x"$ISA" != "x" ]; then
471 break;
472 fi
473 done
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100474 if [ x"$ISA" = "x" ]; then
475 echo "Unable to determine architecture"
Nicolas Geoffray8f500fa2016-11-03 11:18:48 +0000476 # Print a few things for helping diagnosing the problem.
Nicolas Geoffrayd295bc82016-11-04 13:03:05 +0000477 echo "adb invocation output: $ISA_adb_invocation"
478 echo "adb invocation outcome: $ISA_outcome"
Nicolas Geoffray8f500fa2016-11-03 11:18:48 +0000479 echo $(adb shell ls -F /data/dalvik-cache)
480 echo $(adb shell ls /data/dalvik-cache)
481 echo ${ARCHITECTURES_PATTERN}
482 echo $(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100483 exit 1
484 fi
485fi
486
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700487# Prevent test from silently falling back to interpreter in no-prebuild mode. This happens
488# when DEX_LOCATION path is too long, because vdex/odex filename is constructed by taking
489# full path to dex, stripping leading '/', appending '@classes.vdex' and changing every
490# remaining '/' into '@'.
491if [ "$HOST" = "y" ]; then
492 max_filename_size=$(getconf NAME_MAX $DEX_LOCATION)
493else
494 # There is no getconf on device, fallback to standard value. See NAME_MAX in kernel <linux/limits.h>
495 max_filename_size=255
496fi
497# Compute VDEX_NAME.
498DEX_LOCATION_STRIPPED="${DEX_LOCATION#/}"
499VDEX_NAME="${DEX_LOCATION_STRIPPED//\//@}@$TEST_NAME.jar@classes.vdex"
500if [ ${#VDEX_NAME} -gt $max_filename_size ]; then
Nicolas Geoffraybea3e312017-03-07 09:59:05 +0000501 echo "Dex location path too long:"
502 echo "$VDEX_NAME is ${#VDEX_NAME} character long, and the limit is $max_filename_size."
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700503 exit 1
504fi
505
Calin Juravle13439f02017-02-21 01:17:21 -0800506profman_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100507dex2oat_cmdline="true"
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000508vdex_cmdline="true"
Alex Lightafb5d192016-05-24 15:57:45 -0700509mkdir_locations="${DEX_LOCATION}/dalvik-cache/$ISA"
Richard Uhler76f5cb62016-04-04 13:30:16 -0700510strip_cmdline="true"
Igor Murashkin271a0f82017-02-14 21:14:17 +0000511sync_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100512
Jeff Hao002b9312017-03-27 16:23:08 -0700513# PROFILE takes precedence over RANDOM_PROFILE, since PROFILE tests require a
514# specific profile to run properly.
515if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000516 profman_cmdline="${ANDROID_ROOT}/bin/profman \
517 --apk=$DEX_LOCATION/$TEST_NAME.jar \
Jeff Hao002b9312017-03-27 16:23:08 -0700518 --dex-location=$DEX_LOCATION/$TEST_NAME.jar"
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000519 COMPILE_FLAGS="${COMPILE_FLAGS} --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
520 FLAGS="${FLAGS} -Xcompiler-option --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
Jeff Hao002b9312017-03-27 16:23:08 -0700521 if [ "$PROFILE" = "y" ]; then
522 profman_cmdline="${profman_cmdline} --create-profile-from=$DEX_LOCATION/profile \
523 --reference-profile-file=$DEX_LOCATION/$TEST_NAME.prof"
524 else
525 profman_cmdline="${profman_cmdline} --generate-test-profile=$DEX_LOCATION/$TEST_NAME.prof \
526 --generate-test-profile-seed=0"
527 fi
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000528fi
529
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100530if [ "$PREBUILD" = "y" ]; then
Alex Lightafb5d192016-05-24 15:57:45 -0700531 mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/oat/$ISA"
Calin Juravle857f0582016-12-20 14:36:59 +0000532 if [ "$APP_IMAGE" = "y" ]; then
533 # Pick a base that will force the app image to get relocated.
534 app_image="--base=0x4000 --app-image-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.art"
535 fi
536
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000537 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100538 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000539 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100540 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
Andreas Gampe14759242016-03-23 10:54:21 -0700541 --oat-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.odex \
Jeff Haodcdc85b2015-12-04 14:06:18 -0800542 ${app_image} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100543 --instruction-set=$ISA"
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700544 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
545 dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
546 fi
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700547
548 # Add in a timeout. This is important for testing the compilation/verification time of
549 # pathological cases.
550 # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
551 # now. We should try to improve this.
552 # The current value is rather arbitrary. run-tests should compile quickly.
553 if [ "$HOST" != "n" ]; then
554 # Use SIGRTMIN+2 to try to dump threads.
555 # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
556 dex2oat_cmdline="timeout -k 1m -s SIGRTMIN+2 1m ${dex2oat_cmdline}"
557 fi
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000558 if [ "$TEST_VDEX" = "y" ]; then
Nicolas Geoffray74981052017-01-16 17:54:09 +0000559 vdex_cmdline="${dex2oat_cmdline} ${VDEX_FILTER} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000560 fi
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700561fi
562
Richard Uhler76f5cb62016-04-04 13:30:16 -0700563if [ "$STRIP_DEX" = "y" ]; then
564 strip_cmdline="zip --quiet --delete $DEX_LOCATION/$TEST_NAME.jar classes.dex"
565fi
566
Igor Murashkin271a0f82017-02-14 21:14:17 +0000567if [ "$SYNC_BEFORE_RUN" = "y" ]; then
568 sync_cmdline="sync"
569fi
570
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700571DALVIKVM_ISA_FEATURES_ARGS=""
572if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
573 DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100574fi
575
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000576# java.io.tmpdir can only be set at launch time.
577TMP_DIR_OPTION=""
578if [ "$HOST" = "n" ]; then
579 TMP_DIR_OPTION="-Djava.io.tmpdir=/data/local/tmp"
580fi
581
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000582# We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
583# b/27185632
584# b/24664297
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000585dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100586 $GDB_ARGS \
587 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700588 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100589 -XXlib:$LIB \
590 $PATCHOAT \
591 $DEX2OAT \
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700592 $DALVIKVM_ISA_FEATURES_ARGS \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100593 $ZYGOTE \
594 $JNI_OPTS \
595 $INT_OPTS \
596 $DEBUGGER_OPTS \
597 $DALVIKVM_BOOT_OPT \
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000598 $TMP_DIR_OPTION \
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000599 -XX:DumpNativeStackOnSigQuit:false \
Mathieu Chartier031768a2015-08-27 10:25:02 -0700600 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100601
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -0800602# Remove whitespace.
603dex2oat_cmdline=$(echo $dex2oat_cmdline)
604dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000605vdex_cmdline=$(echo $vdex_cmdline)
Calin Juravle13439f02017-02-21 01:17:21 -0800606profman_cmdline=$(echo $profman_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100607
608if [ "$HOST" = "n" ]; then
609 adb root > /dev/null
610 adb wait-for-device
611 if [ "$QUIET" = "n" ]; then
612 adb shell rm -r $DEX_LOCATION
613 adb shell mkdir -p $DEX_LOCATION
614 adb push $TEST_NAME.jar $DEX_LOCATION
615 adb push $TEST_NAME-ex.jar $DEX_LOCATION
Jeff Hao002b9312017-03-27 16:23:08 -0700616 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Calin Juravle13439f02017-02-21 01:17:21 -0800617 adb push profile $DEX_LOCATION
618 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100619 else
620 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
621 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
622 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
623 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
Jeff Hao002b9312017-03-27 16:23:08 -0700624 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Calin Juravle13439f02017-02-21 01:17:21 -0800625 adb push profile $DEX_LOCATION >/dev/null 2>&1
626 fi
627
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100628 fi
629
Colin Crossafd3c9e2016-09-16 13:47:21 -0700630 LD_LIBRARY_PATH=/data/$TEST_DIRECTORY/art/$ISA
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000631 if [ "$ANDROID_ROOT" != "/system" ]; then
632 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
633 # so we can only use LD_LIBRARY_PATH when testing on a local
634 # installation.
Alex Light7233c7e2016-07-28 10:07:45 -0700635 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY:$LD_LIBRARY_PATH
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000636 fi
637
Dimitry Ivanov49c2c922017-02-14 11:06:14 -0800638 # System libraries needed by libarttestd.so
639 PUBLIC_LIBS=libart.so:libartd.so:libc++.so:libbacktrace.so:libbase.so:libnativehelper.so
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700640
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100641 # Create a script with the command. The command can get longer than the longest
642 # allowed adb command and there is no way to get the exit status from a adb shell
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700643 # command. Dalvik cache is cleaned before running to make subsequent executions
644 # of the script follow the same runtime path.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100645 cmdline="cd $DEX_LOCATION && \
646 export ANDROID_DATA=$DEX_LOCATION && \
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700647 export ANDROID_ADDITIONAL_PUBLIC_LIBRARIES=$PUBLIC_LIBS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100648 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000649 export ANDROID_ROOT=$ANDROID_ROOT && \
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700650 rm -rf ${DEX_LOCATION}/dalvik-cache/ && \
Alex Lightafb5d192016-05-24 15:57:45 -0700651 mkdir -p ${mkdir_locations} && \
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100652 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray4f7fdd22015-04-24 11:57:37 +0100653 export PATH=$ANDROID_ROOT/bin:$PATH && \
Calin Juravle13439f02017-02-21 01:17:21 -0800654 $profman_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100655 $dex2oat_cmdline && \
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000656 $vdex_cmdline && \
Richard Uhler76f5cb62016-04-04 13:30:16 -0700657 $strip_cmdline && \
Igor Murashkin271a0f82017-02-14 21:14:17 +0000658 $sync_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100659 $dalvikvm_cmdline"
660
661 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
662 echo "$cmdline" > $cmdfile
663
664 if [ "$DEV_MODE" = "y" ]; then
665 echo $cmdline
666 fi
667
668 if [ "$QUIET" = "n" ]; then
669 adb push $cmdfile $DEX_LOCATION/cmdline.sh
670 else
671 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
672 fi
673
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700674 if [ "$DRY_RUN" != "y" ]; then
675 adb shell sh $DEX_LOCATION/cmdline.sh
676 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100677
678 rm -f $cmdfile
679else
680 export ANDROID_PRINTF_LOG=brief
Andreas Gampea8780822015-03-13 19:51:09 -0700681
682 # By default, and for prebuild dex2oat, we are interested in errors being logged. In dev mode
683 # we want debug messages.
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700684 if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
685 if [ "$DEV_MODE" = "y" ]; then
686 export ANDROID_LOG_TAGS='*:d'
687 else
688 export ANDROID_LOG_TAGS='*:e'
689 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100690 fi
Andreas Gampea8780822015-03-13 19:51:09 -0700691
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100692 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000693 export ANDROID_ROOT="${ANDROID_ROOT}"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700694 export LD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
695 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100696 export PATH="$PATH:${ANDROID_ROOT}/bin"
697
David Srbeckyc9ede382015-06-20 06:03:53 +0100698 # Temporarily disable address space layout randomization (ASLR).
699 # This is needed on the host so that the linker loads core.oat at the necessary address.
700 export LD_USE_LOAD_BIAS=1
701
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100702 cmdline="$dalvikvm_cmdline"
703
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700704 if [ "$TIME_OUT" = "gdb" ]; then
705 if [ `uname` = "Darwin" ]; then
706 # Fall back to timeout on Mac.
707 TIME_OUT="timeout"
Hiroshi Yamauchic823eff2015-09-01 16:21:35 -0700708 elif [ "$ISA" = "x86" ]; then
709 # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
710 TIME_OUT="timeout"
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700711 else
712 # Check if gdb is available.
713 gdb --eval-command="quit" > /dev/null 2>&1
714 if [ $? != 0 ]; then
715 # gdb isn't available. Fall back to timeout.
716 TIME_OUT="timeout"
717 fi
718 fi
719 fi
720
721 if [ "$TIME_OUT" = "timeout" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100722 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -0800723 #
Andreas Gampe6fb92562016-08-01 21:53:57 -0700724 # Note: We first send SIGRTMIN+2 (usually 36) to ART, which will induce a full thread dump
725 # before abort. However, dumping threads might deadlock, so we also use the "-k"
726 # option to definitely kill the child.
727 cmdline="timeout -k 120s -s SIGRTMIN+2 ${TIME_OUT_VALUE}s $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100728 fi
729
730 if [ "$DEV_MODE" = "y" ]; then
Calin Juravle13439f02017-02-21 01:17:21 -0800731 echo "mkdir -p ${mkdir_locations} && $profman_cmdline && $dex2oat_cmdline && $vdex_cmdline && $strip_cmdline && $sync_cmdline && $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100732 fi
733
734 cd $ANDROID_BUILD_TOP
735
David Srbecky2e4afe82016-01-27 18:42:06 +0000736 rm -rf ${DEX_LOCATION}/dalvik-cache/
Alex Lightafb5d192016-05-24 15:57:45 -0700737 mkdir -p ${mkdir_locations} || exit 1
Calin Juravle13439f02017-02-21 01:17:21 -0800738 $profman_cmdline || { echo "Profman failed." >&2 ; exit 2; }
Andreas Gampea8780822015-03-13 19:51:09 -0700739 $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000740 $vdex_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Richard Uhler76f5cb62016-04-04 13:30:16 -0700741 $strip_cmdline || { echo "Strip failed." >&2 ; exit 3; }
Igor Murashkin271a0f82017-02-14 21:14:17 +0000742 $sync_cmdline || { echo "Sync failed." >&2 ; exit 4; }
Andreas Gampea8780822015-03-13 19:51:09 -0700743
744 # For running, we must turn off logging when dex2oat or patchoat are missing. Otherwise we use
745 # the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700746 if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
747 if [ "$DEV_MODE" = "y" ]; then
748 export ANDROID_LOG_TAGS='*:d'
749 elif [ "$USE_DEX2OAT_AND_PATCHOAT" = "n" ]; then
750 # All tests would log the error of failing dex2oat/patchoat. Be silent here and only
751 # log fatal events.
752 export ANDROID_LOG_TAGS='*:s'
753 else
754 # We are interested in LOG(ERROR) output.
755 export ANDROID_LOG_TAGS='*:e'
756 fi
757 fi
758
759 if [ "$DRY_RUN" = "y" ]; then
760 exit 0
Andreas Gampea8780822015-03-13 19:51:09 -0700761 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100762
763 if [ "$USE_GDB" = "y" ]; then
764 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700765 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100766 else
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700767 if [ "$TIME_OUT" != "gdb" ]; then
768 trap 'kill -INT -$pid' INT
769 $cmdline "$@" 2>&1 & pid=$!
770 wait $pid
771 # Add extra detail if time out is enabled.
772 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
773 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
774 fi
775 else
776 # With a thread dump that uses gdb if a timeout.
777 trap 'kill -INT -$pid' INT
778 $cmdline "$@" 2>&1 & pid=$!
779 # Spawn a watcher process.
780 ( sleep $TIME_OUT_VALUE && \
781 echo "##### Thread dump using gdb on test timeout" && \
782 ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
783 --eval-command="call exit(124)" --eval-command=quit || \
784 kill $pid )) 2> /dev/null & watcher=$!
785 wait $pid
786 test_exit_status=$?
787 pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
788 if [ $test_exit_status = 0 ]; then
789 # The test finished normally.
790 exit 0
791 else
792 # The test failed or timed out.
793 if [ $test_exit_status = 124 ]; then
794 # The test timed out.
795 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
796 fi
797 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100798 fi
799 fi
800fi