blob: 1ba433e974a490ff295edd6cb4794c69389a101a [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=""
Roland Levillain76cfe612017-10-30 13:14:28 +000016CHROOT=
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010017COMPILE_FLAGS=""
18DALVIKVM="dalvikvm32"
19DEBUGGER="n"
Alex Light0e151e72017-10-25 10:50:35 -070020WITH_AGENT=""
Alex Lightc281ba52017-10-11 11:35:55 -070021DEBUGGER_AGENT=""
22WRAP_DEBUGGER_AGENT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010023DEV_MODE="n"
24DEX2OAT=""
Alex Light8a0e0332015-10-26 10:11:58 -070025EXPERIMENTAL=""
Nicolas Geoffray90355fe2017-02-20 09:25:40 +000026FALSE_BIN="false"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010027FLAGS=""
Alex Light7233c7e2016-07-28 10:07:45 -070028ANDROID_FLAGS=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010029GDB=""
Nicolas Geoffraybaf91022014-10-08 09:56:45 +010030GDB_ARGS=""
31GDB_SERVER="gdbserver"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010032HAVE_IMAGE="y"
33HOST="n"
34INTERPRETER="n"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080035JIT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010036INVOKE_WITH=""
Alex Lighte06b6342017-01-05 14:37:21 -080037IS_JVMTI_TEST="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010038ISA=x86
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000039LIBRARY_DIRECTORY="lib"
Colin Crossafd3c9e2016-09-16 13:47:21 -070040TEST_DIRECTORY="nativetest"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000041MAIN=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010042OPTIMIZE="y"
43PATCHOAT=""
44PREBUILD="y"
45QUIET="n"
Nicolas Geoffray94e25db2017-01-27 14:54:28 +000046RELOCATE="n"
Richard Uhler76f5cb62016-04-04 13:30:16 -070047STRIP_DEX="n"
Jeff Hao207a37d2014-10-29 17:24:25 -070048SECONDARY_DEX=""
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -070049TIME_OUT="gdb" # "n" (disabled), "timeout" (use timeout), "gdb" (use gdb)
50# Value in seconds
Hiroshi Yamauchifd3161a2017-01-18 14:47:25 -080051if [ "$ART_USE_READ_BARRIER" != "false" ]; then
Hiroshi Yamauchia9b296c2016-10-07 17:07:03 -070052 TIME_OUT_VALUE=2400 # 40 minutes.
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070053else
Mathieu Chartier2576be22016-05-24 10:24:53 -070054 TIME_OUT_VALUE=1200 # 20 minutes.
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070055fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010056USE_GDB="n"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +010057USE_JVM="n"
Alex Lightc281ba52017-10-11 11:35:55 -070058USE_JVMTI="n"
Igor Murashkin7617abd2015-07-10 18:27:47 -070059VERIFY="y" # y=yes,n=no,s=softfail
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010060ZYGOTE=""
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -070061DEX_VERIFY=""
Andreas Gampe65357032015-02-19 15:10:24 -080062USE_DEX2OAT_AND_PATCHOAT="y"
Andreas Gampe4d2ef332015-08-05 09:24:45 -070063INSTRUCTION_SET_FEATURES=""
Mathieu Chartier031768a2015-08-27 10:25:02 -070064ARGS=""
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -070065EXTERNAL_LOG_TAGS="n" # if y respect externally set ANDROID_LOG_TAGS.
66DRY_RUN="n" # if y prepare to run the test but don't run it.
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +000067TEST_VDEX="n"
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +000068TEST_DM="n"
Alex Lighte06b6342017-01-05 14:37:21 -080069TEST_IS_NDEBUG="n"
Calin Juravle857f0582016-12-20 14:36:59 +000070APP_IMAGE="y"
Alex Light8f2c6d42017-04-10 16:27:35 -070071JVMTI_STRESS="n"
Alex Lightc38c3692017-06-27 15:45:14 -070072JVMTI_STEP_STRESS="n"
Alex Light43e935d2017-06-19 15:40:40 -070073JVMTI_FIELD_STRESS="n"
Alex Lightb7edcda2017-04-27 13:20:31 -070074JVMTI_TRACE_STRESS="n"
75JVMTI_REDEFINE_STRESS="n"
Nicolas Geoffray74981052017-01-16 17:54:09 +000076VDEX_FILTER=""
Calin Juravle13439f02017-02-21 01:17:21 -080077PROFILE="n"
Jeff Hao002b9312017-03-27 16:23:08 -070078RANDOM_PROFILE="n"
Alex Light483208d2017-09-26 09:31:17 -070079# The normal dex2oat timeout.
Shubham Ajmeraf97cbd62017-10-11 10:00:57 -070080DEX2OAT_TIMEOUT="300" # 5 mins
Alex Light483208d2017-09-26 09:31:17 -070081# The *hard* timeout where we really start trying to kill the dex2oat.
Shubham Ajmeraf97cbd62017-10-11 10:00:57 -070082DEX2OAT_RT_TIMEOUT="360" # 6 mins
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010083
Igor Murashkin271a0f82017-02-14 21:14:17 +000084# if "y", run 'sync' before dalvikvm to make sure all files from
85# build step (e.g. dex2oat) were finished writing.
86SYNC_BEFORE_RUN="n"
87
Andreas Gampe1c5b42f2017-06-15 18:20:45 -070088# When running a debug build, we want to run with all checks.
89ANDROID_FLAGS="${ANDROID_FLAGS} -XX:SlowDebug=true"
Andreas Gampee8f74ca2018-01-02 09:26:16 -080090# The same for dex2oatd, both prebuild and runtime-driven.
91ANDROID_FLAGS="${ANDROID_FLAGS} -Xcompiler-option --runtime-arg -Xcompiler-option -XX:SlowDebug=true"
92COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -XX:SlowDebug=true"
Andreas Gampe1c5b42f2017-06-15 18:20:45 -070093
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010094while true; do
95 if [ "x$1" = "x--quiet" ]; then
96 QUIET="y"
97 shift
Alex Light483208d2017-09-26 09:31:17 -070098 elif [ "x$1" = "x--dex2oat-rt-timeout" ]; then
99 shift
100 if [ "x$1" = "x" ]; then
101 echo "$0 missing argument to --dex2oat-rt-timeout" 1>&2
102 exit 1
103 fi
104 DEX2OAT_RT_TIMEOUT="$1"
105 shift
106 elif [ "x$1" = "x--dex2oat-timeout" ]; then
107 shift
108 if [ "x$1" = "x" ]; then
109 echo "$0 missing argument to --dex2oat-timeout" 1>&2
110 exit 1
111 fi
112 DEX2OAT_TIMEOUT="$1"
113 shift
Alex Lighte06b6342017-01-05 14:37:21 -0800114 elif [ "x$1" = "x--jvmti" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700115 USE_JVMTI="y"
Alex Lighte06b6342017-01-05 14:37:21 -0800116 IS_JVMTI_TEST="y"
117 shift
Alex Lightfaf90b62016-08-12 14:43:48 -0700118 elif [ "x$1" = "x-O" ]; then
Alex Lighte06b6342017-01-05 14:37:21 -0800119 TEST_IS_NDEBUG="y"
Alex Lightfaf90b62016-08-12 14:43:48 -0700120 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100121 elif [ "x$1" = "x--lib" ]; then
122 shift
123 if [ "x$1" = "x" ]; then
124 echo "$0 missing argument to --lib" 1>&2
125 exit 1
126 fi
127 LIB="$1"
128 shift
Alex Light97acf192016-03-17 09:59:38 -0700129 elif [ "x$1" = "x--gc-stress" ]; then
130 # Give an extra 5 mins if we are gc-stress.
131 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + 300))
132 shift
Mathieu Chartier031768a2015-08-27 10:25:02 -0700133 elif [ "x$1" = "x--testlib" ]; then
134 shift
135 if [ "x$1" = "x" ]; then
136 echo "$0 missing argument to --testlib" 1>&2
137 exit 1
138 fi
Mathieu Chartierde286fd2015-09-03 18:10:29 -0700139 ARGS="${ARGS} $1"
Mathieu Chartier031768a2015-08-27 10:25:02 -0700140 shift
David Srbecky52886112016-01-22 13:56:47 +0000141 elif [ "x$1" = "x--args" ]; then
142 shift
143 if [ "x$1" = "x" ]; then
144 echo "$0 missing argument to --args" 1>&2
145 exit 1
146 fi
147 ARGS="${ARGS} $1"
148 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100149 elif [ "x$1" = "x-Xcompiler-option" ]; then
150 shift
151 option="$1"
152 FLAGS="${FLAGS} -Xcompiler-option $option"
153 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
154 shift
Alex Light7233c7e2016-07-28 10:07:45 -0700155 elif [ "x$1" = "x--android-runtime-option" ]; then
156 shift
157 option="$1"
158 ANDROID_FLAGS="${ANDROID_FLAGS} $option"
159 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100160 elif [ "x$1" = "x--runtime-option" ]; then
161 shift
162 option="$1"
163 FLAGS="${FLAGS} $option"
164 shift
165 elif [ "x$1" = "x--boot" ]; then
166 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000167 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100168 shift
169 elif [ "x$1" = "x--no-dex2oat" ]; then
170 DEX2OAT="-Xcompiler:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800171 USE_DEX2OAT_AND_PATCHOAT="n"
Andreas Gampe5b8a1972017-11-07 10:23:48 -0800172 PREBUILD="n" # Do not use prebuilt odex, either.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100173 shift
174 elif [ "x$1" = "x--no-patchoat" ]; then
175 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800176 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100177 shift
178 elif [ "x$1" = "x--relocate" ]; then
179 RELOCATE="y"
180 shift
181 elif [ "x$1" = "x--no-relocate" ]; then
182 RELOCATE="n"
183 shift
184 elif [ "x$1" = "x--prebuild" ]; then
185 PREBUILD="y"
186 shift
Mathieu Chartierdcd56c92017-11-20 20:30:24 -0800187 elif [ "x$1" = "x--compact-dex-level" ]; then
188 shift
189 COMPILE_FLAGS="${COMPILE_FLAGS} --compact-dex-level=$1"
190 shift
Alex Lightb7edcda2017-04-27 13:20:31 -0700191 elif [ "x$1" = "x--jvmti-redefine-stress" ]; then
192 # APP_IMAGE doesn't really work with jvmti redefine stress
Alex Lightc281ba52017-10-11 11:35:55 -0700193 USE_JVMTI="y"
Alex Light8f2c6d42017-04-10 16:27:35 -0700194 APP_IMAGE="n"
195 JVMTI_STRESS="y"
Alex Lightb7edcda2017-04-27 13:20:31 -0700196 JVMTI_REDEFINE_STRESS="y"
197 shift
Alex Lightc38c3692017-06-27 15:45:14 -0700198 elif [ "x$1" = "x--jvmti-step-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700199 USE_JVMTI="y"
Alex Lightc38c3692017-06-27 15:45:14 -0700200 JVMTI_STRESS="y"
201 JVMTI_STEP_STRESS="y"
202 shift
Alex Light43e935d2017-06-19 15:40:40 -0700203 elif [ "x$1" = "x--jvmti-field-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700204 USE_JVMTI="y"
Alex Light43e935d2017-06-19 15:40:40 -0700205 JVMTI_STRESS="y"
206 JVMTI_FIELD_STRESS="y"
207 shift
Alex Lightb7edcda2017-04-27 13:20:31 -0700208 elif [ "x$1" = "x--jvmti-trace-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700209 USE_JVMTI="y"
Alex Lightb7edcda2017-04-27 13:20:31 -0700210 JVMTI_STRESS="y"
211 JVMTI_TRACE_STRESS="y"
Alex Light8f2c6d42017-04-10 16:27:35 -0700212 shift
Calin Juravle857f0582016-12-20 14:36:59 +0000213 elif [ "x$1" = "x--no-app-image" ]; then
214 APP_IMAGE="n"
215 shift
Richard Uhler76f5cb62016-04-04 13:30:16 -0700216 elif [ "x$1" = "x--strip-dex" ]; then
217 STRIP_DEX="y"
218 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100219 elif [ "x$1" = "x--host" ]; then
220 HOST="y"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000221 ANDROID_ROOT="$ANDROID_HOST_OUT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100222 shift
223 elif [ "x$1" = "x--no-prebuild" ]; then
224 PREBUILD="n"
225 shift
226 elif [ "x$1" = "x--no-image" ]; then
227 HAVE_IMAGE="n"
228 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700229 elif [ "x$1" = "x--secondary" ]; then
230 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
Calin Juravle175dc732015-08-25 15:42:32 +0100231 # Enable cfg-append to make sure we get the dump for both dex files.
232 # (otherwise the runtime compilation of the secondary dex will overwrite
Roland Levillainb0103ca2016-11-01 14:48:47 +0000233 # the dump of the first one).
Calin Juravle175dc732015-08-25 15:42:32 +0100234 FLAGS="${FLAGS} -Xcompiler-option --dump-cfg-append"
235 COMPILE_FLAGS="${COMPILE_FLAGS} --dump-cfg-append"
Jeff Hao207a37d2014-10-29 17:24:25 -0700236 shift
Alex Light0e151e72017-10-25 10:50:35 -0700237 elif [ "x$1" = "x--with-agent" ]; then
238 shift
239 USE_JVMTI="y"
240 WITH_AGENT="$1"
241 shift
Alex Lightc281ba52017-10-11 11:35:55 -0700242 elif [ "x$1" = "x--debug-wrap-agent" ]; then
243 WRAP_DEBUGGER_AGENT="y"
244 shift
245 elif [ "x$1" = "x--debug-agent" ]; then
246 shift
247 DEBUGGER="agent"
248 USE_JVMTI="y"
249 DEBUGGER_AGENT="$1"
250 TIME_OUT="n"
251 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100252 elif [ "x$1" = "x--debug" ]; then
253 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800254 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100255 shift
256 elif [ "x$1" = "x--gdb" ]; then
257 USE_GDB="y"
258 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800259 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100260 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700261 elif [ "x$1" = "x--gdb-arg" ]; then
262 shift
263 gdb_arg="$1"
264 GDB_ARGS="${GDB_ARGS} $gdb_arg"
265 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100266 elif [ "x$1" = "x--zygote" ]; then
267 ZYGOTE="-Xzygote"
268 msg "Spawning from zygote"
269 shift
270 elif [ "x$1" = "x--dev" ]; then
271 DEV_MODE="y"
272 shift
273 elif [ "x$1" = "x--interpreter" ]; then
274 INTERPRETER="y"
275 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800276 elif [ "x$1" = "x--jit" ]; then
277 JIT="y"
278 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100279 elif [ "x$1" = "x--jvm" ]; then
280 USE_JVM="y"
281 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100282 elif [ "x$1" = "x--invoke-with" ]; then
283 shift
284 if [ "x$1" = "x" ]; then
285 echo "$0 missing argument to --invoke-with" 1>&2
286 exit 1
287 fi
288 if [ "x$INVOKE_WITH" = "x" ]; then
289 INVOKE_WITH="$1"
290 else
291 INVOKE_WITH="$INVOKE_WITH $1"
292 fi
293 shift
294 elif [ "x$1" = "x--no-verify" ]; then
295 VERIFY="n"
296 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700297 elif [ "x$1" = "x--verify-soft-fail" ]; then
298 VERIFY="s"
299 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100300 elif [ "x$1" = "x--no-optimize" ]; then
301 OPTIMIZE="n"
302 shift
Roland Levillain76cfe612017-10-30 13:14:28 +0000303 elif [ "x$1" = "x--chroot" ]; then
304 shift
305 CHROOT="$1"
306 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000307 elif [ "x$1" = "x--android-root" ]; then
308 shift
309 ANDROID_ROOT="$1"
310 shift
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700311 elif [ "x$1" = "x--instruction-set-features" ]; then
312 shift
313 INSTRUCTION_SET_FEATURES="$1"
314 shift
Mathieu Chartier2576be22016-05-24 10:24:53 -0700315 elif [ "x$1" = "x--timeout" ]; then
316 shift
317 TIME_OUT_VALUE="$1"
318 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100319 elif [ "x$1" = "x--" ]; then
320 shift
321 break
322 elif [ "x$1" = "x--64" ]; then
323 ISA="x86_64"
324 GDB_SERVER="gdbserver64"
325 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000326 LIBRARY_DIRECTORY="lib64"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700327 TEST_DIRECTORY="nativetest64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100328 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
329 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700330 elif [ "x$1" = "x--pic-test" ]; then
331 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
332 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
333 shift
Alex Light8a0e0332015-10-26 10:11:58 -0700334 elif [ "x$1" = "x--experimental" ]; then
335 if [ "$#" -lt 2 ]; then
336 echo "missing --experimental option" 1>&2
337 exit 1
338 fi
339 EXPERIMENTAL="$EXPERIMENTAL $2"
340 shift 2
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700341 elif [ "x$1" = "x--external-log-tags" ]; then
342 EXTERNAL_LOG_TAGS="y"
343 shift
344 elif [ "x$1" = "x--dry-run" ]; then
345 DRY_RUN="y"
346 shift
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000347 elif [ "x$1" = "x--vdex" ]; then
348 TEST_VDEX="y"
349 shift
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000350 elif [ "x$1" = "x--dm" ]; then
351 TEST_DM="y"
352 shift
Nicolas Geoffray74981052017-01-16 17:54:09 +0000353 elif [ "x$1" = "x--vdex-filter" ]; then
354 shift
355 option="$1"
356 VDEX_FILTER="--compiler-filter=$option"
357 shift
Igor Murashkin271a0f82017-02-14 21:14:17 +0000358 elif [ "x$1" = "x--sync" ]; then
359 SYNC_BEFORE_RUN="y"
360 shift
Calin Juravle13439f02017-02-21 01:17:21 -0800361 elif [ "x$1" = "x--profile" ]; then
362 PROFILE="y"
363 shift
Jeff Hao002b9312017-03-27 16:23:08 -0700364 elif [ "x$1" = "x--random-profile" ]; then
365 RANDOM_PROFILE="y"
366 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100367 elif expr "x$1" : "x--" >/dev/null 2>&1; then
368 echo "unknown $0 option: $1" 1>&2
369 exit 1
370 else
371 break
372 fi
373done
374
Roland Levillain76cfe612017-10-30 13:14:28 +0000375# The DEX_LOCATION with the chroot prefix, if any.
376CHROOT_DEX_LOCATION="$CHROOT$DEX_LOCATION"
377
Alex Light8a0e0332015-10-26 10:11:58 -0700378if [ "$USE_JVM" = "n" ]; then
Alex Light7233c7e2016-07-28 10:07:45 -0700379 FLAGS="${FLAGS} ${ANDROID_FLAGS}"
Alex Light8a0e0332015-10-26 10:11:58 -0700380 for feature in ${EXPERIMENTAL}; do
Alex Lightfa022852015-10-28 09:13:20 -0700381 FLAGS="${FLAGS} -Xexperimental:${feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:${feature}"
Alex Light8a0e0332015-10-26 10:11:58 -0700382 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xexperimental:${feature}"
383 done
384fi
385
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100386if [ "x$1" = "x" ] ; then
387 MAIN="Main"
388else
389 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700390 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100391fi
392
393if [ "$ZYGOTE" = "" ]; then
394 if [ "$OPTIMIZE" = "y" ]; then
395 if [ "$VERIFY" = "y" ]; then
396 DEX_OPTIMIZE="-Xdexopt:verified"
397 else
398 DEX_OPTIMIZE="-Xdexopt:all"
399 fi
400 msg "Performing optimizations"
401 else
402 DEX_OPTIMIZE="-Xdexopt:none"
403 msg "Skipping optimizations"
404 fi
405
406 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100407 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100408 msg "Performing verification"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700409 elif [ "$VERIFY" = "s" ]; then
410 JVM_VERIFY_ARG="Xverify:all"
411 DEX_VERIFY="-Xverify:softfail"
412 msg "Forcing verification to be soft fail"
413 else # VERIFY = "n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100414 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100415 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100416 msg "Skipping verification"
417 fi
418fi
419
420msg "------------------------------"
421
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100422if [ "$DEBUGGER" = "y" ]; then
423 # Use this instead for ddms and connect by running 'ddms':
424 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
425 # TODO: add a separate --ddms option?
426
427 PORT=12345
428 msg "Waiting for jdb to connect:"
429 if [ "$HOST" = "n" ]; then
430 msg " adb forward tcp:$PORT tcp:$PORT"
431 fi
432 msg " jdb -attach localhost:$PORT"
Alex Light264a4862018-01-31 16:47:58 +0000433 if [ "$USE_JVM" = "n" ]; then
434 # TODO We should switch over to using the jvmti agent by default.
435 # Need to tell the runtime to enable the internal jdwp implementation.
436 DEBUGGER_OPTS="-XjdwpOptions:transport=dt_socket,address=$PORT,server=y,suspend=y -XjdwpProvider:internal"
437 else
438 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
439 fi
Alex Lightc281ba52017-10-11 11:35:55 -0700440elif [ "$DEBUGGER" = "agent" ]; then
441 PORT=12345
442 # TODO Support ddms connection and support target.
443 if [ "$HOST" = "n" ]; then
444 echo "--debug-agent not supported yet for target!"
445 exit 1
446 fi
447 AGENTPATH=${DEBUGGER_AGENT}
448 if [ "$WRAP_DEBUGGER_AGENT" = "y" ]; then
449 WRAPPROPS="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}/libwrapagentpropertiesd.so"
450 if [ "$TEST_IS_NDEBUG" = "y" ]; then
451 WRAPPROPS="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}/libwrapagentproperties.so"
452 fi
453 AGENTPATH="${WRAPPROPS}=${ANDROID_BUILD_TOP}/art/tools/libjdwp-compat.props,${AGENTPATH}"
454 fi
455 msg "Connect to localhost:$PORT"
456 DEBUGGER_OPTS="-agentpath:${AGENTPATH}=transport=dt_socket,address=$PORT,server=y,suspend=y"
457fi
458
Alex Light0e151e72017-10-25 10:50:35 -0700459if [ "x$WITH_AGENT" != "x" ]; then
460 FLAGS="${FLAGS} -agentpath:${WITH_AGENT}"
461fi
462
Alex Lightc281ba52017-10-11 11:35:55 -0700463if [ "$USE_JVMTI" = "y" ]; then
464 if [ "$USE_JVM" = "n" ]; then
465 plugin=libopenjdkjvmtid.so
466 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
467 plugin=libopenjdkjvmti.so
468 fi
Alex Light2ce6fc82017-12-18 16:42:36 -0800469 # We used to add flags here that made the runtime debuggable but that is not
470 # needed anymore since the plugin can do it for us now.
Alex Lightc281ba52017-10-11 11:35:55 -0700471 FLAGS="${FLAGS} -Xplugin:${plugin}"
Alex Lightc281ba52017-10-11 11:35:55 -0700472 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100473fi
474
Alex Lightfba89fe2017-01-12 16:11:02 -0800475if [ "$IS_JVMTI_TEST" = "y" ]; then
Alex Lightfba89fe2017-01-12 16:11:02 -0800476 agent=libtiagentd.so
477 lib=tiagentd
478 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
479 agent=libtiagent.so
Alex Lightfba89fe2017-01-12 16:11:02 -0800480 lib=tiagent
481 fi
482
483 ARGS="${ARGS} ${lib}"
484 if [[ "$USE_JVM" = "y" ]]; then
485 FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${TEST_NAME},jvm"
486 else
487 FLAGS="${FLAGS} -agentpath:${agent}=${TEST_NAME},art"
Alex Lightfba89fe2017-01-12 16:11:02 -0800488 fi
489fi
490
Alex Light8f2c6d42017-04-10 16:27:35 -0700491if [[ "$JVMTI_STRESS" = "y" ]]; then
Alex Light42151c02017-04-20 15:54:25 -0700492 agent=libtistressd.so
493 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
494 agent=libtistress.so
Alex Light42151c02017-04-20 15:54:25 -0700495 fi
Alex Light8f2c6d42017-04-10 16:27:35 -0700496
Alex Lightb7edcda2017-04-27 13:20:31 -0700497 # Just give it a default start so we can always add ',' to it.
498 agent_args="jvmti-stress"
499 if [[ "$JVMTI_REDEFINE_STRESS" = "y" ]]; then
500 # We really cannot do this on RI so don't both passing it in that case.
501 if [[ "$USE_JVM" = "n" ]]; then
Alex Lightceae9542017-09-07 13:28:00 -0700502 agent_args="${agent_args},redefine"
Alex Lightb7edcda2017-04-27 13:20:31 -0700503 fi
504 fi
Alex Light43e935d2017-06-19 15:40:40 -0700505 if [[ "$JVMTI_FIELD_STRESS" = "y" ]]; then
506 agent_args="${agent_args},field"
507 fi
Alex Lightc38c3692017-06-27 15:45:14 -0700508 if [[ "$JVMTI_STEP_STRESS" = "y" ]]; then
509 agent_args="${agent_args},step"
510 fi
Alex Lightb7edcda2017-04-27 13:20:31 -0700511 if [[ "$JVMTI_TRACE_STRESS" = "y" ]]; then
512 agent_args="${agent_args},trace"
513 fi
514 # In the future add onto this;
Alex Light42151c02017-04-20 15:54:25 -0700515 if [[ "$USE_JVM" = "y" ]]; then
Alex Lightb7edcda2017-04-27 13:20:31 -0700516 FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${agent_args}"
Alex Light42151c02017-04-20 15:54:25 -0700517 else
Alex Lightb7edcda2017-04-27 13:20:31 -0700518 FLAGS="${FLAGS} -agentpath:${agent}=${agent_args}"
Alex Light8f2c6d42017-04-10 16:27:35 -0700519 fi
520fi
521
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100522if [ "$USE_JVM" = "y" ]; then
Alex Light9c20a142016-08-23 15:05:12 -0700523 export LD_LIBRARY_PATH=${ANDROID_HOST_OUT}/lib64
Alex Light47d49b82017-07-25 14:06:34 -0700524 # Some jvmti tests are flaky without -Xint on the RI.
525 if [ "$IS_JVMTI_TEST" = "y" ]; then
526 FLAGS="${FLAGS} -Xint"
527 fi
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700528 # Xmx is necessary since we don't pass down the ART flags to JVM.
Vladimir Markoc5798bf2016-12-09 10:20:54 +0000529 # We pass the classes2 path whether it's used (src-multidex) or not.
530 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes:classes2 ${FLAGS} $MAIN $@ ${ARGS}"
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700531 if [ "$DEV_MODE" = "y" ]; then
532 echo $cmdline
533 fi
534 $cmdline
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100535 exit
536fi
537
538
539if [ "$HAVE_IMAGE" = "n" ]; then
Vladimir Markoe00e5592017-02-24 14:58:29 +0000540 if [ "${HOST}" = "y" ]; then
541 framework="${ANDROID_HOST_OUT}/framework"
542 bpath_suffix="-hostdex"
543 else
544 framework="${ANDROID_ROOT}/framework"
Nicolas Geoffray320ccca2017-03-01 10:03:08 +0000545 bpath_suffix="-testdex"
Vladimir Markoe00e5592017-02-24 14:58:29 +0000546 fi
Vladimir Markoe00e5592017-02-24 14:58:29 +0000547 bpath="${framework}/core-libart${bpath_suffix}.jar"
548 bpath="${bpath}:${framework}/core-oj${bpath_suffix}.jar"
549 bpath="${bpath}:${framework}/conscrypt${bpath_suffix}.jar"
550 bpath="${bpath}:${framework}/okhttp${bpath_suffix}.jar"
551 bpath="${bpath}:${framework}/bouncycastle${bpath_suffix}.jar"
552 # Pass down the bootclasspath
553 FLAGS="${FLAGS} -Xbootclasspath:${bpath}"
Andreas Gampe1078d152017-11-07 18:00:54 -0800554 # Disable image dex2oat - this will forbid the runtime to patch or compile an image.
555 FLAGS="${FLAGS} -Xnoimage-dex2oat"
556
557 # We'll abuse a second flag here to test different behavior. If --relocate, use the
558 # existing image - relocation will fail as patching is disallowed. If --no-relocate,
559 # pass a non-existent image - compilation will fail as dex2oat is disallowed.
560 if [ "${RELOCATE}" = "y" ] ; then
561 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
562 else
Roland Levillainef012222017-06-21 16:28:06 +0100563 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existent/core.art"
Andreas Gampe1078d152017-11-07 18:00:54 -0800564 fi
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000565else
566 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100567fi
568
569
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100570if [ "$USE_GDB" = "y" ]; then
571 if [ "$HOST" = "n" ]; then
572 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100573 else
574 if [ `uname` = "Darwin" ]; then
575 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700576 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100577 DALVIKVM=
578 else
579 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700580 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100581 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
582 # gdbargs="--annotate=3 $gdbargs"
583 fi
584 fi
585fi
586
587if [ "$INTERPRETER" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000588 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700589 if [ "$VERIFY" = "y" ] ; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100590 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=quicken"
591 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=quicken"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700592 elif [ "$VERIFY" = "s" ]; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100593 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=extract"
594 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=extract"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700595 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
596 else # VERIFY = "n"
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100597 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=assume-verified"
598 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=assume-verified"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700599 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
600 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100601fi
602
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800603if [ "$JIT" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000604 INT_OPTS="-Xusejit:true"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800605 if [ "$VERIFY" = "y" ] ; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100606 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=quicken"
607 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=quicken"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800608 else
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100609 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=assume-verified"
610 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=assume-verified"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800611 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
612 fi
613fi
614
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100615JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
616
Richard Uhler020c0f32017-03-14 16:23:17 +0000617COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100618if [ "$RELOCATE" = "y" ]; then
Richard Uhlerc52f3032017-03-02 13:45:45 +0000619 FLAGS="${FLAGS} -Xrelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100620else
621 FLAGS="$FLAGS -Xnorelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100622fi
623
624if [ "$HOST" = "n" ]; then
Nicolas Geoffrayd295bc82016-11-04 13:03:05 +0000625 # Need to be root to query /data/dalvik-cache
626 adb root > /dev/null
627 adb wait-for-device
628 ISA=
629 ISA_adb_invocation=
630 ISA_outcome=
631 # We iterate a few times to workaround an adb issue. b/32655576
632 for i in {1..10}; do
633 ISA_adb_invocation=$(adb shell ls -F /data/dalvik-cache)
634 ISA_outcome=$?
635 ISA=$(echo $ISA_adb_invocation | grep -Ewo "${ARCHITECTURES_PATTERN}")
636 if [ x"$ISA" != "x" ]; then
637 break;
638 fi
639 done
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100640 if [ x"$ISA" = "x" ]; then
641 echo "Unable to determine architecture"
Nicolas Geoffray8f500fa2016-11-03 11:18:48 +0000642 # Print a few things for helping diagnosing the problem.
Nicolas Geoffrayd295bc82016-11-04 13:03:05 +0000643 echo "adb invocation output: $ISA_adb_invocation"
644 echo "adb invocation outcome: $ISA_outcome"
Nicolas Geoffray8f500fa2016-11-03 11:18:48 +0000645 echo $(adb shell ls -F /data/dalvik-cache)
646 echo $(adb shell ls /data/dalvik-cache)
647 echo ${ARCHITECTURES_PATTERN}
648 echo $(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100649 exit 1
650 fi
651fi
652
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700653# Prevent test from silently falling back to interpreter in no-prebuild mode. This happens
654# when DEX_LOCATION path is too long, because vdex/odex filename is constructed by taking
655# full path to dex, stripping leading '/', appending '@classes.vdex' and changing every
656# remaining '/' into '@'.
657if [ "$HOST" = "y" ]; then
658 max_filename_size=$(getconf NAME_MAX $DEX_LOCATION)
659else
Roland Levillain2ae376f2018-01-30 11:35:11 +0000660 # There is no getconf on device, fallback to standard value.
661 # See NAME_MAX in kernel <linux/limits.h>
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700662 max_filename_size=255
663fi
664# Compute VDEX_NAME.
665DEX_LOCATION_STRIPPED="${DEX_LOCATION#/}"
666VDEX_NAME="${DEX_LOCATION_STRIPPED//\//@}@$TEST_NAME.jar@classes.vdex"
667if [ ${#VDEX_NAME} -gt $max_filename_size ]; then
Nicolas Geoffraybea3e312017-03-07 09:59:05 +0000668 echo "Dex location path too long:"
669 echo "$VDEX_NAME is ${#VDEX_NAME} character long, and the limit is $max_filename_size."
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700670 exit 1
671fi
672
Calin Juravle13439f02017-02-21 01:17:21 -0800673profman_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100674dex2oat_cmdline="true"
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000675vdex_cmdline="true"
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000676dm_cmdline="true"
Andreas Gampeb09abb22018-05-03 11:51:22 -0700677mkdir_locations="${DEX_LOCATION}/dalvik-cache/$ISA"
Richard Uhler76f5cb62016-04-04 13:30:16 -0700678strip_cmdline="true"
Igor Murashkin271a0f82017-02-14 21:14:17 +0000679sync_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100680
Jeff Hao002b9312017-03-27 16:23:08 -0700681# PROFILE takes precedence over RANDOM_PROFILE, since PROFILE tests require a
682# specific profile to run properly.
683if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000684 profman_cmdline="${ANDROID_ROOT}/bin/profman \
685 --apk=$DEX_LOCATION/$TEST_NAME.jar \
Jeff Hao002b9312017-03-27 16:23:08 -0700686 --dex-location=$DEX_LOCATION/$TEST_NAME.jar"
Calin Juravle6df62f72017-04-28 19:58:01 -0700687 if [ -f $DEX_LOCATION/$TEST_NAME-ex.jar ]; then
688 profman_cmdline="${profman_cmdline} \
689 --apk=$DEX_LOCATION/$TEST_NAME-ex.jar \
690 --dex-location=$DEX_LOCATION/$TEST_NAME-ex.jar"
691 fi
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000692 COMPILE_FLAGS="${COMPILE_FLAGS} --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
693 FLAGS="${FLAGS} -Xcompiler-option --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
Jeff Hao002b9312017-03-27 16:23:08 -0700694 if [ "$PROFILE" = "y" ]; then
695 profman_cmdline="${profman_cmdline} --create-profile-from=$DEX_LOCATION/profile \
696 --reference-profile-file=$DEX_LOCATION/$TEST_NAME.prof"
697 else
698 profman_cmdline="${profman_cmdline} --generate-test-profile=$DEX_LOCATION/$TEST_NAME.prof \
699 --generate-test-profile-seed=0"
700 fi
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000701fi
702
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100703if [ "$PREBUILD" = "y" ]; then
Alex Lightafb5d192016-05-24 15:57:45 -0700704 mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/oat/$ISA"
Calin Juravle857f0582016-12-20 14:36:59 +0000705 if [ "$APP_IMAGE" = "y" ]; then
706 # Pick a base that will force the app image to get relocated.
707 app_image="--base=0x4000 --app-image-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.art"
708 fi
709
Roland Levillain6c3af162017-04-27 11:18:56 +0100710 dex2oat_binary=dex2oatd
711 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
712 dex2oat_binary=dex2oat
713 fi
714 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/$dex2oat_binary \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100715 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000716 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100717 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
Andreas Gampe14759242016-03-23 10:54:21 -0700718 --oat-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.odex \
Jeff Haodcdc85b2015-12-04 14:06:18 -0800719 ${app_image} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100720 --instruction-set=$ISA"
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700721 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
722 dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
723 fi
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700724
725 # Add in a timeout. This is important for testing the compilation/verification time of
726 # pathological cases.
727 # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
728 # now. We should try to improve this.
729 # The current value is rather arbitrary. run-tests should compile quickly.
Alex Light483208d2017-09-26 09:31:17 -0700730 # Watchdog timeout is in milliseconds so add 3 '0's to the dex2oat timeout.
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700731 if [ "$HOST" != "n" ]; then
732 # Use SIGRTMIN+2 to try to dump threads.
733 # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
Alex Light483208d2017-09-26 09:31:17 -0700734 dex2oat_cmdline="timeout -k ${DEX2OAT_TIMEOUT}s -s SIGRTMIN+2 ${DEX2OAT_RT_TIMEOUT}s ${dex2oat_cmdline} --watchdog-timeout=${DEX2OAT_TIMEOUT}000"
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700735 fi
Nicolas Geoffrayfbc4f112017-04-27 21:45:35 +0100736 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
737 vdex_cmdline="${dex2oat_cmdline} ${VDEX_FILTER} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex --output-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
738 elif [ "$TEST_VDEX" = "y" ]; then
Nicolas Geoffray74981052017-01-16 17:54:09 +0000739 vdex_cmdline="${dex2oat_cmdline} ${VDEX_FILTER} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000740 elif [ "$TEST_DM" = "y" ]; then
741 dex2oat_cmdline="${dex2oat_cmdline} --output-vdex=$DEX_LOCATION/oat/$ISA/primary.vdex"
742 dm_cmdline="zip -qj $DEX_LOCATION/oat/$ISA/$TEST_NAME.dm $DEX_LOCATION/oat/$ISA/primary.vdex"
743 vdex_cmdline="${dex2oat_cmdline} --dump-timings --dm-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.dm"
Nicolas Geoffraycab65572017-04-21 17:16:44 +0100744 elif [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
745 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 +0000746 fi
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700747fi
748
Richard Uhler76f5cb62016-04-04 13:30:16 -0700749if [ "$STRIP_DEX" = "y" ]; then
750 strip_cmdline="zip --quiet --delete $DEX_LOCATION/$TEST_NAME.jar classes.dex"
751fi
752
Igor Murashkin271a0f82017-02-14 21:14:17 +0000753if [ "$SYNC_BEFORE_RUN" = "y" ]; then
754 sync_cmdline="sync"
755fi
756
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700757DALVIKVM_ISA_FEATURES_ARGS=""
758if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
759 DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100760fi
761
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000762# java.io.tmpdir can only be set at launch time.
763TMP_DIR_OPTION=""
764if [ "$HOST" = "n" ]; then
765 TMP_DIR_OPTION="-Djava.io.tmpdir=/data/local/tmp"
766fi
767
Nicolas Geoffray6ee49712018-03-30 14:39:05 +0000768# We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
769# b/27185632
770# b/24664297
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000771dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100772 $GDB_ARGS \
773 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700774 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100775 -XXlib:$LIB \
776 $PATCHOAT \
777 $DEX2OAT \
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700778 $DALVIKVM_ISA_FEATURES_ARGS \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100779 $ZYGOTE \
780 $JNI_OPTS \
781 $INT_OPTS \
782 $DEBUGGER_OPTS \
783 $DALVIKVM_BOOT_OPT \
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000784 $TMP_DIR_OPTION \
Nicolas Geoffray6ee49712018-03-30 14:39:05 +0000785 -XX:DumpNativeStackOnSigQuit:false \
Mathieu Chartier031768a2015-08-27 10:25:02 -0700786 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100787
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -0800788# Remove whitespace.
789dex2oat_cmdline=$(echo $dex2oat_cmdline)
790dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000791dm_cmdline=$(echo $dm_cmdline)
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000792vdex_cmdline=$(echo $vdex_cmdline)
Calin Juravle13439f02017-02-21 01:17:21 -0800793profman_cmdline=$(echo $profman_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100794
Andreas Gampeb31a8e72017-05-16 10:30:24 -0700795# Use an empty ASAN_OPTIONS to enable defaults.
796# Note: this is required as envsetup right now exports detect_leaks=0.
797RUN_TEST_ASAN_OPTIONS=""
798
Andreas Gampe58408392017-05-16 10:45:46 -0700799# Multiple shutdown leaks. b/38341789
800if [ "x$RUN_TEST_ASAN_OPTIONS" != "x" ] ; then
801 RUN_TEST_ASAN_OPTIONS="${RUN_TEST_ASAN_OPTIONS}:"
802fi
803RUN_TEST_ASAN_OPTIONS="${RUN_TEST_ASAN_OPTIONS}detect_leaks=0"
804
Nicolas Geoffrayf39f04c2018-03-05 15:42:11 +0000805# For running, we must turn off logging when dex2oat or patchoat are missing. Otherwise we use
806# the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
807if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
808 if [ "$DEV_MODE" = "y" ]; then
809 export ANDROID_LOG_TAGS='*:d'
810 elif [ "$USE_DEX2OAT_AND_PATCHOAT" = "n" ]; then
811 # All tests would log the error of failing dex2oat/patchoat. Be silent here and only
812 # log fatal events.
813 export ANDROID_LOG_TAGS='*:s'
814 elif [ "$HAVE_IMAGE" = "n" ]; then
815 # All tests would log the error of missing image. Be silent here and only log fatal
816 # events.
817 export ANDROID_LOG_TAGS='*:s'
818 else
819 # We are interested in LOG(ERROR) output.
820 export ANDROID_LOG_TAGS='*:e'
821 fi
822fi
823
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100824if [ "$HOST" = "n" ]; then
825 adb root > /dev/null
826 adb wait-for-device
827 if [ "$QUIET" = "n" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +0000828 adb shell rm -rf $CHROOT_DEX_LOCATION
829 adb shell mkdir -p $CHROOT_DEX_LOCATION
830 adb push $TEST_NAME.jar $CHROOT_DEX_LOCATION
831 adb push $TEST_NAME-ex.jar $CHROOT_DEX_LOCATION
Jeff Hao002b9312017-03-27 16:23:08 -0700832 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +0000833 adb push profile $CHROOT_DEX_LOCATION
Calin Juravle13439f02017-02-21 01:17:21 -0800834 fi
David Brazdil7d2ec612018-01-19 14:19:59 +0000835 # Copy resource folder
836 if [ -d res ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +0000837 adb push res $CHROOT_DEX_LOCATION
David Brazdil7d2ec612018-01-19 14:19:59 +0000838 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100839 else
Roland Levillain76cfe612017-10-30 13:14:28 +0000840 adb shell rm -rf $CHROOT_DEX_LOCATION >/dev/null 2>&1
841 adb shell mkdir -p $CHROOT_DEX_LOCATION >/dev/null 2>&1
842 adb push $TEST_NAME.jar $CHROOT_DEX_LOCATION >/dev/null 2>&1
843 adb push $TEST_NAME-ex.jar $CHROOT_DEX_LOCATION >/dev/null 2>&1
Jeff Hao002b9312017-03-27 16:23:08 -0700844 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +0000845 adb push profile $CHROOT_DEX_LOCATION >/dev/null 2>&1
Calin Juravle13439f02017-02-21 01:17:21 -0800846 fi
David Brazdil7d2ec612018-01-19 14:19:59 +0000847 # Copy resource folder
848 if [ -d res ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +0000849 adb push res $CHROOT_DEX_LOCATION >/dev/null 2>&1
David Brazdil7d2ec612018-01-19 14:19:59 +0000850 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100851 fi
852
Colin Crossafd3c9e2016-09-16 13:47:21 -0700853 LD_LIBRARY_PATH=/data/$TEST_DIRECTORY/art/$ISA
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000854 if [ "$ANDROID_ROOT" != "/system" ]; then
855 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
856 # so we can only use LD_LIBRARY_PATH when testing on a local
857 # installation.
Roland Levillain76cfe612017-10-30 13:14:28 +0000858 LD_LIBRARY_PATH="$ANDROID_ROOT/$LIBRARY_DIRECTORY:$LD_LIBRARY_PATH"
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000859 fi
860
Dimitry Ivanov49c2c922017-02-14 11:06:14 -0800861 # System libraries needed by libarttestd.so
Vladimir Marko2da72ed2018-03-07 12:58:11 +0000862 PUBLIC_LIBS=libc++.so:libbacktrace.so:libbase.so:libnativehelper.so
863 if [ "$TEST_IS_NDEBUG" = "y" ]; then
David Sehr1f010162018-05-15 08:59:32 -0700864 PUBLIC_LIBS=$PUBLIC_LIBS:libart.so:libdexfile.so:libprofile.so:libartbase.so
Vladimir Marko2da72ed2018-03-07 12:58:11 +0000865 else
David Sehr1f010162018-05-15 08:59:32 -0700866 PUBLIC_LIBS=$PUBLIC_LIBS:libartd.so:libdexfiled.so:libprofiled.so:libartbased.so
Vladimir Marko2da72ed2018-03-07 12:58:11 +0000867 fi
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700868
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100869 # Create a script with the command. The command can get longer than the longest
870 # allowed adb command and there is no way to get the exit status from a adb shell
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700871 # command. Dalvik cache is cleaned before running to make subsequent executions
872 # of the script follow the same runtime path.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100873 cmdline="cd $DEX_LOCATION && \
Andreas Gampeb31a8e72017-05-16 10:30:24 -0700874 export ASAN_OPTIONS=$RUN_TEST_ASAN_OPTIONS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100875 export ANDROID_DATA=$DEX_LOCATION && \
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700876 export ANDROID_ADDITIONAL_PUBLIC_LIBRARIES=$PUBLIC_LIBS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100877 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000878 export ANDROID_ROOT=$ANDROID_ROOT && \
Nicolas Geoffrayf39f04c2018-03-05 15:42:11 +0000879 export ANDROID_LOG_TAGS=$ANDROID_LOG_TAGS && \
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700880 rm -rf ${DEX_LOCATION}/dalvik-cache/ && \
Alex Lightafb5d192016-05-24 15:57:45 -0700881 mkdir -p ${mkdir_locations} && \
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100882 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray4f7fdd22015-04-24 11:57:37 +0100883 export PATH=$ANDROID_ROOT/bin:$PATH && \
Calin Juravle13439f02017-02-21 01:17:21 -0800884 $profman_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100885 $dex2oat_cmdline && \
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000886 $dm_cmdline && \
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000887 $vdex_cmdline && \
Richard Uhler76f5cb62016-04-04 13:30:16 -0700888 $strip_cmdline && \
Igor Murashkin271a0f82017-02-14 21:14:17 +0000889 $sync_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100890 $dalvikvm_cmdline"
891
892 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
893 echo "$cmdline" > $cmdfile
894
895 if [ "$DEV_MODE" = "y" ]; then
896 echo $cmdline
897 fi
898
899 if [ "$QUIET" = "n" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +0000900 adb push $cmdfile $CHROOT_DEX_LOCATION/cmdline.sh
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100901 else
Roland Levillain76cfe612017-10-30 13:14:28 +0000902 adb push $cmdfile $CHROOT_DEX_LOCATION/cmdline.sh >/dev/null 2>&1
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100903 fi
904
Alex Light722d6712018-02-12 17:41:12 +0000905 exit_status=0
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700906 if [ "$DRY_RUN" != "y" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +0000907 if [ -n "$CHROOT" ]; then
908 adb shell chroot "$CHROOT" sh $DEX_LOCATION/cmdline.sh
909 else
910 adb shell sh $DEX_LOCATION/cmdline.sh
911 fi
Alex Light722d6712018-02-12 17:41:12 +0000912 exit_status=$?
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700913 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100914
915 rm -f $cmdfile
Alex Light722d6712018-02-12 17:41:12 +0000916 exit $exit_status
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100917else
Calin Juravle24bd3f92017-05-11 00:36:53 -0700918 # Host run.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100919 export ANDROID_PRINTF_LOG=brief
Andreas Gampea8780822015-03-13 19:51:09 -0700920
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100921 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000922 export ANDROID_ROOT="${ANDROID_ROOT}"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700923 export LD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
924 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100925 export PATH="$PATH:${ANDROID_ROOT}/bin"
926
David Srbeckyc9ede382015-06-20 06:03:53 +0100927 # Temporarily disable address space layout randomization (ASLR).
928 # This is needed on the host so that the linker loads core.oat at the necessary address.
929 export LD_USE_LOAD_BIAS=1
930
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100931 cmdline="$dalvikvm_cmdline"
932
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700933 if [ "$TIME_OUT" = "gdb" ]; then
934 if [ `uname` = "Darwin" ]; then
935 # Fall back to timeout on Mac.
936 TIME_OUT="timeout"
Hiroshi Yamauchic823eff2015-09-01 16:21:35 -0700937 elif [ "$ISA" = "x86" ]; then
938 # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
939 TIME_OUT="timeout"
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700940 else
941 # Check if gdb is available.
942 gdb --eval-command="quit" > /dev/null 2>&1
943 if [ $? != 0 ]; then
944 # gdb isn't available. Fall back to timeout.
945 TIME_OUT="timeout"
946 fi
947 fi
948 fi
949
950 if [ "$TIME_OUT" = "timeout" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100951 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -0800952 #
Andreas Gampe6fb92562016-08-01 21:53:57 -0700953 # Note: We first send SIGRTMIN+2 (usually 36) to ART, which will induce a full thread dump
954 # before abort. However, dumping threads might deadlock, so we also use the "-k"
955 # option to definitely kill the child.
956 cmdline="timeout -k 120s -s SIGRTMIN+2 ${TIME_OUT_VALUE}s $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100957 fi
958
959 if [ "$DEV_MODE" = "y" ]; then
Orion Hodsonee06c5a2018-04-23 13:46:24 +0100960 for var in ANDROID_PRINTF_LOG ANDROID_DATA ANDROID_ROOT LD_LIBRARY_PATH DYLD_LIBRARY_PATH PATH LD_USE_LOAD_BIAS; do
961 echo EXPORT $var=${!var}
962 done
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000963 echo "mkdir -p ${mkdir_locations} && $profman_cmdline && $dex2oat_cmdline && $dm_cmdline && $vdex_cmdline && $strip_cmdline && $sync_cmdline && $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100964 fi
965
966 cd $ANDROID_BUILD_TOP
967
Calin Juravle24bd3f92017-05-11 00:36:53 -0700968 # Make sure we delete any existing compiler artifacts.
969 # This enables tests to call the RUN script multiple times in a row
970 # without worrying about interference.
971 rm -rf ${DEX_LOCATION}/oat
David Srbecky2e4afe82016-01-27 18:42:06 +0000972 rm -rf ${DEX_LOCATION}/dalvik-cache/
Calin Juravle24bd3f92017-05-11 00:36:53 -0700973
Andreas Gampeb31a8e72017-05-16 10:30:24 -0700974 export ASAN_OPTIONS=$RUN_TEST_ASAN_OPTIONS
975
Alex Lightafb5d192016-05-24 15:57:45 -0700976 mkdir -p ${mkdir_locations} || exit 1
Calin Juravle13439f02017-02-21 01:17:21 -0800977 $profman_cmdline || { echo "Profman failed." >&2 ; exit 2; }
Andreas Gampea8780822015-03-13 19:51:09 -0700978 $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000979 $dm_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000980 $vdex_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Richard Uhler76f5cb62016-04-04 13:30:16 -0700981 $strip_cmdline || { echo "Strip failed." >&2 ; exit 3; }
Igor Murashkin271a0f82017-02-14 21:14:17 +0000982 $sync_cmdline || { echo "Sync failed." >&2 ; exit 4; }
Andreas Gampea8780822015-03-13 19:51:09 -0700983
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700984 if [ "$DRY_RUN" = "y" ]; then
985 exit 0
Andreas Gampea8780822015-03-13 19:51:09 -0700986 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100987
988 if [ "$USE_GDB" = "y" ]; then
989 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700990 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100991 else
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700992 if [ "$TIME_OUT" != "gdb" ]; then
993 trap 'kill -INT -$pid' INT
994 $cmdline "$@" 2>&1 & pid=$!
995 wait $pid
Alex Light722d6712018-02-12 17:41:12 +0000996 exit_value=$?
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700997 # Add extra detail if time out is enabled.
Alex Light722d6712018-02-12 17:41:12 +0000998 if [ $exit_value = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700999 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
1000 fi
Alex Light722d6712018-02-12 17:41:12 +00001001 exit $exit_value
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001002 else
1003 # With a thread dump that uses gdb if a timeout.
1004 trap 'kill -INT -$pid' INT
1005 $cmdline "$@" 2>&1 & pid=$!
1006 # Spawn a watcher process.
1007 ( sleep $TIME_OUT_VALUE && \
1008 echo "##### Thread dump using gdb on test timeout" && \
1009 ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
1010 --eval-command="call exit(124)" --eval-command=quit || \
1011 kill $pid )) 2> /dev/null & watcher=$!
1012 wait $pid
1013 test_exit_status=$?
1014 pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
1015 if [ $test_exit_status = 0 ]; then
1016 # The test finished normally.
1017 exit 0
1018 else
1019 # The test failed or timed out.
1020 if [ $test_exit_status = 124 ]; then
1021 # The test timed out.
1022 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
1023 fi
Alex Light722d6712018-02-12 17:41:12 +00001024 exit $test_exit_status
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001025 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001026 fi
1027 fi
1028fi