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