blob: efc0bfb1b93f6d45d3a4510cb91635d09edc5afb [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=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010021FALSE_BIN="/system/bin/false"
22FLAGS=""
23GDB=""
Nicolas Geoffraybaf91022014-10-08 09:56:45 +010024GDB_ARGS=""
25GDB_SERVER="gdbserver"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010026HAVE_IMAGE="y"
27HOST="n"
28INTERPRETER="n"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080029JIT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010030INVOKE_WITH=""
31ISA=x86
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000032LIBRARY_DIRECTORY="lib"
33MAIN=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010034OPTIMIZE="y"
35PATCHOAT=""
36PREBUILD="y"
37QUIET="n"
38RELOCATE="y"
Jeff Hao207a37d2014-10-29 17:24:25 -070039SECONDARY_DEX=""
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -070040TIME_OUT="gdb" # "n" (disabled), "timeout" (use timeout), "gdb" (use gdb)
41# Value in seconds
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070042if [ "$ART_USE_READ_BARRIER" = "true" ]; then
43 TIME_OUT_VALUE=900 # 15 minutes.
44else
45 TIME_OUT_VALUE=600 # 10 minutes.
46fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010047USE_GDB="n"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +010048USE_JVM="n"
Igor Murashkin7617abd2015-07-10 18:27:47 -070049VERIFY="y" # y=yes,n=no,s=softfail
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010050ZYGOTE=""
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -070051DEX_VERIFY=""
Andreas Gampe65357032015-02-19 15:10:24 -080052USE_DEX2OAT_AND_PATCHOAT="y"
Andreas Gampe4d2ef332015-08-05 09:24:45 -070053INSTRUCTION_SET_FEATURES=""
Mathieu Chartier031768a2015-08-27 10:25:02 -070054ARGS=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010055
56while true; do
57 if [ "x$1" = "x--quiet" ]; then
58 QUIET="y"
59 shift
60 elif [ "x$1" = "x--lib" ]; then
61 shift
62 if [ "x$1" = "x" ]; then
63 echo "$0 missing argument to --lib" 1>&2
64 exit 1
65 fi
66 LIB="$1"
67 shift
Mathieu Chartier031768a2015-08-27 10:25:02 -070068 elif [ "x$1" = "x--testlib" ]; then
69 shift
70 if [ "x$1" = "x" ]; then
71 echo "$0 missing argument to --testlib" 1>&2
72 exit 1
73 fi
Mathieu Chartierde286fd2015-09-03 18:10:29 -070074 ARGS="${ARGS} $1"
Mathieu Chartier031768a2015-08-27 10:25:02 -070075 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010076 elif [ "x$1" = "x-Xcompiler-option" ]; then
77 shift
78 option="$1"
79 FLAGS="${FLAGS} -Xcompiler-option $option"
80 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
81 shift
82 elif [ "x$1" = "x--runtime-option" ]; then
83 shift
84 option="$1"
85 FLAGS="${FLAGS} $option"
86 shift
87 elif [ "x$1" = "x--boot" ]; then
88 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000089 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010090 shift
91 elif [ "x$1" = "x--no-dex2oat" ]; then
92 DEX2OAT="-Xcompiler:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -080093 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010094 shift
95 elif [ "x$1" = "x--no-patchoat" ]; then
96 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -080097 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010098 shift
99 elif [ "x$1" = "x--relocate" ]; then
100 RELOCATE="y"
101 shift
102 elif [ "x$1" = "x--no-relocate" ]; then
103 RELOCATE="n"
104 shift
105 elif [ "x$1" = "x--prebuild" ]; then
106 PREBUILD="y"
107 shift
108 elif [ "x$1" = "x--host" ]; then
109 HOST="y"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000110 ANDROID_ROOT="$ANDROID_HOST_OUT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100111 shift
112 elif [ "x$1" = "x--no-prebuild" ]; then
113 PREBUILD="n"
114 shift
115 elif [ "x$1" = "x--no-image" ]; then
116 HAVE_IMAGE="n"
117 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700118 elif [ "x$1" = "x--secondary" ]; then
119 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
120 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100121 elif [ "x$1" = "x--debug" ]; then
122 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800123 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100124 shift
125 elif [ "x$1" = "x--gdb" ]; then
126 USE_GDB="y"
127 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800128 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100129 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700130 elif [ "x$1" = "x--gdb-arg" ]; then
131 shift
132 gdb_arg="$1"
133 GDB_ARGS="${GDB_ARGS} $gdb_arg"
134 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100135 elif [ "x$1" = "x--zygote" ]; then
136 ZYGOTE="-Xzygote"
137 msg "Spawning from zygote"
138 shift
139 elif [ "x$1" = "x--dev" ]; then
140 DEV_MODE="y"
141 shift
142 elif [ "x$1" = "x--interpreter" ]; then
143 INTERPRETER="y"
144 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800145 elif [ "x$1" = "x--jit" ]; then
146 JIT="y"
147 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100148 elif [ "x$1" = "x--jvm" ]; then
149 USE_JVM="y"
150 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100151 elif [ "x$1" = "x--invoke-with" ]; then
152 shift
153 if [ "x$1" = "x" ]; then
154 echo "$0 missing argument to --invoke-with" 1>&2
155 exit 1
156 fi
157 if [ "x$INVOKE_WITH" = "x" ]; then
158 INVOKE_WITH="$1"
159 else
160 INVOKE_WITH="$INVOKE_WITH $1"
161 fi
162 shift
163 elif [ "x$1" = "x--no-verify" ]; then
164 VERIFY="n"
165 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700166 elif [ "x$1" = "x--verify-soft-fail" ]; then
167 VERIFY="s"
168 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100169 elif [ "x$1" = "x--no-optimize" ]; then
170 OPTIMIZE="n"
171 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000172 elif [ "x$1" = "x--android-root" ]; then
173 shift
174 ANDROID_ROOT="$1"
175 shift
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700176 elif [ "x$1" = "x--instruction-set-features" ]; then
177 shift
178 INSTRUCTION_SET_FEATURES="$1"
179 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100180 elif [ "x$1" = "x--" ]; then
181 shift
182 break
183 elif [ "x$1" = "x--64" ]; then
184 ISA="x86_64"
185 GDB_SERVER="gdbserver64"
186 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000187 LIBRARY_DIRECTORY="lib64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100188 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
189 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700190 elif [ "x$1" = "x--pic-test" ]; then
191 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
192 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
193 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100194 elif expr "x$1" : "x--" >/dev/null 2>&1; then
195 echo "unknown $0 option: $1" 1>&2
196 exit 1
197 else
198 break
199 fi
200done
201
202if [ "x$1" = "x" ] ; then
203 MAIN="Main"
204else
205 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700206 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100207fi
208
209if [ "$ZYGOTE" = "" ]; then
210 if [ "$OPTIMIZE" = "y" ]; then
211 if [ "$VERIFY" = "y" ]; then
212 DEX_OPTIMIZE="-Xdexopt:verified"
213 else
214 DEX_OPTIMIZE="-Xdexopt:all"
215 fi
216 msg "Performing optimizations"
217 else
218 DEX_OPTIMIZE="-Xdexopt:none"
219 msg "Skipping optimizations"
220 fi
221
222 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100223 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100224 msg "Performing verification"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700225 elif [ "$VERIFY" = "s" ]; then
226 JVM_VERIFY_ARG="Xverify:all"
227 DEX_VERIFY="-Xverify:softfail"
228 msg "Forcing verification to be soft fail"
229 else # VERIFY = "n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100230 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100231 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100232 msg "Skipping verification"
233 fi
234fi
235
236msg "------------------------------"
237
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100238if [ "$DEBUGGER" = "y" ]; then
239 # Use this instead for ddms and connect by running 'ddms':
240 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
241 # TODO: add a separate --ddms option?
242
243 PORT=12345
244 msg "Waiting for jdb to connect:"
245 if [ "$HOST" = "n" ]; then
246 msg " adb forward tcp:$PORT tcp:$PORT"
247 fi
248 msg " jdb -attach localhost:$PORT"
249 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
250fi
251
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100252if [ "$USE_JVM" = "y" ]; then
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700253 # Xmx is necessary since we don't pass down the ART flags to JVM.
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700254 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes ${FLAGS} $MAIN $@"
255 if [ "$DEV_MODE" = "y" ]; then
256 echo $cmdline
257 fi
258 $cmdline
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100259 exit
260fi
261
262
263if [ "$HAVE_IMAGE" = "n" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000264 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000265else
266 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100267fi
268
269
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100270if [ "$USE_GDB" = "y" ]; then
271 if [ "$HOST" = "n" ]; then
272 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100273 else
274 if [ `uname` = "Darwin" ]; then
275 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700276 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100277 DALVIKVM=
278 else
279 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700280 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100281 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
282 # gdbargs="--annotate=3 $gdbargs"
283 fi
284 fi
285fi
286
287if [ "$INTERPRETER" = "y" ]; then
288 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700289 if [ "$VERIFY" = "y" ] ; then
290 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700291 elif [ "$VERIFY" = "s" ]; then
292 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
293 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
294 else # VERIFY = "n"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700295 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
296 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
297 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100298fi
299
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800300if [ "$JIT" = "y" ]; then
Sebastien Hertz155bef42015-03-09 14:57:48 +0100301 INT_OPTS="-Xusejit:true"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800302 if [ "$VERIFY" = "y" ] ; then
Mathieu Chartiere86deef2015-03-19 13:43:37 -0700303 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800304 else
305 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
306 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
307 fi
308fi
309
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100310JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
311
312if [ "$RELOCATE" = "y" ]; then
313 COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information --runtime-arg -Xnorelocate"
314 FLAGS="${FLAGS} -Xrelocate -Xcompiler-option --include-patch-information"
315 if [ "$HOST" = "y" ]; then
316 # Run test sets a fairly draconian ulimit that we will likely blow right over
317 # since we are relocating. Get the total size of the /system/framework directory
318 # in 512 byte blocks and set it as the ulimit. This should be more than enough
319 # room.
320 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
321 ulimit -S $(du -c -B512 ${ANDROID_HOST_OUT}/framework | tail -1 | cut -f1) || exit 1
322 fi
323 fi
324else
325 FLAGS="$FLAGS -Xnorelocate"
326 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
Mathieu Chartiercae2ed92015-06-09 13:02:50 -0700327 if [ "$HOST" = "y" ]; then
328 # Increase ulimit to 64MB in case we are running hprof test.
329 ulimit -S 64000 || exit 1
330 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100331fi
332
333if [ "$HOST" = "n" ]; then
334 ISA=$(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
335 if [ x"$ISA" = "x" ]; then
336 echo "Unable to determine architecture"
337 exit 1
338 fi
339fi
340
341dex2oat_cmdline="true"
342mkdir_cmdline="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
343
344if [ "$PREBUILD" = "y" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000345 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100346 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000347 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100348 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
349 --oat-file=$DEX_LOCATION/dalvik-cache/$ISA/$(echo $DEX_LOCATION/$TEST_NAME.jar/classes.dex | cut -d/ -f 2- | sed "s:/:@:g") \
350 --instruction-set=$ISA"
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700351 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
352 dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
353 fi
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700354
355 # Add in a timeout. This is important for testing the compilation/verification time of
356 # pathological cases.
357 # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
358 # now. We should try to improve this.
359 # The current value is rather arbitrary. run-tests should compile quickly.
360 if [ "$HOST" != "n" ]; then
361 # Use SIGRTMIN+2 to try to dump threads.
362 # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
363 dex2oat_cmdline="timeout -k 1m -s SIGRTMIN+2 1m ${dex2oat_cmdline}"
364 fi
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700365fi
366
367DALVIKVM_ISA_FEATURES_ARGS=""
368if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
369 DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100370fi
371
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000372dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100373 $GDB_ARGS \
374 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700375 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100376 -XXlib:$LIB \
377 $PATCHOAT \
378 $DEX2OAT \
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700379 $DALVIKVM_ISA_FEATURES_ARGS \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100380 $ZYGOTE \
381 $JNI_OPTS \
382 $INT_OPTS \
383 $DEBUGGER_OPTS \
384 $DALVIKVM_BOOT_OPT \
Mathieu Chartier031768a2015-08-27 10:25:02 -0700385 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100386
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -0800387# Remove whitespace.
388dex2oat_cmdline=$(echo $dex2oat_cmdline)
389dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100390
391if [ "$HOST" = "n" ]; then
392 adb root > /dev/null
393 adb wait-for-device
394 if [ "$QUIET" = "n" ]; then
395 adb shell rm -r $DEX_LOCATION
396 adb shell mkdir -p $DEX_LOCATION
397 adb push $TEST_NAME.jar $DEX_LOCATION
398 adb push $TEST_NAME-ex.jar $DEX_LOCATION
399 else
400 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
401 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
402 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
403 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
404 fi
405
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000406 LD_LIBRARY_PATH=
407 if [ "$ANDROID_ROOT" != "/system" ]; then
408 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
409 # so we can only use LD_LIBRARY_PATH when testing on a local
410 # installation.
411 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY
412 fi
413
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100414 # Create a script with the command. The command can get longer than the longest
415 # allowed adb command and there is no way to get the exit status from a adb shell
416 # command.
417 cmdline="cd $DEX_LOCATION && \
418 export ANDROID_DATA=$DEX_LOCATION && \
419 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000420 export ANDROID_ROOT=$ANDROID_ROOT && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100421 $mkdir_cmdline && \
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100422 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray4f7fdd22015-04-24 11:57:37 +0100423 export PATH=$ANDROID_ROOT/bin:$PATH && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100424 $dex2oat_cmdline && \
425 $dalvikvm_cmdline"
426
427 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
428 echo "$cmdline" > $cmdfile
429
430 if [ "$DEV_MODE" = "y" ]; then
431 echo $cmdline
432 fi
433
434 if [ "$QUIET" = "n" ]; then
435 adb push $cmdfile $DEX_LOCATION/cmdline.sh
436 else
437 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
438 fi
439
440 adb shell sh $DEX_LOCATION/cmdline.sh
441
442 rm -f $cmdfile
443else
444 export ANDROID_PRINTF_LOG=brief
Andreas Gampea8780822015-03-13 19:51:09 -0700445
446 # By default, and for prebuild dex2oat, we are interested in errors being logged. In dev mode
447 # we want debug messages.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100448 if [ "$DEV_MODE" = "y" ]; then
449 export ANDROID_LOG_TAGS='*:d'
450 else
Andreas Gampee4301ff2015-02-17 19:25:29 -0800451 export ANDROID_LOG_TAGS='*:e'
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100452 fi
Andreas Gampea8780822015-03-13 19:51:09 -0700453
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100454 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000455 export ANDROID_ROOT="${ANDROID_ROOT}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100456 export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
457 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
458 export PATH="$PATH:${ANDROID_ROOT}/bin"
459
David Srbeckyc9ede382015-06-20 06:03:53 +0100460 # Temporarily disable address space layout randomization (ASLR).
461 # This is needed on the host so that the linker loads core.oat at the necessary address.
462 export LD_USE_LOAD_BIAS=1
463
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100464 cmdline="$dalvikvm_cmdline"
465
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700466 if [ "$TIME_OUT" = "gdb" ]; then
467 if [ `uname` = "Darwin" ]; then
468 # Fall back to timeout on Mac.
469 TIME_OUT="timeout"
Hiroshi Yamauchic823eff2015-09-01 16:21:35 -0700470 elif [ "$ISA" = "x86" ]; then
471 # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
472 TIME_OUT="timeout"
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700473 else
474 # Check if gdb is available.
475 gdb --eval-command="quit" > /dev/null 2>&1
476 if [ $? != 0 ]; then
477 # gdb isn't available. Fall back to timeout.
478 TIME_OUT="timeout"
479 fi
480 fi
481 fi
482
483 if [ "$TIME_OUT" = "timeout" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100484 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -0800485 #
486 # Note: We use nested timeouts. The inner timeout sends SIGRTMIN+2 (usually 36) to ART, which
487 # will induce a full thread dump before abort. However, dumping threads might deadlock,
488 # so the outer timeout sends the regular SIGTERM after an additional minute to ensure
489 # termination (without dumping all threads).
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700490 TIME_PLUS_ONE=$(($TIME_OUT_VALUE + 60))
491 cmdline="timeout ${TIME_PLUS_ONE}s timeout -s SIGRTMIN+2 ${TIME_OUT_VALUE}s $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100492 fi
493
494 if [ "$DEV_MODE" = "y" ]; then
495 if [ "$PREBUILD" = "y" ]; then
496 echo "$mkdir_cmdline && $dex2oat_cmdline && $cmdline"
497 elif [ "$RELOCATE" = "y" ]; then
498 echo "$mkdir_cmdline && $cmdline"
499 else
500 echo $cmdline
501 fi
502 fi
503
504 cd $ANDROID_BUILD_TOP
505
506 $mkdir_cmdline || exit 1
Andreas Gampea8780822015-03-13 19:51:09 -0700507 $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
508
509 # For running, we must turn off logging when dex2oat or patchoat are missing. Otherwise we use
510 # the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
511 if [ "$DEV_MODE" = "y" ]; then
512 export ANDROID_LOG_TAGS='*:d'
513 elif [ "$USE_DEX2OAT_AND_PATCHOAT" = "n" ]; then
514 # All tests would log the error of failing dex2oat/patchoat. Be silent here and only
515 # log fatal events.
516 export ANDROID_LOG_TAGS='*:s'
517 else
518 # We are interested in LOG(ERROR) output.
519 export ANDROID_LOG_TAGS='*:e'
520 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100521
522 if [ "$USE_GDB" = "y" ]; then
523 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700524 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100525 else
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -0700526 if [ "$TIME_OUT" != "gdb" ]; then
527 trap 'kill -INT -$pid' INT
528 $cmdline "$@" 2>&1 & pid=$!
529 wait $pid
530 # Add extra detail if time out is enabled.
531 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
532 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
533 fi
534 else
535 # With a thread dump that uses gdb if a timeout.
536 trap 'kill -INT -$pid' INT
537 $cmdline "$@" 2>&1 & pid=$!
538 # Spawn a watcher process.
539 ( sleep $TIME_OUT_VALUE && \
540 echo "##### Thread dump using gdb on test timeout" && \
541 ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
542 --eval-command="call exit(124)" --eval-command=quit || \
543 kill $pid )) 2> /dev/null & watcher=$!
544 wait $pid
545 test_exit_status=$?
546 pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
547 if [ $test_exit_status = 0 ]; then
548 # The test finished normally.
549 exit 0
550 else
551 # The test failed or timed out.
552 if [ $test_exit_status = 124 ]; then
553 # The test timed out.
554 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
555 fi
556 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100557 fi
558 fi
559fi