blob: d72e997fd1fdd0d5d25ca61bf2ed3921ad8260a0 [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"
jeffhao5d1ac922011-09-29 17:41:15 -070027
28while true; do
29 if [ "x$1" = "x--quiet" ]; then
30 QUIET="y"
31 shift
Alex Lighta59dd802014-07-02 16:28:08 -070032 elif [ "x$1" = "x--prebuild" ]; then
33 PREBUILD="y"
34 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070035 elif [ "x$1" = "x--lib" ]; then
Brian Carlstromfa42b442013-06-17 12:53:45 -070036 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070037 if [ "x$1" = "x" ]; then
38 echo "$0 missing argument to --lib" 1>&2
39 exit 1
40 fi
Brian Carlstromfa42b442013-06-17 12:53:45 -070041 LIB="$1"
Ian Rogers2a65d4b2014-06-16 22:16:21 -070042 if [ `uname` = "Darwin" ]; then
43 LIB=${LIB/%so/dylib}
44 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -070045 shift
46 elif [ "x$1" = "x--boot" ]; then
47 shift
Alex Lighta59dd802014-07-02 16:28:08 -070048 option="$1"
49 BOOT_OPT="$option"
50 BUILD_BOOT_OPT="--boot-image=${option#-Ximage:}"
Ian Rogers6950e652012-08-28 18:20:00 -070051 shift
jeffhao5d1ac922011-09-29 17:41:15 -070052 elif [ "x$1" = "x--debug" ]; then
Brian Carlstromfa42b442013-06-17 12:53:45 -070053 DEBUGGER="y"
jeffhao5d1ac922011-09-29 17:41:15 -070054 shift
55 elif [ "x$1" = "x--gdb" ]; then
56 GDB="y"
Ian Rogers6030ef42013-02-20 14:15:53 -080057 DEV_MODE="y"
jeffhao5d1ac922011-09-29 17:41:15 -070058 shift
Elliott Hughes7c046102011-10-19 18:16:03 -070059 elif [ "x$1" = "x--invoke-with" ]; then
60 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -070061 if [ "x$1" = "x" ]; then
62 echo "$0 missing argument to --invoke-with" 1>&2
63 exit 1
64 fi
Ian Rogers0e033672013-04-19 10:22:46 -070065 if [ "x$INVOKE_WITH" = "x" ]; then
66 INVOKE_WITH="$1"
67 else
68 INVOKE_WITH="$INVOKE_WITH $1"
69 fi
jeffhao5d1ac922011-09-29 17:41:15 -070070 shift
71 elif [ "x$1" = "x--dev" ]; then
72 DEV_MODE="y"
73 shift
jeffhao0dff3f42012-11-20 15:13:43 -080074 elif [ "x$1" = "x--interpreter" ]; then
75 INTERPRETER="y"
76 shift
Ian Rogersafd9acc2014-06-17 08:21:54 -070077 elif [ "x$1" = "x--64" ]; then
Alex Lighta59dd802014-07-02 16:28:08 -070078 ISA="x64"
Ian Rogersafd9acc2014-06-17 08:21:54 -070079 exe="${ANDROID_HOST_OUT}/bin/dalvikvm64"
80 shift
jeffhao5d1ac922011-09-29 17:41:15 -070081 elif [ "x$1" = "x--no-verify" ]; then
82 VERIFY="n"
83 shift
84 elif [ "x$1" = "x--no-optimize" ]; then
85 OPTIMIZE="n"
86 shift
Alex Lighta59dd802014-07-02 16:28:08 -070087 elif [ "x$1" = "x--no-relocate" ]; then
88 RELOCATE="n"
89 shift
90 elif [ "x$1" = "x--relocate" ]; then
91 RELOCATE="y"
92 shift
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +000093 elif [ "x$1" = "x-Xcompiler-option" ]; then
94 shift
95 option="$1"
Mathieu Chartier769a5ad2014-05-18 15:30:10 -070096 FLAGS="${FLAGS} -Xcompiler-option $option"
Alex Lighta59dd802014-07-02 16:28:08 -070097 COMPILER_FLAGS="${COMPILER_FLAGS} $option"
Mathieu Chartier769a5ad2014-05-18 15:30:10 -070098 shift
99 elif [ "x$1" = "x--runtime-option" ]; then
100 shift
101 option="$1"
102 FLAGS="${FLAGS} $option"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000103 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700104 elif [ "x$1" = "x--" ]; then
105 shift
106 break
107 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700108 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700109 exit 1
110 else
111 break
112 fi
113done
114
jeffhao5d1ac922011-09-29 17:41:15 -0700115msg "------------------------------"
116
jeffhao5d1ac922011-09-29 17:41:15 -0700117export ANDROID_PRINTF_LOG=brief
118if [ "$DEV_MODE" = "y" ]; then
119 export ANDROID_LOG_TAGS='*:d'
120else
121 export ANDROID_LOG_TAGS='*:s'
122fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700123export ANDROID_DATA="$DEX_LOCATION"
Elliott Hughese7fb2a62012-04-23 12:39:12 -0700124export ANDROID_ROOT="${ANDROID_HOST_OUT}"
jeffhao5d1ac922011-09-29 17:41:15 -0700125export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
126export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib"
127
Brian Carlstromfa42b442013-06-17 12:53:45 -0700128if [ "$DEBUGGER" = "y" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700129 PORT=8000
Elliott Hughes72395bf2012-04-24 13:45:26 -0700130 msg "Waiting for jdb to connect:"
131 msg " jdb -attach localhost:$PORT"
Brian Carlstromfa42b442013-06-17 12:53:45 -0700132 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
jeffhao5d1ac922011-09-29 17:41:15 -0700133fi
134
135if [ "$GDB" = "y" ]; then
Ian Rogers2a65d4b2014-06-16 22:16:21 -0700136 if [ `uname` = "Darwin" ]; then
137 gdb=lldb
138 gdbargs="-- $exe"
139 exe=
140 else
141 gdb=gdb
142 gdbargs="--args $exe"
143 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
144 # gdbargs="--annotate=3 $gdbargs"
145 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700146fi
147
jeffhao0dff3f42012-11-20 15:13:43 -0800148if [ "$INTERPRETER" = "y" ]; then
149 INT_OPTS="-Xint"
Alex Lighta59dd802014-07-02 16:28:08 -0700150 COMPILER_FLAGS="${COMPILER_FLAGS} --compiler-filter=interpret-only"
151fi
152
153if [ "$RELOCATE" = "y" ]; then
154 FLAGS="${FLAGS} -Xrelocate"
155 COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -Xnorelocate --include-patch-information"
156 # Run test sets a fairly draconian ulimit that we will likely blow right over
157 # since we are relocating. Get the total size of the /system/framework directory
158 # in 512 byte blocks and set it as the ulimit. This should be more than enough
159 # room.
160 ulimit -S $(du -c -B512 ${ANDROID_ROOT}/framework | tail -1 | cut -f1) || exit 1
161else
162 FLAGS="${FLAGS} -Xnorelocate"
163 COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -Xnorelocate --no-include-patch-information"
164fi
165
166mkdir_cmd="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA"
167if [ "$PREBUILD" = "y" ]; then
168 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")"
169else
170 prebuild_cmd="true"
jeffhao0dff3f42012-11-20 15:13:43 -0800171fi
172
Mathieu Chartierdbe6f462012-09-25 16:54:50 -0700173JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
Alex Lighta59dd802014-07-02 16:28:08 -0700174cmdline="$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 -0700175if [ "$DEV_MODE" = "y" ]; then
Alex Lighta59dd802014-07-02 16:28:08 -0700176 if [ "$PREBUILD" = "y" ]; then
177 echo "$mkdir_cmd && $prebuild_cmd && $cmdline"
178 elif [ "$RELOCATE" = "y" ]; then
179 echo "$mkdir_cmd && $cmdline"
180 else
181 echo $cmdline
182 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700183fi
184
Brian Carlstrom4855cd52012-04-03 21:38:13 -0700185cd $ANDROID_BUILD_TOP
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700186$mkdir_cmd && $prebuild_cmd && LD_PRELOAD=libsigchain.so $cmdline "$@"