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="" |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 26 | exe="${ANDROID_HOST_OUT}/bin/dalvikvm32" |
Andreas Gampe | 855564b | 2014-07-25 02:32:19 -0700 | [diff] [blame^] | 27 | main="Main" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 28 | |
| 29 | while true; do |
| 30 | if [ "x$1" = "x--quiet" ]; then |
| 31 | QUIET="y" |
| 32 | shift |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 33 | elif [ "x$1" = "x--prebuild" ]; then |
| 34 | PREBUILD="y" |
| 35 | shift |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 36 | elif [ "x$1" = "x--lib" ]; then |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 37 | shift |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 38 | if [ "x$1" = "x" ]; then |
| 39 | echo "$0 missing argument to --lib" 1>&2 |
| 40 | exit 1 |
| 41 | fi |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 42 | LIB="$1" |
Ian Rogers | 2a65d4b | 2014-06-16 22:16:21 -0700 | [diff] [blame] | 43 | if [ `uname` = "Darwin" ]; then |
| 44 | LIB=${LIB/%so/dylib} |
| 45 | fi |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 46 | shift |
| 47 | elif [ "x$1" = "x--boot" ]; then |
| 48 | shift |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 49 | option="$1" |
| 50 | BOOT_OPT="$option" |
| 51 | BUILD_BOOT_OPT="--boot-image=${option#-Ximage:}" |
Ian Rogers | 6950e65 | 2012-08-28 18:20:00 -0700 | [diff] [blame] | 52 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 53 | elif [ "x$1" = "x--debug" ]; then |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 54 | DEBUGGER="y" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 55 | shift |
| 56 | elif [ "x$1" = "x--gdb" ]; then |
| 57 | GDB="y" |
Ian Rogers | 6030ef4 | 2013-02-20 14:15:53 -0800 | [diff] [blame] | 58 | DEV_MODE="y" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 59 | shift |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 60 | elif [ "x$1" = "x--invoke-with" ]; then |
| 61 | shift |
Brian Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 62 | if [ "x$1" = "x" ]; then |
| 63 | echo "$0 missing argument to --invoke-with" 1>&2 |
| 64 | exit 1 |
| 65 | fi |
Ian Rogers | 0e03367 | 2013-04-19 10:22:46 -0700 | [diff] [blame] | 66 | if [ "x$INVOKE_WITH" = "x" ]; then |
| 67 | INVOKE_WITH="$1" |
| 68 | else |
| 69 | INVOKE_WITH="$INVOKE_WITH $1" |
| 70 | fi |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 71 | shift |
| 72 | elif [ "x$1" = "x--dev" ]; then |
| 73 | DEV_MODE="y" |
| 74 | shift |
jeffhao | 0dff3f4 | 2012-11-20 15:13:43 -0800 | [diff] [blame] | 75 | elif [ "x$1" = "x--interpreter" ]; then |
| 76 | INTERPRETER="y" |
| 77 | shift |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 78 | elif [ "x$1" = "x--64" ]; then |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 79 | ISA="x64" |
Ian Rogers | afd9acc | 2014-06-17 08:21:54 -0700 | [diff] [blame] | 80 | exe="${ANDROID_HOST_OUT}/bin/dalvikvm64" |
| 81 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 82 | 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 Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 88 | 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 Geoffray | 92cf83e | 2014-03-18 17:59:20 +0000 | [diff] [blame] | 94 | elif [ "x$1" = "x-Xcompiler-option" ]; then |
| 95 | shift |
| 96 | option="$1" |
Mathieu Chartier | 769a5ad | 2014-05-18 15:30:10 -0700 | [diff] [blame] | 97 | FLAGS="${FLAGS} -Xcompiler-option $option" |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 98 | COMPILER_FLAGS="${COMPILER_FLAGS} $option" |
Mathieu Chartier | 769a5ad | 2014-05-18 15:30:10 -0700 | [diff] [blame] | 99 | shift |
| 100 | elif [ "x$1" = "x--runtime-option" ]; then |
| 101 | shift |
| 102 | option="$1" |
| 103 | FLAGS="${FLAGS} $option" |
Nicolas Geoffray | 92cf83e | 2014-03-18 17:59:20 +0000 | [diff] [blame] | 104 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 105 | elif [ "x$1" = "x--" ]; then |
| 106 | shift |
| 107 | break |
| 108 | elif expr "x$1" : "x--" >/dev/null 2>&1; then |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 109 | echo "unknown $0 option: $1" 1>&2 |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 110 | exit 1 |
| 111 | else |
| 112 | break |
| 113 | fi |
| 114 | done |
| 115 | |
Andreas Gampe | 855564b | 2014-07-25 02:32:19 -0700 | [diff] [blame^] | 116 | if [ "x$1" = "x" ] ; then |
| 117 | main="Main" |
| 118 | else |
| 119 | main="$1" |
| 120 | fi |
| 121 | |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 122 | msg "------------------------------" |
| 123 | |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 124 | export ANDROID_PRINTF_LOG=brief |
| 125 | if [ "$DEV_MODE" = "y" ]; then |
| 126 | export ANDROID_LOG_TAGS='*:d' |
| 127 | else |
| 128 | export ANDROID_LOG_TAGS='*:s' |
| 129 | fi |
Brian Carlstrom | 105215d | 2012-06-14 12:50:44 -0700 | [diff] [blame] | 130 | export ANDROID_DATA="$DEX_LOCATION" |
Elliott Hughes | e7fb2a6 | 2012-04-23 12:39:12 -0700 | [diff] [blame] | 131 | export ANDROID_ROOT="${ANDROID_HOST_OUT}" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 132 | export LD_LIBRARY_PATH="${ANDROID_ROOT}/lib" |
| 133 | export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/lib" |
| 134 | |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 135 | if [ "$DEBUGGER" = "y" ]; then |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 136 | PORT=8000 |
Elliott Hughes | 72395bf | 2012-04-24 13:45:26 -0700 | [diff] [blame] | 137 | msg "Waiting for jdb to connect:" |
| 138 | msg " jdb -attach localhost:$PORT" |
Brian Carlstrom | fa42b44 | 2013-06-17 12:53:45 -0700 | [diff] [blame] | 139 | DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 140 | fi |
| 141 | |
| 142 | if [ "$GDB" = "y" ]; then |
Ian Rogers | 2a65d4b | 2014-06-16 22:16:21 -0700 | [diff] [blame] | 143 | 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 |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 153 | fi |
| 154 | |
jeffhao | 0dff3f4 | 2012-11-20 15:13:43 -0800 | [diff] [blame] | 155 | if [ "$INTERPRETER" = "y" ]; then |
| 156 | INT_OPTS="-Xint" |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 157 | COMPILER_FLAGS="${COMPILER_FLAGS} --compiler-filter=interpret-only" |
| 158 | fi |
| 159 | |
| 160 | if [ "$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 |
| 168 | else |
| 169 | FLAGS="${FLAGS} -Xnorelocate" |
| 170 | COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -Xnorelocate --no-include-patch-information" |
| 171 | fi |
| 172 | |
| 173 | mkdir_cmd="mkdir -p ${DEX_LOCATION}/dalvik-cache/$ISA" |
| 174 | if [ "$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")" |
| 176 | else |
| 177 | prebuild_cmd="true" |
jeffhao | 0dff3f4 | 2012-11-20 15:13:43 -0800 | [diff] [blame] | 178 | fi |
| 179 | |
Mathieu Chartier | dbe6f46 | 2012-09-25 16:54:50 -0700 | [diff] [blame] | 180 | JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni" |
Andreas Gampe | 855564b | 2014-07-25 02:32:19 -0700 | [diff] [blame^] | 181 | cmdline="$INVOKE_WITH $gdb $exe $gdbargs -XXlib:$LIB $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] | 182 | if [ "$DEV_MODE" = "y" ]; then |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 183 | 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 Carlstrom | dc959ea | 2013-10-28 00:44:49 -0700 | [diff] [blame] | 190 | fi |
| 191 | |
Brian Carlstrom | 4855cd5 | 2012-04-03 21:38:13 -0700 | [diff] [blame] | 192 | cd $ANDROID_BUILD_TOP |
Andreas Gampe | 1c83cbc | 2014-07-22 18:52:29 -0700 | [diff] [blame] | 193 | $mkdir_cmd && $prebuild_cmd && LD_PRELOAD=libsigchain.so $cmdline "$@" |