Home | History | Annotate | Download | only in etc
      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 ANDROID_ROOT="/system"
     12 ANDROID_RUNTIME_ROOT="/apex/com.android.runtime"
     13 ANDROID_TZDATA_ROOT="/apex/com.android.tzdata"
     14 ARCHITECTURES_32="(arm|x86|mips|none)"
     15 ARCHITECTURES_64="(arm64|x86_64|mips64|none)"
     16 ARCHITECTURES_PATTERN="${ARCHITECTURES_32}"
     17 BOOT_IMAGE=""
     18 CHROOT=
     19 COMPILE_FLAGS=""
     20 DALVIKVM="dalvikvm32"
     21 DEBUGGER="n"
     22 WITH_AGENT=()
     23 DEBUGGER_AGENT=""
     24 WRAP_DEBUGGER_AGENT="n"
     25 DEV_MODE="n"
     26 DEX2OAT_NDEBUG_BINARY="dex2oat"
     27 DEX2OAT_DEBUG_BINARY="dex2oatd"
     28 EXPERIMENTAL=""
     29 FALSE_BIN="false"
     30 FLAGS=""
     31 ANDROID_FLAGS=""
     32 GDB=""
     33 GDB_ARGS=""
     34 GDBSERVER_DEVICE="gdbserver"
     35 GDBSERVER_HOST="gdbserver"
     36 HAVE_IMAGE="y"
     37 HOST="n"
     38 BIONIC="n"
     39 CREATE_ANDROID_ROOT="n"
     40 USE_ZIPAPEX="n"
     41 ZIPAPEX_LOC=""
     42 USE_EXTRACTED_ZIPAPEX="n"
     43 EXTRACTED_ZIPAPEX_LOC=""
     44 INTERPRETER="n"
     45 JIT="n"
     46 INVOKE_WITH=""
     47 IS_JVMTI_TEST="n"
     48 ISA=x86
     49 LIBRARY_DIRECTORY="lib"
     50 TEST_DIRECTORY="nativetest"
     51 MAIN=""
     52 OPTIMIZE="y"
     53 PREBUILD="y"
     54 QUIET="n"
     55 RELOCATE="n"
     56 STRIP_DEX="n"
     57 SECONDARY_DEX=""
     58 TIME_OUT="gdb"  # "n" (disabled), "timeout" (use timeout), "gdb" (use gdb)
     59 TIMEOUT_DUMPER=timeout_dumper
     60 # Value in seconds
     61 if [ "$ART_USE_READ_BARRIER" != "false" ]; then
     62   TIME_OUT_VALUE=2400  # 40 minutes.
     63 else
     64   TIME_OUT_VALUE=1200  # 20 minutes.
     65 fi
     66 USE_GDB="n"
     67 USE_GDBSERVER="n"
     68 GDBSERVER_PORT=":5039"
     69 USE_JVM="n"
     70 USE_JVMTI="n"
     71 VERIFY="y" # y=yes,n=no,s=softfail
     72 ZYGOTE=""
     73 DEX_VERIFY=""
     74 INSTRUCTION_SET_FEATURES=""
     75 ARGS=""
     76 VDEX_ARGS=""
     77 EXTERNAL_LOG_TAGS="n" # if y respect externally set ANDROID_LOG_TAGS.
     78 DRY_RUN="n" # if y prepare to run the test but don't run it.
     79 TEST_VDEX="n"
     80 TEST_DM="n"
     81 TEST_IS_NDEBUG="n"
     82 APP_IMAGE="y"
     83 JVMTI_STRESS="n"
     84 JVMTI_STEP_STRESS="n"
     85 JVMTI_FIELD_STRESS="n"
     86 JVMTI_TRACE_STRESS="n"
     87 JVMTI_REDEFINE_STRESS="n"
     88 PROFILE="n"
     89 RANDOM_PROFILE="n"
     90 # The normal dex2oat timeout.
     91 DEX2OAT_TIMEOUT="300" # 5 mins
     92 # The *hard* timeout where we really start trying to kill the dex2oat.
     93 DEX2OAT_RT_TIMEOUT="360" # 6 mins
     94 
     95 # if "y", run 'sync' before dalvikvm to make sure all files from
     96 # build step (e.g. dex2oat) were finished writing.
     97 SYNC_BEFORE_RUN="n"
     98 
     99 # When running a debug build, we want to run with all checks.
    100 ANDROID_FLAGS="${ANDROID_FLAGS} -XX:SlowDebug=true"
    101 # The same for dex2oatd, both prebuild and runtime-driven.
    102 ANDROID_FLAGS="${ANDROID_FLAGS} -Xcompiler-option --runtime-arg -Xcompiler-option -XX:SlowDebug=true"
    103 COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -XX:SlowDebug=true"
    104 
    105 while true; do
    106     if [ "x$1" = "x--quiet" ]; then
    107         QUIET="y"
    108         shift
    109     elif [ "x$1" = "x--dex2oat-rt-timeout" ]; then
    110         shift
    111         if [ "x$1" = "x" ]; then
    112             echo "$0 missing argument to --dex2oat-rt-timeout" 1>&2
    113             exit 1
    114         fi
    115         DEX2OAT_RT_TIMEOUT="$1"
    116         shift
    117     elif [ "x$1" = "x--dex2oat-timeout" ]; then
    118         shift
    119         if [ "x$1" = "x" ]; then
    120             echo "$0 missing argument to --dex2oat-timeout" 1>&2
    121             exit 1
    122         fi
    123         DEX2OAT_TIMEOUT="$1"
    124         shift
    125     elif [ "x$1" = "x--jvmti" ]; then
    126         USE_JVMTI="y"
    127         IS_JVMTI_TEST="y"
    128         shift
    129     elif [ "x$1" = "x-O" ]; then
    130         TEST_IS_NDEBUG="y"
    131         shift
    132     elif [ "x$1" = "x--lib" ]; then
    133         shift
    134         if [ "x$1" = "x" ]; then
    135             echo "$0 missing argument to --lib" 1>&2
    136             exit 1
    137         fi
    138         LIB="$1"
    139         shift
    140     elif [ "x$1" = "x--gc-stress" ]; then
    141         # Give an extra 5 mins if we are gc-stress.
    142         TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + 300))
    143         shift
    144     elif [ "x$1" = "x--testlib" ]; then
    145         shift
    146         if [ "x$1" = "x" ]; then
    147             echo "$0 missing argument to --testlib" 1>&2
    148             exit 1
    149         fi
    150         ARGS="${ARGS} $1"
    151         shift
    152     elif [ "x$1" = "x--args" ]; then
    153         shift
    154         if [ "x$1" = "x" ]; then
    155             echo "$0 missing argument to --args" 1>&2
    156             exit 1
    157         fi
    158         ARGS="${ARGS} $1"
    159         shift
    160     elif [ "x$1" = "x-Xcompiler-option" ]; then
    161         shift
    162         option="$1"
    163         FLAGS="${FLAGS} -Xcompiler-option $option"
    164         COMPILE_FLAGS="${COMPILE_FLAGS} $option"
    165         shift
    166     elif [ "x$1" = "x--android-runtime-option" ]; then
    167         shift
    168         option="$1"
    169         ANDROID_FLAGS="${ANDROID_FLAGS} $option"
    170         shift
    171     elif [ "x$1" = "x--runtime-option" ]; then
    172         shift
    173         option="$1"
    174         FLAGS="${FLAGS} $option"
    175         shift
    176     elif [ "x$1" = "x--boot" ]; then
    177         shift
    178         BOOT_IMAGE="$1"
    179         shift
    180     elif [ "x$1" = "x--relocate" ]; then
    181         RELOCATE="y"
    182         shift
    183     elif [ "x$1" = "x--no-relocate" ]; then
    184         RELOCATE="n"
    185         shift
    186     elif [ "x$1" = "x--prebuild" ]; then
    187         PREBUILD="y"
    188         shift
    189     elif [ "x$1" = "x--compact-dex-level" ]; then
    190         shift
    191         COMPILE_FLAGS="${COMPILE_FLAGS} --compact-dex-level=$1"
    192         shift
    193     elif [ "x$1" = "x--jvmti-redefine-stress" ]; then
    194         # APP_IMAGE doesn't really work with jvmti redefine stress
    195         USE_JVMTI="y"
    196         APP_IMAGE="n"
    197         JVMTI_STRESS="y"
    198         JVMTI_REDEFINE_STRESS="y"
    199         shift
    200     elif [ "x$1" = "x--jvmti-step-stress" ]; then
    201         USE_JVMTI="y"
    202         JVMTI_STRESS="y"
    203         JVMTI_STEP_STRESS="y"
    204         shift
    205     elif [ "x$1" = "x--jvmti-field-stress" ]; then
    206         USE_JVMTI="y"
    207         JVMTI_STRESS="y"
    208         JVMTI_FIELD_STRESS="y"
    209         shift
    210     elif [ "x$1" = "x--jvmti-trace-stress" ]; then
    211         USE_JVMTI="y"
    212         JVMTI_STRESS="y"
    213         JVMTI_TRACE_STRESS="y"
    214         shift
    215     elif [ "x$1" = "x--no-app-image" ]; then
    216         APP_IMAGE="n"
    217         shift
    218     elif [ "x$1" = "x--strip-dex" ]; then
    219         STRIP_DEX="y"
    220         shift
    221     elif [ "x$1" = "x--host" ]; then
    222         HOST="y"
    223         ANDROID_ROOT="${ANDROID_HOST_OUT}"
    224         ANDROID_RUNTIME_ROOT="${ANDROID_HOST_OUT}/com.android.runtime"
    225         ANDROID_TZDATA_ROOT="${ANDROID_HOST_OUT}/com.android.tzdata"
    226         shift
    227     elif [ "x$1" = "x--bionic" ]; then
    228         BIONIC="y"
    229         # We need to create an ANDROID_ROOT because currently we cannot create
    230         # the frameworks/libcore with linux_bionic so we need to use the normal
    231         # host ones which are in a different location.
    232         CREATE_ANDROID_ROOT="y"
    233         shift
    234     elif [ "x$1" = "x--runtime-extracted-zipapex" ]; then
    235         shift
    236         USE_EXTRACTED_ZIPAPEX="y"
    237         EXTRACTED_ZIPAPEX_LOC="$1"
    238         shift
    239     elif [ "x$1" = "x--runtime-zipapex" ]; then
    240         shift
    241         USE_ZIPAPEX="y"
    242         ZIPAPEX_LOC="$1"
    243         # TODO (b/119942078): Currently apex does not support
    244         # symlink_preferred_arch so we will not have a dex2oatd to execute and
    245         # need to manually provide
    246         # dex2oatd64.
    247         DEX2OAT_DEBUG_BINARY="dex2oatd64"
    248         shift
    249     elif [ "x$1" = "x--no-prebuild" ]; then
    250         PREBUILD="n"
    251         shift
    252     elif [ "x$1" = "x--no-image" ]; then
    253         HAVE_IMAGE="n"
    254         shift
    255     elif [ "x$1" = "x--secondary" ]; then
    256         SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
    257         # Enable cfg-append to make sure we get the dump for both dex files.
    258         # (otherwise the runtime compilation of the secondary dex will overwrite
    259         # the dump of the first one).
    260         FLAGS="${FLAGS} -Xcompiler-option --dump-cfg-append"
    261         COMPILE_FLAGS="${COMPILE_FLAGS} --dump-cfg-append"
    262         shift
    263     elif [ "x$1" = "x--with-agent" ]; then
    264         shift
    265         USE_JVMTI="y"
    266         WITH_AGENT+=("$1")
    267         shift
    268     elif [ "x$1" = "x--debug-wrap-agent" ]; then
    269         WRAP_DEBUGGER_AGENT="y"
    270         shift
    271     elif [ "x$1" = "x--debug-agent" ]; then
    272         shift
    273         DEBUGGER="agent"
    274         USE_JVMTI="y"
    275         DEBUGGER_AGENT="$1"
    276         TIME_OUT="n"
    277         shift
    278     elif [ "x$1" = "x--debug" ]; then
    279         DEBUGGER="y"
    280         TIME_OUT="n"
    281         shift
    282     elif [ "x$1" = "x--gdbserver-port" ]; then
    283         shift
    284         GDBSERVER_PORT=$1
    285         shift
    286     elif [ "x$1" = "x--gdbserver-bin" ]; then
    287         shift
    288         GDBSERVER_HOST=$1
    289         GDBSERVER_DEVICE=$1
    290         shift
    291     elif [ "x$1" = "x--gdbserver" ]; then
    292         USE_GDBSERVER="y"
    293         DEV_MODE="y"
    294         TIME_OUT="n"
    295         HOST="y"
    296         ANDROID_ROOT="${ANDROID_HOST_OUT}"
    297         ANDROID_RUNTIME_ROOT="${ANDROID_HOST_OUT}/com.android.runtime"
    298         ANDROID_TZDATA_ROOT="${ANDROID_HOST_OUT}/com.android.tzdata"
    299         shift
    300     elif [ "x$1" = "x--gdb" ]; then
    301         USE_GDB="y"
    302         DEV_MODE="y"
    303         TIME_OUT="n"
    304         shift
    305     elif [ "x$1" = "x--gdb-arg" ]; then
    306         shift
    307         gdb_arg="$1"
    308         GDB_ARGS="${GDB_ARGS} $gdb_arg"
    309         shift
    310     elif [ "x$1" = "x--zygote" ]; then
    311         ZYGOTE="-Xzygote"
    312         msg "Spawning from zygote"
    313         shift
    314     elif [ "x$1" = "x--dev" ]; then
    315         DEV_MODE="y"
    316         shift
    317     elif [ "x$1" = "x--interpreter" ]; then
    318         INTERPRETER="y"
    319         shift
    320     elif [ "x$1" = "x--jit" ]; then
    321         JIT="y"
    322         shift
    323     elif [ "x$1" = "x--baseline" ]; then
    324         FLAGS="${FLAGS} -Xcompiler-option --baseline"
    325         COMPILE_FLAGS="${COMPILE_FLAGS} --baseline"
    326         shift
    327     elif [ "x$1" = "x--jvm" ]; then
    328         USE_JVM="y"
    329         shift
    330     elif [ "x$1" = "x--invoke-with" ]; then
    331         shift
    332         if [ "x$1" = "x" ]; then
    333             echo "$0 missing argument to --invoke-with" 1>&2
    334             exit 1
    335         fi
    336         if [ "x$INVOKE_WITH" = "x" ]; then
    337             INVOKE_WITH="$1"
    338         else
    339             INVOKE_WITH="$INVOKE_WITH $1"
    340         fi
    341         shift
    342     elif [ "x$1" = "x--no-verify" ]; then
    343         VERIFY="n"
    344         shift
    345     elif [ "x$1" = "x--verify-soft-fail" ]; then
    346         VERIFY="s"
    347         shift
    348     elif [ "x$1" = "x--no-optimize" ]; then
    349         OPTIMIZE="n"
    350         shift
    351     elif [ "x$1" = "x--chroot" ]; then
    352         shift
    353         CHROOT="$1"
    354         shift
    355     elif [ "x$1" = "x--android-root" ]; then
    356         shift
    357         ANDROID_ROOT="$1"
    358         shift
    359     elif [ "x$1" = "x--android-runtime-root" ]; then
    360         shift
    361         ANDROID_RUNTIME_ROOT="$1"
    362         shift
    363     elif [ "x$1" = "x--android-tzdata-root" ]; then
    364         shift
    365         ANDROID_TZDATA_ROOT="$1"
    366         shift
    367     elif [ "x$1" = "x--instruction-set-features" ]; then
    368         shift
    369         INSTRUCTION_SET_FEATURES="$1"
    370         shift
    371     elif [ "x$1" = "x--timeout" ]; then
    372         shift
    373         TIME_OUT_VALUE="$1"
    374         shift
    375     elif [ "x$1" = "x--" ]; then
    376         shift
    377         break
    378     elif [ "x$1" = "x--64" ]; then
    379         ISA="x86_64"
    380         GDBSERVER_DEVICE="gdbserver64"
    381         DALVIKVM="dalvikvm64"
    382         LIBRARY_DIRECTORY="lib64"
    383         TEST_DIRECTORY="nativetest64"
    384         ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
    385         shift
    386     elif [ "x$1" = "x--experimental" ]; then
    387         if [ "$#" -lt 2 ]; then
    388             echo "missing --experimental option" 1>&2
    389             exit 1
    390         fi
    391         EXPERIMENTAL="$EXPERIMENTAL $2"
    392         shift 2
    393     elif [ "x$1" = "x--external-log-tags" ]; then
    394         EXTERNAL_LOG_TAGS="y"
    395         shift
    396     elif [ "x$1" = "x--dry-run" ]; then
    397         DRY_RUN="y"
    398         shift
    399     elif [ "x$1" = "x--vdex" ]; then
    400         TEST_VDEX="y"
    401         shift
    402     elif [ "x$1" = "x--dm" ]; then
    403         TEST_DM="y"
    404         shift
    405     elif [ "x$1" = "x--vdex-filter" ]; then
    406         shift
    407         option="$1"
    408         VDEX_ARGS="${VDEX_ARGS} --compiler-filter=$option"
    409         shift
    410     elif [ "x$1" = "x--vdex-arg" ]; then
    411         shift
    412         VDEX_ARGS="${VDEX_ARGS} $1"
    413         shift
    414     elif [ "x$1" = "x--sync" ]; then
    415         SYNC_BEFORE_RUN="y"
    416         shift
    417     elif [ "x$1" = "x--profile" ]; then
    418         PROFILE="y"
    419         shift
    420     elif [ "x$1" = "x--random-profile" ]; then
    421         RANDOM_PROFILE="y"
    422         shift
    423     elif expr "x$1" : "x--" >/dev/null 2>&1; then
    424         echo "unknown $0 option: $1" 1>&2
    425         exit 1
    426     else
    427         break
    428     fi
    429 done
    430 
    431 # The DEX_LOCATION with the chroot prefix, if any.
    432 CHROOT_DEX_LOCATION="$CHROOT$DEX_LOCATION"
    433 
    434 if [ "$USE_JVM" = "n" ]; then
    435     FLAGS="${FLAGS} ${ANDROID_FLAGS}"
    436     # we don't want to be trying to get adbconnections since the plugin might
    437     # not have been built.
    438     FLAGS="${FLAGS} -XjdwpProvider:none"
    439     for feature in ${EXPERIMENTAL}; do
    440         FLAGS="${FLAGS} -Xexperimental:${feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:${feature}"
    441         COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xexperimental:${feature}"
    442     done
    443 fi
    444 
    445 if [ "$CREATE_ANDROID_ROOT" = "y" ]; then
    446     ANDROID_ROOT=$DEX_LOCATION/android-root
    447 fi
    448 
    449 if [ "x$1" = "x" ] ; then
    450   MAIN="Main"
    451 else
    452   MAIN="$1"
    453   shift
    454 fi
    455 
    456 if [ "$ZYGOTE" = "" ]; then
    457     if [ "$OPTIMIZE" = "y" ]; then
    458         if [ "$VERIFY" = "y" ]; then
    459             DEX_OPTIMIZE="-Xdexopt:verified"
    460         else
    461             DEX_OPTIMIZE="-Xdexopt:all"
    462         fi
    463         msg "Performing optimizations"
    464     else
    465         DEX_OPTIMIZE="-Xdexopt:none"
    466         msg "Skipping optimizations"
    467     fi
    468 
    469     if [ "$VERIFY" = "y" ]; then
    470         JVM_VERIFY_ARG="-Xverify:all"
    471         msg "Performing verification"
    472     elif [ "$VERIFY" = "s" ]; then
    473         JVM_VERIFY_ARG="Xverify:all"
    474         DEX_VERIFY="-Xverify:softfail"
    475         msg "Forcing verification to be soft fail"
    476     else # VERIFY = "n"
    477         DEX_VERIFY="-Xverify:none"
    478         JVM_VERIFY_ARG="-Xverify:none"
    479         msg "Skipping verification"
    480     fi
    481 fi
    482 
    483 msg "------------------------------"
    484 
    485 if [ "$DEBUGGER" = "y" ]; then
    486   # Use this instead for ddms and connect by running 'ddms':
    487   # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
    488   # TODO: add a separate --ddms option?
    489 
    490   PORT=12345
    491   msg "Waiting for jdb to connect:"
    492   if [ "$HOST" = "n" ]; then
    493     msg "    adb forward tcp:$PORT tcp:$PORT"
    494   fi
    495   msg "    jdb -attach localhost:$PORT"
    496   if [ "$USE_JVM" = "n" ]; then
    497     # TODO We should switch over to using the jvmti agent by default.
    498     # Need to tell the runtime to enable the internal jdwp implementation.
    499     DEBUGGER_OPTS="-XjdwpOptions:transport=dt_socket,address=$PORT,server=y,suspend=y -XjdwpProvider:internal"
    500   else
    501     DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
    502   fi
    503 elif [ "$DEBUGGER" = "agent" ]; then
    504   PORT=12345
    505   # TODO Support ddms connection and support target.
    506   if [ "$HOST" = "n" ]; then
    507     echo "--debug-agent not supported yet for target!"
    508     exit 1
    509   fi
    510   AGENTPATH=${DEBUGGER_AGENT}
    511   if [ "$WRAP_DEBUGGER_AGENT" = "y" ]; then
    512     WRAPPROPS="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}/libwrapagentpropertiesd.so"
    513     if [ "$TEST_IS_NDEBUG" = "y" ]; then
    514       WRAPPROPS="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}/libwrapagentproperties.so"
    515     fi
    516     AGENTPATH="${WRAPPROPS}=${ANDROID_BUILD_TOP}/art/tools/libjdwp-compat.props,${AGENTPATH}"
    517   fi
    518   msg "Connect to localhost:$PORT"
    519   DEBUGGER_OPTS="-agentpath:${AGENTPATH}=transport=dt_socket,address=$PORT,server=y,suspend=y"
    520 fi
    521 
    522 for agent in "${WITH_AGENT[@]}"; do
    523   FLAGS="${FLAGS} -agentpath:${agent}"
    524 done
    525 
    526 if [ "$USE_JVMTI" = "y" ]; then
    527   if [ "$USE_JVM" = "n" ]; then
    528     plugin=libopenjdkjvmtid.so
    529     if  [[ "$TEST_IS_NDEBUG" = "y" ]]; then
    530       plugin=libopenjdkjvmti.so
    531     fi
    532     # We used to add flags here that made the runtime debuggable but that is not
    533     # needed anymore since the plugin can do it for us now.
    534     FLAGS="${FLAGS} -Xplugin:${plugin}"
    535   fi
    536 fi
    537 
    538 if [ "$IS_JVMTI_TEST" = "y" ]; then
    539   agent=libtiagentd.so
    540   lib=tiagentd
    541   if  [[ "$TEST_IS_NDEBUG" = "y" ]]; then
    542     agent=libtiagent.so
    543     lib=tiagent
    544   fi
    545 
    546   ARGS="${ARGS} ${lib}"
    547   if [[ "$USE_JVM" = "y" ]]; then
    548     FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${TEST_NAME},jvm"
    549   else
    550     FLAGS="${FLAGS} -agentpath:${agent}=${TEST_NAME},art"
    551   fi
    552 fi
    553 
    554 if [[ "$JVMTI_STRESS" = "y" ]]; then
    555   agent=libtistressd.so
    556   if  [[ "$TEST_IS_NDEBUG" = "y" ]]; then
    557     agent=libtistress.so
    558   fi
    559 
    560   # Just give it a default start so we can always add ',' to it.
    561   agent_args="jvmti-stress"
    562   if [[ "$JVMTI_REDEFINE_STRESS" = "y" ]]; then
    563     # We really cannot do this on RI so don't both passing it in that case.
    564     if [[ "$USE_JVM" = "n" ]]; then
    565       agent_args="${agent_args},redefine"
    566     fi
    567   fi
    568   if [[ "$JVMTI_FIELD_STRESS" = "y" ]]; then
    569     agent_args="${agent_args},field"
    570   fi
    571   if [[ "$JVMTI_STEP_STRESS" = "y" ]]; then
    572     agent_args="${agent_args},step"
    573   fi
    574   if [[ "$JVMTI_TRACE_STRESS" = "y" ]]; then
    575     agent_args="${agent_args},trace"
    576   fi
    577   # In the future add onto this;
    578   if [[ "$USE_JVM" = "y" ]]; then
    579     FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${agent_args}"
    580   else
    581     FLAGS="${FLAGS} -agentpath:${agent}=${agent_args}"
    582   fi
    583 fi
    584 
    585 if [ "$USE_JVM" = "y" ]; then
    586   export LD_LIBRARY_PATH=${ANDROID_HOST_OUT}/lib64
    587   # Some jvmti tests are flaky without -Xint on the RI.
    588   if [ "$IS_JVMTI_TEST" = "y" ]; then
    589     FLAGS="${FLAGS} -Xint"
    590   fi
    591   # Xmx is necessary since we don't pass down the ART flags to JVM.
    592   # We pass the classes2 path whether it's used (src-multidex) or not.
    593   cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes:classes2 ${FLAGS} $MAIN $@ ${ARGS}"
    594   if [ "$DEV_MODE" = "y" ]; then
    595     echo $cmdline
    596   fi
    597   $cmdline
    598   exit
    599 fi
    600 
    601 # Note: This must start with the CORE_IMG_JARS in Android.common_path.mk
    602 # because that's what we use for compiling the core.art image.
    603 # It may contain additional modules from TEST_CORE_JARS.
    604 bpath_modules="core-oj core-libart okhttp bouncycastle apache-xml conscrypt"
    605 if [ "${HOST}" = "y" ]; then
    606     framework="${ANDROID_HOST_OUT}/framework"
    607     if [ "${ANDROID_HOST_OUT:0:${#ANDROID_BUILD_TOP}+1}" = "${ANDROID_BUILD_TOP}/" ]; then
    608       framework_location="${ANDROID_HOST_OUT:${#ANDROID_BUILD_TOP}+1}/framework"
    609     else
    610       echo "error: ANDROID_BUILD_TOP/ is not a prefix of ANDROID_HOST_OUT"
    611       echo "ANDROID_BUILD_TOP=${ANDROID_BUILD_TOP}"
    612       echo "ANDROID_HOST_OUT=${ANDROID_HOST_OUT}"
    613       exit
    614     fi
    615     bpath_suffix="-hostdex"
    616 else
    617     framework="${ANDROID_ROOT}/framework"
    618     framework_location="${ANDROID_ROOT}/framework"
    619     bpath_suffix="-testdex"
    620 fi
    621 bpath=""
    622 bpath_locations=""
    623 bpath_separator=""
    624 for bpath_module in ${bpath_modules}; do
    625   bpath+="${bpath_separator}${framework}/${bpath_module}${bpath_suffix}.jar"
    626   bpath_locations+="${bpath_separator}${framework_location}/${bpath_module}${bpath_suffix}.jar"
    627   bpath_separator=":"
    628 done
    629 # Pass down the bootclasspath
    630 FLAGS="${FLAGS} -Xbootclasspath:${bpath}"
    631 FLAGS="${FLAGS} -Xbootclasspath-locations:${bpath_locations}"
    632 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xbootclasspath:${bpath}"
    633 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xbootclasspath-locations:${bpath_locations}"
    634 
    635 if [ "$HAVE_IMAGE" = "n" ]; then
    636     # Disable image dex2oat - this will forbid the runtime to patch or compile an image.
    637     FLAGS="${FLAGS} -Xnoimage-dex2oat"
    638 
    639     # We'll abuse a second flag here to test different behavior. If --relocate, use the
    640     # existing image - relocation will fail as patching is disallowed. If --no-relocate,
    641     # pass a non-existent image - compilation will fail as dex2oat is disallowed.
    642     if [ "${RELOCATE}" = "y" ] ; then
    643       DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
    644     else
    645       DALVIKVM_BOOT_OPT="-Ximage:/system/non-existent/core.art"
    646     fi
    647 else
    648     DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
    649 fi
    650 
    651 
    652 if [ "$USE_GDB" = "y" ]; then
    653   if [ "$USE_GDBSERVER" = "y" ]; then
    654     echo "Cannot pass both --gdb and --gdbserver at the same time!" >&2
    655     exit 1
    656   elif [ "$HOST" = "n" ]; then
    657     GDB="$GDBSERVER_DEVICE $GDBSERVER_PORT"
    658   else
    659     if [ `uname` = "Darwin" ]; then
    660         GDB=lldb
    661         GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
    662         DALVIKVM=
    663     else
    664         GDB=gdb
    665         GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
    666         # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
    667         # gdbargs="--annotate=3 $gdbargs"
    668     fi
    669   fi
    670 elif [ "$USE_GDBSERVER" = "y" ]; then
    671   if [ "$HOST" = "n" ]; then
    672     echo "Cannot use --gdbserver in non-host configs" >&2
    673     exit 1
    674   fi
    675   GDB="$GDBSERVER_HOST $GDBSERVER_PORT"
    676 fi
    677 
    678 if [ "$INTERPRETER" = "y" ]; then
    679     INT_OPTS="${INT_OPTS} -Xint"
    680     if [ "$VERIFY" = "y" ] ; then
    681       INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=quicken"
    682       COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=quicken"
    683     elif [ "$VERIFY" = "s" ]; then
    684       INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=extract"
    685       COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=extract"
    686       DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
    687     else # VERIFY = "n"
    688       INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=assume-verified"
    689       COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=assume-verified"
    690       DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
    691     fi
    692 fi
    693 
    694 if [ "$JIT" = "y" ]; then
    695     INT_OPTS="${INT_OPTS} -Xusejit:true"
    696     if [ "$VERIFY" = "y" ] ; then
    697       INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=quicken"
    698       COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=quicken"
    699     else
    700       INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=assume-verified"
    701       COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=assume-verified"
    702       DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
    703     fi
    704 else
    705     INT_OPTS="${INT_OPTS} -Xusejit:false"
    706 fi
    707 
    708 JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
    709 
    710 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
    711 if [ "$RELOCATE" = "y" ]; then
    712     FLAGS="${FLAGS} -Xrelocate"
    713 else
    714     FLAGS="$FLAGS -Xnorelocate"
    715 fi
    716 
    717 if [ "$HOST" = "n" ]; then
    718   # Need to be root to query /data/dalvik-cache
    719   adb root > /dev/null
    720   adb wait-for-device
    721   ISA=
    722   ISA_adb_invocation=
    723   ISA_outcome=
    724   # We iterate a few times to workaround an adb issue. b/32655576
    725   for i in {1..10}; do
    726     ISA_adb_invocation=$(adb shell ls -F /data/dalvik-cache)
    727     ISA_outcome=$?
    728     ISA=$(echo $ISA_adb_invocation | grep -Ewo "${ARCHITECTURES_PATTERN}")
    729     if [ x"$ISA" != "x" ]; then
    730       break;
    731     fi
    732   done
    733   if [ x"$ISA" = "x" ]; then
    734     echo "Unable to determine architecture"
    735     # Print a few things for helping diagnosing the problem.
    736     echo "adb invocation output: $ISA_adb_invocation"
    737     echo "adb invocation outcome: $ISA_outcome"
    738     echo $(adb shell ls -F /data/dalvik-cache)
    739     echo $(adb shell ls /data/dalvik-cache)
    740     echo ${ARCHITECTURES_PATTERN}
    741     echo $(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
    742     exit 1
    743   fi
    744 fi
    745 
    746 if [ "$BIONIC" = "y" ]; then
    747   # This is the location that soong drops linux_bionic builds. Despite being
    748   # called linux_bionic-x86 the build is actually amd64 (x86_64) only.
    749   if [ ! -e "$OUT_DIR/soong/host/linux_bionic-x86" ]; then
    750     echo "linux_bionic-x86 target doesn't seem to have been built!" >&2
    751     exit 1
    752   fi
    753   # Set timeout_dumper manually so it works even with apex's
    754   TIMEOUT_DUMPER=$OUT_DIR/soong/host/linux_bionic-x86/bin/timeout_dumper
    755 fi
    756 
    757 # Prevent test from silently falling back to interpreter in no-prebuild mode. This happens
    758 # when DEX_LOCATION path is too long, because vdex/odex filename is constructed by taking
    759 # full path to dex, stripping leading '/', appending '@classes.vdex' and changing every
    760 # remaining '/' into '@'.
    761 if [ "$HOST" = "y" ]; then
    762   max_filename_size=$(getconf NAME_MAX $DEX_LOCATION)
    763 else
    764   # There is no getconf on device, fallback to standard value.
    765   # See NAME_MAX in kernel <linux/limits.h>
    766   max_filename_size=255
    767 fi
    768 # Compute VDEX_NAME.
    769 DEX_LOCATION_STRIPPED="${DEX_LOCATION#/}"
    770 VDEX_NAME="${DEX_LOCATION_STRIPPED//\//@}@$TEST_NAME.jar (at] classes.vdex"
    771 if [ ${#VDEX_NAME} -gt $max_filename_size ]; then
    772     echo "Dex location path too long:"
    773     echo "$VDEX_NAME is ${#VDEX_NAME} character long, and the limit is $max_filename_size."
    774     exit 1
    775 fi
    776 
    777 BIN_DIR=$ANDROID_ROOT/bin
    778 
    779 profman_cmdline="true"
    780 dex2oat_cmdline="true"
    781 vdex_cmdline="true"
    782 dm_cmdline="true"
    783 mkdir_locations="${DEX_LOCATION}/dalvik-cache/$ISA"
    784 strip_cmdline="true"
    785 sync_cmdline="true"
    786 linkroot_cmdline="true"
    787 linkroot_overlay_cmdline="true"
    788 setupapex_cmdline="true"
    789 installapex_cmdline="true"
    790 
    791 linkdirs() {
    792   find "$1" -maxdepth 1 -mindepth 1 -type d | xargs -i ln -sf '{}' "$2"
    793 }
    794 
    795 if [ "$CREATE_ANDROID_ROOT" = "y" ]; then
    796   mkdir_locations="${mkdir_locations} ${ANDROID_ROOT}"
    797   linkroot_cmdline="linkdirs ${ANDROID_HOST_OUT} ${ANDROID_ROOT}"
    798   if [ "${BIONIC}" = "y" ]; then
    799     # TODO Make this overlay more generic.
    800     linkroot_overlay_cmdline="linkdirs $OUT_DIR/soong/host/linux_bionic-x86 ${ANDROID_ROOT}"
    801   fi
    802 fi
    803 
    804 if [ "$USE_ZIPAPEX" = "y" ]; then
    805   # TODO Currently this only works for linux_bionic zipapexes because those are
    806   # stripped and so small enough that the ulimit doesn't kill us.
    807   mkdir_locations="${mkdir_locations} $DEX_LOCATION/zipapex"
    808   zip_options="-qq"
    809   if [ "$DEV_MODE" = "y" ]; then
    810     zip_options=""
    811   fi
    812   setupapex_cmdline="unzip -o -u ${zip_options} ${ZIPAPEX_LOC} apex_payload.zip -d ${DEX_LOCATION}"
    813   installapex_cmdline="unzip -o -u ${zip_options} ${DEX_LOCATION}/apex_payload.zip -d ${DEX_LOCATION}/zipapex"
    814   BIN_DIR=$DEX_LOCATION/zipapex/bin
    815 elif [ "$USE_EXTRACTED_ZIPAPEX" = "y" ]; then
    816   # Just symlink the zipapex binaries
    817   BIN_DIR=$DEX_LOCATION/zipapex/bin
    818   # Force since some tests manually run this file twice.
    819   ln_options=""
    820   if [ "$DEV_MODE" = "y" ]; then
    821     ln_options="--verbose"
    822   fi
    823   installapex_cmdline="ln -s -f ${ln_options} ${EXTRACTED_ZIPAPEX_LOC} ${DEX_LOCATION}/zipapex"
    824 fi
    825 
    826 # PROFILE takes precedence over RANDOM_PROFILE, since PROFILE tests require a
    827 # specific profile to run properly.
    828 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
    829   profman_cmdline="$BIN_DIR/profman  \
    830     --apk=$DEX_LOCATION/$TEST_NAME.jar \
    831     --dex-location=$DEX_LOCATION/$TEST_NAME.jar"
    832   if [ -f $DEX_LOCATION/$TEST_NAME-ex.jar ]; then
    833     profman_cmdline="${profman_cmdline} \
    834       --apk=$DEX_LOCATION/$TEST_NAME-ex.jar \
    835       --dex-location=$DEX_LOCATION/$TEST_NAME-ex.jar"
    836   fi
    837   COMPILE_FLAGS="${COMPILE_FLAGS} --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
    838   FLAGS="${FLAGS} -Xcompiler-option --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
    839   if [ "$PROFILE" = "y" ]; then
    840     profman_cmdline="${profman_cmdline} --create-profile-from=$DEX_LOCATION/profile \
    841         --reference-profile-file=$DEX_LOCATION/$TEST_NAME.prof"
    842   else
    843     profman_cmdline="${profman_cmdline} --generate-test-profile=$DEX_LOCATION/$TEST_NAME.prof \
    844         --generate-test-profile-seed=0"
    845   fi
    846 fi
    847 
    848 if [ "$PREBUILD" = "y" ]; then
    849   mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/oat/$ISA"
    850   if [ "$APP_IMAGE" = "y" ]; then
    851     # Pick a base that will force the app image to get relocated.
    852     app_image="--base=0x4000 --app-image-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.art --resolve-startup-const-strings=true"
    853   fi
    854 
    855   dex2oat_binary=${DEX2OAT_DEBUG_BINARY}
    856   if  [[ "$TEST_IS_NDEBUG" = "y" ]]; then
    857     dex2oat_binary=${DEX2OAT_NDEBUG_BINARY}
    858   fi
    859   dex2oat_cmdline="$INVOKE_WITH $BIN_DIR/$dex2oat_binary \
    860                       $COMPILE_FLAGS \
    861                       --boot-image=${BOOT_IMAGE} \
    862                       --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
    863                       --oat-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.odex \
    864                       ${app_image} \
    865                       --instruction-set=$ISA"
    866   if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
    867     dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
    868   fi
    869 
    870   # Add in a timeout. This is important for testing the compilation/verification time of
    871   # pathological cases.
    872   # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
    873   #       now. We should try to improve this.
    874   #       The current value is rather arbitrary. run-tests should compile quickly.
    875   # Watchdog timeout is in milliseconds so add 3 '0's to the dex2oat timeout.
    876   if [ "$HOST" != "n" ]; then
    877     # Use SIGRTMIN+2 to try to dump threads.
    878     # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
    879     dex2oat_cmdline="timeout -k ${DEX2OAT_TIMEOUT}s -s SIGRTMIN+2 ${DEX2OAT_RT_TIMEOUT}s ${dex2oat_cmdline} --watchdog-timeout=${DEX2OAT_TIMEOUT}000"
    880   fi
    881   if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
    882     vdex_cmdline="${dex2oat_cmdline} ${VDEX_ARGS} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex --output-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
    883   elif [ "$TEST_VDEX" = "y" ]; then
    884     vdex_cmdline="${dex2oat_cmdline} ${VDEX_ARGS} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
    885   elif [ "$TEST_DM" = "y" ]; then
    886     dex2oat_cmdline="${dex2oat_cmdline} --output-vdex=$DEX_LOCATION/oat/$ISA/primary.vdex"
    887     dm_cmdline="zip -qj $DEX_LOCATION/oat/$ISA/$TEST_NAME.dm $DEX_LOCATION/oat/$ISA/primary.vdex"
    888     vdex_cmdline="${dex2oat_cmdline} ${VDEX_ARGS} --dump-timings --dm-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.dm"
    889   elif [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
    890     vdex_cmdline="${dex2oat_cmdline} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex --output-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
    891   fi
    892 fi
    893 
    894 if [ "$STRIP_DEX" = "y" ]; then
    895   strip_cmdline="zip --quiet --delete $DEX_LOCATION/$TEST_NAME.jar classes.dex"
    896 fi
    897 
    898 if [ "$SYNC_BEFORE_RUN" = "y" ]; then
    899   sync_cmdline="sync"
    900 fi
    901 
    902 DALVIKVM_ISA_FEATURES_ARGS=""
    903 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
    904   DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
    905 fi
    906 
    907 # java.io.tmpdir can only be set at launch time.
    908 TMP_DIR_OPTION=""
    909 if [ "$HOST" = "n" ]; then
    910   TMP_DIR_OPTION="-Djava.io.tmpdir=/data/local/tmp"
    911 fi
    912 
    913 # We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
    914 # b/27185632
    915 # b/24664297
    916 dalvikvm_cmdline="$INVOKE_WITH $GDB $BIN_DIR/$DALVIKVM \
    917                   $GDB_ARGS \
    918                   $FLAGS \
    919                   $DEX_VERIFY \
    920                   -XXlib:$LIB \
    921                   $DEX2OAT \
    922                   $DALVIKVM_ISA_FEATURES_ARGS \
    923                   $ZYGOTE \
    924                   $JNI_OPTS \
    925                   $INT_OPTS \
    926                   $DEBUGGER_OPTS \
    927                   $DALVIKVM_BOOT_OPT \
    928                   $TMP_DIR_OPTION \
    929                   -XX:DumpNativeStackOnSigQuit:false \
    930                   -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
    931 
    932 # Remove whitespace.
    933 dex2oat_cmdline=$(echo $dex2oat_cmdline)
    934 dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
    935 dm_cmdline=$(echo $dm_cmdline)
    936 vdex_cmdline=$(echo $vdex_cmdline)
    937 profman_cmdline=$(echo $profman_cmdline)
    938 
    939 # Use an empty ASAN_OPTIONS to enable defaults.
    940 # Note: this is required as envsetup right now exports detect_leaks=0.
    941 RUN_TEST_ASAN_OPTIONS=""
    942 
    943 # Multiple shutdown leaks. b/38341789
    944 if [ "x$RUN_TEST_ASAN_OPTIONS" != "x" ] ; then
    945   RUN_TEST_ASAN_OPTIONS="${RUN_TEST_ASAN_OPTIONS}:"
    946 fi
    947 RUN_TEST_ASAN_OPTIONS="${RUN_TEST_ASAN_OPTIONS}detect_leaks=0"
    948 
    949 # For running, we must turn off logging when dex2oat is missing. Otherwise we use
    950 # the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
    951 if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
    952   if [ "$DEV_MODE" = "y" ]; then
    953       export ANDROID_LOG_TAGS='*:d'
    954   elif [ "$HAVE_IMAGE" = "n" ]; then
    955       # All tests would log the error of missing image. Be silent here and only log fatal
    956       # events.
    957       export ANDROID_LOG_TAGS='*:s'
    958   else
    959       # We are interested in LOG(ERROR) output.
    960       export ANDROID_LOG_TAGS='*:e'
    961   fi
    962 fi
    963 
    964 if [ "$HOST" = "n" ]; then
    965     adb root > /dev/null
    966     adb wait-for-device
    967     if [ "$QUIET" = "n" ]; then
    968       adb shell rm -rf $CHROOT_DEX_LOCATION
    969       adb shell mkdir -p $CHROOT_DEX_LOCATION
    970       adb push $TEST_NAME.jar $CHROOT_DEX_LOCATION
    971       adb push $TEST_NAME-ex.jar $CHROOT_DEX_LOCATION
    972       if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
    973         adb push profile $CHROOT_DEX_LOCATION
    974       fi
    975       # Copy resource folder
    976       if [ -d res ]; then
    977         adb push res $CHROOT_DEX_LOCATION
    978       fi
    979     else
    980       adb shell rm -rf $CHROOT_DEX_LOCATION >/dev/null 2>&1
    981       adb shell mkdir -p $CHROOT_DEX_LOCATION >/dev/null 2>&1
    982       adb push $TEST_NAME.jar $CHROOT_DEX_LOCATION >/dev/null 2>&1
    983       adb push $TEST_NAME-ex.jar $CHROOT_DEX_LOCATION >/dev/null 2>&1
    984       if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
    985         adb push profile $CHROOT_DEX_LOCATION >/dev/null 2>&1
    986       fi
    987       # Copy resource folder
    988       if [ -d res ]; then
    989         adb push res $CHROOT_DEX_LOCATION >/dev/null 2>&1
    990       fi
    991     fi
    992 
    993     LD_LIBRARY_PATH=/data/$TEST_DIRECTORY/art/$ISA
    994     if [ "$ANDROID_ROOT" != "/system" ]; then
    995       # Current default installation is dalvikvm 64bits and dex2oat 32bits,
    996       # so we can only use LD_LIBRARY_PATH when testing on a local
    997       # installation.
    998       LD_LIBRARY_PATH="$ANDROID_ROOT/$LIBRARY_DIRECTORY:$LD_LIBRARY_PATH"
    999     fi
   1000 
   1001     # System libraries needed by libarttestd.so
   1002     PUBLIC_LIBS=libc++.so:libbacktrace.so:libbase.so:libnativehelper.so
   1003     if [ "$TEST_IS_NDEBUG" = "y" ]; then
   1004       PUBLIC_LIBS=$PUBLIC_LIBS:libart.so:libdexfile.so:libprofile.so:libartbase.so
   1005     else
   1006       PUBLIC_LIBS=$PUBLIC_LIBS:libartd.so:libdexfiled.so:libprofiled.so:libartbased.so
   1007     fi
   1008 
   1009     # Create a script with the command. The command can get longer than the longest
   1010     # allowed adb command and there is no way to get the exit status from a adb shell
   1011     # command. Dalvik cache is cleaned before running to make subsequent executions
   1012     # of the script follow the same runtime path.
   1013     cmdline="cd $DEX_LOCATION && \
   1014              export ASAN_OPTIONS=$RUN_TEST_ASAN_OPTIONS && \
   1015              export ANDROID_DATA=$DEX_LOCATION && \
   1016              export ANDROID_ADDITIONAL_PUBLIC_LIBRARIES=$PUBLIC_LIBS && \
   1017              export DEX_LOCATION=$DEX_LOCATION && \
   1018              export ANDROID_ROOT=$ANDROID_ROOT && \
   1019              export ANDROID_RUNTIME_ROOT=$ANDROID_RUNTIME_ROOT && \
   1020              export ANDROID_TZDATA_ROOT=$ANDROID_TZDATA_ROOT && \
   1021              export ANDROID_LOG_TAGS=$ANDROID_LOG_TAGS && \
   1022              rm -rf ${DEX_LOCATION}/dalvik-cache/ && \
   1023              mkdir -p ${mkdir_locations} && \
   1024              export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
   1025              export PATH=$BIN_DIR:$PATH && \
   1026              $profman_cmdline && \
   1027              $dex2oat_cmdline && \
   1028              $dm_cmdline && \
   1029              $vdex_cmdline && \
   1030              $strip_cmdline && \
   1031              $sync_cmdline && \
   1032              $dalvikvm_cmdline"
   1033 
   1034     cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
   1035     echo "$cmdline" > $cmdfile
   1036 
   1037     if [ "$DEV_MODE" = "y" ]; then
   1038       echo $cmdline
   1039     fi
   1040 
   1041     if [ "$QUIET" = "n" ]; then
   1042       adb push $cmdfile $CHROOT_DEX_LOCATION/cmdline.sh
   1043     else
   1044       adb push $cmdfile $CHROOT_DEX_LOCATION/cmdline.sh >/dev/null 2>&1
   1045     fi
   1046 
   1047     exit_status=0
   1048     if [ "$DRY_RUN" != "y" ]; then
   1049       if [ -n "$CHROOT" ]; then
   1050         adb shell chroot "$CHROOT" sh $DEX_LOCATION/cmdline.sh
   1051       else
   1052         adb shell sh $DEX_LOCATION/cmdline.sh
   1053       fi
   1054       exit_status=$?
   1055     fi
   1056 
   1057     rm -f $cmdfile
   1058     exit $exit_status
   1059 else
   1060     # Host run.
   1061     export ANDROID_PRINTF_LOG=brief
   1062 
   1063     export ANDROID_DATA="$DEX_LOCATION"
   1064     export ANDROID_ROOT="${ANDROID_ROOT}"
   1065     export ANDROID_RUNTIME_ROOT="${ANDROID_RUNTIME_ROOT}"
   1066     export ANDROID_TZDATA_ROOT="${ANDROID_TZDATA_ROOT}"
   1067     if [ "$USE_ZIPAPEX" = "y" ] || [ "$USE_EXRACTED_ZIPAPEX" = "y" ]; then
   1068       # Put the zipapex files in front of the ld-library-path
   1069       export LD_LIBRARY_PATH="${ANDROID_DATA}/zipapex/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
   1070       export DYLD_LIBRARY_PATH="${ANDROID_DATA}/zipapex/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
   1071     else
   1072       export LD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
   1073       export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
   1074     fi
   1075     export PATH="$PATH:$BIN_DIR"
   1076 
   1077     # Temporarily disable address space layout randomization (ASLR).
   1078     # This is needed on the host so that the linker loads core.oat at the necessary address.
   1079     export LD_USE_LOAD_BIAS=1
   1080 
   1081     cmdline="$dalvikvm_cmdline"
   1082 
   1083     if [ "$TIME_OUT" = "gdb" ]; then
   1084       if [ `uname` = "Darwin" ]; then
   1085         # Fall back to timeout on Mac.
   1086         TIME_OUT="timeout"
   1087       elif [ "$ISA" = "x86" ]; then
   1088         # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
   1089         TIME_OUT="timeout"
   1090       else
   1091         # Check if gdb is available.
   1092         gdb --eval-command="quit" > /dev/null 2>&1
   1093         if [ $? != 0 ]; then
   1094           # gdb isn't available. Fall back to timeout.
   1095           TIME_OUT="timeout"
   1096         fi
   1097       fi
   1098     fi
   1099 
   1100     if [ "$TIME_OUT" = "timeout" ]; then
   1101       # Add timeout command if time out is desired.
   1102       #
   1103       # Note: We first send SIGRTMIN+2 (usually 36) to ART, which will induce a full thread dump
   1104       #       before abort. However, dumping threads might deadlock, so we also use the "-k"
   1105       #       option to definitely kill the child.
   1106       # Note: Using "--foreground" to not propagate the signal to children, i.e., the runtime.
   1107       cmdline="timeout --foreground -k 120s -s SIGRTMIN+2 ${TIME_OUT_VALUE}s ${TIMEOUT_DUMPER} $cmdline"
   1108     fi
   1109 
   1110     if [ "$DEV_MODE" = "y" ]; then
   1111       for var in ANDROID_PRINTF_LOG ANDROID_DATA ANDROID_ROOT LD_LIBRARY_PATH DYLD_LIBRARY_PATH PATH LD_USE_LOAD_BIAS; do
   1112         echo EXPORT $var=${!var}
   1113       done
   1114       echo "$(declare -f linkdirs)"
   1115       echo "mkdir -p ${mkdir_locations} && $setupapex_cmdline && $installapex_cmdline && $linkroot_cmdline && $linkroot_overlay_cmdline && $profman_cmdline && $dex2oat_cmdline && $dm_cmdline && $vdex_cmdline && $strip_cmdline && $sync_cmdline && $cmdline"
   1116     fi
   1117 
   1118     cd $ANDROID_BUILD_TOP
   1119 
   1120     # Make sure we delete any existing compiler artifacts.
   1121     # This enables tests to call the RUN script multiple times in a row
   1122     # without worrying about interference.
   1123     rm -rf ${DEX_LOCATION}/oat
   1124     rm -rf ${DEX_LOCATION}/dalvik-cache/
   1125 
   1126     export ASAN_OPTIONS=$RUN_TEST_ASAN_OPTIONS
   1127 
   1128     mkdir -p ${mkdir_locations} || exit 1
   1129     $setupapex_cmdline || { echo "zipapex extraction failed." >&2 ; exit 2; }
   1130     $installapex_cmdline || { echo "zipapex install failed. cmd was: ${installapex_cmdline}." >&2; find ${mkdir_locations} -type f >&2; exit 2; }
   1131     $linkroot_cmdline || { echo "create symlink android-root failed." >&2 ; exit 2; }
   1132     $linkroot_overlay_cmdline || { echo "overlay android-root failed." >&2 ; exit 2; }
   1133     $profman_cmdline || { echo "Profman failed." >&2 ; exit 2; }
   1134     $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
   1135     $dm_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
   1136     $vdex_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
   1137     $strip_cmdline || { echo "Strip failed." >&2 ; exit 3; }
   1138     $sync_cmdline || { echo "Sync failed." >&2 ; exit 4; }
   1139 
   1140     if [ "$DRY_RUN" = "y" ]; then
   1141       exit 0
   1142     fi
   1143 
   1144     if [ "$USE_GDB" = "y" ]; then
   1145       # When running under gdb, we cannot do piping and grepping...
   1146       $cmdline "$@"
   1147     elif [ "$USE_GDBSERVER" = "y" ]; then
   1148       echo "Connect to $GDBSERVER_PORT"
   1149       # When running under gdb, we cannot do piping and grepping...
   1150       $cmdline "$@"
   1151     else
   1152       if [ "$TIME_OUT" != "gdb" ]; then
   1153         trap 'kill -INT -$pid' INT
   1154         $cmdline "$@" 2>&1 & pid=$!
   1155         wait $pid
   1156         exit_value=$?
   1157         # Add extra detail if time out is enabled.
   1158         if [ $exit_value = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
   1159           echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
   1160         fi
   1161         exit $exit_value
   1162       else
   1163         # With a thread dump that uses gdb if a timeout.
   1164         trap 'kill -INT -$pid' INT
   1165         $cmdline "$@" 2>&1 & pid=$!
   1166         # Spawn a watcher process.
   1167         ( sleep $TIME_OUT_VALUE && \
   1168           echo "##### Thread dump using gdb on test timeout" && \
   1169           ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
   1170                            --eval-command="call exit(124)" --eval-command=quit || \
   1171             kill $pid )) 2> /dev/null & watcher=$!
   1172         wait $pid
   1173         test_exit_status=$?
   1174         pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
   1175         if [ $test_exit_status = 0 ]; then
   1176           # The test finished normally.
   1177           exit 0
   1178         else
   1179           # The test failed or timed out.
   1180           if [ $test_exit_status = 124 ]; then
   1181             # The test timed out.
   1182             echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
   1183           fi
   1184           exit $test_exit_status
   1185         fi
   1186       fi
   1187     fi
   1188 fi
   1189