blob: b3965c91c364c528add3d974c2534006bcd41796 [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"
Alex Light0e151e72017-10-25 10:50:35 -070019WITH_AGENT=""
Alex Lightc281ba52017-10-11 11:35:55 -070020DEBUGGER_AGENT=""
21WRAP_DEBUGGER_AGENT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010022DEV_MODE="n"
23DEX2OAT=""
Alex Light8a0e0332015-10-26 10:11:58 -070024EXPERIMENTAL=""
Nicolas Geoffray90355fe2017-02-20 09:25:40 +000025FALSE_BIN="false"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010026FLAGS=""
Alex Light7233c7e2016-07-28 10:07:45 -070027ANDROID_FLAGS=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010028GDB=""
Nicolas Geoffraybaf91022014-10-08 09:56:45 +010029GDB_ARGS=""
30GDB_SERVER="gdbserver"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010031HAVE_IMAGE="y"
32HOST="n"
33INTERPRETER="n"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080034JIT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010035INVOKE_WITH=""
Alex Lighte06b6342017-01-05 14:37:21 -080036IS_JVMTI_TEST="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010037ISA=x86
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000038LIBRARY_DIRECTORY="lib"
Colin Crossafd3c9e2016-09-16 13:47:21 -070039TEST_DIRECTORY="nativetest"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000040MAIN=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010041OPTIMIZE="y"
42PATCHOAT=""
43PREBUILD="y"
44QUIET="n"
Nicolas Geoffray94e25db2017-01-27 14:54:28 +000045RELOCATE="n"
Richard Uhler76f5cb62016-04-04 13:30:16 -070046STRIP_DEX="n"
Jeff Hao207a37d2014-10-29 17:24:25 -070047SECONDARY_DEX=""
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -070048TIME_OUT="gdb" # "n" (disabled), "timeout" (use timeout), "gdb" (use gdb)
49# Value in seconds
Hiroshi Yamauchifd3161a2017-01-18 14:47:25 -080050if [ "$ART_USE_READ_BARRIER" != "false" ]; then
Hiroshi Yamauchia9b296c2016-10-07 17:07:03 -070051 TIME_OUT_VALUE=2400 # 40 minutes.
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070052else
Mathieu Chartier2576be22016-05-24 10:24:53 -070053 TIME_OUT_VALUE=1200 # 20 minutes.
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070054fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010055USE_GDB="n"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +010056USE_JVM="n"
Alex Lightc281ba52017-10-11 11:35:55 -070057USE_JVMTI="n"
Igor Murashkin7617abd2015-07-10 18:27:47 -070058VERIFY="y" # y=yes,n=no,s=softfail
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010059ZYGOTE=""
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -070060DEX_VERIFY=""
Andreas Gampe65357032015-02-19 15:10:24 -080061USE_DEX2OAT_AND_PATCHOAT="y"
Andreas Gampe4d2ef332015-08-05 09:24:45 -070062INSTRUCTION_SET_FEATURES=""
Mathieu Chartier031768a2015-08-27 10:25:02 -070063ARGS=""
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -070064EXTERNAL_LOG_TAGS="n" # if y respect externally set ANDROID_LOG_TAGS.
65DRY_RUN="n" # if y prepare to run the test but don't run it.
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +000066TEST_VDEX="n"
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +000067TEST_DM="n"
Alex Lighte06b6342017-01-05 14:37:21 -080068TEST_IS_NDEBUG="n"
Calin Juravle857f0582016-12-20 14:36:59 +000069APP_IMAGE="y"
Alex Light8f2c6d42017-04-10 16:27:35 -070070JVMTI_STRESS="n"
Alex Lightc38c3692017-06-27 15:45:14 -070071JVMTI_STEP_STRESS="n"
Alex Light43e935d2017-06-19 15:40:40 -070072JVMTI_FIELD_STRESS="n"
Alex Lightb7edcda2017-04-27 13:20:31 -070073JVMTI_TRACE_STRESS="n"
74JVMTI_REDEFINE_STRESS="n"
Nicolas Geoffray74981052017-01-16 17:54:09 +000075VDEX_FILTER=""
Calin Juravle13439f02017-02-21 01:17:21 -080076PROFILE="n"
Jeff Hao002b9312017-03-27 16:23:08 -070077RANDOM_PROFILE="n"
Alex Light483208d2017-09-26 09:31:17 -070078# The normal dex2oat timeout.
Shubham Ajmeraf97cbd62017-10-11 10:00:57 -070079DEX2OAT_TIMEOUT="300" # 5 mins
Alex Light483208d2017-09-26 09:31:17 -070080# The *hard* timeout where we really start trying to kill the dex2oat.
Shubham Ajmeraf97cbd62017-10-11 10:00:57 -070081DEX2OAT_RT_TIMEOUT="360" # 6 mins
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010082
Narayan Kamath84695ae2017-04-07 15:41:41 +010083# if "y", set -Xstacktracedir and inform the test of its location. When
84# this is set, stack trace dumps (from signal 3) will be written to a file
85# under this directory instead of stdout.
86SET_STACK_TRACE_DUMP_DIR="n"
87
Igor Murashkin271a0f82017-02-14 21:14:17 +000088# if "y", run 'sync' before dalvikvm to make sure all files from
89# build step (e.g. dex2oat) were finished writing.
90SYNC_BEFORE_RUN="n"
91
Andreas Gampe1c5b42f2017-06-15 18:20:45 -070092# When running a debug build, we want to run with all checks.
93ANDROID_FLAGS="${ANDROID_FLAGS} -XX:SlowDebug=true"
Andreas Gampee8f74ca2018-01-02 09:26:16 -080094# The same for dex2oatd, both prebuild and runtime-driven.
95ANDROID_FLAGS="${ANDROID_FLAGS} -Xcompiler-option --runtime-arg -Xcompiler-option -XX:SlowDebug=true"
96COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -XX:SlowDebug=true"
Andreas Gampe1c5b42f2017-06-15 18:20:45 -070097
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010098while true; do
99 if [ "x$1" = "x--quiet" ]; then
100 QUIET="y"
101 shift
Alex Light483208d2017-09-26 09:31:17 -0700102 elif [ "x$1" = "x--dex2oat-rt-timeout" ]; then
103 shift
104 if [ "x$1" = "x" ]; then
105 echo "$0 missing argument to --dex2oat-rt-timeout" 1>&2
106 exit 1
107 fi
108 DEX2OAT_RT_TIMEOUT="$1"
109 shift
110 elif [ "x$1" = "x--dex2oat-timeout" ]; then
111 shift
112 if [ "x$1" = "x" ]; then
113 echo "$0 missing argument to --dex2oat-timeout" 1>&2
114 exit 1
115 fi
116 DEX2OAT_TIMEOUT="$1"
117 shift
Alex Lighte06b6342017-01-05 14:37:21 -0800118 elif [ "x$1" = "x--jvmti" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700119 USE_JVMTI="y"
Alex Lighte06b6342017-01-05 14:37:21 -0800120 IS_JVMTI_TEST="y"
121 shift
Alex Lightfaf90b62016-08-12 14:43:48 -0700122 elif [ "x$1" = "x-O" ]; then
Alex Lighte06b6342017-01-05 14:37:21 -0800123 TEST_IS_NDEBUG="y"
Alex Lightfaf90b62016-08-12 14:43:48 -0700124 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100125 elif [ "x$1" = "x--lib" ]; then
126 shift
127 if [ "x$1" = "x" ]; then
128 echo "$0 missing argument to --lib" 1>&2
129 exit 1
130 fi
131 LIB="$1"
132 shift
Alex Light97acf192016-03-17 09:59:38 -0700133 elif [ "x$1" = "x--gc-stress" ]; then
134 # Give an extra 5 mins if we are gc-stress.
135 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + 300))
136 shift
Mathieu Chartier031768a2015-08-27 10:25:02 -0700137 elif [ "x$1" = "x--testlib" ]; then
138 shift
139 if [ "x$1" = "x" ]; then
140 echo "$0 missing argument to --testlib" 1>&2
141 exit 1
142 fi
Mathieu Chartierde286fd2015-09-03 18:10:29 -0700143 ARGS="${ARGS} $1"
Mathieu Chartier031768a2015-08-27 10:25:02 -0700144 shift
David Srbecky52886112016-01-22 13:56:47 +0000145 elif [ "x$1" = "x--args" ]; then
146 shift
147 if [ "x$1" = "x" ]; then
148 echo "$0 missing argument to --args" 1>&2
149 exit 1
150 fi
151 ARGS="${ARGS} $1"
152 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100153 elif [ "x$1" = "x-Xcompiler-option" ]; then
154 shift
155 option="$1"
156 FLAGS="${FLAGS} -Xcompiler-option $option"
157 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
158 shift
Alex Light7233c7e2016-07-28 10:07:45 -0700159 elif [ "x$1" = "x--android-runtime-option" ]; then
160 shift
161 option="$1"
162 ANDROID_FLAGS="${ANDROID_FLAGS} $option"
163 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100164 elif [ "x$1" = "x--runtime-option" ]; then
165 shift
166 option="$1"
167 FLAGS="${FLAGS} $option"
168 shift
169 elif [ "x$1" = "x--boot" ]; then
170 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000171 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100172 shift
173 elif [ "x$1" = "x--no-dex2oat" ]; then
174 DEX2OAT="-Xcompiler:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800175 USE_DEX2OAT_AND_PATCHOAT="n"
Andreas Gampe5b8a1972017-11-07 10:23:48 -0800176 PREBUILD="n" # Do not use prebuilt odex, either.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100177 shift
178 elif [ "x$1" = "x--no-patchoat" ]; then
179 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800180 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100181 shift
182 elif [ "x$1" = "x--relocate" ]; then
183 RELOCATE="y"
184 shift
185 elif [ "x$1" = "x--no-relocate" ]; then
186 RELOCATE="n"
187 shift
188 elif [ "x$1" = "x--prebuild" ]; then
189 PREBUILD="y"
190 shift
Mathieu Chartierdcd56c92017-11-20 20:30:24 -0800191 elif [ "x$1" = "x--compact-dex-level" ]; then
192 shift
193 COMPILE_FLAGS="${COMPILE_FLAGS} --compact-dex-level=$1"
194 shift
Alex Lightb7edcda2017-04-27 13:20:31 -0700195 elif [ "x$1" = "x--jvmti-redefine-stress" ]; then
196 # APP_IMAGE doesn't really work with jvmti redefine stress
Alex Lightc281ba52017-10-11 11:35:55 -0700197 USE_JVMTI="y"
Alex Light8f2c6d42017-04-10 16:27:35 -0700198 APP_IMAGE="n"
199 JVMTI_STRESS="y"
Alex Lightb7edcda2017-04-27 13:20:31 -0700200 JVMTI_REDEFINE_STRESS="y"
201 shift
Alex Lightc38c3692017-06-27 15:45:14 -0700202 elif [ "x$1" = "x--jvmti-step-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700203 USE_JVMTI="y"
Alex Lightc38c3692017-06-27 15:45:14 -0700204 JVMTI_STRESS="y"
205 JVMTI_STEP_STRESS="y"
206 shift
Alex Light43e935d2017-06-19 15:40:40 -0700207 elif [ "x$1" = "x--jvmti-field-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700208 USE_JVMTI="y"
Alex Light43e935d2017-06-19 15:40:40 -0700209 JVMTI_STRESS="y"
210 JVMTI_FIELD_STRESS="y"
211 shift
Alex Lightb7edcda2017-04-27 13:20:31 -0700212 elif [ "x$1" = "x--jvmti-trace-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700213 USE_JVMTI="y"
Alex Lightb7edcda2017-04-27 13:20:31 -0700214 JVMTI_STRESS="y"
215 JVMTI_TRACE_STRESS="y"
Alex Light8f2c6d42017-04-10 16:27:35 -0700216 shift
Calin Juravle857f0582016-12-20 14:36:59 +0000217 elif [ "x$1" = "x--no-app-image" ]; then
218 APP_IMAGE="n"
219 shift
Richard Uhler76f5cb62016-04-04 13:30:16 -0700220 elif [ "x$1" = "x--strip-dex" ]; then
221 STRIP_DEX="y"
222 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100223 elif [ "x$1" = "x--host" ]; then
224 HOST="y"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000225 ANDROID_ROOT="$ANDROID_HOST_OUT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100226 shift
227 elif [ "x$1" = "x--no-prebuild" ]; then
228 PREBUILD="n"
229 shift
230 elif [ "x$1" = "x--no-image" ]; then
231 HAVE_IMAGE="n"
232 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700233 elif [ "x$1" = "x--secondary" ]; then
234 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
Calin Juravle175dc732015-08-25 15:42:32 +0100235 # Enable cfg-append to make sure we get the dump for both dex files.
236 # (otherwise the runtime compilation of the secondary dex will overwrite
Roland Levillainb0103ca2016-11-01 14:48:47 +0000237 # the dump of the first one).
Calin Juravle175dc732015-08-25 15:42:32 +0100238 FLAGS="${FLAGS} -Xcompiler-option --dump-cfg-append"
239 COMPILE_FLAGS="${COMPILE_FLAGS} --dump-cfg-append"
Jeff Hao207a37d2014-10-29 17:24:25 -0700240 shift
Alex Light0e151e72017-10-25 10:50:35 -0700241 elif [ "x$1" = "x--with-agent" ]; then
242 shift
243 USE_JVMTI="y"
244 WITH_AGENT="$1"
245 shift
Alex Lightc281ba52017-10-11 11:35:55 -0700246 elif [ "x$1" = "x--debug-wrap-agent" ]; then
247 WRAP_DEBUGGER_AGENT="y"
248 shift
249 elif [ "x$1" = "x--debug-agent" ]; then
250 shift
251 DEBUGGER="agent"
252 USE_JVMTI="y"
253 DEBUGGER_AGENT="$1"
254 TIME_OUT="n"
255 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100256 elif [ "x$1" = "x--debug" ]; then
257 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800258 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100259 shift
260 elif [ "x$1" = "x--gdb" ]; then
261 USE_GDB="y"
262 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800263 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100264 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700265 elif [ "x$1" = "x--gdb-arg" ]; then
266 shift
267 gdb_arg="$1"
268 GDB_ARGS="${GDB_ARGS} $gdb_arg"
269 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100270 elif [ "x$1" = "x--zygote" ]; then
271 ZYGOTE="-Xzygote"
272 msg "Spawning from zygote"
273 shift
274 elif [ "x$1" = "x--dev" ]; then
275 DEV_MODE="y"
276 shift
277 elif [ "x$1" = "x--interpreter" ]; then
278 INTERPRETER="y"
279 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800280 elif [ "x$1" = "x--jit" ]; then
281 JIT="y"
282 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100283 elif [ "x$1" = "x--jvm" ]; then
284 USE_JVM="y"
285 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100286 elif [ "x$1" = "x--invoke-with" ]; then
287 shift
288 if [ "x$1" = "x" ]; then
289 echo "$0 missing argument to --invoke-with" 1>&2
290 exit 1
291 fi
292 if [ "x$INVOKE_WITH" = "x" ]; then
293 INVOKE_WITH="$1"
294 else
295 INVOKE_WITH="$INVOKE_WITH $1"
296 fi
297 shift
298 elif [ "x$1" = "x--no-verify" ]; then
299 VERIFY="n"
300 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700301 elif [ "x$1" = "x--verify-soft-fail" ]; then
302 VERIFY="s"
303 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100304 elif [ "x$1" = "x--no-optimize" ]; then
305 OPTIMIZE="n"
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
Narayan Kamath84695ae2017-04-07 15:41:41 +0100367 elif [ "x$1" = "x--set-stack-trace-dump-dir" ]; then
368 SET_STACK_TRACE_DUMP_DIR="y"
369 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100370 elif expr "x$1" : "x--" >/dev/null 2>&1; then
371 echo "unknown $0 option: $1" 1>&2
372 exit 1
373 else
374 break
375 fi
376done
377
Narayan Kamath84695ae2017-04-07 15:41:41 +0100378mkdir_locations=""
379
Alex Light8a0e0332015-10-26 10:11:58 -0700380if [ "$USE_JVM" = "n" ]; then
Alex Light7233c7e2016-07-28 10:07:45 -0700381 FLAGS="${FLAGS} ${ANDROID_FLAGS}"
Alex Light8a0e0332015-10-26 10:11:58 -0700382 for feature in ${EXPERIMENTAL}; do
Alex Lightfa022852015-10-28 09:13:20 -0700383 FLAGS="${FLAGS} -Xexperimental:${feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:${feature}"
Alex Light8a0e0332015-10-26 10:11:58 -0700384 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xexperimental:${feature}"
385 done
Narayan Kamath84695ae2017-04-07 15:41:41 +0100386
387 if [ "$SET_STACK_TRACE_DUMP_DIR" = "y" ]; then
388 # Note that DEX_LOCATION is used as a proxy for tmpdir throughout this
389 # file (it will be under the test specific folder).
390 mkdir_locations="${mkdir_locations} $DEX_LOCATION/stack_traces"
391 FLAGS="${FLAGS} -Xstacktracedir:$DEX_LOCATION/stack_traces"
392 ARGS="${ARGS} --stack-trace-dir $DEX_LOCATION/stack_traces"
393 fi
Alex Light8a0e0332015-10-26 10:11:58 -0700394fi
395
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100396if [ "x$1" = "x" ] ; then
397 MAIN="Main"
398else
399 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700400 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100401fi
402
403if [ "$ZYGOTE" = "" ]; then
404 if [ "$OPTIMIZE" = "y" ]; then
405 if [ "$VERIFY" = "y" ]; then
406 DEX_OPTIMIZE="-Xdexopt:verified"
407 else
408 DEX_OPTIMIZE="-Xdexopt:all"
409 fi
410 msg "Performing optimizations"
411 else
412 DEX_OPTIMIZE="-Xdexopt:none"
413 msg "Skipping optimizations"
414 fi
415
416 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100417 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100418 msg "Performing verification"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700419 elif [ "$VERIFY" = "s" ]; then
420 JVM_VERIFY_ARG="Xverify:all"
421 DEX_VERIFY="-Xverify:softfail"
422 msg "Forcing verification to be soft fail"
423 else # VERIFY = "n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100424 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100425 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100426 msg "Skipping verification"
427 fi
428fi
429
430msg "------------------------------"
431
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100432if [ "$DEBUGGER" = "y" ]; then
433 # Use this instead for ddms and connect by running 'ddms':
434 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
435 # TODO: add a separate --ddms option?
436
437 PORT=12345
438 msg "Waiting for jdb to connect:"
439 if [ "$HOST" = "n" ]; then
440 msg " adb forward tcp:$PORT tcp:$PORT"
441 fi
442 msg " jdb -attach localhost:$PORT"
Alex Light264a4862018-01-31 16:47:58 +0000443 if [ "$USE_JVM" = "n" ]; then
444 # TODO We should switch over to using the jvmti agent by default.
445 # Need to tell the runtime to enable the internal jdwp implementation.
446 DEBUGGER_OPTS="-XjdwpOptions:transport=dt_socket,address=$PORT,server=y,suspend=y -XjdwpProvider:internal"
447 else
448 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
449 fi
Alex Lightc281ba52017-10-11 11:35:55 -0700450elif [ "$DEBUGGER" = "agent" ]; then
451 PORT=12345
452 # TODO Support ddms connection and support target.
453 if [ "$HOST" = "n" ]; then
454 echo "--debug-agent not supported yet for target!"
455 exit 1
456 fi
457 AGENTPATH=${DEBUGGER_AGENT}
458 if [ "$WRAP_DEBUGGER_AGENT" = "y" ]; then
459 WRAPPROPS="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}/libwrapagentpropertiesd.so"
460 if [ "$TEST_IS_NDEBUG" = "y" ]; then
461 WRAPPROPS="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}/libwrapagentproperties.so"
462 fi
463 AGENTPATH="${WRAPPROPS}=${ANDROID_BUILD_TOP}/art/tools/libjdwp-compat.props,${AGENTPATH}"
464 fi
465 msg "Connect to localhost:$PORT"
466 DEBUGGER_OPTS="-agentpath:${AGENTPATH}=transport=dt_socket,address=$PORT,server=y,suspend=y"
467fi
468
Alex Light0e151e72017-10-25 10:50:35 -0700469if [ "x$WITH_AGENT" != "x" ]; then
470 FLAGS="${FLAGS} -agentpath:${WITH_AGENT}"
471fi
472
Alex Lightc281ba52017-10-11 11:35:55 -0700473if [ "$USE_JVMTI" = "y" ]; then
474 if [ "$USE_JVM" = "n" ]; then
475 plugin=libopenjdkjvmtid.so
476 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
477 plugin=libopenjdkjvmti.so
478 fi
Alex Light2ce6fc82017-12-18 16:42:36 -0800479 # We used to add flags here that made the runtime debuggable but that is not
480 # needed anymore since the plugin can do it for us now.
Alex Lightc281ba52017-10-11 11:35:55 -0700481 FLAGS="${FLAGS} -Xplugin:${plugin}"
Alex Lightc281ba52017-10-11 11:35:55 -0700482 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100483fi
484
Alex Lightfba89fe2017-01-12 16:11:02 -0800485if [ "$IS_JVMTI_TEST" = "y" ]; then
Alex Lightfba89fe2017-01-12 16:11:02 -0800486 agent=libtiagentd.so
487 lib=tiagentd
488 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
489 agent=libtiagent.so
Alex Lightfba89fe2017-01-12 16:11:02 -0800490 lib=tiagent
491 fi
492
493 ARGS="${ARGS} ${lib}"
494 if [[ "$USE_JVM" = "y" ]]; then
495 FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${TEST_NAME},jvm"
496 else
497 FLAGS="${FLAGS} -agentpath:${agent}=${TEST_NAME},art"
Alex Lightfba89fe2017-01-12 16:11:02 -0800498 fi
499fi
500
Alex Light8f2c6d42017-04-10 16:27:35 -0700501if [[ "$JVMTI_STRESS" = "y" ]]; then
Alex Light42151c02017-04-20 15:54:25 -0700502 agent=libtistressd.so
503 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
504 agent=libtistress.so
Alex Light42151c02017-04-20 15:54:25 -0700505 fi
Alex Light8f2c6d42017-04-10 16:27:35 -0700506
Alex Lightb7edcda2017-04-27 13:20:31 -0700507 # Just give it a default start so we can always add ',' to it.
508 agent_args="jvmti-stress"
509 if [[ "$JVMTI_REDEFINE_STRESS" = "y" ]]; then
510 # We really cannot do this on RI so don't both passing it in that case.
511 if [[ "$USE_JVM" = "n" ]]; then
Alex Lightceae9542017-09-07 13:28:00 -0700512 agent_args="${agent_args},redefine"
Alex Lightb7edcda2017-04-27 13:20:31 -0700513 fi
514 fi
Alex Light43e935d2017-06-19 15:40:40 -0700515 if [[ "$JVMTI_FIELD_STRESS" = "y" ]]; then
516 agent_args="${agent_args},field"
517 fi
Alex Lightc38c3692017-06-27 15:45:14 -0700518 if [[ "$JVMTI_STEP_STRESS" = "y" ]]; then
519 agent_args="${agent_args},step"
520 fi
Alex Lightb7edcda2017-04-27 13:20:31 -0700521 if [[ "$JVMTI_TRACE_STRESS" = "y" ]]; then
522 agent_args="${agent_args},trace"
523 fi
524 # In the future add onto this;
Alex Light42151c02017-04-20 15:54:25 -0700525 if [[ "$USE_JVM" = "y" ]]; then
Alex Lightb7edcda2017-04-27 13:20:31 -0700526 FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${agent_args}"
Alex Light42151c02017-04-20 15:54:25 -0700527 else
Alex Lightb7edcda2017-04-27 13:20:31 -0700528 FLAGS="${FLAGS} -agentpath:${agent}=${agent_args}"
Alex Light8f2c6d42017-04-10 16:27:35 -0700529 fi
530fi
531
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100532if [ "$USE_JVM" = "y" ]; then
Alex Light9c20a142016-08-23 15:05:12 -0700533 export LD_LIBRARY_PATH=${ANDROID_HOST_OUT}/lib64
Alex Light47d49b82017-07-25 14:06:34 -0700534 # Some jvmti tests are flaky without -Xint on the RI.
535 if [ "$IS_JVMTI_TEST" = "y" ]; then
536 FLAGS="${FLAGS} -Xint"
537 fi
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700538 # Xmx is necessary since we don't pass down the ART flags to JVM.
Vladimir Markoc5798bf2016-12-09 10:20:54 +0000539 # We pass the classes2 path whether it's used (src-multidex) or not.
540 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes:classes2 ${FLAGS} $MAIN $@ ${ARGS}"
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700541 if [ "$DEV_MODE" = "y" ]; then
542 echo $cmdline
543 fi
544 $cmdline
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100545 exit
546fi
547
548
549if [ "$HAVE_IMAGE" = "n" ]; then
Vladimir Markoe00e5592017-02-24 14:58:29 +0000550 if [ "${HOST}" = "y" ]; then
551 framework="${ANDROID_HOST_OUT}/framework"
552 bpath_suffix="-hostdex"
553 else
554 framework="${ANDROID_ROOT}/framework"
Nicolas Geoffray320ccca2017-03-01 10:03:08 +0000555 bpath_suffix="-testdex"
Vladimir Markoe00e5592017-02-24 14:58:29 +0000556 fi
Vladimir Markoe00e5592017-02-24 14:58:29 +0000557 bpath="${framework}/core-libart${bpath_suffix}.jar"
558 bpath="${bpath}:${framework}/core-oj${bpath_suffix}.jar"
559 bpath="${bpath}:${framework}/conscrypt${bpath_suffix}.jar"
560 bpath="${bpath}:${framework}/okhttp${bpath_suffix}.jar"
561 bpath="${bpath}:${framework}/bouncycastle${bpath_suffix}.jar"
562 # Pass down the bootclasspath
563 FLAGS="${FLAGS} -Xbootclasspath:${bpath}"
Andreas Gampe1078d152017-11-07 18:00:54 -0800564 # Disable image dex2oat - this will forbid the runtime to patch or compile an image.
565 FLAGS="${FLAGS} -Xnoimage-dex2oat"
566
567 # We'll abuse a second flag here to test different behavior. If --relocate, use the
568 # existing image - relocation will fail as patching is disallowed. If --no-relocate,
569 # pass a non-existent image - compilation will fail as dex2oat is disallowed.
570 if [ "${RELOCATE}" = "y" ] ; then
571 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
572 else
Roland Levillainef012222017-06-21 16:28:06 +0100573 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existent/core.art"
Andreas Gampe1078d152017-11-07 18:00:54 -0800574 fi
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000575else
576 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100577fi
578
579
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100580if [ "$USE_GDB" = "y" ]; then
581 if [ "$HOST" = "n" ]; then
582 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100583 else
584 if [ `uname` = "Darwin" ]; then
585 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700586 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100587 DALVIKVM=
588 else
589 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700590 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100591 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
592 # gdbargs="--annotate=3 $gdbargs"
593 fi
594 fi
595fi
596
597if [ "$INTERPRETER" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000598 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700599 if [ "$VERIFY" = "y" ] ; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100600 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=quicken"
601 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=quicken"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700602 elif [ "$VERIFY" = "s" ]; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100603 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=extract"
604 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=extract"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700605 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
606 else # VERIFY = "n"
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100607 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=assume-verified"
608 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=assume-verified"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700609 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
610 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100611fi
612
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800613if [ "$JIT" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000614 INT_OPTS="-Xusejit:true"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800615 if [ "$VERIFY" = "y" ] ; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100616 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=quicken"
617 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=quicken"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800618 else
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100619 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=assume-verified"
620 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=assume-verified"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800621 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
622 fi
623fi
624
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100625JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
626
Richard Uhler020c0f32017-03-14 16:23:17 +0000627COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100628if [ "$RELOCATE" = "y" ]; then
Richard Uhlerc52f3032017-03-02 13:45:45 +0000629 FLAGS="${FLAGS} -Xrelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100630else
631 FLAGS="$FLAGS -Xnorelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100632fi
633
634if [ "$HOST" = "n" ]; then
Nicolas Geoffrayd295bc82016-11-04 13:03:05 +0000635 # Need to be root to query /data/dalvik-cache
636 adb root > /dev/null
637 adb wait-for-device
638 ISA=
639 ISA_adb_invocation=
640 ISA_outcome=
641 # We iterate a few times to workaround an adb issue. b/32655576
642 for i in {1..10}; do
643 ISA_adb_invocation=$(adb shell ls -F /data/dalvik-cache)
644 ISA_outcome=$?
645 ISA=$(echo $ISA_adb_invocation | grep -Ewo "${ARCHITECTURES_PATTERN}")
646 if [ x"$ISA" != "x" ]; then
647 break;
648 fi
649 done
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100650 if [ x"$ISA" = "x" ]; then
651 echo "Unable to determine architecture"
Nicolas Geoffray8f500fa2016-11-03 11:18:48 +0000652 # Print a few things for helping diagnosing the problem.
Nicolas Geoffrayd295bc82016-11-04 13:03:05 +0000653 echo "adb invocation output: $ISA_adb_invocation"
654 echo "adb invocation outcome: $ISA_outcome"
Nicolas Geoffray8f500fa2016-11-03 11:18:48 +0000655 echo $(adb shell ls -F /data/dalvik-cache)
656 echo $(adb shell ls /data/dalvik-cache)
657 echo ${ARCHITECTURES_PATTERN}
658 echo $(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100659 exit 1
660 fi
661fi
662
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700663# Prevent test from silently falling back to interpreter in no-prebuild mode. This happens
664# when DEX_LOCATION path is too long, because vdex/odex filename is constructed by taking
665# full path to dex, stripping leading '/', appending '@classes.vdex' and changing every
666# remaining '/' into '@'.
667if [ "$HOST" = "y" ]; then
668 max_filename_size=$(getconf NAME_MAX $DEX_LOCATION)
669else
Roland Levillain2ae376f2018-01-30 11:35:11 +0000670 # There is no getconf on device, fallback to standard value.
671 # See NAME_MAX in kernel <linux/limits.h>
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700672 max_filename_size=255
673fi
674# Compute VDEX_NAME.
675DEX_LOCATION_STRIPPED="${DEX_LOCATION#/}"
676VDEX_NAME="${DEX_LOCATION_STRIPPED//\//@}@$TEST_NAME.jar@classes.vdex"
677if [ ${#VDEX_NAME} -gt $max_filename_size ]; then
Nicolas Geoffraybea3e312017-03-07 09:59:05 +0000678 echo "Dex location path too long:"
679 echo "$VDEX_NAME is ${#VDEX_NAME} character long, and the limit is $max_filename_size."
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700680 exit 1
681fi
682
Calin Juravle13439f02017-02-21 01:17:21 -0800683profman_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100684dex2oat_cmdline="true"
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000685vdex_cmdline="true"
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000686dm_cmdline="true"
Narayan Kamath84695ae2017-04-07 15:41:41 +0100687mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/dalvik-cache/$ISA"
Richard Uhler76f5cb62016-04-04 13:30:16 -0700688strip_cmdline="true"
Igor Murashkin271a0f82017-02-14 21:14:17 +0000689sync_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100690
Jeff Hao002b9312017-03-27 16:23:08 -0700691# PROFILE takes precedence over RANDOM_PROFILE, since PROFILE tests require a
692# specific profile to run properly.
693if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000694 profman_cmdline="${ANDROID_ROOT}/bin/profman \
695 --apk=$DEX_LOCATION/$TEST_NAME.jar \
Jeff Hao002b9312017-03-27 16:23:08 -0700696 --dex-location=$DEX_LOCATION/$TEST_NAME.jar"
Calin Juravle6df62f72017-04-28 19:58:01 -0700697 if [ -f $DEX_LOCATION/$TEST_NAME-ex.jar ]; then
698 profman_cmdline="${profman_cmdline} \
699 --apk=$DEX_LOCATION/$TEST_NAME-ex.jar \
700 --dex-location=$DEX_LOCATION/$TEST_NAME-ex.jar"
701 fi
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000702 COMPILE_FLAGS="${COMPILE_FLAGS} --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
703 FLAGS="${FLAGS} -Xcompiler-option --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
Jeff Hao002b9312017-03-27 16:23:08 -0700704 if [ "$PROFILE" = "y" ]; then
705 profman_cmdline="${profman_cmdline} --create-profile-from=$DEX_LOCATION/profile \
706 --reference-profile-file=$DEX_LOCATION/$TEST_NAME.prof"
707 else
708 profman_cmdline="${profman_cmdline} --generate-test-profile=$DEX_LOCATION/$TEST_NAME.prof \
709 --generate-test-profile-seed=0"
710 fi
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000711fi
712
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100713if [ "$PREBUILD" = "y" ]; then
Alex Lightafb5d192016-05-24 15:57:45 -0700714 mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/oat/$ISA"
Calin Juravle857f0582016-12-20 14:36:59 +0000715 if [ "$APP_IMAGE" = "y" ]; then
716 # Pick a base that will force the app image to get relocated.
717 app_image="--base=0x4000 --app-image-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.art"
718 fi
719
Roland Levillain6c3af162017-04-27 11:18:56 +0100720 dex2oat_binary=dex2oatd
721 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
722 dex2oat_binary=dex2oat
723 fi
724 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/$dex2oat_binary \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100725 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000726 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100727 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
Andreas Gampe14759242016-03-23 10:54:21 -0700728 --oat-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.odex \
Jeff Haodcdc85b2015-12-04 14:06:18 -0800729 ${app_image} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100730 --instruction-set=$ISA"
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700731 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
732 dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
733 fi
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700734
735 # Add in a timeout. This is important for testing the compilation/verification time of
736 # pathological cases.
737 # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
738 # now. We should try to improve this.
739 # The current value is rather arbitrary. run-tests should compile quickly.
Alex Light483208d2017-09-26 09:31:17 -0700740 # Watchdog timeout is in milliseconds so add 3 '0's to the dex2oat timeout.
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700741 if [ "$HOST" != "n" ]; then
742 # Use SIGRTMIN+2 to try to dump threads.
743 # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
Alex Light483208d2017-09-26 09:31:17 -0700744 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 -0700745 fi
Nicolas Geoffrayfbc4f112017-04-27 21:45:35 +0100746 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
747 vdex_cmdline="${dex2oat_cmdline} ${VDEX_FILTER} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex --output-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
748 elif [ "$TEST_VDEX" = "y" ]; then
Nicolas Geoffray74981052017-01-16 17:54:09 +0000749 vdex_cmdline="${dex2oat_cmdline} ${VDEX_FILTER} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000750 elif [ "$TEST_DM" = "y" ]; then
751 dex2oat_cmdline="${dex2oat_cmdline} --output-vdex=$DEX_LOCATION/oat/$ISA/primary.vdex"
752 dm_cmdline="zip -qj $DEX_LOCATION/oat/$ISA/$TEST_NAME.dm $DEX_LOCATION/oat/$ISA/primary.vdex"
Calin Juravle5a0381f2020-11-23 19:21:09 -0800753 vdex_cmdline="${dex2oat_cmdline} --copy-dex-files=false --dump-timings --dm-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.dm"
Nicolas Geoffraycab65572017-04-21 17:16:44 +0100754 elif [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
755 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 +0000756 fi
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700757fi
758
Richard Uhler76f5cb62016-04-04 13:30:16 -0700759if [ "$STRIP_DEX" = "y" ]; then
760 strip_cmdline="zip --quiet --delete $DEX_LOCATION/$TEST_NAME.jar classes.dex"
761fi
762
Igor Murashkin271a0f82017-02-14 21:14:17 +0000763if [ "$SYNC_BEFORE_RUN" = "y" ]; then
764 sync_cmdline="sync"
765fi
766
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700767DALVIKVM_ISA_FEATURES_ARGS=""
768if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
769 DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100770fi
771
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000772# java.io.tmpdir can only be set at launch time.
773TMP_DIR_OPTION=""
774if [ "$HOST" = "n" ]; then
775 TMP_DIR_OPTION="-Djava.io.tmpdir=/data/local/tmp"
776fi
777
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000778# We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
779# b/27185632
780# b/24664297
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000781dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100782 $GDB_ARGS \
783 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700784 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100785 -XXlib:$LIB \
786 $PATCHOAT \
787 $DEX2OAT \
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700788 $DALVIKVM_ISA_FEATURES_ARGS \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100789 $ZYGOTE \
790 $JNI_OPTS \
791 $INT_OPTS \
792 $DEBUGGER_OPTS \
793 $DALVIKVM_BOOT_OPT \
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000794 $TMP_DIR_OPTION \
Mathieu Chartier031768a2015-08-27 10:25:02 -0700795 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100796
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -0800797# Remove whitespace.
798dex2oat_cmdline=$(echo $dex2oat_cmdline)
799dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000800dm_cmdline=$(echo $dm_cmdline)
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000801vdex_cmdline=$(echo $vdex_cmdline)
Calin Juravle13439f02017-02-21 01:17:21 -0800802profman_cmdline=$(echo $profman_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100803
Andreas Gampeb31a8e72017-05-16 10:30:24 -0700804# Use an empty ASAN_OPTIONS to enable defaults.
805# Note: this is required as envsetup right now exports detect_leaks=0.
806RUN_TEST_ASAN_OPTIONS=""
807
Andreas Gampe58408392017-05-16 10:45:46 -0700808# Multiple shutdown leaks. b/38341789
809if [ "x$RUN_TEST_ASAN_OPTIONS" != "x" ] ; then
810 RUN_TEST_ASAN_OPTIONS="${RUN_TEST_ASAN_OPTIONS}:"
811fi
812RUN_TEST_ASAN_OPTIONS="${RUN_TEST_ASAN_OPTIONS}detect_leaks=0"
813
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100814if [ "$HOST" = "n" ]; then
815 adb root > /dev/null
816 adb wait-for-device
817 if [ "$QUIET" = "n" ]; then
Calin Juravle24bd3f92017-05-11 00:36:53 -0700818 adb shell rm -rf $DEX_LOCATION
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100819 adb shell mkdir -p $DEX_LOCATION
820 adb push $TEST_NAME.jar $DEX_LOCATION
821 adb push $TEST_NAME-ex.jar $DEX_LOCATION
Jeff Hao002b9312017-03-27 16:23:08 -0700822 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Calin Juravle13439f02017-02-21 01:17:21 -0800823 adb push profile $DEX_LOCATION
824 fi
David Brazdil7d2ec612018-01-19 14:19:59 +0000825 # Copy resource folder
826 if [ -d res ]; then
827 adb push res $DEX_LOCATION
828 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100829 else
830 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
831 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
832 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
833 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
Jeff Hao002b9312017-03-27 16:23:08 -0700834 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Calin Juravle13439f02017-02-21 01:17:21 -0800835 adb push profile $DEX_LOCATION >/dev/null 2>&1
836 fi
David Brazdil7d2ec612018-01-19 14:19:59 +0000837 # Copy resource folder
838 if [ -d res ]; then
839 adb push res $DEX_LOCATION >/dev/null 2>&1
840 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100841 fi
842
Colin Crossafd3c9e2016-09-16 13:47:21 -0700843 LD_LIBRARY_PATH=/data/$TEST_DIRECTORY/art/$ISA
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000844 if [ "$ANDROID_ROOT" != "/system" ]; then
845 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
846 # so we can only use LD_LIBRARY_PATH when testing on a local
847 # installation.
Alex Light7233c7e2016-07-28 10:07:45 -0700848 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY:$LD_LIBRARY_PATH
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000849 fi
850
Dimitry Ivanov49c2c922017-02-14 11:06:14 -0800851 # System libraries needed by libarttestd.so
David Sehrfcbe15c2018-02-15 09:41:13 -0800852 PUBLIC_LIBS=libart.so:libartd.so:libc++.so:libbacktrace.so:libdexfile.so:libdexfiled.so:libbase.so:libnativehelper.so
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700853
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100854 # Create a script with the command. The command can get longer than the longest
855 # allowed adb command and there is no way to get the exit status from a adb shell
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700856 # command. Dalvik cache is cleaned before running to make subsequent executions
857 # of the script follow the same runtime path.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100858 cmdline="cd $DEX_LOCATION && \
Andreas Gampeb31a8e72017-05-16 10:30:24 -0700859 export ASAN_OPTIONS=$RUN_TEST_ASAN_OPTIONS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100860 export ANDROID_DATA=$DEX_LOCATION && \
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700861 export ANDROID_ADDITIONAL_PUBLIC_LIBRARIES=$PUBLIC_LIBS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100862 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000863 export ANDROID_ROOT=$ANDROID_ROOT && \
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700864 rm -rf ${DEX_LOCATION}/dalvik-cache/ && \
Alex Lightafb5d192016-05-24 15:57:45 -0700865 mkdir -p ${mkdir_locations} && \
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100866 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray4f7fdd22015-04-24 11:57:37 +0100867 export PATH=$ANDROID_ROOT/bin:$PATH && \
Calin Juravle13439f02017-02-21 01:17:21 -0800868 $profman_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100869 $dex2oat_cmdline && \
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000870 $dm_cmdline && \
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000871 $vdex_cmdline && \
Richard Uhler76f5cb62016-04-04 13:30:16 -0700872 $strip_cmdline && \
Igor Murashkin271a0f82017-02-14 21:14:17 +0000873 $sync_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100874 $dalvikvm_cmdline"
875
876 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
877 echo "$cmdline" > $cmdfile
878
879 if [ "$DEV_MODE" = "y" ]; then
880 echo $cmdline
881 fi
882
883 if [ "$QUIET" = "n" ]; then
884 adb push $cmdfile $DEX_LOCATION/cmdline.sh
885 else
886 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
887 fi
888
Alex Light722d6712018-02-12 17:41:12 +0000889 exit_status=0
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700890 if [ "$DRY_RUN" != "y" ]; then
891 adb shell sh $DEX_LOCATION/cmdline.sh
Alex Light722d6712018-02-12 17:41:12 +0000892 exit_status=$?
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700893 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100894
895 rm -f $cmdfile
Alex Light722d6712018-02-12 17:41:12 +0000896 exit $exit_status
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100897else
Calin Juravle24bd3f92017-05-11 00:36:53 -0700898 # Host run.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100899 export ANDROID_PRINTF_LOG=brief
Andreas Gampea8780822015-03-13 19:51:09 -0700900
901 # By default, and for prebuild dex2oat, we are interested in errors being logged. In dev mode
902 # we want debug messages.
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700903 if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
904 if [ "$DEV_MODE" = "y" ]; then
905 export ANDROID_LOG_TAGS='*:d'
906 else
907 export ANDROID_LOG_TAGS='*:e'
908 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100909 fi
Andreas Gampea8780822015-03-13 19:51:09 -0700910
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100911 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000912 export ANDROID_ROOT="${ANDROID_ROOT}"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700913 export LD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
914 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100915 export PATH="$PATH:${ANDROID_ROOT}/bin"
916
David Srbeckyc9ede382015-06-20 06:03:53 +0100917 # Temporarily disable address space layout randomization (ASLR).
918 # This is needed on the host so that the linker loads core.oat at the necessary address.
919 export LD_USE_LOAD_BIAS=1
920
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100921 cmdline="$dalvikvm_cmdline"
922
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700923 if [ "$TIME_OUT" = "gdb" ]; then
924 if [ `uname` = "Darwin" ]; then
925 # Fall back to timeout on Mac.
926 TIME_OUT="timeout"
Hiroshi Yamauchic823eff2015-09-01 16:21:35 -0700927 elif [ "$ISA" = "x86" ]; then
928 # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
929 TIME_OUT="timeout"
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700930 else
931 # Check if gdb is available.
932 gdb --eval-command="quit" > /dev/null 2>&1
933 if [ $? != 0 ]; then
934 # gdb isn't available. Fall back to timeout.
935 TIME_OUT="timeout"
936 fi
937 fi
938 fi
939
940 if [ "$TIME_OUT" = "timeout" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100941 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -0800942 #
Andreas Gampe6fb92562016-08-01 21:53:57 -0700943 # Note: We first send SIGRTMIN+2 (usually 36) to ART, which will induce a full thread dump
944 # before abort. However, dumping threads might deadlock, so we also use the "-k"
945 # option to definitely kill the child.
946 cmdline="timeout -k 120s -s SIGRTMIN+2 ${TIME_OUT_VALUE}s $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100947 fi
948
949 if [ "$DEV_MODE" = "y" ]; then
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000950 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 +0100951 fi
952
953 cd $ANDROID_BUILD_TOP
954
Calin Juravle24bd3f92017-05-11 00:36:53 -0700955 # Make sure we delete any existing compiler artifacts.
956 # This enables tests to call the RUN script multiple times in a row
957 # without worrying about interference.
958 rm -rf ${DEX_LOCATION}/oat
David Srbecky2e4afe82016-01-27 18:42:06 +0000959 rm -rf ${DEX_LOCATION}/dalvik-cache/
Calin Juravle24bd3f92017-05-11 00:36:53 -0700960
Andreas Gampeb31a8e72017-05-16 10:30:24 -0700961 export ASAN_OPTIONS=$RUN_TEST_ASAN_OPTIONS
962
Alex Lightafb5d192016-05-24 15:57:45 -0700963 mkdir -p ${mkdir_locations} || exit 1
Calin Juravle13439f02017-02-21 01:17:21 -0800964 $profman_cmdline || { echo "Profman failed." >&2 ; exit 2; }
Andreas Gampea8780822015-03-13 19:51:09 -0700965 $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000966 $dm_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000967 $vdex_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Richard Uhler76f5cb62016-04-04 13:30:16 -0700968 $strip_cmdline || { echo "Strip failed." >&2 ; exit 3; }
Igor Murashkin271a0f82017-02-14 21:14:17 +0000969 $sync_cmdline || { echo "Sync failed." >&2 ; exit 4; }
Andreas Gampea8780822015-03-13 19:51:09 -0700970
971 # For running, we must turn off logging when dex2oat or patchoat are missing. Otherwise we use
972 # the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700973 if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
974 if [ "$DEV_MODE" = "y" ]; then
975 export ANDROID_LOG_TAGS='*:d'
976 elif [ "$USE_DEX2OAT_AND_PATCHOAT" = "n" ]; then
977 # All tests would log the error of failing dex2oat/patchoat. Be silent here and only
978 # log fatal events.
979 export ANDROID_LOG_TAGS='*:s'
Andreas Gampe1078d152017-11-07 18:00:54 -0800980 elif [ "$HAVE_IMAGE" = "n" ]; then
981 # All tests would log the error of missing image. Be silent here and only log fatal
982 # events.
983 export ANDROID_LOG_TAGS='*:s'
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700984 else
985 # We are interested in LOG(ERROR) output.
986 export ANDROID_LOG_TAGS='*:e'
987 fi
988 fi
989
990 if [ "$DRY_RUN" = "y" ]; then
991 exit 0
Andreas Gampea8780822015-03-13 19:51:09 -0700992 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100993
994 if [ "$USE_GDB" = "y" ]; then
995 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700996 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100997 else
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700998 if [ "$TIME_OUT" != "gdb" ]; then
999 trap 'kill -INT -$pid' INT
1000 $cmdline "$@" 2>&1 & pid=$!
1001 wait $pid
Alex Light722d6712018-02-12 17:41:12 +00001002 exit_value=$?
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001003 # Add extra detail if time out is enabled.
Alex Light722d6712018-02-12 17:41:12 +00001004 if [ $exit_value = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001005 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
1006 fi
Alex Light722d6712018-02-12 17:41:12 +00001007 exit $exit_value
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001008 else
1009 # With a thread dump that uses gdb if a timeout.
1010 trap 'kill -INT -$pid' INT
1011 $cmdline "$@" 2>&1 & pid=$!
1012 # Spawn a watcher process.
1013 ( sleep $TIME_OUT_VALUE && \
1014 echo "##### Thread dump using gdb on test timeout" && \
1015 ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
1016 --eval-command="call exit(124)" --eval-command=quit || \
1017 kill $pid )) 2> /dev/null & watcher=$!
1018 wait $pid
1019 test_exit_status=$?
1020 pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
1021 if [ $test_exit_status = 0 ]; then
1022 # The test finished normally.
1023 exit 0
1024 else
1025 # The test failed or timed out.
1026 if [ $test_exit_status = 124 ]; then
1027 # The test timed out.
1028 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
1029 fi
Alex Light722d6712018-02-12 17:41:12 +00001030 exit $test_exit_status
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001031 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001032 fi
1033 fi
1034fi