blob: 776a01146d6b2b14d4358fa6e1cf1b2836a86a44 [file] [log] [blame]
jeffhao5d1ac922011-09-29 17:41:15 -07001#!/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.
jeffhao5d1ac922011-09-29 17:41:15 -07005
6msg() {
7 if [ "$QUIET" = "n" ]; then
8 echo "$@"
9 fi
10}
11
Alex Lighta59dd802014-07-02 16:28:08 -070012RELOCATE="y"
Ian Rogers4c1bf1a2012-12-11 10:44:28 -080013GDB="n"
Brian Carlstromfa42b442013-06-17 12:53:45 -070014DEBUGGER="n"
jeffhao0dff3f42012-11-20 15:13:43 -080015INTERPRETER="n"
jeffhao5d1ac922011-09-29 17:41:15 -070016VERIFY="y"
17OPTIMIZE="y"
Elliott Hughes58bcc402012-02-14 14:10:10 -080018ZYGOTE=""
jeffhao5d1ac922011-09-29 17:41:15 -070019QUIET="n"
jeffhao5d1ac922011-09-29 17:41:15 -070020DEV_MODE="n"
Elliott Hughes7c046102011-10-19 18:16:03 -070021INVOKE_WITH=""
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000022FLAGS=""
Andreas Gampeafbaa1a2014-03-25 18:09:32 -070023TARGET_SUFFIX=""
jeffhao5d1ac922011-09-29 17:41:15 -070024
25while true; do
26 if [ "x$1" = "x--quiet" ]; then
27 QUIET="y"
28 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070029 elif [ "x$1" = "x--lib" ]; then
Brian Carlstromfa42b442013-06-17 12:53:45 -070030 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070031 if [ "x$1" = "x" ]; then
32 echo "$0 missing argument to --lib" 1>&2
33 exit 1
34 fi
Brian Carlstromfa42b442013-06-17 12:53:45 -070035 LIB="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -070036 shift
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000037 elif [ "x$1" = "x-Xcompiler-option" ]; then
38 shift
39 option="$1"
40 FLAGS="${FLAGS} -Xcompiler-option $option"
41 shift
Mathieu Chartier769a5ad2014-05-18 15:30:10 -070042 elif [ "x$1" = "x--runtime-option" ]; then
43 shift
44 option="$1"
45 FLAGS="${FLAGS} $option"
46 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070047 elif [ "x$1" = "x--boot" ]; then
48 shift
49 BOOT_OPT="$1"
Elliott Hughes7c046102011-10-19 18:16:03 -070050 shift
jeffhao5d1ac922011-09-29 17:41:15 -070051 elif [ "x$1" = "x--debug" ]; then
Brian Carlstromfa42b442013-06-17 12:53:45 -070052 DEBUGGER="y"
jeffhao5d1ac922011-09-29 17:41:15 -070053 shift
Ian Rogers4c1bf1a2012-12-11 10:44:28 -080054 elif [ "x$1" = "x--gdb" ]; then
55 GDB="y"
56 DEV_MODE="y"
57 shift
jeffhao5d1ac922011-09-29 17:41:15 -070058 elif [ "x$1" = "x--zygote" ]; then
Elliott Hughes58bcc402012-02-14 14:10:10 -080059 ZYGOTE="--zygote"
jeffhao5d1ac922011-09-29 17:41:15 -070060 msg "Spawning from zygote"
61 shift
62 elif [ "x$1" = "x--dev" ]; then
63 DEV_MODE="y"
64 shift
Alex Lighta59dd802014-07-02 16:28:08 -070065 elif [ "x$1" = "x--relocate" ]; then
66 RELOCATE="y"
67 shift
68 elif [ "x$1" = "x--no-relocate" ]; then
69 RELOCATE="n"
70 shift
jeffhao0dff3f42012-11-20 15:13:43 -080071 elif [ "x$1" = "x--interpreter" ]; then
72 INTERPRETER="y"
73 shift
Elliott Hughes7c046102011-10-19 18:16:03 -070074 elif [ "x$1" = "x--invoke-with" ]; then
75 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070076 if [ "x$1" = "x" ]; then
77 echo "$0 missing argument to --invoke-with" 1>&2
78 exit 1
79 fi
Ian Rogers0e033672013-04-19 10:22:46 -070080 if [ "x$INVOKE_WITH" = "x" ]; then
81 INVOKE_WITH="$1"
82 else
83 INVOKE_WITH="$INVOKE_WITH $1"
84 fi
Elliott Hughes7c046102011-10-19 18:16:03 -070085 shift
jeffhao5d1ac922011-09-29 17:41:15 -070086 elif [ "x$1" = "x--no-verify" ]; then
87 VERIFY="n"
88 shift
89 elif [ "x$1" = "x--no-optimize" ]; then
90 OPTIMIZE="n"
91 shift
jeffhao5d1ac922011-09-29 17:41:15 -070092 elif [ "x$1" = "x--" ]; then
93 shift
94 break
Andreas Gampeafbaa1a2014-03-25 18:09:32 -070095 elif [ "x$1" = "x--64" ]; then
96 TARGET_SUFFIX="64"
97 shift
jeffhao5d1ac922011-09-29 17:41:15 -070098 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -070099 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700100 exit 1
101 else
102 break
103 fi
104done
105
Elliott Hughes58bcc402012-02-14 14:10:10 -0800106if [ "$ZYGOTE" = "" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700107 if [ "$OPTIMIZE" = "y" ]; then
108 if [ "$VERIFY" = "y" ]; then
109 DEX_OPTIMIZE="-Xdexopt:verified"
110 else
111 DEX_OPTIMIZE="-Xdexopt:all"
112 fi
113 msg "Performing optimizations"
114 else
115 DEX_OPTIMIZE="-Xdexopt:none"
116 msg "Skipping optimizations"
117 fi
118
119 if [ "$VERIFY" = "y" ]; then
120 DEX_VERIFY=""
121 msg "Performing verification"
122 else
123 DEX_VERIFY="-Xverify:none"
124 msg "Skipping verification"
125 fi
126fi
127
128msg "------------------------------"
129
130if [ "$QUIET" = "n" ]; then
Brian Carlstrom4ec9b1f2012-06-17 22:27:43 -0700131 adb shell rm -r $DEX_LOCATION
Brian Carlstrom105215d2012-06-14 12:50:44 -0700132 adb shell mkdir -p $DEX_LOCATION
133 adb push $TEST_NAME.jar $DEX_LOCATION
134 adb push $TEST_NAME-ex.jar $DEX_LOCATION
jeffhao5d1ac922011-09-29 17:41:15 -0700135else
Brian Carlstrom4ec9b1f2012-06-17 22:27:43 -0700136 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
Brian Carlstrom105215d2012-06-14 12:50:44 -0700137 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
138 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
139 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
jeffhao5d1ac922011-09-29 17:41:15 -0700140fi
141
Brian Carlstromfa42b442013-06-17 12:53:45 -0700142if [ "$DEBUGGER" = "y" ]; then
Elliott Hughes72395bf2012-04-24 13:45:26 -0700143 # Use this instead for ddms and connect by running 'ddms':
Brian Carlstromfa42b442013-06-17 12:53:45 -0700144 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
Elliott Hughes72395bf2012-04-24 13:45:26 -0700145 # TODO: add a separate --ddms option?
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700146
Elliott Hughes72395bf2012-04-24 13:45:26 -0700147 PORT=12345
148 msg "Waiting for jdb to connect:"
149 msg " adb forward tcp:$PORT tcp:$PORT"
150 msg " jdb -attach localhost:$PORT"
Brian Carlstromfa42b442013-06-17 12:53:45 -0700151 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
jeffhao5d1ac922011-09-29 17:41:15 -0700152fi
153
Ian Rogers4c1bf1a2012-12-11 10:44:28 -0800154if [ "$GDB" = "y" ]; then
Andreas Gamped6728432014-05-01 08:47:51 -0700155 gdb="gdbserver$TARGET_SUFFIX :5039"
Ian Rogersee043fc2014-03-11 11:30:20 -0700156 gdbargs="$exe"
Ian Rogers4c1bf1a2012-12-11 10:44:28 -0800157fi
158
jeffhao0dff3f42012-11-20 15:13:43 -0800159if [ "$INTERPRETER" = "y" ]; then
160 INT_OPTS="-Xint"
161fi
162
Mathieu Chartierdbe6f462012-09-25 16:54:50 -0700163JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
Elliott Hughes72395bf2012-04-24 13:45:26 -0700164
Alex Lighta59dd802014-07-02 16:28:08 -0700165if [ "$RELOCATE" = "y" ]; then
166 RELOCATE_OPT="-Xrelocate"
167 FLAGS="${FLAGS} -Xcompiler-option --include-patch-information"
168else
169 RELOCATE_OPT="-Xnorelocate"
170fi
171
Brian Carlstrom41ccffd2014-05-06 10:37:30 -0700172cmdline="cd $DEX_LOCATION && export ANDROID_DATA=$DEX_LOCATION && export DEX_LOCATION=$DEX_LOCATION && \
Alex Lighta59dd802014-07-02 16:28:08 -0700173 $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 Hughes58bcc402012-02-14 14:10:10 -0800174if [ "$DEV_MODE" = "y" ]; then
175 echo $cmdline "$@"
jeffhao5d1ac922011-09-29 17:41:15 -0700176fi
Elliott Hughes58bcc402012-02-14 14:10:10 -0800177
178adb shell $cmdline "$@"