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