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