mescc: Tinycc support: Support bit-fields.
[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 BLOOD_ELF GUILE HEX2 M1 MES MESCC
22 export M1FLAGS HEX2FLAGS PREPROCESS LIBC
23 export MES_ARENA MES_PREFIX MES_SEED
24
25 MES=${MES-src/mes}
26 MESCC=${MESCC-scripts/mescc}
27 GUILE=${GUILE-guile}
28 MES_PREFIX=${MES_PREFIX-.}
29
30 HEX2=${HEX2-hex2}
31 M1=${M1-M1}
32 BLOOD_ELF=${BLOOD_ELF-blood-elf}
33 MES_SEED=${MES_SEED-../mes-seed}
34 MESCC=${MESCC-$(command -v mescc)}
35 [ -z "$MESCC" ] && MESCC=scripts/mescc
36 MES=${MES-$(command -v mes)}
37 [ -z "$MES" ] && MES=src/mes
38
39
40 tests="
41 t
42 00-exit-0
43 01-return-0
44 02-return-1
45 03-call
46 04-call-0
47 05-call-1
48 06-call-!1
49 10-if-0
50 11-if-1
51 12-if-==
52 13-if-!=
53 14-if-goto
54 15-if-!f
55 16-if-t
56 20-while
57 21-char[]
58 22-while-char[]
59 23-pointer
60 30-strlen
61 31-eputs
62 32-compare
63 33-and-or
64 34-pre-post
65 35-compare-char
66 36-compare-arithmetic
67 37-compare-assign
68 38-compare-call
69 40-if-else
70 41-?
71 42-goto-label
72 43-for-do-while
73 44-switch
74 45-void-call
75 46-function-static
76 47-function-expression
77 48-function-destruct
78 49-global-static
79 4a-char-array
80 50-assert
81 51-strcmp
82 52-itoa
83 53-strcpy
84 54-argv
85 60-math
86 61-array
87 62-array
88 63-struct-cell
89 64-make-cell
90 65-read
91 70-printf
92 71-struct-array
93 72-typedef-struct-def
94 73-union
95 74-multi-line-string
96 75-struct-union
97 76-pointer-arithmetic
98 77-pointer-assign
99 78-union-struct
100 79-int-array
101 7a-struct-char-array
102 7b-struct-int-array
103 7c-dynarray
104 7d-cast-char
105 7e-struct-array-access
106 7f-struct-pointer-arithmetic
107 7g-struct-byte-word-field
108 7h-struct-assign
109 7i-struct-struct
110 7j-strtoull
111 7k-for-each-elem
112 7l-struct-any-size-array
113 7m-struct-char-array-assign
114 7n-struct-struct-array
115 7o-struct-pre-post
116 7p-struct-cast
117 7q-bit-field
118 80-setjmp
119 81-qsort
120 82-define
121 83-heterogenoous-init
122 84-struct-field-list
123 85-sizeof
124 "
125
126 broken="$broken
127 "
128
129 set +e
130 expect=$(echo $broken | wc -w)
131 pass=0
132 fail=0
133 total=0
134 LIBC=libc/libc
135 for t in $tests; do
136     if [ -z "${t/[012][0-9]-*/}" ]; then
137         LIBC=lib/mini-libc;
138     elif [ -z "${t/8[0-9]-*/}" ]; then
139         LIBC=lib/libc+tcc;
140     else
141         LIBC=lib/libc;
142     fi
143     sh build-aux/test.sh "scaffold/tests/$t" &> scaffold/tests/"$t".log
144     r=$?
145     total=$((total+1))
146     if [ $r = 0 ]; then
147         echo $t: [OK]
148         pass=$((pass+1))
149     else
150         echo $t: [FAIL]
151         fail=$((fail+1))
152     fi
153 done
154
155 tests="
156 00_assignment
157 01_comment
158 02_printf
159 03_struct
160 04_for
161 05_array
162 06_case
163 07_function
164 08_while
165 09_do_while
166
167 10_pointer
168 11_precedence
169 12_hashdefine
170 13_integer_literals
171 14_if
172 15_recursion
173 16_nesting
174 17_enum
175 18_include
176 19_pointer_arithmetic
177
178 20_pointer_comparison
179 21_char_array
180 22_floating_point
181 23_type_coercion
182 24_math_library
183 25_quicksort
184 26_character_constants
185 27_sizeof
186 28_strings
187 29_array_address
188
189 30_hanoi
190 31_args
191 32_led
192 33_ternary_op
193 34_array_assignment
194 35_sizeof
195 36_array_initialisers
196 37_sprintf
197 38_multiple_array_index
198 39_typedef
199
200 40_stdio
201 41_hashif
202 42_function_pointer
203 43_void_param
204 44_scoped_declarations
205 45_empty_for
206 46_grep
207 47_switch_return
208 48_nested_break
209 49_bracket_evaluation
210
211 50_logical_second_arg
212 51_static
213 52_unnamed_enum
214 54_goto
215 55_lshift_type
216 "
217
218 broken="$broken
219 18_include
220
221 22_floating_point
222 23_type_coercion
223 24_math_library
224 26_character_constants
225 27_sizeof
226 28_strings
227
228 31_args
229 37_sprintf
230 38_multiple_array_index
231 39_typedef
232
233 40_stdio
234 42_function_pointer
235 46_grep
236 49_bracket_evaluation
237 "
238
239 #22_floating_point       ; float
240 #23_type_coercion        ; float
241 #24_math_library         ; float
242 #27_sizeof               ; float
243 #28_strings              ; TODO: strncpy strchr strrchr memset memcpy memcmp
244 #30_hanoi                ; fails with GCC
245 #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"))))))
246 #34_array_assignment     ; fails with GCC
247 #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"))))))))
248 #37_sprintf              ; integer formatting unsupported
249 #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"))))))
250 #39_typedef              ;unsupported: (decl (decl-spec-list (stor-spec (typedef)) (type-spec (typename "MyFunStruct"))) (init-declr-list (init-declr (ptr-declr (pointer) (ident "MoreFunThanEver")))))
251
252 #40_stdio                ; f* functions
253 #42_function_pointer     ; f* functions
254 #46_grep                 ; f* functions
255 #49_bracket_evaluation   ; float
256 #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"))))))
257 #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"))))
258 #55_lshift_type          ; unsigned
259
260
261 expect=$(echo $broken | wc -w)
262 for t in $tests; do
263     if [ ! -f scaffold/tinycc/"$t.c" ]; then
264         echo ' [SKIP]'
265         continue;
266     fi
267     sh build-aux/test.sh "scaffold/tinycc/$t" &> scaffold/tinycc/"$t".log
268     r=$?
269     total=$((total+1))
270     if [ $r = 0 ]; then
271         echo $t: [OK]
272         pass=$((pass+1))
273     else
274         echo $t: [FAIL]
275         fail=$((fail+1))
276     fi
277 done
278 [ $expect != 0 ] && echo "expect: $expect"
279 [ $fail != 0 ] && echo "failed: $fail"
280 [ $fail -lt $expect ] && echo "solved: $(($expect - $fail))"
281 echo "passed: $pass"
282 echo "total:  $total"
283 if [ $fail != 0 -a $fail -gt $expect ]; then
284     echo FAILED: $fail/$total
285     exit 1
286 elif [ $fail != 0 ]; then
287     echo PASS: $pass/$total
288 else
289     echo PASS: $total
290 fi