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