blob: 9e30f6500455da382bf1e25c804119474da852b1 [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=""
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000021FLAGS=""
jeffhao5d1ac922011-09-29 17:41:15 -070022
23while true; do
24 if [ "x$1" = "x--quiet" ]; then
25 QUIET="y"
26 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070027 elif [ "x$1" = "x--lib" ]; then
Brian Carlstromfa42b442013-06-17 12:53:45 -070028 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070029 if [ "x$1" = "x" ]; then
30 echo "$0 missing argument to --lib" 1>&2
31 exit 1
32 fi
Brian Carlstromfa42b442013-06-17 12:53:45 -070033 LIB="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -070034 shift
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000035 elif [ "x$1" = "x-Xcompiler-option" ]; then
36 shift
37 option="$1"
38 FLAGS="${FLAGS} -Xcompiler-option $option"
39 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070040 elif [ "x$1" = "x--boot" ]; then
41 shift
42 BOOT_OPT="$1"
Elliott Hughes7c046102011-10-19 18:16:03 -070043 shift
jeffhao5d1ac922011-09-29 17:41:15 -070044 elif [ "x$1" = "x--debug" ]; then
Brian Carlstromfa42b442013-06-17 12:53:45 -070045 DEBUGGER="y"
jeffhao5d1ac922011-09-29 17:41:15 -070046 shift
Ian Rogers4c1bf1a2012-12-11 10:44:28 -080047 elif [ "x$1" = "x--gdb" ]; then
48 GDB="y"
49 DEV_MODE="y"
50 shift
jeffhao5d1ac922011-09-29 17:41:15 -070051 elif [ "x$1" = "x--zygote" ]; then
Elliott Hughes58bcc402012-02-14 14:10:10 -080052 ZYGOTE="--zygote"
jeffhao5d1ac922011-09-29 17:41:15 -070053 msg "Spawning from zygote"
54 shift
55 elif [ "x$1" = "x--dev" ]; then
56 DEV_MODE="y"
57 shift
jeffhao0dff3f42012-11-20 15:13:43 -080058 elif [ "x$1" = "x--interpreter" ]; then
59 INTERPRETER="y"
60 shift
Elliott Hughes7c046102011-10-19 18:16:03 -070061 elif [ "x$1" = "x--invoke-with" ]; then
62 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070063 if [ "x$1" = "x" ]; then
64 echo "$0 missing argument to --invoke-with" 1>&2
65 exit 1
66 fi
Ian Rogers0e033672013-04-19 10:22:46 -070067 if [ "x$INVOKE_WITH" = "x" ]; then
68 INVOKE_WITH="$1"
69 else
70 INVOKE_WITH="$INVOKE_WITH $1"
71 fi
Elliott Hughes7c046102011-10-19 18:16:03 -070072 shift
jeffhao5d1ac922011-09-29 17:41:15 -070073 elif [ "x$1" = "x--no-verify" ]; then
74 VERIFY="n"
75 shift
76 elif [ "x$1" = "x--no-optimize" ]; then
77 OPTIMIZE="n"
78 shift
jeffhao5d1ac922011-09-29 17:41:15 -070079 elif [ "x$1" = "x--" ]; then
80 shift
81 break
82 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -070083 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -070084 exit 1
85 else
86 break
87 fi
88done
89
Elliott Hughes58bcc402012-02-14 14:10:10 -080090if [ "$ZYGOTE" = "" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -070091 if [ "$OPTIMIZE" = "y" ]; then
92 if [ "$VERIFY" = "y" ]; then
93 DEX_OPTIMIZE="-Xdexopt:verified"
94 else
95 DEX_OPTIMIZE="-Xdexopt:all"
96 fi
97 msg "Performing optimizations"
98 else
99 DEX_OPTIMIZE="-Xdexopt:none"
100 msg "Skipping optimizations"
101 fi
102
103 if [ "$VERIFY" = "y" ]; then
104 DEX_VERIFY=""
105 msg "Performing verification"
106 else
107 DEX_VERIFY="-Xverify:none"
108 msg "Skipping verification"
109 fi
110fi
111
112msg "------------------------------"
113
114if [ "$QUIET" = "n" ]; then
Brian Carlstrom4ec9b1f2012-06-17 22:27:43 -0700115 adb shell rm -r $DEX_LOCATION
Brian Carlstrom105215d2012-06-14 12:50:44 -0700116 adb shell mkdir -p $DEX_LOCATION
117 adb push $TEST_NAME.jar $DEX_LOCATION
118 adb push $TEST_NAME-ex.jar $DEX_LOCATION
jeffhao5d1ac922011-09-29 17:41:15 -0700119else
Brian Carlstrom4ec9b1f2012-06-17 22:27:43 -0700120 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
Brian Carlstrom105215d2012-06-14 12:50:44 -0700121 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
122 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
123 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
jeffhao5d1ac922011-09-29 17:41:15 -0700124fi
125
Brian Carlstromfa42b442013-06-17 12:53:45 -0700126if [ "$DEBUGGER" = "y" ]; then
Elliott Hughes72395bf2012-04-24 13:45:26 -0700127 # Use this instead for ddms and connect by running 'ddms':
Brian Carlstromfa42b442013-06-17 12:53:45 -0700128 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
Elliott Hughes72395bf2012-04-24 13:45:26 -0700129 # TODO: add a separate --ddms option?
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700130
Elliott Hughes72395bf2012-04-24 13:45:26 -0700131 PORT=12345
132 msg "Waiting for jdb to connect:"
133 msg " adb forward tcp:$PORT tcp:$PORT"
134 msg " jdb -attach localhost:$PORT"
Brian Carlstromfa42b442013-06-17 12:53:45 -0700135 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
jeffhao5d1ac922011-09-29 17:41:15 -0700136fi
137
Ian Rogers4c1bf1a2012-12-11 10:44:28 -0800138if [ "$GDB" = "y" ]; then
139 gdb="gdbserver :5039"
Ian Rogersee043fc2014-03-11 11:30:20 -0700140 gdbargs="$exe"
Ian Rogers4c1bf1a2012-12-11 10:44:28 -0800141fi
142
jeffhao0dff3f42012-11-20 15:13:43 -0800143if [ "$INTERPRETER" = "y" ]; then
144 INT_OPTS="-Xint"
145fi
146
Mathieu Chartierdbe6f462012-09-25 16:54:50 -0700147JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
Elliott Hughes72395bf2012-04-24 13:45:26 -0700148
Brian Carlstrom7675e162013-06-10 16:18:04 -0700149cmdline="cd $DEX_LOCATION && mkdir dalvik-cache && export ANDROID_DATA=$DEX_LOCATION && export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000150 $INVOKE_WITH $gdb /system/bin/dalvikvm $FLAGS $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 -0800151if [ "$DEV_MODE" = "y" ]; then
152 echo $cmdline "$@"
jeffhao5d1ac922011-09-29 17:41:15 -0700153fi
Elliott Hughes58bcc402012-02-14 14:10:10 -0800154
155adb shell $cmdline "$@"