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