6 default_cmd
="sparse \$file"
7 tests_list
=`find . -name '*.c' | sed -e 's#^\./\(.*\)#\1#' | sort`
8 prog_name
=`basename $0`
10 if [ ! -x "$default_path/sparse-llvm" ]; then
11 disabled_cmds
="sparsec sparsei sparse-llvm"
15 # - tests that have not been converted to test-suite format
16 # - tests that are disabled
19 # - tests that failed but are known to fail
26 # defaults to not verbose
30 # get_value(key, file) - gets the value of a (key, value) pair in file.
32 # returns 0 on success, 1 if the file does not have the key
35 last_result
=`grep $1: $2 | sed -e "s/^.*$1:\(.*\)$/\1/"`
36 [ -z "$last_result" ] && return 1
41 # get_tag(key, file) - does file has the tag key in it ?
43 # returns 0 if present, 1 otherwise
46 last_result
=`grep $1 $2`
51 # verbose(string) - prints string if we are in verbose mode
54 [ "$V" -eq "1" ] && echo " $1"
59 # error(string[, die]) - prints an error and exits with value die if given
63 [ -n "$2" ] && exit $2
69 echo "$prog_name - a tiny automatic testing script"
70 echo "Usage: $prog_name [command] [command arguments]"
73 echo " none runs the whole test suite"
74 echo " single file runs the test in 'file'"
75 echo " format file [name [cmd]] helps writing a new test case using cmd"
77 echo " help prints usage"
81 # do_test(file) - tries to validate a test case
83 # it "parses" file, looking for check-* tags and tries to validate
84 # the test against an expected result
86 # - 0 if the test passed,
88 # - 2 if it is not a "test-suite" test.
89 # - 3 if the test is disabled.
95 # can this test be handled by test-suite ?
96 # (it has to have a check-name key in it)
97 get_value
"check-name" $file
98 if [ "$?" -eq 1 ]; then
99 echo "warning: test '$file' unhandled"
100 unhandled_tests
=`expr $unhandled_tests + 1`
103 test_name
=$last_result
105 # does the test provide a specific command ?
106 cmd
=`eval echo $default_path/$default_cmd`
107 get_value
"check-command" $file
108 if [ "$?" -eq "0" ]; then
109 last_result
=`echo $last_result | sed -e 's/^ *//'`
110 cmd
=`eval echo $default_path/$last_result`
113 # check for disabled commands
115 base_cmd
=`basename $1`
116 for i
in $disabled_cmds; do
117 if [ "$i" = "$base_cmd" ] ; then
118 disabled_tests
=`expr $disabled_tests + 1`
119 echo " DISABLE $test_name ($file)"
124 echo " TEST $test_name ($file)"
126 verbose
"Using command : $cmd"
128 # grab the expected output
129 sed -n '/check-output-start/,/check-output-end/p' $file \
130 |
grep -v check-output
> "$file".output.expected
131 sed -n '/check-error-start/,/check-error-end/p' $file \
132 |
grep -v check-error
> "$file".error.expected
134 # grab the expected exit value
135 get_value
"check-exit-value" $file
136 if [ "$?" -eq "0" ]; then
137 expected_exit_value
=`echo $last_result | tr -d ' '`
139 expected_exit_value
=0
141 verbose
"Expecting exit value: $expected_exit_value"
144 # grab the actual output & exit value
145 $cmd 1> $file.output.got
2> $file.error.got
148 for stream
in output error
; do
149 diff -u "$file".
$stream.expected
"$file".
$stream.got
> "$file".
$stream.
diff
150 if [ "$?" -ne "0" ]; then
151 error
"actual $stream text does not match expected $stream text."
152 error
"see $file.$stream.* for further investigation."
153 cat "$file".
$stream.
diff
158 if [ "$actual_exit_value" -ne "$expected_exit_value" ]; then
159 error
"Actual exit value does not match the expected one."
160 error
"expected $expected_exit_value, got $actual_exit_value."
164 if [ "$test_failed" -eq "1" ]; then
165 ko_tests
=`expr $ko_tests + 1`
166 get_tag
"check-known-to-fail" $file
167 if [ "$?" -eq "0" ]; then
168 echo "info: test '$file' is known to fail"
169 known_ko_tests
=`expr $known_ko_tests + 1`
173 ok_tests
=`expr $ok_tests + 1`
180 for i
in $tests_list; do
184 # prints some numbers
185 tests_nr
=`expr $ok_tests + $ko_tests`
186 echo -n "Out of $tests_nr tests, $ok_tests passed, $ko_tests failed"
187 echo " ($known_ko_tests of them are known to fail)"
188 if [ "$unhandled_tests" -ne "0" ]; then
189 echo "$unhandled_tests tests could not be handled by $prog_name"
191 if [ "$disabled_tests" -ne "0" ]; then
192 echo "$disabled_tests tests were disabled"
197 # do_format(file[, name[, cmd]]) - helps a test writer to format test-suite tags
203 elif [ -z "$3" ]; then
211 cmd
=`eval echo $default_path/$fcmd`
212 $cmd 1> $file.output.got
2> $file.error.got
218 if [ "$fcmd" != "$default_cmd" ]; then
219 echo " * check-command: $fcmd"
221 if [ "$fexit_value" -ne "0" ]; then
222 echo " * check-exit-value: $fexit_value"
224 for stream
in output error
; do
225 if [ -s "$file.$stream.got" ]; then
227 echo " * check-$stream-start"
228 cat "$file.$stream.got"
229 echo " * check-$stream-end"
237 # arg_file(filename) - checks if filename exists
245 error
"Can't open file $1"
259 0) echo "$2 passed !";;
260 1) echo "$2 failed !";;
261 2) echo "$2 can't be handled by $prog_name";;
266 do_format
"$2" "$3" "$4"