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. |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 5 | |
| 6 | msg() { |
| 7 | if [ "$QUIET" = "n" ]; then |
| 8 | echo "$@" |
| 9 | fi |
| 10 | } |
| 11 | |
Ian Rogers | 4c1bf1a | 2012-12-11 10:44:28 -0800 | [diff] [blame] | 12 | GDB="n" |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 13 | DEBUGGER="n" |
jeffhao | 0dff3f4 | 2012-11-20 15:13:43 -0800 | [diff] [blame] | 14 | INTERPRETER="n" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 15 | VERIFY="y" |
| 16 | OPTIMIZE="y" |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 17 | ZYGOTE="" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 18 | QUIET="n" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 19 | DEV_MODE="n" |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 20 | INVOKE_WITH="" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 21 | FLAGS="" |
Andreas Gampe | afbaa1a | 2014-03-25 18:09:32 -0700 | [diff] [blame] | 22 | TARGET_SUFFIX="" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 23 | |
| 24 | while true; do |
| 25 | if [ "x$1" = "x--quiet" ]; then |
| 26 | QUIET="y" |
| 27 | shift |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 28 | elif [ "x$1" = "x--lib" ]; then |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 29 | shift |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 30 | if [ "x$1" = "x" ]; then |
| 31 | echo "$0 missing argument to --lib" 1>&2 |
| 32 | exit 1 |
| 33 | fi |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 34 | LIB="$1" |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 35 | shift |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 36 | elif [ "x$1" = "x-Xcompiler-option" ]; then |
| 37 | shift |
| 38 | option="$1" |
| 39 | FLAGS="${FLAGS} -Xcompiler-option $option" |
| 40 | shift |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 41 | elif [ "x$1" = "x--boot" ]; then |
| 42 | shift |
| 43 | BOOT_OPT="$1" |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 44 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 45 | elif [ "x$1" = "x--debug" ]; then |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 46 | DEBUGGER="y" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 47 | shift |
Ian Rogers | 4c1bf1a | 2012-12-11 10:44:28 -0800 | [diff] [blame] | 48 | elif [ "x$1" = "x--gdb" ]; then |
| 49 | GDB="y" |
| 50 | DEV_MODE="y" |
| 51 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 52 | elif [ "x$1" = "x--zygote" ]; then |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 53 | ZYGOTE="--zygote" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 54 | msg "Spawning from zygote" |
| 55 | shift |
| 56 | elif [ "x$1" = "x--dev" ]; then |
| 57 | DEV_MODE="y" |
| 58 | shift |
jeffhao | 0dff3f4 | 2012-11-20 15:13:43 -0800 | [diff] [blame] | 59 | elif [ "x$1" = "x--interpreter" ]; then |
| 60 | INTERPRETER="y" |
| 61 | shift |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 62 | elif [ "x$1" = "x--invoke-with" ]; then |
| 63 | shift |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 64 | if [ "x$1" = "x" ]; then |
| 65 | echo "$0 missing argument to --invoke-with" 1>&2 |
| 66 | exit 1 |
| 67 | fi |
Ian Rogers | 0e03367 | 2013-04-19 10:22:46 -0700 | [diff] [blame] | 68 | if [ "x$INVOKE_WITH" = "x" ]; then |
| 69 | INVOKE_WITH="$1" |
| 70 | else |
| 71 | INVOKE_WITH="$INVOKE_WITH $1" |
| 72 | fi |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 73 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 74 | elif [ "x$1" = "x--no-verify" ]; then |
| 75 | VERIFY="n" |
| 76 | shift |
| 77 | elif [ "x$1" = "x--no-optimize" ]; then |
| 78 | OPTIMIZE="n" |
| 79 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 80 | elif [ "x$1" = "x--" ]; then |
| 81 | shift |
| 82 | break |
Andreas Gampe | afbaa1a | 2014-03-25 18:09:32 -0700 | [diff] [blame] | 83 | elif [ "x$1" = "x--64" ]; then |
| 84 | TARGET_SUFFIX="64" |
| 85 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 86 | elif expr "x$1" : "x--" >/dev/null 2>&1; then |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 87 | echo "unknown $0 option: $1" 1>&2 |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 88 | exit 1 |
| 89 | else |
| 90 | break |
| 91 | fi |
| 92 | done |
| 93 | |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 94 | if [ "$ZYGOTE" = "" ]; then |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 95 | if [ "$OPTIMIZE" = "y" ]; then |
| 96 | if [ "$VERIFY" = "y" ]; then |
| 97 | DEX_OPTIMIZE="-Xdexopt:verified" |
| 98 | else |
| 99 | DEX_OPTIMIZE="-Xdexopt:all" |
| 100 | fi |
| 101 | msg "Performing optimizations" |
| 102 | else |
| 103 | DEX_OPTIMIZE="-Xdexopt:none" |
| 104 | msg "Skipping optimizations" |
| 105 | fi |
| 106 | |
| 107 | if [ "$VERIFY" = "y" ]; then |
| 108 | DEX_VERIFY="" |
| 109 | msg "Performing verification" |
| 110 | else |
| 111 | DEX_VERIFY="-Xverify:none" |
| 112 | msg "Skipping verification" |
| 113 | fi |
| 114 | fi |
| 115 | |
| 116 | msg "------------------------------" |
| 117 | |
| 118 | if [ "$QUIET" = "n" ]; then |
Brian Carlstrom | 4ec9b1f | 2012-06-17 22:27:43 -0700 | [diff] [blame] | 119 | adb shell rm -r $DEX_LOCATION |
Brian Carlstrom | 105215d | 2012-06-14 12:50:44 -0700 | [diff] [blame] | 120 | adb shell mkdir -p $DEX_LOCATION |
| 121 | adb push $TEST_NAME.jar $DEX_LOCATION |
| 122 | adb push $TEST_NAME-ex.jar $DEX_LOCATION |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 123 | else |
Brian Carlstrom | 4ec9b1f | 2012-06-17 22:27:43 -0700 | [diff] [blame] | 124 | adb shell rm -r $DEX_LOCATION >/dev/null 2>&1 |
Brian Carlstrom | 105215d | 2012-06-14 12:50:44 -0700 | [diff] [blame] | 125 | adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1 |
| 126 | adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1 |
| 127 | adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1 |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 128 | fi |
| 129 | |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 130 | if [ "$DEBUGGER" = "y" ]; then |
Elliott Hughes | 72395bf | 2012-04-24 13:45:26 -0700 | [diff] [blame] | 131 | # Use this instead for ddms and connect by running 'ddms': |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 132 | # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y" |
Elliott Hughes | 72395bf | 2012-04-24 13:45:26 -0700 | [diff] [blame] | 133 | # TODO: add a separate --ddms option? |
Elliott Hughes | d1cc836 | 2011-10-24 16:58:50 -0700 | [diff] [blame] | 134 | |
Elliott Hughes | 72395bf | 2012-04-24 13:45:26 -0700 | [diff] [blame] | 135 | PORT=12345 |
| 136 | msg "Waiting for jdb to connect:" |
| 137 | msg " adb forward tcp:$PORT tcp:$PORT" |
| 138 | msg " jdb -attach localhost:$PORT" |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 139 | DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 140 | fi |
| 141 | |
Ian Rogers | 4c1bf1a | 2012-12-11 10:44:28 -0800 | [diff] [blame] | 142 | if [ "$GDB" = "y" ]; then |
Andreas Gampe | afbaa1a | 2014-03-25 18:09:32 -0700 | [diff] [blame] | 143 | gdb="/data/gdbserver$TARGET_SUFFIX :5039" |
Ian Rogers | ee043fc | 2014-03-11 11:30:20 -0700 | [diff] [blame] | 144 | gdbargs="$exe" |
Ian Rogers | 4c1bf1a | 2012-12-11 10:44:28 -0800 | [diff] [blame] | 145 | fi |
| 146 | |
jeffhao | 0dff3f4 | 2012-11-20 15:13:43 -0800 | [diff] [blame] | 147 | if [ "$INTERPRETER" = "y" ]; then |
| 148 | INT_OPTS="-Xint" |
| 149 | fi |
| 150 | |
Mathieu Chartier | dbe6f46 | 2012-09-25 16:54:50 -0700 | [diff] [blame] | 151 | JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni" |
Elliott Hughes | 72395bf | 2012-04-24 13:45:26 -0700 | [diff] [blame] | 152 | |
Brian Carlstrom | 7675e16 | 2013-06-10 16:18:04 -0700 | [diff] [blame] | 153 | cmdline="cd $DEX_LOCATION && mkdir dalvik-cache && export ANDROID_DATA=$DEX_LOCATION && export DEX_LOCATION=$DEX_LOCATION && \ |
Andreas Gampe | afbaa1a | 2014-03-25 18:09:32 -0700 | [diff] [blame] | 154 | $INVOKE_WITH $gdb /system/bin/dalvikvm$TARGET_SUFFIX $FLAGS $gdbargs -XXlib:$LIB $ZYGOTE $JNI_OPTS $INT_OPTS $DEBUGGER_OPTS $BOOT_OPT -cp $DEX_LOCATION/$TEST_NAME.jar Main" |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 155 | if [ "$DEV_MODE" = "y" ]; then |
| 156 | echo $cmdline "$@" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 157 | fi |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 158 | |
| 159 | adb shell $cmdline "$@" |