.
[mu.git] / linux / test_apps
bloba72b1ce57b11e2135c67effc4374cfd61d34468b
1 #!/bin/sh
2 # Build and test all included Mu and SubX programs on Linux:
3 # translate them into ELF binaries
4 # if possible, compare the generated binaries with what's already in git
5 # run/test the ELF binaries in emulated mode
6 # run/test the ELF binaries in native mode
8 # Example usage:
9 # test_apps
10 # test_apps record # don't compare with what's in git
12 set -e
13 cd `dirname $0`
15 echo "== translating using the bootstrap C++ translator"
17 # example programs
19 echo ex1
20 bootstrap/bootstrap translate 000init.subx apps/ex1.subx -o ex1
22 bootstrap/bootstrap run ex1 || ret=$?
23 test $ret -eq 42 # life, the universe and everything
26 chmod +x ex1
27 ./ex1 || ret=$?
28 test $ret -eq 42 # life, the universe and everything
31 echo ex2
32 bootstrap/bootstrap translate 000init.subx apps/ex2.subx -o ex2
34 bootstrap/bootstrap run ex2 || ret=$?
35 test $ret -eq 7 # 3 + 4
38 chmod +x ex2
39 ./ex2 || ret=$?
40 test $ret -eq 7 # 3 + 4
43 echo ex3
44 bootstrap/bootstrap translate 000init.subx apps/ex3.subx -o ex3
46 bootstrap/bootstrap run ex3 || ret=$?
47 test $ret -eq 55 # 1 + 2 + ... + 10
50 chmod +x ex3
51 ./ex3 || ret=$?
52 test $ret -eq 55 # 1 + 2 + ... + 10
55 echo ex4
56 bootstrap/bootstrap translate 000init.subx apps/ex4.subx -o ex4
58 echo a | bootstrap/bootstrap run ex4 >ex4.out || true
59 test `cat ex4.out` = 'a'
62 chmod +x ex4
63 echo a | ./ex4 >ex4.out || true
64 test `cat ex4.out` = 'a'
67 echo ex5
68 bootstrap/bootstrap translate 000init.subx apps/ex5.subx -o ex5
70 echo a | bootstrap/bootstrap run ex5 >ex5.out || true
71 test `cat ex5.out` = 'a'
74 chmod +x ex5
75 echo a | ./ex5 >ex5.out || true
76 test `cat ex5.out` = 'a'
79 echo ex6
80 bootstrap/bootstrap translate 000init.subx apps/ex6.subx -o ex6
82 bootstrap/bootstrap run ex6 >ex6.out || true
83 test "`cat ex6.out`" = 'Hello world!'
86 chmod +x ex6
87 ./ex6 >ex6.out || true
88 test "`cat ex6.out`" = 'Hello world!'
91 echo ex7
92 bootstrap/bootstrap translate 000init.subx apps/ex7.subx -o ex7
94 bootstrap/bootstrap run ex7 || ret=$?
95 test $ret -eq 97 # 'a'
98 chmod +x ex7
99 ./ex7 || ret=$?
100 test $ret -eq 97 # 'a'
103 echo ex8
104 bootstrap/bootstrap translate 000init.subx apps/ex8.subx -o ex8
106 bootstrap/bootstrap run ex8 abcd || ret=$?
107 test $ret -eq 4 # length('abcd')
110 chmod +x ex8
111 ./ex8 abcd || ret=$?
112 test $ret -eq 4 # length('abcd')
115 echo ex9
116 bootstrap/bootstrap translate 000init.subx apps/ex9.subx -o ex9
118 bootstrap/bootstrap run ex9 z x || ret=$?
119 test $ret -eq 2 # 'z' - 'x'
122 chmod +x ex9
123 ./ex9 z x || ret=$?
124 test $ret -eq 2 # 'z' - 'x'
127 echo ex10
128 bootstrap/bootstrap translate 000init.subx apps/ex10.subx -o ex10
130 bootstrap/bootstrap run ex10 abc abc || ret=$?
131 test $ret -eq 1 # equal
132 bootstrap/bootstrap run ex10 abc abcd # 0; not equal
135 chmod +x ex10
136 ./ex10 abc abc || ret=$?
137 test $ret -eq 1 # equal
138 ./ex10 abc abcd # 0; not equal
141 echo ex11
142 bootstrap/bootstrap translate 000init.subx apps/ex11.subx -o ex11
144 bootstrap/bootstrap run ex11
145 echo
148 chmod +x ex11
149 ./ex11
150 echo
153 echo ex12
154 bootstrap/bootstrap translate 000init.subx apps/ex12.subx -o ex12
155 bootstrap/bootstrap run ex12 # final byte of mmap'd address is well-nigh guaranteed to be 0
156 chmod +x ex12
157 ./ex12
159 echo ex13
160 bootstrap/bootstrap translate 000init.subx apps/ex13.subx -o ex13
162 bootstrap/bootstrap run ex13 || ret=$?
163 test $ret -eq 1 # 3 == 3
166 chmod +x ex13
167 ./ex13 || ret=$?
168 test $ret -eq 1 # 3 == 3
171 # Larger apps that use the standard library.
173 echo factorial
174 bootstrap/bootstrap translate [01]*.subx apps/factorial.subx -o factorial
176 bootstrap/bootstrap run factorial || ret=$?
177 test $ret -eq 120 # factorial(5)
178 bootstrap/bootstrap run factorial test
179 echo
182 chmod +x factorial
183 ./factorial || ret=$?
184 test $ret -eq 120 # factorial(5)
185 ./factorial test
186 echo
189 echo random
190 bootstrap/bootstrap translate [01]*.subx apps/random.subx -o random
191 # don't run
193 # Phases of the self-hosted SubX translator.
195 for phase in hex survey_elf survey_baremetal labels_baremetal pack assort dquotes tests
197 echo $phase
198 bootstrap/bootstrap translate [01]*.subx subx-params.subx $phase.subx -o $phase
199 test "$1" = 'record' || git diff --exit-code $phase
201 bootstrap/bootstrap run $phase test
202 echo
205 chmod +x $phase
206 ./$phase test
207 echo
209 done
211 # Higher-level syntax.
213 # Certain phases of translation run native beyond this point. We're starting
214 # to go beyond functionality of the C++ bootstrap_bin.
216 echo sigils
217 bootstrap/bootstrap translate [012]*.subx subx-params.subx sigils.subx -o sigils
218 test "$1" = 'record' || git diff --exit-code sigils
220 bootstrap/bootstrap run sigils test
221 echo
224 chmod +x sigils
225 ./sigils test
226 echo
229 echo calls
230 cat [012]*.subx subx-params.subx calls.subx | ./sigils > a.sigils
231 bootstrap/bootstrap translate a.sigils -o calls
232 test "$1" = 'record' || git diff --exit-code calls
234 bootstrap/bootstrap run calls test
235 echo
238 chmod +x calls
239 ./calls test
240 echo
243 echo braces
244 cat [012]*.subx subx-params.subx braces.subx | ./calls | ./sigils > a.sigils
245 bootstrap/bootstrap translate a.sigils -o braces
246 test "$1" = 'record' || git diff --exit-code braces
248 bootstrap/bootstrap run braces test
249 echo
252 chmod +x braces
253 ./braces test
254 echo
257 echo mu
258 cat [0-2]*.subx mu.subx | ./braces | ./calls | ./sigils > a.sigils
259 bootstrap/bootstrap translate a.sigils -o mu
260 test "$1" = 'record' || git diff --exit-code mu
262 bootstrap/bootstrap run mu test
263 echo
266 chmod +x mu
267 ./mu test
268 echo
271 echo "== translating using the self-hosted translator"
273 # example programs
275 for n in `seq 1 12`
277 echo ex$n
278 ./translate_subx 000init.subx apps/ex$n.subx
279 diff ex$n a.elf
280 done
282 # Larger apps that use the standard library.
284 for app in factorial
286 echo $app
287 ./translate_subx [01]*.subx apps/$app.subx
288 diff $app a.elf
289 done
291 # Phases of the self-hosted SubX translator.
293 for app in hex survey_elf survey_baremetal labels_baremetal pack assort dquotes tests
295 echo $app
296 ./translate_subx [01]*.subx subx-params.subx $app.subx
297 diff $app a.elf
298 done
300 for app in sigils calls braces
302 echo $app
303 ./translate_subx [012]*.subx subx-params.subx $app.subx
304 diff $app a.elf
305 done
307 # Mu translator
308 echo mu
309 ./translate_subx [0-2]*.subx mu.subx
310 diff mu a.elf
312 # Mu programs
314 echo ex1.mu
315 ./translate apps/ex1.mu
317 bootstrap/bootstrap run a.elf || ret=$?
318 test $ret -eq 42 # life, the universe and everything
321 ./a.elf || ret=$?
322 test $ret -eq 42 # life, the universe and everything
325 echo ex2.mu
326 ./translate apps/ex2.mu
328 bootstrap/bootstrap run a.elf || ret=$?
329 test $ret -eq 7
332 ./a.elf || ret=$?
333 test $ret -eq 7
336 echo ex3.mu
337 ./translate apps/ex3.mu
339 bootstrap/bootstrap run a.elf || ret=$?
340 test $ret -eq 55
343 ./a.elf || ret=$?
344 test $ret -eq 55
347 echo ex3.2.mu
348 ./translate apps/ex3.2.mu
350 bootstrap/bootstrap run a.elf || ret=$?
351 test $ret -eq 55
354 ./a.elf || ret=$?
355 test $ret -eq 55
358 echo factorial.mu
359 ./translate apps/factorial.mu
361 bootstrap/bootstrap run a.elf || ret=$?
362 test $ret -eq 120
363 bootstrap/bootstrap run a.elf test
364 echo
367 ./a.elf || ret=$?
368 test $ret -eq 120
369 ./a.elf test
370 echo
373 exit 0