interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / ng / tests / ngbuild / gate.om

544 lines · 10546 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Independent first-birth and regression gate for ngbuild. This file has no helper units.
3note omc < seed/ng/tests/ngbuild/gate.om > GATE; GATE OMC SCRATCH
4note Runs from repository root; creates SCRATCH if absent. All joining, process control and checks
5note are Omega. Only first birth uses the independent two-unit join here; every later build uses
6note ngbuild's pinned units parser. No cat, shell command or shell process runs in this gate.
7note Exit 0 all checks passed; 1 a check failed; 2 usage/fixture IO failed; 3 bootstrap failed.
8note Optional fourth argument "wrong" inverts the missing-unit expected exit: the gate must fail.
9note Any other fourth argument names a different NGBUILD to test an implementation mutant.
10text g_words "ngbuild ngbuild2 ngbuild2.src out out.src err units large alias missing ng ng.src source seed/ng/sha256.om seed/ng/ngbuild.om seed/ng/ngbuild.units seed/ng/ng.units build sums wrong stdout "
11text g_zero "0000000000000000000000000000000000000000000000000000000000000000 "
12text g_pass "NGBUILDGATE PASS\n"
13text g_fail "NGBUILDGATE FAIL\n"
14text g_case "PASS case "
15text g_bad "FAIL case "
16text g_nl "\n"
17text g_exp "ngbuild: unreadable: |ngbuild: duplicate unit line 2: |ngbuild: malformed units line 0|ngbuild: no units|ngbuild: more than 64 units|ngbuild: too large: |ngbuild: sha256 mismatch | have 049532d3bf88d8abaede42dff6642b402008e141b7635cb1e1f8aca26a5e4ebf|"
18text g_wrong "wrong"
19text g_prog "fn main to int\nret 0\nend\n"
20global g_ep ulong 1
21global g_pa uchar 4096
22global g_pn ulong 1
23global g_sc uchar 2048
24global g_sn ulong 1
25global g_om uchar 2048
26global g_on ulong 1
27global g_nb uchar 4096
28global g_nn ulong 1
29global g_arg uchar 2048
30global g_av uchar 16384
31global g_an ulong 2
32global g_wo ulong 32
33global g_wl ulong 32
34global g_a uchar 16777216
35global g_b uchar 16777216
36global g_n ulong 8
37global g_st uchar 4
38global g_d uchar 24
39fn g_init to void
40s = ulong 0
41k = ulong 0
42for i ulong len g_words
43if eq get g_words i 32
44put g_wo k s
45put g_wl k sub i s
46k = add k 1
47s = add i 1
48end
49end
50end
51fn g_path k ulong scratch bool to void
52n = ulong 0
53if scratch
54for i ulong get g_sn 0 bound 2048
55put g_pa i get g_sc i
56end
57n = get g_sn 0
58put g_pa n 47
59n = add n 1
60end
61s = get g_wo k
62for i ulong get g_wl k bound 4096
63put g_pa add n i get g_words add s i
64end
65put g_pn 0 add n get g_wl k
66end
67fn g_open flags int mode int to int
68fd = fopen g_pa 0 get g_pn 0 flags mode
69if lt fd 0
70exit 2
71end
72ret int fd
73end
74fn g_load which bool to ulong
75fd = g_open 0 0
76n = ulong 0
77while lt n len g_a bound 16777217
78x = long 0
79if which
80x = read fd g_a n sub len g_a n
81else
82x = read fd g_b n sub len g_b n
83end
84if lt x 0
85exit 2
86end
87if eq x 0
88r = fclose fd
89ret n
90end
91n = add n ulong x
92end
93exit 2
94end
95fn g_save n ulong mode int to void
96fd = g_open 577 mode
97o = ulong 0
98while lt o n bound 16777217
99x = write fd g_a o sub n o
100if le x 0
101exit 2
102end
103o = add o ulong x
104end
105r = fclose fd
106end
107fn g_equal n ulong m ulong to bool
108if ne n m
109ret false
110end
111for i ulong n bound 16777216
112if ne get g_a i get g_b i
113ret false
114end
115end
116ret true
117end
118fn g_clr to void
119put g_an 0 2
120put g_an 1 0
121end
122fn g_pack a view uchar 4096 n ulong to void
123p = get g_an 0
124put g_av p uchar and n 255
125put g_av add p 1 uchar shr n 8
126for i ulong n bound 4096
127put g_av add add p 2 i get a i
128end
129put g_an 0 add add p 2 n
130put g_an 1 add get g_an 1 1
131end
132note Global arrays cannot be arguments: copy the current path to one local argument buffer.
133fn g_argp to void
134a = new uchar 4096 0
135n = get g_pn 0
136for i ulong n bound 4096
137put a i get g_pa i
138end
139g_pack a n
140end
141fn g_argo to void
142for i ulong get g_on 0 bound 2048
143put g_pa i get g_om i
144end
145put g_pn 0 get g_on 0
146g_argp
147end
148fn g_argn to void
149for i ulong get g_nn 0 bound 4096
150put g_pa i get g_nb i
151end
152put g_pn 0 get g_nn 0
153g_argp
154end
155fn g_run fi int fo int to ulong
156g_path 5 true
157fe = g_open 577 420
158c = get g_an 1
159put g_av 0 uchar and c 255
160put g_av 1 uchar shr c 8
161pid = fork
162if lt pid 0
163exit 2
164end
165if eq pid 0
166r = dupfd fi 0 0
167r = dupfd fo 1 0
168r = dupfd fe 2 0
169r = execprog g_av 0 get g_an 0
170exit 127
171end
172r = fclose fi
173r = fclose fo
174r = fclose fe
175r = waitpid int pid g_st 0 4 0
176if ne r pid
177exit 2
178end
179if ne get g_st 0 0
180ret add 256 ulong get g_st 0
181end
182ret ulong get g_st 1
183end
184fn g_nullin to int
185g_path 6 true
186ret g_open 0 0
187end
188fn g_stdout to int
189g_path 20 true
190ret g_open 577 420
191end
192fn g_call sums bool units ulong output ulong to ulong
193g_clr
194g_argn
195if sums
196g_path 18 false
197g_argp
198else
199g_path 17 false
200g_argp
201g_argo
202end
203g_path units true
204g_argp
205if not sums
206g_path output true
207g_argp
208end
209fi = g_nullin
210fo = g_stdout
211ret g_run fi fo
212end
213note Construct one fixture line (zero pin), from the scratch path k. append at offset n.
214fn g_line n ulong k ulong to ulong
215for i ulong len g_zero
216put g_a add n i get g_zero i
217end
218p = add n len g_zero
219g_path k true
220for i ulong get g_pn 0 bound 4096
221put g_a add p i get g_pa i
222end
223p = add p get g_pn 0
224put g_a p 10
225ret add p 1
226end
227fn g_fixture n ulong to void
228g_path 6 true
229g_save n 420
230end
231fn g_num n ulong to void
232if ge n 10
233g_num div n 10
234end
235put g_d 0 uchar add 48 rem n 10
236r = write 1 g_d 0 1
237end
238fn g_check id ulong ok bool to void
239put g_n 2 add get g_n 2 1
240if ok
241r = write 1 g_case 0 len g_case
242else
243put g_n 1 add get g_n 1 1
244r = write 1 g_bad 0 len g_bad
245end
246g_num id
247r = write 1 g_nl 0 len g_nl
248end
249note Every refusal must happen before output or its source is created; stdout must be empty and stderr
250note must begin with ngbuild: (not a runtime trap). OMC is real, so a surviving refusal would compile.
251note Independent exact diagnostics; the fixture digest is GNU sha256sum of g_prog.
252fn g_et k ulong to void
253s = ulong 0
254c = ulong 0
255for i ulong len g_exp
256if eq get g_exp i 124
257if eq c k
258p = get g_ep 0
259for j ulong sub i s bound 512
260put g_b add p j get g_exp add s j
261end
262put g_ep 0 add p sub i s
263ret
264end
265s = add i 1
266c = add c 1
267end
268end
269end
270fn g_etpath k ulong to void
271g_path k true
272p = get g_ep 0
273for i ulong get g_pn 0 bound 4096
274put g_b add p i get g_pa i
275end
276put g_ep 0 add p get g_pn 0
277end
278fn g_exact id ulong n ulong to bool
279put g_ep 0 0
280if eq id 4
281g_et 0
282g_etpath 9
283end
284if eq id 5
285g_et 1
286g_etpath 9
287end
288if eq id 6
289g_et 1
290g_etpath 8
291end
292if or or eq id 7 eq id 8 ge id 17
293g_et 2
294end
295if eq id 9
296g_et 3
297end
298if eq id 10
299g_et 4
300end
301if eq id 11
302g_et 5
303g_etpath 6
304end
305if or eq id 12 eq id 13
306g_et 5
307g_etpath 7
308end
309if eq id 14
310g_et 6
311g_etpath 7
312g_et 7
313end
314p = get g_ep 0
315put g_b p 10
316ret g_equal n add p 1
317end
318fn g_refuse id ulong expected ulong to void
319g_path 3 true
320r = unlink g_pa 0 get g_pn 0
321g_path 4 true
322r = unlink g_pa 0 get g_pn 0
323x = g_call false 6 3
324ok = eq x expected
325g_path 3 true
326if ge faccess g_pa 0 get g_pn 0 0 0
327ok = false
328end
329g_path 4 true
330if ge faccess g_pa 0 get g_pn 0 0 0
331ok = false
332end
333g_path 20 true
334n = g_load true
335if ne n 0
336ok = false
337end
338g_path 5 true
339n = g_load true
340if not g_exact id n
341ok = false
342end
343g_check id ok
344end
345note first birth, independent of ngbuild and ngbuild.units: exact two-unit join, no separators
346fn g_birth to void
347g_path 13 false
348n = g_load true
349g_path 14 false
350m = g_load false
351for i ulong m bound 16777216
352put g_a add n i get g_b i
353end
354g_path 12 true
355g_save add n m 420
356g_clr
357g_argo
358g_path 12 true
359fi = g_open 0 0
360g_path 0 true
361fo = g_open 577 493
362if ne g_run fi fo 0
363exit 3
364end
365g_path 0 true
366n = get g_pn 0
367for i ulong n bound 4096
368put g_nb i get g_pa i
369end
370put g_nn 0 n
371end
372fn g_self to void
373g_clr
374g_argn
375g_path 17 false
376g_argp
377g_argo
378g_path 15 false
379g_argp
380g_path 1 true
381g_argp
382fi = g_nullin
383fo = g_stdout
384x = g_run fi fo
385g_check 1 eq x 0
386if ne x 0
387exit 1
388end
389g_path 0 true
390n = g_load true
391g_path 1 true
392m = g_load false
393g_check 2 g_equal n m
394g_path 12 true
395n = g_load true
396g_path 2 true
397m = g_load false
398g_check 3 g_equal n m
399end
400fn g_tests wrong bool to void
401note missing unit
402a = g_line 0 9
403g_fixture a
404ex = ulong 5
405if wrong
406ex = 0
407end
408g_refuse 4 ex
409note duplicate path, checked before reading either missing unit
410a = g_line 0 9
411a = g_line a 9
412g_fixture a
413g_refuse 5 8
414note duplicate pin under two distinct paths
415a = g_line 0 9
416a = g_line a 8
417g_fixture a
418g_refuse 6 8
419note malformed lowercase digest
420a = g_line 0 9
421put g_a 0 71
422g_fixture a
423g_refuse 7 4
424note missing final newline
425a = g_line 0 9
426g_fixture sub a 1
427g_refuse 8 4
428note empty list
429g_fixture 0
430g_refuse 9 4
431note 65 entries checked before duplicate detection
432a = ulong 0
433for i ulong 65
434a = g_line a 9
435end
436g_fixture a
437g_refuse 10 9
438note oversize UNITS, one byte over the 65536-byte bound
439for i ulong 65537
440put g_a i 65
441end
442g_fixture 65537
443g_refuse 11 9
444note oversize unit, at the 16 MiB file buffer bound: sparse fixture, never allocated on disk
445g_path 7 true
446fd = g_open 577 420
447r = ftrunc fd 16777216
448r = fclose fd
449a = g_line 0 7
450g_fixture a
451g_refuse 12 9
452note total input at 8388608 bytes, one over omc's accepted size
453g_path 7 true
454r = truncate g_pa 0 get g_pn 0 8388608
455a = g_line 0 7
456g_fixture a
457g_refuse 13 9
458note wrong pin on a small readable unit
459g_path 7 true
460for i ulong len g_prog
461put g_a i get g_prog i
462end
463g_save len g_prog 420
464a = g_line 0 7
465g_fixture a
466g_refuse 14 3
467note sums prints the measured pin, then build takes that manifest and compiles the valid program
468note into out, so the self-built ngbuild2 and ngbuild2.src of cases 2 and 3 stay for inspection.
469x = g_call true 6 3
470g_check 15 eq x 0
471g_path 20 true
472n = g_load true
473g_fixture n
474x = g_call false 6 3
475g_check 16 eq x 0
476note embedded NUL path refused by parser, not host-word trap
477a = g_line 0 9
478put g_a 65 0
479g_fixture a
480g_refuse 17 4
481note path of 4096 bytes refused before copying into nb_p
482for i ulong 4096
483put g_a add 65 i 65
484end
485for i ulong 64
486put g_a i 48
487end
488put g_a 64 32
489put g_a 4161 10
490g_fixture 4162
491g_refuse 18 4
492note attempted ordering metadata is not in the format (cycles have no representation)
493for i ulong len g_prog
494put g_a i get g_prog i
495end
496g_fixture len g_prog
497g_refuse 19 4
498end
499fn main to int
500if or lt argcnt 3 gt argcnt 4
501ret 2
502end
503g_init
504n = argread 1 g_om 0 len g_om
505m = argread 2 g_sc 0 len g_sc
506if or le n 0 le m 0
507ret 2
508end
509put g_on 0 ulong n
510put g_sn 0 ulong m
511r = makedir g_sc 0 ulong m 493
512note empty units fixture is also the harmless stdin for all child tools
513g_fixture 0
514g_birth
515g_self
516wrong = false
517if eq argcnt 4
518n = argread 3 g_arg 0 len g_arg
519if eq n long len g_wrong
520wrong = true
521for i ulong len g_wrong
522if ne get g_arg i get g_wrong i
523wrong = false
524end
525end
526end
527if not wrong
528if le n 0
529ret 2
530end
531for i ulong ulong n bound 2048
532put g_nb i get g_arg i
533end
534put g_nn 0 ulong n
535end
536end
537g_tests wrong
538if ne get g_n 1 0
539r = write 1 g_fail 0 len g_fail
540ret 1
541end
542r = write 1 g_pass 0 len g_pass
543ret 0
544end