host-run-test-jar revision 9d722533b0ef6547ee0ab5286f65af98451c36e4
1#!/bin/sh
2#
3# Run the code in test.jar using the host-mode virtual machine. The jar should
4# contain a top-level class named Main to run.
5
6msg() {
7    if [ "$QUIET" = "n" ]; then
8        echo "$@"
9    fi
10}
11
12DEBUGGER="n"
13PREBUILD="n"
14GDB="n"
15ISA="x86"
16INTERPRETER="n"
17VERIFY="y"
18RELOCATE="y"
19OPTIMIZE="y"
20INVOKE_WITH=""
21DEV_MODE="n"
22QUIET="n"
23FLAGS=""
24COMPILER_FLAGS=""
25BUILD_BOOT_OPT=""
26exe="${ANDROID_HOST_OUT}/bin/dalvikvm32"
27
28while true; do
29    if [ "x$1" = "x--quiet" ]; then
30        QUIET="y"
31        shift
32    elif [ "x$1" = "x--prebuild" ]; then
33        PREBUILD="y"
34        shift
35    elif [ "x$1" = "x--lib" ]; then
36        shift
37        if [ "x$1" = "x" ]; then
38            echo "$0 missing argument to --lib" 1>&2
39            exit 1
40        fi
41        LIB="$1"
42        if [ `uname` = "Darwin" ]; then
43            LIB=${LIB/%so/dylib}
44        fi
45        shift
46    elif [ "x$1" = "x--boot" ]; then
47        shift
48        option="$1"
49        BOOT_OPT="$option"
50        BUILD_BOOT_OPT="--boot-image=${option#-Ximage:}"
51        shift
52    elif [ "x$1" = "x--debug" ]; then
53        DEBUGGER="y"
54        shift
55    elif [ "x$1" = "x--gdb" ]; then
56        GDB="y"
57        DEV_MODE="y"
58        shift
59    elif [ "x$1" = "x--invoke-with" ]; then
60        shift
61        if [ "x$1" = "x" ]; then
62            echo "$0 missing argument to --invoke-with" 1>&2
63            exit 1
64        fi
65        if [ "x$INVOKE_WITH" = "x" ]; then
66            INVOKE_WITH="$1"
67        else
68            INVOKE_WITH="$INVOKE_WITH $1"
69        fi
70        shift
71    elif [ "x$1" = "x--dev" ]; then
72        DEV_MODE="y"
73        shift
74    elif [ "x$1" = "x--interpreter" ]; then
75        INTERPRETER="y"
76        shift
77    elif [ "x$1" = "x--64" ]; then
78        ISA="x64"
79        exe="${ANDROID_HOST_OUT}/bin/dalvikvm64"
80        shift
81    elif [ "x$1" = "x--no-verify" ]; then
82        VERIFY="n"
83        shift
84    elif [ "x$1" = "x--no-optimize" ]; then
85        OPTIMIZE="n"
86        shift
87    elif [ "x$1" = "x--no-relocate" ]; then
88        RELOCATE="n"
89        shift
90    elif [ "x$1" = "x--relocate" ]; then
91        RELOCATE="y"
92        shift
93    elif [ "x$1" = "x-Xcompiler-option" ]; then
94        shift
95        option="$1"
96        FLAGS="${FLAGS} -Xcompiler-option $option"
97        COMPILER_FLAGS="${COMPILER_FLAGS} $option"
98        shift
99    elif [ "x$1" = "x--runtime-option" ]; then
100        shift
101        option="$1"
102        FLAGS="${FLAGS} $option"
103        shift
104    elif [ "x$1" = "x--" ]; then
105        shift
106        break
107    elif expr "x$1" : "x--" >/dev/null 2>&1; then
108        echo "unknown $0 option: $1" 1>&2
109        exit 1
110    else
111        break
112    fi
113done
114
115msg "------------------------------"
116
117export ANDROID_PRINTF_LOG=brief
118if [ "$DEV_MODE" = "y" ]; then
119    export ANDROID_LOG_TAGS='*:d'
120else
121    export ANDROID_LOG_TAGS='*:s'
122fi
123export ANDROID_DATA="$DEX_LOCATION"
124export ANDROID_ROOT="${ANDROID_HOST_OUT}"
125export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
126export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
127
128if [ "$DEBUGGER" = "y" ]; then
129    PORT=8000
130    msg "Waiting for jdb to connect:"
131    msg "    jdb -attach localhost:$PORT"
132    DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
133fi
134
135if [ "$GDB" = "y" ]; then
136    if [ `uname` = "Darwin" ]; then
137        gdb=lldb
138        gdbargs="-- $exe"
139        exe=
140    else
141        gdb=gdb
142        gdbargs="--args $exe"
143        # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
144        # gdbargs="--annotate=3 $gdbargs"
145    fi
146fi
147
148if [ "$INTERPRETER" = "y" ]; then
149    INT_OPTS="-Xint"
150    COMPILER_FLAGS="${COMPILER_FLAGS} --compiler-filter=interpret-only"
151fi
152
153if [ "$RELOCATE" = "y" ]; then
154  FLAGS="${FLAGS} -Xrelocate"
155  COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -Xnorelocate --include-patch-information"
156  # Run test sets a fairly draconian ulimit that we will likely blow right over
157  # since we are relocating. Get the total size of the /system/framework directory
158  # in 512 byte blocks and set it as the ulimit. This should be more than enough
159  # room.
160  ulimit -S $(du -c -B512 ${ANDROID_ROOT}/framework | tail -1 | cut -f1) || exit 1
161else
162  FLAGS="${FLAGS} -Xnorelocate"
163  COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -Xnorelocate --no-include-patch-information"
164fi
165
166mkdir_cmd="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
167if [ "$PREBUILD" = "y" ]; then
168  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")"
169else
170  prebuild_cmd="true"
171fi
172
173JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
174cmdline="$INVOKE_WITH $gdb $exe $gdbargs -XXlib:$LIB $JNI_OPTS $FLAGS $INT_OPTS $DEBUGGER_OPTS $BOOT_OPT -cp $DEX_LOCATION/$TEST_NAME.jar Main"
175if [ "$DEV_MODE" = "y" ]; then
176  if [ "$PREBUILD" = "y" ]; then
177    echo "$mkdir_cmd && $prebuild_cmd && $cmdline"
178  elif [ "$RELOCATE" = "y" ]; then
179    echo "$mkdir_cmd && $cmdline"
180  else
181    echo $cmdline
182  fi
183fi
184
185cd $ANDROID_BUILD_TOP
186$mkdir_cmd && $prebuild_cmd && $cmdline "$@"
187