blob: 2241f85699e7ec62179e0210a862cd65756636de [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=""
Ian Rogersafd9acc2014-06-17 08:21:54 -070026exe="${ANDROID_HOST_OUT}/bin/dalvikvm32"
Andreas Gampe855564b2014-07-25 02:32:19 -070027main="Main"
jeffhao5d1ac922011-09-29 17:41:15 -070028
29while true; do
30 if [ "x$1" = "x--quiet" ]; then
31 QUIET="y"
32 shift
Alex Lighta59dd802014-07-02 16:28:08 -070033 elif [ "x$1" = "x--prebuild" ]; then
34 PREBUILD="y"
35 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070036 elif [ "x$1" = "x--lib" ]; then
Brian Carlstromfa42b442013-06-17 12:53:45 -070037 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070038 if [ "x$1" = "x" ]; then
39 echo "$0 missing argument to --lib" 1>&2
40 exit 1
41 fi
Brian Carlstromfa42b442013-06-17 12:53:45 -070042 LIB="$1"
Ian Rogers2a65d4b2014-06-16 22:16:21 -070043 if [ `uname` = "Darwin" ]; then
44 LIB=${LIB/%so/dylib}
45 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -070046 shift
47 elif [ "x$1" = "x--boot" ]; then
48 shift
Alex Lighta59dd802014-07-02 16:28:08 -070049 option="$1"
50 BOOT_OPT="$option"
51 BUILD_BOOT_OPT="--boot-image=${option#-Ximage:}"
Ian Rogers6950e652012-08-28 18:20:00 -070052 shift
jeffhao5d1ac922011-09-29 17:41:15 -070053 elif [ "x$1" = "x--debug" ]; then
Brian Carlstromfa42b442013-06-17 12:53:45 -070054 DEBUGGER="y"
jeffhao5d1ac922011-09-29 17:41:15 -070055 shift
56 elif [ "x$1" = "x--gdb" ]; then
57 GDB="y"
Ian Rogers6030ef42013-02-20 14:15:53 -080058 DEV_MODE="y"
jeffhao5d1ac922011-09-29 17:41:15 -070059 shift
Elliott Hughes7c046102011-10-19 18:16:03 -070060 elif [ "x$1" = "x--invoke-with" ]; then
61 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070062 if [ "x$1" = "x" ]; then
63 echo "$0 missing argument to --invoke-with" 1>&2
64 exit 1
65 fi
Ian Rogers0e033672013-04-19 10:22:46 -070066 if [ "x$INVOKE_WITH" = "x" ]; then
67 INVOKE_WITH="$1"
68 else
69 INVOKE_WITH="$INVOKE_WITH $1"
70 fi
jeffhao5d1ac922011-09-29 17:41:15 -070071 shift
72 elif [ "x$1" = "x--dev" ]; then
73 DEV_MODE="y"
74 shift
jeffhao0dff3f42012-11-20 15:13:43 -080075 elif [ "x$1" = "x--interpreter" ]; then
76 INTERPRETER="y"
77 shift
Ian Rogersafd9acc2014-06-17 08:21:54 -070078 elif [ "x$1" = "x--64" ]; then
Alex Lighta59dd802014-07-02 16:28:08 -070079 ISA="x64"
Ian Rogersafd9acc2014-06-17 08:21:54 -070080 exe="${ANDROID_HOST_OUT}/bin/dalvikvm64"
81 shift
jeffhao5d1ac922011-09-29 17:41:15 -070082 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
Alex Lighta59dd802014-07-02 16:28:08 -070088 elif [ "x$1" = "x--no-relocate" ]; then
89 RELOCATE="n"
90 shift
91 elif [ "x$1" = "x--relocate" ]; then
92 RELOCATE="y"
93 shift
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +000094 elif [ "x$1" = "x-Xcompiler-option" ]; then
95 shift
96 option="$1"
Mathieu Chartier769a5ad2014-05-18 15:30:10 -070097 FLAGS="${FLAGS} -Xcompiler-option $option"
Alex Lighta59dd802014-07-02 16:28:08 -070098 COMPILER_FLAGS="${COMPILER_FLAGS} $option"
Mathieu Chartier769a5ad2014-05-18 15:30:10 -070099 shift
100 elif [ "x$1" = "x--runtime-option" ]; then
101 shift
102 option="$1"
103 FLAGS="${FLAGS} $option"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000104 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700105 elif [ "x$1" = "x--" ]; then
106 shift
107 break
108 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700109 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700110 exit 1
111 else
112 break
113 fi
114done
115
Andreas Gampe855564b2014-07-25 02:32:19 -0700116if [ "x$1" = "x" ] ; then
117 main="Main"
118else
119 main="$1"
120fi
121
jeffhao5d1ac922011-09-29 17:41:15 -0700122msg "------------------------------"
123
jeffhao5d1ac922011-09-29 17:41:15 -0700124export ANDROID_PRINTF_LOG=brief
125if [ "$DEV_MODE" = "y" ]; then
126 export ANDROID_LOG_TAGS='*:d'
127else
128 export ANDROID_LOG_TAGS='*:s'
129fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700130export ANDROID_DATA="$DEX_LOCATION"
Elliott Hughese7fb2a62012-04-23 12:39:12 -0700131export ANDROID_ROOT="${ANDROID_HOST_OUT}"
jeffhao5d1ac922011-09-29 17:41:15 -0700132export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
133export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
134
Brian Carlstromfa42b442013-06-17 12:53:45 -0700135if [ "$DEBUGGER" = "y" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700136 PORT=8000
Elliott Hughes72395bf2012-04-24 13:45:26 -0700137 msg "Waiting for jdb to connect:"
138 msg " jdb -attach localhost:$PORT"
Brian Carlstromfa42b442013-06-17 12:53:45 -0700139 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
jeffhao5d1ac922011-09-29 17:41:15 -0700140fi
141
142if [ "$GDB" = "y" ]; then
Ian Rogers2a65d4b2014-06-16 22:16:21 -0700143 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
jeffhao5d1ac922011-09-29 17:41:15 -0700153fi
154
jeffhao0dff3f42012-11-20 15:13:43 -0800155if [ "$INTERPRETER" = "y" ]; then
156 INT_OPTS="-Xint"
Alex Lighta59dd802014-07-02 16:28:08 -0700157 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 ulimit -S $(du -c -B512 ${ANDROID_ROOT}/framework | tail -1 | cut -f1) || exit 1
168else
169 FLAGS="${FLAGS} -Xnorelocate"
170 COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -Xnorelocate --no-include-patch-information"
171fi
172
173mkdir_cmd="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
174if [ "$PREBUILD" = "y" ]; then
175 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")"
176else
177 prebuild_cmd="true"
jeffhao0dff3f42012-11-20 15:13:43 -0800178fi
179
Mathieu Chartierdbe6f462012-09-25 16:54:50 -0700180JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
Andreas Gampe855564b2014-07-25 02:32:19 -0700181cmdline="$INVOKE_WITH $gdb $exe $gdbargs -XXlib:$LIB $JNI_OPTS $FLAGS $INT_OPTS $DEBUGGER_OPTS $BOOT_OPT -cp $DEX_LOCATION/$TEST_NAME.jar $main"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700182if [ "$DEV_MODE" = "y" ]; then
Alex Lighta59dd802014-07-02 16:28:08 -0700183 if [ "$PREBUILD" = "y" ]; then
184 echo "$mkdir_cmd && $prebuild_cmd && $cmdline"
185 elif [ "$RELOCATE" = "y" ]; then
186 echo "$mkdir_cmd && $cmdline"
187 else
188 echo $cmdline
189 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700190fi
191
Brian Carlstrom4855cd52012-04-03 21:38:13 -0700192cd $ANDROID_BUILD_TOP
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700193$mkdir_cmd && $prebuild_cmd && LD_PRELOAD=libsigchain.so $cmdline "$@"