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