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