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