Home | History | Annotate | Download | only in etc
      1 #!/bin/sh
      2 #
      3 # Run the code in test.jar using the host-mode virtual machine. The jar should
      4 # contain a top-level class named Main to run.
      5 
      6 msg() {
      7     if [ "$QUIET" = "n" ]; then
      8         echo "$@"
      9     fi
     10 }
     11 
     12 DEBUGGER="n"
     13 PREBUILD="n"
     14 GDB="n"
     15 ISA="x86"
     16 INTERPRETER="n"
     17 VERIFY="y"
     18 RELOCATE="y"
     19 OPTIMIZE="y"
     20 INVOKE_WITH=""
     21 DEV_MODE="n"
     22 QUIET="n"
     23 FLAGS=""
     24 COMPILER_FLAGS=""
     25 BUILD_BOOT_OPT=""
     26 exe="${ANDROID_HOST_OUT}/bin/dalvikvm32"
     27 main="Main"
     28 
     29 while true; do
     30     if [ "x$1" = "x--quiet" ]; then
     31         QUIET="y"
     32         shift
     33     elif [ "x$1" = "x--prebuild" ]; then
     34         PREBUILD="y"
     35         shift
     36     elif [ "x$1" = "x--lib" ]; then
     37         shift
     38         if [ "x$1" = "x" ]; then
     39             echo "$0 missing argument to --lib" 1>&2
     40             exit 1
     41         fi
     42         LIB="$1"
     43         if [ `uname` = "Darwin" ]; then
     44             LIB=${LIB/%so/dylib}
     45         fi
     46         shift
     47     elif [ "x$1" = "x--boot" ]; then
     48         shift
     49         option="$1"
     50         BOOT_OPT="$option"
     51         BUILD_BOOT_OPT="--boot-image=${option#-Ximage:}"
     52         shift
     53     elif [ "x$1" = "x--debug" ]; then
     54         DEBUGGER="y"
     55         shift
     56     elif [ "x$1" = "x--gdb" ]; then
     57         GDB="y"
     58         DEV_MODE="y"
     59         shift
     60     elif [ "x$1" = "x--invoke-with" ]; then
     61         shift
     62         if [ "x$1" = "x" ]; then
     63             echo "$0 missing argument to --invoke-with" 1>&2
     64             exit 1
     65         fi
     66         if [ "x$INVOKE_WITH" = "x" ]; then
     67             INVOKE_WITH="$1"
     68         else
     69             INVOKE_WITH="$INVOKE_WITH $1"
     70         fi
     71         shift
     72     elif [ "x$1" = "x--dev" ]; then
     73         DEV_MODE="y"
     74         shift
     75     elif [ "x$1" = "x--interpreter" ]; then
     76         INTERPRETER="y"
     77         shift
     78     elif [ "x$1" = "x--64" ]; then
     79         ISA="x86_64"
     80         exe="${ANDROID_HOST_OUT}/bin/dalvikvm64"
     81         shift
     82     elif [ "x$1" = "x--no-verify" ]; then
     83         VERIFY="n"
     84         shift
     85     elif [ "x$1" = "x--no-optimize" ]; then
     86         OPTIMIZE="n"
     87         shift
     88     elif [ "x$1" = "x--no-relocate" ]; then
     89         RELOCATE="n"
     90         shift
     91     elif [ "x$1" = "x--relocate" ]; then
     92         RELOCATE="y"
     93         shift
     94     elif [ "x$1" = "x-Xcompiler-option" ]; then
     95         shift
     96         option="$1"
     97         FLAGS="${FLAGS} -Xcompiler-option $option"
     98         COMPILER_FLAGS="${COMPILER_FLAGS} $option"
     99         shift
    100     elif [ "x$1" = "x--runtime-option" ]; then
    101         shift
    102         option="$1"
    103         FLAGS="${FLAGS} $option"
    104         shift
    105     elif [ "x$1" = "x--" ]; then
    106         shift
    107         break
    108     elif expr "x$1" : "x--" >/dev/null 2>&1; then
    109         echo "unknown $0 option: $1" 1>&2
    110         exit 1
    111     else
    112         break
    113     fi
    114 done
    115 
    116 if [ "x$1" = "x" ] ; then
    117   main="Main"
    118 else
    119   main="$1"
    120 fi
    121 
    122 msg "------------------------------"
    123 
    124 export ANDROID_PRINTF_LOG=brief
    125 if [ "$DEV_MODE" = "y" ]; then
    126     export ANDROID_LOG_TAGS='*:d'
    127 else
    128     export ANDROID_LOG_TAGS='*:s'
    129 fi
    130 export ANDROID_DATA="$DEX_LOCATION"
    131 export ANDROID_ROOT="${ANDROID_HOST_OUT}"
    132 export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
    133 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
    134 
    135 if [ "$DEBUGGER" = "y" ]; then
    136     PORT=8000
    137     msg "Waiting for jdb to connect:"
    138     msg "    jdb -attach localhost:$PORT"
    139     DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
    140 fi
    141 
    142 if [ "$GDB" = "y" ]; then
    143     if [ `uname` = "Darwin" ]; then
    144         gdb=lldb
    145         gdbargs="-- $exe"
    146         exe=
    147     else
    148         gdb=gdb
    149         gdbargs="--args $exe"
    150         # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
    151         # gdbargs="--annotate=3 $gdbargs"
    152     fi
    153 fi
    154 
    155 if [ "$INTERPRETER" = "y" ]; then
    156     INT_OPTS="-Xint"
    157     COMPILER_FLAGS="${COMPILER_FLAGS} --compiler-filter=interpret-only"
    158 fi
    159 
    160 if [ "$RELOCATE" = "y" ]; then
    161   FLAGS="${FLAGS} -Xrelocate"
    162   COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -Xnorelocate --include-patch-information"
    163   # Run test sets a fairly draconian ulimit that we will likely blow right over
    164   # since we are relocating. Get the total size of the /system/framework directory
    165   # in 512 byte blocks and set it as the ulimit. This should be more than enough
    166   # room.
    167   if [ ! `uname` = "Darwin" ]; then  # TODO: Darwin doesn't support "du -B..."
    168     ulimit -S $(du -c -B512 ${ANDROID_ROOT}/framework | tail -1 | cut -f1) || exit 1
    169   fi
    170 else
    171   FLAGS="${FLAGS} -Xnorelocate"
    172   COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -Xnorelocate --no-include-patch-information"
    173 fi
    174 
    175 mkdir_cmd="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
    176 if [ "$PREBUILD" = "y" ]; then
    177   prebuild_cmd="${ANDROID_HOST_OUT}/bin/dex2oatd $COMPILER_FLAGS --instruction-set=$ISA $BUILD_BOOT_OPT --dex-file=$DEX_LOCATION/$TEST_NAME.jar --oat-file=$DEX_LOCATION/dalvik-cache/$ISA/$(echo $DEX_LOCATION/$TEST_NAME.jar/classes.dex | cut -d/ -f 2- | sed "s:/:@:g")"
    178 else
    179   prebuild_cmd="true"
    180 fi
    181 
    182 JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
    183 cmdline="$INVOKE_WITH $gdb $exe $gdbargs -XXlib:$LIB $JNI_OPTS $FLAGS $INT_OPTS $DEBUGGER_OPTS $BOOT_OPT -cp $DEX_LOCATION/$TEST_NAME.jar $main"
    184 if [ "$DEV_MODE" = "y" ]; then
    185   if [ "$PREBUILD" = "y" ]; then
    186     echo "$mkdir_cmd && $prebuild_cmd && $cmdline"
    187   elif [ "$RELOCATE" = "y" ]; then
    188     echo "$mkdir_cmd && $cmdline"
    189   else
    190     echo $cmdline
    191   fi
    192 fi
    193 
    194 cd $ANDROID_BUILD_TOP
    195 $mkdir_cmd && $prebuild_cmd && LD_PRELOAD=libsigchain.so $cmdline "$@"
    196