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}"` |
Brian Carlstrom | 105215d | 2012-06-14 12:50:44 -0700 | [diff] [blame] | 35 | test_dir="test-$$" |
| 36 | tmp_dir="/tmp/${test_dir}" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 37 | |
| 38 | export JAVA="java" |
Elliott Hughes | 4b0d1ee | 2011-11-30 14:11:39 -0800 | [diff] [blame] | 39 | export JAVAC="javac -g -target 1.5" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 40 | export RUN="${progdir}/etc/push-and-run-test-jar" |
Brian Carlstrom | 105215d | 2012-06-14 12:50:44 -0700 | [diff] [blame] | 41 | export DEX_LOCATION=/data/run-test/${test_dir} |
Elliott Hughes | c717eef | 2012-06-15 16:01:26 -0700 | [diff] [blame] | 42 | export NEED_DEX="true" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 43 | |
Tsu Chiang Chuang | 4407e61 | 2012-07-19 16:13:43 -0700 | [diff] [blame] | 44 | # If dx was not set by the environment variable, assume it is in the path. |
| 45 | if [ -z "$DX" ]; then |
| 46 | export DX="dx" |
| 47 | fi |
| 48 | |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 49 | info="info.txt" |
| 50 | build="build" |
| 51 | run="run" |
| 52 | expected="expected.txt" |
| 53 | output="output.txt" |
| 54 | build_output="build-output.txt" |
| 55 | run_args="--quiet" |
| 56 | |
Brian Carlstrom | 2613de4 | 2012-06-15 17:37:16 -0700 | [diff] [blame] | 57 | target_mode="yes" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 58 | dev_mode="no" |
| 59 | update_mode="no" |
| 60 | debug_mode="no" |
| 61 | usage="no" |
Tsu Chiang Chuang | 011fade | 2012-07-09 18:34:47 -0700 | [diff] [blame] | 62 | build_only="no" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 63 | |
| 64 | while true; do |
| 65 | if [ "x$1" = "x--host" ]; then |
Brian Carlstrom | 2613de4 | 2012-06-15 17:37:16 -0700 | [diff] [blame] | 66 | target_mode="no" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 67 | RUN="${progdir}/etc/host-run-test-jar" |
TDYa127 | b92bcab | 2012-04-08 00:09:51 -0700 | [diff] [blame] | 68 | DEX_LOCATION=$tmp_dir |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 69 | shift |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 70 | elif [ "x$1" = "x--jvm" ]; then |
Brian Carlstrom | 2613de4 | 2012-06-15 17:37:16 -0700 | [diff] [blame] | 71 | target_mode="no" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 72 | RUN="${progdir}/etc/reference-run-test-classes" |
Elliott Hughes | c717eef | 2012-06-15 16:01:26 -0700 | [diff] [blame] | 73 | NEED_DEX="false" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 74 | shift |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 75 | elif [ "x$1" = "x-O" ]; then |
| 76 | run_args="${run_args} -O" |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 77 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 78 | elif [ "x$1" = "x--debug" ]; then |
| 79 | run_args="${run_args} --debug" |
| 80 | shift |
| 81 | elif [ "x$1" = "x--gdb" ]; then |
| 82 | run_args="${run_args} --gdb" |
| 83 | dev_mode="yes" |
| 84 | shift |
| 85 | elif [ "x$1" = "x--zygote" ]; then |
| 86 | run_args="${run_args} --zygote" |
| 87 | shift |
| 88 | elif [ "x$1" = "x--no-verify" ]; then |
| 89 | run_args="${run_args} --no-verify" |
| 90 | shift |
| 91 | elif [ "x$1" = "x--no-optimize" ]; then |
| 92 | run_args="${run_args} --no-optimize" |
| 93 | shift |
| 94 | elif [ "x$1" = "x--no-precise" ]; then |
| 95 | run_args="${run_args} --no-precise" |
| 96 | shift |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 97 | elif [ "x$1" = "x--invoke-with" ]; then |
| 98 | shift |
| 99 | what="$1" |
| 100 | run_args="${run_args} --invoke-with \"${what}\"" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 101 | shift |
| 102 | elif [ "x$1" = "x--dev" ]; then |
| 103 | run_args="${run_args} --dev" |
| 104 | dev_mode="yes" |
| 105 | shift |
Tsu Chiang Chuang | 011fade | 2012-07-09 18:34:47 -0700 | [diff] [blame] | 106 | elif [ "x$1" = "x--build-only" ]; then |
| 107 | build_only="yes" |
| 108 | shift |
| 109 | elif [ "x$1" = "x--output-path" ]; then |
| 110 | shift |
| 111 | tmp_dir=$1 |
| 112 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 113 | elif [ "x$1" = "x--update" ]; then |
| 114 | update_mode="yes" |
| 115 | shift |
| 116 | elif [ "x$1" = "x--help" ]; then |
| 117 | usage="yes" |
| 118 | shift |
| 119 | elif expr "x$1" : "x--" >/dev/null 2>&1; then |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 120 | echo "unknown $0 option: $1" 1>&2 |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 121 | usage="yes" |
| 122 | break |
| 123 | else |
| 124 | break |
| 125 | fi |
| 126 | done |
| 127 | |
| 128 | if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then |
| 129 | echo "--dev and --update are mutually exclusive" 1>&2 |
| 130 | usage="yes" |
| 131 | fi |
| 132 | |
| 133 | if [ "$usage" = "no" ]; then |
| 134 | if [ "x$1" = "x" -o "x$1" = "x-" ]; then |
| 135 | test_dir=`basename "$oldwd"` |
| 136 | else |
| 137 | test_dir="$1" |
| 138 | fi |
| 139 | |
| 140 | if [ '!' -d "$test_dir" ]; then |
| 141 | td2=`echo ${test_dir}-*` |
| 142 | if [ '!' -d "$td2" ]; then |
| 143 | echo "${test_dir}: no such test directory" 1>&2 |
| 144 | usage="yes" |
| 145 | fi |
| 146 | test_dir="$td2" |
| 147 | fi |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 148 | # Shift to get rid of the test name argument. The rest of the arguments |
| 149 | # will get passed to the test run. |
| 150 | shift |
| 151 | fi |
| 152 | |
| 153 | if [ "$usage" = "yes" ]; then |
| 154 | prog=`basename $prog` |
| 155 | ( |
| 156 | echo "usage:" |
| 157 | echo " $prog --help Print this message." |
| 158 | echo " $prog [options] [test-name] Run test normally." |
| 159 | echo " $prog --dev [options] [test-name] Development mode" \ |
| 160 | "(dumps to stdout)." |
| 161 | echo " $prog --update [options] [test-name] Update mode" \ |
| 162 | "(replaces expected.txt)." |
| 163 | echo ' Omitting the test name or specifying "-" will use the' \ |
| 164 | "current directory." |
| 165 | echo " Runtime Options:" |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 166 | echo " -O Run oatexec rather than oatexecd (off by default)." |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 167 | echo " --debug Wait for a debugger to attach." |
| 168 | #echo " --gdb Run under gdb; incompatible with some tests." |
Tsu Chiang Chuang | 011fade | 2012-07-09 18:34:47 -0700 | [diff] [blame] | 169 | echo " --build-only Build test files only (off by default)." |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 170 | echo " --no-verify Turn off verification (on by default)." |
| 171 | echo " --no-optimize Turn off optimization (on by default)." |
| 172 | echo " --no-precise Turn off precise GC (on by default)." |
| 173 | echo " --zygote Spawn the process from the Zygote." \ |
| 174 | "If used, then the" |
| 175 | echo " other runtime options are ignored." |
| 176 | echo " --host Use the host-mode virtual machine." |
| 177 | echo " --valgrind Use valgrind when running locally." |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 178 | echo " --jvm Use a host-local RI virtual machine." |
Tsu Chiang Chuang | 011fade | 2012-07-09 18:34:47 -0700 | [diff] [blame] | 179 | echo " --output-path [path] Location where to store the build" \ |
| 180 | "files." |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 181 | ) 1>&2 |
| 182 | exit 1 |
| 183 | fi |
| 184 | |
| 185 | cd "$test_dir" |
| 186 | test_dir=`pwd` |
| 187 | |
| 188 | td_info="${test_dir}/${info}" |
| 189 | td_expected="${test_dir}/${expected}" |
| 190 | |
Brian Carlstrom | 22469aa | 2012-09-07 10:34:57 -0700 | [diff] [blame] | 191 | if [ ! -r $td_info ]; then |
| 192 | echo "${test_dir}: missing file $td_info" 1>&2 |
| 193 | exit 1 |
| 194 | fi |
| 195 | |
| 196 | if [ ! -r $td_expected ]; then |
| 197 | echo "${test_dir}: missing file $td_expected" 1>&2 |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 198 | exit 1 |
| 199 | fi |
| 200 | |
| 201 | # copy the test to a temp dir and run it |
| 202 | |
Elliott Hughes | 510c878 | 2011-10-06 10:57:34 -0700 | [diff] [blame] | 203 | echo "${test_dir}: building..." 1>&2 |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 204 | |
| 205 | rm -rf "$tmp_dir" |
| 206 | cp -Rp "$test_dir" "$tmp_dir" |
| 207 | cd "$tmp_dir" |
| 208 | |
| 209 | if [ '!' -r "$build" ]; then |
| 210 | cp "${progdir}/etc/default-build" build |
| 211 | fi |
| 212 | |
Elliott Hughes | 510c878 | 2011-10-06 10:57:34 -0700 | [diff] [blame] | 213 | echo "${test_dir}: running..." 1>&2 |
| 214 | |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 215 | if [ '!' -r "$run" ]; then |
| 216 | cp "${progdir}/etc/default-run" run |
| 217 | fi |
| 218 | |
| 219 | chmod 755 "$build" |
| 220 | chmod 755 "$run" |
| 221 | |
Elliott Hughes | 8cbc8bc | 2011-10-04 11:19:45 -0700 | [diff] [blame] | 222 | export TEST_NAME=`basename ${test_dir}` |
| 223 | |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 224 | good="no" |
| 225 | if [ "$dev_mode" = "yes" ]; then |
| 226 | "./${build}" 2>&1 |
Elliott Hughes | 7ab3a2a | 2012-06-18 16:34:20 -0700 | [diff] [blame] | 227 | build_exit="$?" |
| 228 | echo "build exit status: $build_exit" 1>&2 |
| 229 | if [ "$build_exit" = '0' ]; then |
| 230 | "./${run}" $run_args "$@" 2>&1 |
| 231 | echo "run exit status: $?" 1>&2 |
| 232 | good="yes" |
| 233 | fi |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 234 | elif [ "$update_mode" = "yes" ]; then |
| 235 | "./${build}" >"$build_output" 2>&1 |
| 236 | build_exit="$?" |
| 237 | if [ "$build_exit" = '0' ]; then |
| 238 | "./${run}" $run_args "$@" >"$output" 2>&1 |
| 239 | sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}" |
| 240 | good="yes" |
| 241 | else |
| 242 | cat "$build_output" 1>&2 |
| 243 | echo "build exit status: $build_exit" 1>&2 |
| 244 | fi |
Tsu Chiang Chuang | 011fade | 2012-07-09 18:34:47 -0700 | [diff] [blame] | 245 | elif [ "$build_only" = "yes" ]; then |
| 246 | good="yes" |
| 247 | "./${build}" >"$build_output" 2>&1 |
| 248 | build_exit="$?" |
| 249 | if [ "$build_exit" '!=' '0' ]; then |
| 250 | cp "$build_output" "$output" |
| 251 | echo "build exit status: $build_exit" >>"$output" |
| 252 | diff --strip-trailing-cr -q "$expected" "$output" >/dev/null |
| 253 | if [ "$?" '!=' "0" ]; then |
| 254 | good="no" |
| 255 | echo "BUILD FAILED For ${TEST_NAME}" |
| 256 | fi |
| 257 | fi |
| 258 | exit 0 |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 259 | else |
| 260 | "./${build}" >"$build_output" 2>&1 |
| 261 | build_exit="$?" |
| 262 | if [ "$build_exit" = '0' ]; then |
| 263 | "./${run}" $run_args "$@" >"$output" 2>&1 |
| 264 | else |
| 265 | cp "$build_output" "$output" |
| 266 | echo "build exit status: $build_exit" >>"$output" |
| 267 | fi |
| 268 | diff --strip-trailing-cr -q "$expected" "$output" >/dev/null |
| 269 | if [ "$?" = "0" ]; then |
| 270 | # output == expected |
| 271 | good="yes" |
| 272 | echo "${test_dir}: succeeded!" 1>&2 |
| 273 | fi |
| 274 | fi |
| 275 | |
Tsu Chiang Chuang | 011fade | 2012-07-09 18:34:47 -0700 | [diff] [blame] | 276 | # Clean up test files. |
| 277 | if [ "$good" == "yes" ]; then |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 278 | cd "$oldwd" |
| 279 | rm -rf "$tmp_dir" |
Elliott Hughes | 7ab3a2a | 2012-06-18 16:34:20 -0700 | [diff] [blame] | 280 | if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then |
Brian Carlstrom | 105215d | 2012-06-14 12:50:44 -0700 | [diff] [blame] | 281 | adb shell rm -r $DEX_LOCATION |
| 282 | fi |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 283 | exit 0 |
| 284 | fi |
| 285 | |
Tsu Chiang Chuang | 011fade | 2012-07-09 18:34:47 -0700 | [diff] [blame] | 286 | |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 287 | ( |
Tsu Chiang Chuang | 011fade | 2012-07-09 18:34:47 -0700 | [diff] [blame] | 288 | if [ "$update_mode" != "yes" ]; then |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 289 | echo "${test_dir}: FAILED!" |
| 290 | echo ' ' |
| 291 | echo '#################### info' |
| 292 | cat "${td_info}" | sed 's/^/# /g' |
| 293 | echo '#################### diffs' |
| 294 | diff --strip-trailing-cr -u "$expected" "$output" |
| 295 | echo '####################' |
| 296 | echo ' ' |
| 297 | fi |
Brian Carlstrom | 105215d | 2012-06-14 12:50:44 -0700 | [diff] [blame] | 298 | echo "${TEST_NAME} files left in ${tmp_dir} on host" |
Tsu Chiang Chuang | 011fade | 2012-07-09 18:34:47 -0700 | [diff] [blame] | 299 | if [ "$target_mode" == "yes" ]; then |
Brian Carlstrom | 105215d | 2012-06-14 12:50:44 -0700 | [diff] [blame] | 300 | echo "and in ${DEX_LOCATION} on target" |
| 301 | fi |
| 302 | |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 303 | ) 1>&2 |
| 304 | |
| 305 | exit 1 |