5884f8f83d4cba62b09100daa80f8ec7573ae896
[mes.git] / build-aux / check-mescc.sh
1 #! /bin/sh
2
3 # GNU Mes --- Maxwell Equations of Software
4 # Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
5 #
6 # This file is part of GNU Mes.
7 #
8 # GNU 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 # GNU 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 GNU Mes.  If not, see <http://www.gnu.org/licenses/>.
20
21 set -e
22 . ${srcdest}build-aux/config.sh
23 . ${srcdest}build-aux/trace.sh
24
25 MES=${MES-src/mes}
26 [ -z "$MESCC" ] && MESCC=scripts/mescc
27 GUILE=${GUILE-guile}
28 MES_PREFIX=${MES_PREFIX-mes}
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 if ! command -v $GUILE > /dev/null; then
40     GUILE=true
41 fi
42
43 test_sh=${test_sh-${srcdest}build-aux/test.sh}
44 if [ "$arch" = "x86_64-mes" ]; then
45     test_sh=${srcdest}build-aux/test64.sh
46 fi
47
48 tests="
49 t
50 00-exit-0
51 01-return-0
52 02-return-1
53 03-call
54 04-call-0
55 05-call-1
56 06-call-!1
57 06-!call-1
58 06-call-2
59 06-call-string
60 06-call-variable
61 06-return-void
62 07-include
63 08-assign
64 08-assign-negative
65 08-assign-global
66 10-if-0
67 11-if-1
68 12-if-==
69 13-if-!=
70 14-if-goto
71 15-if-!f
72 16-if-t
73 17-compare-ge
74 17-compare-gt
75 17-compare-le
76 17-compare-lt
77 17-compare-unsigned-ge
78 17-compare-unsigned-gt
79 17-compare-unsigned-le
80 17-compare-unsigned-lt
81 17-compare-and
82 17-compare-or
83 17-compare-and-or
84 17-compare-assign
85 17-compare-call
86 18-assign-shadow
87 20-while
88 21-char[]-simple
89 21-char[]
90 22-while-char[]
91 23-global-pointer-init-null
92 23-global-pointer-init
93 23-global-pointer-ref
94 23-global-pointer-pointer-ref
95 23-pointer-sub
96 23-pointer
97 30-strlen
98 31-oputs
99 32-call-wrap
100 32-compare
101 33-and-or
102 34-pre-post
103 35-compare-char
104 36-compare-arithmetic
105 37-compare-assign
106 38-compare-call-2
107 38-compare-call-3
108 38-compare-call
109 40-if-else
110 41-?
111 42-goto-label
112 43-for-do-while
113 44-switch
114 44-switch-fallthrough
115 44-switch-body-fallthrough
116 45-void-call
117 46-function-static
118 47-function-expression
119 48-global-static
120 50-assert
121 51-pointer-sub
122 51-itoa
123 51-strcmp
124 51-strncmp
125 53-strcpy
126 54-argc
127 54-argv
128 55-char-array
129 60-math
130 61-array
131 62-array
132 63-struct
133 63-struct-pointer
134 63-struct-local
135 63-struct-function
136 63-struct-assign
137 63-struct-array
138 63-struct-array-assign
139 63-struct-array-compare
140 63-struct-cell
141 64-make-cell
142 65-read
143 66-local-char-array
144 70-strchr
145 70-stdarg
146 70-printf-hello
147 70-printf-simple
148 70-printf
149 71-struct-array
150 72-typedef-struct-def
151 73-union-hello
152 73-union
153 74-multi-line-string
154 75-struct-union
155 76-pointer-arithmetic-pp
156 76-pointer-arithmetic
157 77-pointer-assign
158 78-union-struct
159 79-int-array-simple
160 79-int-array
161 7a-struct-char-array
162 7b-struct-int-array-hello
163 7b-struct-int-array-pointer
164 7b-struct-int-array
165 7c-dynarray
166 7d-cast-char
167 7e-struct-array-access
168 7f-struct-pointer-arithmetic
169 7g-struct-byte-word-field
170 7h-struct-assign
171 7i-struct-struct-simple
172 7i-struct-struct
173 7j-strtoull
174 7k-empty-for
175 7k-for-each-elem-simple
176 7k-for-each-elem
177 7l-struct-any-size-array-simple
178 7l-struct-any-size-array
179 7m-struct-char-array-assign
180 7n-struct-struct-array
181 7o-struct-pre-post-simple
182 7o-struct-pre-post
183 7p-struct-cast
184 7q-bit-field-simple
185 7q-bit-field
186 7r-sign-extend
187 7s-struct-short
188 7s-unsigned-compare
189 7t-function-destruct
190 7u-double
191 7u-long-long
192 7u-?-expression
193 7u-call-?
194 7u-inc-byte-word
195 7u-struct-func
196 7u-struct-size10
197 7u-vstack
198 80-setjmp
199 81-qsort
200 81-qsort-dupes
201 82-define
202 83-heterogenoous-init
203 84-struct-field-list
204 85-sizeof
205 86-strncpy
206 87-sscanf
207 88-strrchr
208 90-strspn
209 90-strpbrk
210 91-fseek
211 92-stat
212 93-fread-fwrite
213 94-unsetenv
214 95-signal
215 96-strto
216 97-fopen
217 98-fopen
218 99-readdir
219 a0-call-trunc-char
220 a0-call-trunc-short
221 "
222
223 broken="$broken
224 66-local-char-array
225 "
226
227 # gcc not supported
228 CC=
229 set +e
230 expect=$(echo $broken | wc -w)
231 pass=0
232 fail=0
233 total=0
234 mkdir -p scaffold/tests
235 for t in $tests; do
236     if [ -z "${t/[012][0-9]-*/}" ]; then
237         LIBC=
238         MES_LIBS="-l none"
239     elif [ -z "${t/[34][0-9]-*/}" ]; then
240         LIBC=c-mini
241         MES_LIBS="-l c-mini"
242     elif [ -z "${t/[78][0-9a-z]-*/}" ]; then
243         LIBC=c+tcc
244         MES_LIBS="-l c+tcc"
245     elif [ -z "${t/9[0-9]-*/}" ]; then
246         LIBC=c+gnu
247         MES_LIBS="-l c+gnu"
248     else
249         LIBC=c
250         MES_LIBS=
251     fi
252     sh $test_sh "scaffold/tests/$t" &> scaffold/tests/"$t".log
253     r=$?
254     total=$((total+1))
255     if [ $r = 0 ]; then
256         echo $t: [OK]
257         pass=$((pass+1))
258     else
259         echo $t: [FAIL]
260         fail=$((fail+1))
261     fi
262 done
263
264 [ $expect != 0 ] && echo "expect: $expect"
265 [ $fail != 0 ] && echo "failed: $fail"
266 [ $fail -lt $expect ] && echo "solved: $(($expect - $fail))"
267 echo "passed: $pass"
268 echo "total:  $total"
269 if [ $fail != 0 -a $fail -gt $expect ]; then
270     echo FAILED: $fail/$total
271     exit 1
272 elif [ $fail != 0 ]; then
273     echo PASS: $pass/$total
274 else
275     echo PASS: $total
276 fi