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