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 | |
Nicolas Geoffray | 5fd18ba | 2014-10-03 12:08:38 +0100 | [diff] [blame] | 12 | ARCHITECTURES_32="(arm|x86|mips|none)" |
| 13 | ARCHITECTURES_64="(arm64|x86_64|none)" |
| 14 | ARCHITECTURES_PATTERN="${ARCHITECTURES_32}" |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 15 | RELOCATE="y" |
Ian Rogers | 4c1bf1a | 2012-12-11 10:44:28 -0800 | [diff] [blame] | 16 | GDB="n" |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 17 | DEBUGGER="n" |
jeffhao | 0dff3f4 | 2012-11-20 15:13:43 -0800 | [diff] [blame] | 18 | INTERPRETER="n" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 19 | VERIFY="y" |
| 20 | OPTIMIZE="y" |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 21 | ZYGOTE="" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 22 | QUIET="n" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 23 | DEV_MODE="n" |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 24 | INVOKE_WITH="" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 25 | FLAGS="" |
Alex Light | fc0082b | 2014-07-29 18:31:18 -0700 | [diff] [blame] | 26 | TARGET_SUFFIX="32" |
| 27 | GDB_TARGET_SUFFIX="" |
Nicolas Geoffray | 5fd18ba | 2014-10-03 12:08:38 +0100 | [diff] [blame] | 28 | COMPILE_FLAGS="" |
Alex Light | 03a112d | 2014-08-25 13:25:56 -0700 | [diff] [blame] | 29 | FALSE_BIN="/system/bin/false" |
| 30 | PATCHOAT="" |
| 31 | DEX2OAT="" |
| 32 | HAVE_IMAGE="y" |
Nicolas Geoffray | 5fd18ba | 2014-10-03 12:08:38 +0100 | [diff] [blame] | 33 | PREBUILD="y" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 34 | |
| 35 | while true; do |
| 36 | if [ "x$1" = "x--quiet" ]; then |
| 37 | QUIET="y" |
| 38 | shift |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 39 | elif [ "x$1" = "x--lib" ]; then |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 40 | shift |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 41 | if [ "x$1" = "x" ]; then |
| 42 | echo "$0 missing argument to --lib" 1>&2 |
| 43 | exit 1 |
| 44 | fi |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 45 | LIB="$1" |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 46 | shift |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 47 | elif [ "x$1" = "x-Xcompiler-option" ]; then |
| 48 | shift |
| 49 | option="$1" |
| 50 | FLAGS="${FLAGS} -Xcompiler-option $option" |
Nicolas Geoffray | 5fd18ba | 2014-10-03 12:08:38 +0100 | [diff] [blame] | 51 | COMPILE_FLAGS="${COMPILE_FLAGS} $option" |
Alex Light | 03a112d | 2014-08-25 13:25:56 -0700 | [diff] [blame] | 52 | shift |
Mathieu Chartier | 769a5ad | 2014-05-18 15:30:10 -0700 | [diff] [blame] | 53 | elif [ "x$1" = "x--runtime-option" ]; then |
| 54 | shift |
| 55 | option="$1" |
| 56 | FLAGS="${FLAGS} $option" |
| 57 | shift |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 58 | elif [ "x$1" = "x--boot" ]; then |
| 59 | shift |
| 60 | BOOT_OPT="$1" |
Nicolas Geoffray | 5fd18ba | 2014-10-03 12:08:38 +0100 | [diff] [blame] | 61 | BUILD_BOOT_OPT="--boot-image=${1#-Ximage:}" |
| 62 | shift |
| 63 | elif [ "x$1" = "x--no-dex2oat" ]; then |
| 64 | DEX2OAT="-Xcompiler:${FALSE_BIN}" |
| 65 | shift |
| 66 | elif [ "x$1" = "x--no-patchoat" ]; then |
| 67 | PATCHOAT="-Xpatchoat:${FALSE_BIN}" |
| 68 | shift |
| 69 | elif [ "x$1" = "x--relocate" ]; then |
| 70 | RELOCATE="y" |
| 71 | shift |
| 72 | elif [ "x$1" = "x--no-relocate" ]; then |
| 73 | RELOCATE="n" |
| 74 | shift |
| 75 | elif [ "x$1" = "x--prebuild" ]; then |
| 76 | PREBUILD="y" |
| 77 | shift |
| 78 | elif [ "x$1" = "x--no-prebuild" ]; then |
| 79 | PREBUILD="n" |
| 80 | shift |
| 81 | elif [ "x$1" = "x--no-image" ]; then |
| 82 | HAVE_IMAGE="n" |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 83 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 84 | elif [ "x$1" = "x--debug" ]; then |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 85 | DEBUGGER="y" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 86 | shift |
Ian Rogers | 4c1bf1a | 2012-12-11 10:44:28 -0800 | [diff] [blame] | 87 | elif [ "x$1" = "x--gdb" ]; then |
| 88 | GDB="y" |
| 89 | DEV_MODE="y" |
| 90 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 91 | elif [ "x$1" = "x--zygote" ]; then |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 92 | ZYGOTE="--zygote" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 93 | msg "Spawning from zygote" |
| 94 | shift |
| 95 | elif [ "x$1" = "x--dev" ]; then |
| 96 | DEV_MODE="y" |
| 97 | shift |
jeffhao | 0dff3f4 | 2012-11-20 15:13:43 -0800 | [diff] [blame] | 98 | elif [ "x$1" = "x--interpreter" ]; then |
| 99 | INTERPRETER="y" |
| 100 | shift |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 101 | elif [ "x$1" = "x--invoke-with" ]; then |
| 102 | shift |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 103 | if [ "x$1" = "x" ]; then |
| 104 | echo "$0 missing argument to --invoke-with" 1>&2 |
| 105 | exit 1 |
| 106 | fi |
Ian Rogers | 0e03367 | 2013-04-19 10:22:46 -0700 | [diff] [blame] | 107 | if [ "x$INVOKE_WITH" = "x" ]; then |
| 108 | INVOKE_WITH="$1" |
| 109 | else |
| 110 | INVOKE_WITH="$INVOKE_WITH $1" |
| 111 | fi |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 112 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 113 | elif [ "x$1" = "x--no-verify" ]; then |
| 114 | VERIFY="n" |
| 115 | shift |
| 116 | elif [ "x$1" = "x--no-optimize" ]; then |
| 117 | OPTIMIZE="n" |
| 118 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 119 | elif [ "x$1" = "x--" ]; then |
| 120 | shift |
| 121 | break |
Andreas Gampe | afbaa1a | 2014-03-25 18:09:32 -0700 | [diff] [blame] | 122 | elif [ "x$1" = "x--64" ]; then |
| 123 | TARGET_SUFFIX="64" |
Alex Light | fc0082b | 2014-07-29 18:31:18 -0700 | [diff] [blame] | 124 | GDB_TARGET_SUFFIX="64" |
Nicolas Geoffray | 5fd18ba | 2014-10-03 12:08:38 +0100 | [diff] [blame] | 125 | ARCHITECTURES_PATTERN="${ARCHITECTURES_64}" |
Andreas Gampe | afbaa1a | 2014-03-25 18:09:32 -0700 | [diff] [blame] | 126 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 127 | elif expr "x$1" : "x--" >/dev/null 2>&1; then |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 128 | echo "unknown $0 option: $1" 1>&2 |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 129 | exit 1 |
| 130 | else |
| 131 | break |
| 132 | fi |
| 133 | done |
| 134 | |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 135 | if [ "$ZYGOTE" = "" ]; then |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 136 | if [ "$OPTIMIZE" = "y" ]; then |
| 137 | if [ "$VERIFY" = "y" ]; then |
| 138 | DEX_OPTIMIZE="-Xdexopt:verified" |
| 139 | else |
| 140 | DEX_OPTIMIZE="-Xdexopt:all" |
| 141 | fi |
| 142 | msg "Performing optimizations" |
| 143 | else |
| 144 | DEX_OPTIMIZE="-Xdexopt:none" |
| 145 | msg "Skipping optimizations" |
| 146 | fi |
| 147 | |
| 148 | if [ "$VERIFY" = "y" ]; then |
| 149 | DEX_VERIFY="" |
| 150 | msg "Performing verification" |
| 151 | else |
| 152 | DEX_VERIFY="-Xverify:none" |
| 153 | msg "Skipping verification" |
| 154 | fi |
| 155 | fi |
| 156 | |
| 157 | msg "------------------------------" |
| 158 | |
Alex Light | 03a112d | 2014-08-25 13:25:56 -0700 | [diff] [blame] | 159 | if [ "$HAVE_IMAGE" = "n" ]; then |
Alex Light | 1ef4ce8 | 2014-08-27 11:13:47 -0700 | [diff] [blame] | 160 | BOOT_OPT="-Ximage:/system/non-existant/core.art" |
Alex Light | 03a112d | 2014-08-25 13:25:56 -0700 | [diff] [blame] | 161 | fi |
| 162 | |
Nicolas Geoffray | 5fd18ba | 2014-10-03 12:08:38 +0100 | [diff] [blame] | 163 | ARCH=$(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}") |
| 164 | if [ x"$ARCH" = "x" ]; then |
| 165 | echo "Unable to determine architecture" |
| 166 | exit 1 |
| 167 | fi |
| 168 | |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 169 | if [ "$QUIET" = "n" ]; then |
Brian Carlstrom | 4ec9b1f | 2012-06-17 22:27:43 -0700 | [diff] [blame] | 170 | adb shell rm -r $DEX_LOCATION |
Brian Carlstrom | 105215d | 2012-06-14 12:50:44 -0700 | [diff] [blame] | 171 | adb shell mkdir -p $DEX_LOCATION |
| 172 | adb push $TEST_NAME.jar $DEX_LOCATION |
| 173 | adb push $TEST_NAME-ex.jar $DEX_LOCATION |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 174 | else |
Brian Carlstrom | 4ec9b1f | 2012-06-17 22:27:43 -0700 | [diff] [blame] | 175 | adb shell rm -r $DEX_LOCATION >/dev/null 2>&1 |
Brian Carlstrom | 105215d | 2012-06-14 12:50:44 -0700 | [diff] [blame] | 176 | adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1 |
| 177 | adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1 |
| 178 | adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1 |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 179 | fi |
| 180 | |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 181 | if [ "$DEBUGGER" = "y" ]; then |
Elliott Hughes | 72395bf | 2012-04-24 13:45:26 -0700 | [diff] [blame] | 182 | # Use this instead for ddms and connect by running 'ddms': |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 183 | # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y" |
Elliott Hughes | 72395bf | 2012-04-24 13:45:26 -0700 | [diff] [blame] | 184 | # TODO: add a separate --ddms option? |
Elliott Hughes | d1cc836 | 2011-10-24 16:58:50 -0700 | [diff] [blame] | 185 | |
Elliott Hughes | 72395bf | 2012-04-24 13:45:26 -0700 | [diff] [blame] | 186 | PORT=12345 |
| 187 | msg "Waiting for jdb to connect:" |
| 188 | msg " adb forward tcp:$PORT tcp:$PORT" |
| 189 | msg " jdb -attach localhost:$PORT" |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 190 | DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 191 | fi |
| 192 | |
Ian Rogers | 4c1bf1a | 2012-12-11 10:44:28 -0800 | [diff] [blame] | 193 | if [ "$GDB" = "y" ]; then |
Alex Light | fc0082b | 2014-07-29 18:31:18 -0700 | [diff] [blame] | 194 | gdb="gdbserver$GDB_TARGET_SUFFIX :5039" |
Ian Rogers | ee043fc | 2014-03-11 11:30:20 -0700 | [diff] [blame] | 195 | gdbargs="$exe" |
Ian Rogers | 4c1bf1a | 2012-12-11 10:44:28 -0800 | [diff] [blame] | 196 | fi |
| 197 | |
jeffhao | 0dff3f4 | 2012-11-20 15:13:43 -0800 | [diff] [blame] | 198 | if [ "$INTERPRETER" = "y" ]; then |
| 199 | INT_OPTS="-Xint" |
Nicolas Geoffray | 5fd18ba | 2014-10-03 12:08:38 +0100 | [diff] [blame] | 200 | COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=interpret-only" |
jeffhao | 0dff3f4 | 2012-11-20 15:13:43 -0800 | [diff] [blame] | 201 | fi |
| 202 | |
Mathieu Chartier | dbe6f46 | 2012-09-25 16:54:50 -0700 | [diff] [blame] | 203 | JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni" |
Elliott Hughes | 72395bf | 2012-04-24 13:45:26 -0700 | [diff] [blame] | 204 | |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 205 | if [ "$RELOCATE" = "y" ]; then |
Nicolas Geoffray | 5fd18ba | 2014-10-03 12:08:38 +0100 | [diff] [blame] | 206 | RELOCATE_OPT="-Xrelocate" |
| 207 | BUILD_RELOCATE_OPT="--runtime-arg -Xnorelocate" |
| 208 | COMPILE_FLAGS="${COMPILE_FLAGS} --include-patch-information" |
| 209 | FLAGS="${FLAGS} -Xcompiler-option --include-patch-information" |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 210 | else |
Nicolas Geoffray | 5fd18ba | 2014-10-03 12:08:38 +0100 | [diff] [blame] | 211 | RELOCATE_OPT="-Xnorelocate" |
| 212 | BUILD_RELOCATE_OPT="--runtime-arg -Xnorelocate" |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 213 | fi |
| 214 | |
Nicolas Geoffray | 5fd18ba | 2014-10-03 12:08:38 +0100 | [diff] [blame] | 215 | # Create a script with the command. The command can get longer than the longest |
| 216 | # allowed adb command and there is no way to get the exit status from a adb shell |
| 217 | # command. |
| 218 | cmdline="cd $DEX_LOCATION && \ |
| 219 | export ANDROID_DATA=$DEX_LOCATION && \ |
| 220 | export DEX_LOCATION=$DEX_LOCATION && " |
| 221 | if [ "$PREBUILD" = "y" ]; then |
| 222 | cmdline+="mkdir -p $DEX_LOCATION/dalvik-cache/$ARCH/ && \ |
| 223 | $INVOKE_WITH /system/bin/dex2oatd \ |
| 224 | $COMPILE_FLAGS \ |
| 225 | $BUILD_BOOT_OPT \ |
| 226 | $BUILD_RELOCATE_OPT \ |
| 227 | --runtime-arg -classpath --runtime-arg $DEX_LOCATION/$TEST_NAME.jar \ |
| 228 | --dex-file=$DEX_LOCATION/$TEST_NAME.jar \ |
| 229 | --oat-file=$DEX_LOCATION/dalvik-cache/$ARCH/$(echo $DEX_LOCATION/$TEST_NAME.jar/classes.dex | cut -d/ -f 2- | sed "s:/:@:g") \ |
| 230 | --instruction-set=$ARCH && " |
| 231 | fi |
| 232 | |
| 233 | cmdline+="$INVOKE_WITH $gdb /system/bin/dalvikvm$TARGET_SUFFIX \ |
| 234 | $FLAGS \ |
| 235 | $gdbargs \ |
| 236 | -XXlib:$LIB \ |
| 237 | $PATCHOAT \ |
| 238 | $DEX2OAT \ |
| 239 | $ZYGOTE \ |
| 240 | $JNI_OPTS \ |
| 241 | $RELOCATE_OPT \ |
| 242 | $INT_OPTS \ |
| 243 | $DEBUGGER_OPTS \ |
| 244 | $BOOT_OPT \ |
| 245 | -cp $DEX_LOCATION/$TEST_NAME.jar Main" |
| 246 | |
| 247 | cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME") |
| 248 | echo "$cmdline" > $cmdfile |
| 249 | |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 250 | if [ "$DEV_MODE" = "y" ]; then |
Nicolas Geoffray | 5fd18ba | 2014-10-03 12:08:38 +0100 | [diff] [blame] | 251 | echo $cmdline |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 252 | fi |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 253 | |
Nicolas Geoffray | 5fd18ba | 2014-10-03 12:08:38 +0100 | [diff] [blame] | 254 | if [ "$QUIET" = "n" ]; then |
| 255 | adb push $cmdfile $DEX_LOCATION/cmdline.sh |
| 256 | else |
| 257 | adb push $cmdfile $DEX_LOCATION/cmdline.sh > /dev/null 2>&1 |
| 258 | fi |
| 259 | |
| 260 | adb shell sh $DEX_LOCATION/cmdline.sh |
| 261 | |
| 262 | rm -f $cmdfile |