blob: 06075c26197d2075bf78bbded69f8f64cb10420a [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=""
Alex Lightfc0082b2014-07-29 18:31:18 -070023TARGET_SUFFIX="32"
24GDB_TARGET_SUFFIX=""
jeffhao5d1ac922011-09-29 17:41:15 -070025
26while true; do
27 if [ "x$1" = "x--quiet" ]; then
28 QUIET="y"
29 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070030 elif [ "x$1" = "x--lib" ]; then
Brian Carlstromfa42b442013-06-17 12:53:45 -070031 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070032 if [ "x$1" = "x" ]; then
33 echo "$0 missing argument to --lib" 1>&2
34 exit 1
35 fi
Brian Carlstromfa42b442013-06-17 12:53:45 -070036 LIB="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -070037 shift
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000038 elif [ "x$1" = "x-Xcompiler-option" ]; then
39 shift
40 option="$1"
41 FLAGS="${FLAGS} -Xcompiler-option $option"
42 shift
Mathieu Chartier769a5ad2014-05-18 15:30:10 -070043 elif [ "x$1" = "x--runtime-option" ]; then
44 shift
45 option="$1"
46 FLAGS="${FLAGS} $option"
47 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070048 elif [ "x$1" = "x--boot" ]; then
49 shift
50 BOOT_OPT="$1"
Elliott Hughes7c046102011-10-19 18:16:03 -070051 shift
jeffhao5d1ac922011-09-29 17:41:15 -070052 elif [ "x$1" = "x--debug" ]; then
Brian Carlstromfa42b442013-06-17 12:53:45 -070053 DEBUGGER="y"
jeffhao5d1ac922011-09-29 17:41:15 -070054 shift
Ian Rogers4c1bf1a2012-12-11 10:44:28 -080055 elif [ "x$1" = "x--gdb" ]; then
56 GDB="y"
57 DEV_MODE="y"
58 shift
jeffhao5d1ac922011-09-29 17:41:15 -070059 elif [ "x$1" = "x--zygote" ]; then
Elliott Hughes58bcc402012-02-14 14:10:10 -080060 ZYGOTE="--zygote"
jeffhao5d1ac922011-09-29 17:41:15 -070061 msg "Spawning from zygote"
62 shift
63 elif [ "x$1" = "x--dev" ]; then
64 DEV_MODE="y"
65 shift
Alex Lighta59dd802014-07-02 16:28:08 -070066 elif [ "x$1" = "x--relocate" ]; then
67 RELOCATE="y"
68 shift
69 elif [ "x$1" = "x--no-relocate" ]; then
70 RELOCATE="n"
71 shift
jeffhao0dff3f42012-11-20 15:13:43 -080072 elif [ "x$1" = "x--interpreter" ]; then
73 INTERPRETER="y"
74 shift
Elliott Hughes7c046102011-10-19 18:16:03 -070075 elif [ "x$1" = "x--invoke-with" ]; then
76 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070077 if [ "x$1" = "x" ]; then
78 echo "$0 missing argument to --invoke-with" 1>&2
79 exit 1
80 fi
Ian Rogers0e033672013-04-19 10:22:46 -070081 if [ "x$INVOKE_WITH" = "x" ]; then
82 INVOKE_WITH="$1"
83 else
84 INVOKE_WITH="$INVOKE_WITH $1"
85 fi
Elliott Hughes7c046102011-10-19 18:16:03 -070086 shift
jeffhao5d1ac922011-09-29 17:41:15 -070087 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
jeffhao5d1ac922011-09-29 17:41:15 -070093 elif [ "x$1" = "x--" ]; then
94 shift
95 break
Andreas Gampeafbaa1a2014-03-25 18:09:32 -070096 elif [ "x$1" = "x--64" ]; then
97 TARGET_SUFFIX="64"
Alex Lightfc0082b2014-07-29 18:31:18 -070098 GDB_TARGET_SUFFIX="64"
Andreas Gampeafbaa1a2014-03-25 18:09:32 -070099 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700100 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700101 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700102 exit 1
103 else
104 break
105 fi
106done
107
Elliott Hughes58bcc402012-02-14 14:10:10 -0800108if [ "$ZYGOTE" = "" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700109 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
128fi
129
130msg "------------------------------"
131
132if [ "$QUIET" = "n" ]; then
Brian Carlstrom4ec9b1f2012-06-17 22:27:43 -0700133 adb shell rm -r $DEX_LOCATION
Brian Carlstrom105215d2012-06-14 12:50:44 -0700134 adb shell mkdir -p $DEX_LOCATION
135 adb push $TEST_NAME.jar $DEX_LOCATION
136 adb push $TEST_NAME-ex.jar $DEX_LOCATION
jeffhao5d1ac922011-09-29 17:41:15 -0700137else
Brian Carlstrom4ec9b1f2012-06-17 22:27:43 -0700138 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
Brian Carlstrom105215d2012-06-14 12:50:44 -0700139 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
jeffhao5d1ac922011-09-29 17:41:15 -0700142fi
143
Brian Carlstromfa42b442013-06-17 12:53:45 -0700144if [ "$DEBUGGER" = "y" ]; then
Elliott Hughes72395bf2012-04-24 13:45:26 -0700145 # Use this instead for ddms and connect by running 'ddms':
Brian Carlstromfa42b442013-06-17 12:53:45 -0700146 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
Elliott Hughes72395bf2012-04-24 13:45:26 -0700147 # TODO: add a separate --ddms option?
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700148
Elliott Hughes72395bf2012-04-24 13:45:26 -0700149 PORT=12345
150 msg "Waiting for jdb to connect:"
151 msg " adb forward tcp:$PORT tcp:$PORT"
152 msg " jdb -attach localhost:$PORT"
Brian Carlstromfa42b442013-06-17 12:53:45 -0700153 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
jeffhao5d1ac922011-09-29 17:41:15 -0700154fi
155
Ian Rogers4c1bf1a2012-12-11 10:44:28 -0800156if [ "$GDB" = "y" ]; then
Alex Lightfc0082b2014-07-29 18:31:18 -0700157 gdb="gdbserver$GDB_TARGET_SUFFIX :5039"
Ian Rogersee043fc2014-03-11 11:30:20 -0700158 gdbargs="$exe"
Ian Rogers4c1bf1a2012-12-11 10:44:28 -0800159fi
160
jeffhao0dff3f42012-11-20 15:13:43 -0800161if [ "$INTERPRETER" = "y" ]; then
162 INT_OPTS="-Xint"
163fi
164
Mathieu Chartierdbe6f462012-09-25 16:54:50 -0700165JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
Elliott Hughes72395bf2012-04-24 13:45:26 -0700166
Alex Lighta59dd802014-07-02 16:28:08 -0700167if [ "$RELOCATE" = "y" ]; then
168 RELOCATE_OPT="-Xrelocate"
169 FLAGS="${FLAGS} -Xcompiler-option --include-patch-information"
170else
171 RELOCATE_OPT="-Xnorelocate"
172fi
173
Brian Carlstrom41ccffd2014-05-06 10:37:30 -0700174cmdline="cd $DEX_LOCATION && export ANDROID_DATA=$DEX_LOCATION && export DEX_LOCATION=$DEX_LOCATION && \
Alex Lighta59dd802014-07-02 16:28:08 -0700175 $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 -0800176if [ "$DEV_MODE" = "y" ]; then
177 echo $cmdline "$@"
jeffhao5d1ac922011-09-29 17:41:15 -0700178fi
Elliott Hughes58bcc402012-02-14 14:10:10 -0800179
180adb shell $cmdline "$@"