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