interplane.Get Omega
Read in your language

aien-architecture-mv

Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.

Brought by drakestapleton

branch main Branches Tags History

aien-architecture-mv / tools / zero-legacy / gate.om

590 lines · 9882 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note gate: the ARCH-ZERO-LEGACY-CLOSURE gate runner (#316), seeded native Omega.
3note usage: gate OMC (run from tools/zero-legacy; writes under build/)
4note Builds closure.om, expect.om and sha256.om with OMC, hashes OMC with the native sha256 and
5note compares it to omega.pin, runs the hostile and clean fixtures in release mode, judges the
6note reports with expect, builds elfclose.om and fixtures/elfgen.om, generates the synthetic ELF
7note fixtures, runs elfclose over them and over fixtures/proc and judges both reports (#316
8note item 2), prints AIEN-OBS lines. Exit 0 only when every expectation holds;
9note 3 when OMC is missing or does not match the pin (NOT_RUN); 1 otherwise.
10note gate.sh authenticates the compiler independently before compiling this native fixture gate.
11
12text tbl "closure.om\nexpect.om\nsha256.om\nbuild/closure\nbuild/expect\nbuild/sha256\nfixtures/tree\nrelease\nfixtures/manifest.txt\nfixtures/clean\nfixtures/clean-manifest.txt\nfixtures/tree.expected\nfixtures/clean.expected\nbuild/tree.out\nbuild/clean.out\nbuild/clean2.out\nbuild/omc.sha\nbuild/closure.sha\nomega.pin\nbuild\nfixtures/io-build.om\nbuild/io-build\nbuild/io-errors.om\nbuild/io-errors\nfixtures/clean/src\nread-error\ndirectory-error\nbuild/read-error.out\nbuild/directory-error.out\nelfclose.om\nbuild/elfclose\nfixtures/elfgen.om\nbuild/elfgen\nbuild/elf\nelf\nproc\nfixtures/proc\nbuild/elf.out\nbuild/proc.out\nfixtures/elf.expected\nfixtures/proc.expected\nbuild/elf/dyn-gcc\nbuild/elf/dyn-nomark\nbuild/elf/badneed\nbuild/elf/need-nostr\nbuild/elf/strtab-unmapped\nbuild/elf/bad-shstrndx\nbuild/elf/static-rust\nbuild/elf/clang-lld\nbuild/elf/static-pie-go\nbuild/elf/bare\nbuild/elf/gnu-phdr\nbuild/elf/trunc\nbuild/elf/badph\nbuild/elf/elf32\nbuild/elf/bigend\nbuild/elf/notelf\nbuild/elf/absent\nbuild/elf/need-inject\nbuild/elf/need-comma\nbuild/elf/interp-tab\nbuild/elf/interp-del\nbuild/elf/load-wrap\nbuild/elf/esc\tname\\x\n"
13text tobs "AIEN-OBS "
14text tcls "closure_sha256 \""
15text tq "\"\n"
16text ttre "tree_release_exit "
17text tcle "clean_release_exit "
18text tcl2 "clean_undeclared_exit "
19text tex1 "expect_tree_exit "
20text tex2 "expect_clean_exit "
21text trerr "read_error_exit "
22text tderr "directory_error_exit "
23text tegen "elfgen_exit "
24text telfs "elf_scan_exit "
25text tprcs "proc_scan_exit "
26text texel "expect_elf_exit "
27text texpr "expect_proc_exit "
28text txcr "cross_expect_refused "
29text tnl "\n"
30text tuse "usage: gate OMC\n"
31text tnot "gate: OMC missing or not the pinned compiler (NOT_RUN)\n"
32text tcf "gate: compile failed\n"
33text tkey "omc_sha256: "
34
35global omcp uchar 4096
36global omcl ulong 1
37global pk uchar 4096
38global pkn ulong 1
39global pkc ulong 1
40global arg uchar 256
41global argl ulong 1
42global fin uchar 256
43global finl ulong 1
44global fout uchar 256
45global foutl ulong 1
46global status uchar 4
47global pin uchar 4096
48global pinl ulong 1
49global sha uchar 128
50global nb uchar 24
51
52note ---- text table ----
53
54fn pick i ulong to void
55s = ulong 0
56k = ulong 0
57while lt k i bound 4096
58if eq get tbl s 10
59k = add k 1
60end
61s = add s 1
62end
63n = ulong 0
64while ne get tbl add s n 10 bound 256
65put arg n get tbl add s n
66n = add n 1
67end
68put argl 0 n
69end
70
71note ---- packets for execprog ----
72
73fn pk0 to void
74put pkn 0 2
75put pkc 0 0
76end
77
78fn pka to void
79n = get pkn 0
80m = get argl 0
81put pk n uchar rem m 256
82put pk add n 1 uchar div m 256
83for i ulong m
84put pk add n add 2 i get arg i
85end
86put pkn 0 add n add 2 m
87c = add get pkc 0 1
88put pkc 0 c
89put pk 0 uchar rem c 256
90put pk 1 uchar div c 256
91end
92
93fn pkt i ulong to void
94pick i
95pka
96end
97
98fn pkomc to void
99for i ulong get omcl 0
100put arg i get omcp i
101end
102put argl 0 get omcl 0
103pka
104end
105
106fn setin i ulong to void
107pick i
108for j ulong get argl 0
109put fin j get arg j
110end
111put finl 0 get argl 0
112end
113
114fn setout i ulong to void
115pick i
116for j ulong get argl 0
117put fout j get arg j
118end
119put foutl 0 get argl 0
120end
121
122fn noio to void
123put finl 0 0
124put foutl 0 0
125end
126
127note ---- run the packet; stdin/stdout redirected when set; returns exit code or -1 ----
128
129fn child to void
130if gt get finl 0 0
131fd = fopen fin 0 get finl 0 0 0
132if lt fd 0
133exit 126
134end
135r = dupfd int fd 0 0
136end
137if gt get foutl 0 0
138fd = fopen fout 0 get foutl 0 577 420
139if lt fd 0
140exit 126
141end
142r = dupfd int fd 1 0
143end
144r = execprog pk 0 get pkn 0
145exit 127
146end
147
148fn run to long
149pid = fork
150if lt pid 0
151ret -1
152end
153if eq pid 0
154child
155end
156r = waitpid int pid status 0 4 0
157if ne r pid
158ret -1
159end
160if ne get status 0 0
161ret -1
162end
163ret long get status 1
164end
165
166note ---- steps ----
167
168fn compile src ulong dst ulong to bool
169pk0
170pkomc
171setin src
172setout dst
173r = run
174if ne r 0
175ret false
176end
177pick dst
178r = chmod arg 0 get argl 0 493
179ret eq r 0
180end
181
182note hash the file named by table entry f into table entry out; read 64 hex into sha
183fn hashto f ulong out ulong to bool
184pk0
185pkt 5
186pkt f
187put finl 0 0
188setout out
189r = run
190if ne r 0
191ret false
192end
193ret readsha out
194end
195
196fn hashomc to bool
197pk0
198pkt 5
199pkomc
200put finl 0 0
201setout 16
202r = run
203if ne r 0
204ret false
205end
206ret readsha 16
207end
208
209fn readsha out ulong to bool
210pick out
211fd = fopen arg 0 get argl 0 0 0
212if lt fd 0
213ret false
214end
215r = read int fd sha 0 128
216c = fclose int fd
217ret ge r 64
218end
219
220fn loadpin to bool
221pick 18
222fd = fopen arg 0 get argl 0 0 0
223if lt fd 0
224ret false
225end
226r = read int fd pin 0 4096
227c = fclose int fd
228if le r 0
229ret false
230end
231put pinl 0 ulong r
232ret true
233end
234
235note does sha[0..64) equal the 64 bytes after "omc_sha256: " in the pin
236fn pinok to bool
237n = get pinl 0
238m = len tkey
239if lt n add m 64
240ret false
241end
242e = sub n add m 64
243i = ulong 0
244while le i e bound 4096
245j = ulong 0
246while lt j m bound 16
247if ne get pin add i j get tkey j
248break
249end
250j = add j 1
251end
252if eq j m
253ret same add i m
254end
255i = add i 1
256end
257ret false
258end
259
260fn same p ulong to bool
261for j ulong 64
262if ne get pin add p j get sha j
263ret false
264end
265end
266ret true
267end
268
269fn tree to long
270pk0
271pkt 3
272pkt 6
273pkt 7
274pkt 8
275put finl 0 0
276setout 13
277ret run
278end
279
280fn clean to long
281pk0
282pkt 3
283pkt 9
284pkt 7
285pkt 10
286put finl 0 0
287setout 14
288ret run
289end
290
291fn clean2 to long
292pk0
293pkt 3
294pkt 9
295pkt 7
296put finl 0 0
297setout 15
298ret run
299end
300
301fn judge out ulong exp ulong to long
302pk0
303pkt 4
304pkt out
305pkt exp
306noio
307ret run
308end
309
310note Build the test copy natively; no shell transformation or production fault switch.
311fn buildio to bool
312if not compile 20 21
313ret false
314end
315pk0
316pkt 21
317put finl 0 0
318setout 22
319r = run
320if ne r 0
321ret false
322end
323ret compile 22 23
324end
325
326fn iotest mode ulong out ulong to long
327pk0
328pkt 23
329pkt 24
330pkt mode
331put finl 0 0
332setout out
333ret run
334end
335
336note ---- ELF and process closure (#316 item 2) ----
337
338fn elfgen to long
339pk0
340pkt 32
341pkt 33
342noio
343ret run
344end
345
346note elfclose elf over the 16 base fixtures, build/closure (real omc output), a missing path, the 6
347note hostile-string fixtures (control bytes, a comma, a wrapping PT_LOAD, a tab in the file name)
348note and the directory build/elf (not a regular file: UNREADABLE)
349fn elfscan to long
350pk0
351pkt 30
352pkt 34
353for i ulong 16
354pkt add 41 i
355end
356pkt 3
357pkt 57
358for j ulong 6
359pkt add 58 j
360end
361pkt 33
362put finl 0 0
363setout 37
364ret run
365end
366
367fn procscan to long
368pk0
369pkt 30
370pkt 35
371pkt 36
372put finl 0 0
373setout 38
374ret run
375end
376
377note run the ELF/process stage, print its observations; true when every expectation holds.
378note The cross judgment (process report against the ELF expectations) must be refused, so a
379note judge that accepts anything cannot pass this stage.
380fn elfstage to bool
381h = elfgen
382i = elfscan
383j = procscan
384k = judge 37 39
385l = judge 38 40
386m = judge 38 39
387x = long 0
388if ne m 0
389x = 1
390end
391obsn 7 h
392obsn 8 i
393obsn 9 j
394obsn 10 k
395obsn 11 l
396obsn 12 x
397ok = true
398if ne h 0
399ok = false
400end
401if ne i 0
402ok = false
403end
404if ne j 0
405ok = false
406end
407if ne k 0
408ok = false
409end
410if ne l 0
411ok = false
412end
413if ne x 1
414ok = false
415end
416ret ok
417end
418
419note ---- output ----
420
421fn wnum v long to void
422if lt v 0
423put nb 22 45
424put nb 23 49
425r = write 1 nb 22 2
426ret
427end
428x = ulong v
429n = ulong 0
430if eq x 0
431put nb 23 48
432n = 1
433end
434while gt x 0 bound 20
435put nb sub 23 n uchar add 48 rem x 10
436x = div x 10
437n = add n 1
438end
439r = write 1 nb sub 24 n n
440end
441
442fn obs1 to void
443r = write 1 tobs 0 len tobs
444r = write 1 tcls 0 len tcls
445r = write 1 sha 0 64
446r = write 1 tq 0 len tq
447end
448
449fn obsn k ulong v long to void
450r = write 1 tobs 0 len tobs
451if eq k 0
452r = write 1 ttre 0 len ttre
453end
454if eq k 1
455r = write 1 tcle 0 len tcle
456end
457if eq k 2
458r = write 1 tcl2 0 len tcl2
459end
460if eq k 3
461r = write 1 tex1 0 len tex1
462end
463if eq k 4
464r = write 1 tex2 0 len tex2
465end
466if eq k 5
467r = write 1 trerr 0 len trerr
468end
469if eq k 6
470r = write 1 tderr 0 len tderr
471end
472if eq k 7
473r = write 1 tegen 0 len tegen
474end
475if eq k 8
476r = write 1 telfs 0 len telfs
477end
478if eq k 9
479r = write 1 tprcs 0 len tprcs
480end
481if eq k 10
482r = write 1 texel 0 len texel
483end
484if eq k 11
485r = write 1 texpr 0 len texpr
486end
487if eq k 12
488r = write 1 txcr 0 len txcr
489end
490wnum v
491r = write 1 tnl 0 1
492end
493
494fn main to int
495if lt argcnt 2
496r = write 2 tuse 0 len tuse
497ret 64
498end
499n = argread 1 omcp 0 4095
500if lt n 1
501r = write 2 tuse 0 len tuse
502ret 64
503end
504put omcl 0 ulong n
505pick 19
506r = makedir arg 0 get argl 0 493
507if not compile 2 5
508r = write 2 tnot 0 len tnot
509ret 3
510end
511if not loadpin
512r = write 2 tnot 0 len tnot
513ret 3
514end
515if not hashomc
516r = write 2 tnot 0 len tnot
517ret 3
518end
519if not pinok
520r = write 2 tnot 0 len tnot
521ret 3
522end
523if not compile 0 3
524r = write 2 tcf 0 len tcf
525ret 1
526end
527if not compile 1 4
528r = write 2 tcf 0 len tcf
529ret 1
530end
531if not hashto 3 17
532r = write 2 tcf 0 len tcf
533ret 1
534end
535if not buildio
536r = write 2 tcf 0 len tcf
537ret 1
538end
539if not compile 29 30
540r = write 2 tcf 0 len tcf
541ret 1
542end
543if not compile 31 32
544r = write 2 tcf 0 len tcf
545ret 1
546end
547pick 33
548r = makedir arg 0 get argl 0 493
549obs1
550a = tree
551b = clean
552c = clean2
553d = judge 13 11
554e = judge 14 12
555f = iotest 25 27
556g = iotest 26 28
557obsn 0 a
558obsn 1 b
559obsn 2 c
560obsn 3 d
561obsn 4 e
562obsn 5 f
563obsn 6 g
564y = elfstage
565if not y
566ret 1
567end
568if ne a 1
569ret 1
570end
571if ne b 0
572ret 1
573end
574if ne c 1
575ret 1
576end
577if ne d 0
578ret 1
579end
580if ne e 0
581ret 1
582end
583if ne f 0
584ret 1
585end
586if ne g 0
587ret 1
588end
589ret 0
590end