| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
#set -x |
| 4 |
|
| 5 |
default_path=".." |
| 6 |
tests_list=`find . -name '*.c' | sed -e 's#^\./\(.*\)#\1#' | sort` |
| 7 |
prog_name=`basename $0` |
| 8 |
|
| 9 |
export TEXINPUTS=$PWD/..//:$TEXINPUTS |
| 10 |
|
| 11 |
# counts: |
| 12 |
# - tests that have not been converted to test-suite format |
| 13 |
# - tests that passed |
| 14 |
# - tests that failed |
| 15 |
# - tests that failed but are known to fail |
| 16 |
unhandled_tests=0 |
| 17 |
ok_tests=0 |
| 18 |
ko_tests=0 |
| 19 |
known_ko_tests=0 |
| 20 |
|
| 21 |
|
| 22 |
# defaults to not verbose |
| 23 |
[ -z "$V" ] && V=0 |
| 24 |
|
| 25 |
## |
| 26 |
# get_value(key, file) - gets the value of a (key, value) pair in file. |
| 27 |
# |
| 28 |
# returns 0 on success, 1 if the file does not have the key |
| 29 |
get_value() |
| 30 |
{ |
| 31 |
last_result=`grep $1: $2 | sed -e "s/^.*$1:\(.*\)$/\1/"` |
| 32 |
[ -z "$last_result" ] && return 1 |
| 33 |
return 0 |
| 34 |
} |
| 35 |
|
| 36 |
## |
| 37 |
# get_tag(key, file) - does file has the tag key in it ? |
| 38 |
# |
| 39 |
# returns 0 if present, 1 otherwise |
| 40 |
get_tag() |
| 41 |
{ |
| 42 |
last_result=`grep $1 $2` |
| 43 |
return $? |
| 44 |
} |
| 45 |
|
| 46 |
## |
| 47 |
# verbose(string) - prints string if we are in verbose mode |
| 48 |
verbose() |
| 49 |
{ |
| 50 |
[ "$V" -eq "1" ] && echo " $1" |
| 51 |
return 0 |
| 52 |
} |
| 53 |
|
| 54 |
## |
| 55 |
# error(string[, die]) - prints an error and exits with value die if given |
| 56 |
error() |
| 57 |
{ |
| 58 |
echo " error: $1" |
| 59 |
[ -n "$2" ] && exit $2 |
| 60 |
return 0 |
| 61 |
} |
| 62 |
|
| 63 |
do_usage() |
| 64 |
{ |
| 65 |
echo "$prog_name - a tiny automatic testing script" |
| 66 |
echo "Usage: $prog_name [command] [command arguments]" |
| 67 |
echo |
| 68 |
echo "commands:" |
| 69 |
echo " none runs the whole test suite" |
| 70 |
echo " single file runs the test in 'file'" |
| 71 |
echo |
| 72 |
echo " help prints usage" |
| 73 |
} |
| 74 |
|
| 75 |
## |
| 76 |
# do_test(file) - tries to validate a test case |
| 77 |
# |
| 78 |
# it "parses" file, looking for check-* tags and tries to validate |
| 79 |
# the test against an expected result |
| 80 |
# returns: |
| 81 |
# - 0 if the test passed, |
| 82 |
# - 1 if it failed, |
| 83 |
# - 2 if it is not a "test-suite" test. |
| 84 |
do_test() |
| 85 |
{ |
| 86 |
test_failed=0 |
| 87 |
file="$1" |
| 88 |
|
| 89 |
# can this test be handled by test-suite ? |
| 90 |
# (it has to have a check-name key in it) |
| 91 |
get_value "check-name" $file |
| 92 |
if [ "$?" -eq 1 ]; then |
| 93 |
echo "warning: test '$file' unhandled" |
| 94 |
unhandled_tests=`expr $unhandled_tests + 1` |
| 95 |
return 2 |
| 96 |
fi |
| 97 |
test_name=$last_result |
| 98 |
|
| 99 |
echo -n "TEST $test_name ($file)" |
| 100 |
|
| 101 |
cp HEADER "$file".tex |
| 102 |
get_value compiler-opts "$file" |
| 103 |
echo "\avrloadc[-Os -mmcu=atmega8 $last_result]{$file}" >> "$file".tex |
| 104 |
|
| 105 |
awk '/check-start/,/check-end/ {print}' $file \ |
| 106 |
| egrep -v 'check-(start|end)' >> "$file".tex |
| 107 |
cat FOOTER >> "$file".tex |
| 108 |
|
| 109 |
|
| 110 |
# grab the actual output & exit value |
| 111 |
pdflatex -halt-on-error -shell-escape "$file".tex 1> $file.output 2> $file.error |
| 112 |
actual_exit_value=$? |
| 113 |
rm -f *.log *.aux |
| 114 |
|
| 115 |
if [ "$actual_exit_value" -ne 0 ]; then |
| 116 |
echo |
| 117 |
error " Actual exit value does not match the expected one." |
| 118 |
error " expected 0, got $actual_exit_value" |
| 119 |
if [ x"$V" = x"1" ]; then |
| 120 |
cat $file.output | sed 's/^/ /' |
| 121 |
else |
| 122 |
tail -n 10 $file.output | sed 's/^/ /' |
| 123 |
fi |
| 124 |
test_failed=1 |
| 125 |
else |
| 126 |
get_value BREAK "$file".output |
| 127 |
echo " ($last_result)" | sed 's/ instructions//' | tr -d "\n" |
| 128 |
echo |
| 129 |
fi |
| 130 |
|
| 131 |
if [ "$test_failed" -eq "1" ]; then |
| 132 |
ko_tests=`expr $ko_tests + 1` |
| 133 |
get_tag "check-known-to-fail" $file |
| 134 |
if [ "$?" -eq "0" ]; then |
| 135 |
echo "info: test '$file' is known to fail" |
| 136 |
known_ko_tests=`expr $known_ko_tests + 1` |
| 137 |
fi |
| 138 |
return 1 |
| 139 |
else |
| 140 |
ok_tests=`expr $ok_tests + 1` |
| 141 |
return 0 |
| 142 |
fi |
| 143 |
} |
| 144 |
|
| 145 |
pwait() { |
| 146 |
# This functions blocks until less than $1 subprocesses are running |
| 147 |
jobs="$1" |
| 148 |
[ -z "$jobs" ] && jobs=5 |
| 149 |
|
| 150 |
while [ $(jobs -r | wc -l) -gt "$jobs" ]; do |
| 151 |
sleep 0.5 |
| 152 |
done |
| 153 |
} |
| 154 |
|
| 155 |
do_test_suite() |
| 156 |
{ |
| 157 |
for i in $tests_list; do |
| 158 |
if get_value "check-long" "$i" > /dev/null; then |
| 159 |
echo "IGNORED $i (long running)" |
| 160 |
continue |
| 161 |
fi |
| 162 |
do_test "$i" |
| 163 |
done |
| 164 |
|
| 165 |
# prints some numbers |
| 166 |
tests_nr=`expr $ok_tests + $ko_tests` |
| 167 |
echo -n "Out of $tests_nr tests, $ok_tests passed, $ko_tests failed" |
| 168 |
echo " ($known_ko_tests of them are known to fail)" |
| 169 |
if [ "$unhandled_tests" -ne "0" ]; then |
| 170 |
echo "$unhandled_tests tests could not be handled by $prog_name" |
| 171 |
fi |
| 172 |
} |
| 173 |
|
| 174 |
## |
| 175 |
# arg_file(filename) - checks if filename exists |
| 176 |
arg_file() |
| 177 |
{ |
| 178 |
[ -z "$1" ] && { |
| 179 |
do_usage |
| 180 |
exit 1 |
| 181 |
} |
| 182 |
[ -e "$1" ] || { |
| 183 |
error "Can't open file $1" |
| 184 |
exit 1 |
| 185 |
} |
| 186 |
return 0 |
| 187 |
} |
| 188 |
|
| 189 |
case "$1" in |
| 190 |
'') |
| 191 |
do_test_suite |
| 192 |
if test `expr $ko_tests - $known_ko_tests` -gt 0; then |
| 193 |
for f in *.error.diff *.output.diff; do |
| 194 |
if test -s "$f"; then |
| 195 |
echo "Contents of $f:" |
| 196 |
cat "$f" |
| 197 |
echo "===" |
| 198 |
fi |
| 199 |
done |
| 200 |
exit 1 |
| 201 |
fi |
| 202 |
;; |
| 203 |
single) |
| 204 |
arg_file "$2" |
| 205 |
do_test "$2" |
| 206 |
case "$?" in |
| 207 |
0) echo "$2 passed !";; |
| 208 |
1) echo "$2 failed !";; |
| 209 |
2) echo "$2 can't be handled by $prog_name";; |
| 210 |
esac |
| 211 |
;; |
| 212 |
format) |
| 213 |
arg_file "$2" |
| 214 |
do_format "$2" "$3" "$4" |
| 215 |
;; |
| 216 |
help | *) |
| 217 |
do_usage |
| 218 |
exit 1 |
| 219 |
;; |
| 220 |
esac |
| 221 |
|
| 222 |
exit 0 |
| 223 |
|