guix: Add nyacc-for-mes.
[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 7r-sign-extend
119 7s-struct-short
120 80-setjmp
121 81-qsort
122 82-define
123 83-heterogenoous-init
124 84-struct-field-list
125 85-sizeof
126 86-strncpy
127 "
128
129 broken="$broken
130 7s-struct-short
131 "
132
133 set +e
134 expect=$(echo $broken | wc -w)
135 pass=0
136 fail=0
137 total=0
138 LIBC=libc/libc
139 for t in $tests; do
140     if [ -z "${t/[012][0-9]-*/}" ]; then
141         LIBC=lib/mini-libc;
142     elif [ -z "${t/8[0-9]-*/}" ]; then
143         LIBC=lib/libc+tcc;
144     else
145         LIBC=lib/libc;
146     fi
147     sh build-aux/test.sh "scaffold/tests/$t" &> scaffold/tests/"$t".log
148     r=$?
149     total=$((total+1))
150     if [ $r = 0 ]; then
151         echo $t: [OK]
152         pass=$((pass+1))
153     else
154         echo $t: [FAIL]
155         fail=$((fail+1))
156     fi
157 done
158
159 tests="
160 00_assignment
161 01_comment
162 02_printf
163 03_struct
164 04_for
165 05_array
166 06_case
167 07_function
168 08_while
169 09_do_while
170
171 10_pointer
172 11_precedence
173 12_hashdefine
174 13_integer_literals
175 14_if
176 15_recursion
177 16_nesting
178 17_enum
179 18_include
180 19_pointer_arithmetic
181
182 20_pointer_comparison
183 21_char_array
184 22_floating_point
185 23_type_coercion
186 24_math_library
187 25_quicksort
188 26_character_constants
189 27_sizeof
190 28_strings
191 29_array_address
192
193 30_hanoi
194 31_args
195 32_led
196 33_ternary_op
197 34_array_assignment
198 35_sizeof
199 36_array_initialisers
200 37_sprintf
201 38_multiple_array_index
202 39_typedef
203
204 40_stdio
205 41_hashif
206 42_function_pointer
207 43_void_param
208 44_scoped_declarations
209 45_empty_for
210 46_grep
211 47_switch_return
212 48_nested_break
213 49_bracket_evaluation
214
215 50_logical_second_arg
216 51_static
217 52_unnamed_enum
218 54_goto
219 55_lshift_type
220 "
221
222 broken="$broken
223 18_include
224
225 22_floating_point
226 23_type_coercion
227 24_math_library
228 26_character_constants
229 27_sizeof
230 28_strings
231
232 31_args
233 34_array_assignment
234 37_sprintf
235 39_typedef
236
237 40_stdio
238 42_function_pointer
239 46_grep
240 49_bracket_evaluation
241 "
242
243 #22_floating_point       ; float
244 #23_type_coercion        ; float
245 #24_math_library         ; float
246 #27_sizeof               ; float
247 #28_strings              ; TODO: strncpy strchr strrchr memset memcpy memcmp
248 #30_hanoi                ; fails with GCC
249 #34_array_assignment     ; fails with GCC
250 #37_sprintf              ; integer formatting unsupported
251 #39_typedef              ;unsupported: (decl (decl-spec-list (stor-spec (typedef)) (type-spec (typename "MyFunStruct"))) (init-declr-list (init-declr (ptr-declr (pointer) (ident "MoreFunThanEver")))))
252
253 #40_stdio                ; f* functions
254 #42_function_pointer     ; f* functions
255 #46_grep                 ; f* functions
256 #49_bracket_evaluation   ; float
257
258
259
260 expect=$(echo $broken | wc -w)
261 for t in $tests; do
262     if [ ! -f scaffold/tinycc/"$t.c" ]; then
263         echo ' [SKIP]'
264         continue;
265     fi
266     sh build-aux/test.sh "scaffold/tinycc/$t" &> scaffold/tinycc/"$t".log
267     r=$?
268     total=$((total+1))
269     if [ $r = 0 ]; then
270         echo $t: [OK]
271         pass=$((pass+1))
272     else
273         echo $t: [FAIL]
274         fail=$((fail+1))
275     fi
276 done
277 [ $expect != 0 ] && echo "expect: $expect"
278 [ $fail != 0 ] && echo "failed: $fail"
279 [ $fail -lt $expect ] && echo "solved: $(($expect - $fail))"
280 echo "passed: $pass"
281 echo "total:  $total"
282 if [ $fail != 0 -a $fail -gt $expect ]; then
283     echo FAILED: $fail/$total
284     exit 1
285 elif [ $fail != 0 ]; then
286     echo PASS: $pass/$total
287 else
288     echo PASS: $total
289 fi