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 / name-check / gate.om

458 lines · 8023 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note gate: the ARCH-NAME-CHECK gate runner (ADR 0038), seeded native Omega.
3note usage: gate OMC DIFF (run from tools/name-check; writes under build/)
4note Builds ../zero-legacy/sha256.om with OMC, hashes OMC with it and compares the hash with
5note ../zero-legacy/omega.pin, builds namecheck.om, then runs build/namecheck on six fixtures
6note (red 1, green 0, long 1, refuse 2, nohdr 2, pathmax 2: the exit, and stdout exactly the .out
7note file), counts those that pass, and finally runs it on DIFF, the added lines of the
8note change under review, with this process's stdout. Exit: 0 PASS; 1 a fixture differs, a build
9note fails or DIFF names a retired word; 2 DIFF unreadable; 3 OMC missing or not the pinned
10note compiler (NOT_RUN). The process helpers below are copied unchanged from ../doctrine/gate.om.
11
12text tbl "../zero-legacy/sha256.om\nbuild/sha256\nnamecheck.om\nbuild/namecheck\nbuild/omc.sha\nbuild/namecheck.sha\n../zero-legacy/omega.pin\nbuild\nfixtures/red.diff\nbuild/red.out\nfixtures/red.out\nfixtures/green.diff\nbuild/green.out\nfixtures/green.out\nfixtures/long.diff\nbuild/long.out\nfixtures/long.out\nfixtures/refuse.diff\nbuild/refuse.out\nfixtures/refuse.out\nfixtures/nohdr.diff\nbuild/nohdr.out\nfixtures/nohdr.out\nfixtures/pathmax.diff\nbuild/pathmax.out\nfixtures/pathmax.out\n"
13text tobs "AIEN-OBS "
14text tsha "name_check_sha256 \""
15text tq "\"\n"
16text texit "name_check_exit "
17text tfx "name_check_fixtures "
18text tnl "\n"
19text tuse "usage: gate OMC DIFF\n"
20text tnot "gate: OMC missing or not the pinned compiler (NOT_RUN)\n"
21text tcf "gate: compile failed\n"
22text tfxf "gate: a name-check fixture gave another exit or other output (FAIL)\n"
23text tkey "omc_sha256: "
24
25global omcp uchar 4096
26global omcl ulong 1
27global rootp uchar 4096
28global rootl ulong 1
29global pk uchar 4096
30global pkn ulong 1
31global pkc ulong 1
32global arg uchar 4096
33global argl ulong 1
34global fin uchar 4096
35global finl ulong 1
36global fout uchar 256
37global foutl ulong 1
38global status uchar 4
39global pin uchar 4096
40global pinl ulong 1
41global sha uchar 128
42global nb uchar 24
43global fa uchar 65536
44global fb uchar 65536
45global fxn ulong 1
46
47note ---- text table ----
48
49fn pick i ulong to void
50s = ulong 0
51k = ulong 0
52while lt k i bound 4096
53if eq get tbl s 10
54k = add k 1
55end
56s = add s 1
57end
58n = ulong 0
59while ne get tbl add s n 10 bound 256
60put arg n get tbl add s n
61n = add n 1
62end
63put argl 0 n
64end
65
66note ---- packets for execprog ----
67
68fn pk0 to void
69put pkn 0 2
70put pkc 0 0
71end
72
73fn pka to void
74n = get pkn 0
75m = get argl 0
76put pk n uchar rem m 256
77put pk add n 1 uchar div m 256
78for i ulong m
79put pk add n add 2 i get arg i
80end
81put pkn 0 add n add 2 m
82c = add get pkc 0 1
83put pkc 0 c
84put pk 0 uchar rem c 256
85put pk 1 uchar div c 256
86end
87
88fn pkt i ulong to void
89pick i
90pka
91end
92
93fn pkomc to void
94for i ulong get omcl 0
95put arg i get omcp i
96end
97put argl 0 get omcl 0
98pka
99end
100
101fn pkroot to void
102for i ulong get rootl 0
103put arg i get rootp i
104end
105put argl 0 get rootl 0
106pka
107end
108
109fn setin i ulong to void
110pick i
111for j ulong get argl 0
112put fin j get arg j
113end
114put finl 0 get argl 0
115end
116
117fn setout i ulong to void
118pick i
119for j ulong get argl 0
120put fout j get arg j
121end
122put foutl 0 get argl 0
123end
124
125fn noio to void
126put finl 0 0
127put foutl 0 0
128end
129
130note ---- run the packet; stdin/stdout redirected when set; returns exit code or -1 ----
131
132fn child to void
133if gt get finl 0 0
134fd = fopen fin 0 get finl 0 0 0
135if lt fd 0
136exit 126
137end
138r = dupfd int fd 0 0
139end
140if gt get foutl 0 0
141fd = fopen fout 0 get foutl 0 577 420
142if lt fd 0
143exit 126
144end
145r = dupfd int fd 1 0
146end
147r = execprog pk 0 get pkn 0
148exit 127
149end
150
151fn run to long
152pid = fork
153if lt pid 0
154ret -1
155end
156if eq pid 0
157child
158end
159r = waitpid int pid status 0 4 0
160if ne r pid
161ret -1
162end
163if ne get status 0 0
164ret -1
165end
166ret long get status 1
167end
168
169note ---- steps ----
170
171fn compile src ulong dst ulong to bool
172pk0
173pkomc
174setin src
175setout dst
176r = run
177if ne r 0
178ret false
179end
180pick dst
181r = chmod arg 0 get argl 0 493
182ret eq r 0
183end
184
185note hash the file named by table entry f into table entry out; read 64 hex into sha
186fn hashto f ulong out ulong to bool
187pk0
188pkt 1
189pkt f
190put finl 0 0
191setout out
192r = run
193if ne r 0
194ret false
195end
196ret readsha out
197end
198
199fn hashomc to bool
200pk0
201pkt 1
202pkomc
203put finl 0 0
204setout 4
205r = run
206if ne r 0
207ret false
208end
209ret readsha 4
210end
211
212fn readsha out ulong to bool
213pick out
214fd = fopen arg 0 get argl 0 0 0
215if lt fd 0
216ret false
217end
218r = read int fd sha 0 128
219c = fclose int fd
220ret ge r 64
221end
222
223fn loadpin to bool
224pick 6
225fd = fopen arg 0 get argl 0 0 0
226if lt fd 0
227ret false
228end
229r = read int fd pin 0 4096
230c = fclose int fd
231if le r 0
232ret false
233end
234put pinl 0 ulong r
235ret true
236end
237
238note does sha[0..64) equal the 64 bytes after "omc_sha256: " in the pin
239fn pinok to bool
240n = get pinl 0
241m = len tkey
242if lt n add m 64
243ret false
244end
245e = sub n add m 64
246i = ulong 0
247while le i e bound 4096
248j = ulong 0
249while lt j m bound 16
250if ne get pin add i j get tkey j
251break
252end
253j = add j 1
254end
255if eq j m
256ret same add i m
257end
258i = add i 1
259end
260ret false
261end
262
263fn same p ulong to bool
264for j ulong 64
265if ne get pin add p j get sha j
266ret false
267end
268end
269ret true
270end
271
272note ---- output ----
273
274fn wnum v long to void
275if lt v 0
276put nb 22 45
277put nb 23 49
278r = write 1 nb 22 2
279ret
280end
281x = ulong v
282n = ulong 0
283if eq x 0
284put nb 23 48
285n = 1
286end
287while gt x 0 bound 20
288put nb sub 23 n uchar add 48 rem x 10
289x = div x 10
290n = add n 1
291end
292r = write 1 nb sub 24 n n
293end
294
295fn obs1 to void
296r = write 1 tobs 0 len tobs
297r = write 1 tsha 0 len tsha
298r = write 1 sha 0 64
299r = write 1 tq 0 len tq
300end
301
302fn obs2 v long to void
303r = write 1 tobs 0 len tobs
304r = write 1 texit 0 len texit
305wnum v
306r = write 1 tnl 0 1
307end
308
309note ---- name-check steps ----
310
311note read table entry f into fa (which 0) or fb (which 1); returns the byte count, or -1
312fn slurp f ulong which ulong to long
313pick f
314fd = fopen arg 0 get argl 0 0 0
315if lt fd 0
316ret -1
317end
318r = long 0
319if eq which 0
320r = read int fd fa 0 65536
321else
322r = read int fd fb 0 65536
323end
324c = fclose int fd
325ret r
326end
327
328note do files a and b (table entries) hold the same bytes (each under 65536 bytes)
329fn sameb a ulong b ulong to bool
330na = slurp a 0
331nb2 = slurp b 1
332if or lt na 0 lt nb2 0
333ret false
334end
335if ne na nb2
336ret false
337end
338if ge na 65536
339ret false
340end
341n = ulong na
342i = ulong 0
343while lt i n bound 65536
344if ne get fa i get fb i
345ret false
346end
347i = add i 1
348end
349ret true
350end
351
352note run build/namecheck with stdin table entry src and stdout table entry dst; want its exit
353fn fixture src ulong dst ulong want long to bool
354pk0
355pkt 3
356setin src
357setout dst
358r = run
359ret eq r want
360end
361
362note build/namecheck < DIFF (the path in rootp), stdout inherited
363fn rundiff to long
364pk0
365pkt 3
366j = ulong 0
367while lt j get rootl 0 bound 4096
368put fin j get rootp j
369j = add j 1
370end
371put finl 0 get rootl 0
372put foutl 0 0
373ret run
374end
375
376note fixture t: table entries t (input), t+1 (build output), t+2 (recorded output); want its exit
377fn fxcase t ulong want long to bool
378ok = fixture t add t 1 want
379if not ok
380ret false
381end
382if not sameb add t 1 add t 2
383ret false
384end
385put fxn 0 add get fxn 0 1
386ret true
387end
388
389fn obs3 to void
390r = write 1 tobs 0 len tobs
391r = write 1 tfx 0 len tfx
392wnum long get fxn 0
393r = write 1 tnl 0 1
394end
395
396fn main to int
397if lt argcnt 3
398r = write 2 tuse 0 len tuse
399ret 64
400end
401n = argread 1 omcp 0 4095
402if lt n 1
403r = write 2 tuse 0 len tuse
404ret 64
405end
406put omcl 0 ulong n
407n = argread 2 rootp 0 4095
408if lt n 1
409r = write 2 tuse 0 len tuse
410ret 64
411end
412put rootl 0 ulong n
413pick 7
414r = makedir arg 0 get argl 0 493
415if not compile 0 1
416r = write 2 tnot 0 len tnot
417ret 3
418end
419if not loadpin
420r = write 2 tnot 0 len tnot
421ret 3
422end
423if not hashomc
424r = write 2 tnot 0 len tnot
425ret 3
426end
427if not pinok
428r = write 2 tnot 0 len tnot
429ret 3
430end
431if not compile 2 3
432r = write 2 tcf 0 len tcf
433ret 1
434end
435if not hashto 3 5
436r = write 2 tcf 0 len tcf
437ret 1
438end
439obs1
440ok1 = fxcase 8 1
441ok2 = fxcase 11 0
442ok3 = fxcase 14 1
443ok4 = fxcase 17 2
444ok5 = fxcase 20 2
445ok6 = fxcase 23 2
446if ne get fxn 0 6
447obs3
448r = write 2 tfxf 0 len tfxf
449ret 1
450end
451obs3
452e = rundiff
453obs2 e
454if lt e 0
455ret 1
456end
457ret int e
458end