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" |
Elliott Hughes | 4b0d1ee | 2011-11-30 14:11:39 -0800 | [diff] [blame] | 37 | export JAVAC="javac -g -target 1.5" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 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 |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 60 | elif [ "x$1" = "x-d" ]; then |
| 61 | run_args="${run_args} -d" |
| 62 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 63 | elif [ "x$1" = "x--debug" ]; then |
| 64 | run_args="${run_args} --debug" |
| 65 | shift |
| 66 | elif [ "x$1" = "x--gdb" ]; then |
| 67 | run_args="${run_args} --gdb" |
| 68 | dev_mode="yes" |
| 69 | shift |
| 70 | elif [ "x$1" = "x--zygote" ]; then |
| 71 | run_args="${run_args} --zygote" |
| 72 | shift |
| 73 | elif [ "x$1" = "x--no-verify" ]; then |
| 74 | run_args="${run_args} --no-verify" |
| 75 | shift |
| 76 | elif [ "x$1" = "x--no-optimize" ]; then |
| 77 | run_args="${run_args} --no-optimize" |
| 78 | shift |
| 79 | elif [ "x$1" = "x--no-precise" ]; then |
| 80 | run_args="${run_args} --no-precise" |
| 81 | shift |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 82 | elif [ "x$1" = "x--invoke-with" ]; then |
| 83 | shift |
| 84 | what="$1" |
| 85 | run_args="${run_args} --invoke-with \"${what}\"" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 86 | shift |
| 87 | elif [ "x$1" = "x--dev" ]; then |
| 88 | run_args="${run_args} --dev" |
| 89 | dev_mode="yes" |
| 90 | shift |
| 91 | elif [ "x$1" = "x--update" ]; then |
| 92 | update_mode="yes" |
| 93 | shift |
| 94 | elif [ "x$1" = "x--help" ]; then |
| 95 | usage="yes" |
| 96 | shift |
| 97 | elif expr "x$1" : "x--" >/dev/null 2>&1; then |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 98 | echo "unknown $0 option: $1" 1>&2 |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 99 | usage="yes" |
| 100 | break |
| 101 | else |
| 102 | break |
| 103 | fi |
| 104 | done |
| 105 | |
| 106 | if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then |
| 107 | echo "--dev and --update are mutually exclusive" 1>&2 |
| 108 | usage="yes" |
| 109 | fi |
| 110 | |
| 111 | if [ "$usage" = "no" ]; then |
| 112 | if [ "x$1" = "x" -o "x$1" = "x-" ]; then |
| 113 | test_dir=`basename "$oldwd"` |
| 114 | else |
| 115 | test_dir="$1" |
| 116 | fi |
| 117 | |
| 118 | if [ '!' -d "$test_dir" ]; then |
| 119 | td2=`echo ${test_dir}-*` |
| 120 | if [ '!' -d "$td2" ]; then |
| 121 | echo "${test_dir}: no such test directory" 1>&2 |
| 122 | usage="yes" |
| 123 | fi |
| 124 | test_dir="$td2" |
| 125 | fi |
| 126 | |
| 127 | # Shift to get rid of the test name argument. The rest of the arguments |
| 128 | # will get passed to the test run. |
| 129 | shift |
| 130 | fi |
| 131 | |
| 132 | if [ "$usage" = "yes" ]; then |
| 133 | prog=`basename $prog` |
| 134 | ( |
| 135 | echo "usage:" |
| 136 | echo " $prog --help Print this message." |
| 137 | echo " $prog [options] [test-name] Run test normally." |
| 138 | echo " $prog --dev [options] [test-name] Development mode" \ |
| 139 | "(dumps to stdout)." |
| 140 | echo " $prog --update [options] [test-name] Update mode" \ |
| 141 | "(replaces expected.txt)." |
| 142 | echo ' Omitting the test name or specifying "-" will use the' \ |
| 143 | "current directory." |
| 144 | echo " Runtime Options:" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 145 | echo " --debug Wait for a debugger to attach." |
| 146 | #echo " --gdb Run under gdb; incompatible with some tests." |
| 147 | echo " --no-verify Turn off verification (on by default)." |
| 148 | echo " --no-optimize Turn off optimization (on by default)." |
| 149 | echo " --no-precise Turn off precise GC (on by default)." |
| 150 | echo " --zygote Spawn the process from the Zygote." \ |
| 151 | "If used, then the" |
| 152 | echo " other runtime options are ignored." |
| 153 | echo " --host Use the host-mode virtual machine." |
| 154 | echo " --valgrind Use valgrind when running locally." |
| 155 | echo " --reference Use a host-local reference virtual machine." |
| 156 | ) 1>&2 |
| 157 | exit 1 |
| 158 | fi |
| 159 | |
| 160 | cd "$test_dir" |
| 161 | test_dir=`pwd` |
| 162 | |
| 163 | td_info="${test_dir}/${info}" |
| 164 | td_expected="${test_dir}/${expected}" |
| 165 | |
| 166 | tmp_dir="/tmp/test-$$" |
| 167 | |
| 168 | if [ '!' '(' -r "$td_info" -a -r "$td_expected" ')' ]; then |
| 169 | echo "${test_dir}: missing files" 1>&2 |
| 170 | exit 1 |
| 171 | fi |
| 172 | |
| 173 | # copy the test to a temp dir and run it |
| 174 | |
Elliott Hughes | 510c878 | 2011-10-06 10:57:34 -0700 | [diff] [blame] | 175 | echo "${test_dir}: building..." 1>&2 |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 176 | |
| 177 | rm -rf "$tmp_dir" |
| 178 | cp -Rp "$test_dir" "$tmp_dir" |
| 179 | cd "$tmp_dir" |
| 180 | |
| 181 | if [ '!' -r "$build" ]; then |
| 182 | cp "${progdir}/etc/default-build" build |
| 183 | fi |
| 184 | |
Elliott Hughes | 510c878 | 2011-10-06 10:57:34 -0700 | [diff] [blame] | 185 | echo "${test_dir}: running..." 1>&2 |
| 186 | |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 187 | if [ '!' -r "$run" ]; then |
| 188 | cp "${progdir}/etc/default-run" run |
| 189 | fi |
| 190 | |
| 191 | chmod 755 "$build" |
| 192 | chmod 755 "$run" |
| 193 | |
Elliott Hughes | 8cbc8bc | 2011-10-04 11:19:45 -0700 | [diff] [blame] | 194 | export TEST_NAME=`basename ${test_dir}` |
| 195 | |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 196 | good="no" |
| 197 | if [ "$dev_mode" = "yes" ]; then |
| 198 | "./${build}" 2>&1 |
| 199 | echo "build exit status: $?" 1>&2 |
| 200 | "./${run}" $run_args "$@" 2>&1 |
| 201 | echo "run exit status: $?" 1>&2 |
| 202 | good="yes" |
| 203 | elif [ "$update_mode" = "yes" ]; then |
| 204 | "./${build}" >"$build_output" 2>&1 |
| 205 | build_exit="$?" |
| 206 | if [ "$build_exit" = '0' ]; then |
| 207 | "./${run}" $run_args "$@" >"$output" 2>&1 |
| 208 | sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}" |
| 209 | good="yes" |
| 210 | else |
| 211 | cat "$build_output" 1>&2 |
| 212 | echo "build exit status: $build_exit" 1>&2 |
| 213 | fi |
| 214 | else |
| 215 | "./${build}" >"$build_output" 2>&1 |
| 216 | build_exit="$?" |
| 217 | if [ "$build_exit" = '0' ]; then |
| 218 | "./${run}" $run_args "$@" >"$output" 2>&1 |
| 219 | else |
| 220 | cp "$build_output" "$output" |
| 221 | echo "build exit status: $build_exit" >>"$output" |
| 222 | fi |
| 223 | diff --strip-trailing-cr -q "$expected" "$output" >/dev/null |
| 224 | if [ "$?" = "0" ]; then |
| 225 | # output == expected |
| 226 | good="yes" |
| 227 | echo "${test_dir}: succeeded!" 1>&2 |
| 228 | fi |
| 229 | fi |
| 230 | |
| 231 | if [ "$good" = "yes" ]; then |
| 232 | cd "$oldwd" |
| 233 | rm -rf "$tmp_dir" |
| 234 | exit 0 |
| 235 | fi |
| 236 | |
| 237 | ( |
| 238 | if [ "$update_mode" '!=' "yes" ]; then |
| 239 | echo "${test_dir}: FAILED!" |
| 240 | echo ' ' |
| 241 | echo '#################### info' |
| 242 | cat "${td_info}" | sed 's/^/# /g' |
| 243 | echo '#################### diffs' |
| 244 | diff --strip-trailing-cr -u "$expected" "$output" |
| 245 | echo '####################' |
| 246 | echo ' ' |
| 247 | fi |
Elliott Hughes | 8cbc8bc | 2011-10-04 11:19:45 -0700 | [diff] [blame] | 248 | echo "${TEST_NAME} files left in ${tmp_dir}" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 249 | ) 1>&2 |
| 250 | |
| 251 | exit 1 |