58bcf78b06cf1f3968942ab71662893fc11c7cb6
[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 tests="
44 t
45 00-exit-0
46 01-return-0
47 02-return-1
48 03-call
49 04-call-0
50 05-call-1
51 06-call-!1
52 10-if-0
53 11-if-1
54 12-if-==
55 13-if-!=
56 14-if-goto
57 15-if-!f
58 16-if-t
59 20-while
60 21-char[]
61 22-while-char[]
62 23-pointer
63 30-strlen
64 31-eputs
65 32-compare
66 33-and-or
67 34-pre-post
68 35-compare-char
69 36-compare-arithmetic
70 37-compare-assign
71 38-compare-call
72 40-if-else
73 41-?
74 42-goto-label
75 43-for-do-while
76 44-switch
77 45-void-call
78 46-function-static
79 47-function-expression
80 48-function-destruct
81 49-global-static
82 4a-char-array
83 50-assert
84 51-strcmp
85 52-itoa
86 53-strcpy
87 54-argv
88 60-math
89 61-array
90 62-array
91 63-struct-cell
92 64-make-cell
93 65-read
94 70-printf
95 71-struct-array
96 72-typedef-struct-def
97 73-union
98 74-multi-line-string
99 75-struct-union
100 76-pointer-arithmetic
101 77-pointer-assign
102 78-union-struct
103 79-int-array
104 7a-struct-char-array
105 7b-struct-int-array
106 7c-dynarray
107 7d-cast-char
108 7e-struct-array-access
109 7f-struct-pointer-arithmetic
110 7g-struct-byte-word-field
111 7h-struct-assign
112 7i-struct-struct
113 7j-strtoull
114 7k-for-each-elem
115 7l-struct-any-size-array
116 7m-struct-char-array-assign
117 7n-struct-struct-array
118 7o-struct-pre-post
119 7p-struct-cast
120 7q-bit-field
121 7r-sign-extend
122 7s-struct-short
123 80-setjmp
124 81-qsort
125 82-define
126 83-heterogenoous-init
127 84-struct-field-list
128 85-sizeof
129 86-strncpy
130 87-sscanf
131 88-strrchr
132 90-strpbrk
133 91-fseek
134 92-stat
135 93-fread-fwrite
136 94-unsetenv
137 95-signal
138 96-strto
139 97-fopen
140 98-fopen
141 "
142
143 # 90: needs GNU, fails for mescc, passes for tcc
144 broken="$broken
145 7s-struct-short
146 "
147
148 # gcc not supported
149 CC=
150 set +e
151 expect=$(echo $broken | wc -w)
152 pass=0
153 fail=0
154 total=0
155 mkdir -p scaffold/tests
156 for t in $tests; do
157     if [ -z "${t/[012][0-9]-*/}" ]; then
158         LIBC=
159         MES_LIBS="-l none"
160     elif [ -z "${t/[34][0-9]-*/}" ]; then
161         LIBC=c-mini
162         MES_LIBS="-l c-mini"
163     elif [ -z "${t/[78][0-9a-z]-*/}" ]; then
164         LIBC=c+tcc
165         MES_LIBS="-l c+tcc"
166     elif [ -z "${t/9[0-9]-*/}" ]; then
167         LIBC=c+gnu
168         MES_LIBS="-l c+gnu"
169     else
170         LIBC=c
171         MES_LIBS=
172     fi
173     sh ${srcdest}build-aux/test.sh "scaffold/tests/$t" &> scaffold/tests/"$t".log
174     r=$?
175     total=$((total+1))
176     if [ $r = 0 ]; then
177         echo $t: [OK]
178         pass=$((pass+1))
179     else
180         echo $t: [FAIL]
181         fail=$((fail+1))
182     fi
183 done
184
185 [ $expect != 0 ] && echo "expect: $expect"
186 [ $fail != 0 ] && echo "failed: $fail"
187 [ $fail -lt $expect ] && echo "solved: $(($expect - $fail))"
188 echo "passed: $pass"
189 echo "total:  $total"
190 if [ $fail != 0 -a $fail -gt $expect ]; then
191     echo FAILED: $fail/$total
192     exit 1
193 elif [ $fail != 0 ]; then
194     echo PASS: $pass/$total
195 else
196     echo PASS: $total
197 fi