Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Runner for an individual run-test. |
| 4 | |
| 5 | msg() { |
| 6 | if [ "$QUIET" = "n" ]; then |
| 7 | echo "$@" |
| 8 | fi |
| 9 | } |
| 10 | |
Nicolas Geoffray | c8f23fc | 2014-10-28 17:59:47 +0000 | [diff] [blame^] | 11 | ANDROID_ROOT="/system" |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 12 | ARCHITECTURES_32="(arm|x86|mips|none)" |
| 13 | ARCHITECTURES_64="(arm64|x86_64|none)" |
| 14 | ARCHITECTURES_PATTERN="${ARCHITECTURES_32}" |
Nicolas Geoffray | c8f23fc | 2014-10-28 17:59:47 +0000 | [diff] [blame^] | 15 | BOOT_IMAGE="" |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 16 | COMPILE_FLAGS="" |
| 17 | DALVIKVM="dalvikvm32" |
| 18 | DEBUGGER="n" |
| 19 | DEV_MODE="n" |
| 20 | DEX2OAT="" |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 21 | FALSE_BIN="/system/bin/false" |
| 22 | FLAGS="" |
| 23 | GDB="" |
Nicolas Geoffray | baf9102 | 2014-10-08 09:56:45 +0100 | [diff] [blame] | 24 | GDB_ARGS="" |
| 25 | GDB_SERVER="gdbserver" |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 26 | HAVE_IMAGE="y" |
| 27 | HOST="n" |
| 28 | INTERPRETER="n" |
| 29 | INVOKE_WITH="" |
| 30 | ISA=x86 |
Nicolas Geoffray | c8f23fc | 2014-10-28 17:59:47 +0000 | [diff] [blame^] | 31 | LIBRARY_DIRECTORY="lib" |
| 32 | MAIN="" |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 33 | OPTIMIZE="y" |
| 34 | PATCHOAT="" |
| 35 | PREBUILD="y" |
| 36 | QUIET="n" |
| 37 | RELOCATE="y" |
| 38 | USE_GDB="n" |
Nicolas Geoffray | 288a4a2 | 2014-10-07 11:02:40 +0100 | [diff] [blame] | 39 | USE_JVM="n" |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 40 | VERIFY="y" |
| 41 | ZYGOTE="" |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 42 | |
| 43 | while true; do |
| 44 | if [ "x$1" = "x--quiet" ]; then |
| 45 | QUIET="y" |
| 46 | shift |
| 47 | elif [ "x$1" = "x--lib" ]; then |
| 48 | shift |
| 49 | if [ "x$1" = "x" ]; then |
| 50 | echo "$0 missing argument to --lib" 1>&2 |
| 51 | exit 1 |
| 52 | fi |
| 53 | LIB="$1" |
| 54 | shift |
| 55 | elif [ "x$1" = "x-Xcompiler-option" ]; then |
| 56 | shift |
| 57 | option="$1" |
| 58 | FLAGS="${FLAGS} -Xcompiler-option $option" |
| 59 | COMPILE_FLAGS="${COMPILE_FLAGS} $option" |
| 60 | shift |
| 61 | elif [ "x$1" = "x--runtime-option" ]; then |
| 62 | shift |
| 63 | option="$1" |
| 64 | FLAGS="${FLAGS} $option" |
| 65 | shift |
| 66 | elif [ "x$1" = "x--boot" ]; then |
| 67 | shift |
Nicolas Geoffray | c8f23fc | 2014-10-28 17:59:47 +0000 | [diff] [blame^] | 68 | BOOT_IMAGE="$1" |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 69 | shift |
| 70 | elif [ "x$1" = "x--no-dex2oat" ]; then |
| 71 | DEX2OAT="-Xcompiler:${FALSE_BIN}" |
| 72 | shift |
| 73 | elif [ "x$1" = "x--no-patchoat" ]; then |
| 74 | PATCHOAT="-Xpatchoat:${FALSE_BIN}" |
| 75 | shift |
| 76 | elif [ "x$1" = "x--relocate" ]; then |
| 77 | RELOCATE="y" |
| 78 | shift |
| 79 | elif [ "x$1" = "x--no-relocate" ]; then |
| 80 | RELOCATE="n" |
| 81 | shift |
| 82 | elif [ "x$1" = "x--prebuild" ]; then |
| 83 | PREBUILD="y" |
| 84 | shift |
| 85 | elif [ "x$1" = "x--host" ]; then |
| 86 | HOST="y" |
| 87 | shift |
| 88 | elif [ "x$1" = "x--no-prebuild" ]; then |
| 89 | PREBUILD="n" |
| 90 | shift |
| 91 | elif [ "x$1" = "x--no-image" ]; then |
| 92 | HAVE_IMAGE="n" |
| 93 | shift |
| 94 | elif [ "x$1" = "x--debug" ]; then |
| 95 | DEBUGGER="y" |
| 96 | shift |
| 97 | elif [ "x$1" = "x--gdb" ]; then |
| 98 | USE_GDB="y" |
| 99 | DEV_MODE="y" |
| 100 | shift |
| 101 | elif [ "x$1" = "x--zygote" ]; then |
| 102 | ZYGOTE="-Xzygote" |
| 103 | msg "Spawning from zygote" |
| 104 | shift |
| 105 | elif [ "x$1" = "x--dev" ]; then |
| 106 | DEV_MODE="y" |
| 107 | shift |
| 108 | elif [ "x$1" = "x--interpreter" ]; then |
| 109 | INTERPRETER="y" |
| 110 | shift |
Nicolas Geoffray | 288a4a2 | 2014-10-07 11:02:40 +0100 | [diff] [blame] | 111 | elif [ "x$1" = "x--jvm" ]; then |
| 112 | USE_JVM="y" |
| 113 | shift |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 114 | elif [ "x$1" = "x--invoke-with" ]; then |
| 115 | shift |
| 116 | if [ "x$1" = "x" ]; then |
| 117 | echo "$0 missing argument to --invoke-with" 1>&2 |
| 118 | exit 1 |
| 119 | fi |
| 120 | if [ "x$INVOKE_WITH" = "x" ]; then |
| 121 | INVOKE_WITH="$1" |
| 122 | else |
| 123 | INVOKE_WITH="$INVOKE_WITH $1" |
| 124 | fi |
| 125 | shift |
| 126 | elif [ "x$1" = "x--no-verify" ]; then |
| 127 | VERIFY="n" |
| 128 | shift |
| 129 | elif [ "x$1" = "x--no-optimize" ]; then |
| 130 | OPTIMIZE="n" |
| 131 | shift |
Nicolas Geoffray | c8f23fc | 2014-10-28 17:59:47 +0000 | [diff] [blame^] | 132 | elif [ "x$1" = "x--android-root" ]; then |
| 133 | shift |
| 134 | ANDROID_ROOT="$1" |
| 135 | shift |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 136 | elif [ "x$1" = "x--" ]; then |
| 137 | shift |
| 138 | break |
| 139 | elif [ "x$1" = "x--64" ]; then |
| 140 | ISA="x86_64" |
| 141 | GDB_SERVER="gdbserver64" |
| 142 | DALVIKVM="dalvikvm64" |
Nicolas Geoffray | c8f23fc | 2014-10-28 17:59:47 +0000 | [diff] [blame^] | 143 | LIBRARY_DIRECTORY="lib64" |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 144 | ARCHITECTURES_PATTERN="${ARCHITECTURES_64}" |
| 145 | shift |
Andreas Gampe | c23c9c9 | 2014-10-28 14:47:25 -0700 | [diff] [blame] | 146 | elif [ "x$1" = "x--pic-test" ]; then |
| 147 | FLAGS="${FLAGS} -Xcompiler-option --compile-pic" |
| 148 | COMPILE_FLAGS="${COMPILE_FLAGS} --compile-pic" |
| 149 | shift |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 150 | elif expr "x$1" : "x--" >/dev/null 2>&1; then |
| 151 | echo "unknown $0 option: $1" 1>&2 |
| 152 | exit 1 |
| 153 | else |
| 154 | break |
| 155 | fi |
| 156 | done |
| 157 | |
| 158 | if [ "x$1" = "x" ] ; then |
| 159 | MAIN="Main" |
| 160 | else |
| 161 | MAIN="$1" |
| 162 | fi |
| 163 | |
| 164 | if [ "$ZYGOTE" = "" ]; then |
| 165 | if [ "$OPTIMIZE" = "y" ]; then |
| 166 | if [ "$VERIFY" = "y" ]; then |
| 167 | DEX_OPTIMIZE="-Xdexopt:verified" |
| 168 | else |
| 169 | DEX_OPTIMIZE="-Xdexopt:all" |
| 170 | fi |
| 171 | msg "Performing optimizations" |
| 172 | else |
| 173 | DEX_OPTIMIZE="-Xdexopt:none" |
| 174 | msg "Skipping optimizations" |
| 175 | fi |
| 176 | |
| 177 | if [ "$VERIFY" = "y" ]; then |
| 178 | DEX_VERIFY="" |
Nicolas Geoffray | 288a4a2 | 2014-10-07 11:02:40 +0100 | [diff] [blame] | 179 | JVM_VERIFY_ARG="-Xverify:all" |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 180 | msg "Performing verification" |
| 181 | else |
| 182 | DEX_VERIFY="-Xverify:none" |
Nicolas Geoffray | 288a4a2 | 2014-10-07 11:02:40 +0100 | [diff] [blame] | 183 | JVM_VERIFY_ARG="-Xverify:none" |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 184 | msg "Skipping verification" |
| 185 | fi |
| 186 | fi |
| 187 | |
| 188 | msg "------------------------------" |
| 189 | |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 190 | if [ "$DEBUGGER" = "y" ]; then |
| 191 | # Use this instead for ddms and connect by running 'ddms': |
| 192 | # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y" |
| 193 | # TODO: add a separate --ddms option? |
| 194 | |
| 195 | PORT=12345 |
| 196 | msg "Waiting for jdb to connect:" |
| 197 | if [ "$HOST" = "n" ]; then |
| 198 | msg " adb forward tcp:$PORT tcp:$PORT" |
| 199 | fi |
| 200 | msg " jdb -attach localhost:$PORT" |
| 201 | DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y" |
| 202 | fi |
| 203 | |
Nicolas Geoffray | 288a4a2 | 2014-10-07 11:02:40 +0100 | [diff] [blame] | 204 | if [ "$USE_JVM" = "y" ]; then |
| 205 | ${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -classpath classes $MAIN "$@" |
| 206 | exit |
| 207 | fi |
| 208 | |
| 209 | |
| 210 | if [ "$HAVE_IMAGE" = "n" ]; then |
Nicolas Geoffray | c8f23fc | 2014-10-28 17:59:47 +0000 | [diff] [blame^] | 211 | DALVIKVM_BOOT_OPT="-Ximage:/system/non-existant/core.art" |
| 212 | DEX2OAT_BOOT_OPT="--boot-image=/system/non-existant/core.art" |
| 213 | else |
| 214 | DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}" |
| 215 | DEX2OAT_BOOT_OPT="--boot-image=${BOOT_IMAGE}" |
Nicolas Geoffray | 288a4a2 | 2014-10-07 11:02:40 +0100 | [diff] [blame] | 216 | fi |
| 217 | |
| 218 | |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 219 | if [ "$USE_GDB" = "y" ]; then |
| 220 | if [ "$HOST" = "n" ]; then |
| 221 | GDB="$GDB_SERVER :5039" |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 222 | else |
| 223 | if [ `uname` = "Darwin" ]; then |
| 224 | GDB=lldb |
| 225 | GDB_ARGS="-- $DALVIKVM" |
| 226 | DALVIKVM= |
| 227 | else |
| 228 | GDB=gdb |
| 229 | GDB_ARGS="--args $DALVIKVM" |
| 230 | # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line. |
| 231 | # gdbargs="--annotate=3 $gdbargs" |
| 232 | fi |
| 233 | fi |
| 234 | fi |
| 235 | |
| 236 | if [ "$INTERPRETER" = "y" ]; then |
| 237 | INT_OPTS="-Xint" |
| 238 | COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only" |
| 239 | fi |
| 240 | |
| 241 | JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni" |
| 242 | |
| 243 | if [ "$RELOCATE" = "y" ]; then |
| 244 | COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information --runtime-arg -Xnorelocate" |
| 245 | FLAGS="${FLAGS} -Xrelocate -Xcompiler-option --include-patch-information" |
| 246 | if [ "$HOST" = "y" ]; then |
| 247 | # Run test sets a fairly draconian ulimit that we will likely blow right over |
| 248 | # since we are relocating. Get the total size of the /system/framework directory |
| 249 | # in 512 byte blocks and set it as the ulimit. This should be more than enough |
| 250 | # room. |
| 251 | if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..." |
| 252 | ulimit -S $(du -c -B512 ${ANDROID_HOST_OUT}/framework | tail -1 | cut -f1) || exit 1 |
| 253 | fi |
| 254 | fi |
| 255 | else |
| 256 | FLAGS="$FLAGS -Xnorelocate" |
| 257 | COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate" |
| 258 | fi |
| 259 | |
| 260 | if [ "$HOST" = "n" ]; then |
| 261 | ISA=$(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}") |
| 262 | if [ x"$ISA" = "x" ]; then |
| 263 | echo "Unable to determine architecture" |
| 264 | exit 1 |
| 265 | fi |
| 266 | fi |
| 267 | |
| 268 | dex2oat_cmdline="true" |
| 269 | mkdir_cmdline="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA" |
| 270 | |
| 271 | if [ "$PREBUILD" = "y" ]; then |
Nicolas Geoffray | c8f23fc | 2014-10-28 17:59:47 +0000 | [diff] [blame^] | 272 | dex2oat_cmdline="$INVOKE_WITH $ANDROID_ROOT/bin/dex2oatd \ |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 273 | $COMPILE_FLAGS \ |
| 274 | $DEX2OAT_BOOT_OPT \ |
| 275 | --dex-file=$DEX_LOCATION/$TEST_NAME.jar \ |
| 276 | --oat-file=$DEX_LOCATION/dalvik-cache/$ISA/$(echo $DEX_LOCATION/$TEST_NAME.jar/classes.dex | cut -d/ -f 2- | sed "s:/:@:g") \ |
| 277 | --instruction-set=$ISA" |
| 278 | fi |
| 279 | |
Nicolas Geoffray | c8f23fc | 2014-10-28 17:59:47 +0000 | [diff] [blame^] | 280 | dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ROOT/bin/$DALVIKVM \ |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 281 | $GDB_ARGS \ |
| 282 | $FLAGS \ |
| 283 | -XXlib:$LIB \ |
| 284 | $PATCHOAT \ |
| 285 | $DEX2OAT \ |
| 286 | $ZYGOTE \ |
| 287 | $JNI_OPTS \ |
| 288 | $INT_OPTS \ |
| 289 | $DEBUGGER_OPTS \ |
| 290 | $DALVIKVM_BOOT_OPT \ |
| 291 | -cp $DEX_LOCATION/$TEST_NAME.jar $MAIN" |
| 292 | |
| 293 | |
| 294 | if [ "$HOST" = "n" ]; then |
| 295 | adb root > /dev/null |
| 296 | adb wait-for-device |
| 297 | if [ "$QUIET" = "n" ]; then |
| 298 | adb shell rm -r $DEX_LOCATION |
| 299 | adb shell mkdir -p $DEX_LOCATION |
| 300 | adb push $TEST_NAME.jar $DEX_LOCATION |
| 301 | adb push $TEST_NAME-ex.jar $DEX_LOCATION |
| 302 | else |
| 303 | adb shell rm -r $DEX_LOCATION >/dev/null 2>&1 |
| 304 | adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1 |
| 305 | adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1 |
| 306 | adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1 |
| 307 | fi |
| 308 | |
| 309 | # Create a script with the command. The command can get longer than the longest |
| 310 | # allowed adb command and there is no way to get the exit status from a adb shell |
| 311 | # command. |
| 312 | cmdline="cd $DEX_LOCATION && \ |
| 313 | export ANDROID_DATA=$DEX_LOCATION && \ |
| 314 | export DEX_LOCATION=$DEX_LOCATION && \ |
Nicolas Geoffray | c8f23fc | 2014-10-28 17:59:47 +0000 | [diff] [blame^] | 315 | export ANDROID_ROOT=$ANDROID_ROOT && \ |
| 316 | export LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBRARY_DIRECTORY && \ |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 317 | $mkdir_cmdline && \ |
| 318 | $dex2oat_cmdline && \ |
| 319 | $dalvikvm_cmdline" |
| 320 | |
| 321 | cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME") |
| 322 | echo "$cmdline" > $cmdfile |
| 323 | |
| 324 | if [ "$DEV_MODE" = "y" ]; then |
| 325 | echo $cmdline |
| 326 | fi |
| 327 | |
| 328 | if [ "$QUIET" = "n" ]; then |
| 329 | adb push $cmdfile $DEX_LOCATION/cmdline.sh |
| 330 | else |
| 331 | adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1 |
| 332 | fi |
| 333 | |
| 334 | adb shell sh $DEX_LOCATION/cmdline.sh |
| 335 | |
| 336 | rm -f $cmdfile |
| 337 | else |
| 338 | export ANDROID_PRINTF_LOG=brief |
| 339 | if [ "$DEV_MODE" = "y" ]; then |
| 340 | export ANDROID_LOG_TAGS='*:d' |
| 341 | else |
| 342 | export ANDROID_LOG_TAGS='*:s' |
| 343 | fi |
| 344 | export ANDROID_DATA="$DEX_LOCATION" |
| 345 | export ANDROID_ROOT="${ANDROID_HOST_OUT}" |
| 346 | export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib" |
| 347 | export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib" |
| 348 | export PATH="$PATH:${ANDROID_ROOT}/bin" |
| 349 | |
| 350 | cmdline="$dalvikvm_cmdline" |
| 351 | |
| 352 | if [ "$TIME_OUT" = "y" ]; then |
| 353 | # Add timeout command if time out is desired. |
| 354 | cmdline="timeout $TIME_OUT_VALUE $cmdline" |
| 355 | fi |
| 356 | |
| 357 | if [ "$DEV_MODE" = "y" ]; then |
| 358 | if [ "$PREBUILD" = "y" ]; then |
| 359 | echo "$mkdir_cmdline && $dex2oat_cmdline && $cmdline" |
| 360 | elif [ "$RELOCATE" = "y" ]; then |
| 361 | echo "$mkdir_cmdline && $cmdline" |
| 362 | else |
| 363 | echo $cmdline |
| 364 | fi |
| 365 | fi |
| 366 | |
| 367 | cd $ANDROID_BUILD_TOP |
| 368 | |
| 369 | $mkdir_cmdline || exit 1 |
| 370 | $dex2oat_cmdline || exit 2 |
| 371 | |
| 372 | if [ "$USE_GDB" = "y" ]; then |
| 373 | # When running under gdb, we cannot do piping and grepping... |
Dmitriy Ivanov | f57874d | 2014-10-07 13:43:23 -0700 | [diff] [blame] | 374 | $cmdline "$@" |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 375 | else |
Dmitriy Ivanov | f57874d | 2014-10-07 13:43:23 -0700 | [diff] [blame] | 376 | $cmdline "$@" 2>&1 |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 377 | # Add extra detail if time out is enabled. |
| 378 | if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "y" ]; then |
| 379 | echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2 |
| 380 | fi |
| 381 | fi |
| 382 | fi |