Debian Codegraph @

test/run_tests.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 # Simple test script adapted from Matt Dillon's 2.16 release.
4 # It's harder to do this in a Makefile, so let's use a script.
5
6 should_fail="0"
7
8 REL_DIR="../bin"
9
10 DEFINES=""
11 format="1"
12
13 while [ "$1" != "" ]
14 do
15 case "$1" in
16 -R) REL_DIR="$2"
17 shift
18 ;;
19 -S) should_fail="$2"
20 shift
21 ;;
22 -D) DEFINES="${DEFINES} -D$2"
23 shift
24 ;;
25 -F) format="$2"
26 shift
27 ;;
28 -I) DEFINES="${DEFINES} -I$2"
29 ;;
30 esac
31 shift
32 done
33
34 echo "=== build test cases (strict=off)"
35
36 fail="0"
37 ok="0"
38 nTests="0"
39
40 leadingSpace() {
41 echo "$@" | awk '{ printf(" * % 32s", $0)}'
42 }
43
44 refFiles=`find . -type f -name '*.bin.ref' | sort`
45
46 for item in $refFiles
47 do
48 ARGS="-f${format}"
49
50 NAME=$(echo $item | sed 's/\.bin\.ref$//g;s/^\.\///g')
51
52 leadingSpace "$NAME"
53
54 if test -r ${NAME}.args
55 then
56 . ${NAME}.args
57 fi
58
59 if ${REL_DIR}/dasm ${NAME}.asm ${ARGS} -o$NAME.bin -L$NAME.list.txt -DINEEPROM ${DEFINES} >$NAME.out 2>&1
60 then
61 if test -s $NAME.bin
62 then
63 ${REL_DIR}/ftohex 1 $NAME.bin $NAME.hex
64 if cmp -s $NAME.bin $NAME.bin.ref
65 then
66 echo " binary is same, pass"
67 ok="$[$ok+1]"
68 else
69 # second compare test is not needed, just help to find the diff
70 if ! test -r $NAME.hex.ref
71 then
72 echo " file [$NAME.hex.ref] missing FAILED!"
73 else
74 diff -bBduw $NAME.hex $NAME.hex.ref >$NAME.hex.diff
75 echo " binaries differ FAILED!"
76 fi
77 fail="$[$fail+1]"
78 fi
79 else
80 echo " file doesn't exist or has zero size FAILED!"
81 fail="$[$fail+1]"
82 fi
83 else
84 echo " assembly FAILED! [$?]"
85 fail="$[$fail+1]"
86 fi
87 nTests="$[$nTests+1]"
88 done
89
90 LIST=`find . -type f -name '*.fail' | sort`
91 if [ "$LIST" != "" ]
92 then
93
94 echo ""
95 echo "=== error test cases (strict=on)"
96
97 # test for assembly sniplets that should fail
98 for item in $LIST
99 do
100 ARGS="-f${format}"
101
102 NAME=$(echo $item | sed 's/\.fail$//g;s/^\.\///g')
103 leadingSpace "$NAME"
104
105 if test -r ${NAME}.args
106 then
107 . ${NAME}.args
108 fi
109
110 if ! test -r ${NAME}.asm
111 then
112 echo "source file [${NAME}.asm] is missing"
113 fail="$[$fail+1]"
114 else
115 if ${REL_DIR}/dasm ${NAME}.asm -S ${ARGS} -o$NAME.bin -L$NAME.list.txt -DINEEPROM ${DEFINES} >${NAME}.out 2>&1
116 then
117 echo " no error FAILED!"
118 fail="$[$fail+1]"
119 else
120 case "$ARGS" in
121 *-R) if test -r $NAME.bin
122 then
123 echo " file exists, FAILED!"
124 fail="$[$fail+1]"
125 else
126 echo " file was deleted, pass"
127 ok="$[$ok+1]"
128 fi
129 ;;
130 *) got_error_level="$?"
131 expected_error_level=`cat $item | head -1`
132 if [ "${expected_error_level}" = "" ]
133 then
134 echo " testcase definition incomplete, missing error_level (${got_error_level}), FAILED!"
135 fail="$[$fail+1]"
136 else
137 if [ "${got_error_level}" != "${expected_error_level}" ]
138 then
139 echo " got error_level (${got_error_level}) but expected (${expected_error_level}), double FAULT!"
140 fail="$[$fail+1]"
141 else
142 echo " error_code [${got_error_level}] pass"
143 ok="$[$ok+1]"
144 fi
145 fi
146 ;;
147 esac
148 fi
149 fi
150 nTests="$[$nTests+1]"
151 done
152
153 fi
154
155 echo -n "executed ${nTests} tests, $ok OK, $fail failed, result: "
156
157 if [ "$[$ok+${should_fail}]" = "$nTests" ]
158 then
159 echo "overall PASS"
160 exit 0
161 else
162 suspect="$[$fail-${should_fail}]"
163 echo "need to investigate in $suspect test-cases"
164 exit $suspect
165 fi
166
167
168