blob: 6ee1dcd1ca34eb8a1cb9769c77bffa402eac3379 [file] [log] [blame]
Nicolas Geoffraye7d66622014-09-25 16:40:07 +01001#!/bin/bash
jeffhao5d1ac922011-09-29 17:41:15 -07002#
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.
jeffhao5d1ac922011-09-29 17:41:15 -07005
6msg() {
7 if [ "$QUIET" = "n" ]; then
8 echo "$@"
9 fi
10}
11
Brian Carlstromfa42b442013-06-17 12:53:45 -070012DEBUGGER="n"
Alex Lighta59dd802014-07-02 16:28:08 -070013PREBUILD="n"
jeffhao5d1ac922011-09-29 17:41:15 -070014GDB="n"
Alex Lighta59dd802014-07-02 16:28:08 -070015ISA="x86"
jeffhao0dff3f42012-11-20 15:13:43 -080016INTERPRETER="n"
jeffhao5d1ac922011-09-29 17:41:15 -070017VERIFY="y"
Alex Lighta59dd802014-07-02 16:28:08 -070018RELOCATE="y"
jeffhao5d1ac922011-09-29 17:41:15 -070019OPTIMIZE="y"
Elliott Hughes7c046102011-10-19 18:16:03 -070020INVOKE_WITH=""
jeffhao5d1ac922011-09-29 17:41:15 -070021DEV_MODE="n"
22QUIET="n"
Mathieu Chartier769a5ad2014-05-18 15:30:10 -070023FLAGS=""
Alex Lighta59dd802014-07-02 16:28:08 -070024COMPILER_FLAGS=""
25BUILD_BOOT_OPT=""
Alex Light03a112d2014-08-25 13:25:56 -070026PATCHOAT=""
27DEX2OAT=""
28FALSE_BIN="/bin/false"
29HAVE_IMAGE="y"
Ian Rogers741c02c2014-09-14 22:49:15 -070030TIME_OUT="y"
31TIME_OUT_VALUE=5m
Ian Rogersafd9acc2014-06-17 08:21:54 -070032exe="${ANDROID_HOST_OUT}/bin/dalvikvm32"
Andreas Gampe855564b2014-07-25 02:32:19 -070033main="Main"
jeffhao5d1ac922011-09-29 17:41:15 -070034
35while true; do
36 if [ "x$1" = "x--quiet" ]; then
37 QUIET="y"
38 shift
Alex Lighta59dd802014-07-02 16:28:08 -070039 elif [ "x$1" = "x--prebuild" ]; then
40 PREBUILD="y"
41 shift
Nicolas Geoffray1b4e2522014-10-04 10:40:54 +010042 elif [ "x$1" = "x--no-prebuild" ]; then
43 PREBUILD="n"
44 shift
Alex Light03a112d2014-08-25 13:25:56 -070045 elif [ "x$1" = "x--no-dex2oat" ]; then
46 DEX2OAT="-Xcompiler:${FALSE_BIN}"
47 shift
48 elif [ "x$1" = "x--no-patchoat" ]; then
49 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
50 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070051 elif [ "x$1" = "x--lib" ]; then
Brian Carlstromfa42b442013-06-17 12:53:45 -070052 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070053 if [ "x$1" = "x" ]; then
54 echo "$0 missing argument to --lib" 1>&2
55 exit 1
56 fi
Brian Carlstromfa42b442013-06-17 12:53:45 -070057 LIB="$1"
Ian Rogers2a65d4b2014-06-16 22:16:21 -070058 if [ `uname` = "Darwin" ]; then
59 LIB=${LIB/%so/dylib}
60 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -070061 shift
Alex Light03a112d2014-08-25 13:25:56 -070062 elif [ "x$1" = "x--no-image" ]; then
63 HAVE_IMAGE="n"
64 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070065 elif [ "x$1" = "x--boot" ]; then
66 shift
Alex Lighta59dd802014-07-02 16:28:08 -070067 option="$1"
68 BOOT_OPT="$option"
69 BUILD_BOOT_OPT="--boot-image=${option#-Ximage:}"
Ian Rogers6950e652012-08-28 18:20:00 -070070 shift
jeffhao5d1ac922011-09-29 17:41:15 -070071 elif [ "x$1" = "x--debug" ]; then
Brian Carlstromfa42b442013-06-17 12:53:45 -070072 DEBUGGER="y"
Ian Rogers741c02c2014-09-14 22:49:15 -070073 TIME_OUT="n"
jeffhao5d1ac922011-09-29 17:41:15 -070074 shift
75 elif [ "x$1" = "x--gdb" ]; then
76 GDB="y"
Ian Rogers6030ef42013-02-20 14:15:53 -080077 DEV_MODE="y"
Ian Rogers741c02c2014-09-14 22:49:15 -070078 TIME_OUT="n"
jeffhao5d1ac922011-09-29 17:41:15 -070079 shift
Elliott Hughes7c046102011-10-19 18:16:03 -070080 elif [ "x$1" = "x--invoke-with" ]; then
81 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070082 if [ "x$1" = "x" ]; then
83 echo "$0 missing argument to --invoke-with" 1>&2
84 exit 1
85 fi
Ian Rogers0e033672013-04-19 10:22:46 -070086 if [ "x$INVOKE_WITH" = "x" ]; then
87 INVOKE_WITH="$1"
88 else
89 INVOKE_WITH="$INVOKE_WITH $1"
90 fi
jeffhao5d1ac922011-09-29 17:41:15 -070091 shift
92 elif [ "x$1" = "x--dev" ]; then
93 DEV_MODE="y"
94 shift
jeffhao0dff3f42012-11-20 15:13:43 -080095 elif [ "x$1" = "x--interpreter" ]; then
96 INTERPRETER="y"
97 shift
Ian Rogersafd9acc2014-06-17 08:21:54 -070098 elif [ "x$1" = "x--64" ]; then
Alex Light60ffbca2014-08-21 10:00:27 -070099 ISA="x86_64"
Ian Rogersafd9acc2014-06-17 08:21:54 -0700100 exe="${ANDROID_HOST_OUT}/bin/dalvikvm64"
101 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700102 elif [ "x$1" = "x--no-verify" ]; then
103 VERIFY="n"
104 shift
105 elif [ "x$1" = "x--no-optimize" ]; then
106 OPTIMIZE="n"
107 shift
Alex Lighta59dd802014-07-02 16:28:08 -0700108 elif [ "x$1" = "x--no-relocate" ]; then
109 RELOCATE="n"
110 shift
111 elif [ "x$1" = "x--relocate" ]; then
112 RELOCATE="y"
113 shift
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000114 elif [ "x$1" = "x-Xcompiler-option" ]; then
115 shift
116 option="$1"
Mathieu Chartier769a5ad2014-05-18 15:30:10 -0700117 FLAGS="${FLAGS} -Xcompiler-option $option"
Alex Lighta59dd802014-07-02 16:28:08 -0700118 COMPILER_FLAGS="${COMPILER_FLAGS} $option"
Mathieu Chartier769a5ad2014-05-18 15:30:10 -0700119 shift
120 elif [ "x$1" = "x--runtime-option" ]; then
121 shift
122 option="$1"
123 FLAGS="${FLAGS} $option"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000124 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700125 elif [ "x$1" = "x--" ]; then
126 shift
127 break
128 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700129 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700130 exit 1
131 else
132 break
133 fi
134done
135
Andreas Gampe855564b2014-07-25 02:32:19 -0700136if [ "x$1" = "x" ] ; then
137 main="Main"
138else
139 main="$1"
140fi
141
jeffhao5d1ac922011-09-29 17:41:15 -0700142msg "------------------------------"
143
jeffhao5d1ac922011-09-29 17:41:15 -0700144export ANDROID_PRINTF_LOG=brief
145if [ "$DEV_MODE" = "y" ]; then
146 export ANDROID_LOG_TAGS='*:d'
147else
148 export ANDROID_LOG_TAGS='*:s'
149fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700150export ANDROID_DATA="$DEX_LOCATION"
Elliott Hughese7fb2a62012-04-23 12:39:12 -0700151export ANDROID_ROOT="${ANDROID_HOST_OUT}"
jeffhao5d1ac922011-09-29 17:41:15 -0700152export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
153export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
154
Brian Carlstromfa42b442013-06-17 12:53:45 -0700155if [ "$DEBUGGER" = "y" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700156 PORT=8000
Elliott Hughes72395bf2012-04-24 13:45:26 -0700157 msg "Waiting for jdb to connect:"
158 msg " jdb -attach localhost:$PORT"
Brian Carlstromfa42b442013-06-17 12:53:45 -0700159 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
jeffhao5d1ac922011-09-29 17:41:15 -0700160fi
161
162if [ "$GDB" = "y" ]; then
Ian Rogers2a65d4b2014-06-16 22:16:21 -0700163 if [ `uname` = "Darwin" ]; then
164 gdb=lldb
165 gdbargs="-- $exe"
166 exe=
167 else
168 gdb=gdb
169 gdbargs="--args $exe"
170 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
171 # gdbargs="--annotate=3 $gdbargs"
172 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700173fi
174
jeffhao0dff3f42012-11-20 15:13:43 -0800175if [ "$INTERPRETER" = "y" ]; then
176 INT_OPTS="-Xint"
Alex Lighta59dd802014-07-02 16:28:08 -0700177 COMPILER_FLAGS="${COMPILER_FLAGS} --compiler-filter=interpret-only"
178fi
179
Alex Light03a112d2014-08-25 13:25:56 -0700180if [ "$HAVE_IMAGE" = "n" ]; then
Alex Light1ef4ce82014-08-27 11:13:47 -0700181 # Set image to a place were there isn't one.
182 BOOT_OPT="-Ximage:/system/non-existant/core.art"
Alex Light03a112d2014-08-25 13:25:56 -0700183fi
184
Alex Lighta59dd802014-07-02 16:28:08 -0700185if [ "$RELOCATE" = "y" ]; then
186 FLAGS="${FLAGS} -Xrelocate"
187 COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -Xnorelocate --include-patch-information"
188 # Run test sets a fairly draconian ulimit that we will likely blow right over
189 # since we are relocating. Get the total size of the /system/framework directory
190 # in 512 byte blocks and set it as the ulimit. This should be more than enough
191 # room.
Brian Carlstromc580e042014-09-08 21:37:39 -0700192 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
193 ulimit -S $(du -c -B512 ${ANDROID_ROOT}/framework | tail -1 | cut -f1) || exit 1
194 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700195else
196 FLAGS="${FLAGS} -Xnorelocate"
197 COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -Xnorelocate --no-include-patch-information"
198fi
199
200mkdir_cmd="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
201if [ "$PREBUILD" = "y" ]; then
202 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")"
203else
204 prebuild_cmd="true"
jeffhao0dff3f42012-11-20 15:13:43 -0800205fi
206
Mathieu Chartierdbe6f462012-09-25 16:54:50 -0700207JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
Alex Light03a112d2014-08-25 13:25:56 -0700208cmdline="$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"
Ian Rogers741c02c2014-09-14 22:49:15 -0700209if [ "$TIME_OUT" = "y" ]; then
210 # Add timeout command if time out is desired.
211 cmdline="timeout $TIME_OUT_VALUE $cmdline"
212fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700213if [ "$DEV_MODE" = "y" ]; then
Alex Lighta59dd802014-07-02 16:28:08 -0700214 if [ "$PREBUILD" = "y" ]; then
215 echo "$mkdir_cmd && $prebuild_cmd && $cmdline"
216 elif [ "$RELOCATE" = "y" ]; then
217 echo "$mkdir_cmd && $cmdline"
218 else
219 echo $cmdline
220 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700221fi
222
Brian Carlstrom4855cd52012-04-03 21:38:13 -0700223cd $ANDROID_BUILD_TOP
Andreas Gampe1d9aa4d2014-09-04 14:19:51 -0700224
225$mkdir_cmd || exit 1
226$prebuild_cmd || exit 2
227
228if [ "$GDB" = "y" ]; then
229 # When running under gdb, we cannot do piping and grepping...
230 LD_PRELOAD=libsigchain.so $cmdline "$@"
231else
232 # If we are execing /bin/false we might not be on the same ISA as libsigchain.so
233 # ld.so will helpfully warn us of this. Unfortunately this messes up our error
234 # checking so we will just filter out the error with a grep.
Andreas Gampe441336c2014-09-15 09:40:03 -0700235 LD_PRELOAD=libsigchain.so $cmdline "$@" 2>&1 | grep -v -E "^ERROR: ld\.so: object '.+\.so' from LD_PRELOAD cannot be preloaded.*: ignored\.$"
Ian Rogers741c02c2014-09-14 22:49:15 -0700236 # Add extra detail if time out is enabled.
237 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "y" ]; then
238 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
239 fi
Nicolas Geoffraye7d66622014-09-25 16:40:07 +0100240fi