blob: d2b3fb1869dea963998cf78ba02ebc1bec74d83c [file] [log] [blame]
jeffhao5d1ac922011-09-29 17:41:15 -07001#!/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.
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
Alex Light03a112d2014-08-25 13:25:56 -070042 elif [ "x$1" = "x--no-dex2oat" ]; then
43 DEX2OAT="-Xcompiler:${FALSE_BIN}"
44 shift
45 elif [ "x$1" = "x--no-patchoat" ]; then
46 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
47 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070048 elif [ "x$1" = "x--lib" ]; then
Brian Carlstromfa42b442013-06-17 12:53:45 -070049 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070050 if [ "x$1" = "x" ]; then
51 echo "$0 missing argument to --lib" 1>&2
52 exit 1
53 fi
Brian Carlstromfa42b442013-06-17 12:53:45 -070054 LIB="$1"
Ian Rogers2a65d4b2014-06-16 22:16:21 -070055 if [ `uname` = "Darwin" ]; then
56 LIB=${LIB/%so/dylib}
57 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -070058 shift
Alex Light03a112d2014-08-25 13:25:56 -070059 elif [ "x$1" = "x--no-image" ]; then
60 HAVE_IMAGE="n"
61 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070062 elif [ "x$1" = "x--boot" ]; then
63 shift
Alex Lighta59dd802014-07-02 16:28:08 -070064 option="$1"
65 BOOT_OPT="$option"
66 BUILD_BOOT_OPT="--boot-image=${option#-Ximage:}"
Ian Rogers6950e652012-08-28 18:20:00 -070067 shift
jeffhao5d1ac922011-09-29 17:41:15 -070068 elif [ "x$1" = "x--debug" ]; then
Brian Carlstromfa42b442013-06-17 12:53:45 -070069 DEBUGGER="y"
Ian Rogers741c02c2014-09-14 22:49:15 -070070 TIME_OUT="n"
jeffhao5d1ac922011-09-29 17:41:15 -070071 shift
72 elif [ "x$1" = "x--gdb" ]; then
73 GDB="y"
Ian Rogers6030ef42013-02-20 14:15:53 -080074 DEV_MODE="y"
Ian Rogers741c02c2014-09-14 22:49:15 -070075 TIME_OUT="n"
jeffhao5d1ac922011-09-29 17:41:15 -070076 shift
Elliott Hughes7c046102011-10-19 18:16:03 -070077 elif [ "x$1" = "x--invoke-with" ]; then
78 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070079 if [ "x$1" = "x" ]; then
80 echo "$0 missing argument to --invoke-with" 1>&2
81 exit 1
82 fi
Ian Rogers0e033672013-04-19 10:22:46 -070083 if [ "x$INVOKE_WITH" = "x" ]; then
84 INVOKE_WITH="$1"
85 else
86 INVOKE_WITH="$INVOKE_WITH $1"
87 fi
jeffhao5d1ac922011-09-29 17:41:15 -070088 shift
89 elif [ "x$1" = "x--dev" ]; then
90 DEV_MODE="y"
91 shift
jeffhao0dff3f42012-11-20 15:13:43 -080092 elif [ "x$1" = "x--interpreter" ]; then
93 INTERPRETER="y"
94 shift
Ian Rogersafd9acc2014-06-17 08:21:54 -070095 elif [ "x$1" = "x--64" ]; then
Alex Light60ffbca2014-08-21 10:00:27 -070096 ISA="x86_64"
Ian Rogersafd9acc2014-06-17 08:21:54 -070097 exe="${ANDROID_HOST_OUT}/bin/dalvikvm64"
98 shift
jeffhao5d1ac922011-09-29 17:41:15 -070099 elif [ "x$1" = "x--no-verify" ]; then
100 VERIFY="n"
101 shift
102 elif [ "x$1" = "x--no-optimize" ]; then
103 OPTIMIZE="n"
104 shift
Alex Lighta59dd802014-07-02 16:28:08 -0700105 elif [ "x$1" = "x--no-relocate" ]; then
106 RELOCATE="n"
107 shift
108 elif [ "x$1" = "x--relocate" ]; then
109 RELOCATE="y"
110 shift
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000111 elif [ "x$1" = "x-Xcompiler-option" ]; then
112 shift
113 option="$1"
Mathieu Chartier769a5ad2014-05-18 15:30:10 -0700114 FLAGS="${FLAGS} -Xcompiler-option $option"
Alex Lighta59dd802014-07-02 16:28:08 -0700115 COMPILER_FLAGS="${COMPILER_FLAGS} $option"
Mathieu Chartier769a5ad2014-05-18 15:30:10 -0700116 shift
117 elif [ "x$1" = "x--runtime-option" ]; then
118 shift
119 option="$1"
120 FLAGS="${FLAGS} $option"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000121 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700122 elif [ "x$1" = "x--" ]; then
123 shift
124 break
125 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700126 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700127 exit 1
128 else
129 break
130 fi
131done
132
Andreas Gampe855564b2014-07-25 02:32:19 -0700133if [ "x$1" = "x" ] ; then
134 main="Main"
135else
136 main="$1"
137fi
138
jeffhao5d1ac922011-09-29 17:41:15 -0700139msg "------------------------------"
140
jeffhao5d1ac922011-09-29 17:41:15 -0700141export ANDROID_PRINTF_LOG=brief
142if [ "$DEV_MODE" = "y" ]; then
143 export ANDROID_LOG_TAGS='*:d'
144else
145 export ANDROID_LOG_TAGS='*:s'
146fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700147export ANDROID_DATA="$DEX_LOCATION"
Elliott Hughese7fb2a62012-04-23 12:39:12 -0700148export ANDROID_ROOT="${ANDROID_HOST_OUT}"
jeffhao5d1ac922011-09-29 17:41:15 -0700149export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
150export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
151
Brian Carlstromfa42b442013-06-17 12:53:45 -0700152if [ "$DEBUGGER" = "y" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700153 PORT=8000
Elliott Hughes72395bf2012-04-24 13:45:26 -0700154 msg "Waiting for jdb to connect:"
155 msg " jdb -attach localhost:$PORT"
Brian Carlstromfa42b442013-06-17 12:53:45 -0700156 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
jeffhao5d1ac922011-09-29 17:41:15 -0700157fi
158
159if [ "$GDB" = "y" ]; then
Ian Rogers2a65d4b2014-06-16 22:16:21 -0700160 if [ `uname` = "Darwin" ]; then
161 gdb=lldb
162 gdbargs="-- $exe"
163 exe=
164 else
165 gdb=gdb
166 gdbargs="--args $exe"
167 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
168 # gdbargs="--annotate=3 $gdbargs"
169 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700170fi
171
jeffhao0dff3f42012-11-20 15:13:43 -0800172if [ "$INTERPRETER" = "y" ]; then
173 INT_OPTS="-Xint"
Alex Lighta59dd802014-07-02 16:28:08 -0700174 COMPILER_FLAGS="${COMPILER_FLAGS} --compiler-filter=interpret-only"
175fi
176
Alex Light03a112d2014-08-25 13:25:56 -0700177if [ "$HAVE_IMAGE" = "n" ]; then
Alex Light1ef4ce82014-08-27 11:13:47 -0700178 # Set image to a place were there isn't one.
179 BOOT_OPT="-Ximage:/system/non-existant/core.art"
Alex Light03a112d2014-08-25 13:25:56 -0700180fi
181
Alex Lighta59dd802014-07-02 16:28:08 -0700182if [ "$RELOCATE" = "y" ]; then
183 FLAGS="${FLAGS} -Xrelocate"
184 COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -Xnorelocate --include-patch-information"
185 # Run test sets a fairly draconian ulimit that we will likely blow right over
186 # since we are relocating. Get the total size of the /system/framework directory
187 # in 512 byte blocks and set it as the ulimit. This should be more than enough
188 # room.
Brian Carlstromc580e042014-09-08 21:37:39 -0700189 if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
190 ulimit -S $(du -c -B512 ${ANDROID_ROOT}/framework | tail -1 | cut -f1) || exit 1
191 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700192else
193 FLAGS="${FLAGS} -Xnorelocate"
194 COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -Xnorelocate --no-include-patch-information"
195fi
196
197mkdir_cmd="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
198if [ "$PREBUILD" = "y" ]; then
199 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")"
200else
201 prebuild_cmd="true"
jeffhao0dff3f42012-11-20 15:13:43 -0800202fi
203
Mathieu Chartierdbe6f462012-09-25 16:54:50 -0700204JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
Alex Light03a112d2014-08-25 13:25:56 -0700205cmdline="$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 -0700206if [ "$TIME_OUT" = "y" ]; then
207 # Add timeout command if time out is desired.
208 cmdline="timeout $TIME_OUT_VALUE $cmdline"
209fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700210if [ "$DEV_MODE" = "y" ]; then
Alex Lighta59dd802014-07-02 16:28:08 -0700211 if [ "$PREBUILD" = "y" ]; then
212 echo "$mkdir_cmd && $prebuild_cmd && $cmdline"
213 elif [ "$RELOCATE" = "y" ]; then
214 echo "$mkdir_cmd && $cmdline"
215 else
216 echo $cmdline
217 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700218fi
219
Brian Carlstrom4855cd52012-04-03 21:38:13 -0700220cd $ANDROID_BUILD_TOP
Andreas Gampe1d9aa4d2014-09-04 14:19:51 -0700221
222$mkdir_cmd || exit 1
223$prebuild_cmd || exit 2
224
225if [ "$GDB" = "y" ]; then
226 # When running under gdb, we cannot do piping and grepping...
227 LD_PRELOAD=libsigchain.so $cmdline "$@"
228else
229 # If we are execing /bin/false we might not be on the same ISA as libsigchain.so
230 # ld.so will helpfully warn us of this. Unfortunately this messes up our error
231 # checking so we will just filter out the error with a grep.
Andreas Gampe441336c2014-09-15 09:40:03 -0700232 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 -0700233 # Add extra detail if time out is enabled.
234 if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "y" ]; then
235 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
236 fi
Andreas Gampe1d9aa4d2014-09-04 14:19:51 -0700237fi