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

709 lines · 15449 bytes Raw Blame History
1note Omega Node durable scheduling-policy replay (DRA-398). Concatenate
2note after transport.om, pool.om, super.om, sched.om,
3note seed/authority/action.om, journal.om and auth.om.
4note A reference creator R runs 10 dispatch events on journal a. A creator
5note C runs the same first k events on journal b and dies (77); C2
6note recovers journal b and runs the remaining events. Each event resumes
7note dispatch once (auth_pause false, then true), then lets every assigned
8note job finish and releases them in slot order, so each event ends at a
9note quiescent point. Trace record per event (10 words): 0, 1 the ids
10note assigned, 2 cursor, 3 reserved job id, 4 fold of (slot, id, bypass
11note count) over ready jobs, 5 policy words (with the ticket lifetime), 6
12note fold of (id, need, estimate, uncertainty, topics) over waiting and
13note ready jobs, 7 capacities, 8 sum of the ready jobs' bypass counts, 9
14note state and bypass count of job 7001. C2's state right after recovery
15note must equal R's after event k (words 2..9), and the C and C2 trace
16note must equal R's.
17note Jobs: 14 ready jobs needing 1..3 of 4 CPU, two workers, window 4,
18note dispatch budget 2, bypass budget 2, ticket lifetime 777, and job 7001
19note (3 CPU) waiting on topic 8, which the creator publishes before event
20note 1 (39 if refused), so it is ready, by publication, across the crash.
21note Policy 2 adds three waiting jobs, declared topics, estimates and
22note uncertainties (one on a waiting job).
23note Exits: 10..22 creator checks; per case base b: b R failed, b+1 C did
24note not stop at 77, b+2 C2 failed, b+3 recovered state differs, b+4 traces
25note differ, b+5 the case would not test replay (no bypass count, a zero
26note cursor or job 7001 not ready at the boundary, or no reservation in
27note the run), b+6 C3, which
28note recovers journal b again after C2, differs from R's final state (or R's
29note final cursor equals its boundary cursor, so the check would not see
30note C2's FAIR records missing). Mid-event crash
31note (90): C' dies right after a dispatch and its PAUSE, before the creator
32note collects or releases the jobs it assigned; C2' must see the cursor, reservation and bypass counts of the
33note jobs that were not assigned (93; 95 nothing assigned or bypassed, or
34note the event moved neither cursor nor reservation, so losing its FAIR
35note would go unseen). Records refused (96 a FAIR that repeats the last
36note event, 97 a FAIR naming a free slot, 98 an OPEN of another SPVER, 23
37note an ADMIT into a held slot, 24 a FAIR assigning and bypassing one slot,
38note 26 a FAIR assigning a waiting job, 27 a readiness record for a ready
39note job (and a valid one at the last event refused), 25 a FAIR reserving
40note a cancelled job, 28 a first FAIR that both assigns and readies).
41note Failed journal (40..43): revoke, pause, cancel,
42note admission, policy and goal change nothing. 44: a full replay ring
43note stops dispatch; 47: and refuses publication. 29: recovery refuses a
44note fence past the incarnation range.
45text rpja "build/node/rpa/journal"
46text rpla "build/node/rpa/lock"
47text rpjb "build/node/rpb/journal"
48text rplb "build/node/rpb/lock"
49text rpda "build/node/rpa"
50text rpdb "build/node/rpb"
51text rpok "PASS node replay\n"
52global rpm long 1
53global rpp uchar 128
54
55fn rp_ok ok bool code int to void
56if not ok
57exit code
58end
59end
60
61note Path k (0 journal a, 1 lock a, 2 journal b, 3 lock b, 4 dir a, 5 dir
62note b) into rpp; its length.
63fn rp_path k ulong to ulong
64n = ulong 0
65if eq k 0
66n = len rpja
67for i ulong n bound 64
68put rpp i get rpja i
69end
70end
71if eq k 1
72n = len rpla
73for i ulong n bound 64
74put rpp i get rpla i
75end
76end
77if eq k 2
78n = len rpjb
79for i ulong n bound 64
80put rpp i get rpjb i
81end
82end
83if eq k 3
84n = len rplb
85for i ulong n bound 64
86put rpp i get rplb i
87end
88end
89if eq k 4
90n = len rpda
91for i ulong n bound 64
92put rpp i get rpda i
93end
94end
95if eq k 5
96n = len rpdb
97for i ulong n bound 64
98put rpp i get rpdb i
99end
100end
101ret n
102end
103
104fn rp_clean to void
105for k ulong 4
106n = rp_path k
107r = unlink rpp 0 n
108end
109end
110
111fn rp_open d ulong ms ulong to ulong
112o = new ulong 4 0
113put o 0 398
114put o 1 7
115put o 2 7
116put o 3 7
117n = rp_path add d 4
118p = new uchar 128 0
119for i ulong n bound 128
120put p i get rpp i
121end
122ret jn_open p n o ms
123end
124
125note The CPU job i (0..13) needs.
126fn rp_cpu i ulong to ulong
127ret add 1 rem mul i 7 3
128end
129
130fn rp_worker c long w ulong to int
131out = new uchar 4096 0
132for it ulong 1000000000
133q = sched_wjob w
134if gt q 0
135d = sched_wdone w q 2 out 0
136end
137r = auth_wwait c w neg int 1 1000000000
138if or eq r 2 eq r 3
139ret 0
140end
141if eq r 4
142t = auth_wctl w
143end
144if lt r 0
145ret 45
146end
147end
148ret 46
149end
150
151note Creator on journal d (0 a, 1 b): open it, recover, spawn two workers.
152fn rp_setup d ulong to long
153c = pool_new 4 2
154rp_ok gt c 0 10
155rp_ok eq sup_init c 0 11
156rp_ok eq sched_new c 32 8 0 12
157rp_ok eq auth_new c 0 13
158rp_ok eq rp_open d 3000 0 14
159rp_ok eq auth_recover c 0 15
160for w ulong 2
161p = auth_spawn c w
162if eq p 0
163exit rp_worker c w
164end
165rp_ok gt p 0 16
166end
167ret c
168end
169
170fn rp_slot id ulong to ulong
171for j ulong 64
172s = get sjst j
173if and eq get sjid j id and ge s 1 le s 2
174ret j
175end
176end
177ret 64
178end
179
180note A fresh creator: paused, capacities, policy, the jobs and (policy 2)
181note the waiting jobs and declarations, all journaled.
182fn rp_load c long pol ulong to void
183rp_ok ge auth_pause c true 0 17
184rp_ok eq jn_cap 4 0 17
185rp_ok eq jn_policy pol 4 2 2 777 0 17
186for i ulong 14
187rp_ok ge jn_admitr add 5000 i 0 0 rp_cpu i 0 18
188end
189rp_ok ge jn_admitr 7001 8 0 3 0 18
190if eq pol 2
191for i ulong 3
192rp_ok ge jn_admitr add 6000 i shl 1 i 0 0 0 18
193end
194rp_ok eq jn_goal rp_slot 5003 3 40 5 0 19
195rp_ok eq jn_goal rp_slot 5008 4 60 7 0 19
196rp_ok eq jn_goal rp_slot 5005 0 10 1 0 19
197rp_ok eq jn_goal rp_slot 5011 0 20 3 0 19
198rp_ok eq jn_goal rp_slot 6000 0 30 9 0 19
199end
200end
201
202fn rp_put base ulong e ulong i ulong v ulong to void
203r = mapset get rpm 0 mul add add base mul e 10 i 8 8 v
204end
205
206fn rp_get base ulong e ulong i ulong to ulong
207ret mapget get rpm 0 mul add add base mul e 10 i 8 8
208end
209
210note Step until no job runs, then release every finished one, slot order.
211fn rp_drive c long to void
212dl = add ulong monons 20000000000
213for t ulong 100000000
214r = sched_step c 5000000
215k = auth_step c
216busy = false
217for j ulong 64
218if eq get sjst j 3
219busy = true
220end
221end
222if not busy
223for j ulong 64
224if eq get sjst j 4
225rp_ok ge jn_release j 0 21
226end
227end
228ret
229end
230rp_ok lt ulong monons dl 22
231end
232end
233
234note Fold of (slot, id, bypass count) over ready jobs other than ids x, y;
235note with sum true the sum of those bypass counts instead.
236fn rp_fbyp x ulong y ulong sum bool to ulong
237h = ulong 1469598103934665603
238n = ulong 0
239for j ulong 64
240id = get sjid j
241if and eq get sjst j 2 and ne id x ne id y
242n = add n get sjbyp j
243h = mul xor h j 1099511628211
244h = mul xor h id 1099511628211
245h = mul xor h get sjbyp j 1099511628211
246end
247end
248if sum
249ret n
250end
251ret h
252end
253
254note Fold of (id, need, estimate, uncertainty, topics) over waiting and
255note ready jobs.
256fn rp_fjob to ulong
257h = ulong 1469598103934665603
258for j ulong 64
259s = get sjst j
260if and ge s 1 le s 4
261h = mul xor h get sjid j 1099511628211
262h = mul xor h get sjneed j 1099511628211
263h = mul xor h get sjest j 1099511628211
264h = mul xor h get sjunc j 1099511628211
265h = mul xor h get sjpro j 1099511628211
266end
267end
268ret h
269end
270
271note Job 7001's state and bypass count, 0 when x or y is 7001 or it is not
272note in the table.
273fn rp_dep x ulong y ulong to ulong
274if or eq x 7001 eq y 7001
275ret 0
276end
277for j ulong 64
278if and eq get sjid j 7001 ne get sjst j 0
279ret or get sjst j shl get sjbyp j 8
280end
281end
282ret 0
283end
284
285fn rp_rid to ulong
286r = sched_stat 29
287if eq r 0
288ret 0
289end
290ret get sjid sub r 1
291end
292
293note Words 2..9 of trace record e (base), x and y excluded from 4, 8, 9.
294fn rp_state base ulong e ulong x ulong y ulong to void
295rp_put base e 2 sched_stat 28
296rp_put base e 3 rp_rid
297rp_put base e 4 rp_fbyp x y false
298p = or or sched_stat 24 shl sched_stat 25 8 or shl sched_stat 26 16 shl sched_stat 27 24
299rp_put base e 5 or p shl sched_stat 31 32
300rp_put base e 6 rp_fjob
301rp_put base e 7 sched_caps
302rp_put base e 8 rp_fbyp x y true
303rp_put base e 9 rp_dep x y
304end
305
306note Resume dispatch once, pause; record the ids assigned (words 0, 1).
307fn rp_dispatch c long e ulong base ulong to void
308rp_ok ge auth_pause c false 0 20
309rp_ok ge auth_pause c true 0 20
310a0 = ulong 0
311a1 = ulong 0
312for j ulong 64
313s = get sjst j
314if and ge s 3 le s 4
315if eq a0 0
316a0 = get sjid j
317else
318a1 = get sjid j
319end
320end
321end
322rp_put base e 0 a0
323rp_put base e 1 a1
324end
325
326note Event e; before event 1 the creator publishes topic 8 (job 7001).
327fn rp_event c long e ulong base ulong to void
328pb = new uchar 4096 0
329if eq e 1
330rp_ok gt sched_publish c 8 pb 16 0 39
331end
332rp_dispatch c e base
333rp_drive c
334rp_state base e 0 0
335end
336
337fn rp_down c long to void
338r = sched_stop c 2000000000
339sup_closeall
340jn_close
341end
342
343fn rp_ref pol ulong en ulong to int
344c = rp_setup 0
345rp_load c pol
346for e ulong en
347rp_event c e 0
348end
349rp_down c
350ret 0
351end
352
353fn rp_crash pol ulong k ulong to int
354c = rp_setup 1
355rp_load c pol
356for e ulong k
357rp_event c e 1024
358end
359ret 77
360end
361
362fn rp_rec k ulong en ulong to int
363c = rp_setup 1
364rp_state 2048 0 0 0
365for e ulong sub en k
366rp_event c add k e 1024
367end
368rp_down c
369ret 0
370end
371
372note C3: recover journal b again, state at 2048 + 10.
373fn rp_again to int
374c = rp_setup 1
375rp_state 2048 1 0 0
376rp_down c
377ret 0
378end
379
380note C': k events, then one dispatch and its PAUSE, state at 3072, die.
381fn rp_mcrash pol ulong k ulong to int
382c = rp_setup 1
383rp_load c pol
384for e ulong k
385rp_event c e 1024
386end
387rp_dispatch c 0 3072
388rp_state 3072 0 rp_get 3072 0 0 rp_get 3072 0 1
389ret 77
390end
391
392note C2': recover, state at 3072 + 10 without the jobs C' assigned.
393fn rp_mrec to int
394c = rp_setup 1
395rp_state 3072 1 rp_get 3072 0 0 rp_get 3072 0 1
396rp_down c
397ret 0
398end
399
400fn rp_reap p long to ulong
401ws = new uchar 4 0
402g = waitpid int p ws 0 4 0
403if le g 0
404ret 999
405end
406if ne and get ws 0 127 0
407ret add 128 ulong and get ws 0 127
408end
409ret ulong get ws 1
410end
411
412note A child that should exit want: anything else ends the test with the
413note child's own check code (10..48, 90..99), or code.
414fn rp_child x ulong want ulong code int to void
415if ne x want
416if or and ge x 10 le x 48 and ge x 90 le x 99
417exit int x
418end
419exit code
420end
421end
422
423fn rp_zero to void
424for i ulong 4096
425r = mapset get rpm 0 mul i 8 8 0
426end
427end
428
429fn rp_case pol ulong k ulong b int to void
430en = ulong 10
431rp_zero
432rp_clean
433p = fork
434if eq p 0
435exit rp_ref pol en
436end
437rp_child rp_reap p 0 b
438p = fork
439if eq p 0
440exit rp_crash pol k
441end
442rp_child rp_reap p 77 add b 1
443p = fork
444if eq p 0
445exit rp_rec k en
446end
447rp_child rp_reap p 0 add b 2
448p = fork
449if eq p 0
450exit rp_again
451end
452rp_child rp_reap p 0 add b 6
453rp_cmp k en b
454end
455
456fn rp_cmp k ulong en ulong b int to void
457for i ulong 8
458rp_ok eq rp_get 2048 0 add i 2 rp_get 0 sub k 1 add i 2 add b 3
459end
460seen = false
461for e ulong en
462for i ulong 10
463rp_ok eq rp_get 0 e i rp_get 1024 e i add b 4
464end
465if gt rp_get 0 e 3 0
466seen = true
467end
468end
469rp_ok seen add b 5
470rp_ok gt rp_get 0 sub k 1 8 0 add b 5
471rp_ok ne rp_get 0 sub k 1 2 0 add b 5
472rp_ok eq and rp_get 0 sub k 1 9 255 2 add b 5
473for i ulong 8
474rp_ok eq rp_get 2048 1 add i 2 rp_get 0 sub en 1 add i 2 add b 6
475end
476rp_ok ne rp_get 0 sub en 1 2 rp_get 0 sub k 1 2 add b 6
477end
478
479fn rp_mid pol ulong k ulong to void
480rp_zero
481rp_clean
482p = fork
483if eq p 0
484exit rp_mcrash pol k
485end
486rp_child rp_reap p 77 91
487p = fork
488if eq p 0
489exit rp_mrec
490end
491rp_child rp_reap p 0 92
492for i ulong 8
493rp_ok eq rp_get 3072 1 add i 2 rp_get 3072 0 add i 2 93
494end
495rp_ok gt rp_get 3072 0 0 0 95
496rp_ok gt rp_get 3072 0 8 0 95
497w2 = rp_get 1024 sub k 1 2
498w3 = rp_get 1024 sub k 1 3
499rp_ok or ne rp_get 3072 0 2 w2 ne rp_get 3072 0 3 w3 95
500end
501
502note Journal b as left by the mid-event case: a FAIR repeating the last
503note event is refused (96), and one assigning a free slot (97).
504fn rp_dup to int
505rp_ok eq rp_open 1 3000 0 96
506r = new ulong 16 0
507put r 0 13
508put r 3 get jfair 0
509put r 6 get jfair 1
510rp_ok eq jn_put r 25 96
511for i ulong 16
512put r i 0
513end
514s = ulong 64
515for j ulong 64
516if eq get jsl j 0
517s = j
518end
519end
520rp_ok lt s 64 97
521put r 0 13
522put r 3 add get jfair 0 1
523put r 4 shl 1 s
524rp_ok eq jn_put r 25 97
525for i ulong 16
526put r i 0
527end
528put r 0 1
529put r 3 1
530put r 5 add SPVER 1
531rp_ok eq jn_put r 33 98
532rp_dupv
533jn_close
534ret 0
535end
536
537note A live ready job's slot (no deps, not cancelled), or 64.
538fn rp_rslot to ulong
539for s ulong 64
540x = get jsl s
541if ne x 0
542b = mul sub x 1 8
543if and eq get jjob add b 2 0 eq get jjob add b 6 0
544ret s
545end
546end
547end
548ret 64
549end
550
551fn rp_fair r edit ulong 16 ev ulong am ulong bm ulong rs ulong rd ulong to void
552for i ulong 16
553put r i 0
554end
555put r 0 13
556put r 3 ev
557put r 4 am
558put r 5 bm
559put r 6 get jfair 1
560put r 7 rs
561put r 8 rd
562end
563
564note Contradictory records are refused (23..27); valid ones still pass.
565fn rp_dupv to void
566r = new ulong 16 0
567s = rp_rslot
568rp_ok lt s 64 23
569f = ulong 64
570for j ulong 64
571if eq get jsl j 0
572f = j
573end
574end
575rp_ok lt f 64 23
576put r 0 2
577put r 3 9100
578put r 7 s
579rp_ok eq jn_put r 25 23
580e = add get jfair 0 1
581rp_fair r e shl 1 s shl 1 s 0 0
582rp_ok eq jn_put r 25 24
583for i ulong 16
584put r i 0
585end
586put r 0 2
587put r 3 9101
588put r 4 16
589put r 7 f
590rp_ok eq jn_put r 0 26
591rp_fair r e shl 1 f 0 0 0
592rp_ok eq jn_put r 25 26
593rp_fair r get jfair 0 0 0 0 shl 1 s
594rp_ok eq jn_put r 25 27
595put jfair 3 0
596rp_fair r e shl 1 s 0 0 shl 1 f
597rp_ok eq jn_put r 25 28
598rp_ok eq get jfair 3 0 28
599rp_ok eq get jrdy sub get jsl f 1 0 28
600put jfair 3 1
601rp_fair r get jfair 0 0 0 0 shl 1 f
602rp_ok eq jn_put r 0 27
603for i ulong 16
604put r i 0
605end
606put r 0 8
607put r 3 get jjob add mul sub get jsl s 1 8 1
608rp_ok eq jn_put r 0 25
609rp_fair r add get jfair 0 1 0 0 add s 1 0
610rp_ok eq jn_put r 25 25
611end
612
613note A full replay ring (64 records not yet durable) refuses dispatch (44)
614note and publication (47: job 7001 stays waiting).
615fn rp_ring to int
616c = rp_setup 0
617rp_load c 1
618put sfj 1 64
619put scpause 0 0
620x = sched_dispatch c
621rp_ok eq x 0 44
622rp_ok eq sched_stat 15 1 44
623rp_ok eq sched_stat 4 0 44
624pb = new uchar 4096 0
625rp_ok eq sched_publish c 8 pb 16 neg long 105 47
626rp_ok eq sched_stat 15 2 47
627rp_ok eq get sjst rp_slot 7001 1 47
628put sfj 1 0
629put scpause 0 1
630rp_down c
631ret 0
632end
633
634note A failed journal: nothing it refuses changes the creator (40..43).
635fn rp_fail to int
636c = rp_setup 0
637rp_load c 2
638j = rp_slot 5000
639g = get augen 0
640put jbad 0 1
641rp_ok eq auth_revoke c 0 40
642rp_ok eq get augen 0 g 40
643rp_ok eq auth_pause c false neg long 5 41
644rp_ok eq get scpause 0 1 41
645rp_ok eq auth_cancel c j neg long 5 42
646rp_ok eq get sjst j 2 42
647rp_ok eq jn_admitr 7000 0 0 1 neg long 5 43
648rp_ok eq jn_policy 1 8 2 2 1000 neg long 5 43
649rp_ok eq sched_stat 25 4 43
650rp_ok eq jn_goal j 1 99 1 neg long 5 43
651rp_ok eq get sjest j 0 43
652rp_ok eq jn_cap 8 neg long 5 43
653rp_ok eq sched_caps 4 43
654rp_down c
655ret 0
656end
657
658note Recovery fails closed past the incarnation range (29): fence 2^24 + 1,
659note which a 24-bit mask would fold onto incarnation 1, is refused and
660note leaves the scheduler unincarnated, so 2^24 - 1 is then accepted.
661fn rp_fence to int
662c = pool_new 4 2
663rp_ok gt c 0 29
664rp_ok eq sched_new c 32 8 0 29
665put jpol 0 0
666put jfence 0 16777217
667rp_ok not jn_rpol 29
668put jfence 0 16777215
669rp_ok jn_rpol 29
670ret 0
671end
672
673fn main to int
674m = mapnew neg int 1 0 32768 3 33
675rp_ok gt m 0 9
676put rpm 0 m
677rp_case 1 3 50
678rp_case 1 6 60
679rp_case 2 3 70
680rp_case 2 6 80
681rp_mid 1 3
682p = fork
683if eq p 0
684exit rp_dup
685end
686rp_child rp_reap p 0 96
687rp_clean
688p = fork
689if eq p 0
690exit rp_fail
691end
692rp_child rp_reap p 0 40
693rp_clean
694p = fork
695if eq p 0
696exit rp_ring
697end
698rp_child rp_reap p 0 44
699rp_clean
700p = fork
701if eq p 0
702exit rp_fence
703end
704rp_child rp_reap p 0 29
705if ne write 1 rpok 0 len rpok long len rpok
706ret 100
707end
708ret 0
709end