blob: 08df02b451e0a25cea7deb72f01746f1daa1f5af [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.
5#
6# Options:
7# --quiet -- don't chatter
jeffhao5d1ac922011-09-29 17:41:15 -07008# --debug -- wait for debugger to attach
9# --zygote -- use the zygote (if so, all other options are ignored)
10# --dev -- development mode (print the vm invocation cmdline)
11# --no-verify -- turn off verification (on by default)
12# --no-optimize -- turn off optimization (on by default)
13# --no-precise -- turn off precise GC (on by default)
Ian Rogers7769f502012-02-03 18:02:28 -080014# -O -- run non-debug code
jeffhao5d1ac922011-09-29 17:41:15 -070015
16msg() {
17 if [ "$QUIET" = "n" ]; then
18 echo "$@"
19 fi
20}
21
Ian Rogers7769f502012-02-03 18:02:28 -080022OATEXEC="oatexecd"
jeffhao5d1ac922011-09-29 17:41:15 -070023DEBUG="n"
24VERIFY="y"
25OPTIMIZE="y"
Elliott Hughes58bcc402012-02-14 14:10:10 -080026ZYGOTE=""
jeffhao5d1ac922011-09-29 17:41:15 -070027QUIET="n"
jeffhao5d1ac922011-09-29 17:41:15 -070028DEV_MODE="n"
Elliott Hughes7c046102011-10-19 18:16:03 -070029INVOKE_WITH=""
jeffhao5d1ac922011-09-29 17:41:15 -070030
31while true; do
32 if [ "x$1" = "x--quiet" ]; then
33 QUIET="y"
34 shift
Ian Rogers7769f502012-02-03 18:02:28 -080035 elif [ "x$1" = "x-O" ]; then
36 OATEXEC="oatexec"
Elliott Hughes7c046102011-10-19 18:16:03 -070037 shift
jeffhao5d1ac922011-09-29 17:41:15 -070038 elif [ "x$1" = "x--debug" ]; then
39 DEBUG="y"
40 shift
41 elif [ "x$1" = "x--zygote" ]; then
Elliott Hughes58bcc402012-02-14 14:10:10 -080042 ZYGOTE="--zygote"
jeffhao5d1ac922011-09-29 17:41:15 -070043 msg "Spawning from zygote"
44 shift
45 elif [ "x$1" = "x--dev" ]; then
46 DEV_MODE="y"
47 shift
Elliott Hughes7c046102011-10-19 18:16:03 -070048 elif [ "x$1" = "x--invoke-with" ]; then
49 shift
50 INVOKE_WITH="$1"
51 shift
jeffhao5d1ac922011-09-29 17:41:15 -070052 elif [ "x$1" = "x--no-verify" ]; then
53 VERIFY="n"
54 shift
55 elif [ "x$1" = "x--no-optimize" ]; then
56 OPTIMIZE="n"
57 shift
jeffhao5d1ac922011-09-29 17:41:15 -070058 elif [ "x$1" = "x--" ]; then
59 shift
60 break
61 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -070062 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -070063 exit 1
64 else
65 break
66 fi
67done
68
Elliott Hughes58bcc402012-02-14 14:10:10 -080069if [ "$ZYGOTE" = "" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -070070 if [ "$OPTIMIZE" = "y" ]; then
71 if [ "$VERIFY" = "y" ]; then
72 DEX_OPTIMIZE="-Xdexopt:verified"
73 else
74 DEX_OPTIMIZE="-Xdexopt:all"
75 fi
76 msg "Performing optimizations"
77 else
78 DEX_OPTIMIZE="-Xdexopt:none"
79 msg "Skipping optimizations"
80 fi
81
82 if [ "$VERIFY" = "y" ]; then
83 DEX_VERIFY=""
84 msg "Performing verification"
85 else
86 DEX_VERIFY="-Xverify:none"
87 msg "Skipping verification"
88 fi
89fi
90
91msg "------------------------------"
92
93if [ "$QUIET" = "n" ]; then
Brian Carlstrom4ec9b1f2012-06-17 22:27:43 -070094 adb shell rm -r $DEX_LOCATION
Brian Carlstrom105215d2012-06-14 12:50:44 -070095 adb shell mkdir -p $DEX_LOCATION
96 adb push $TEST_NAME.jar $DEX_LOCATION
97 adb push $TEST_NAME-ex.jar $DEX_LOCATION
jeffhao5d1ac922011-09-29 17:41:15 -070098else
Brian Carlstrom4ec9b1f2012-06-17 22:27:43 -070099 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
Brian Carlstrom105215d2012-06-14 12:50:44 -0700100 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
101 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
102 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
jeffhao5d1ac922011-09-29 17:41:15 -0700103fi
104
105if [ "$DEBUG" = "y" ]; then
Elliott Hughes72395bf2012-04-24 13:45:26 -0700106 # Use this instead for ddms and connect by running 'ddms':
107 # DEBUG_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
108 # TODO: add a separate --ddms option?
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700109
Elliott Hughes72395bf2012-04-24 13:45:26 -0700110 PORT=12345
111 msg "Waiting for jdb to connect:"
112 msg " adb forward tcp:$PORT tcp:$PORT"
113 msg " jdb -attach localhost:$PORT"
114 DEBUG_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
jeffhao5d1ac922011-09-29 17:41:15 -0700115fi
116
Elliott Hughes72395bf2012-04-24 13:45:26 -0700117JNI_OPTS="-Xjnigreflimit:256 -Xcheck:jni"
118
Brian Carlstrom105215d2012-06-14 12:50:44 -0700119cmdline="cd $DEX_LOCATION && mkdir art-cache && export ANDROID_DATA=$DEX_LOCATION && export DEX_LOCATION=$DEX_LOCATION && \
120 $INVOKE_WITH $OATEXEC $ZYGOTE $JNI_OPTS $DEBUG_OPTS -Ximage:/data/art-test/core.art -cp $DEX_LOCATION/$TEST_NAME.jar Main"
Elliott Hughes58bcc402012-02-14 14:10:10 -0800121if [ "$DEV_MODE" = "y" ]; then
122 echo $cmdline "$@"
jeffhao5d1ac922011-09-29 17:41:15 -0700123fi
Elliott Hughes58bcc402012-02-14 14:10:10 -0800124
125adb shell $cmdline "$@"