blob: cf2999b24a89e7a563aefaa8a292c90ae1f87a19 [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=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010066
Igor Murashkin271a0f82017-02-14 21:14:17 +000067# if "y", run 'sync' before dalvikvm to make sure all files from
68# build step (e.g. dex2oat) were finished writing.
69SYNC_BEFORE_RUN="n"
70
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010071while true; do
72 if [ "x$1" = "x--quiet" ]; then
73 QUIET="y"
74 shift
Alex Lighte06b6342017-01-05 14:37:21 -080075 elif [ "x$1" = "x--jvmti" ]; then
76 IS_JVMTI_TEST="y"
77 shift
Alex Lightfaf90b62016-08-12 14:43:48 -070078 elif [ "x$1" = "x-O" ]; then
Alex Lighte06b6342017-01-05 14:37:21 -080079 TEST_IS_NDEBUG="y"
Alex Lightfaf90b62016-08-12 14:43:48 -070080 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010081 elif [ "x$1" = "x--lib" ]; then
82 shift
83 if [ "x$1" = "x" ]; then
84 echo "$0 missing argument to --lib" 1>&2
85 exit 1
86 fi
87 LIB="$1"
88 shift
Alex Light97acf192016-03-17 09:59:38 -070089 elif [ "x$1" = "x--gc-stress" ]; then
90 # Give an extra 5 mins if we are gc-stress.
91 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + 300))
92 shift
Mathieu Chartier031768a2015-08-27 10:25:02 -070093 elif [ "x$1" = "x--testlib" ]; then
94 shift
95 if [ "x$1" = "x" ]; then
96 echo "$0 missing argument to --testlib" 1>&2
97 exit 1
98 fi
Mathieu Chartierde286fd2015-09-03 18:10:29 -070099 ARGS="${ARGS} $1"
Mathieu Chartier031768a2015-08-27 10:25:02 -0700100 shift
David Srbecky52886112016-01-22 13:56:47 +0000101 elif [ "x$1" = "x--args" ]; then
102 shift
103 if [ "x$1" = "x" ]; then
104 echo "$0 missing argument to --args" 1>&2
105 exit 1
106 fi
107 ARGS="${ARGS} $1"
108 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100109 elif [ "x$1" = "x-Xcompiler-option" ]; then
110 shift
111 option="$1"
112 FLAGS="${FLAGS} -Xcompiler-option $option"
113 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
114 shift
Alex Light7233c7e2016-07-28 10:07:45 -0700115 elif [ "x$1" = "x--android-runtime-option" ]; then
116 shift
117 option="$1"
118 ANDROID_FLAGS="${ANDROID_FLAGS} $option"
119 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100120 elif [ "x$1" = "x--runtime-option" ]; then
121 shift
122 option="$1"
123 FLAGS="${FLAGS} $option"
124 shift
125 elif [ "x$1" = "x--boot" ]; then
126 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000127 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100128 shift
129 elif [ "x$1" = "x--no-dex2oat" ]; then
130 DEX2OAT="-Xcompiler:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800131 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100132 shift
133 elif [ "x$1" = "x--no-patchoat" ]; then
134 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800135 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100136 shift
137 elif [ "x$1" = "x--relocate" ]; then
138 RELOCATE="y"
139 shift
140 elif [ "x$1" = "x--no-relocate" ]; then
141 RELOCATE="n"
142 shift
143 elif [ "x$1" = "x--prebuild" ]; then
144 PREBUILD="y"
145 shift
Calin Juravle857f0582016-12-20 14:36:59 +0000146 elif [ "x$1" = "x--no-app-image" ]; then
147 APP_IMAGE="n"
148 shift
Richard Uhler76f5cb62016-04-04 13:30:16 -0700149 elif [ "x$1" = "x--strip-dex" ]; then
150 STRIP_DEX="y"
151 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100152 elif [ "x$1" = "x--host" ]; then
153 HOST="y"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000154 ANDROID_ROOT="$ANDROID_HOST_OUT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100155 shift
156 elif [ "x$1" = "x--no-prebuild" ]; then
157 PREBUILD="n"
158 shift
159 elif [ "x$1" = "x--no-image" ]; then
160 HAVE_IMAGE="n"
161 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700162 elif [ "x$1" = "x--secondary" ]; then
163 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
Calin Juravle175dc732015-08-25 15:42:32 +0100164 # Enable cfg-append to make sure we get the dump for both dex files.
165 # (otherwise the runtime compilation of the secondary dex will overwrite
Roland Levillainb0103ca2016-11-01 14:48:47 +0000166 # the dump of the first one).
Calin Juravle175dc732015-08-25 15:42:32 +0100167 FLAGS="${FLAGS} -Xcompiler-option --dump-cfg-append"
168 COMPILE_FLAGS="${COMPILE_FLAGS} --dump-cfg-append"
Jeff Hao207a37d2014-10-29 17:24:25 -0700169 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100170 elif [ "x$1" = "x--debug" ]; then
171 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800172 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100173 shift
174 elif [ "x$1" = "x--gdb" ]; then
175 USE_GDB="y"
176 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800177 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100178 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700179 elif [ "x$1" = "x--gdb-arg" ]; then
180 shift
181 gdb_arg="$1"
182 GDB_ARGS="${GDB_ARGS} $gdb_arg"
183 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100184 elif [ "x$1" = "x--zygote" ]; then
185 ZYGOTE="-Xzygote"
186 msg "Spawning from zygote"
187 shift
188 elif [ "x$1" = "x--dev" ]; then
189 DEV_MODE="y"
190 shift
191 elif [ "x$1" = "x--interpreter" ]; then
192 INTERPRETER="y"
193 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800194 elif [ "x$1" = "x--jit" ]; then
195 JIT="y"
196 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100197 elif [ "x$1" = "x--jvm" ]; then
198 USE_JVM="y"
199 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100200 elif [ "x$1" = "x--invoke-with" ]; then
201 shift
202 if [ "x$1" = "x" ]; then
203 echo "$0 missing argument to --invoke-with" 1>&2
204 exit 1
205 fi
206 if [ "x$INVOKE_WITH" = "x" ]; then
207 INVOKE_WITH="$1"
208 else
209 INVOKE_WITH="$INVOKE_WITH $1"
210 fi
211 shift
212 elif [ "x$1" = "x--no-verify" ]; then
213 VERIFY="n"
214 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700215 elif [ "x$1" = "x--verify-soft-fail" ]; then
216 VERIFY="s"
217 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100218 elif [ "x$1" = "x--no-optimize" ]; then
219 OPTIMIZE="n"
220 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000221 elif [ "x$1" = "x--android-root" ]; then
222 shift
223 ANDROID_ROOT="$1"
224 shift
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700225 elif [ "x$1" = "x--instruction-set-features" ]; then
226 shift
227 INSTRUCTION_SET_FEATURES="$1"
228 shift
Mathieu Chartier2576be22016-05-24 10:24:53 -0700229 elif [ "x$1" = "x--timeout" ]; then
230 shift
231 TIME_OUT_VALUE="$1"
232 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100233 elif [ "x$1" = "x--" ]; then
234 shift
235 break
236 elif [ "x$1" = "x--64" ]; then
237 ISA="x86_64"
238 GDB_SERVER="gdbserver64"
239 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000240 LIBRARY_DIRECTORY="lib64"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700241 TEST_DIRECTORY="nativetest64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100242 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
243 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700244 elif [ "x$1" = "x--pic-test" ]; then
245 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
246 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
247 shift
Alex Light8a0e0332015-10-26 10:11:58 -0700248 elif [ "x$1" = "x--experimental" ]; then
249 if [ "$#" -lt 2 ]; then
250 echo "missing --experimental option" 1>&2
251 exit 1
252 fi
253 EXPERIMENTAL="$EXPERIMENTAL $2"
254 shift 2
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700255 elif [ "x$1" = "x--external-log-tags" ]; then
256 EXTERNAL_LOG_TAGS="y"
257 shift
258 elif [ "x$1" = "x--dry-run" ]; then
259 DRY_RUN="y"
260 shift
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000261 elif [ "x$1" = "x--vdex" ]; then
262 TEST_VDEX="y"
263 shift
Nicolas Geoffray74981052017-01-16 17:54:09 +0000264 elif [ "x$1" = "x--vdex-filter" ]; then
265 shift
266 option="$1"
267 VDEX_FILTER="--compiler-filter=$option"
268 shift
Igor Murashkin271a0f82017-02-14 21:14:17 +0000269 elif [ "x$1" = "x--sync" ]; then
270 SYNC_BEFORE_RUN="y"
271 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100272 elif expr "x$1" : "x--" >/dev/null 2>&1; then
273 echo "unknown $0 option: $1" 1>&2
274 exit 1
275 else
276 break
277 fi
278done
279
Alex Light8a0e0332015-10-26 10:11:58 -0700280if [ "$USE_JVM" = "n" ]; then
Alex Light7233c7e2016-07-28 10:07:45 -0700281 FLAGS="${FLAGS} ${ANDROID_FLAGS}"
Alex Light8a0e0332015-10-26 10:11:58 -0700282 for feature in ${EXPERIMENTAL}; do
Alex Lightfa022852015-10-28 09:13:20 -0700283 FLAGS="${FLAGS} -Xexperimental:${feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:${feature}"
Alex Light8a0e0332015-10-26 10:11:58 -0700284 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xexperimental:${feature}"
285 done
286fi
287
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100288if [ "x$1" = "x" ] ; then
289 MAIN="Main"
290else
291 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700292 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100293fi
294
295if [ "$ZYGOTE" = "" ]; then
296 if [ "$OPTIMIZE" = "y" ]; then
297 if [ "$VERIFY" = "y" ]; then
298 DEX_OPTIMIZE="-Xdexopt:verified"
299 else
300 DEX_OPTIMIZE="-Xdexopt:all"
301 fi
302 msg "Performing optimizations"
303 else
304 DEX_OPTIMIZE="-Xdexopt:none"
305 msg "Skipping optimizations"
306 fi
307
308 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100309 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100310 msg "Performing verification"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700311 elif [ "$VERIFY" = "s" ]; then
312 JVM_VERIFY_ARG="Xverify:all"
313 DEX_VERIFY="-Xverify:softfail"
314 msg "Forcing verification to be soft fail"
315 else # VERIFY = "n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100316 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100317 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100318 msg "Skipping verification"
319 fi
320fi
321
322msg "------------------------------"
323
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100324if [ "$DEBUGGER" = "y" ]; then
325 # Use this instead for ddms and connect by running 'ddms':
326 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
327 # TODO: add a separate --ddms option?
328
329 PORT=12345
330 msg "Waiting for jdb to connect:"
331 if [ "$HOST" = "n" ]; then
332 msg " adb forward tcp:$PORT tcp:$PORT"
333 fi
334 msg " jdb -attach localhost:$PORT"
335 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
336fi
337
Alex Lightfba89fe2017-01-12 16:11:02 -0800338if [ "$IS_JVMTI_TEST" = "y" ]; then
339 plugin=libopenjdkjvmtid.so
340 agent=libtiagentd.so
341 lib=tiagentd
342 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
343 agent=libtiagent.so
344 plugin=libopenjdkjvmti.so
345 lib=tiagent
346 fi
347
348 ARGS="${ARGS} ${lib}"
349 if [[ "$USE_JVM" = "y" ]]; then
350 FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${TEST_NAME},jvm"
351 else
352 FLAGS="${FLAGS} -agentpath:${agent}=${TEST_NAME},art"
353 FLAGS="${FLAGS} -Xplugin:${plugin}"
Nicolas Geoffraya0619e22016-12-20 13:57:43 +0000354 FLAGS="${FLAGS} -Xcompiler-option --debuggable"
Alex Lightfba89fe2017-01-12 16:11:02 -0800355 # Always make the compilation be debuggable.
356 COMPILE_FLAGS="${COMPILE_FLAGS} --debuggable"
357 fi
358fi
359
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100360if [ "$USE_JVM" = "y" ]; then
Alex Light9c20a142016-08-23 15:05:12 -0700361 export LD_LIBRARY_PATH=${ANDROID_HOST_OUT}/lib64
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700362 # Xmx is necessary since we don't pass down the ART flags to JVM.
Vladimir Markoc5798bf2016-12-09 10:20:54 +0000363 # We pass the classes2 path whether it's used (src-multidex) or not.
364 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes:classes2 ${FLAGS} $MAIN $@ ${ARGS}"
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700365 if [ "$DEV_MODE" = "y" ]; then
366 echo $cmdline
367 fi
368 $cmdline
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100369 exit
370fi
371
372
373if [ "$HAVE_IMAGE" = "n" ]; then
Vladimir Markoe00e5592017-02-24 14:58:29 +0000374 if [ "${HOST}" = "y" ]; then
375 framework="${ANDROID_HOST_OUT}/framework"
376 bpath_suffix="-hostdex"
377 else
378 framework="${ANDROID_ROOT}/framework"
Nicolas Geoffray320ccca2017-03-01 10:03:08 +0000379 bpath_suffix="-testdex"
Vladimir Markoe00e5592017-02-24 14:58:29 +0000380 fi
Vladimir Markoe00e5592017-02-24 14:58:29 +0000381 bpath="${framework}/core-libart${bpath_suffix}.jar"
382 bpath="${bpath}:${framework}/core-oj${bpath_suffix}.jar"
383 bpath="${bpath}:${framework}/conscrypt${bpath_suffix}.jar"
384 bpath="${bpath}:${framework}/okhttp${bpath_suffix}.jar"
385 bpath="${bpath}:${framework}/bouncycastle${bpath_suffix}.jar"
386 # Pass down the bootclasspath
387 FLAGS="${FLAGS} -Xbootclasspath:${bpath}"
Nicolas Geoffray47e61d52017-01-31 09:13:52 +0000388 # Add 5 minutes to give some time to generate the boot image.
389 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + 300))
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000390 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000391else
392 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100393fi
394
395
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100396if [ "$USE_GDB" = "y" ]; then
397 if [ "$HOST" = "n" ]; then
398 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100399 else
400 if [ `uname` = "Darwin" ]; then
401 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700402 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100403 DALVIKVM=
404 else
405 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700406 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100407 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
408 # gdbargs="--annotate=3 $gdbargs"
409 fi
410 fi
411fi
412
413if [ "$INTERPRETER" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000414 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700415 if [ "$VERIFY" = "y" ] ; then
Richard Uhlerf4b34872016-04-13 11:03:46 -0700416 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=interpret-only"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700417 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700418 elif [ "$VERIFY" = "s" ]; then
Richard Uhlerf4b34872016-04-13 11:03:46 -0700419 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-at-runtime"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700420 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
421 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
422 else # VERIFY = "n"
Richard Uhlerf4b34872016-04-13 11:03:46 -0700423 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-none"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700424 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
425 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
426 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100427fi
428
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800429if [ "$JIT" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000430 INT_OPTS="-Xusejit:true"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800431 if [ "$VERIFY" = "y" ] ; then
Calin Juravle09665582016-12-20 14:00:48 +0000432 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=interpret-only"
433 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800434 else
Richard Uhlerf4b34872016-04-13 11:03:46 -0700435 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-none"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800436 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
437 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
438 fi
439fi
440
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100441JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
442
443if [ "$RELOCATE" = "y" ]; then
Richard Uhlerc52f3032017-03-02 13:45:45 +0000444 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
445 FLAGS="${FLAGS} -Xrelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100446 if [ "$HOST" = "y" ]; then
447 # Run test sets a fairly draconian ulimit that we will likely blow right over
448 # since we are relocating. Get the total size of the /system/framework directory
449 # in 512 byte blocks and set it as the ulimit. This should be more than enough
450 # room.
451 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
Alex Lightd26b7e42016-04-08 09:44:54 -0700452 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 +0100453 fi
454 fi
455else
456 FLAGS="$FLAGS -Xnorelocate"
457 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
Mathieu Chartiercae2ed92015-06-09 13:02:50 -0700458 if [ "$HOST" = "y" ]; then
Roland Levillain9e6e3d42017-03-03 15:39:51 +0000459 # Increase ulimit to 128MB in case we are running hprof test,
460 # or string append test with art-debug-gc.
461 ulimit -S 128000 || exit 1
Mathieu Chartiercae2ed92015-06-09 13:02:50 -0700462 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100463fi
464
465if [ "$HOST" = "n" ]; then
Nicolas Geoffrayd295bc82016-11-04 13:03:05 +0000466 # Need to be root to query /data/dalvik-cache
467 adb root > /dev/null
468 adb wait-for-device
469 ISA=
470 ISA_adb_invocation=
471 ISA_outcome=
472 # We iterate a few times to workaround an adb issue. b/32655576
473 for i in {1..10}; do
474 ISA_adb_invocation=$(adb shell ls -F /data/dalvik-cache)
475 ISA_outcome=$?
476 ISA=$(echo $ISA_adb_invocation | grep -Ewo "${ARCHITECTURES_PATTERN}")
477 if [ x"$ISA" != "x" ]; then
478 break;
479 fi
480 done
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100481 if [ x"$ISA" = "x" ]; then
482 echo "Unable to determine architecture"
Nicolas Geoffray8f500fa2016-11-03 11:18:48 +0000483 # Print a few things for helping diagnosing the problem.
Nicolas Geoffrayd295bc82016-11-04 13:03:05 +0000484 echo "adb invocation output: $ISA_adb_invocation"
485 echo "adb invocation outcome: $ISA_outcome"
Nicolas Geoffray8f500fa2016-11-03 11:18:48 +0000486 echo $(adb shell ls -F /data/dalvik-cache)
487 echo $(adb shell ls /data/dalvik-cache)
488 echo ${ARCHITECTURES_PATTERN}
489 echo $(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100490 exit 1
491 fi
492fi
493
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700494# Prevent test from silently falling back to interpreter in no-prebuild mode. This happens
495# when DEX_LOCATION path is too long, because vdex/odex filename is constructed by taking
496# full path to dex, stripping leading '/', appending '@classes.vdex' and changing every
497# remaining '/' into '@'.
498if [ "$HOST" = "y" ]; then
499 max_filename_size=$(getconf NAME_MAX $DEX_LOCATION)
500else
501 # There is no getconf on device, fallback to standard value. See NAME_MAX in kernel <linux/limits.h>
502 max_filename_size=255
503fi
504# Compute VDEX_NAME.
505DEX_LOCATION_STRIPPED="${DEX_LOCATION#/}"
506VDEX_NAME="${DEX_LOCATION_STRIPPED//\//@}@$TEST_NAME.jar@classes.vdex"
507if [ ${#VDEX_NAME} -gt $max_filename_size ]; then
508 echo "Dex location path too long."
509 exit 1
510fi
511
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100512dex2oat_cmdline="true"
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000513vdex_cmdline="true"
Alex Lightafb5d192016-05-24 15:57:45 -0700514mkdir_locations="${DEX_LOCATION}/dalvik-cache/$ISA"
Richard Uhler76f5cb62016-04-04 13:30:16 -0700515strip_cmdline="true"
Igor Murashkin271a0f82017-02-14 21:14:17 +0000516sync_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100517
Jeff Haodcdc85b2015-12-04 14:06:18 -0800518
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100519if [ "$PREBUILD" = "y" ]; then
Alex Lightafb5d192016-05-24 15:57:45 -0700520 mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/oat/$ISA"
Calin Juravle857f0582016-12-20 14:36:59 +0000521 if [ "$APP_IMAGE" = "y" ]; then
522 # Pick a base that will force the app image to get relocated.
523 app_image="--base=0x4000 --app-image-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.art"
524 fi
525
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000526 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100527 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000528 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100529 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
Andreas Gampe14759242016-03-23 10:54:21 -0700530 --oat-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.odex \
Jeff Haodcdc85b2015-12-04 14:06:18 -0800531 ${app_image} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100532 --instruction-set=$ISA"
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700533 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
534 dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
535 fi
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700536
537 # Add in a timeout. This is important for testing the compilation/verification time of
538 # pathological cases.
539 # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
540 # now. We should try to improve this.
541 # The current value is rather arbitrary. run-tests should compile quickly.
542 if [ "$HOST" != "n" ]; then
543 # Use SIGRTMIN+2 to try to dump threads.
544 # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
545 dex2oat_cmdline="timeout -k 1m -s SIGRTMIN+2 1m ${dex2oat_cmdline}"
546 fi
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000547 if [ "$TEST_VDEX" = "y" ]; then
Nicolas Geoffray74981052017-01-16 17:54:09 +0000548 vdex_cmdline="${dex2oat_cmdline} ${VDEX_FILTER} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000549 fi
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700550fi
551
Richard Uhler76f5cb62016-04-04 13:30:16 -0700552if [ "$STRIP_DEX" = "y" ]; then
553 strip_cmdline="zip --quiet --delete $DEX_LOCATION/$TEST_NAME.jar classes.dex"
554fi
555
Igor Murashkin271a0f82017-02-14 21:14:17 +0000556if [ "$SYNC_BEFORE_RUN" = "y" ]; then
557 sync_cmdline="sync"
558fi
559
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700560DALVIKVM_ISA_FEATURES_ARGS=""
561if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
562 DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100563fi
564
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000565# java.io.tmpdir can only be set at launch time.
566TMP_DIR_OPTION=""
567if [ "$HOST" = "n" ]; then
568 TMP_DIR_OPTION="-Djava.io.tmpdir=/data/local/tmp"
569fi
570
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000571# We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
572# b/27185632
573# b/24664297
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000574dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100575 $GDB_ARGS \
576 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700577 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100578 -XXlib:$LIB \
579 $PATCHOAT \
580 $DEX2OAT \
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700581 $DALVIKVM_ISA_FEATURES_ARGS \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100582 $ZYGOTE \
583 $JNI_OPTS \
584 $INT_OPTS \
585 $DEBUGGER_OPTS \
586 $DALVIKVM_BOOT_OPT \
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000587 $TMP_DIR_OPTION \
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000588 -XX:DumpNativeStackOnSigQuit:false \
Mathieu Chartier031768a2015-08-27 10:25:02 -0700589 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100590
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -0800591# Remove whitespace.
592dex2oat_cmdline=$(echo $dex2oat_cmdline)
593dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000594vdex_cmdline=$(echo $vdex_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100595
596if [ "$HOST" = "n" ]; then
597 adb root > /dev/null
598 adb wait-for-device
599 if [ "$QUIET" = "n" ]; then
600 adb shell rm -r $DEX_LOCATION
601 adb shell mkdir -p $DEX_LOCATION
602 adb push $TEST_NAME.jar $DEX_LOCATION
603 adb push $TEST_NAME-ex.jar $DEX_LOCATION
604 else
605 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
606 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
607 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
608 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
609 fi
610
Colin Crossafd3c9e2016-09-16 13:47:21 -0700611 LD_LIBRARY_PATH=/data/$TEST_DIRECTORY/art/$ISA
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000612 if [ "$ANDROID_ROOT" != "/system" ]; then
613 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
614 # so we can only use LD_LIBRARY_PATH when testing on a local
615 # installation.
Alex Light7233c7e2016-07-28 10:07:45 -0700616 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY:$LD_LIBRARY_PATH
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000617 fi
618
Dimitry Ivanov49c2c922017-02-14 11:06:14 -0800619 # System libraries needed by libarttestd.so
620 PUBLIC_LIBS=libart.so:libartd.so:libc++.so:libbacktrace.so:libbase.so:libnativehelper.so
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700621
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100622 # Create a script with the command. The command can get longer than the longest
623 # allowed adb command and there is no way to get the exit status from a adb shell
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700624 # command. Dalvik cache is cleaned before running to make subsequent executions
625 # of the script follow the same runtime path.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100626 cmdline="cd $DEX_LOCATION && \
627 export ANDROID_DATA=$DEX_LOCATION && \
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700628 export ANDROID_ADDITIONAL_PUBLIC_LIBRARIES=$PUBLIC_LIBS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100629 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000630 export ANDROID_ROOT=$ANDROID_ROOT && \
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700631 rm -rf ${DEX_LOCATION}/dalvik-cache/ && \
Alex Lightafb5d192016-05-24 15:57:45 -0700632 mkdir -p ${mkdir_locations} && \
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100633 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray4f7fdd22015-04-24 11:57:37 +0100634 export PATH=$ANDROID_ROOT/bin:$PATH && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100635 $dex2oat_cmdline && \
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000636 $vdex_cmdline && \
Richard Uhler76f5cb62016-04-04 13:30:16 -0700637 $strip_cmdline && \
Igor Murashkin271a0f82017-02-14 21:14:17 +0000638 $sync_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100639 $dalvikvm_cmdline"
640
641 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
642 echo "$cmdline" > $cmdfile
643
644 if [ "$DEV_MODE" = "y" ]; then
645 echo $cmdline
646 fi
647
648 if [ "$QUIET" = "n" ]; then
649 adb push $cmdfile $DEX_LOCATION/cmdline.sh
650 else
651 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
652 fi
653
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700654 if [ "$DRY_RUN" != "y" ]; then
655 adb shell sh $DEX_LOCATION/cmdline.sh
656 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100657
658 rm -f $cmdfile
659else
660 export ANDROID_PRINTF_LOG=brief
Andreas Gampea8780822015-03-13 19:51:09 -0700661
662 # By default, and for prebuild dex2oat, we are interested in errors being logged. In dev mode
663 # we want debug messages.
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700664 if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
665 if [ "$DEV_MODE" = "y" ]; then
666 export ANDROID_LOG_TAGS='*:d'
667 else
668 export ANDROID_LOG_TAGS='*:e'
669 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100670 fi
Andreas Gampea8780822015-03-13 19:51:09 -0700671
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100672 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000673 export ANDROID_ROOT="${ANDROID_ROOT}"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700674 export LD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
675 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100676 export PATH="$PATH:${ANDROID_ROOT}/bin"
677
David Srbeckyc9ede382015-06-20 06:03:53 +0100678 # Temporarily disable address space layout randomization (ASLR).
679 # This is needed on the host so that the linker loads core.oat at the necessary address.
680 export LD_USE_LOAD_BIAS=1
681
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100682 cmdline="$dalvikvm_cmdline"
683
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700684 if [ "$TIME_OUT" = "gdb" ]; then
685 if [ `uname` = "Darwin" ]; then
686 # Fall back to timeout on Mac.
687 TIME_OUT="timeout"
Hiroshi Yamauchic823eff2015-09-01 16:21:35 -0700688 elif [ "$ISA" = "x86" ]; then
689 # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
690 TIME_OUT="timeout"
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700691 else
692 # Check if gdb is available.
693 gdb --eval-command="quit" > /dev/null 2>&1
694 if [ $? != 0 ]; then
695 # gdb isn't available. Fall back to timeout.
696 TIME_OUT="timeout"
697 fi
698 fi
699 fi
700
701 if [ "$TIME_OUT" = "timeout" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100702 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -0800703 #
Andreas Gampe6fb92562016-08-01 21:53:57 -0700704 # Note: We first send SIGRTMIN+2 (usually 36) to ART, which will induce a full thread dump
705 # before abort. However, dumping threads might deadlock, so we also use the "-k"
706 # option to definitely kill the child.
707 cmdline="timeout -k 120s -s SIGRTMIN+2 ${TIME_OUT_VALUE}s $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100708 fi
709
710 if [ "$DEV_MODE" = "y" ]; then
Igor Murashkin271a0f82017-02-14 21:14:17 +0000711 echo "mkdir -p ${mkdir_locations} && $dex2oat_cmdline && $vdex_cmdline && $strip_cmdline && $sync_cmdline && $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100712 fi
713
714 cd $ANDROID_BUILD_TOP
715
David Srbecky2e4afe82016-01-27 18:42:06 +0000716 rm -rf ${DEX_LOCATION}/dalvik-cache/
Alex Lightafb5d192016-05-24 15:57:45 -0700717 mkdir -p ${mkdir_locations} || exit 1
Andreas Gampea8780822015-03-13 19:51:09 -0700718 $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000719 $vdex_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Richard Uhler76f5cb62016-04-04 13:30:16 -0700720 $strip_cmdline || { echo "Strip failed." >&2 ; exit 3; }
Igor Murashkin271a0f82017-02-14 21:14:17 +0000721 $sync_cmdline || { echo "Sync failed." >&2 ; exit 4; }
Andreas Gampea8780822015-03-13 19:51:09 -0700722
723 # For running, we must turn off logging when dex2oat or patchoat are missing. Otherwise we use
724 # the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700725 if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
726 if [ "$DEV_MODE" = "y" ]; then
727 export ANDROID_LOG_TAGS='*:d'
728 elif [ "$USE_DEX2OAT_AND_PATCHOAT" = "n" ]; then
729 # All tests would log the error of failing dex2oat/patchoat. Be silent here and only
730 # log fatal events.
731 export ANDROID_LOG_TAGS='*:s'
732 else
733 # We are interested in LOG(ERROR) output.
734 export ANDROID_LOG_TAGS='*:e'
735 fi
736 fi
737
738 if [ "$DRY_RUN" = "y" ]; then
739 exit 0
Andreas Gampea8780822015-03-13 19:51:09 -0700740 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100741
742 if [ "$USE_GDB" = "y" ]; then
743 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700744 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100745 else
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700746 if [ "$TIME_OUT" != "gdb" ]; then
747 trap 'kill -INT -$pid' INT
748 $cmdline "$@" 2>&1 & pid=$!
749 wait $pid
750 # Add extra detail if time out is enabled.
751 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
752 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
753 fi
754 else
755 # With a thread dump that uses gdb if a timeout.
756 trap 'kill -INT -$pid' INT
757 $cmdline "$@" 2>&1 & pid=$!
758 # Spawn a watcher process.
759 ( sleep $TIME_OUT_VALUE && \
760 echo "##### Thread dump using gdb on test timeout" && \
761 ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
762 --eval-command="call exit(124)" --eval-command=quit || \
763 kill $pid )) 2> /dev/null & watcher=$!
764 wait $pid
765 test_exit_status=$?
766 pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
767 if [ $test_exit_status = 0 ]; then
768 # The test finished normally.
769 exit 0
770 else
771 # The test failed or timed out.
772 if [ $test_exit_status = 124 ]; then
773 # The test timed out.
774 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
775 fi
776 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100777 fi
778 fi
779fi