blob: 751aa95f50d7bc8a4685a1943053b1c6c063164e [file] [log] [blame]
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001#!/bin/bash
2#
3# Runner for an individual run-test.
4
5msg() {
6 if [ "$QUIET" = "n" ]; then
7 echo "$@"
8 fi
9}
10
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000011ANDROID_ROOT="/system"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010012ARCHITECTURES_32="(arm|x86|mips|none)"
Andreas Gampe1a5c4062015-01-15 12:10:47 -080013ARCHITECTURES_64="(arm64|x86_64|mips64|none)"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010014ARCHITECTURES_PATTERN="${ARCHITECTURES_32}"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000015BOOT_IMAGE=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010016COMPILE_FLAGS=""
17DALVIKVM="dalvikvm32"
18DEBUGGER="n"
19DEV_MODE="n"
20DEX2OAT=""
Alex Light8a0e0332015-10-26 10:11:58 -070021EXPERIMENTAL=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010022FALSE_BIN="/system/bin/false"
23FLAGS=""
Alex Light7233c7e2016-07-28 10:07:45 -070024ANDROID_FLAGS=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010025GDB=""
Nicolas Geoffraybaf91022014-10-08 09:56:45 +010026GDB_ARGS=""
27GDB_SERVER="gdbserver"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010028HAVE_IMAGE="y"
29HOST="n"
30INTERPRETER="n"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080031JIT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010032INVOKE_WITH=""
Alex Lighte06b6342017-01-05 14:37:21 -080033IS_JVMTI_TEST="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010034ISA=x86
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000035LIBRARY_DIRECTORY="lib"
Colin Crossafd3c9e2016-09-16 13:47:21 -070036TEST_DIRECTORY="nativetest"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000037MAIN=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010038OPTIMIZE="y"
39PATCHOAT=""
40PREBUILD="y"
41QUIET="n"
Nicolas Geoffray94e25db2017-01-27 14:54:28 +000042RELOCATE="n"
Richard Uhler76f5cb62016-04-04 13:30:16 -070043STRIP_DEX="n"
Jeff Hao207a37d2014-10-29 17:24:25 -070044SECONDARY_DEX=""
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -070045TIME_OUT="gdb" # "n" (disabled), "timeout" (use timeout), "gdb" (use gdb)
46# Value in seconds
Hiroshi Yamauchifd3161a2017-01-18 14:47:25 -080047if [ "$ART_USE_READ_BARRIER" != "false" ]; then
Hiroshi Yamauchia9b296c2016-10-07 17:07:03 -070048 TIME_OUT_VALUE=2400 # 40 minutes.
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070049else
Mathieu Chartier2576be22016-05-24 10:24:53 -070050 TIME_OUT_VALUE=1200 # 20 minutes.
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070051fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010052USE_GDB="n"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +010053USE_JVM="n"
Igor Murashkin7617abd2015-07-10 18:27:47 -070054VERIFY="y" # y=yes,n=no,s=softfail
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010055ZYGOTE=""
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -070056DEX_VERIFY=""
Andreas Gampe65357032015-02-19 15:10:24 -080057USE_DEX2OAT_AND_PATCHOAT="y"
Andreas Gampe4d2ef332015-08-05 09:24:45 -070058INSTRUCTION_SET_FEATURES=""
Mathieu Chartier031768a2015-08-27 10:25:02 -070059ARGS=""
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -070060EXTERNAL_LOG_TAGS="n" # if y respect externally set ANDROID_LOG_TAGS.
61DRY_RUN="n" # if y prepare to run the test but don't run it.
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +000062TEST_VDEX="n"
Alex Lighte06b6342017-01-05 14:37:21 -080063TEST_IS_NDEBUG="n"
Calin Juravle857f0582016-12-20 14:36:59 +000064APP_IMAGE="y"
Nicolas Geoffray74981052017-01-16 17:54:09 +000065VDEX_FILTER=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010066
67while true; do
68 if [ "x$1" = "x--quiet" ]; then
69 QUIET="y"
70 shift
Alex Lighte06b6342017-01-05 14:37:21 -080071 elif [ "x$1" = "x--jvmti" ]; then
72 IS_JVMTI_TEST="y"
73 shift
Alex Lightfaf90b62016-08-12 14:43:48 -070074 elif [ "x$1" = "x-O" ]; then
Alex Lighte06b6342017-01-05 14:37:21 -080075 TEST_IS_NDEBUG="y"
Alex Lightfaf90b62016-08-12 14:43:48 -070076 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010077 elif [ "x$1" = "x--lib" ]; then
78 shift
79 if [ "x$1" = "x" ]; then
80 echo "$0 missing argument to --lib" 1>&2
81 exit 1
82 fi
83 LIB="$1"
84 shift
Alex Light97acf192016-03-17 09:59:38 -070085 elif [ "x$1" = "x--gc-stress" ]; then
86 # Give an extra 5 mins if we are gc-stress.
87 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + 300))
88 shift
Mathieu Chartier031768a2015-08-27 10:25:02 -070089 elif [ "x$1" = "x--testlib" ]; then
90 shift
91 if [ "x$1" = "x" ]; then
92 echo "$0 missing argument to --testlib" 1>&2
93 exit 1
94 fi
Mathieu Chartierde286fd2015-09-03 18:10:29 -070095 ARGS="${ARGS} $1"
Mathieu Chartier031768a2015-08-27 10:25:02 -070096 shift
David Srbecky52886112016-01-22 13:56:47 +000097 elif [ "x$1" = "x--args" ]; then
98 shift
99 if [ "x$1" = "x" ]; then
100 echo "$0 missing argument to --args" 1>&2
101 exit 1
102 fi
103 ARGS="${ARGS} $1"
104 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100105 elif [ "x$1" = "x-Xcompiler-option" ]; then
106 shift
107 option="$1"
108 FLAGS="${FLAGS} -Xcompiler-option $option"
109 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
110 shift
Alex Light7233c7e2016-07-28 10:07:45 -0700111 elif [ "x$1" = "x--android-runtime-option" ]; then
112 shift
113 option="$1"
114 ANDROID_FLAGS="${ANDROID_FLAGS} $option"
115 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100116 elif [ "x$1" = "x--runtime-option" ]; then
117 shift
118 option="$1"
119 FLAGS="${FLAGS} $option"
120 shift
121 elif [ "x$1" = "x--boot" ]; then
122 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000123 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100124 shift
125 elif [ "x$1" = "x--no-dex2oat" ]; then
126 DEX2OAT="-Xcompiler:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800127 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100128 shift
129 elif [ "x$1" = "x--no-patchoat" ]; then
130 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -0800131 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100132 shift
133 elif [ "x$1" = "x--relocate" ]; then
134 RELOCATE="y"
135 shift
136 elif [ "x$1" = "x--no-relocate" ]; then
137 RELOCATE="n"
138 shift
139 elif [ "x$1" = "x--prebuild" ]; then
140 PREBUILD="y"
141 shift
Calin Juravle857f0582016-12-20 14:36:59 +0000142 elif [ "x$1" = "x--no-app-image" ]; then
143 APP_IMAGE="n"
144 shift
Richard Uhler76f5cb62016-04-04 13:30:16 -0700145 elif [ "x$1" = "x--strip-dex" ]; then
146 STRIP_DEX="y"
147 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100148 elif [ "x$1" = "x--host" ]; then
149 HOST="y"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000150 ANDROID_ROOT="$ANDROID_HOST_OUT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100151 shift
152 elif [ "x$1" = "x--no-prebuild" ]; then
153 PREBUILD="n"
154 shift
155 elif [ "x$1" = "x--no-image" ]; then
156 HAVE_IMAGE="n"
157 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700158 elif [ "x$1" = "x--secondary" ]; then
159 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
Calin Juravle175dc732015-08-25 15:42:32 +0100160 # Enable cfg-append to make sure we get the dump for both dex files.
161 # (otherwise the runtime compilation of the secondary dex will overwrite
Roland Levillainb0103ca2016-11-01 14:48:47 +0000162 # the dump of the first one).
Calin Juravle175dc732015-08-25 15:42:32 +0100163 FLAGS="${FLAGS} -Xcompiler-option --dump-cfg-append"
164 COMPILE_FLAGS="${COMPILE_FLAGS} --dump-cfg-append"
Jeff Hao207a37d2014-10-29 17:24:25 -0700165 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100166 elif [ "x$1" = "x--debug" ]; then
167 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800168 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100169 shift
170 elif [ "x$1" = "x--gdb" ]; then
171 USE_GDB="y"
172 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800173 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100174 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700175 elif [ "x$1" = "x--gdb-arg" ]; then
176 shift
177 gdb_arg="$1"
178 GDB_ARGS="${GDB_ARGS} $gdb_arg"
179 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100180 elif [ "x$1" = "x--zygote" ]; then
181 ZYGOTE="-Xzygote"
182 msg "Spawning from zygote"
183 shift
184 elif [ "x$1" = "x--dev" ]; then
185 DEV_MODE="y"
186 shift
187 elif [ "x$1" = "x--interpreter" ]; then
188 INTERPRETER="y"
189 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800190 elif [ "x$1" = "x--jit" ]; then
191 JIT="y"
192 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100193 elif [ "x$1" = "x--jvm" ]; then
194 USE_JVM="y"
195 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100196 elif [ "x$1" = "x--invoke-with" ]; then
197 shift
198 if [ "x$1" = "x" ]; then
199 echo "$0 missing argument to --invoke-with" 1>&2
200 exit 1
201 fi
202 if [ "x$INVOKE_WITH" = "x" ]; then
203 INVOKE_WITH="$1"
204 else
205 INVOKE_WITH="$INVOKE_WITH $1"
206 fi
207 shift
208 elif [ "x$1" = "x--no-verify" ]; then
209 VERIFY="n"
210 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700211 elif [ "x$1" = "x--verify-soft-fail" ]; then
212 VERIFY="s"
213 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100214 elif [ "x$1" = "x--no-optimize" ]; then
215 OPTIMIZE="n"
216 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000217 elif [ "x$1" = "x--android-root" ]; then
218 shift
219 ANDROID_ROOT="$1"
220 shift
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700221 elif [ "x$1" = "x--instruction-set-features" ]; then
222 shift
223 INSTRUCTION_SET_FEATURES="$1"
224 shift
Mathieu Chartier2576be22016-05-24 10:24:53 -0700225 elif [ "x$1" = "x--timeout" ]; then
226 shift
227 TIME_OUT_VALUE="$1"
228 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100229 elif [ "x$1" = "x--" ]; then
230 shift
231 break
232 elif [ "x$1" = "x--64" ]; then
233 ISA="x86_64"
234 GDB_SERVER="gdbserver64"
235 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000236 LIBRARY_DIRECTORY="lib64"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700237 TEST_DIRECTORY="nativetest64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100238 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
239 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700240 elif [ "x$1" = "x--pic-test" ]; then
241 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
242 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
243 shift
Alex Light8a0e0332015-10-26 10:11:58 -0700244 elif [ "x$1" = "x--experimental" ]; then
245 if [ "$#" -lt 2 ]; then
246 echo "missing --experimental option" 1>&2
247 exit 1
248 fi
249 EXPERIMENTAL="$EXPERIMENTAL $2"
250 shift 2
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700251 elif [ "x$1" = "x--external-log-tags" ]; then
252 EXTERNAL_LOG_TAGS="y"
253 shift
254 elif [ "x$1" = "x--dry-run" ]; then
255 DRY_RUN="y"
256 shift
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000257 elif [ "x$1" = "x--vdex" ]; then
258 TEST_VDEX="y"
259 shift
Nicolas Geoffray74981052017-01-16 17:54:09 +0000260 elif [ "x$1" = "x--vdex-filter" ]; then
261 shift
262 option="$1"
263 VDEX_FILTER="--compiler-filter=$option"
264 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100265 elif expr "x$1" : "x--" >/dev/null 2>&1; then
266 echo "unknown $0 option: $1" 1>&2
267 exit 1
268 else
269 break
270 fi
271done
272
Alex Light8a0e0332015-10-26 10:11:58 -0700273if [ "$USE_JVM" = "n" ]; then
Alex Light7233c7e2016-07-28 10:07:45 -0700274 FLAGS="${FLAGS} ${ANDROID_FLAGS}"
Alex Light8a0e0332015-10-26 10:11:58 -0700275 for feature in ${EXPERIMENTAL}; do
Alex Lightfa022852015-10-28 09:13:20 -0700276 FLAGS="${FLAGS} -Xexperimental:${feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:${feature}"
Alex Light8a0e0332015-10-26 10:11:58 -0700277 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xexperimental:${feature}"
278 done
279fi
280
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100281if [ "x$1" = "x" ] ; then
282 MAIN="Main"
283else
284 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700285 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100286fi
287
288if [ "$ZYGOTE" = "" ]; then
289 if [ "$OPTIMIZE" = "y" ]; then
290 if [ "$VERIFY" = "y" ]; then
291 DEX_OPTIMIZE="-Xdexopt:verified"
292 else
293 DEX_OPTIMIZE="-Xdexopt:all"
294 fi
295 msg "Performing optimizations"
296 else
297 DEX_OPTIMIZE="-Xdexopt:none"
298 msg "Skipping optimizations"
299 fi
300
301 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100302 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100303 msg "Performing verification"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700304 elif [ "$VERIFY" = "s" ]; then
305 JVM_VERIFY_ARG="Xverify:all"
306 DEX_VERIFY="-Xverify:softfail"
307 msg "Forcing verification to be soft fail"
308 else # VERIFY = "n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100309 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100310 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100311 msg "Skipping verification"
312 fi
313fi
314
315msg "------------------------------"
316
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100317if [ "$DEBUGGER" = "y" ]; then
318 # Use this instead for ddms and connect by running 'ddms':
319 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
320 # TODO: add a separate --ddms option?
321
322 PORT=12345
323 msg "Waiting for jdb to connect:"
324 if [ "$HOST" = "n" ]; then
325 msg " adb forward tcp:$PORT tcp:$PORT"
326 fi
327 msg " jdb -attach localhost:$PORT"
328 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
329fi
330
Alex Lightfba89fe2017-01-12 16:11:02 -0800331if [ "$IS_JVMTI_TEST" = "y" ]; then
332 plugin=libopenjdkjvmtid.so
333 agent=libtiagentd.so
334 lib=tiagentd
335 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
336 agent=libtiagent.so
337 plugin=libopenjdkjvmti.so
338 lib=tiagent
339 fi
340
341 ARGS="${ARGS} ${lib}"
342 if [[ "$USE_JVM" = "y" ]]; then
343 FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${TEST_NAME},jvm"
344 else
345 FLAGS="${FLAGS} -agentpath:${agent}=${TEST_NAME},art"
346 FLAGS="${FLAGS} -Xplugin:${plugin}"
Nicolas Geoffraya0619e22016-12-20 13:57:43 +0000347 FLAGS="${FLAGS} -Xcompiler-option --debuggable"
Alex Lightfba89fe2017-01-12 16:11:02 -0800348 # Always make the compilation be debuggable.
349 COMPILE_FLAGS="${COMPILE_FLAGS} --debuggable"
350 fi
351fi
352
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100353if [ "$USE_JVM" = "y" ]; then
Alex Light9c20a142016-08-23 15:05:12 -0700354 export LD_LIBRARY_PATH=${ANDROID_HOST_OUT}/lib64
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700355 # Xmx is necessary since we don't pass down the ART flags to JVM.
Vladimir Markoc5798bf2016-12-09 10:20:54 +0000356 # We pass the classes2 path whether it's used (src-multidex) or not.
357 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes:classes2 ${FLAGS} $MAIN $@ ${ARGS}"
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700358 if [ "$DEV_MODE" = "y" ]; then
359 echo $cmdline
360 fi
361 $cmdline
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100362 exit
363fi
364
365
366if [ "$HAVE_IMAGE" = "n" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000367 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000368else
369 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100370fi
371
372
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100373if [ "$USE_GDB" = "y" ]; then
374 if [ "$HOST" = "n" ]; then
375 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100376 else
377 if [ `uname` = "Darwin" ]; then
378 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700379 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100380 DALVIKVM=
381 else
382 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700383 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100384 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
385 # gdbargs="--annotate=3 $gdbargs"
386 fi
387 fi
388fi
389
390if [ "$INTERPRETER" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000391 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700392 if [ "$VERIFY" = "y" ] ; then
Richard Uhlerf4b34872016-04-13 11:03:46 -0700393 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=interpret-only"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700394 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700395 elif [ "$VERIFY" = "s" ]; then
Richard Uhlerf4b34872016-04-13 11:03:46 -0700396 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-at-runtime"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700397 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
398 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
399 else # VERIFY = "n"
Richard Uhlerf4b34872016-04-13 11:03:46 -0700400 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-none"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700401 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
402 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
403 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100404fi
405
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800406if [ "$JIT" = "y" ]; then
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000407 INT_OPTS="-Xusejit:true"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800408 if [ "$VERIFY" = "y" ] ; then
Calin Juravle09665582016-12-20 14:00:48 +0000409 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=interpret-only"
410 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800411 else
Richard Uhlerf4b34872016-04-13 11:03:46 -0700412 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify-none"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800413 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
414 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
415 fi
416fi
417
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100418JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
419
420if [ "$RELOCATE" = "y" ]; then
421 COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information --runtime-arg -Xnorelocate"
422 FLAGS="${FLAGS} -Xrelocate -Xcompiler-option --include-patch-information"
423 if [ "$HOST" = "y" ]; then
424 # Run test sets a fairly draconian ulimit that we will likely blow right over
425 # since we are relocating. Get the total size of the /system/framework directory
426 # in 512 byte blocks and set it as the ulimit. This should be more than enough
427 # room.
428 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
Alex Lightd26b7e42016-04-08 09:44:54 -0700429 ulimit -S $(du -c -B512 ${ANDROID_HOST_OUT}/framework 2>/dev/null | tail -1 | cut -f1) || exit 1
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100430 fi
431 fi
432else
433 FLAGS="$FLAGS -Xnorelocate"
434 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
Mathieu Chartiercae2ed92015-06-09 13:02:50 -0700435 if [ "$HOST" = "y" ]; then
436 # Increase ulimit to 64MB in case we are running hprof test.
437 ulimit -S 64000 || exit 1
438 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100439fi
440
441if [ "$HOST" = "n" ]; then
Nicolas Geoffrayd295bc82016-11-04 13:03:05 +0000442 # Need to be root to query /data/dalvik-cache
443 adb root > /dev/null
444 adb wait-for-device
445 ISA=
446 ISA_adb_invocation=
447 ISA_outcome=
448 # We iterate a few times to workaround an adb issue. b/32655576
449 for i in {1..10}; do
450 ISA_adb_invocation=$(adb shell ls -F /data/dalvik-cache)
451 ISA_outcome=$?
452 ISA=$(echo $ISA_adb_invocation | grep -Ewo "${ARCHITECTURES_PATTERN}")
453 if [ x"$ISA" != "x" ]; then
454 break;
455 fi
456 done
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100457 if [ x"$ISA" = "x" ]; then
458 echo "Unable to determine architecture"
Nicolas Geoffray8f500fa2016-11-03 11:18:48 +0000459 # Print a few things for helping diagnosing the problem.
Nicolas Geoffrayd295bc82016-11-04 13:03:05 +0000460 echo "adb invocation output: $ISA_adb_invocation"
461 echo "adb invocation outcome: $ISA_outcome"
Nicolas Geoffray8f500fa2016-11-03 11:18:48 +0000462 echo $(adb shell ls -F /data/dalvik-cache)
463 echo $(adb shell ls /data/dalvik-cache)
464 echo ${ARCHITECTURES_PATTERN}
465 echo $(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100466 exit 1
467 fi
468fi
469
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700470# Prevent test from silently falling back to interpreter in no-prebuild mode. This happens
471# when DEX_LOCATION path is too long, because vdex/odex filename is constructed by taking
472# full path to dex, stripping leading '/', appending '@classes.vdex' and changing every
473# remaining '/' into '@'.
474if [ "$HOST" = "y" ]; then
475 max_filename_size=$(getconf NAME_MAX $DEX_LOCATION)
476else
477 # There is no getconf on device, fallback to standard value. See NAME_MAX in kernel <linux/limits.h>
478 max_filename_size=255
479fi
480# Compute VDEX_NAME.
481DEX_LOCATION_STRIPPED="${DEX_LOCATION#/}"
482VDEX_NAME="${DEX_LOCATION_STRIPPED//\//@}@$TEST_NAME.jar@classes.vdex"
483if [ ${#VDEX_NAME} -gt $max_filename_size ]; then
484 echo "Dex location path too long."
485 exit 1
486fi
487
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100488dex2oat_cmdline="true"
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000489vdex_cmdline="true"
Alex Lightafb5d192016-05-24 15:57:45 -0700490mkdir_locations="${DEX_LOCATION}/dalvik-cache/$ISA"
Richard Uhler76f5cb62016-04-04 13:30:16 -0700491strip_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100492
Jeff Haodcdc85b2015-12-04 14:06:18 -0800493
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100494if [ "$PREBUILD" = "y" ]; then
Alex Lightafb5d192016-05-24 15:57:45 -0700495 mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/oat/$ISA"
Calin Juravle857f0582016-12-20 14:36:59 +0000496 if [ "$APP_IMAGE" = "y" ]; then
497 # Pick a base that will force the app image to get relocated.
498 app_image="--base=0x4000 --app-image-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.art"
499 fi
500
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000501 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100502 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000503 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100504 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
Andreas Gampe14759242016-03-23 10:54:21 -0700505 --oat-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.odex \
Jeff Haodcdc85b2015-12-04 14:06:18 -0800506 ${app_image} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100507 --instruction-set=$ISA"
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700508 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
509 dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
510 fi
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700511
512 # Add in a timeout. This is important for testing the compilation/verification time of
513 # pathological cases.
514 # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
515 # now. We should try to improve this.
516 # The current value is rather arbitrary. run-tests should compile quickly.
517 if [ "$HOST" != "n" ]; then
518 # Use SIGRTMIN+2 to try to dump threads.
519 # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
520 dex2oat_cmdline="timeout -k 1m -s SIGRTMIN+2 1m ${dex2oat_cmdline}"
521 fi
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000522 if [ "$TEST_VDEX" = "y" ]; then
Nicolas Geoffray74981052017-01-16 17:54:09 +0000523 vdex_cmdline="${dex2oat_cmdline} ${VDEX_FILTER} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000524 fi
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700525fi
526
Richard Uhler76f5cb62016-04-04 13:30:16 -0700527if [ "$STRIP_DEX" = "y" ]; then
528 strip_cmdline="zip --quiet --delete $DEX_LOCATION/$TEST_NAME.jar classes.dex"
529fi
530
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700531DALVIKVM_ISA_FEATURES_ARGS=""
532if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
533 DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100534fi
535
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000536# java.io.tmpdir can only be set at launch time.
537TMP_DIR_OPTION=""
538if [ "$HOST" = "n" ]; then
539 TMP_DIR_OPTION="-Djava.io.tmpdir=/data/local/tmp"
540fi
541
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000542# We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
543# b/27185632
544# b/24664297
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000545dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100546 $GDB_ARGS \
547 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700548 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100549 -XXlib:$LIB \
550 $PATCHOAT \
551 $DEX2OAT \
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700552 $DALVIKVM_ISA_FEATURES_ARGS \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100553 $ZYGOTE \
554 $JNI_OPTS \
555 $INT_OPTS \
556 $DEBUGGER_OPTS \
557 $DALVIKVM_BOOT_OPT \
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000558 $TMP_DIR_OPTION \
Nicolas Geoffraya73280d2016-02-15 13:05:16 +0000559 -XX:DumpNativeStackOnSigQuit:false \
Mathieu Chartier031768a2015-08-27 10:25:02 -0700560 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100561
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -0800562# Remove whitespace.
563dex2oat_cmdline=$(echo $dex2oat_cmdline)
564dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000565vdex_cmdline=$(echo $vdex_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100566
567if [ "$HOST" = "n" ]; then
568 adb root > /dev/null
569 adb wait-for-device
570 if [ "$QUIET" = "n" ]; then
571 adb shell rm -r $DEX_LOCATION
572 adb shell mkdir -p $DEX_LOCATION
573 adb push $TEST_NAME.jar $DEX_LOCATION
574 adb push $TEST_NAME-ex.jar $DEX_LOCATION
575 else
576 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
577 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
578 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
579 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
580 fi
581
Colin Crossafd3c9e2016-09-16 13:47:21 -0700582 LD_LIBRARY_PATH=/data/$TEST_DIRECTORY/art/$ISA
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000583 if [ "$ANDROID_ROOT" != "/system" ]; then
584 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
585 # so we can only use LD_LIBRARY_PATH when testing on a local
586 # installation.
Alex Light7233c7e2016-07-28 10:07:45 -0700587 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY:$LD_LIBRARY_PATH
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000588 fi
589
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700590 PUBLIC_LIBS=libart.so:libartd.so
591
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100592 # Create a script with the command. The command can get longer than the longest
593 # allowed adb command and there is no way to get the exit status from a adb shell
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700594 # command. Dalvik cache is cleaned before running to make subsequent executions
595 # of the script follow the same runtime path.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100596 cmdline="cd $DEX_LOCATION && \
597 export ANDROID_DATA=$DEX_LOCATION && \
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700598 export ANDROID_ADDITIONAL_PUBLIC_LIBRARIES=$PUBLIC_LIBS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100599 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000600 export ANDROID_ROOT=$ANDROID_ROOT && \
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700601 rm -rf ${DEX_LOCATION}/dalvik-cache/ && \
Alex Lightafb5d192016-05-24 15:57:45 -0700602 mkdir -p ${mkdir_locations} && \
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100603 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray4f7fdd22015-04-24 11:57:37 +0100604 export PATH=$ANDROID_ROOT/bin:$PATH && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100605 $dex2oat_cmdline && \
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000606 $vdex_cmdline && \
Richard Uhler76f5cb62016-04-04 13:30:16 -0700607 $strip_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100608 $dalvikvm_cmdline"
609
610 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
611 echo "$cmdline" > $cmdfile
612
613 if [ "$DEV_MODE" = "y" ]; then
614 echo $cmdline
615 fi
616
617 if [ "$QUIET" = "n" ]; then
618 adb push $cmdfile $DEX_LOCATION/cmdline.sh
619 else
620 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
621 fi
622
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700623 if [ "$DRY_RUN" != "y" ]; then
624 adb shell sh $DEX_LOCATION/cmdline.sh
625 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100626
627 rm -f $cmdfile
628else
629 export ANDROID_PRINTF_LOG=brief
Andreas Gampea8780822015-03-13 19:51:09 -0700630
631 # By default, and for prebuild dex2oat, we are interested in errors being logged. In dev mode
632 # we want debug messages.
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700633 if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
634 if [ "$DEV_MODE" = "y" ]; then
635 export ANDROID_LOG_TAGS='*:d'
636 else
637 export ANDROID_LOG_TAGS='*:e'
638 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100639 fi
Andreas Gampea8780822015-03-13 19:51:09 -0700640
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100641 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000642 export ANDROID_ROOT="${ANDROID_ROOT}"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700643 export LD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
644 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100645 export PATH="$PATH:${ANDROID_ROOT}/bin"
646
David Srbeckyc9ede382015-06-20 06:03:53 +0100647 # Temporarily disable address space layout randomization (ASLR).
648 # This is needed on the host so that the linker loads core.oat at the necessary address.
649 export LD_USE_LOAD_BIAS=1
650
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100651 cmdline="$dalvikvm_cmdline"
652
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700653 if [ "$TIME_OUT" = "gdb" ]; then
654 if [ `uname` = "Darwin" ]; then
655 # Fall back to timeout on Mac.
656 TIME_OUT="timeout"
Hiroshi Yamauchic823eff2015-09-01 16:21:35 -0700657 elif [ "$ISA" = "x86" ]; then
658 # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
659 TIME_OUT="timeout"
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700660 else
661 # Check if gdb is available.
662 gdb --eval-command="quit" > /dev/null 2>&1
663 if [ $? != 0 ]; then
664 # gdb isn't available. Fall back to timeout.
665 TIME_OUT="timeout"
666 fi
667 fi
668 fi
669
670 if [ "$TIME_OUT" = "timeout" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100671 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -0800672 #
Andreas Gampe6fb92562016-08-01 21:53:57 -0700673 # Note: We first send SIGRTMIN+2 (usually 36) to ART, which will induce a full thread dump
674 # before abort. However, dumping threads might deadlock, so we also use the "-k"
675 # option to definitely kill the child.
676 cmdline="timeout -k 120s -s SIGRTMIN+2 ${TIME_OUT_VALUE}s $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100677 fi
678
679 if [ "$DEV_MODE" = "y" ]; then
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000680 echo "mkdir -p ${mkdir_locations} && $dex2oat_cmdline && $vdex_cmdline && $strip_cmdline && $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100681 fi
682
683 cd $ANDROID_BUILD_TOP
684
David Srbecky2e4afe82016-01-27 18:42:06 +0000685 rm -rf ${DEX_LOCATION}/dalvik-cache/
Alex Lightafb5d192016-05-24 15:57:45 -0700686 mkdir -p ${mkdir_locations} || exit 1
Andreas Gampea8780822015-03-13 19:51:09 -0700687 $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000688 $vdex_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Richard Uhler76f5cb62016-04-04 13:30:16 -0700689 $strip_cmdline || { echo "Strip failed." >&2 ; exit 3; }
Andreas Gampea8780822015-03-13 19:51:09 -0700690
691 # For running, we must turn off logging when dex2oat or patchoat are missing. Otherwise we use
692 # the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700693 if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
694 if [ "$DEV_MODE" = "y" ]; then
695 export ANDROID_LOG_TAGS='*:d'
696 elif [ "$USE_DEX2OAT_AND_PATCHOAT" = "n" ]; then
697 # All tests would log the error of failing dex2oat/patchoat. Be silent here and only
698 # log fatal events.
699 export ANDROID_LOG_TAGS='*:s'
700 else
701 # We are interested in LOG(ERROR) output.
702 export ANDROID_LOG_TAGS='*:e'
703 fi
704 fi
705
706 if [ "$DRY_RUN" = "y" ]; then
707 exit 0
Andreas Gampea8780822015-03-13 19:51:09 -0700708 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100709
710 if [ "$USE_GDB" = "y" ]; then
711 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700712 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100713 else
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700714 if [ "$TIME_OUT" != "gdb" ]; then
715 trap 'kill -INT -$pid' INT
716 $cmdline "$@" 2>&1 & pid=$!
717 wait $pid
718 # Add extra detail if time out is enabled.
719 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
720 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
721 fi
722 else
723 # With a thread dump that uses gdb if a timeout.
724 trap 'kill -INT -$pid' INT
725 $cmdline "$@" 2>&1 & pid=$!
726 # Spawn a watcher process.
727 ( sleep $TIME_OUT_VALUE && \
728 echo "##### Thread dump using gdb on test timeout" && \
729 ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
730 --eval-command="call exit(124)" --eval-command=quit || \
731 kill $pid )) 2> /dev/null & watcher=$!
732 wait $pid
733 test_exit_status=$?
734 pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
735 if [ $test_exit_status = 0 ]; then
736 # The test finished normally.
737 exit 0
738 else
739 # The test failed or timed out.
740 if [ $test_exit_status = 124 ]; then
741 # The test timed out.
742 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
743 fi
744 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100745 fi
746 fi
747fi