jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) 2007 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # Set up prog to be the path of this script, including following symlinks, |
| 18 | # and set up progdir to be the fully-qualified pathname of its directory. |
| 19 | prog="$0" |
| 20 | while [ -h "${prog}" ]; do |
| 21 | newProg=`/bin/ls -ld "${prog}"` |
| 22 | newProg=`expr "${newProg}" : ".* -> \(.*\)$"` |
| 23 | if expr "x${newProg}" : 'x/' >/dev/null; then |
| 24 | prog="${newProg}" |
| 25 | else |
| 26 | progdir=`dirname "${prog}"` |
| 27 | prog="${progdir}/${newProg}" |
| 28 | fi |
| 29 | done |
| 30 | oldwd=`pwd` |
| 31 | progdir=`dirname "${prog}"` |
| 32 | cd "${progdir}" |
| 33 | progdir=`pwd` |
| 34 | prog="${progdir}"/`basename "${prog}"` |
| 35 | |
| 36 | export JAVA="java" |
| 37 | export JAVAC="javac -target 1.5" |
| 38 | export RUN="${progdir}/etc/push-and-run-test-jar" |
| 39 | |
| 40 | info="info.txt" |
| 41 | build="build" |
| 42 | run="run" |
| 43 | expected="expected.txt" |
| 44 | output="output.txt" |
| 45 | build_output="build-output.txt" |
| 46 | run_args="--quiet" |
| 47 | |
| 48 | dev_mode="no" |
| 49 | update_mode="no" |
| 50 | debug_mode="no" |
| 51 | usage="no" |
| 52 | |
| 53 | while true; do |
| 54 | if [ "x$1" = "x--host" ]; then |
| 55 | RUN="${progdir}/etc/host-run-test-jar" |
| 56 | shift |
| 57 | elif [ "x$1" = "x--reference" ]; then |
| 58 | RUN="${progdir}/etc/reference-run-test-classes" |
| 59 | shift |
| 60 | elif [ "x$1" = "x--jit" ]; then |
| 61 | run_args="${run_args} --jit" |
| 62 | shift |
| 63 | elif [ "x$1" = "x--fast" ]; then |
| 64 | run_args="${run_args} --fast" |
| 65 | shift |
| 66 | elif [ "x$1" = "x--portable" ]; then |
| 67 | run_args="${run_args} --portable" |
| 68 | shift |
| 69 | elif [ "x$1" = "x--debug" ]; then |
| 70 | run_args="${run_args} --debug" |
| 71 | shift |
| 72 | elif [ "x$1" = "x--gdb" ]; then |
| 73 | run_args="${run_args} --gdb" |
| 74 | dev_mode="yes" |
| 75 | shift |
| 76 | elif [ "x$1" = "x--zygote" ]; then |
| 77 | run_args="${run_args} --zygote" |
| 78 | shift |
| 79 | elif [ "x$1" = "x--no-verify" ]; then |
| 80 | run_args="${run_args} --no-verify" |
| 81 | shift |
| 82 | elif [ "x$1" = "x--no-optimize" ]; then |
| 83 | run_args="${run_args} --no-optimize" |
| 84 | shift |
| 85 | elif [ "x$1" = "x--no-precise" ]; then |
| 86 | run_args="${run_args} --no-precise" |
| 87 | shift |
| 88 | elif [ "x$1" = "x--valgrind" ]; then |
| 89 | run_args="${run_args} --valgrind" |
| 90 | shift |
| 91 | elif [ "x$1" = "x--dev" ]; then |
| 92 | run_args="${run_args} --dev" |
| 93 | dev_mode="yes" |
| 94 | shift |
| 95 | elif [ "x$1" = "x--update" ]; then |
| 96 | update_mode="yes" |
| 97 | shift |
| 98 | elif [ "x$1" = "x--help" ]; then |
| 99 | usage="yes" |
| 100 | shift |
| 101 | elif expr "x$1" : "x--" >/dev/null 2>&1; then |
| 102 | echo "unknown option: $1" 1>&2 |
| 103 | usage="yes" |
| 104 | break |
| 105 | else |
| 106 | break |
| 107 | fi |
| 108 | done |
| 109 | |
| 110 | if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then |
| 111 | echo "--dev and --update are mutually exclusive" 1>&2 |
| 112 | usage="yes" |
| 113 | fi |
| 114 | |
| 115 | if [ "$usage" = "no" ]; then |
| 116 | if [ "x$1" = "x" -o "x$1" = "x-" ]; then |
| 117 | test_dir=`basename "$oldwd"` |
| 118 | else |
| 119 | test_dir="$1" |
| 120 | fi |
| 121 | |
| 122 | if [ '!' -d "$test_dir" ]; then |
| 123 | td2=`echo ${test_dir}-*` |
| 124 | if [ '!' -d "$td2" ]; then |
| 125 | echo "${test_dir}: no such test directory" 1>&2 |
| 126 | usage="yes" |
| 127 | fi |
| 128 | test_dir="$td2" |
| 129 | fi |
| 130 | |
| 131 | # Shift to get rid of the test name argument. The rest of the arguments |
| 132 | # will get passed to the test run. |
| 133 | shift |
| 134 | fi |
| 135 | |
| 136 | if [ "$usage" = "yes" ]; then |
| 137 | prog=`basename $prog` |
| 138 | ( |
| 139 | echo "usage:" |
| 140 | echo " $prog --help Print this message." |
| 141 | echo " $prog [options] [test-name] Run test normally." |
| 142 | echo " $prog --dev [options] [test-name] Development mode" \ |
| 143 | "(dumps to stdout)." |
| 144 | echo " $prog --update [options] [test-name] Update mode" \ |
| 145 | "(replaces expected.txt)." |
| 146 | echo ' Omitting the test name or specifying "-" will use the' \ |
| 147 | "current directory." |
| 148 | echo " Runtime Options:" |
| 149 | echo " --fast Use the fast interpreter (the default)." |
| 150 | echo " --jit Use the jit." |
| 151 | echo " --portable Use the portable interpreter." |
| 152 | echo " --debug Wait for a debugger to attach." |
| 153 | #echo " --gdb Run under gdb; incompatible with some tests." |
| 154 | echo " --no-verify Turn off verification (on by default)." |
| 155 | echo " --no-optimize Turn off optimization (on by default)." |
| 156 | echo " --no-precise Turn off precise GC (on by default)." |
| 157 | echo " --zygote Spawn the process from the Zygote." \ |
| 158 | "If used, then the" |
| 159 | echo " other runtime options are ignored." |
| 160 | echo " --host Use the host-mode virtual machine." |
| 161 | echo " --valgrind Use valgrind when running locally." |
| 162 | echo " --reference Use a host-local reference virtual machine." |
| 163 | ) 1>&2 |
| 164 | exit 1 |
| 165 | fi |
| 166 | |
| 167 | cd "$test_dir" |
| 168 | test_dir=`pwd` |
| 169 | |
| 170 | td_info="${test_dir}/${info}" |
| 171 | td_expected="${test_dir}/${expected}" |
| 172 | |
| 173 | tmp_dir="/tmp/test-$$" |
| 174 | |
| 175 | if [ '!' '(' -r "$td_info" -a -r "$td_expected" ')' ]; then |
| 176 | echo "${test_dir}: missing files" 1>&2 |
| 177 | exit 1 |
| 178 | fi |
| 179 | |
| 180 | # copy the test to a temp dir and run it |
| 181 | |
| 182 | echo "${test_dir}: running..." 1>&2 |
| 183 | |
| 184 | rm -rf "$tmp_dir" |
| 185 | cp -Rp "$test_dir" "$tmp_dir" |
| 186 | cd "$tmp_dir" |
| 187 | |
| 188 | if [ '!' -r "$build" ]; then |
| 189 | cp "${progdir}/etc/default-build" build |
| 190 | fi |
| 191 | |
| 192 | if [ '!' -r "$run" ]; then |
| 193 | cp "${progdir}/etc/default-run" run |
| 194 | fi |
| 195 | |
| 196 | chmod 755 "$build" |
| 197 | chmod 755 "$run" |
| 198 | |
Elliott Hughes | 8cbc8bc | 2011-10-04 11:19:45 -0700 | [diff] [blame^] | 199 | export TEST_NAME=`basename ${test_dir}` |
| 200 | |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 201 | good="no" |
| 202 | if [ "$dev_mode" = "yes" ]; then |
| 203 | "./${build}" 2>&1 |
| 204 | echo "build exit status: $?" 1>&2 |
| 205 | "./${run}" $run_args "$@" 2>&1 |
| 206 | echo "run exit status: $?" 1>&2 |
| 207 | good="yes" |
| 208 | elif [ "$update_mode" = "yes" ]; then |
| 209 | "./${build}" >"$build_output" 2>&1 |
| 210 | build_exit="$?" |
| 211 | if [ "$build_exit" = '0' ]; then |
| 212 | "./${run}" $run_args "$@" >"$output" 2>&1 |
| 213 | sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}" |
| 214 | good="yes" |
| 215 | else |
| 216 | cat "$build_output" 1>&2 |
| 217 | echo "build exit status: $build_exit" 1>&2 |
| 218 | fi |
| 219 | else |
| 220 | "./${build}" >"$build_output" 2>&1 |
| 221 | build_exit="$?" |
| 222 | if [ "$build_exit" = '0' ]; then |
| 223 | "./${run}" $run_args "$@" >"$output" 2>&1 |
| 224 | else |
| 225 | cp "$build_output" "$output" |
| 226 | echo "build exit status: $build_exit" >>"$output" |
| 227 | fi |
| 228 | diff --strip-trailing-cr -q "$expected" "$output" >/dev/null |
| 229 | if [ "$?" = "0" ]; then |
| 230 | # output == expected |
| 231 | good="yes" |
| 232 | echo "${test_dir}: succeeded!" 1>&2 |
| 233 | fi |
| 234 | fi |
| 235 | |
| 236 | if [ "$good" = "yes" ]; then |
| 237 | cd "$oldwd" |
| 238 | rm -rf "$tmp_dir" |
| 239 | exit 0 |
| 240 | fi |
| 241 | |
| 242 | ( |
| 243 | if [ "$update_mode" '!=' "yes" ]; then |
| 244 | echo "${test_dir}: FAILED!" |
| 245 | echo ' ' |
| 246 | echo '#################### info' |
| 247 | cat "${td_info}" | sed 's/^/# /g' |
| 248 | echo '#################### diffs' |
| 249 | diff --strip-trailing-cr -u "$expected" "$output" |
| 250 | echo '####################' |
| 251 | echo ' ' |
| 252 | fi |
Elliott Hughes | 8cbc8bc | 2011-10-04 11:19:45 -0700 | [diff] [blame^] | 253 | echo "${TEST_NAME} files left in ${tmp_dir}" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 254 | ) 1>&2 |
| 255 | |
| 256 | exit 1 |