blob: ff75d32d1b2a2ab37e5d63d50c0f55b04dd2e518 [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
Ian Rogers4c1bf1a2012-12-11 10:44:28 -080012GDB="n"
Brian Carlstromfa42b442013-06-17 12:53:45 -070013DEBUGGER="n"
jeffhao0dff3f42012-11-20 15:13:43 -080014INTERPRETER="n"
jeffhao5d1ac922011-09-29 17:41:15 -070015VERIFY="y"
16OPTIMIZE="y"
Elliott Hughes58bcc402012-02-14 14:10:10 -080017ZYGOTE=""
jeffhao5d1ac922011-09-29 17:41:15 -070018QUIET="n"
jeffhao5d1ac922011-09-29 17:41:15 -070019DEV_MODE="n"
Elliott Hughes7c046102011-10-19 18:16:03 -070020INVOKE_WITH=""
jeffhao5d1ac922011-09-29 17:41:15 -070021
22while true; do
23 if [ "x$1" = "x--quiet" ]; then
24 QUIET="y"
25 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070026 elif [ "x$1" = "x--lib" ]; then
Brian Carlstromfa42b442013-06-17 12:53:45 -070027 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070028 if [ "x$1" = "x" ]; then
29 echo "$0 missing argument to --lib" 1>&2
30 exit 1
31 fi
Brian Carlstromfa42b442013-06-17 12:53:45 -070032 LIB="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -070033 shift
34 elif [ "x$1" = "x--boot" ]; then
35 shift
36 BOOT_OPT="$1"
Elliott Hughes7c046102011-10-19 18:16:03 -070037 shift
jeffhao5d1ac922011-09-29 17:41:15 -070038 elif [ "x$1" = "x--debug" ]; then
Brian Carlstromfa42b442013-06-17 12:53:45 -070039 DEBUGGER="y"
jeffhao5d1ac922011-09-29 17:41:15 -070040 shift
Ian Rogers4c1bf1a2012-12-11 10:44:28 -080041 elif [ "x$1" = "x--gdb" ]; then
42 GDB="y"
43 DEV_MODE="y"
44 shift
jeffhao5d1ac922011-09-29 17:41:15 -070045 elif [ "x$1" = "x--zygote" ]; then
Elliott Hughes58bcc402012-02-14 14:10:10 -080046 ZYGOTE="--zygote"
jeffhao5d1ac922011-09-29 17:41:15 -070047 msg "Spawning from zygote"
48 shift
49 elif [ "x$1" = "x--dev" ]; then
50 DEV_MODE="y"
51 shift
jeffhao0dff3f42012-11-20 15:13:43 -080052 elif [ "x$1" = "x--interpreter" ]; then
53 INTERPRETER="y"
54 shift
Elliott Hughes7c046102011-10-19 18:16:03 -070055 elif [ "x$1" = "x--invoke-with" ]; then
56 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070057 if [ "x$1" = "x" ]; then
58 echo "$0 missing argument to --invoke-with" 1>&2
59 exit 1
60 fi
Ian Rogers0e033672013-04-19 10:22:46 -070061 if [ "x$INVOKE_WITH" = "x" ]; then
62 INVOKE_WITH="$1"
63 else
64 INVOKE_WITH="$INVOKE_WITH $1"
65 fi
Elliott Hughes7c046102011-10-19 18:16:03 -070066 shift
jeffhao5d1ac922011-09-29 17:41:15 -070067 elif [ "x$1" = "x--no-verify" ]; then
68 VERIFY="n"
69 shift
70 elif [ "x$1" = "x--no-optimize" ]; then
71 OPTIMIZE="n"
72 shift
jeffhao5d1ac922011-09-29 17:41:15 -070073 elif [ "x$1" = "x--" ]; then
74 shift
75 break
76 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -070077 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -070078 exit 1
79 else
80 break
81 fi
82done
83
Elliott Hughes58bcc402012-02-14 14:10:10 -080084if [ "$ZYGOTE" = "" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -070085 if [ "$OPTIMIZE" = "y" ]; then
86 if [ "$VERIFY" = "y" ]; then
87 DEX_OPTIMIZE="-Xdexopt:verified"
88 else
89 DEX_OPTIMIZE="-Xdexopt:all"
90 fi
91 msg "Performing optimizations"
92 else
93 DEX_OPTIMIZE="-Xdexopt:none"
94 msg "Skipping optimizations"
95 fi
96
97 if [ "$VERIFY" = "y" ]; then
98 DEX_VERIFY=""
99 msg "Performing verification"
100 else
101 DEX_VERIFY="-Xverify:none"
102 msg "Skipping verification"
103 fi
104fi
105
106msg "------------------------------"
107
108if [ "$QUIET" = "n" ]; then
Brian Carlstrom4ec9b1f2012-06-17 22:27:43 -0700109 adb shell rm -r $DEX_LOCATION
Brian Carlstrom105215d2012-06-14 12:50:44 -0700110 adb shell mkdir -p $DEX_LOCATION
111 adb push $TEST_NAME.jar $DEX_LOCATION
112 adb push $TEST_NAME-ex.jar $DEX_LOCATION
jeffhao5d1ac922011-09-29 17:41:15 -0700113else
Brian Carlstrom4ec9b1f2012-06-17 22:27:43 -0700114 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
Brian Carlstrom105215d2012-06-14 12:50:44 -0700115 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
116 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
117 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
jeffhao5d1ac922011-09-29 17:41:15 -0700118fi
119
Brian Carlstromfa42b442013-06-17 12:53:45 -0700120if [ "$DEBUGGER" = "y" ]; then
Elliott Hughes72395bf2012-04-24 13:45:26 -0700121 # Use this instead for ddms and connect by running 'ddms':
Brian Carlstromfa42b442013-06-17 12:53:45 -0700122 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
Elliott Hughes72395bf2012-04-24 13:45:26 -0700123 # TODO: add a separate --ddms option?
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700124
Elliott Hughes72395bf2012-04-24 13:45:26 -0700125 PORT=12345
126 msg "Waiting for jdb to connect:"
127 msg " adb forward tcp:$PORT tcp:$PORT"
128 msg " jdb -attach localhost:$PORT"
Brian Carlstromfa42b442013-06-17 12:53:45 -0700129 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
jeffhao5d1ac922011-09-29 17:41:15 -0700130fi
131
Ian Rogers4c1bf1a2012-12-11 10:44:28 -0800132if [ "$GDB" = "y" ]; then
133 gdb="gdbserver :5039"
134 gdbargs="--args $exe"
135fi
136
jeffhao0dff3f42012-11-20 15:13:43 -0800137if [ "$INTERPRETER" = "y" ]; then
138 INT_OPTS="-Xint"
139fi
140
Mathieu Chartierdbe6f462012-09-25 16:54:50 -0700141JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
Elliott Hughes72395bf2012-04-24 13:45:26 -0700142
Brian Carlstrom7675e162013-06-10 16:18:04 -0700143cmdline="cd $DEX_LOCATION && mkdir dalvik-cache && export ANDROID_DATA=$DEX_LOCATION && export DEX_LOCATION=$DEX_LOCATION && \
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700144 $INVOKE_WITH $gdb dalvikvm $gdbargs -XXlib:$LIB $ZYGOTE $JNI_OPTS $INT_OPTS $DEBUGGER_OPTS $BOOT_OPT -cp $DEX_LOCATION/$TEST_NAME.jar Main"
Elliott Hughes58bcc402012-02-14 14:10:10 -0800145if [ "$DEV_MODE" = "y" ]; then
146 echo $cmdline "$@"
jeffhao5d1ac922011-09-29 17:41:15 -0700147fi
Elliott Hughes58bcc402012-02-14 14:10:10 -0800148
149adb shell $cmdline "$@"