jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 1 | #!/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. |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 5 | |
| 6 | msg() { |
| 7 | if [ "$QUIET" = "n" ]; then |
| 8 | echo "$@" |
| 9 | fi |
| 10 | } |
| 11 | |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 12 | DEBUGGER="n" |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 13 | PREBUILD="n" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 14 | GDB="n" |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 15 | ISA="x86" |
jeffhao | 0dff3f4 | 2012-11-20 15:13:43 -0800 | [diff] [blame] | 16 | INTERPRETER="n" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 17 | VERIFY="y" |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 18 | RELOCATE="y" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 19 | OPTIMIZE="y" |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 20 | INVOKE_WITH="" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 21 | DEV_MODE="n" |
| 22 | QUIET="n" |
Mathieu Chartier | 769a5ad | 2014-05-18 15:30:10 -0700 | [diff] [blame] | 23 | FLAGS="" |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 24 | COMPILER_FLAGS="" |
| 25 | BUILD_BOOT_OPT="" |
Alex Light | 03a112d | 2014-08-25 13:25:56 -0700 | [diff] [blame] | 26 | PATCHOAT="" |
| 27 | DEX2OAT="" |
| 28 | FALSE_BIN="/bin/false" |
| 29 | HAVE_IMAGE="y" |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 30 | exe="${ANDROID_HOST_OUT}/bin/dalvikvm32" |
Andreas Gampe | 855564b | 2014-07-25 02:32:19 -0700 | [diff] [blame] | 31 | main="Main" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 32 | |
| 33 | while true; do |
| 34 | if [ "x$1" = "x--quiet" ]; then |
| 35 | QUIET="y" |
| 36 | shift |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 37 | elif [ "x$1" = "x--prebuild" ]; then |
| 38 | PREBUILD="y" |
| 39 | shift |
Alex Light | 03a112d | 2014-08-25 13:25:56 -0700 | [diff] [blame] | 40 | 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 Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 46 | elif [ "x$1" = "x--lib" ]; then |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 47 | shift |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 48 | if [ "x$1" = "x" ]; then |
| 49 | echo "$0 missing argument to --lib" 1>&2 |
| 50 | exit 1 |
| 51 | fi |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 52 | LIB="$1" |
Ian Rogers | 2a65d4b | 2014-06-16 22:16:21 -0700 | [diff] [blame] | 53 | if [ `uname` = "Darwin" ]; then |
| 54 | LIB=${LIB/%so/dylib} |
| 55 | fi |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 56 | shift |
Alex Light | 03a112d | 2014-08-25 13:25:56 -0700 | [diff] [blame] | 57 | elif [ "x$1" = "x--no-image" ]; then |
| 58 | HAVE_IMAGE="n" |
| 59 | shift |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 60 | elif [ "x$1" = "x--boot" ]; then |
| 61 | shift |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 62 | option="$1" |
| 63 | BOOT_OPT="$option" |
| 64 | BUILD_BOOT_OPT="--boot-image=${option#-Ximage:}" |
Ian Rogers | 6950e65 | 2012-08-28 18:20:00 -0700 | [diff] [blame] | 65 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 66 | elif [ "x$1" = "x--debug" ]; then |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 67 | DEBUGGER="y" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 68 | shift |
| 69 | elif [ "x$1" = "x--gdb" ]; then |
| 70 | GDB="y" |
Ian Rogers | 6030ef4 | 2013-02-20 14:15:53 -0800 | [diff] [blame] | 71 | DEV_MODE="y" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 72 | shift |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 73 | elif [ "x$1" = "x--invoke-with" ]; then |
| 74 | shift |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 75 | if [ "x$1" = "x" ]; then |
| 76 | echo "$0 missing argument to --invoke-with" 1>&2 |
| 77 | exit 1 |
| 78 | fi |
Ian Rogers | 0e03367 | 2013-04-19 10:22:46 -0700 | [diff] [blame] | 79 | if [ "x$INVOKE_WITH" = "x" ]; then |
| 80 | INVOKE_WITH="$1" |
| 81 | else |
| 82 | INVOKE_WITH="$INVOKE_WITH $1" |
| 83 | fi |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 84 | shift |
| 85 | elif [ "x$1" = "x--dev" ]; then |
| 86 | DEV_MODE="y" |
| 87 | shift |
jeffhao | 0dff3f4 | 2012-11-20 15:13:43 -0800 | [diff] [blame] | 88 | elif [ "x$1" = "x--interpreter" ]; then |
| 89 | INTERPRETER="y" |
| 90 | shift |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 91 | elif [ "x$1" = "x--64" ]; then |
Alex Light | 60ffbca | 2014-08-21 10:00:27 -0700 | [diff] [blame] | 92 | ISA="x86_64" |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 93 | exe="${ANDROID_HOST_OUT}/bin/dalvikvm64" |
| 94 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 95 | 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 Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 101 | 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 Geoffray | 92cf83e | 2014-03-18 17:59:20 +0000 | [diff] [blame] | 107 | elif [ "x$1" = "x-Xcompiler-option" ]; then |
| 108 | shift |
| 109 | option="$1" |
Mathieu Chartier | 769a5ad | 2014-05-18 15:30:10 -0700 | [diff] [blame] | 110 | FLAGS="${FLAGS} -Xcompiler-option $option" |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 111 | COMPILER_FLAGS="${COMPILER_FLAGS} $option" |
Mathieu Chartier | 769a5ad | 2014-05-18 15:30:10 -0700 | [diff] [blame] | 112 | shift |
| 113 | elif [ "x$1" = "x--runtime-option" ]; then |
| 114 | shift |
| 115 | option="$1" |
| 116 | FLAGS="${FLAGS} $option" |
Nicolas Geoffray | 92cf83e | 2014-03-18 17:59:20 +0000 | [diff] [blame] | 117 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 118 | elif [ "x$1" = "x--" ]; then |
| 119 | shift |
| 120 | break |
| 121 | elif expr "x$1" : "x--" >/dev/null 2>&1; then |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 122 | echo "unknown $0 option: $1" 1>&2 |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 123 | exit 1 |
| 124 | else |
| 125 | break |
| 126 | fi |
| 127 | done |
| 128 | |
Andreas Gampe | 855564b | 2014-07-25 02:32:19 -0700 | [diff] [blame] | 129 | if [ "x$1" = "x" ] ; then |
| 130 | main="Main" |
| 131 | else |
| 132 | main="$1" |
| 133 | fi |
| 134 | |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 135 | msg "------------------------------" |
| 136 | |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 137 | export ANDROID_PRINTF_LOG=brief |
| 138 | if [ "$DEV_MODE" = "y" ]; then |
| 139 | export ANDROID_LOG_TAGS='*:d' |
| 140 | else |
| 141 | export ANDROID_LOG_TAGS='*:s' |
| 142 | fi |
Brian Carlstrom | 105215d | 2012-06-14 12:50:44 -0700 | [diff] [blame] | 143 | export ANDROID_DATA="$DEX_LOCATION" |
Elliott Hughes | e7fb2a6 | 2012-04-23 12:39:12 -0700 | [diff] [blame] | 144 | export ANDROID_ROOT="${ANDROID_HOST_OUT}" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 145 | export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib" |
| 146 | export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib" |
| 147 | |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 148 | if [ "$DEBUGGER" = "y" ]; then |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 149 | PORT=8000 |
Elliott Hughes | 72395bf | 2012-04-24 13:45:26 -0700 | [diff] [blame] | 150 | msg "Waiting for jdb to connect:" |
| 151 | msg " jdb -attach localhost:$PORT" |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 152 | DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 153 | fi |
| 154 | |
| 155 | if [ "$GDB" = "y" ]; then |
Ian Rogers | 2a65d4b | 2014-06-16 22:16:21 -0700 | [diff] [blame] | 156 | 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 |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 166 | fi |
| 167 | |
jeffhao | 0dff3f4 | 2012-11-20 15:13:43 -0800 | [diff] [blame] | 168 | if [ "$INTERPRETER" = "y" ]; then |
| 169 | INT_OPTS="-Xint" |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 170 | COMPILER_FLAGS="${COMPILER_FLAGS} --compiler-filter=interpret-only" |
| 171 | fi |
| 172 | |
Alex Light | 03a112d | 2014-08-25 13:25:56 -0700 | [diff] [blame] | 173 | if [ "$HAVE_IMAGE" = "n" ]; then |
Alex Light | 1ef4ce8 | 2014-08-27 11:13:47 -0700 | [diff] [blame^] | 174 | # Set image to a place were there isn't one. |
| 175 | BOOT_OPT="-Ximage:/system/non-existant/core.art" |
Alex Light | 03a112d | 2014-08-25 13:25:56 -0700 | [diff] [blame] | 176 | fi |
| 177 | |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 178 | if [ "$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 |
| 186 | else |
| 187 | FLAGS="${FLAGS} -Xnorelocate" |
| 188 | COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -Xnorelocate --no-include-patch-information" |
| 189 | fi |
| 190 | |
| 191 | mkdir_cmd="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA" |
| 192 | if [ "$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")" |
| 194 | else |
| 195 | prebuild_cmd="true" |
jeffhao | 0dff3f4 | 2012-11-20 15:13:43 -0800 | [diff] [blame] | 196 | fi |
| 197 | |
Mathieu Chartier | dbe6f46 | 2012-09-25 16:54:50 -0700 | [diff] [blame] | 198 | JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni" |
Alex Light | 03a112d | 2014-08-25 13:25:56 -0700 | [diff] [blame] | 199 | cmdline="$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 Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 200 | if [ "$DEV_MODE" = "y" ]; then |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 201 | 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 Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 208 | fi |
| 209 | |
Brian Carlstrom | 4855cd5 | 2012-04-03 21:38:13 -0700 | [diff] [blame] | 210 | cd $ANDROID_BUILD_TOP |
Alex Light | 03a112d | 2014-08-25 13:25:56 -0700 | [diff] [blame] | 211 | # 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\.$" |