blob: c16c487dd1723f769024815a8b7a8933529dee1d [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"
Alex Light8f2c6d42017-04-10 16:27:35 -070065JVMTI_STRESS="n"
Alex Lightc38c3692017-06-27 15:45:14 -070066JVMTI_STEP_STRESS="n"
Alex Light43e935d2017-06-19 15:40:40 -070067JVMTI_FIELD_STRESS="n"
Alex Lightb7edcda2017-04-27 13:20:31 -070068JVMTI_TRACE_STRESS="n"
69JVMTI_REDEFINE_STRESS="n"
Nicolas Geoffray74981052017-01-16 17:54:09 +000070VDEX_FILTER=""
Calin Juravle13439f02017-02-21 01:17:21 -080071PROFILE="n"
Jeff Hao002b9312017-03-27 16:23:08 -070072RANDOM_PROFILE="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010073
Narayan Kamath84695ae2017-04-07 15:41:41 +010074# if "y", set -Xstacktracedir and inform the test of its location. When
75# this is set, stack trace dumps (from signal 3) will be written to a file
76# under this directory instead of stdout.
77SET_STACK_TRACE_DUMP_DIR="n"
78
Igor Murashkin271a0f82017-02-14 21:14:17 +000079# if "y", run 'sync' before dalvikvm to make sure all files from
80# build step (e.g. dex2oat) were finished writing.
81SYNC_BEFORE_RUN="n"
82
Andreas Gampe1c5b42f2017-06-15 18:20:45 -070083# When running a debug build, we want to run with all checks.
84ANDROID_FLAGS="${ANDROID_FLAGS} -XX:SlowDebug=true"
85
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010086while true; do
87 if [ "x$1" = "x--quiet" ]; then
88 QUIET="y"
89 shift
Alex Lighte06b6342017-01-05 14:37:21 -080090 elif [ "x$1" = "x--jvmti" ]; then
91 IS_JVMTI_TEST="y"
92 shift
Alex Lightfaf90b62016-08-12 14:43:48 -070093 elif [ "x$1" = "x-O" ]; then
Alex Lighte06b6342017-01-05 14:37:21 -080094 TEST_IS_NDEBUG="y"
Alex Lightfaf90b62016-08-12 14:43:48 -070095 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010096 elif [ "x$1" = "x--lib" ]; then
97 shift
98 if [ "x$1" = "x" ]; then
99 echo "$0 missing argument to --lib" 1>&2
100 exit 1
101 fi
102 LIB="$1"
103 shift
Alex Light97acf192016-03-17 09:59:38 -0700104 elif [ "x$1" = "x--gc-stress" ]; then
105 # Give an extra 5 mins if we are gc-stress.
106 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + 300))
107 shift
Mathieu Chartier031768a2015-08-27 10:25:02 -0700108 elif [ "x$1" = "x--testlib" ]; then
109 shift
110 if [ "x$1" = "x" ]; then
111 echo "$0 missing argument to --testlib" 1>&2
112 exit 1
113 fi
Mathieu Chartierde286fd2015-09-03 18:10:29 -0700114 ARGS="${ARGS} $1"
Mathieu Chartier031768a2015-08-27 10:25:02 -0700115 shift
David Srbecky52886112016-01-22 13:56:47 +0000116 elif [ "x$1" = "x--args" ]; then
117 shift
118 if [ "x$1" = "x" ]; then
119 echo "$0 missing argument to --args" 1>&2
120 exit 1
121 fi
122 ARGS="${ARGS} $1"
123 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100124 elif [ "x$1" = "x-Xcompiler-option" ]; then
125 shift
126 option="$1"
127 FLAGS="${FLAGS} -Xcompiler-option $option"
128 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
129 shift
Alex Light7233c7e2016-07-28 10:07:45 -0700130 elif [ "x$1" = "x--android-runtime-option" ]; then
131 shift
132 option="$1"
133 ANDROID_FLAGS="${ANDROID_FLAGS} $option"
134 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100135 elif [ "x$1" = "x--runtime-option" ]; then
136 shift
137 option="$1"
138 FLAGS="${FLAGS} $option"
139 shift
140 elif [ "x$1" = "x--boot" ]; then
141 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000142 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100143 shift
144 elif [ "x$1" = "x--no-dex2oat" ]; then
145 DEX2OAT="-Xcompiler:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800146 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100147 shift
148 elif [ "x$1" = "x--no-patchoat" ]; then
149 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800150 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100151 shift
152 elif [ "x$1" = "x--relocate" ]; then
153 RELOCATE="y"
154 shift
155 elif [ "x$1" = "x--no-relocate" ]; then
156 RELOCATE="n"
157 shift
158 elif [ "x$1" = "x--prebuild" ]; then
159 PREBUILD="y"
160 shift
Alex Lightb7edcda2017-04-27 13:20:31 -0700161 elif [ "x$1" = "x--jvmti-redefine-stress" ]; then
162 # APP_IMAGE doesn't really work with jvmti redefine stress
Alex Light8f2c6d42017-04-10 16:27:35 -0700163 APP_IMAGE="n"
164 JVMTI_STRESS="y"
Alex Lightb7edcda2017-04-27 13:20:31 -0700165 JVMTI_REDEFINE_STRESS="y"
166 shift
Alex Lightc38c3692017-06-27 15:45:14 -0700167 elif [ "x$1" = "x--jvmti-step-stress" ]; then
168 JVMTI_STRESS="y"
169 JVMTI_STEP_STRESS="y"
170 shift
Alex Light43e935d2017-06-19 15:40:40 -0700171 elif [ "x$1" = "x--jvmti-field-stress" ]; then
172 JVMTI_STRESS="y"
173 JVMTI_FIELD_STRESS="y"
174 shift
Alex Lightb7edcda2017-04-27 13:20:31 -0700175 elif [ "x$1" = "x--jvmti-trace-stress" ]; then
176 JVMTI_STRESS="y"
177 JVMTI_TRACE_STRESS="y"
Alex Light8f2c6d42017-04-10 16:27:35 -0700178 shift
Calin Juravle857f0582016-12-20 14:36:59 +0000179 elif [ "x$1" = "x--no-app-image" ]; then
180 APP_IMAGE="n"
181 shift
Richard Uhler76f5cb62016-04-04 13:30:16 -0700182 elif [ "x$1" = "x--strip-dex" ]; then
183 STRIP_DEX="y"
184 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100185 elif [ "x$1" = "x--host" ]; then
186 HOST="y"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000187 ANDROID_ROOT="$ANDROID_HOST_OUT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100188 shift
189 elif [ "x$1" = "x--no-prebuild" ]; then
190 PREBUILD="n"
191 shift
192 elif [ "x$1" = "x--no-image" ]; then
193 HAVE_IMAGE="n"
194 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700195 elif [ "x$1" = "x--secondary" ]; then
196 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
Calin Juravle175dc732015-08-25 15:42:32 +0100197 # Enable cfg-append to make sure we get the dump for both dex files.
198 # (otherwise the runtime compilation of the secondary dex will overwrite
Roland Levillainb0103ca2016-11-01 14:48:47 +0000199 # the dump of the first one).
Calin Juravle175dc732015-08-25 15:42:32 +0100200 FLAGS="${FLAGS} -Xcompiler-option --dump-cfg-append"
201 COMPILE_FLAGS="${COMPILE_FLAGS} --dump-cfg-append"
Jeff Hao207a37d2014-10-29 17:24:25 -0700202 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100203 elif [ "x$1" = "x--debug" ]; then
204 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800205 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100206 shift
207 elif [ "x$1" = "x--gdb" ]; then
208 USE_GDB="y"
209 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800210 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100211 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700212 elif [ "x$1" = "x--gdb-arg" ]; then
213 shift
214 gdb_arg="$1"
215 GDB_ARGS="${GDB_ARGS} $gdb_arg"
216 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100217 elif [ "x$1" = "x--zygote" ]; then
218 ZYGOTE="-Xzygote"
219 msg "Spawning from zygote"
220 shift
221 elif [ "x$1" = "x--dev" ]; then
222 DEV_MODE="y"
223 shift
224 elif [ "x$1" = "x--interpreter" ]; then
225 INTERPRETER="y"
226 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800227 elif [ "x$1" = "x--jit" ]; then
228 JIT="y"
229 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100230 elif [ "x$1" = "x--jvm" ]; then
231 USE_JVM="y"
232 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100233 elif [ "x$1" = "x--invoke-with" ]; then
234 shift
235 if [ "x$1" = "x" ]; then
236 echo "$0 missing argument to --invoke-with" 1>&2
237 exit 1
238 fi
239 if [ "x$INVOKE_WITH" = "x" ]; then
240 INVOKE_WITH="$1"
241 else
242 INVOKE_WITH="$INVOKE_WITH $1"
243 fi
244 shift
245 elif [ "x$1" = "x--no-verify" ]; then
246 VERIFY="n"
247 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700248 elif [ "x$1" = "x--verify-soft-fail" ]; then
249 VERIFY="s"
250 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100251 elif [ "x$1" = "x--no-optimize" ]; then
252 OPTIMIZE="n"
253 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000254 elif [ "x$1" = "x--android-root" ]; then
255 shift
256 ANDROID_ROOT="$1"
257 shift
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700258 elif [ "x$1" = "x--instruction-set-features" ]; then
259 shift
260 INSTRUCTION_SET_FEATURES="$1"
261 shift
Mathieu Chartier2576be22016-05-24 10:24:53 -0700262 elif [ "x$1" = "x--timeout" ]; then
263 shift
264 TIME_OUT_VALUE="$1"
265 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100266 elif [ "x$1" = "x--" ]; then
267 shift
268 break
269 elif [ "x$1" = "x--64" ]; then
270 ISA="x86_64"
271 GDB_SERVER="gdbserver64"
272 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000273 LIBRARY_DIRECTORY="lib64"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700274 TEST_DIRECTORY="nativetest64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100275 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
276 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700277 elif [ "x$1" = "x--pic-test" ]; then
278 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
279 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
280 shift
Alex Light8a0e0332015-10-26 10:11:58 -0700281 elif [ "x$1" = "x--experimental" ]; then
282 if [ "$#" -lt 2 ]; then
283 echo "missing --experimental option" 1>&2
284 exit 1
285 fi
286 EXPERIMENTAL="$EXPERIMENTAL $2"
287 shift 2
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700288 elif [ "x$1" = "x--external-log-tags" ]; then
289 EXTERNAL_LOG_TAGS="y"
290 shift
291 elif [ "x$1" = "x--dry-run" ]; then
292 DRY_RUN="y"
293 shift
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000294 elif [ "x$1" = "x--vdex" ]; then
295 TEST_VDEX="y"
296 shift
Nicolas Geoffray74981052017-01-16 17:54:09 +0000297 elif [ "x$1" = "x--vdex-filter" ]; then
298 shift
299 option="$1"
300 VDEX_FILTER="--compiler-filter=$option"
301 shift
Igor Murashkin271a0f82017-02-14 21:14:17 +0000302 elif [ "x$1" = "x--sync" ]; then
303 SYNC_BEFORE_RUN="y"
304 shift
Calin Juravle13439f02017-02-21 01:17:21 -0800305 elif [ "x$1" = "x--profile" ]; then
306 PROFILE="y"
307 shift
Jeff Hao002b9312017-03-27 16:23:08 -0700308 elif [ "x$1" = "x--random-profile" ]; then
309 RANDOM_PROFILE="y"
310 shift
Narayan Kamath84695ae2017-04-07 15:41:41 +0100311 elif [ "x$1" = "x--set-stack-trace-dump-dir" ]; then
312 SET_STACK_TRACE_DUMP_DIR="y"
313 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100314 elif expr "x$1" : "x--" >/dev/null 2>&1; then
315 echo "unknown $0 option: $1" 1>&2
316 exit 1
317 else
318 break
319 fi
320done
321
Narayan Kamath84695ae2017-04-07 15:41:41 +0100322mkdir_locations=""
323
Alex Light8a0e0332015-10-26 10:11:58 -0700324if [ "$USE_JVM" = "n" ]; then
Alex Light7233c7e2016-07-28 10:07:45 -0700325 FLAGS="${FLAGS} ${ANDROID_FLAGS}"
Alex Light8a0e0332015-10-26 10:11:58 -0700326 for feature in ${EXPERIMENTAL}; do
Alex Lightfa022852015-10-28 09:13:20 -0700327 FLAGS="${FLAGS} -Xexperimental:${feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:${feature}"
Alex Light8a0e0332015-10-26 10:11:58 -0700328 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xexperimental:${feature}"
329 done
Narayan Kamath84695ae2017-04-07 15:41:41 +0100330
331 if [ "$SET_STACK_TRACE_DUMP_DIR" = "y" ]; then
332 # Note that DEX_LOCATION is used as a proxy for tmpdir throughout this
333 # file (it will be under the test specific folder).
334 mkdir_locations="${mkdir_locations} $DEX_LOCATION/stack_traces"
335 FLAGS="${FLAGS} -Xstacktracedir:$DEX_LOCATION/stack_traces"
336 ARGS="${ARGS} --stack-trace-dir $DEX_LOCATION/stack_traces"
337 fi
Alex Light8a0e0332015-10-26 10:11:58 -0700338fi
339
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100340if [ "x$1" = "x" ] ; then
341 MAIN="Main"
342else
343 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700344 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100345fi
346
347if [ "$ZYGOTE" = "" ]; then
348 if [ "$OPTIMIZE" = "y" ]; then
349 if [ "$VERIFY" = "y" ]; then
350 DEX_OPTIMIZE="-Xdexopt:verified"
351 else
352 DEX_OPTIMIZE="-Xdexopt:all"
353 fi
354 msg "Performing optimizations"
355 else
356 DEX_OPTIMIZE="-Xdexopt:none"
357 msg "Skipping optimizations"
358 fi
359
360 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100361 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100362 msg "Performing verification"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700363 elif [ "$VERIFY" = "s" ]; then
364 JVM_VERIFY_ARG="Xverify:all"
365 DEX_VERIFY="-Xverify:softfail"
366 msg "Forcing verification to be soft fail"
367 else # VERIFY = "n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100368 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100369 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100370 msg "Skipping verification"
371 fi
372fi
373
374msg "------------------------------"
375
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100376if [ "$DEBUGGER" = "y" ]; then
377 # Use this instead for ddms and connect by running 'ddms':
378 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
379 # TODO: add a separate --ddms option?
380
381 PORT=12345
382 msg "Waiting for jdb to connect:"
383 if [ "$HOST" = "n" ]; then
384 msg " adb forward tcp:$PORT tcp:$PORT"
385 fi
386 msg " jdb -attach localhost:$PORT"
387 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
388fi
389
Alex Lightfba89fe2017-01-12 16:11:02 -0800390if [ "$IS_JVMTI_TEST" = "y" ]; then
391 plugin=libopenjdkjvmtid.so
392 agent=libtiagentd.so
393 lib=tiagentd
394 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
395 agent=libtiagent.so
396 plugin=libopenjdkjvmti.so
397 lib=tiagent
398 fi
399
400 ARGS="${ARGS} ${lib}"
401 if [[ "$USE_JVM" = "y" ]]; then
402 FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${TEST_NAME},jvm"
403 else
404 FLAGS="${FLAGS} -agentpath:${agent}=${TEST_NAME},art"
405 FLAGS="${FLAGS} -Xplugin:${plugin}"
Nicolas Geoffraya0619e22016-12-20 13:57:43 +0000406 FLAGS="${FLAGS} -Xcompiler-option --debuggable"
Alex Lightfba89fe2017-01-12 16:11:02 -0800407 # Always make the compilation be debuggable.
408 COMPILE_FLAGS="${COMPILE_FLAGS} --debuggable"
409 fi
410fi
411
Alex Light8f2c6d42017-04-10 16:27:35 -0700412if [[ "$JVMTI_STRESS" = "y" ]]; then
Alex Light42151c02017-04-20 15:54:25 -0700413 plugin=libopenjdkjvmtid.so
414 agent=libtistressd.so
415 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
416 agent=libtistress.so
417 plugin=libopenjdkjvmti.so
418 fi
Alex Light8f2c6d42017-04-10 16:27:35 -0700419
Alex Lightb7edcda2017-04-27 13:20:31 -0700420 # Just give it a default start so we can always add ',' to it.
421 agent_args="jvmti-stress"
422 if [[ "$JVMTI_REDEFINE_STRESS" = "y" ]]; then
423 # We really cannot do this on RI so don't both passing it in that case.
424 if [[ "$USE_JVM" = "n" ]]; then
Alex Lightceae9542017-09-07 13:28:00 -0700425 agent_args="${agent_args},redefine"
Alex Lightb7edcda2017-04-27 13:20:31 -0700426 fi
427 fi
Alex Light43e935d2017-06-19 15:40:40 -0700428 if [[ "$JVMTI_FIELD_STRESS" = "y" ]]; then
429 agent_args="${agent_args},field"
430 fi
Alex Lightc38c3692017-06-27 15:45:14 -0700431 if [[ "$JVMTI_STEP_STRESS" = "y" ]]; then
432 agent_args="${agent_args},step"
433 fi
Alex Lightb7edcda2017-04-27 13:20:31 -0700434 if [[ "$JVMTI_TRACE_STRESS" = "y" ]]; then
435 agent_args="${agent_args},trace"
436 fi
437 # In the future add onto this;
Alex Light42151c02017-04-20 15:54:25 -0700438 if [[ "$USE_JVM" = "y" ]]; then
Alex Lightb7edcda2017-04-27 13:20:31 -0700439 FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${agent_args}"
Alex Light42151c02017-04-20 15:54:25 -0700440 else
Alex Lightb7edcda2017-04-27 13:20:31 -0700441 FLAGS="${FLAGS} -agentpath:${agent}=${agent_args}"
Alex Light8f2c6d42017-04-10 16:27:35 -0700442 if [ "$IS_JVMTI_TEST" = "n" ]; then
443 FLAGS="${FLAGS} -Xplugin:${plugin}"
444 FLAGS="${FLAGS} -Xcompiler-option --debuggable"
445 # Always make the compilation be debuggable.
446 COMPILE_FLAGS="${COMPILE_FLAGS} --debuggable"
447 fi
448 fi
449fi
450
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100451if [ "$USE_JVM" = "y" ]; then
Alex Light9c20a142016-08-23 15:05:12 -0700452 export LD_LIBRARY_PATH=${ANDROID_HOST_OUT}/lib64
Alex Light47d49b82017-07-25 14:06:34 -0700453 # Some jvmti tests are flaky without -Xint on the RI.
454 if [ "$IS_JVMTI_TEST" = "y" ]; then
455 FLAGS="${FLAGS} -Xint"
456 fi
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700457 # Xmx is necessary since we don't pass down the ART flags to JVM.
Vladimir Markoc5798bf2016-12-09 10:20:54 +0000458 # We pass the classes2 path whether it's used (src-multidex) or not.
459 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes:classes2 ${FLAGS} $MAIN $@ ${ARGS}"
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700460 if [ "$DEV_MODE" = "y" ]; then
461 echo $cmdline
462 fi
463 $cmdline
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100464 exit
465fi
466
467
468if [ "$HAVE_IMAGE" = "n" ]; then
Vladimir Markoe00e5592017-02-24 14:58:29 +0000469 if [ "${HOST}" = "y" ]; then
470 framework="${ANDROID_HOST_OUT}/framework"
471 bpath_suffix="-hostdex"
472 else
473 framework="${ANDROID_ROOT}/framework"
Nicolas Geoffray320ccca2017-03-01 10:03:08 +0000474 bpath_suffix="-testdex"
Vladimir Markoe00e5592017-02-24 14:58:29 +0000475 fi
Vladimir Markoe00e5592017-02-24 14:58:29 +0000476 bpath="${framework}/core-libart${bpath_suffix}.jar"
477 bpath="${bpath}:${framework}/core-oj${bpath_suffix}.jar"
478 bpath="${bpath}:${framework}/conscrypt${bpath_suffix}.jar"
479 bpath="${bpath}:${framework}/okhttp${bpath_suffix}.jar"
480 bpath="${bpath}:${framework}/bouncycastle${bpath_suffix}.jar"
481 # Pass down the bootclasspath
482 FLAGS="${FLAGS} -Xbootclasspath:${bpath}"
Nicolas Geoffray47e61d52017-01-31 09:13:52 +0000483 # Add 5 minutes to give some time to generate the boot image.
484 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + 300))
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000485 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000486else
487 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100488fi
489
490
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100491if [ "$USE_GDB" = "y" ]; then
492 if [ "$HOST" = "n" ]; then
493 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100494 else
495 if [ `uname` = "Darwin" ]; then
496 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700497 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100498 DALVIKVM=
499 else
500 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700501 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100502 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
503 # gdbargs="--annotate=3 $gdbargs"
504 fi
505 fi
506fi
507
508if [ "$INTERPRETER" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000509 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700510 if [ "$VERIFY" = "y" ] ; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100511 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=quicken"
512 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=quicken"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700513 elif [ "$VERIFY" = "s" ]; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100514 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=extract"
515 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=extract"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700516 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
517 else # VERIFY = "n"
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100518 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=assume-verified"
519 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=assume-verified"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700520 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
521 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100522fi
523
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800524if [ "$JIT" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000525 INT_OPTS="-Xusejit:true"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800526 if [ "$VERIFY" = "y" ] ; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100527 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=quicken"
528 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=quicken"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800529 else
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100530 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=assume-verified"
531 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=assume-verified"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800532 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
533 fi
534fi
535
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100536JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
537
Richard Uhler020c0f32017-03-14 16:23:17 +0000538COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100539if [ "$RELOCATE" = "y" ]; then
Richard Uhlerc52f3032017-03-02 13:45:45 +0000540 FLAGS="${FLAGS} -Xrelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100541else
542 FLAGS="$FLAGS -Xnorelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100543fi
544
545if [ "$HOST" = "n" ]; then
Nicolas Geoffrayd295bc82016-11-04 13:03:05 +0000546 # Need to be root to query /data/dalvik-cache
547 adb root > /dev/null
548 adb wait-for-device
549 ISA=
550 ISA_adb_invocation=
551 ISA_outcome=
552 # We iterate a few times to workaround an adb issue. b/32655576
553 for i in {1..10}; do
554 ISA_adb_invocation=$(adb shell ls -F /data/dalvik-cache)
555 ISA_outcome=$?
556 ISA=$(echo $ISA_adb_invocation | grep -Ewo "${ARCHITECTURES_PATTERN}")
557 if [ x"$ISA" != "x" ]; then
558 break;
559 fi
560 done
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100561 if [ x"$ISA" = "x" ]; then
562 echo "Unable to determine architecture"
Nicolas Geoffray8f500fa2016-11-03 11:18:48 +0000563 # Print a few things for helping diagnosing the problem.
Nicolas Geoffrayd295bc82016-11-04 13:03:05 +0000564 echo "adb invocation output: $ISA_adb_invocation"
565 echo "adb invocation outcome: $ISA_outcome"
Nicolas Geoffray8f500fa2016-11-03 11:18:48 +0000566 echo $(adb shell ls -F /data/dalvik-cache)
567 echo $(adb shell ls /data/dalvik-cache)
568 echo ${ARCHITECTURES_PATTERN}
569 echo $(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100570 exit 1
571 fi
572fi
573
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700574# Prevent test from silently falling back to interpreter in no-prebuild mode. This happens
575# when DEX_LOCATION path is too long, because vdex/odex filename is constructed by taking
576# full path to dex, stripping leading '/', appending '@classes.vdex' and changing every
577# remaining '/' into '@'.
578if [ "$HOST" = "y" ]; then
579 max_filename_size=$(getconf NAME_MAX $DEX_LOCATION)
580else
581 # There is no getconf on device, fallback to standard value. See NAME_MAX in kernel <linux/limits.h>
582 max_filename_size=255
583fi
584# Compute VDEX_NAME.
585DEX_LOCATION_STRIPPED="${DEX_LOCATION#/}"
586VDEX_NAME="${DEX_LOCATION_STRIPPED//\//@}@$TEST_NAME.jar@classes.vdex"
587if [ ${#VDEX_NAME} -gt $max_filename_size ]; then
Nicolas Geoffraybea3e312017-03-07 09:59:05 +0000588 echo "Dex location path too long:"
589 echo "$VDEX_NAME is ${#VDEX_NAME} character long, and the limit is $max_filename_size."
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700590 exit 1
591fi
592
Calin Juravle13439f02017-02-21 01:17:21 -0800593profman_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100594dex2oat_cmdline="true"
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000595vdex_cmdline="true"
Narayan Kamath84695ae2017-04-07 15:41:41 +0100596mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/dalvik-cache/$ISA"
Richard Uhler76f5cb62016-04-04 13:30:16 -0700597strip_cmdline="true"
Igor Murashkin271a0f82017-02-14 21:14:17 +0000598sync_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100599
Jeff Hao002b9312017-03-27 16:23:08 -0700600# PROFILE takes precedence over RANDOM_PROFILE, since PROFILE tests require a
601# specific profile to run properly.
602if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000603 profman_cmdline="${ANDROID_ROOT}/bin/profman \
604 --apk=$DEX_LOCATION/$TEST_NAME.jar \
Jeff Hao002b9312017-03-27 16:23:08 -0700605 --dex-location=$DEX_LOCATION/$TEST_NAME.jar"
Calin Juravle6df62f72017-04-28 19:58:01 -0700606 if [ -f $DEX_LOCATION/$TEST_NAME-ex.jar ]; then
607 profman_cmdline="${profman_cmdline} \
608 --apk=$DEX_LOCATION/$TEST_NAME-ex.jar \
609 --dex-location=$DEX_LOCATION/$TEST_NAME-ex.jar"
610 fi
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000611 COMPILE_FLAGS="${COMPILE_FLAGS} --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
612 FLAGS="${FLAGS} -Xcompiler-option --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
Jeff Hao002b9312017-03-27 16:23:08 -0700613 if [ "$PROFILE" = "y" ]; then
614 profman_cmdline="${profman_cmdline} --create-profile-from=$DEX_LOCATION/profile \
615 --reference-profile-file=$DEX_LOCATION/$TEST_NAME.prof"
616 else
617 profman_cmdline="${profman_cmdline} --generate-test-profile=$DEX_LOCATION/$TEST_NAME.prof \
618 --generate-test-profile-seed=0"
619 fi
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000620fi
621
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100622if [ "$PREBUILD" = "y" ]; then
Alex Lightafb5d192016-05-24 15:57:45 -0700623 mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/oat/$ISA"
Calin Juravle857f0582016-12-20 14:36:59 +0000624 if [ "$APP_IMAGE" = "y" ]; then
625 # Pick a base that will force the app image to get relocated.
626 app_image="--base=0x4000 --app-image-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.art"
627 fi
628
Roland Levillain6c3af162017-04-27 11:18:56 +0100629 dex2oat_binary=dex2oatd
630 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
631 dex2oat_binary=dex2oat
632 fi
633 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/$dex2oat_binary \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100634 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000635 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100636 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
Andreas Gampe14759242016-03-23 10:54:21 -0700637 --oat-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.odex \
Jeff Haodcdc85b2015-12-04 14:06:18 -0800638 ${app_image} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100639 --instruction-set=$ISA"
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700640 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
641 dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
642 fi
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700643
644 # Add in a timeout. This is important for testing the compilation/verification time of
645 # pathological cases.
646 # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
647 # now. We should try to improve this.
648 # The current value is rather arbitrary. run-tests should compile quickly.
649 if [ "$HOST" != "n" ]; then
650 # Use SIGRTMIN+2 to try to dump threads.
651 # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
Andreas Gampe43ee0542017-06-05 18:04:52 -0700652 dex2oat_cmdline="timeout -k 1m -s SIGRTMIN+2 90s ${dex2oat_cmdline} --watchdog-timeout=60000"
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700653 fi
Nicolas Geoffrayfbc4f112017-04-27 21:45:35 +0100654 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
655 vdex_cmdline="${dex2oat_cmdline} ${VDEX_FILTER} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex --output-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
656 elif [ "$TEST_VDEX" = "y" ]; then
Nicolas Geoffray74981052017-01-16 17:54:09 +0000657 vdex_cmdline="${dex2oat_cmdline} ${VDEX_FILTER} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
Nicolas Geoffraycab65572017-04-21 17:16:44 +0100658 elif [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
659 vdex_cmdline="${dex2oat_cmdline} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex --output-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000660 fi
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700661fi
662
Richard Uhler76f5cb62016-04-04 13:30:16 -0700663if [ "$STRIP_DEX" = "y" ]; then
664 strip_cmdline="zip --quiet --delete $DEX_LOCATION/$TEST_NAME.jar classes.dex"
665fi
666
Igor Murashkin271a0f82017-02-14 21:14:17 +0000667if [ "$SYNC_BEFORE_RUN" = "y" ]; then
668 sync_cmdline="sync"
669fi
670
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700671DALVIKVM_ISA_FEATURES_ARGS=""
672if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
673 DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100674fi
675
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000676# java.io.tmpdir can only be set at launch time.
677TMP_DIR_OPTION=""
678if [ "$HOST" = "n" ]; then
679 TMP_DIR_OPTION="-Djava.io.tmpdir=/data/local/tmp"
680fi
681
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000682# We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
683# b/27185632
684# b/24664297
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000685dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100686 $GDB_ARGS \
687 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700688 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100689 -XXlib:$LIB \
690 $PATCHOAT \
691 $DEX2OAT \
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700692 $DALVIKVM_ISA_FEATURES_ARGS \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100693 $ZYGOTE \
694 $JNI_OPTS \
695 $INT_OPTS \
696 $DEBUGGER_OPTS \
697 $DALVIKVM_BOOT_OPT \
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000698 $TMP_DIR_OPTION \
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000699 -XX:DumpNativeStackOnSigQuit:false \
Mathieu Chartier031768a2015-08-27 10:25:02 -0700700 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100701
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -0800702# Remove whitespace.
703dex2oat_cmdline=$(echo $dex2oat_cmdline)
704dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000705vdex_cmdline=$(echo $vdex_cmdline)
Calin Juravle13439f02017-02-21 01:17:21 -0800706profman_cmdline=$(echo $profman_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100707
Andreas Gampeb31a8e72017-05-16 10:30:24 -0700708# Use an empty ASAN_OPTIONS to enable defaults.
709# Note: this is required as envsetup right now exports detect_leaks=0.
710RUN_TEST_ASAN_OPTIONS=""
711
Andreas Gampe58408392017-05-16 10:45:46 -0700712# Multiple shutdown leaks. b/38341789
713if [ "x$RUN_TEST_ASAN_OPTIONS" != "x" ] ; then
714 RUN_TEST_ASAN_OPTIONS="${RUN_TEST_ASAN_OPTIONS}:"
715fi
716RUN_TEST_ASAN_OPTIONS="${RUN_TEST_ASAN_OPTIONS}detect_leaks=0"
717
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100718if [ "$HOST" = "n" ]; then
719 adb root > /dev/null
720 adb wait-for-device
721 if [ "$QUIET" = "n" ]; then
Calin Juravle24bd3f92017-05-11 00:36:53 -0700722 adb shell rm -rf $DEX_LOCATION
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100723 adb shell mkdir -p $DEX_LOCATION
724 adb push $TEST_NAME.jar $DEX_LOCATION
725 adb push $TEST_NAME-ex.jar $DEX_LOCATION
Jeff Hao002b9312017-03-27 16:23:08 -0700726 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Calin Juravle13439f02017-02-21 01:17:21 -0800727 adb push profile $DEX_LOCATION
728 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100729 else
730 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
731 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
732 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
733 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
Jeff Hao002b9312017-03-27 16:23:08 -0700734 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Calin Juravle13439f02017-02-21 01:17:21 -0800735 adb push profile $DEX_LOCATION >/dev/null 2>&1
736 fi
737
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100738 fi
739
Colin Crossafd3c9e2016-09-16 13:47:21 -0700740 LD_LIBRARY_PATH=/data/$TEST_DIRECTORY/art/$ISA
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000741 if [ "$ANDROID_ROOT" != "/system" ]; then
742 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
743 # so we can only use LD_LIBRARY_PATH when testing on a local
744 # installation.
Alex Light7233c7e2016-07-28 10:07:45 -0700745 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY:$LD_LIBRARY_PATH
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000746 fi
747
Dimitry Ivanov49c2c922017-02-14 11:06:14 -0800748 # System libraries needed by libarttestd.so
749 PUBLIC_LIBS=libart.so:libartd.so:libc++.so:libbacktrace.so:libbase.so:libnativehelper.so
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700750
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100751 # Create a script with the command. The command can get longer than the longest
752 # allowed adb command and there is no way to get the exit status from a adb shell
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700753 # command. Dalvik cache is cleaned before running to make subsequent executions
754 # of the script follow the same runtime path.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100755 cmdline="cd $DEX_LOCATION && \
Andreas Gampeb31a8e72017-05-16 10:30:24 -0700756 export ASAN_OPTIONS=$RUN_TEST_ASAN_OPTIONS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100757 export ANDROID_DATA=$DEX_LOCATION && \
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700758 export ANDROID_ADDITIONAL_PUBLIC_LIBRARIES=$PUBLIC_LIBS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100759 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000760 export ANDROID_ROOT=$ANDROID_ROOT && \
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700761 rm -rf ${DEX_LOCATION}/dalvik-cache/ && \
Alex Lightafb5d192016-05-24 15:57:45 -0700762 mkdir -p ${mkdir_locations} && \
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100763 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray4f7fdd22015-04-24 11:57:37 +0100764 export PATH=$ANDROID_ROOT/bin:$PATH && \
Calin Juravle13439f02017-02-21 01:17:21 -0800765 $profman_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100766 $dex2oat_cmdline && \
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000767 $vdex_cmdline && \
Richard Uhler76f5cb62016-04-04 13:30:16 -0700768 $strip_cmdline && \
Igor Murashkin271a0f82017-02-14 21:14:17 +0000769 $sync_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100770 $dalvikvm_cmdline"
771
772 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
773 echo "$cmdline" > $cmdfile
774
775 if [ "$DEV_MODE" = "y" ]; then
776 echo $cmdline
777 fi
778
779 if [ "$QUIET" = "n" ]; then
780 adb push $cmdfile $DEX_LOCATION/cmdline.sh
781 else
782 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
783 fi
784
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700785 if [ "$DRY_RUN" != "y" ]; then
786 adb shell sh $DEX_LOCATION/cmdline.sh
787 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100788
789 rm -f $cmdfile
790else
Calin Juravle24bd3f92017-05-11 00:36:53 -0700791 # Host run.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100792 export ANDROID_PRINTF_LOG=brief
Andreas Gampea8780822015-03-13 19:51:09 -0700793
794 # By default, and for prebuild dex2oat, we are interested in errors being logged. In dev mode
795 # we want debug messages.
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700796 if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
797 if [ "$DEV_MODE" = "y" ]; then
798 export ANDROID_LOG_TAGS='*:d'
799 else
800 export ANDROID_LOG_TAGS='*:e'
801 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100802 fi
Andreas Gampea8780822015-03-13 19:51:09 -0700803
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100804 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000805 export ANDROID_ROOT="${ANDROID_ROOT}"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700806 export LD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
807 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100808 export PATH="$PATH:${ANDROID_ROOT}/bin"
809
David Srbeckyc9ede382015-06-20 06:03:53 +0100810 # Temporarily disable address space layout randomization (ASLR).
811 # This is needed on the host so that the linker loads core.oat at the necessary address.
812 export LD_USE_LOAD_BIAS=1
813
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100814 cmdline="$dalvikvm_cmdline"
815
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700816 if [ "$TIME_OUT" = "gdb" ]; then
817 if [ `uname` = "Darwin" ]; then
818 # Fall back to timeout on Mac.
819 TIME_OUT="timeout"
Hiroshi Yamauchic823eff2015-09-01 16:21:35 -0700820 elif [ "$ISA" = "x86" ]; then
821 # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
822 TIME_OUT="timeout"
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700823 else
824 # Check if gdb is available.
825 gdb --eval-command="quit" > /dev/null 2>&1
826 if [ $? != 0 ]; then
827 # gdb isn't available. Fall back to timeout.
828 TIME_OUT="timeout"
829 fi
830 fi
831 fi
832
833 if [ "$TIME_OUT" = "timeout" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100834 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -0800835 #
Andreas Gampe6fb92562016-08-01 21:53:57 -0700836 # Note: We first send SIGRTMIN+2 (usually 36) to ART, which will induce a full thread dump
837 # before abort. However, dumping threads might deadlock, so we also use the "-k"
838 # option to definitely kill the child.
839 cmdline="timeout -k 120s -s SIGRTMIN+2 ${TIME_OUT_VALUE}s $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100840 fi
841
842 if [ "$DEV_MODE" = "y" ]; then
Calin Juravle13439f02017-02-21 01:17:21 -0800843 echo "mkdir -p ${mkdir_locations} && $profman_cmdline && $dex2oat_cmdline && $vdex_cmdline && $strip_cmdline && $sync_cmdline && $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100844 fi
845
846 cd $ANDROID_BUILD_TOP
847
Calin Juravle24bd3f92017-05-11 00:36:53 -0700848 # Make sure we delete any existing compiler artifacts.
849 # This enables tests to call the RUN script multiple times in a row
850 # without worrying about interference.
851 rm -rf ${DEX_LOCATION}/oat
David Srbecky2e4afe82016-01-27 18:42:06 +0000852 rm -rf ${DEX_LOCATION}/dalvik-cache/
Calin Juravle24bd3f92017-05-11 00:36:53 -0700853
Andreas Gampeb31a8e72017-05-16 10:30:24 -0700854 export ASAN_OPTIONS=$RUN_TEST_ASAN_OPTIONS
855
Alex Lightafb5d192016-05-24 15:57:45 -0700856 mkdir -p ${mkdir_locations} || exit 1
Calin Juravle13439f02017-02-21 01:17:21 -0800857 $profman_cmdline || { echo "Profman failed." >&2 ; exit 2; }
Andreas Gampea8780822015-03-13 19:51:09 -0700858 $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000859 $vdex_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Richard Uhler76f5cb62016-04-04 13:30:16 -0700860 $strip_cmdline || { echo "Strip failed." >&2 ; exit 3; }
Igor Murashkin271a0f82017-02-14 21:14:17 +0000861 $sync_cmdline || { echo "Sync failed." >&2 ; exit 4; }
Andreas Gampea8780822015-03-13 19:51:09 -0700862
863 # For running, we must turn off logging when dex2oat or patchoat are missing. Otherwise we use
864 # the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700865 if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
866 if [ "$DEV_MODE" = "y" ]; then
867 export ANDROID_LOG_TAGS='*:d'
868 elif [ "$USE_DEX2OAT_AND_PATCHOAT" = "n" ]; then
869 # All tests would log the error of failing dex2oat/patchoat. Be silent here and only
870 # log fatal events.
871 export ANDROID_LOG_TAGS='*:s'
872 else
873 # We are interested in LOG(ERROR) output.
874 export ANDROID_LOG_TAGS='*:e'
875 fi
876 fi
877
878 if [ "$DRY_RUN" = "y" ]; then
879 exit 0
Andreas Gampea8780822015-03-13 19:51:09 -0700880 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100881
882 if [ "$USE_GDB" = "y" ]; then
883 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700884 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100885 else
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700886 if [ "$TIME_OUT" != "gdb" ]; then
887 trap 'kill -INT -$pid' INT
888 $cmdline "$@" 2>&1 & pid=$!
889 wait $pid
890 # Add extra detail if time out is enabled.
891 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
892 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
893 fi
894 else
895 # With a thread dump that uses gdb if a timeout.
896 trap 'kill -INT -$pid' INT
897 $cmdline "$@" 2>&1 & pid=$!
898 # Spawn a watcher process.
899 ( sleep $TIME_OUT_VALUE && \
900 echo "##### Thread dump using gdb on test timeout" && \
901 ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
902 --eval-command="call exit(124)" --eval-command=quit || \
903 kill $pid )) 2> /dev/null & watcher=$!
904 wait $pid
905 test_exit_status=$?
906 pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
907 if [ $test_exit_status = 0 ]; then
908 # The test finished normally.
909 exit 0
910 else
911 # The test failed or timed out.
912 if [ $test_exit_status = 124 ]; then
913 # The test timed out.
914 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
915 fi
916 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100917 fi
918 fi
919fi