blob: 54a086574ac9a8938131b1b7bfa2e4ca85658017 [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 Rogersafd9acc2014-06-17 08:21:54 -070030exe="${ANDROID_HOST_OUT}/bin/dalvikvm32"
Andreas Gampe855564b2014-07-25 02:32:19 -070031main="Main"
jeffhao5d1ac922011-09-29 17:41:15 -070032
33while true; do
34 if [ "x$1" = "x--quiet" ]; then
35 QUIET="y"
36 shift
Alex Lighta59dd802014-07-02 16:28:08 -070037 elif [ "x$1" = "x--prebuild" ]; then
38 PREBUILD="y"
39 shift
Alex Light03a112d2014-08-25 13:25:56 -070040 elif [ "x$1" = "x--no-dex2oat" ]; then
41 DEX2OAT="-Xcompiler:${FALSE_BIN}"
42 shift
43 elif [ "x$1" = "x--no-patchoat" ]; then
44 PATCHOAT="-Xpatchoat:${FALSE_BIN}"
45 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070046 elif [ "x$1" = "x--lib" ]; then
Brian Carlstromfa42b442013-06-17 12:53:45 -070047 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070048 if [ "x$1" = "x" ]; then
49 echo "$0 missing argument to --lib" 1>&2
50 exit 1
51 fi
Brian Carlstromfa42b442013-06-17 12:53:45 -070052 LIB="$1"
Ian Rogers2a65d4b2014-06-16 22:16:21 -070053 if [ `uname` = "Darwin" ]; then
54 LIB=${LIB/%so/dylib}
55 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -070056 shift
Alex Light03a112d2014-08-25 13:25:56 -070057 elif [ "x$1" = "x--no-image" ]; then
58 HAVE_IMAGE="n"
59 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070060 elif [ "x$1" = "x--boot" ]; then
61 shift
Alex Lighta59dd802014-07-02 16:28:08 -070062 option="$1"
63 BOOT_OPT="$option"
64 BUILD_BOOT_OPT="--boot-image=${option#-Ximage:}"
Ian Rogers6950e652012-08-28 18:20:00 -070065 shift
jeffhao5d1ac922011-09-29 17:41:15 -070066 elif [ "x$1" = "x--debug" ]; then
Brian Carlstromfa42b442013-06-17 12:53:45 -070067 DEBUGGER="y"
jeffhao5d1ac922011-09-29 17:41:15 -070068 shift
69 elif [ "x$1" = "x--gdb" ]; then
70 GDB="y"
Ian Rogers6030ef42013-02-20 14:15:53 -080071 DEV_MODE="y"
jeffhao5d1ac922011-09-29 17:41:15 -070072 shift
Elliott Hughes7c046102011-10-19 18:16:03 -070073 elif [ "x$1" = "x--invoke-with" ]; then
74 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070075 if [ "x$1" = "x" ]; then
76 echo "$0 missing argument to --invoke-with" 1>&2
77 exit 1
78 fi
Ian Rogers0e033672013-04-19 10:22:46 -070079 if [ "x$INVOKE_WITH" = "x" ]; then
80 INVOKE_WITH="$1"
81 else
82 INVOKE_WITH="$INVOKE_WITH $1"
83 fi
jeffhao5d1ac922011-09-29 17:41:15 -070084 shift
85 elif [ "x$1" = "x--dev" ]; then
86 DEV_MODE="y"
87 shift
jeffhao0dff3f42012-11-20 15:13:43 -080088 elif [ "x$1" = "x--interpreter" ]; then
89 INTERPRETER="y"
90 shift
Ian Rogersafd9acc2014-06-17 08:21:54 -070091 elif [ "x$1" = "x--64" ]; then
Alex Light60ffbca2014-08-21 10:00:27 -070092 ISA="x86_64"
Ian Rogersafd9acc2014-06-17 08:21:54 -070093 exe="${ANDROID_HOST_OUT}/bin/dalvikvm64"
94 shift
jeffhao5d1ac922011-09-29 17:41:15 -070095 elif [ "x$1" = "x--no-verify" ]; then
96 VERIFY="n"
97 shift
98 elif [ "x$1" = "x--no-optimize" ]; then
99 OPTIMIZE="n"
100 shift
Alex Lighta59dd802014-07-02 16:28:08 -0700101 elif [ "x$1" = "x--no-relocate" ]; then
102 RELOCATE="n"
103 shift
104 elif [ "x$1" = "x--relocate" ]; then
105 RELOCATE="y"
106 shift
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000107 elif [ "x$1" = "x-Xcompiler-option" ]; then
108 shift
109 option="$1"
Mathieu Chartier769a5ad2014-05-18 15:30:10 -0700110 FLAGS="${FLAGS} -Xcompiler-option $option"
Alex Lighta59dd802014-07-02 16:28:08 -0700111 COMPILER_FLAGS="${COMPILER_FLAGS} $option"
Mathieu Chartier769a5ad2014-05-18 15:30:10 -0700112 shift
113 elif [ "x$1" = "x--runtime-option" ]; then
114 shift
115 option="$1"
116 FLAGS="${FLAGS} $option"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000117 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700118 elif [ "x$1" = "x--" ]; then
119 shift
120 break
121 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700122 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700123 exit 1
124 else
125 break
126 fi
127done
128
Andreas Gampe855564b2014-07-25 02:32:19 -0700129if [ "x$1" = "x" ] ; then
130 main="Main"
131else
132 main="$1"
133fi
134
jeffhao5d1ac922011-09-29 17:41:15 -0700135msg "------------------------------"
136
jeffhao5d1ac922011-09-29 17:41:15 -0700137export ANDROID_PRINTF_LOG=brief
138if [ "$DEV_MODE" = "y" ]; then
139 export ANDROID_LOG_TAGS='*:d'
140else
141 export ANDROID_LOG_TAGS='*:s'
142fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700143export ANDROID_DATA="$DEX_LOCATION"
Elliott Hughese7fb2a62012-04-23 12:39:12 -0700144export ANDROID_ROOT="${ANDROID_HOST_OUT}"
jeffhao5d1ac922011-09-29 17:41:15 -0700145export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
146export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
147
Brian Carlstromfa42b442013-06-17 12:53:45 -0700148if [ "$DEBUGGER" = "y" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700149 PORT=8000
Elliott Hughes72395bf2012-04-24 13:45:26 -0700150 msg "Waiting for jdb to connect:"
151 msg " jdb -attach localhost:$PORT"
Brian Carlstromfa42b442013-06-17 12:53:45 -0700152 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
jeffhao5d1ac922011-09-29 17:41:15 -0700153fi
154
155if [ "$GDB" = "y" ]; then
Ian Rogers2a65d4b2014-06-16 22:16:21 -0700156 if [ `uname` = "Darwin" ]; then
157 gdb=lldb
158 gdbargs="-- $exe"
159 exe=
160 else
161 gdb=gdb
162 gdbargs="--args $exe"
163 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
164 # gdbargs="--annotate=3 $gdbargs"
165 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700166fi
167
jeffhao0dff3f42012-11-20 15:13:43 -0800168if [ "$INTERPRETER" = "y" ]; then
169 INT_OPTS="-Xint"
Alex Lighta59dd802014-07-02 16:28:08 -0700170 COMPILER_FLAGS="${COMPILER_FLAGS} --compiler-filter=interpret-only"
171fi
172
Alex Light03a112d2014-08-25 13:25:56 -0700173if [ "$HAVE_IMAGE" = "n" ]; then
Alex Light1ef4ce82014-08-27 11:13:47 -0700174 # Set image to a place were there isn't one.
175 BOOT_OPT="-Ximage:/system/non-existant/core.art"
Alex Light03a112d2014-08-25 13:25:56 -0700176fi
177
Alex Lighta59dd802014-07-02 16:28:08 -0700178if [ "$RELOCATE" = "y" ]; then
179 FLAGS="${FLAGS} -Xrelocate"
180 COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -Xnorelocate --include-patch-information"
181 # Run test sets a fairly draconian ulimit that we will likely blow right over
182 # since we are relocating. Get the total size of the /system/framework directory
183 # in 512 byte blocks and set it as the ulimit. This should be more than enough
184 # room.
185 ulimit -S $(du -c -B512 ${ANDROID_ROOT}/framework | tail -1 | cut -f1) || exit 1
186else
187 FLAGS="${FLAGS} -Xnorelocate"
188 COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -Xnorelocate --no-include-patch-information"
189fi
190
191mkdir_cmd="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
192if [ "$PREBUILD" = "y" ]; then
193 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")"
194else
195 prebuild_cmd="true"
jeffhao0dff3f42012-11-20 15:13:43 -0800196fi
197
Mathieu Chartierdbe6f462012-09-25 16:54:50 -0700198JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
Alex Light03a112d2014-08-25 13:25:56 -0700199cmdline="$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"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700200if [ "$DEV_MODE" = "y" ]; then
Alex Lighta59dd802014-07-02 16:28:08 -0700201 if [ "$PREBUILD" = "y" ]; then
202 echo "$mkdir_cmd && $prebuild_cmd && $cmdline"
203 elif [ "$RELOCATE" = "y" ]; then
204 echo "$mkdir_cmd && $cmdline"
205 else
206 echo $cmdline
207 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700208fi
209
Brian Carlstrom4855cd52012-04-03 21:38:13 -0700210cd $ANDROID_BUILD_TOP
Alex Light03a112d2014-08-25 13:25:56 -0700211# If we are execing /bin/false we might not be on the same ISA as libsigchain.so
212# ld.so will helpfully warn us of this. Unfortunately this messes up our error
213# checking so we will just filter out the error with a grep.
214$mkdir_cmd && $prebuild_cmd && LD_PRELOAD=libsigchain.so $cmdline "$@" 2>&1 | grep -v -E "^ERROR: ld\.so: object '.+\.so' from LD_PRELOAD cannot be preloaded: ignored\.$"