summaryrefslogtreecommitdiffstats
path: root/test/etc/push-and-run-test-jar
blob: 9e63beddef91258d68be4e8cbf6b04d0a259cd20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/sh
#
# Run the code in test.jar on the device. The jar should contain a top-level
# class named Main to run.

msg() {
    if [ "$QUIET" = "n" ]; then
        echo "$@"
    fi
}

RELOCATE="y"
GDB="n"
DEBUGGER="n"
INTERPRETER="n"
VERIFY="y"
OPTIMIZE="y"
ZYGOTE=""
QUIET="n"
DEV_MODE="n"
INVOKE_WITH=""
FLAGS=""
TARGET_SUFFIX="32"
GDB_TARGET_SUFFIX=""
FALSE_BIN="/system/bin/false"
PATCHOAT=""
DEX2OAT=""
HAVE_IMAGE="y"

while true; do
    if [ "x$1" = "x--quiet" ]; then
        QUIET="y"
        shift
    elif [ "x$1" = "x--lib" ]; then
        shift
        if [ "x$1" = "x" ]; then
            echo "$0 missing argument to --lib" 1>&2
            exit 1
        fi
        LIB="$1"
        shift
    elif [ "x$1" = "x-Xcompiler-option" ]; then
        shift
        option="$1"
        FLAGS="${FLAGS} -Xcompiler-option $option"
        shift
    elif [ "x$1" = "x--no-image" ]; then
        HAVE_IMAGE="n"
        shift
    elif [ "x$1" = "x--no-dex2oat" ]; then
        DEX2OAT="-Xcompiler:${FALSE_BIN}"
        shift
    elif [ "x$1" = "x--no-patchoat" ]; then
        PATCHOAT="-Xpatchoat:${FALSE_BIN}"
        shift
    elif [ "x$1" = "x--runtime-option" ]; then
        shift
        option="$1"
        FLAGS="${FLAGS} $option"
        shift
    elif [ "x$1" = "x--boot" ]; then
        shift
        BOOT_OPT="$1"
        shift
    elif [ "x$1" = "x--debug" ]; then
        DEBUGGER="y"
        shift
    elif [ "x$1" = "x--gdb" ]; then
        GDB="y"
        DEV_MODE="y"
        shift
    elif [ "x$1" = "x--zygote" ]; then
        ZYGOTE="--zygote"
        msg "Spawning from zygote"
        shift
    elif [ "x$1" = "x--dev" ]; then
        DEV_MODE="y"
        shift
    elif [ "x$1" = "x--relocate" ]; then
        RELOCATE="y"
        shift
    elif [ "x$1" = "x--no-relocate" ]; then
        RELOCATE="n"
        shift
    elif [ "x$1" = "x--interpreter" ]; then
        INTERPRETER="y"
        shift
    elif [ "x$1" = "x--invoke-with" ]; then
        shift
        if [ "x$1" = "x" ]; then
            echo "$0 missing argument to --invoke-with" 1>&2
            exit 1
        fi
        if [ "x$INVOKE_WITH" = "x" ]; then
            INVOKE_WITH="$1"
        else
            INVOKE_WITH="$INVOKE_WITH $1"
        fi
        shift
    elif [ "x$1" = "x--no-verify" ]; then
        VERIFY="n"
        shift
    elif [ "x$1" = "x--no-optimize" ]; then
        OPTIMIZE="n"
        shift
    elif [ "x$1" = "x--" ]; then
        shift
        break
    elif [ "x$1" = "x--64" ]; then
        TARGET_SUFFIX="64"
        GDB_TARGET_SUFFIX="64"
        shift
    elif expr "x$1" : "x--" >/dev/null 2>&1; then
        echo "unknown $0 option: $1" 1>&2
        exit 1
    else
        break
    fi
done

if [ "$ZYGOTE" = "" ]; then
    if [ "$OPTIMIZE" = "y" ]; then
        if [ "$VERIFY" = "y" ]; then
            DEX_OPTIMIZE="-Xdexopt:verified"
        else
            DEX_OPTIMIZE="-Xdexopt:all"
        fi
        msg "Performing optimizations"
    else
        DEX_OPTIMIZE="-Xdexopt:none"
        msg "Skipping optimizations"
    fi

    if [ "$VERIFY" = "y" ]; then
        DEX_VERIFY=""
        msg "Performing verification"
    else
        DEX_VERIFY="-Xverify:none"
        msg "Skipping verification"
    fi
fi

msg "------------------------------"

if [ "$HAVE_IMAGE" = "n" ]; then
    BOOT_OPT="-Ximage:/system/non-existant/boot.art"
    BOOT_OPT="${BOOT_OPT} -Xbootclasspath:/system/framework/core-libart.jar"
fi

if [ "$QUIET" = "n" ]; then
  adb shell rm -r $DEX_LOCATION
  adb shell mkdir -p $DEX_LOCATION
  adb push $TEST_NAME.jar $DEX_LOCATION
  adb push $TEST_NAME-ex.jar $DEX_LOCATION
else
  adb shell rm -r $DEX_LOCATION >/dev/null 2>&1
  adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1
  adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1
  adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1
fi

if [ "$DEBUGGER" = "y" ]; then
  # Use this instead for ddms and connect by running 'ddms':
  # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
  # TODO: add a separate --ddms option?

  PORT=12345
  msg "Waiting for jdb to connect:"
  msg "    adb forward tcp:$PORT tcp:$PORT"
  msg "    jdb -attach localhost:$PORT"
  DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
fi

if [ "$GDB" = "y" ]; then
    gdb="gdbserver$GDB_TARGET_SUFFIX :5039"
    gdbargs="$exe"
fi

if [ "$INTERPRETER" = "y" ]; then
    INT_OPTS="-Xint"
fi

JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"

if [ "$RELOCATE" = "y" ]; then
  RELOCATE_OPT="-Xrelocate"
  FLAGS="${FLAGS} -Xcompiler-option --include-patch-information"
else
  RELOCATE_OPT="-Xnorelocate"
fi

cmdline="cd $DEX_LOCATION && export ANDROID_DATA=$DEX_LOCATION && export DEX_LOCATION=$DEX_LOCATION && \
    $INVOKE_WITH $gdb /system/bin/dalvikvm$TARGET_SUFFIX $FLAGS $gdbargs -XXlib:$LIB $PATCHOAT $DEX2OAT $ZYGOTE $JNI_OPTS $RELOCATE_OPT $INT_OPTS $DEBUGGER_OPTS $BOOT_OPT -cp $DEX_LOCATION/$TEST_NAME.jar Main"
if [ "$DEV_MODE" = "y" ]; then
  echo $cmdline "$@"
fi

adb shell $cmdline "$@"