jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 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 | # Options: |
| 7 | # --quiet -- don't chatter |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 8 | # --debug -- wait for debugger to attach |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 9 | # --no-verify -- turn off verification (on by default) |
| 10 | # --no-optimize -- turn off optimization (on by default) |
| 11 | |
| 12 | msg() { |
| 13 | if [ "$QUIET" = "n" ]; then |
| 14 | echo "$@" |
| 15 | fi |
| 16 | } |
| 17 | |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 18 | DEBUG="n" |
| 19 | GDB="n" |
| 20 | VERIFY="y" |
| 21 | OPTIMIZE="y" |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame^] | 22 | INVOKE_WITH="" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 23 | DEV_MODE="n" |
| 24 | QUIET="n" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 25 | |
| 26 | while true; do |
| 27 | if [ "x$1" = "x--quiet" ]; then |
| 28 | QUIET="y" |
| 29 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 30 | elif [ "x$1" = "x--debug" ]; then |
| 31 | DEBUG="y" |
| 32 | shift |
| 33 | elif [ "x$1" = "x--gdb" ]; then |
| 34 | GDB="y" |
| 35 | shift |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame^] | 36 | elif [ "x$1" = "x--invoke-with" ]; then |
| 37 | shift |
| 38 | INVOKE_WITH="$1" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 39 | shift |
| 40 | elif [ "x$1" = "x--dev" ]; then |
| 41 | DEV_MODE="y" |
| 42 | shift |
| 43 | elif [ "x$1" = "x--no-verify" ]; then |
| 44 | VERIFY="n" |
| 45 | shift |
| 46 | elif [ "x$1" = "x--no-optimize" ]; then |
| 47 | OPTIMIZE="n" |
| 48 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 49 | elif [ "x$1" = "x--" ]; then |
| 50 | shift |
| 51 | break |
| 52 | elif expr "x$1" : "x--" >/dev/null 2>&1; then |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame^] | 53 | echo "unknown $0 option: $1" 1>&2 |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 54 | exit 1 |
| 55 | else |
| 56 | break |
| 57 | fi |
| 58 | done |
| 59 | |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 60 | if [ "$OPTIMIZE" = "y" ]; then |
| 61 | if [ "$VERIFY" = "y" ]; then |
| 62 | DEX_OPTIMIZE="-Xdexopt:verified" |
| 63 | else |
| 64 | DEX_OPTIMIZE="-Xdexopt:all" |
| 65 | fi |
| 66 | msg "Performing optimizations" |
| 67 | else |
| 68 | DEX_OPTIMIZE="-Xdexopt:none" |
| 69 | msg "Skipping optimizations" |
| 70 | fi |
| 71 | |
| 72 | if [ "$VERIFY" = "y" ]; then |
| 73 | DEX_VERIFY="" |
| 74 | msg "Performing verification" |
| 75 | else |
| 76 | DEX_VERIFY="-Xverify:none" |
| 77 | msg "Skipping verification" |
| 78 | fi |
| 79 | |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 80 | msg "------------------------------" |
| 81 | |
| 82 | HOSTBASE="${ANDROID_BUILD_TOP}/out/host" |
| 83 | BASE="$OUT" # from build environment |
| 84 | DATA_DIR=/tmp |
| 85 | DEBUG_OPTS="-Xcheck:jni -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n" |
| 86 | |
| 87 | if [ ! -d $DATA_DIR/dalvik-cache ]; then |
| 88 | mkdir -p $DATA_DIR/dalvik-cache |
| 89 | [[ $? -ne 0 ]] && exit |
| 90 | fi |
| 91 | |
| 92 | export ANDROID_PRINTF_LOG=brief |
| 93 | if [ "$DEV_MODE" = "y" ]; then |
| 94 | export ANDROID_LOG_TAGS='*:d' |
| 95 | else |
| 96 | export ANDROID_LOG_TAGS='*:s' |
| 97 | fi |
| 98 | export ANDROID_DATA="$DATA_DIR" |
| 99 | export ANDROID_ROOT="${HOSTBASE}/linux-x86" |
| 100 | export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib" |
| 101 | export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib" |
| 102 | |
| 103 | exe="${ANDROID_ROOT}/bin/dalvikvm" |
| 104 | framework="${BASE}/system/framework" |
| 105 | bpath="${framework}/core.jar:${framework}/ext.jar:${framework}/framework.jar" |
| 106 | |
| 107 | if [ "$DEBUG" = "y" ]; then |
| 108 | PORT=8000 |
| 109 | msg "Waiting for debugger to connect on localhost:$PORT" |
| 110 | DEX_DEBUG="-agentlib:jdwp=transport=dt_socket,addres=$PORT,server=y,suspend=y" |
| 111 | fi |
| 112 | |
| 113 | if [ "$GDB" = "y" ]; then |
| 114 | gdb=gdb |
| 115 | gdbargs="--args $exe" |
| 116 | fi |
| 117 | |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame^] | 118 | $INVOKE_WITH $gdb $exe $gdbargs "-Xbootclasspath:${bpath}" \ |
Elliott Hughes | bb1e8f0 | 2011-10-18 14:14:25 -0700 | [diff] [blame] | 119 | $DEX_VERIFY $DEX_OPTIMIZE $DEX_DEBUG -ea \ |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 120 | -cp test.jar Main "$@" |