test: enable all tests, use expect count, add tinycc tests.
[mes.git] / build-aux / check-mescc.sh
1 #! /bin/sh
2
3 # Mes --- Maxwell Equations of Software
4 # Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
5 #
6 # This file is part of Mes.
7 #
8 # Mes is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or (at
11 # your option) any later version.
12 #
13 # Mes is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Mes.  If not, see <http://www.gnu.org/licenses/>.
20
21 export MES=${MES-src/mes}
22 export MESCC=${MESCC-scripts/mescc}
23 export GUILE=${GUILE-guile}
24 export MES_PREFIX=${MES_PREFIX-.}
25
26 export HEX2=${HEX2-hex2}
27 export M1=${M1-M1}
28 export BLOOD_ELF=${BLOOD_ELF-blood-elf}
29 export MES_SEED=${MES_SEED-../mes-seed}
30 export MESCC=${MESCC-$(type -p mescc)}
31 [ -z "$MESCC" ] && MESCC=scripts/mescc
32 export MES=${MES-$(type -p mes)}
33 [ -z "$MES" ] && MES=src/mes
34
35
36 tests="
37 t
38 00-exit-0
39 01-return-0
40 02-return-1
41 03-call
42 04-call-0
43 05-call-1
44 06-call-!1
45 10-if-0
46 11-if-1
47 12-if-==
48 13-if-!=
49 14-if-goto
50 15-if-!f
51 16-if-t
52 20-while
53 21-char[]
54 22-while-char[]
55 23-pointer
56 30-strlen
57 31-eputs
58 32-compare
59 33-and-or
60 34-pre-post
61 35-compare-char
62 36-compare-arithmetic
63 37-compare-assign
64 38-compare-call
65 40-if-else
66 41-?
67 42-goto-label
68 43-for-do-while
69 44-switch
70 45-void-call
71 50-assert
72 51-strcmp
73 52-itoa
74 53-strcpy
75 54-argv
76 60-math
77 61-array
78 63-struct-cell
79 64-make-cell
80 65-read
81 70-printf
82 71-struct-array
83 72-typedef-struct-def
84 73-union
85 74-multi-line-string
86 75-struct-union
87 76-pointer-arithmetic
88 77-pointer-assign
89 78-union-struct
90 79-int-array
91 7a-struct-char-array
92 7b-struct-int-array
93 7c-dynarray
94 7d-cast-char
95 7e-struct-array-access
96 7f-struct-pointer-arithmetic
97 7g-struct-byte-word-field
98 7h-struct-assign
99 7i-struct-struct
100 7j-strtoull
101 7k-for-each-elem
102 7l-struct-any-size-array
103 7m-struct-char-array-assign
104 7n-struct-struct-array
105 80-setjmp
106 81-qsort
107 82-define
108 "
109
110 broken="$broken
111 "
112
113 set +e
114 expect=$(echo $broken | wc -w)
115 pass=0
116 fail=0
117 total=0
118 export LIBC=libc/libc
119 for t in $tests; do
120     if [ -z "${t/[012][0-9]-*/}" ]; then
121         LIBC=lib/mini-libc;
122     elif [ -z "${t/8[0-9]-*/}" ]; then
123         LIBC=lib/libc+tcc;
124     else
125         LIBC=lib/libc;
126     fi
127     sh build-aux/test.sh "scaffold/tests/$t" &> scaffold/tests/"$t".log
128     r=$?
129     total=$((total+1))
130     if [ $r = 0 ]; then
131         echo $t: [OK]
132         pass=$((pass+1))
133     else
134         echo $t: [FAIL]
135         fail=$((fail+1))
136     fi
137 done
138
139 tests="
140 00_assignment
141 01_comment
142 02_printf
143 03_struct
144 04_for
145 05_array
146 06_case
147 07_function
148 08_while
149 09_do_while
150
151 10_pointer
152 11_precedence
153 12_hashdefine
154 13_integer_literals
155 14_if
156 15_recursion
157 16_nesting
158 17_enum
159 18_include
160 19_pointer_arithmetic
161
162 20_pointer_comparison
163 21_char_array
164 22_floating_point
165 23_type_coercion
166 24_math_library
167 25_quicksort
168 26_character_constants
169 27_sizeof
170 28_strings
171 29_array_address
172
173 30_hanoi
174 31_args
175 32_led
176 33_ternary_op
177 34_array_assignment
178 35_sizeof
179 36_array_initialisers
180 37_sprintf
181 38_multiple_array_index
182 39_typedef
183
184 40_stdio
185 41_hashif
186 42_function_pointer
187 43_void_param
188 44_scoped_declarations
189 45_empty_for
190 46_grep
191 47_switch_return
192 48_nested_break
193 49_bracket_evaluation
194
195 50_logical_second_arg
196 51_static
197 52_unnamed_enum
198 55_lshift_type
199 54_goto
200 "
201
202 broken="$broken
203 18_include
204
205 22_floating_point
206 23_type_coercion
207 24_math_library
208 26_character_constants
209 27_sizeof
210 28_strings
211
212 30_hanoi
213 32_led
214 34_array_assignment
215 37_sprintf
216 38_multiple_array_index
217 39_typedef
218
219 40_stdio
220 42_function_pointer
221 46_grep
222 49_bracket_evaluation
223
224 51_static
225 52_unnamed_enum
226 55_lshift_type
227 "
228
229 #22_floating_point       ; float
230 #23_type_coercion        ; float
231 #24_math_library         ; float
232 #27_sizeof               ; float
233 #28_strings              ; TODO: strncpy strchr strrchr memset memcpy memcmp
234 #30_hanoi                ; fails with GCC
235 #32_led                  ; unsupported: (decl (decl-spec-list (stor-spec (static)) (type-spec (fixed-type "int"))) (init-declr-list (init-declr (array-of (ident "d") (p-expr (fixed "32"))))))
236 #34_array_assignment     ; fails with GCC
237 #36_array_initialisers   ; unspported: (decl (decl-spec-list (type-spec (fixed-type "int"))) (init-declr-list (init-declr (array-of (ident "Array") (p-expr (fixed "10"))) (initzer (initzer-list (initzer (p-expr (fixed "12"))) (initzer (p-expr (fixed "34"))) (initzer (p-expr (fixed "56"))) (initzer (p-expr (fixed "78"))) (initzer (p-expr (fixed "90"))) (initzer (p-expr (fixed "123"))) (initzer (p-expr (fixed "456"))) (initzer (p-expr (fixed "789"))) (initzer (p-expr (fixed "8642"))) (initzer (p-expr (fixed "9753"))))))))
238 #37_sprintf              ; integer formatting unsupported
239 #38_multiple_array_index ; unspported: (decl (decl-spec-list (type-spec (fixed-type "int"))) (init-declr-list (init-declr (array-of (array-of (ident "a") (p-expr (fixed "4"))) (p-expr (fixed "4"))))))
240 #39_typedef              ;unsupported: (decl (decl-spec-list (stor-spec (typedef)) (type-spec (typename "MyFunStruct"))) (init-declr-list (init-declr (ptr-declr (pointer) (ident "MoreFunThanEver")))))
241
242 #40_stdio                ; f* functions
243 #42_function_pointer     ; f* functions
244 #46_grep                 ; f* functions
245 #49_bracket_evaluation   ; float
246 #51_static               ; unsupported: (decl (decl-spec-list (stor-spec (static)) (type-spec (fixed-type "int"))) (init-declr-list (init-declr (ident "fred") (initzer (p-expr (fixed "1234"))))))
247 #52_unnamed_enum         ; unsupported: (decl (decl-spec-list (stor-spec (typedef)) (type-spec (enum-def (enum-def-list (enum-defn (ident "e")) (enum-defn (ident "f")) (enum-defn (ident "g")))))) (init-declr-list (init-declr (ident "h"))))
248 #55_lshift_type          ; unsigned
249
250
251 expect=$(echo $broken | wc -w)
252 for t in $tests; do
253     if [ ! -f scaffold/tinycc/"$t.c" ]; then
254         echo ' [SKIP]'
255         continue;
256     fi
257     sh build-aux/test.sh "scaffold/tinycc/$t" arg1 arg2 arg3 arg4 arg5 &> scaffold/tinycc/"$t".log
258     r=$?
259     total=$((total+1))
260     if [ $r = 0 ]; then
261         echo $t: [OK]
262         pass=$((pass+1))
263     else
264         echo $t: [FAIL]
265         fail=$((fail+1))
266     fi
267 done
268 [ $expect != 0 ] && echo "expect: $expect"
269 [ $fail != 0 ] && echo "failed: $fail"
270 [ $fail -lt $expect ] && echo "solved: $(($expect - $fail))"
271 echo "passed: $pass"
272 echo "total:  $total"
273 if [ $fail != 0 -a $fail -gt $expect ]; then
274     echo FAILED: $fail/$total
275     exit 1
276 elif [ $fail != 0 ]; then
277     echo PASS: $pass/$total
278 else
279     echo PASS: $total
280 fi