blob: b1dddfc54c655fa6159d566ff07cdbd7ff28bb2a [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 Rogers7769f502012-02-03 18:02:28 -080012OATEXEC="oatexecd"
Ian Rogers4c1bf1a2012-12-11 10:44:28 -080013GDB="n"
jeffhao5d1ac922011-09-29 17:41:15 -070014DEBUG="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=""
jeffhao5d1ac922011-09-29 17:41:15 -070022
23while true; do
24 if [ "x$1" = "x--quiet" ]; then
25 QUIET="y"
26 shift
Ian Rogers7769f502012-02-03 18:02:28 -080027 elif [ "x$1" = "x-O" ]; then
28 OATEXEC="oatexec"
Elliott Hughes7c046102011-10-19 18:16:03 -070029 shift
jeffhao5d1ac922011-09-29 17:41:15 -070030 elif [ "x$1" = "x--debug" ]; then
31 DEBUG="y"
32 shift
Ian Rogers4c1bf1a2012-12-11 10:44:28 -080033 elif [ "x$1" = "x--gdb" ]; then
34 GDB="y"
35 DEV_MODE="y"
36 shift
jeffhao5d1ac922011-09-29 17:41:15 -070037 elif [ "x$1" = "x--zygote" ]; then
Elliott Hughes58bcc402012-02-14 14:10:10 -080038 ZYGOTE="--zygote"
jeffhao5d1ac922011-09-29 17:41:15 -070039 msg "Spawning from zygote"
40 shift
41 elif [ "x$1" = "x--dev" ]; then
42 DEV_MODE="y"
43 shift
jeffhao0dff3f42012-11-20 15:13:43 -080044 elif [ "x$1" = "x--interpreter" ]; then
45 INTERPRETER="y"
46 shift
Elliott Hughes7c046102011-10-19 18:16:03 -070047 elif [ "x$1" = "x--invoke-with" ]; then
48 shift
Ian Rogers0e033672013-04-19 10:22:46 -070049 if [ "x$INVOKE_WITH" = "x" ]; then
50 INVOKE_WITH="$1"
51 else
52 INVOKE_WITH="$INVOKE_WITH $1"
53 fi
Elliott Hughes7c046102011-10-19 18:16:03 -070054 shift
jeffhao5d1ac922011-09-29 17:41:15 -070055 elif [ "x$1" = "x--no-verify" ]; then
56 VERIFY="n"
57 shift
58 elif [ "x$1" = "x--no-optimize" ]; then
59 OPTIMIZE="n"
60 shift
jeffhao5d1ac922011-09-29 17:41:15 -070061 elif [ "x$1" = "x--" ]; then
62 shift
63 break
64 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -070065 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -070066 exit 1
67 else
68 break
69 fi
70done
71
Elliott Hughes58bcc402012-02-14 14:10:10 -080072if [ "$ZYGOTE" = "" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -070073 if [ "$OPTIMIZE" = "y" ]; then
74 if [ "$VERIFY" = "y" ]; then
75 DEX_OPTIMIZE="-Xdexopt:verified"
76 else
77 DEX_OPTIMIZE="-Xdexopt:all"
78 fi
79 msg "Performing optimizations"
80 else
81 DEX_OPTIMIZE="-Xdexopt:none"
82 msg "Skipping optimizations"
83 fi
84
85 if [ "$VERIFY" = "y" ]; then
86 DEX_VERIFY=""
87 msg "Performing verification"
88 else
89 DEX_VERIFY="-Xverify:none"
90 msg "Skipping verification"
91 fi
92fi
93
94msg "------------------------------"
95
96if [ "$QUIET" = "n" ]; then
Brian Carlstrom4ec9b1f2012-06-17 22:27:43 -070097 adb shell rm -r $DEX_LOCATION
Brian Carlstrom105215d2012-06-14 12:50:44 -070098 adb shell mkdir -p $DEX_LOCATION
99 adb push $TEST_NAME.jar $DEX_LOCATION
100 adb push $TEST_NAME-ex.jar $DEX_LOCATION
jeffhao5d1ac922011-09-29 17:41:15 -0700101else
Brian Carlstrom4ec9b1f2012-06-17 22:27:43 -0700102 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
Brian Carlstrom105215d2012-06-14 12:50:44 -0700103 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
104 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
105 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
jeffhao5d1ac922011-09-29 17:41:15 -0700106fi
107
108if [ "$DEBUG" = "y" ]; then
Elliott Hughes72395bf2012-04-24 13:45:26 -0700109 # Use this instead for ddms and connect by running 'ddms':
110 # DEBUG_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
111 # TODO: add a separate --ddms option?
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700112
Elliott Hughes72395bf2012-04-24 13:45:26 -0700113 PORT=12345
114 msg "Waiting for jdb to connect:"
115 msg " adb forward tcp:$PORT tcp:$PORT"
116 msg " jdb -attach localhost:$PORT"
117 DEBUG_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
jeffhao5d1ac922011-09-29 17:41:15 -0700118fi
119
Ian Rogers4c1bf1a2012-12-11 10:44:28 -0800120if [ "$GDB" = "y" ]; then
121 gdb="gdbserver :5039"
122 gdbargs="--args $exe"
123fi
124
jeffhao0dff3f42012-11-20 15:13:43 -0800125if [ "$INTERPRETER" = "y" ]; then
126 INT_OPTS="-Xint"
127fi
128
Mathieu Chartierdbe6f462012-09-25 16:54:50 -0700129JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
Elliott Hughes72395bf2012-04-24 13:45:26 -0700130
Brian Carlstrom105215d2012-06-14 12:50:44 -0700131cmdline="cd $DEX_LOCATION && mkdir art-cache && export ANDROID_DATA=$DEX_LOCATION && export DEX_LOCATION=$DEX_LOCATION && \
Ian Rogers4c1bf1a2012-12-11 10:44:28 -0800132 $INVOKE_WITH $gdb $OATEXEC $gdbargs $ZYGOTE $JNI_OPTS $INT_OPTS $DEBUG_OPTS -Ximage:/data/art-test/core.art -cp $DEX_LOCATION/$TEST_NAME.jar Main"
Elliott Hughes58bcc402012-02-14 14:10:10 -0800133if [ "$DEV_MODE" = "y" ]; then
134 echo $cmdline "$@"
jeffhao5d1ac922011-09-29 17:41:15 -0700135fi
Elliott Hughes58bcc402012-02-14 14:10:10 -0800136
137adb shell $cmdline "$@"