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