Nicolas Geoffray | e7d6662 | 2014-09-25 16:40:07 +0100 | [diff] [blame] | 1 | #!/bin/bash |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 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 | 741c02c | 2014-09-14 22:49:15 -0700 | [diff] [blame] | 30 | TIME_OUT="y" |
| 31 | TIME_OUT_VALUE=5m |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 32 | exe="${ANDROID_HOST_OUT}/bin/dalvikvm32" |
Andreas Gampe | 855564b | 2014-07-25 02:32:19 -0700 | [diff] [blame] | 33 | main="Main" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 34 | |
| 35 | while true; do |
| 36 | if [ "x$1" = "x--quiet" ]; then |
| 37 | QUIET="y" |
| 38 | shift |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 39 | elif [ "x$1" = "x--prebuild" ]; then |
| 40 | PREBUILD="y" |
| 41 | shift |
Nicolas Geoffray | 1b4e252 | 2014-10-04 10:40:54 +0100 | [diff] [blame] | 42 | elif [ "x$1" = "x--no-prebuild" ]; then |
| 43 | PREBUILD="n" |
| 44 | shift |
Alex Light | 03a112d | 2014-08-25 13:25:56 -0700 | [diff] [blame] | 45 | elif [ "x$1" = "x--no-dex2oat" ]; then |
| 46 | DEX2OAT="-Xcompiler:${FALSE_BIN}" |
| 47 | shift |
| 48 | elif [ "x$1" = "x--no-patchoat" ]; then |
| 49 | PATCHOAT="-Xpatchoat:${FALSE_BIN}" |
| 50 | shift |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 51 | elif [ "x$1" = "x--lib" ]; then |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 52 | shift |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 53 | if [ "x$1" = "x" ]; then |
| 54 | echo "$0 missing argument to --lib" 1>&2 |
| 55 | exit 1 |
| 56 | fi |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 57 | LIB="$1" |
Ian Rogers | 2a65d4b | 2014-06-16 22:16:21 -0700 | [diff] [blame] | 58 | if [ `uname` = "Darwin" ]; then |
| 59 | LIB=${LIB/%so/dylib} |
| 60 | fi |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 61 | shift |
Alex Light | 03a112d | 2014-08-25 13:25:56 -0700 | [diff] [blame] | 62 | elif [ "x$1" = "x--no-image" ]; then |
| 63 | HAVE_IMAGE="n" |
| 64 | shift |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 65 | elif [ "x$1" = "x--boot" ]; then |
| 66 | shift |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 67 | option="$1" |
| 68 | BOOT_OPT="$option" |
| 69 | BUILD_BOOT_OPT="--boot-image=${option#-Ximage:}" |
Ian Rogers | 6950e65 | 2012-08-28 18:20:00 -0700 | [diff] [blame] | 70 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 71 | elif [ "x$1" = "x--debug" ]; then |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 72 | DEBUGGER="y" |
Ian Rogers | 741c02c | 2014-09-14 22:49:15 -0700 | [diff] [blame] | 73 | TIME_OUT="n" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 74 | shift |
| 75 | elif [ "x$1" = "x--gdb" ]; then |
| 76 | GDB="y" |
Ian Rogers | 6030ef4 | 2013-02-20 14:15:53 -0800 | [diff] [blame] | 77 | DEV_MODE="y" |
Ian Rogers | 741c02c | 2014-09-14 22:49:15 -0700 | [diff] [blame] | 78 | TIME_OUT="n" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 79 | shift |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 80 | elif [ "x$1" = "x--invoke-with" ]; then |
| 81 | shift |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 82 | if [ "x$1" = "x" ]; then |
| 83 | echo "$0 missing argument to --invoke-with" 1>&2 |
| 84 | exit 1 |
| 85 | fi |
Ian Rogers | 0e03367 | 2013-04-19 10:22:46 -0700 | [diff] [blame] | 86 | if [ "x$INVOKE_WITH" = "x" ]; then |
| 87 | INVOKE_WITH="$1" |
| 88 | else |
| 89 | INVOKE_WITH="$INVOKE_WITH $1" |
| 90 | fi |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 91 | shift |
| 92 | elif [ "x$1" = "x--dev" ]; then |
| 93 | DEV_MODE="y" |
| 94 | shift |
jeffhao | 0dff3f4 | 2012-11-20 15:13:43 -0800 | [diff] [blame] | 95 | elif [ "x$1" = "x--interpreter" ]; then |
| 96 | INTERPRETER="y" |
| 97 | shift |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 98 | elif [ "x$1" = "x--64" ]; then |
Alex Light | 60ffbca | 2014-08-21 10:00:27 -0700 | [diff] [blame] | 99 | ISA="x86_64" |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 100 | exe="${ANDROID_HOST_OUT}/bin/dalvikvm64" |
| 101 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 102 | elif [ "x$1" = "x--no-verify" ]; then |
| 103 | VERIFY="n" |
| 104 | shift |
| 105 | elif [ "x$1" = "x--no-optimize" ]; then |
| 106 | OPTIMIZE="n" |
| 107 | shift |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 108 | elif [ "x$1" = "x--no-relocate" ]; then |
| 109 | RELOCATE="n" |
| 110 | shift |
| 111 | elif [ "x$1" = "x--relocate" ]; then |
| 112 | RELOCATE="y" |
| 113 | shift |
Nicolas Geoffray | 92cf83e | 2014-03-18 17:59:20 +0000 | [diff] [blame] | 114 | elif [ "x$1" = "x-Xcompiler-option" ]; then |
| 115 | shift |
| 116 | option="$1" |
Mathieu Chartier | 769a5ad | 2014-05-18 15:30:10 -0700 | [diff] [blame] | 117 | FLAGS="${FLAGS} -Xcompiler-option $option" |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 118 | COMPILER_FLAGS="${COMPILER_FLAGS} $option" |
Mathieu Chartier | 769a5ad | 2014-05-18 15:30:10 -0700 | [diff] [blame] | 119 | shift |
| 120 | elif [ "x$1" = "x--runtime-option" ]; then |
| 121 | shift |
| 122 | option="$1" |
| 123 | FLAGS="${FLAGS} $option" |
Nicolas Geoffray | 92cf83e | 2014-03-18 17:59:20 +0000 | [diff] [blame] | 124 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 125 | elif [ "x$1" = "x--" ]; then |
| 126 | shift |
| 127 | break |
| 128 | elif expr "x$1" : "x--" >/dev/null 2>&1; then |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 129 | echo "unknown $0 option: $1" 1>&2 |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 130 | exit 1 |
| 131 | else |
| 132 | break |
| 133 | fi |
| 134 | done |
| 135 | |
Andreas Gampe | 855564b | 2014-07-25 02:32:19 -0700 | [diff] [blame] | 136 | if [ "x$1" = "x" ] ; then |
| 137 | main="Main" |
| 138 | else |
| 139 | main="$1" |
| 140 | fi |
| 141 | |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 142 | msg "------------------------------" |
| 143 | |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 144 | export ANDROID_PRINTF_LOG=brief |
| 145 | if [ "$DEV_MODE" = "y" ]; then |
| 146 | export ANDROID_LOG_TAGS='*:d' |
| 147 | else |
| 148 | export ANDROID_LOG_TAGS='*:s' |
| 149 | fi |
Brian Carlstrom | 105215d | 2012-06-14 12:50:44 -0700 | [diff] [blame] | 150 | export ANDROID_DATA="$DEX_LOCATION" |
Elliott Hughes | e7fb2a6 | 2012-04-23 12:39:12 -0700 | [diff] [blame] | 151 | export ANDROID_ROOT="${ANDROID_HOST_OUT}" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 152 | export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib" |
| 153 | export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib" |
| 154 | |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 155 | if [ "$DEBUGGER" = "y" ]; then |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 156 | PORT=8000 |
Elliott Hughes | 72395bf | 2012-04-24 13:45:26 -0700 | [diff] [blame] | 157 | msg "Waiting for jdb to connect:" |
| 158 | msg " jdb -attach localhost:$PORT" |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 159 | DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 160 | fi |
| 161 | |
| 162 | if [ "$GDB" = "y" ]; then |
Ian Rogers | 2a65d4b | 2014-06-16 22:16:21 -0700 | [diff] [blame] | 163 | if [ `uname` = "Darwin" ]; then |
| 164 | gdb=lldb |
| 165 | gdbargs="-- $exe" |
| 166 | exe= |
| 167 | else |
| 168 | gdb=gdb |
| 169 | gdbargs="--args $exe" |
| 170 | # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line. |
| 171 | # gdbargs="--annotate=3 $gdbargs" |
| 172 | fi |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 173 | fi |
| 174 | |
jeffhao | 0dff3f4 | 2012-11-20 15:13:43 -0800 | [diff] [blame] | 175 | if [ "$INTERPRETER" = "y" ]; then |
| 176 | INT_OPTS="-Xint" |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 177 | COMPILER_FLAGS="${COMPILER_FLAGS} --compiler-filter=interpret-only" |
| 178 | fi |
| 179 | |
Alex Light | 03a112d | 2014-08-25 13:25:56 -0700 | [diff] [blame] | 180 | if [ "$HAVE_IMAGE" = "n" ]; then |
Alex Light | 1ef4ce8 | 2014-08-27 11:13:47 -0700 | [diff] [blame] | 181 | # Set image to a place were there isn't one. |
| 182 | BOOT_OPT="-Ximage:/system/non-existant/core.art" |
Alex Light | 03a112d | 2014-08-25 13:25:56 -0700 | [diff] [blame] | 183 | fi |
| 184 | |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 185 | if [ "$RELOCATE" = "y" ]; then |
| 186 | FLAGS="${FLAGS} -Xrelocate" |
| 187 | COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -Xnorelocate --include-patch-information" |
| 188 | # Run test sets a fairly draconian ulimit that we will likely blow right over |
| 189 | # since we are relocating. Get the total size of the /system/framework directory |
| 190 | # in 512 byte blocks and set it as the ulimit. This should be more than enough |
| 191 | # room. |
Brian Carlstrom | c580e04 | 2014-09-08 21:37:39 -0700 | [diff] [blame] | 192 | if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..." |
| 193 | ulimit -S $(du -c -B512 ${ANDROID_ROOT}/framework | tail -1 | cut -f1) || exit 1 |
| 194 | fi |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 195 | else |
| 196 | FLAGS="${FLAGS} -Xnorelocate" |
| 197 | COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -Xnorelocate --no-include-patch-information" |
| 198 | fi |
| 199 | |
| 200 | mkdir_cmd="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA" |
| 201 | if [ "$PREBUILD" = "y" ]; then |
| 202 | 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")" |
| 203 | else |
| 204 | prebuild_cmd="true" |
jeffhao | 0dff3f4 | 2012-11-20 15:13:43 -0800 | [diff] [blame] | 205 | fi |
| 206 | |
Mathieu Chartier | dbe6f46 | 2012-09-25 16:54:50 -0700 | [diff] [blame] | 207 | JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni" |
Alex Light | 03a112d | 2014-08-25 13:25:56 -0700 | [diff] [blame] | 208 | 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" |
Ian Rogers | 741c02c | 2014-09-14 22:49:15 -0700 | [diff] [blame] | 209 | if [ "$TIME_OUT" = "y" ]; then |
| 210 | # Add timeout command if time out is desired. |
| 211 | cmdline="timeout $TIME_OUT_VALUE $cmdline" |
| 212 | fi |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 213 | if [ "$DEV_MODE" = "y" ]; then |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 214 | if [ "$PREBUILD" = "y" ]; then |
| 215 | echo "$mkdir_cmd && $prebuild_cmd && $cmdline" |
| 216 | elif [ "$RELOCATE" = "y" ]; then |
| 217 | echo "$mkdir_cmd && $cmdline" |
| 218 | else |
| 219 | echo $cmdline |
| 220 | fi |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 221 | fi |
| 222 | |
Brian Carlstrom | 4855cd5 | 2012-04-03 21:38:13 -0700 | [diff] [blame] | 223 | cd $ANDROID_BUILD_TOP |
Andreas Gampe | 1d9aa4d | 2014-09-04 14:19:51 -0700 | [diff] [blame] | 224 | |
| 225 | $mkdir_cmd || exit 1 |
| 226 | $prebuild_cmd || exit 2 |
| 227 | |
| 228 | if [ "$GDB" = "y" ]; then |
| 229 | # When running under gdb, we cannot do piping and grepping... |
| 230 | LD_PRELOAD=libsigchain.so $cmdline "$@" |
| 231 | else |
| 232 | # If we are execing /bin/false we might not be on the same ISA as libsigchain.so |
| 233 | # ld.so will helpfully warn us of this. Unfortunately this messes up our error |
| 234 | # checking so we will just filter out the error with a grep. |
Andreas Gampe | 441336c | 2014-09-15 09:40:03 -0700 | [diff] [blame] | 235 | LD_PRELOAD=libsigchain.so $cmdline "$@" 2>&1 | grep -v -E "^ERROR: ld\.so: object '.+\.so' from LD_PRELOAD cannot be preloaded.*: ignored\.$" |
Ian Rogers | 741c02c | 2014-09-14 22:49:15 -0700 | [diff] [blame] | 236 | # Add extra detail if time out is enabled. |
| 237 | if [ ${PIPESTATUS[0]} = 124 ] && [ "$TIME_OUT" = "y" ]; then |
| 238 | echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2 |
| 239 | fi |
Nicolas Geoffray | e7d6662 | 2014-09-25 16:40:07 +0100 | [diff] [blame] | 240 | fi |