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 / node / auth-test.om

637 lines · 13586 bytes Raw Blame History
1note Concatenate after transport.om, pool.om, super.om, sched.om,
2note seed/authority/action.om and auth.om. CPU-only acceptance of DRA-288
3note with real forked workers running real child tools (/bin/sh): granted
4note and duplicate operations, stale input, forged proposals, revocation
5note before, during and after a tool, cancellation before, during, after and
6note racing a tool's exit, worker death mid-tool, pause and resume.
7note A job id is kind*1000 + op. Kind 1 runs "echo ok", kind 2 starts a
8note 30 s grandchild and prints its pid, kind 5 exits at once and leaves a
9note 1 s grandchild holding its output. Outcome 16+v reports verdict v.
10text tsh "/bin/sh"
11text tdc "-c"
12text tk1 "echo ok"
13text tk2 "/bin/sleep 30 & echo $!; wait"
14text tk5 "/bin/sleep 1 & exit 0"
15text sok "PASS node authority\n"
16text sproc "/proc/"
17text sstat "/stat"
18global atc long 1
19global atm long 1
20
21fn at_ok ok bool code int to void
22if not ok
23exit code
24end
25end
26
27note Append text k (0 tsh, 1 tdc, 2 tk1, 3 tk2, 4 tk5) to the packed list.
28fn at_arg pk edit uchar 4096 w ulong k ulong to ulong
29m = len tsh
30if eq k 1
31m = len tdc
32end
33if eq k 2
34m = len tk1
35end
36if eq k 3
37m = len tk2
38end
39if eq k 4
40m = len tk5
41end
42put pk w uchar and m 255
43put pk add w 1 uchar shr m 8
44for j ulong m bound 64
45b = get tsh 0
46if eq k 0
47b = get tsh j
48end
49if eq k 1
50b = get tdc j
51end
52if eq k 2
53b = get tk1 j
54end
55if eq k 3
56b = get tk2 j
57end
58if eq k 4
59b = get tk5 j
60end
61put pk add add w 2 j b
62end
63ret add add w 2 m
64end
65
66note Packed argv of tool kind: /bin/sh -c <script>.
67fn at_pack kind ulong pk edit uchar 4096 to ulong
68put pk 0 3
69put pk 1 0
70w = at_arg pk 2 0
71w = at_arg pk w 1
72if eq kind 2
73ret at_arg pk w 3
74end
75if eq kind 5
76ret at_arg pk w 4
77end
78ret at_arg pk w 2
79end
80
81fn at_op op edit ulong 4 n ulong to void
82put op 0 n
83put op 1 7
84put op 2 1
85put op 3 1
86end
87
88fn at_count w ulong to void
89m = get atm 0
90a = add 512 mul w 8
91r = mapset m a 8 add mapget m a 8 1
92end
93
94note Worker: propose the job's operation, wait for the decision, run the
95note tool when granted, report. Tool runs are counted in test word 512+8w.
96fn at_job c long w ulong q ulong to void
97op = new ulong 4 0
98pk = new uchar 4096 0
99out = new uchar 4096 0
100id = sc_cell w 8
101at_op op rem id 1000
102r = auth_propose w q op 1
103v = auth_wdecide c w q 30000000000
104if ne v 0
105r = sched_wdone w q add 16 ulong v out 0
106ret
107end
108pn = at_pack div id 1000 pk
109at_count w
110o = auth_wtool c w q pk pn 1
111r = auth_wreport w q ulong o
112r = sched_wdone w q ulong o out 0
113end
114
115fn at_worker w ulong to int
116c = get atc 0
117for it ulong 1000000000
118q = sched_wjob w
119if gt q 0
120at_job c w q
121end
122r = auth_wwait c w neg int 1 1000000000
123if or eq r 2 eq r 3
124ret 0
125end
126if eq r 4
127t = auth_wctl w
128end
129if lt r 0
130ret 45
131end
132end
133ret 46
134end
135
136fn at_spawn c long w ulong to bool
137p = auth_spawn c w
138if eq p 0
139exit at_worker w
140end
141ret gt p 0
142end
143
144note Pool of 4 arenas for 2 workers, admission and review limits 8, the
145note test page, authority, both workers spawned. Exits with code on refusal.
146fn at_setup code int to long
147c = pool_new 4 2
148at_ok gt c 0 code
149put atc 0 c
150m = mapnew neg int 1 0 4096 3 33
151at_ok gt m 0 code
152put atm 0 m
153at_ok eq sup_init c 0 code
154at_ok eq sched_new c 8 8 0 code
155at_ok eq auth_new c 0 code
156for w ulong 2
157at_ok at_spawn c w code
158end
159ret c
160end
161
162fn at_down c long code int to void
163at_ok ge sched_stop c 2000000000 0 code
164sup_closeall
165at_ok eq auth_free 0 code
166at_ok eq sched_free 0 code
167at_ok eq pool_free c 0 code
168at_ok eq mapdrop get atm 0 0 code
169end
170
171fn at_step c long to void
172r = sched_step c 5000000
173k = auth_step c
174end
175
176fn at_runs to ulong
177m = get atm 0
178ret add mapget m 512 8 mapget m 520 8
179end
180
181note Step creator and authority until job j is in state st, up to ms. The
182note step comes first, so reports that preceded the state are recorded.
183fn at_until c long j ulong st ulong ms ulong to bool
184dl = add ulong monons mul ms 1000000
185for t ulong 1000000
186at_step c
187if eq get sjst j st
188ret true
189end
190if ge ulong monons dl
191ret false
192end
193end
194ret false
195end
196
197note Step the scheduler only (nothing is decided) until worker w has
198note proposed assignment q, up to ms.
199fn at_prop c long w ulong q ulong ms ulong to bool
200dl = add ulong monons mul ms 1000000
201for t ulong 1000000
202if ge auth_cell w 72 q
203ret true
204end
205if ge ulong monons dl
206ret false
207end
208r = sched_step c 5000000
209end
210ret false
211end
212
213note Step creator and authority until worker w's decided seq reaches q.
214fn at_decided c long w ulong q ulong ms ulong to bool
215dl = add ulong monons mul ms 1000000
216for t ulong 1000000
217if ge auth_cell w 16 q
218ret true
219end
220if ge ulong monons dl
221ret false
222end
223at_step c
224end
225ret false
226end
227
228note Admit job id, step until it runs; its worker in test word 0 and its
229note assignment seq in word 8. Exits with code on failure.
230fn at_start c long id ulong code int to ulong
231j = sched_admit id 0 0
232at_ok ge j 0 code
233for t ulong 400
234if eq get sjst ulong j 3
235break
236end
237r = sched_step c 5000000
238end
239at_ok eq get sjst ulong j 3 code
240w = get sjw ulong j
241r = mapset get atm 0 0 8 w
242r = mapset get atm 0 8 8 sc_cell w 0
243ret ulong j
244end
245
246fn at_w to ulong
247ret mapget get atm 0 0 8
248end
249
250fn at_q to ulong
251ret mapget get atm 0 8 8
252end
253
254note The pid printed by a kind 2 tool of worker w, 0 while none.
255fn at_gpid w ulong to ulong
256b = new uchar 4096 0
257n = auth_wout w b
258v = ulong 0
259for i ulong n bound 4096
260x = get b i
261if or lt x 48 gt x 57
262ret v
263end
264v = add mul v 10 sub ulong x 48
265end
266ret 0
267end
268
269note Step until worker w's kind 2 tool has printed its grandchild's pid.
270fn at_gp c long w ulong ms ulong to ulong
271dl = add ulong monons mul ms 1000000
272for t ulong 1000000
273p = at_gpid w
274if gt p 0
275ret p
276end
277if ge ulong monons dl
278ret 0
279end
280at_step c
281end
282ret 0
283end
284
285fn at_path pid ulong p edit uchar 64 to ulong
286d = new uchar 20 0
287for i ulong 6
288put p i get sproc i
289end
290x = pid
291k = ulong 20
292for i ulong 20
293k = sub k 1
294put d k uchar add rem x 10 48
295x = div x 10
296if eq x 0
297break
298end
299end
300n = ulong 6
301for i ulong sub 20 k bound 20
302put p n get d add k i
303n = add n 1
304end
305for i ulong 5
306put p n get sstat i
307n = add n 1
308end
309ret n
310end
311
312note true while process pid exists and is neither a zombie nor dead.
313fn at_alive pid ulong to bool
314p = new uchar 64 0
315b = new uchar 512 0
316n = at_path pid p
317fd = fopen p 0 n 524288 0
318if lt fd 0
319ret false
320end
321got = read int fd b 0 511
322r = fclose int fd
323if le got 2
324ret false
325end
326rp = ulong 0
327for i ulong ulong got bound 511
328if eq get b i 41
329rp = i
330end
331end
332s = get b add rp 2
333ret and ne s 90 ne s 88
334end
335
336note Wait up to ms for pid to be gone.
337fn at_gone pid ulong ms ulong to bool
338for t ulong ms bound 100000
339if not at_alive pid
340ret true
341end
342r = sleepns 1000000
343end
344ret not at_alive pid
345end
346
347note Phase A: a granted operation is performed once; the same operation in
348note a new job is refused (7) without running its tool again.
349fn at_perform to void
350op = new ulong 4 0
351c = at_setup 10
352j = sched_admit 1001 0 0
353at_ok ge j 0 11
354at_ok at_until c ulong j 4 5000 12
355at_ok eq get sjout ulong j 2 13
356at_op op 1
357at_ok eq auth_act op 1 4 14
358at_ok eq auth_act op 2 1 15
359r = sched_review ulong j
360k = sched_admit 1001 0 0
361at_ok at_until c ulong k 4 5000 16
362at_ok eq get sjout ulong k 23 17
363at_ok eq auth_act op 2 1 18
364at_ok eq at_runs 1 19
365at_down c 20
366end
367
368note Phase B: a proposal whose dependency topic gained a newer version, or
369note whose epoch was rolled, before the decision is stale (4); a newer
370note version on an unrelated topic is not.
371fn at_stale to void
372buf = new uchar 4096 0
373op = new ulong 4 0
374c = at_setup 21
375j = sched_admit 1002 2 0
376at_ok ge j 0 22
377at_ok gt sched_publish c 2 buf 8 0 23
378w = get sjw ulong j
379at_ok at_prop c w sc_cell w 0 3000 24
380at_ok gt sched_publish c 2 buf 8 0 25
381at_ok at_until c ulong j 4 5000 26
382at_ok eq get sjout ulong j 20 27
383at_op op 2
384at_ok eq auth_act op 0 neg long 1 28
385r = sched_review ulong j
386j = sched_admit 1003 2 0
387at_ok gt sched_publish c 2 buf 8 0 29
388w = get sjw ulong j
389at_ok at_prop c w sc_cell w 0 3000 30
390at_ok gt sched_publish c 4 buf 8 0 31
391at_ok at_until c ulong j 4 5000 32
392at_ok eq get sjout ulong j 2 33
393r = sched_review ulong j
394k = at_start c 1004 34
395at_ok at_prop c at_w at_q 3000 34
396at_ok ge pool_roll c 0 35
397at_ok at_until c k 4 5000 35
398at_ok eq get sjout k 20 35
399at_down c 35
400end
401
402note Proposal word i of worker w is overwritten after it was made: a
403note proposal the worker never made.
404fn at_forge w ulong i ulong v ulong to void
405r = mapset get aumap 1 add mul w 4096 mul i 8 8 v
406end
407
408note Phase C: forged incarnation (3), job id (2) and version (1) are refused
409note and no tool runs.
410fn at_forged to void
411c = at_setup 36
412for f ulong 3
413j = at_start c add 1010 f 37
414w = at_w
415at_ok at_prop c w at_q 3000 38
416if eq f 0
417at_forge w 5 add get auinc w 1
418end
419if eq f 1
420at_forge w 2 add sc_cell w 8 1
421end
422if eq f 2
423at_forge w 0 2
424end
425at_ok at_until c j 4 5000 39
426at_ok eq get sjout j sub 19 f int add 40 f
427r = sched_review j
428end
429at_ok eq at_runs 0 44
430at_down c 45
431end
432
433note Phase D: revocation before the decision refuses the proposal (5);
434note revocation while a tool runs kills its whole process group and
435note records UNKNOWN, after which the operation is never retried (7);
436note revocation after the tool exited but before its report was recorded
437note still records it as performed.
438fn at_revoke to void
439op = new ulong 4 0
440c = at_setup 50
441j = at_start c 1020 51
442at_ok at_prop c at_w at_q 3000 51
443g = auth_revoke c
444at_ok at_until c j 4 5000 52
445at_ok eq get sjout j 21 52
446r = sched_review j
447j = at_start c 2021 53
448w = at_w
449p = at_gp c w 5000
450at_ok gt p 0 53
451at_ok at_alive p 54
452g = auth_revoke c
453at_ok at_until c j 4 5000 55
454at_ok eq get sjout j 0 56
455at_op op 21
456at_ok eq auth_act op 1 3 57
457at_ok at_gone p 3000 58
458at_ok eq auth_cell w 112 0 59
459r = sched_review j
460j = at_start c 1021 60
461at_ok at_until c j 4 5000 60
462at_ok eq get sjout j 23 61
463at_ok eq at_runs 1 62
464r = sched_review j
465j = at_start c 1022 63
466w = at_w
467at_ok at_decided c w at_q 3000 63
468at_ok eq auth_cell w 24 0 63
469dl = add ulong monons 3000000000
470for t ulong 1000000
471if or ge auth_cell w 80 at_q ge ulong monons dl
472break
473end
474r = sched_step c 5000000
475end
476at_ok ge auth_cell w 80 at_q 64
477g = auth_revoke c
478at_ok at_until c j 4 5000 65
479at_op op 22
480at_ok eq auth_act op 1 4 66
481at_ok eq get sjout j 2 67
482at_down c 68
483end
484
485note Phase E: cancel before start frees the job with no action; cancel of a
486note running tool kills its group and records UNKNOWN; cancel after the
487note result is in review changes nothing; cancel after the tool's own
488note process exited (its grandchild still holding the output) records
489note performed and still kills the leftover grandchild.
490fn at_cancel to void
491op = new ulong 4 0
492c = at_setup 70
493k = auth_pause c true
494j = sched_admit 1030 0 0
495at_ok ge j 0 71
496at_ok eq auth_cancel c ulong j 1 71
497at_ok eq get sjst ulong j 0 72
498at_op op 30
499at_ok eq auth_act op 0 neg long 1 72
500k = auth_pause c false
501i = at_start c 2031 73
502w = at_w
503p = at_gp c w 5000
504at_ok gt p 0 73
505at_ok eq auth_cancel c i 2 74
506at_ok at_until c i 4 5000 75
507at_ok eq get sjout i 0 75
508at_op op 31
509at_ok eq auth_act op 1 3 76
510at_ok at_gone p 3000 77
511r = sched_review i
512i = at_start c 1032 78
513at_ok at_until c i 4 5000 78
514at_ok eq auth_cancel c i 3 79
515at_ok eq get sjout i 2 79
516at_op op 32
517at_ok eq auth_act op 1 4 80
518r = sched_review i
519at_race c 81
520at_down c 89
521end
522
523note Kind 5: the shell exits at once, its 1 s grandchild keeps the output
524note open, the cancel lands 200 ms later.
525fn at_race c long code int to void
526op = new ulong 4 0
527i = at_start c 5033 code
528w = at_w
529at_ok at_decided c w at_q 3000 code
530dl = add ulong monons 3000000000
531for t ulong 1000000
532if or gt auth_cell w 112 0 ge ulong monons dl
533break
534end
535r = sleepns 1000000
536end
537pg = auth_cell w 112
538at_ok gt pg 0 82
539r = sleepns 200000000
540at_ok eq auth_cancel c i 2 83
541at_ok at_until c i 4 5000 84
542at_ok eq get sjout i 2 85
543at_op op 33
544at_ok eq auth_act op 1 4 86
545at_ok eq auth_cell w 96 0 87
546gone = false
547for t ulong 3000
548if eq killpid neg int pg 0 neg long 3
549gone = true
550break
551end
552r = sleepns 1000000
553end
554at_ok gone 88
555end
556
557note Phase F: a worker killed while its tool runs: the creator kills the
558note tool's process group and records UNKNOWN; the job is UNKNOWN.
559fn at_death to void
560op = new ulong 4 0
561c = at_setup 90
562i = at_start c 2040 91
563w = at_w
564p = at_gp c w 5000
565at_ok gt p 0 92
566at_ok eq killpid int get swpid w 9 0 93
567at_ok at_until c i 6 5000 94
568at_op op 40
569at_ok eq auth_act op 1 3 95
570at_ok at_gone p 3000 96
571at_ok eq auth_cell w 112 0 97
572at_down c 98
573end
574
575note Every live worker has acknowledged the latest control with paused
576note flag pv, within ms; stepping meanwhile.
577fn at_acked c long pv ulong ms ulong to bool
578dl = add ulong monons mul ms 1000000
579for t ulong 1000000
580ok = true
581for w ulong 2
582if or ne auth_cell w 64 auth_cell w 0 ne auth_cell w 104 pv
583ok = false
584end
585end
586if ok
587ret true
588end
589if ge ulong monons dl
590ret false
591end
592at_step c
593end
594ret false
595end
596
597note Phase G: pause reaches every worker through its control notification;
598note while paused a proposal is held undecided and a ready job is not
599note assigned; resume decides and assigns, and both jobs are performed.
600fn at_pausec to void
601c = at_setup 115
602j = at_start c 1050 116
603w = at_w
604q = at_q
605at_ok at_prop c w q 3000 117
606k = auth_pause c true
607at_ok at_acked c 1 1000 118
608i = sched_admit 1051 0 0
609at_ok ge i 0 119
610for t ulong 60
611at_step c
612end
613at_ok lt auth_cell w 16 q 120
614at_ok eq get sjst ulong i 2 121
615k = auth_pause c false
616at_ok at_acked c 0 1000 122
617at_ok at_until c j 4 5000 123
618at_ok eq get sjout j 2 124
619at_ok at_until c ulong i 4 5000 125
620at_ok eq get sjout ulong i 2 126
621at_ok eq at_runs 2 127
622at_down c 128
623end
624
625fn main to int
626at_perform
627at_stale
628at_forged
629at_revoke
630at_cancel
631at_death
632at_pausec
633if ne write 1 sok 0 len sok long len sok
634ret 100
635end
636ret 0
637end