jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Run the code in test.jar on the device. The jar should contain a top-level |
| 4 | # 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 |
| 9 | # --zygote -- use the zygote (if so, all other options are ignored) |
| 10 | # --dev -- development mode (print the vm invocation cmdline) |
| 11 | # --no-verify -- turn off verification (on by default) |
| 12 | # --no-optimize -- turn off optimization (on by default) |
| 13 | # --no-precise -- turn off precise GC (on by default) |
Ian Rogers | 7769f50 | 2012-02-03 18:02:28 -0800 | [diff] [blame] | 14 | # -O -- run non-debug code |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 15 | |
| 16 | msg() { |
| 17 | if [ "$QUIET" = "n" ]; then |
| 18 | echo "$@" |
| 19 | fi |
| 20 | } |
| 21 | |
Ian Rogers | 7769f50 | 2012-02-03 18:02:28 -0800 | [diff] [blame] | 22 | OATEXEC="oatexecd" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 23 | DEBUG="n" |
| 24 | VERIFY="y" |
| 25 | OPTIMIZE="y" |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 26 | ZYGOTE="" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 27 | QUIET="n" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 28 | DEV_MODE="n" |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 29 | INVOKE_WITH="" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 30 | |
| 31 | while true; do |
| 32 | if [ "x$1" = "x--quiet" ]; then |
| 33 | QUIET="y" |
| 34 | shift |
Ian Rogers | 7769f50 | 2012-02-03 18:02:28 -0800 | [diff] [blame] | 35 | elif [ "x$1" = "x-O" ]; then |
| 36 | OATEXEC="oatexec" |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 37 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 38 | elif [ "x$1" = "x--debug" ]; then |
| 39 | DEBUG="y" |
| 40 | shift |
| 41 | elif [ "x$1" = "x--zygote" ]; then |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 42 | ZYGOTE="--zygote" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 43 | msg "Spawning from zygote" |
| 44 | shift |
| 45 | elif [ "x$1" = "x--dev" ]; then |
| 46 | DEV_MODE="y" |
| 47 | shift |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 48 | elif [ "x$1" = "x--invoke-with" ]; then |
| 49 | shift |
| 50 | INVOKE_WITH="$1" |
| 51 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 52 | elif [ "x$1" = "x--no-verify" ]; then |
| 53 | VERIFY="n" |
| 54 | shift |
| 55 | elif [ "x$1" = "x--no-optimize" ]; then |
| 56 | OPTIMIZE="n" |
| 57 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 58 | elif [ "x$1" = "x--" ]; then |
| 59 | shift |
| 60 | break |
| 61 | elif expr "x$1" : "x--" >/dev/null 2>&1; then |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 62 | echo "unknown $0 option: $1" 1>&2 |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 63 | exit 1 |
| 64 | else |
| 65 | break |
| 66 | fi |
| 67 | done |
| 68 | |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 69 | if [ "$ZYGOTE" = "" ]; then |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 70 | if [ "$OPTIMIZE" = "y" ]; then |
| 71 | if [ "$VERIFY" = "y" ]; then |
| 72 | DEX_OPTIMIZE="-Xdexopt:verified" |
| 73 | else |
| 74 | DEX_OPTIMIZE="-Xdexopt:all" |
| 75 | fi |
| 76 | msg "Performing optimizations" |
| 77 | else |
| 78 | DEX_OPTIMIZE="-Xdexopt:none" |
| 79 | msg "Skipping optimizations" |
| 80 | fi |
| 81 | |
| 82 | if [ "$VERIFY" = "y" ]; then |
| 83 | DEX_VERIFY="" |
| 84 | msg "Performing verification" |
| 85 | else |
| 86 | DEX_VERIFY="-Xverify:none" |
| 87 | msg "Skipping verification" |
| 88 | fi |
| 89 | fi |
| 90 | |
| 91 | msg "------------------------------" |
| 92 | |
| 93 | if [ "$QUIET" = "n" ]; then |
Brian Carlstrom | 4ec9b1f | 2012-06-17 22:27:43 -0700 | [diff] [blame^] | 94 | adb shell rm -r $DEX_LOCATION |
Brian Carlstrom | 105215d | 2012-06-14 12:50:44 -0700 | [diff] [blame] | 95 | adb shell mkdir -p $DEX_LOCATION |
| 96 | adb push $TEST_NAME.jar $DEX_LOCATION |
| 97 | adb push $TEST_NAME-ex.jar $DEX_LOCATION |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 98 | else |
Brian Carlstrom | 4ec9b1f | 2012-06-17 22:27:43 -0700 | [diff] [blame^] | 99 | adb shell rm -r $DEX_LOCATION >/dev/null 2>&1 |
Brian Carlstrom | 105215d | 2012-06-14 12:50:44 -0700 | [diff] [blame] | 100 | adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1 |
| 101 | adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1 |
| 102 | adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1 |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 103 | fi |
| 104 | |
| 105 | if [ "$DEBUG" = "y" ]; then |
Elliott Hughes | 72395bf | 2012-04-24 13:45:26 -0700 | [diff] [blame] | 106 | # Use this instead for ddms and connect by running 'ddms': |
| 107 | # DEBUG_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y" |
| 108 | # TODO: add a separate --ddms option? |
Elliott Hughes | d1cc836 | 2011-10-24 16:58:50 -0700 | [diff] [blame] | 109 | |
Elliott Hughes | 72395bf | 2012-04-24 13:45:26 -0700 | [diff] [blame] | 110 | PORT=12345 |
| 111 | msg "Waiting for jdb to connect:" |
| 112 | msg " adb forward tcp:$PORT tcp:$PORT" |
| 113 | msg " jdb -attach localhost:$PORT" |
| 114 | DEBUG_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 115 | fi |
| 116 | |
Elliott Hughes | 72395bf | 2012-04-24 13:45:26 -0700 | [diff] [blame] | 117 | JNI_OPTS="-Xjnigreflimit:256 -Xcheck:jni" |
| 118 | |
Brian Carlstrom | 105215d | 2012-06-14 12:50:44 -0700 | [diff] [blame] | 119 | cmdline="cd $DEX_LOCATION && mkdir art-cache && export ANDROID_DATA=$DEX_LOCATION && export DEX_LOCATION=$DEX_LOCATION && \ |
| 120 | $INVOKE_WITH $OATEXEC $ZYGOTE $JNI_OPTS $DEBUG_OPTS -Ximage:/data/art-test/core.art -cp $DEX_LOCATION/$TEST_NAME.jar Main" |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 121 | if [ "$DEV_MODE" = "y" ]; then |
| 122 | echo $cmdline "$@" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 123 | fi |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 124 | |
| 125 | adb shell $cmdline "$@" |