blob: db64b77f6c6eb4977a1e8c3558549543a29a1648 [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=""
Brian Carlstrom93d6ce52014-11-04 22:31:35 -080040TIME_OUT="y"
Andreas Gampe038bb222015-01-13 19:48:14 -080041# Value in minutes.
Mathieu Chartier8dcde232015-01-15 17:23:16 -080042TIME_OUT_VALUE=10
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010043USE_GDB="n"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +010044USE_JVM="n"
Igor Murashkin7617abd2015-07-10 18:27:47 -070045VERIFY="y" # y=yes,n=no,s=softfail
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010046ZYGOTE=""
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -070047DEX_VERIFY=""
Andreas Gampe65357032015-02-19 15:10:24 -080048USE_DEX2OAT_AND_PATCHOAT="y"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010049
50while true; do
51 if [ "x$1" = "x--quiet" ]; then
52 QUIET="y"
53 shift
54 elif [ "x$1" = "x--lib" ]; then
55 shift
56 if [ "x$1" = "x" ]; then
57 echo "$0 missing argument to --lib" 1>&2
58 exit 1
59 fi
60 LIB="$1"
61 shift
62 elif [ "x$1" = "x-Xcompiler-option" ]; then
63 shift
64 option="$1"
65 FLAGS="${FLAGS} -Xcompiler-option $option"
66 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
67 shift
68 elif [ "x$1" = "x--runtime-option" ]; then
69 shift
70 option="$1"
71 FLAGS="${FLAGS} $option"
72 shift
73 elif [ "x$1" = "x--boot" ]; then
74 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000075 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010076 shift
77 elif [ "x$1" = "x--no-dex2oat" ]; then
78 DEX2OAT="-Xcompiler:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -080079 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010080 shift
81 elif [ "x$1" = "x--no-patchoat" ]; then
82 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
Andreas Gampe65357032015-02-19 15:10:24 -080083 USE_DEX2OAT_AND_PATCHOAT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010084 shift
85 elif [ "x$1" = "x--relocate" ]; then
86 RELOCATE="y"
87 shift
88 elif [ "x$1" = "x--no-relocate" ]; then
89 RELOCATE="n"
90 shift
91 elif [ "x$1" = "x--prebuild" ]; then
92 PREBUILD="y"
93 shift
94 elif [ "x$1" = "x--host" ]; then
95 HOST="y"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +000096 ANDROID_ROOT="$ANDROID_HOST_OUT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010097 shift
98 elif [ "x$1" = "x--no-prebuild" ]; then
99 PREBUILD="n"
100 shift
101 elif [ "x$1" = "x--no-image" ]; then
102 HAVE_IMAGE="n"
103 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700104 elif [ "x$1" = "x--secondary" ]; then
105 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
106 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100107 elif [ "x$1" = "x--debug" ]; then
108 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800109 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100110 shift
111 elif [ "x$1" = "x--gdb" ]; then
112 USE_GDB="y"
113 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800114 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100115 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700116 elif [ "x$1" = "x--gdb-arg" ]; then
117 shift
118 gdb_arg="$1"
119 GDB_ARGS="${GDB_ARGS} $gdb_arg"
120 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100121 elif [ "x$1" = "x--zygote" ]; then
122 ZYGOTE="-Xzygote"
123 msg "Spawning from zygote"
124 shift
125 elif [ "x$1" = "x--dev" ]; then
126 DEV_MODE="y"
127 shift
128 elif [ "x$1" = "x--interpreter" ]; then
129 INTERPRETER="y"
130 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800131 elif [ "x$1" = "x--jit" ]; then
132 JIT="y"
133 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100134 elif [ "x$1" = "x--jvm" ]; then
135 USE_JVM="y"
136 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100137 elif [ "x$1" = "x--invoke-with" ]; then
138 shift
139 if [ "x$1" = "x" ]; then
140 echo "$0 missing argument to --invoke-with" 1>&2
141 exit 1
142 fi
143 if [ "x$INVOKE_WITH" = "x" ]; then
144 INVOKE_WITH="$1"
145 else
146 INVOKE_WITH="$INVOKE_WITH $1"
147 fi
148 shift
149 elif [ "x$1" = "x--no-verify" ]; then
150 VERIFY="n"
151 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700152 elif [ "x$1" = "x--verify-soft-fail" ]; then
153 VERIFY="s"
154 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100155 elif [ "x$1" = "x--no-optimize" ]; then
156 OPTIMIZE="n"
157 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000158 elif [ "x$1" = "x--android-root" ]; then
159 shift
160 ANDROID_ROOT="$1"
161 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100162 elif [ "x$1" = "x--" ]; then
163 shift
164 break
165 elif [ "x$1" = "x--64" ]; then
166 ISA="x86_64"
167 GDB_SERVER="gdbserver64"
168 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000169 LIBRARY_DIRECTORY="lib64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100170 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
171 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700172 elif [ "x$1" = "x--pic-test" ]; then
173 FLAGS="${FLAGS} -Xcompiler-option --compile-pic"
174 COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic"
175 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100176 elif expr "x$1" : "x--" >/dev/null 2>&1; then
177 echo "unknown $0 option: $1" 1>&2
178 exit 1
179 else
180 break
181 fi
182done
183
184if [ "x$1" = "x" ] ; then
185 MAIN="Main"
186else
187 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700188 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100189fi
190
191if [ "$ZYGOTE" = "" ]; then
192 if [ "$OPTIMIZE" = "y" ]; then
193 if [ "$VERIFY" = "y" ]; then
194 DEX_OPTIMIZE="-Xdexopt:verified"
195 else
196 DEX_OPTIMIZE="-Xdexopt:all"
197 fi
198 msg "Performing optimizations"
199 else
200 DEX_OPTIMIZE="-Xdexopt:none"
201 msg "Skipping optimizations"
202 fi
203
204 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100205 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100206 msg "Performing verification"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700207 elif [ "$VERIFY" = "s" ]; then
208 JVM_VERIFY_ARG="Xverify:all"
209 DEX_VERIFY="-Xverify:softfail"
210 msg "Forcing verification to be soft fail"
211 else # VERIFY = "n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100212 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100213 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100214 msg "Skipping verification"
215 fi
216fi
217
218msg "------------------------------"
219
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100220if [ "$DEBUGGER" = "y" ]; then
221 # Use this instead for ddms and connect by running 'ddms':
222 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
223 # TODO: add a separate --ddms option?
224
225 PORT=12345
226 msg "Waiting for jdb to connect:"
227 if [ "$HOST" = "n" ]; then
228 msg " adb forward tcp:$PORT tcp:$PORT"
229 fi
230 msg " jdb -attach localhost:$PORT"
231 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
232fi
233
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100234if [ "$USE_JVM" = "y" ]; then
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700235 # Xmx is necessary since we don't pass down the ART flags to JVM.
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700236 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes ${FLAGS} $MAIN $@"
237 if [ "$DEV_MODE" = "y" ]; then
238 echo $cmdline
239 fi
240 $cmdline
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100241 exit
242fi
243
244
245if [ "$HAVE_IMAGE" = "n" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000246 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000247else
248 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100249fi
250
251
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100252if [ "$USE_GDB" = "y" ]; then
253 if [ "$HOST" = "n" ]; then
254 GDB="$GDB_SERVER :5039"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100255 else
256 if [ `uname` = "Darwin" ]; then
257 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700258 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100259 DALVIKVM=
260 else
261 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700262 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100263 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
264 # gdbargs="--annotate=3 $gdbargs"
265 fi
266 fi
267fi
268
269if [ "$INTERPRETER" = "y" ]; then
270 INT_OPTS="-Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700271 if [ "$VERIFY" = "y" ] ; then
272 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700273 elif [ "$VERIFY" = "s" ]; then
274 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
275 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
276 else # VERIFY = "n"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700277 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
278 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
279 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100280fi
281
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800282if [ "$JIT" = "y" ]; then
Sebastien Hertz155bef42015-03-09 14:57:48 +0100283 INT_OPTS="-Xusejit:true"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800284 if [ "$VERIFY" = "y" ] ; then
Mathieu Chartiere86deef2015-03-19 13:43:37 -0700285 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-at-runtime"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800286 else
287 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify-none"
288 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
289 fi
290fi
291
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100292JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
293
294if [ "$RELOCATE" = "y" ]; then
295 COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information --runtime-arg -Xnorelocate"
296 FLAGS="${FLAGS} -Xrelocate -Xcompiler-option --include-patch-information"
297 if [ "$HOST" = "y" ]; then
298 # Run test sets a fairly draconian ulimit that we will likely blow right over
299 # since we are relocating. Get the total size of the /system/framework directory
300 # in 512 byte blocks and set it as the ulimit. This should be more than enough
301 # room.
302 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
303 ulimit -S $(du -c -B512 ${ANDROID_HOST_OUT}/framework | tail -1 | cut -f1) || exit 1
304 fi
305 fi
306else
307 FLAGS="$FLAGS -Xnorelocate"
308 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
Mathieu Chartiercae2ed92015-06-09 13:02:50 -0700309 if [ "$HOST" = "y" ]; then
310 # Increase ulimit to 64MB in case we are running hprof test.
311 ulimit -S 64000 || exit 1
312 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100313fi
314
315if [ "$HOST" = "n" ]; then
316 ISA=$(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
317 if [ x"$ISA" = "x" ]; then
318 echo "Unable to determine architecture"
319 exit 1
320 fi
321fi
322
323dex2oat_cmdline="true"
324mkdir_cmdline="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
325
326if [ "$PREBUILD" = "y" ]; then
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000327 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100328 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000329 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100330 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
331 --oat-file=$DEX_LOCATION/dalvik-cache/$ISA/$(echo $DEX_LOCATION/$TEST_NAME.jar/classes.dex | cut -d/ -f 2- | sed "s:/:@:g") \
332 --instruction-set=$ISA"
333fi
334
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000335dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100336 $GDB_ARGS \
337 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700338 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100339 -XXlib:$LIB \
340 $PATCHOAT \
341 $DEX2OAT \
342 $ZYGOTE \
343 $JNI_OPTS \
344 $INT_OPTS \
345 $DEBUGGER_OPTS \
346 $DALVIKVM_BOOT_OPT \
Jeff Hao207a37d2014-10-29 17:24:25 -0700347 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100348
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -0800349# Remove whitespace.
350dex2oat_cmdline=$(echo $dex2oat_cmdline)
351dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100352
353if [ "$HOST" = "n" ]; then
354 adb root > /dev/null
355 adb wait-for-device
356 if [ "$QUIET" = "n" ]; then
357 adb shell rm -r $DEX_LOCATION
358 adb shell mkdir -p $DEX_LOCATION
359 adb push $TEST_NAME.jar $DEX_LOCATION
360 adb push $TEST_NAME-ex.jar $DEX_LOCATION
361 else
362 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
363 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
364 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
365 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
366 fi
367
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000368 LD_LIBRARY_PATH=
369 if [ "$ANDROID_ROOT" != "/system" ]; then
370 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
371 # so we can only use LD_LIBRARY_PATH when testing on a local
372 # installation.
373 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY
374 fi
375
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100376 # Create a script with the command. The command can get longer than the longest
377 # allowed adb command and there is no way to get the exit status from a adb shell
378 # command.
379 cmdline="cd $DEX_LOCATION && \
380 export ANDROID_DATA=$DEX_LOCATION && \
381 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000382 export ANDROID_ROOT=$ANDROID_ROOT && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100383 $mkdir_cmdline && \
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100384 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Nicolas Geoffray4f7fdd22015-04-24 11:57:37 +0100385 export PATH=$ANDROID_ROOT/bin:$PATH && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100386 $dex2oat_cmdline && \
387 $dalvikvm_cmdline"
388
389 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
390 echo "$cmdline" > $cmdfile
391
392 if [ "$DEV_MODE" = "y" ]; then
393 echo $cmdline
394 fi
395
396 if [ "$QUIET" = "n" ]; then
397 adb push $cmdfile $DEX_LOCATION/cmdline.sh
398 else
399 adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1
400 fi
401
402 adb shell sh $DEX_LOCATION/cmdline.sh
403
404 rm -f $cmdfile
405else
406 export ANDROID_PRINTF_LOG=brief
Andreas Gampea8780822015-03-13 19:51:09 -0700407
408 # By default, and for prebuild dex2oat, we are interested in errors being logged. In dev mode
409 # we want debug messages.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100410 if [ "$DEV_MODE" = "y" ]; then
411 export ANDROID_LOG_TAGS='*:d'
412 else
Andreas Gampee4301ff2015-02-17 19:25:29 -0800413 export ANDROID_LOG_TAGS='*:e'
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100414 fi
Andreas Gampea8780822015-03-13 19:51:09 -0700415
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100416 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +0000417 export ANDROID_ROOT="${ANDROID_ROOT}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100418 export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
419 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
420 export PATH="$PATH:${ANDROID_ROOT}/bin"
421
David Srbeckyc9ede382015-06-20 06:03:53 +0100422 # Temporarily disable address space layout randomization (ASLR).
423 # This is needed on the host so that the linker loads core.oat at the necessary address.
424 export LD_USE_LOAD_BIAS=1
425
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100426 cmdline="$dalvikvm_cmdline"
427
428 if [ "$TIME_OUT" = "y" ]; then
429 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -0800430 #
431 # Note: We use nested timeouts. The inner timeout sends SIGRTMIN+2 (usually 36) to ART, which
432 # will induce a full thread dump before abort. However, dumping threads might deadlock,
433 # so the outer timeout sends the regular SIGTERM after an additional minute to ensure
434 # termination (without dumping all threads).
435 TIME_PLUS_ONE=$(($TIME_OUT_VALUE + 1))
436 cmdline="timeout ${TIME_PLUS_ONE}m timeout -s SIGRTMIN+2 ${TIME_OUT_VALUE}m $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100437 fi
438
439 if [ "$DEV_MODE" = "y" ]; then
440 if [ "$PREBUILD" = "y" ]; then
441 echo "$mkdir_cmdline && $dex2oat_cmdline && $cmdline"
442 elif [ "$RELOCATE" = "y" ]; then
443 echo "$mkdir_cmdline && $cmdline"
444 else
445 echo $cmdline
446 fi
447 fi
448
449 cd $ANDROID_BUILD_TOP
450
451 $mkdir_cmdline || exit 1
Andreas Gampea8780822015-03-13 19:51:09 -0700452 $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
453
454 # For running, we must turn off logging when dex2oat or patchoat are missing. Otherwise we use
455 # the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
456 if [ "$DEV_MODE" = "y" ]; then
457 export ANDROID_LOG_TAGS='*:d'
458 elif [ "$USE_DEX2OAT_AND_PATCHOAT" = "n" ]; then
459 # All tests would log the error of failing dex2oat/patchoat. Be silent here and only
460 # log fatal events.
461 export ANDROID_LOG_TAGS='*:s'
462 else
463 # We are interested in LOG(ERROR) output.
464 export ANDROID_LOG_TAGS='*:e'
465 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100466
467 if [ "$USE_GDB" = "y" ]; then
468 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -0700469 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100470 else
Mathieu Chartier38ba3fe2015-07-08 14:03:02 -0700471 trap 'kill -INT -$pid' INT
472 $cmdline "$@" 2>&1 & pid=$!
473 wait $pid
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100474 # Add extra detail if time out is enabled.
475 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "y" ]; then
476 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
477 fi
478 fi
479fi