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