summaryrefslogtreecommitdiffstats
path: root/test/etc/host-run-test-jar
blob: 49aa912232f2471badd321d70d21992fc08f864a (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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/bin/sh
#
# Run the code in test.jar using the host-mode virtual machine. The jar should
# contain a top-level class named Main to run.

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

DEBUGGER="n"
PREBUILD="n"
GDB="n"
ISA="x86"
INTERPRETER="n"
VERIFY="y"
RELOCATE="y"
OPTIMIZE="y"
INVOKE_WITH=""
DEV_MODE="n"
QUIET="n"
FLAGS=""
COMPILER_FLAGS=""
BUILD_BOOT_OPT=""
PATCHOAT=""
DEX2OAT=""
FALSE_BIN="/bin/false"
HAVE_IMAGE="y"
exe="${ANDROID_HOST_OUT}/bin/dalvikvm32"
main="Main"

while true; do
    if [ "x$1" = "x--quiet" ]; then
        QUIET="y"
        shift
    elif [ "x$1" = "x--prebuild" ]; then
        PREBUILD="y"
        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--lib" ]; then
        shift
        if [ "x$1" = "x" ]; then
            echo "$0 missing argument to --lib" 1>&2
            exit 1
        fi
        LIB="$1"
        if [ `uname` = "Darwin" ]; then
            LIB=${LIB/%so/dylib}
        fi
        shift
    elif [ "x$1" = "x--no-image" ]; then
        HAVE_IMAGE="n"
        shift
    elif [ "x$1" = "x--boot" ]; then
        shift
        option="$1"
        BOOT_OPT="$option"
        BUILD_BOOT_OPT="--boot-image=${option#-Ximage:}"
        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--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--dev" ]; then
        DEV_MODE="y"
        shift
    elif [ "x$1" = "x--interpreter" ]; then
        INTERPRETER="y"
        shift
    elif [ "x$1" = "x--64" ]; then
        ISA="x86_64"
        exe="${ANDROID_HOST_OUT}/bin/dalvikvm64"
        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--no-relocate" ]; then
        RELOCATE="n"
        shift
    elif [ "x$1" = "x--relocate" ]; then
        RELOCATE="y"
        shift
    elif [ "x$1" = "x-Xcompiler-option" ]; then
        shift
        option="$1"
        FLAGS="${FLAGS} -Xcompiler-option $option"
        COMPILER_FLAGS="${COMPILER_FLAGS} $option"
        shift
    elif [ "x$1" = "x--runtime-option" ]; then
        shift
        option="$1"
        FLAGS="${FLAGS} $option"
        shift
    elif [ "x$1" = "x--" ]; then
        shift
        break
    elif expr "x$1" : "x--" >/dev/null 2>&1; then
        echo "unknown $0 option: $1" 1>&2
        exit 1
    else
        break
    fi
done

if [ "x$1" = "x" ] ; then
  main="Main"
else
  main="$1"
fi

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

export ANDROID_PRINTF_LOG=brief
if [ "$DEV_MODE" = "y" ]; then
    export ANDROID_LOG_TAGS='*:d'
else
    export ANDROID_LOG_TAGS='*:s'
fi
export ANDROID_DATA="$DEX_LOCATION"
export ANDROID_ROOT="${ANDROID_HOST_OUT}"
export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"

if [ "$DEBUGGER" = "y" ]; then
    PORT=8000
    msg "Waiting for jdb to connect:"
    msg "    jdb -attach localhost:$PORT"
    DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
fi

if [ "$GDB" = "y" ]; then
    if [ `uname` = "Darwin" ]; then
        gdb=lldb
        gdbargs="-- $exe"
        exe=
    else
        gdb=gdb
        gdbargs="--args $exe"
        # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
        # gdbargs="--annotate=3 $gdbargs"
    fi
fi

if [ "$INTERPRETER" = "y" ]; then
    INT_OPTS="-Xint"
    COMPILER_FLAGS="${COMPILER_FLAGS} --compiler-filter=interpret-only"
fi

if [ "$HAVE_IMAGE" = "n" ]; then
    # Set image to a place were there isn't one.
    BOOT_OPT="-Ximage:/system/non-existant/core.art"
fi

if [ "$RELOCATE" = "y" ]; then
  FLAGS="${FLAGS} -Xrelocate"
  COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -Xnorelocate --include-patch-information"
  # Run test sets a fairly draconian ulimit that we will likely blow right over
  # since we are relocating. Get the total size of the /system/framework directory
  # in 512 byte blocks and set it as the ulimit. This should be more than enough
  # room.
  if [ ! `uname` = "Darwin" ]; then  # TODO: Darwin doesn't support "du -B..."
    ulimit -S $(du -c -B512 ${ANDROID_ROOT}/framework | tail -1 | cut -f1) || exit 1
  fi
else
  FLAGS="${FLAGS} -Xnorelocate"
  COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -Xnorelocate --no-include-patch-information"
fi

mkdir_cmd="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
if [ "$PREBUILD" = "y" ]; then
  prebuild_cmd="${ANDROID_HOST_OUT}/bin/dex2oatd $COMPILER_FLAGS --instruction-set=$ISA $BUILD_BOOT_OPT --dex-file=$DEX_LOCATION/$TEST_NAME.jar --oat-file=$DEX_LOCATION/dalvik-cache/$ISA/$(echo $DEX_LOCATION/$TEST_NAME.jar/classes.dex | cut -d/ -f 2- | sed "s:/:@:g")"
else
  prebuild_cmd="true"
fi

JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
cmdline="$INVOKE_WITH $gdb $exe $gdbargs -XXlib:$LIB $PATCHOAT $DEX2OAT $JNI_OPTS $FLAGS $INT_OPTS $DEBUGGER_OPTS $BOOT_OPT -cp $DEX_LOCATION/$TEST_NAME.jar $main"
if [ "$DEV_MODE" = "y" ]; then
  if [ "$PREBUILD" = "y" ]; then
    echo "$mkdir_cmd && $prebuild_cmd && $cmdline"
  elif [ "$RELOCATE" = "y" ]; then
    echo "$mkdir_cmd && $cmdline"
  else
    echo $cmdline
  fi
fi

cd $ANDROID_BUILD_TOP

$mkdir_cmd || exit 1
$prebuild_cmd || exit 2

if [ "$GDB" = "y" ]; then
  # When running under gdb, we cannot do piping and grepping...
  LD_PRELOAD=libsigchain.so $cmdline "$@"
else
  # If we are execing /bin/false we might not be on the same ISA as libsigchain.so
  # ld.so will helpfully warn us of this. Unfortunately this messes up our error
  # checking so we will just filter out the error with a grep.
  LD_PRELOAD=libsigchain.so $cmdline "$@" 2>&1 | grep -v -E "^ERROR: ld\.so: object '.+\.so' from LD_PRELOAD cannot be preloaded: ignored\.$"
fi