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