The Android Open Source Project | 23580ca | 2008-10-21 07:00:00 -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 | info="info.txt" |
| 37 | run="run" |
| 38 | expected="expected.txt" |
| 39 | output="out.txt" |
| 40 | skip="SKIP" |
| 41 | |
| 42 | dev_mode="no" |
| 43 | if [ "x$1" = "x--dev" ]; then |
| 44 | dev_mode="yes" |
| 45 | shift |
| 46 | fi |
| 47 | |
| 48 | update_mode="no" |
| 49 | if [ "x$1" = "x--update" ]; then |
| 50 | update_mode="yes" |
| 51 | shift |
| 52 | fi |
| 53 | |
| 54 | usage="no" |
| 55 | if [ "x$1" = "x--help" ]; then |
| 56 | usage="yes" |
| 57 | else |
| 58 | if [ "x$1" = "x" ]; then |
| 59 | testdir=`basename "$oldwd"` |
| 60 | else |
| 61 | testdir="$1" |
| 62 | fi |
| 63 | |
| 64 | if [ '!' -d "$testdir" ]; then |
| 65 | td2=`echo ${testdir}-*` |
| 66 | if [ '!' -d "$td2" ]; then |
| 67 | echo "${testdir}: no such test directory" 1>&2 |
| 68 | usage="yes" |
| 69 | fi |
| 70 | testdir="$td2" |
| 71 | fi |
| 72 | fi |
| 73 | |
| 74 | if [ "$usage" = "yes" ]; then |
| 75 | prog=`basename $prog` |
| 76 | ( |
| 77 | echo "usage:" |
| 78 | echo " $prog --help Print this message." |
| 79 | echo " $prog testname Run test normally." |
| 80 | echo " $prog --dev testname Development mode (dump to stdout)." |
| 81 | echo " $prog --update testname Update mode (replace expected.txt)." |
| 82 | echo " Omitting the test name uses the current directory as the test." |
| 83 | ) 1>&2 |
| 84 | exit 1 |
| 85 | fi |
| 86 | |
| 87 | td_info="$testdir"/"$info" |
| 88 | td_run="$testdir"/"$run" |
| 89 | td_expected="$testdir"/"$expected" |
| 90 | td_skip="$testdir"/"$skip" |
| 91 | |
| 92 | if [ -r "$td_skip" ]; then |
| 93 | exit 2 |
| 94 | fi |
| 95 | |
| 96 | tmpdir=/tmp/test-$$ |
| 97 | |
| 98 | if [ '!' '(' -r "$td_info" -a -r "$td_run" -a -r "$td_expected" ')' ]; then |
| 99 | echo "${testdir}: missing files" 1>&2 |
| 100 | exit 1 |
| 101 | fi |
| 102 | |
| 103 | # copy the test to a temp dir and run it |
| 104 | |
| 105 | echo "${testdir}: running..." 1>&2 |
| 106 | |
| 107 | rm -rf "$tmpdir" |
| 108 | cp -Rp "$testdir" "$tmpdir" |
| 109 | cd "$tmpdir" |
| 110 | chmod 755 "$run" |
| 111 | |
| 112 | #PATH="${progdir}/../build/bin:${PATH}" |
| 113 | |
| 114 | good="no" |
| 115 | if [ "$dev_mode" = "yes" ]; then |
| 116 | "./$run" 2>&1 |
| 117 | echo "exit status: $?" 1>&2 |
| 118 | good="yes" |
| 119 | elif [ "$update_mode" = "yes" ]; then |
| 120 | "./$run" >"${progdir}/$td_expected" 2>&1 |
| 121 | good="yes" |
| 122 | else |
| 123 | "./$run" >"$output" 2>&1 |
| 124 | cmp -s "$expected" "$output" |
| 125 | if [ "$?" = "0" ]; then |
| 126 | # output == expected |
| 127 | good="yes" |
| 128 | echo "$testdir"': succeeded!' 1>&2 |
| 129 | fi |
| 130 | fi |
| 131 | |
| 132 | if [ "$good" = "yes" ]; then |
| 133 | cd "$oldwd" |
| 134 | rm -rf "$tmpdir" |
| 135 | exit 0 |
| 136 | fi |
| 137 | |
| 138 | ( |
| 139 | echo "${testdir}: FAILED!" |
| 140 | echo ' ' |
| 141 | echo '#################### info' |
| 142 | cat "$info" | sed 's/^/# /g' |
| 143 | echo '#################### diffs' |
| 144 | diff -u "$expected" "$output" |
| 145 | echo '####################' |
| 146 | echo ' ' |
| 147 | echo "files left in $tmpdir" |
| 148 | ) 1>&2 |
| 149 | |
| 150 | exit 1 |