8 default_cmd
="sparse \$file"
9 tests_list
=`find . -name '*.c' | sed -e 's#^\./\(.*\)#\1#' | sort`
10 prog_name
=`basename $0`
12 if [ ! -x "$default_path/sparse-llvm" ]; then
13 disabled_cmds
="sparsec sparsei sparse-llvm"
17 # - some tests gave an unexpected result
21 # - tests that have not been converted to test-suite format
22 # - tests that are disabled
25 # - tests that failed but are known to fail
32 # defaults to not verbose
36 # get_value(key, file) - gets the value of a (key, value) pair in file.
38 # returns 0 on success, 1 if the file does not have the key
41 last_result
=`grep $1: $2 | sed -e "s/^.*$1:\(.*\)$/\1/"`
42 [ -z "$last_result" ] && return 1
47 # get_tag(key, file) - does file has the tag key in it ?
49 # returns 0 if present, 1 otherwise
52 last_result
=`grep $1 $2`
57 # helper for has_(each|none)_patterns()
64 grep "$patt:" "$ifile" | \
65 sed -e "s/^.*$patt: *\(.*\)$/\1/" | \
67 grep -s -q "$val" "$ofile"
68 if [ "$?" $cmp 0 ]; then
77 # has_each_patterns(ifile tag ofile) - does ofile contains some
78 # of the patterns given by ifile's tags?
80 # returns 0 if all present, 1 otherwise
83 has_patterns
"$1" "$2" "$3" -ne
87 # has_none_patterns(ifile tag ofile) - does ofile contains some
88 # of the patterns given by ifile's tags?
90 # returns 1 if any present, 0 otherwise
93 has_patterns
"$1" "$2" "$3" -eq
97 # nbr_patterns(ifile tag ofile) - does ofile contains the
98 # the patterns given by ifile's tags
99 # the right number of time?
105 grep "$patt-[0-9][0-9]*-times:" "$ifile" | \
106 sed -e "s/^.*$patt-\([0-9][0-9]*\)-times: *\(.*\)/\1 \2/" | \
107 while read nbr pat
; do
108 n
=$
(grep -s "$pat" "$ofile" |
wc -l)
109 if [ "$n" -ne "$nbr" ]; then
118 # verbose(string) - prints string if we are in verbose mode
121 [ "$V" -eq "1" ] && echo " $1"
126 # error(string[, die]) - prints an error and exits with value die if given
129 [ "$quiet" -ne 1 ] && echo "error: $1"
130 [ -n "$2" ] && exit $2
136 echo "$prog_name - a tiny automatic testing script"
137 echo "Usage: $prog_name [command] [command arguments]"
140 echo " none runs the whole test suite"
141 echo " single file runs the test in 'file'"
142 echo " format file [name [cmd]] helps writing a new test case using cmd"
144 echo " help prints usage"
148 # do_test(file) - tries to validate a test case
150 # it "parses" file, looking for check-* tags and tries to validate
151 # the test against an expected result
153 # - 0 if the test passed,
155 # - 2 if it is not a "test-suite" test.
156 # - 3 if the test is disabled.
162 # can this test be handled by test-suite ?
163 # (it has to have a check-name key in it)
164 get_value
"check-name" $file
165 if [ "$?" -eq 1 ]; then
166 echo "warning: test '$file' unhandled"
167 unhandled_tests
=`expr $unhandled_tests + 1`
170 test_name
=$last_result
172 # does the test provide a specific command ?
173 cmd
=`eval echo $default_path/$default_cmd`
174 get_value
"check-command" $file
175 if [ "$?" -eq "0" ]; then
176 last_result
=`echo $last_result | sed -e 's/^ *//'`
177 cmd
=`eval echo $default_path/$last_result`
180 # check for disabled commands
182 base_cmd
=`basename $1`
183 for i
in $disabled_cmds; do
184 if [ "$i" = "$base_cmd" ] ; then
185 disabled_tests
=`expr $disabled_tests + 1`
186 echo " DISABLE $test_name ($file)"
191 echo " TEST $test_name ($file)"
193 verbose
"Using command : $cmd"
195 # grab the expected output
196 sed -n '/check-output-start/,/check-output-end/p' $file \
197 |
grep -v check-output
> "$file".output.expected
198 sed -n '/check-error-start/,/check-error-end/p' $file \
199 |
grep -v check-error
> "$file".error.expected
201 # grab the expected exit value
202 get_value
"check-exit-value" $file
203 if [ "$?" -eq "0" ]; then
204 expected_exit_value
=`echo $last_result | tr -d ' '`
206 expected_exit_value
=0
208 verbose
"Expecting exit value: $expected_exit_value"
211 # grab the actual output & exit value
212 $cmd 1> $file.output.got
2> $file.error.got
215 get_tag
"check-known-to-fail" $file
216 must_fail
=`expr "$?" = 0`
218 [ $must_fail -eq 1 ] && [ $V -eq 0 ] && quiet
=1
219 known_ko_tests
=`expr $known_ko_tests + $must_fail`
221 for stream
in output error
; do
222 grep -s -q "check-$stream-ignore" $file && continue
224 diff -u "$file".
$stream.expected
"$file".
$stream.got
> "$file".
$stream.
diff
225 if [ "$?" -ne "0" ]; then
226 error
"actual $stream text does not match expected $stream text."
227 error
"see $file.$stream.* for further investigation."
228 [ $quiet -ne 1 ] && cat "$file".
$stream.
diff
233 if [ "$actual_exit_value" -ne "$expected_exit_value" ]; then
234 error
"Actual exit value does not match the expected one."
235 error
"expected $expected_exit_value, got $actual_exit_value."
239 # verify the 'check-output-contains/excludes' tags
240 has_each_patterns
"$file" 'check-output-contains' $file.output.got
241 if [ "$?" -ne "0" ]; then
242 error
"Actual output doesn't contain some of the expected patterns."
245 has_none_patterns
"$file" 'check-output-excludes' $file.output.got
246 if [ "$?" -ne "0" ]; then
247 error
"Actual output contains some patterns which are not expected."
251 # verify the 'check-output-pattern-X-times' tags
252 nbr_patterns
"$file" 'check-output-pattern' $file.output.got
253 if [ "$?" -ne "0" ]; then
254 error
"Actual output doesn't contain the pattern the expected number."
258 [ "$test_failed" -eq "$must_fail" ] || failed
=1
260 if [ "$must_fail" -eq "1" ]; then
261 if [ "$test_failed" -eq "1" ]; then
262 echo "info: test '$file' is known to fail"
264 echo "error: test '$file' is known to fail but succeed!"
269 if [ "$test_failed" -eq "1" ]; then
270 ko_tests
=`expr $ko_tests + 1`
272 ok_tests
=`expr $ok_tests + 1`
273 rm -f $file.
{error
,output
}.
{expected
,got
,diff}
280 for i
in $tests_list; do
284 # prints some numbers
285 tests_nr
=`expr $ok_tests + $ko_tests`
286 echo -n "Out of $tests_nr tests, $ok_tests passed, $ko_tests failed"
287 echo " ($known_ko_tests of them are known to fail)"
288 if [ "$unhandled_tests" -ne "0" ]; then
289 echo "$unhandled_tests tests could not be handled by $prog_name"
291 if [ "$disabled_tests" -ne "0" ]; then
292 echo "$disabled_tests tests were disabled"
297 # do_format(file[, name[, cmd]]) - helps a test writer to format test-suite tags
303 elif [ -z "$3" ]; then
311 cmd
=`eval echo $default_path/$fcmd`
312 $cmd 1> $file.output.got
2> $file.error.got
318 if [ "$fcmd" != "$default_cmd" ]; then
319 echo " * check-command: $fcmd"
321 if [ "$fexit_value" -ne "0" ]; then
322 echo " * check-exit-value: $fexit_value"
324 for stream
in output error
; do
325 if [ -s "$file.$stream.got" ]; then
327 echo " * check-$stream-start"
328 cat "$file.$stream.got"
329 echo " * check-$stream-end"
337 # arg_file(filename) - checks if filename exists
345 error
"Can't open file $1"
359 0) echo "$2 passed !";;
360 1) echo "$2 failed !";;
361 2) echo "$2 can't be handled by $prog_name";;
366 do_format
"$2" "$3" "$4"