blob: 9cebd3f47845801075615a201ec63aaa5b99da14 [file] [log] [blame]
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -08001#!/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.
19prog="$0"
20while [ -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
29done
30oldwd=`pwd`
31progdir=`dirname "${prog}"`
32cd "${progdir}"
33progdir=`pwd`
34prog="${progdir}"/`basename "${prog}"`
35
36info="info.txt"
37run="run"
38expected="expected.txt"
39output="out.txt"
40skip="SKIP"
41
42dev_mode="no"
43if [ "x$1" = "x--dev" ]; then
44 dev_mode="yes"
45 shift
46fi
47
48update_mode="no"
49if [ "x$1" = "x--update" ]; then
50 update_mode="yes"
51 shift
52fi
53
54usage="no"
55if [ "x$1" = "x--help" ]; then
56 usage="yes"
57else
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
72fi
73
74if [ "$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
85fi
86
87td_info="$testdir"/"$info"
88td_run="$testdir"/"$run"
89td_expected="$testdir"/"$expected"
90td_skip="$testdir"/"$skip"
91
92if [ -r "$td_skip" ]; then
93 exit 2
94fi
95
96tmpdir=/tmp/test-$$
97
98if [ '!' '(' -r "$td_info" -a -r "$td_run" -a -r "$td_expected" ')' ]; then
99 echo "${testdir}: missing files" 1>&2
100 exit 1
101fi
102
103# copy the test to a temp dir and run it
104
105echo "${testdir}: running..." 1>&2
106
107rm -rf "$tmpdir"
108cp -Rp "$testdir" "$tmpdir"
109cd "$tmpdir"
110chmod 755 "$run"
111
112#PATH="${progdir}/../build/bin:${PATH}"
113
114good="no"
115if [ "$dev_mode" = "yes" ]; then
116 "./$run" 2>&1
117 echo "exit status: $?" 1>&2
118 good="yes"
119elif [ "$update_mode" = "yes" ]; then
120 "./$run" >"${progdir}/$td_expected" 2>&1
121 good="yes"
122else
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
130fi
131
132if [ "$good" = "yes" ]; then
133 cd "$oldwd"
134 rm -rf "$tmpdir"
135 exit 0
136fi
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
150exit 1