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_tag_value(file) - get the 'check-<...>' tags & values
40 check_command
="$default_cmd"
45 check_output_contains
=0
46 check_output_excludes
=0
47 check_output_pattern
=0
49 lines
=$
(grep 'check-[a-z-]*' $1 | \
50 sed -e 's/^.*\(check-[a-z-]*:*\) *\(.*\)$/\1 \2/')
52 while read tag val
; do
53 #echo "-> tag: '$tag'"
54 #echo "-> val: '$val'"
56 check-name
:) check_name
="$val" ;;
57 check-command
:) check_command
="$val" ;;
58 check-exit-value
:) check_exit_value
="$val" ;;
59 check-known-to-fail
) check_known_to_fail
=1 ;;
60 check-error-ignore
) check_error_ignore
=1 ;;
61 check-output-ignore
) check_output_ignore
=1 ;;
62 check-output-contains
:) check_output_contains
=1 ;;
63 check-output-excludes
:) check_output_excludes
=1 ;;
64 check-output-pattern-
) check_output_pattern
=1 ;;
72 # helper for has_(each|none)_patterns()
79 grep "$patt:" "$ifile" | \
80 sed -e "s/^.*$patt: *\(.*\)$/\1/" | \
82 grep -s -q "$val" "$ofile"
83 if [ "$?" $cmp 0 ]; then
92 # has_each_patterns(ifile tag ofile) - does ofile contains some
93 # of the patterns given by ifile's tags?
95 # returns 0 if all present, 1 otherwise
98 has_patterns
"$1" "$2" "$3" -ne
102 # has_none_patterns(ifile tag ofile) - does ofile contains some
103 # of the patterns given by ifile's tags?
105 # returns 1 if any present, 0 otherwise
108 has_patterns
"$1" "$2" "$3" -eq
112 # nbr_patterns(ifile tag ofile) - does ofile contains the
113 # the patterns given by ifile's tags
114 # the right number of time?
120 grep "$patt-[0-9][0-9]*-times:" "$ifile" | \
121 sed -e "s/^.*$patt-\([0-9][0-9]*\)-times: *\(.*\)/\1 \2/" | \
122 while read nbr pat
; do
123 n
=$
(grep -s "$pat" "$ofile" |
wc -l)
124 if [ "$n" -ne "$nbr" ]; then
133 # verbose(string) - prints string if we are in verbose mode
136 [ "$V" -eq "1" ] && echo " $1"
141 # error(string[, die]) - prints an error and exits with value die if given
144 [ "$quiet" -ne 1 ] && echo "error: $1"
145 [ -n "$2" ] && exit $2
151 echo "$prog_name - a tiny automatic testing script"
152 echo "Usage: $prog_name [command] [command arguments]"
155 echo " none runs the whole test suite"
156 echo " single file runs the test in 'file'"
157 echo " format file [name [cmd]] helps writing a new test case using cmd"
159 echo " help prints usage"
163 # do_test(file) - tries to validate a test case
165 # it "parses" file, looking for check-* tags and tries to validate
166 # the test against an expected result
168 # - 0 if the test passed,
170 # - 2 if it is not a "test-suite" test.
171 # - 3 if the test is disabled.
179 # can this test be handled by test-suite ?
180 # (it has to have a check-name key in it)
181 if [ "$check_name" = "" ]; then
182 echo "warning: test '$file' unhandled"
183 unhandled_tests
=`expr $unhandled_tests + 1`
186 test_name
="$check_name"
188 # does the test provide a specific command ?
189 if [ "$check_command" = "" ]; then
190 check_command
="$defaut_command"
192 cmd
=`eval echo $default_path/$check_command`
194 # check for disabled commands
196 base_cmd
=`basename $1`
197 for i
in $disabled_cmds; do
198 if [ "$i" = "$base_cmd" ] ; then
199 disabled_tests
=`expr $disabled_tests + 1`
200 echo " DISABLE $test_name ($file)"
205 echo " TEST $test_name ($file)"
207 verbose
"Using command : $cmd"
209 # grab the expected output
210 sed -n '/check-output-start/,/check-output-end/p' $file \
211 |
grep -v check-output
> "$file".output.expected
212 sed -n '/check-error-start/,/check-error-end/p' $file \
213 |
grep -v check-error
> "$file".error.expected
215 # grab the expected exit value
216 expected_exit_value
=$check_exit_value
217 verbose
"Expecting exit value: $expected_exit_value"
220 # grab the actual output & exit value
221 $cmd 1> $file.output.got
2> $file.error.got
224 must_fail
=$check_known_to_fail
226 [ $must_fail -eq 1 ] && [ $V -eq 0 ] && quiet
=1
227 known_ko_tests
=`expr $known_ko_tests + $must_fail`
229 for stream
in output error
; do
230 eval ignore
=\
$check_${stream}_ignore
231 [ $ignore -eq 1 ] && continue
233 diff -u "$file".
$stream.expected
"$file".
$stream.got
> "$file".
$stream.
diff
234 if [ "$?" -ne "0" ]; then
235 error
"actual $stream text does not match expected $stream text."
236 error
"see $file.$stream.* for further investigation."
237 [ $quiet -ne 1 ] && cat "$file".
$stream.
diff
242 if [ "$actual_exit_value" -ne "$expected_exit_value" ]; then
243 error
"Actual exit value does not match the expected one."
244 error
"expected $expected_exit_value, got $actual_exit_value."
248 # verify the 'check-output-contains/excludes' tags
249 has_each_patterns
"$file" 'check-output-contains' $file.output.got
250 if [ "$?" -ne "0" ]; then
251 error
"Actual output doesn't contain some of the expected patterns."
254 has_none_patterns
"$file" 'check-output-excludes' $file.output.got
255 if [ "$?" -ne "0" ]; then
256 error
"Actual output contains some patterns which are not expected."
260 # verify the 'check-output-pattern-X-times' tags
261 nbr_patterns
"$file" 'check-output-pattern' $file.output.got
262 if [ "$?" -ne "0" ]; then
263 error
"Actual output doesn't contain the pattern the expected number."
267 [ "$test_failed" -eq "$must_fail" ] || failed
=1
269 if [ "$must_fail" -eq "1" ]; then
270 if [ "$test_failed" -eq "1" ]; then
271 echo "info: test '$file' is known to fail"
273 echo "error: test '$file' is known to fail but succeed!"
278 if [ "$test_failed" -eq "1" ]; then
279 ko_tests
=`expr $ko_tests + 1`
281 ok_tests
=`expr $ok_tests + 1`
282 rm -f $file.
{error
,output
}.
{expected
,got
,diff}
289 for i
in $tests_list; do
293 # prints some numbers
294 tests_nr
=`expr $ok_tests + $ko_tests`
295 echo -n "Out of $tests_nr tests, $ok_tests passed, $ko_tests failed"
296 echo " ($known_ko_tests of them are known to fail)"
297 if [ "$unhandled_tests" -ne "0" ]; then
298 echo "$unhandled_tests tests could not be handled by $prog_name"
300 if [ "$disabled_tests" -ne "0" ]; then
301 echo "$disabled_tests tests were disabled"
306 # do_format(file[, name[, cmd]]) - helps a test writer to format test-suite tags
312 elif [ -z "$3" ]; then
320 cmd
=`eval echo $default_path/$fcmd`
321 $cmd 1> $file.output.got
2> $file.error.got
327 if [ "$fcmd" != "$default_cmd" ]; then
328 echo " * check-command: $fcmd"
330 if [ "$fexit_value" -ne "0" ]; then
331 echo " * check-exit-value: $fexit_value"
333 for stream
in output error
; do
334 if [ -s "$file.$stream.got" ]; then
336 echo " * check-$stream-start"
337 cat "$file.$stream.got"
338 echo " * check-$stream-end"
346 # arg_file(filename) - checks if filename exists
354 error
"Can't open file $1"
368 0) echo "$2 passed !";;
369 1) echo "$2 failed !";;
370 2) echo "$2 can't be handled by $prog_name";;
375 do_format
"$2" "$3" "$4"