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

1450 lines · 24597 bytes Raw Blame History
1om2
2note SPDX-License-Identifier: AGPL-3.0-only
3note seed/profile/check.om: qualification for seed/profile (DRA-419 critical source profile) and the
4note profiled authority modules. Seeded Omega, program mode, Linux AArch64. It compiles and runs the
5note seeded checker (profile.om), the OM-2 conductor (seed/qualification/om2/gate.om) and the authority
6note gates with the pinned omc, and compares their results.
7note Build and run from the repository root:
8note mkdir -p build/seed && seed/out/omc < seed/profile/check.om > build/seed/profile-check
9note chmod +x build/seed/profile-check && build/seed/profile-check
10note Exit 0 PASS (last line PROFILE CHECK PASS), 1 FAIL (PROFILE CHECK FAIL failed=N, or a compile
11note failure of gate.om or profile.om), 3 NOT_RUN (no seed/out/omc, or its sha256 is not om/units.sh
12note OMC_PIN). The sha256 is FIPS 180-4 with the constants of seed/qualification/om2/fixtures.
13note Children get an empty environment (execprog); stdin and stderr are inherited unless redirected.
14note Scratch: build/seed/profile, removed and recreated on every run.
15
16text omcp "seed/out/omc"
17text units "om/units.sh"
18text pinkey "OMC_PIN="
19text kdec "seed/qualification/om2/fixtures/sha256-k.dec"
20text ivdec "seed/qualification/om2/fixtures/sha256-iv.dec"
21text bd1 "build"
22text bd2 "build/seed"
23text bdir "build/seed/profile"
24text slash "/"
25text adir "seed/authority/"
26text dotom ".om"
27text dotout ".out"
28text dnull "/dev/null"
29text mname "src"
30text gatesrc "seed/qualification/om2/gate.om"
31text profsrc "seed/profile/profile.om"
32text ngate "gate"
33text nprof "profile"
34text pcases "seed/profile/profile.cases"
35text mcases "seed/profile/mutants.cases"
36text ncases "cases"
37text nmut "mutants"
38text ncaslog "cases.log"
39text nmutlog "mutants.log"
40text nunit "unit.txt"
41text aact "seed/authority/action.om"
42text asto "seed/authority/store.om"
43text alck "seed/authority/lock.om"
44text adis "seed/authority/dispatch.om"
45text oldlock "seed/profile/cases/lock-943d955.om"
46text olddis "seed/profile/cases/dispatch-943d955.om"
47text nlkold "lock-old"
48text nlkout "lock-old.out"
49text nfold "fault-old"
50text nfout "fault-old.out"
51text faction "action.om"
52text fstore "store.om"
53text flck "lock.om"
54text fdisp "dispatch.om"
55text fdtest "dispatch-test.om"
56text fltest "lock-test.om"
57text fstest "store-test.om"
58text fotest "dispatch-order-test.om"
59text fxtest "store-exact-test.om"
60text fctest "store-cleanup-test.om"
61text fftest "dispatch-fault-test.om"
62text gdisp "dispatch-gate"
63text glock "lock-gate"
64text gstore "store-gate"
65text gorder "dispatch-order-gate"
66text gexact "store-exact-gate"
67text gclean "store-cleanup-gate"
68text gfault "dispatch-fault-gate"
69text ldisp "action.om store.om lock.om dispatch.om dispatch-test.om"
70text llock "lock.om lock-test.om"
71text lstore "store.om store-test.om"
72text lorder "action.om store.om dispatch.om dispatch-order-test.om"
73text lexact "store.om store-exact-test.om"
74text ocleanm "store-cleanup-gate.om = injected store.om store-cleanup-test.om\n"
75text bcleanm "store-cleanup-gate.om is stale against store.om store-cleanup-test.om\n"
76text ofaultm "dispatch-fault-gate.om = injected dispatch.om\n"
77text bfaultm "dispatch-fault-gate.om is stale against action.om store.om dispatch.om dispatch-fault-test.om\n"
78note store-cleanup-gate routes the store descriptor calls through the test's failure injectors:
79note the first occurrence on each line is replaced, in this order.
80text cf1 "fopen spath"
81text ct1 "cfopen"
82text cf2 "write int fd sb"
83text ct2 "cwrite int fd"
84text cf3 "fsync int fd"
85text ct3 "cfsync int fd"
86text cf4 "fclose int fd"
87text ct4 "cfclose int fd"
88text cf5 "renames spkt"
89text ct5 "crenames"
90note dispatch-fault-gate routes dispatch's actlost, actrecon and writerec results through the
91note test's injectors: whole-line replacements.
92text ff1 "err = actlost r"
93text ft1 "err = factlost r"
94text ff2 "err = actrecon r s"
95text ft2 "err = factrecon r s"
96text ff3 "err = writerec r"
97text ft3 "err = fwriterec r"
98text okp "ok "
99text badp "FAIL "
100text nl "\n"
101text nrnoomc "NOT_RUN profile: no omc at seed/out/omc\n"
102text nrpin "NOT_RUN profile: omc is not the pinned compiler "
103text nrsha "NOT_RUN profile: cannot read the SHA-256 constants in seed/qualification/om2/fixtures\n"
104text tomc "omc "
105text tgatecc "FAIL gate.om does not compile\n"
106text tprofcc "FAIL profile.om does not compile\n"
107text tprofsha "profile sha256 "
108text pass53 "OM2GATE PASS cases=53 pass=53 fail=0 invalid=0 not_run=0"
109text mut22 "OM2GATE FAIL cases=22 pass=11 fail=11 invalid=0 not_run=0"
110text vctl "VERDICT ctl-"
111text vmut "VERDICT m-"
112text spass " PASS "
113text sfail " FAIL "
114text verdict "VERDICT"
115text okcases "profile cases (53)\n"
116text bdcases "profile cases\n"
117text okmut "11 profile.om mutants killed, 11 controls pass\n"
118text bdmut "profile mutants (gate exit "
119text cpar ")\n"
120text profok "PROFILE-PASS"
121text okunit "authority unit profile\n"
122text bdunit "authority unit: "
123text teq ".om = "
124text tstale ".om is stale against "
125text tnocc " does not compile\n"
126text texit0 " exit 0: "
127text texit " exit "
128text tcolon ": "
129text oklk "pre-fix lock.om refused by lock-test (exit 1)\n"
130text bdlk "pre-fix lock.om: lock-test exit "
131text casep "case "
132text want "234578"
133text okfault "pre-fix dispatch.om fails fault cases 2 3 4 5 7 8 (79 77 78 79 77 78)\n"
134text bdfault "pre-fix dispatch.om: fault gate exit "
135text tcases " cases '"
136text tquote "'\n"
137text tpass "PROFILE CHECK PASS\n"
138text tfail "PROFILE CHECK FAIL failed="
139text dbig "FAIL check.om: input or line too large\n"
140text dproc "FAIL check.om: fork, wait or memfd failed\n"
141text dargs "FAIL check.om: path or argument capacity\n"
142text dwipe "FAIL check.om: cannot remove build/seed/profile\n"
143
144global pb uchar 4096
145global pbn ulong 1
146global av uchar 16384
147global avp ulong 1
148global avc ulong 1
149global avl ulong 1
150global fa uchar 4194304
151global fan ulong 1
152global fb uchar 4194304
153global fbn ulong 1
154global ln uchar 65536
155global lnn ulong 1
156global l2 uchar 65536
157global pin uchar 4096
158global pinn ulong 1
159global hexd uchar 64
160global kk uint 64
161global ivs uint 8
162global nums ulong 64
163global hv uint 8
164global ws uint 64
165global st uint 8
166global blk uchar 64
167global bk ulong 2
168global stb uchar 4
169global nfail ulong 1
170global wpath uchar 4096
171global dg uchar 4096
172global dgn ulong 1
173global nb uchar 32
174
175note ---- output ------------------------------------------------------------------------------
176fn say t view uchar * to void
177r = write 1 t 0 len t
178end
179
180fn num v ulong to void
181n = ulong 0
182x = v
183while true bound 32
184put nb sub 31 n uchar add rem x 10 48
185n = add n 1
186x = div x 10
187if eq x 0
188break
189end
190end
191r = write 1 nb sub 32 n n
192end
193
194fn die t view uchar * to void
195r = write 1 t 0 len t
196exit 1
197end
198
199fn okh to void
200say okp
201end
202
203fn badh to void
204put nfail 0 add get nfail 0 1
205say badp
206end
207
208note ---- paths and argument lists -----------------------------------------------------------
209fn pclear to void
210put pbn 0 0
211end
212
213fn pcat t view uchar * to void
214p = get pbn 0
215n = len t
216if gt add p n 4095
217die dargs
218end
219for i ulong n
220put pb add p i get t i
221end
222put pbn 0 add p n
223end
224
225note pb = build/seed/profile/NAME
226fn bpath t view uchar * to void
227pclear
228pcat bdir
229pcat slash
230pcat t
231end
232
233fn areset to void
234put avc 0 0
235put avp 0 2
236put av 0 0
237put av 1 0
238end
239
240fn afix to void
241p = get avp 0
242q = get avl 0
243m = sub sub p q 2
244if gt m 65535
245die dargs
246end
247put av q uchar and m 255
248put av add q 1 uchar shr m 8
249end
250
251note start a new argument record
252fn anew to void
253p = get avp 0
254if gt add p 2 len av
255die dargs
256end
257put avl 0 p
258put avp 0 add p 2
259c = add get avc 0 1
260put avc 0 c
261put av 0 uchar and c 255
262put av 1 uchar shr c 8
263afix
264end
265
266fn amore t view uchar * to void
267p = get avp 0
268n = len t
269if gt add p n len av
270die dargs
271end
272for i ulong n
273put av add p i get t i
274end
275put avp 0 add p n
276afix
277end
278
279fn apin to void
280p = get avp 0
281n = get pinn 0
282if gt add p n len av
283die dargs
284end
285for i ulong n
286put av add p i get pin i
287end
288put avp 0 add p n
289afix
290end
291
292note argv[0] = build/seed/profile/NAME
293fn abin t view uchar * to void
294areset
295anew
296amore bdir
297amore slash
298amore t
299end
300
301note ---- children ---------------------------------------------------------------------------
302note run the argument list; a negative descriptor is inherited. Shell-style status: the exit status,
303note 128 + signal for a signalled child, 127 when the program is missing, 126 when it cannot run.
304fn spawn fi int fo int fe int ss bool to ulong
305pid = fork
306if lt pid 0
307die dproc
308end
309if eq pid 0
310if ge fi 0
311r = dupfd fi 0 0
312end
313if ge fo 0
314r = dupfd fo 1 0
315end
316if ge fe 0
317r = dupfd fe 2 0
318end
319if ss
320r = setsid
321end
322r = execprog av 0 get avp 0
323if eq r -2
324exit 127
325end
326exit 126
327end
328r = waitpid int pid stb 0 4 0
329if ne r pid
330die dproc
331end
332sg = and ulong get stb 0 127
333if eq sg 0
334ret ulong get stb 1
335end
336ret add sg 128
337end
338
339fn opr to long
340ret fopen pb 0 get pbn 0 0 0
341end
342
343fn opw to long
344ret fopen pb 0 get pbn 0 577 420
345end
346
347fn fclo fd long to void
348if ge fd 0
349r = fclose int fd
350end
351end
352
353note run the argument list with stdout to the file pb (stderr too when both), stdin /dev/null when
354note nul, in a new session when ss; status 1 when the output file cannot be created
355fn runpb nul bool both bool ss bool to ulong
356ofd = opw
357if lt ofd 0
358ret 1
359end
360ifd = long -1
361if nul
362ifd = fopen dnull 0 len dnull 0 0
363end
364efd = long -1
365if both
366efd = ofd
367end
368s = spawn int ifd int ofd int efd ss
369fclo ifd
370fclo ofd
371ret s
372end
373
374note compile the source on descriptor sfd with the pinned omc into build/seed/profile/NAME; on
375note exit 0 the output is made executable (0755)
376fn compfd sfd long t view uchar * to ulong
377if lt sfd 0
378ret 1
379end
380bpath t
381ofd = opw
382if lt ofd 0
383fclo sfd
384ret 1
385end
386areset
387anew
388amore omcp
389s = spawn int sfd int ofd -1 false
390fclo sfd
391fclo ofd
392if eq s 0
393r = chmod pb 0 get pbn 0 493
394end
395ret s
396end
397
398fn comptx src view uchar * t view uchar * to ulong
399pclear
400pcat src
401fd = opr
402ret compfd fd t
403end
404
405note a memfd holding fa, positioned at 0
406fn famem to long
407fd = memfd mname 0 len mname 0
408if lt fd 0
409die dproc
410end
411n = get fan 0
412o = ulong 0
413while lt o n bound 4194304
414r = write int fd fa o sub n o
415if le r 0
416die dproc
417end
418o = add o ulong r
419end
420r = fseek int fd 0 0
421if ne r 0
422die dproc
423end
424ret fd
425end
426
427note ---- files ------------------------------------------------------------------------------
428note fb = the bytes of the file pb; false when it cannot be read
429fn rdb to bool
430put fbn 0 0
431fd = opr
432if lt fd 0
433ret false
434end
435n = ulong 0
436while true bound 4194305
437if eq n len fb
438die dbig
439end
440r = read int fd fb n sub len fb n
441if lt r 0
442fclo fd
443put fbn 0 n
444ret false
445end
446if eq r 0
447break
448end
449n = add n ulong r
450end
451fclo fd
452put fbn 0 n
453ret true
454end
455
456note append the bytes of the file pb to fa (cat: an unreadable file adds nothing)
457fn rda to void
458fd = opr
459if lt fd 0
460ret
461end
462n = get fan 0
463while true bound 4194305
464if eq n len fa
465die dbig
466end
467r = read int fd fa n sub len fa n
468if le r 0
469break
470end
471n = add n ulong r
472end
473fclo fd
474put fan 0 n
475end
476
477fn cata t view uchar * to void
478pclear
479pcat t
480rda
481end
482
483fn cats t view uchar * to void
484pclear
485pcat adir
486pcat t
487rda
488end
489
490note fa equals fb
491fn sameab to bool
492n = get fan 0
493if ne n get fbn 0
494ret false
495end
496i = ulong 0
497while lt i n bound 4194304
498if ne get fa i get fb i
499ret false
500end
501i = add i 1
502end
503ret true
504end
505
506fn faputb b uchar to void
507n = get fan 0
508if ge n len fa
509die dbig
510end
511put fa n b
512put fan 0 add n 1
513end
514
515note ---- lines of fb ------------------------------------------------------------------------
516note index of the next newline at or after s, or the end of fb
517fn lend s ulong to ulong
518n = get fbn 0
519e = s
520while lt e n bound 4194305
521if eq get fb e 10
522ret e
523end
524e = add e 1
525end
526ret n
527end
528
529fn eqat p ulong t view uchar * to bool
530if gt add p len t get fbn 0
531ret false
532end
533for i ulong len t
534if ne get fb add p i get t i
535ret false
536end
537end
538ret true
539end
540
541note grep -qx: some line of fb equals t
542fn hasline t view uchar * to bool
543n = get fbn 0
544s = ulong 0
545while lt s n bound 4194305
546e = lend s
547if eq sub e s len t
548if eqat s t
549ret true
550end
551end
552s = add e 1
553end
554ret false
555end
556
557fn hasin s ulong e ulong t view uchar * to bool
558p = s
559while le add p len t e bound 4194305
560if eqat p t
561ret true
562end
563p = add p 1
564end
565ret false
566end
567
568fn isnm c uchar to bool
569if and ge c 97 le c 122
570ret true
571end
572if and ge c 48 le c 57
573ret true
574end
575ret eq c 45
576end
577
578note does line [s, e) match ^PRE[a-z0-9-]*SUF
579fn verok s ulong e ulong pre view uchar * suf view uchar * to bool
580if gt add s len pre e
581ret false
582end
583if eqat s pre
584p = add s len pre
585while lt p e bound 4194305
586if isnm get fb p
587p = add p 1
588else
589break
590end
591end
592if gt add p len suf e
593ret false
594end
595ret eqat p suf
596end
597ret false
598end
599
600note grep -c '^PRE[a-z0-9-]*SUF' over fb
601fn cntver pre view uchar * suf view uchar * to ulong
602n = get fbn 0
603c = ulong 0
604s = ulong 0
605while lt s n bound 4194305
606e = lend s
607if verok s e pre suf
608c = add c 1
609end
610s = add e 1
611end
612ret c
613end
614
615note grep -v ' PASS ' | grep '^VERDICT' over fb
616fn badver to void
617n = get fbn 0
618s = ulong 0
619while lt s n bound 4194305
620e = lend s
621if eqat s verdict
622if hasin s e spass
623else
624r = write 1 fb s sub e s
625say nl
626end
627end
628s = add e 1
629end
630end
631
632note tail -1 of fb: raw keeps the final newline; otherwise as $(tail -1)
633fn tailln raw bool to void
634n = get fbn 0
635k = n
636if gt n 0
637if eq get fb sub n 1 10
638k = sub n 1
639end
640end
641s = k
642while gt s 0 bound 4194305
643if eq get fb sub s 1 10
644break
645end
646s = sub s 1
647end
648if raw
649r = write 1 fb s sub n s
650else
651r = write 1 fb s sub k s
652end
653end
654
655note $(cat): fb without its trailing newlines
656fn catstr to void
657n = get fbn 0
658while gt n 0 bound 4194305
659if ne get fb sub n 1 10
660break
661end
662n = sub n 1
663end
664r = write 1 fb 0 n
665end
666
667note ---- line rewriting (fb to fa) ----------------------------------------------------------
668fn lnat p ulong t view uchar * to bool
669if gt add p len t get lnn 0
670ret false
671end
672for i ulong len t
673if ne get ln add p i get t i
674ret false
675end
676end
677ret true
678end
679
680note ln[p .. p+fl) becomes t
681fn splice p ulong fl ulong t view uchar * to void
682r = add p fl
683k = sub get lnn 0 r
684q = add p len t
685if gt add q k len ln
686die dbig
687end
688for i ulong k
689put l2 i get ln add r i
690end
691for i ulong len t
692put ln add p i get t i
693end
694for i ulong k
695put ln add q i get l2 i
696end
697put lnn 0 add q k
698end
699
700note sed s/F/T/: the first occurrence of f in ln becomes t
701fn subst f view uchar * t view uchar * to void
702n = get lnn 0
703p = ulong 0
704while le add p len f n bound 65537
705if lnat p f
706splice p len f t
707ret
708end
709p = add p 1
710end
711end
712
713note sed s/^F$/T/: a line equal to f becomes t
714fn wsub f view uchar * t view uchar * to void
715if eq get lnn 0 len f
716if lnat 0 f
717for i ulong len t
718put ln i get t i
719end
720put lnn 0 len t
721end
722end
723end
724
725note fa += fb with mode 1 the store-cleanup injection, mode 2 the dispatch-fault injection
726fn xform mode ulong to void
727n = get fbn 0
728s = ulong 0
729while lt s n bound 4194305
730e = lend s
731k = sub e s
732if gt k len ln
733die dbig
734end
735for i ulong k
736put ln i get fb add s i
737end
738put lnn 0 k
739if eq mode 1
740subst cf1 ct1
741subst cf2 ct2
742subst cf3 ct3
743subst cf4 ct4
744subst cf5 ct5
745else
746wsub ff1 ft1
747wsub ff2 ft2
748wsub ff3 ft3
749end
750for i ulong get lnn 0
751faputb get ln i
752end
753if lt e n
754faputb 10
755end
756s = add e 1
757end
758end
759
760note fa = action.om store.om, injected D, dispatch-fault-test.om
761fn faultsrc d view uchar * to void
762put fan 0 0
763cats faction
764cats fstore
765pclear
766pcat d
767b = rdb
768xform 2
769cats fftest
770end
771
772note ---- SHA-256 (FIPS 180-4), for compiler and checker identity ----------------------------
773fn shasched to void
774for i ulong 16
775b = mul i 4
776v = shl uint get blk b 24
777v = or v shl uint get blk add b 1 16
778v = or v shl uint get blk add b 2 8
779v = or v uint get blk add b 3
780put ws i v
781end
782for j ulong 48
783q = add j 16
784x = get ws sub q 15
785y = get ws sub q 2
786s0 = xor xor rotr x 7 rotr x 18 shr x 3
787s1 = xor xor rotr y 17 rotr y 19 shr y 10
788put ws q add add add get ws sub q 16 s0 get ws sub q 7 s1
789end
790end
791
792fn shat1 i ulong to uint
793e = get st 4
794s1 = xor xor rotr e 6 rotr e 11 rotr e 25
795ch = xor and e get st 5 and not e get st 6
796ret add add add add get st 7 s1 ch get kk i get ws i
797end
798
799fn shat2 to uint
800a = get st 0
801b = get st 1
802c = get st 2
803s0 = xor xor rotr a 2 rotr a 13 rotr a 22
804mj = xor xor and a b and a c and b c
805ret add s0 mj
806end
807
808fn shacomp to void
809shasched
810for i ulong 8
811put st i get hv i
812end
813for i ulong 64
814t1 = shat1 i
815t2 = shat2
816put st 7 get st 6
817put st 6 get st 5
818put st 5 get st 4
819put st 4 add get st 3 t1
820put st 3 get st 2
821put st 2 get st 1
822put st 1 get st 0
823put st 0 add t1 t2
824end
825for i ulong 8
826put hv i add get hv i get st i
827end
828end
829
830fn shabyte b uchar to void
831n = get bk 0
832put blk n b
833n = add n 1
834if eq n 64
835shacomp
836n = ulong 0
837end
838put bk 0 n
839put bk 1 add get bk 1 1
840end
841
842fn hexch v uint to uchar
843if lt v 10
844ret uchar add v 48
845end
846ret uchar add v 87
847end
848
849fn shafinal to void
850bits = mul get bk 1 8
851shabyte 128
852while ne get bk 0 56 bound 64
853shabyte 0
854end
855for i ulong 8
856shabyte uchar and shr bits mul sub 7 i 8 255
857end
858for i ulong 8
859v = get hv i
860for j ulong 8
861put hexd add mul i 8 j hexch and shr v mul sub 7 j 4 15
862end
863end
864end
865
866note hexd = sha256 of the file pb; false when it cannot be read
867fn hashpb to bool
868fd = opr
869if lt fd 0
870ret false
871end
872for i ulong 8
873put hv i get ivs i
874end
875put bk 0 0
876put bk 1 0
877while true bound 1000000000
878r = read int fd ln 0 len ln
879if lt r 0
880fclo fd
881ret false
882end
883if eq r 0
884fclo fd
885shafinal
886ret true
887end
888for i ulong ulong r
889shabyte get ln i
890end
891end
892ret false
893end
894
895note fb as WANT decimal lines, each below 2^32, into nums
896fn parsenum wn ulong to bool
897n = get fbn 0
898k = ulong 0
899v = ulong 0
900nd = ulong 0
901for i ulong n
902c = get fb i
903if and ge c 48 le c 57
904if ge nd 10
905ret false
906end
907v = add mul v 10 ulong sub c 48
908nd = add nd 1
909else
910if or ne c 10 eq nd 0
911ret false
912end
913if or ge k wn gt v 4294967295
914ret false
915end
916put nums k v
917k = add k 1
918v = ulong 0
919nd = ulong 0
920end
921end
922ret and eq k wn eq nd 0
923end
924
925fn ldconst to bool
926pclear
927pcat kdec
928if rdb
929if parsenum 64
930for i ulong 64
931put kk i uint get nums i
932end
933pclear
934pcat ivdec
935if rdb
936if parsenum 8
937for i ulong 8
938put ivs i uint get nums i
939end
940ret true
941end
942end
943end
944end
945ret false
946end
947
948note ---- pin --------------------------------------------------------------------------------
949note pin += fb[a .. e), after a newline when pin is not empty
950fn pinadd a ulong e ulong to void
951m = get pinn 0
952if gt add m add 1 sub e a len pin
953die dbig
954end
955if gt m 0
956put pin m 10
957m = add m 1
958end
959for i ulong sub e a
960put pin add m i get fb add a i
961end
962put pinn 0 add m sub e a
963end
964
965note pin = the rest of every om/units.sh line that starts with OMC_PIN=, joined by newlines
966fn ldpin to void
967put pinn 0 0
968pclear
969pcat units
970b = rdb
971n = get fbn 0
972s = ulong 0
973while lt s n bound 4194305
974e = lend s
975if eqat s pinkey
976pinadd add s len pinkey e
977end
978s = add e 1
979end
980end
981
982fn pinok to bool
983if ne get pinn 0 64
984ret false
985end
986for i ulong 64
987if ne get pin i get hexd i
988ret false
989end
990end
991ret true
992end
993
994note ---- scratch directory ------------------------------------------------------------------
995fn wname d view uchar * o ulong base ulong to ulong
996k = add o 19
997if eq get d k 46
998if eq get d add k 1 0
999ret 0
1000end
1001if eq get d add k 1 46
1002if eq get d add k 2 0
1003ret 0
1004end
1005end
1006end
1007put wpath base 47
1008p = add base 1
1009while ne get d k 0 bound 4096
1010if ge p 4095
1011die dwipe
1012end
1013put wpath p get d k
1014p = add p 1
1015k = add k 1
1016end
1017ret p
1018end
1019
1020fn wone d view uchar * o ulong base ulong depth ulong to ulong
1021rl = or ulong get d add o 16 shl ulong get d add o 17 8
1022if eq rl 0
1023die dwipe
1024end
1025q = wname d o base
1026if eq q 0
1027ret rl
1028end
1029r = unlink wpath 0 q
1030if eq r -21
1031if eq depth 0
1032die dwipe
1033end
1034wipe q sub depth 1
1035r = rmdir wpath 0 q
1036end
1037if ne r 0
1038die dwipe
1039end
1040ret rl
1041end
1042
1043fn wipe base ulong depth ulong to void
1044d = new uchar 8192 0
1045fd = fopen wpath 0 base 16384 0
1046if lt fd 0
1047die dwipe
1048end
1049while true bound 1000000
1050n = getdnts int fd d 0 len d
1051if lt n 0
1052die dwipe
1053end
1054if eq n 0
1055break
1056end
1057o = ulong 0
1058while lt o ulong n bound 8192
1059o = add o wone d o base depth
1060end
1061end
1062fclo fd
1063end
1064
1065note rm -rf build/seed/profile; mkdir -p build/seed/profile
1066fn fresh0 to void
1067n = len bdir
1068for i ulong n
1069put wpath i get bdir i
1070end
1071r = unlink wpath 0 n
1072if eq r -21
1073wipe n 16
1074r = rmdir wpath 0 n
1075end
1076if and ne r 0 ne r -2
1077die dwipe
1078end
1079r = makedir bd1 0 len bd1 511
1080r = makedir bd2 0 len bd2 511
1081r = makedir bdir 0 len bdir 511
1082end
1083
1084note ---- checks -----------------------------------------------------------------------------
1085note gate OMC PIN CASES build/seed/profile/SCRATCH > build/seed/profile/LOG; fb = LOG; gate status
1086fn rungate cases view uchar * scr view uchar * log view uchar * to ulong
1087abin ngate
1088anew
1089amore omcp
1090anew
1091apin
1092anew
1093amore cases
1094anew
1095amore bdir
1096amore slash
1097amore scr
1098bpath log
1099s = runpb false false false
1100bpath log
1101b = rdb
1102ret s
1103end
1104
1105note 1. Rule fixtures, real-module pre-fix controls, capacity and stop rows.
1106fn step1 to void
1107s = rungate pcases ncases ncaslog
1108if hasline pass53
1109okh
1110say okcases
1111else
1112badh
1113say bdcases
1114badver
1115end
1116end
1117
1118note 2. One profile.om mutant per rule: every control PASS, every kill row FAIL.
1119fn step2 to void
1120s = rungate mcases nmut nmutlog
1121g = false
1122if eq s 1
1123if hasline mut22
1124if eq cntver vctl spass 11
1125if eq cntver vmut sfail 11
1126g = true
1127end
1128end
1129end
1130end
1131if g
1132okh
1133say okmut
1134else
1135badh
1136say bdmut
1137num s
1138say cpar
1139tailln true
1140end
1141end
1142
1143note 3. The profiled modules pass the profile as one unit (dispatch is the consumer of lock and store).
1144fn step3 to void
1145abin nprof
1146anew
1147amore aact
1148anew
1149amore asto
1150anew
1151amore alck
1152anew
1153amore adis
1154bpath nunit
1155s = runpb false false false
1156bpath nunit
1157b = rdb
1158g = false
1159if eq s 0
1160if hasline profok
1161g = true
1162end
1163end
1164if g
1165okh
1166say okunit
1167else
1168badh
1169say bdunit
1170catstr
1171say nl
1172end
1173end
1174
1175note fb = seed/authority/G.om; report whether fa equals it
1176fn gatecmp g view uchar * to bool
1177pclear
1178pcat adir
1179pcat g
1180pcat dotom
1181if rdb
1182ret sameab
1183end
1184ret false
1185end
1186
1187note 4. The authority gates are the committed module text plus the test.
1188fn same g view uchar * lbl view uchar * to void
1189if gatecmp g
1190okh
1191say g
1192say teq
1193else
1194badh
1195say g
1196say tstale
1197end
1198say lbl
1199say nl
1200end
1201
1202fn step4a to void
1203put fan 0 0
1204cats faction
1205cats fstore
1206cats flck
1207cats fdisp
1208cats fdtest
1209same gdisp ldisp
1210put fan 0 0
1211cats flck
1212cats fltest
1213same glock llock
1214put fan 0 0
1215cats fstore
1216cats fstest
1217same gstore lstore
1218put fan 0 0
1219cats faction
1220cats fstore
1221cats fdisp
1222cats fotest
1223same gorder lorder
1224put fan 0 0
1225cats fstore
1226cats fxtest
1227same gexact lexact
1228end
1229
1230fn step4b to void
1231put fan 0 0
1232pclear
1233pcat asto
1234b = rdb
1235xform 1
1236cats fctest
1237if gatecmp gclean
1238okh
1239say ocleanm
1240else
1241badh
1242say bcleanm
1243end
1244faultsrc adis
1245if gatecmp gfault
1246okh
1247say ofaultm
1248else
1249badh
1250say bfaultm
1251end
1252end
1253
1254note compile seed/authority/G.om to build/seed/profile/G and run it: stdin /dev/null, stdout and
1255note stderr to build/seed/profile/G.out
1256fn rungt g view uchar * to void
1257pclear
1258pcat adir
1259pcat g
1260pcat dotom
1261fd = opr
1262s = compfd fd g
1263if ne s 0
1264badh
1265say g
1266say tnocc
1267ret
1268end
1269abin g
1270bpath g
1271pcat dotout
1272s = runpb true true false
1273bpath g
1274pcat dotout
1275b = rdb
1276if eq s 0
1277okh
1278say g
1279say texit0
1280else
1281badh
1282say g
1283say texit
1284num s
1285say tcolon
1286end
1287tailln false
1288say nl
1289end
1290
1291fn step4c to void
1292rungt gdisp
1293rungt glock
1294rungt gstore
1295rungt gorder
1296rungt gexact
1297rungt gclean
1298rungt gfault
1299end
1300
1301note the digit after every "case " in fb (grep -o 'case [0-9]' | tr -d 'case ' | tr -d '\n')
1302fn digits to void
1303n = get fbn 0
1304m = ulong 0
1305p = ulong 0
1306while lt add p 5 n bound 4194305
1307g = false
1308if eqat p casep
1309c = get fb add p 5
1310if and ge c 48 le c 57
1311g = true
1312if ge m len dg
1313die dbig
1314end
1315put dg m c
1316m = add m 1
1317end
1318end
1319if g
1320p = add p 6
1321else
1322p = add p 1
1323end
1324end
1325put dgn 0 m
1326end
1327
1328fn dgok to bool
1329if ne get dgn 0 len want
1330ret false
1331end
1332for i ulong len want
1333if ne get dg i get want i
1334ret false
1335end
1336end
1337ret true
1338end
1339
1340note 5. Negative controls: the pre-fix modules of main 943d955 fail the new regression tests.
1341note The old lock test run may signal its own process group, so it runs in a new session.
1342fn step5a to void
1343put fan 0 0
1344cata oldlock
1345cats fltest
1346fd = famem
1347s = compfd fd nlkold
1348abin nlkold
1349bpath nlkout
1350s = runpb true true true
1351if eq s 1
1352okh
1353say oklk
1354else
1355badh
1356say bdlk
1357num s
1358say nl
1359end
1360end
1361
1362fn step5b to void
1363faultsrc olddis
1364fd = famem
1365s = compfd fd nfold
1366abin nfold
1367bpath nfout
1368s = runpb true true true
1369bpath nfout
1370b = rdb
1371digits
1372g = false
1373if eq s 1
1374if dgok
1375g = true
1376end
1377end
1378if g
1379okh
1380say okfault
1381else
1382badh
1383say bdfault
1384num s
1385say tcases
1386r = write 1 dg 0 get dgn 0
1387say tquote
1388end
1389end
1390
1391fn main to int
1392ldpin
1393r = faccess omcp 0 len omcp 1
1394if ne r 0
1395say nrnoomc
1396ret 3
1397end
1398if ldconst
1399else
1400say nrsha
1401ret 3
1402end
1403pclear
1404pcat omcp
1405g = false
1406if hashpb
1407g = pinok
1408end
1409if g
1410else
1411say nrpin
1412r = write 1 pin 0 get pinn 0
1413say nl
1414ret 3
1415end
1416fresh0
1417put nfail 0 0
1418say tomc
1419r = write 1 pin 0 get pinn 0
1420say nl
1421if ne comptx gatesrc ngate 0
1422say tgatecc
1423ret 1
1424end
1425if ne comptx profsrc nprof 0
1426say tprofcc
1427ret 1
1428end
1429bpath nprof
1430g = hashpb
1431say tprofsha
1432r = write 1 hexd 0 64
1433say nl
1434step1
1435step2
1436step3
1437step4a
1438step4b
1439step4c
1440step5a
1441step5b
1442if eq get nfail 0 0
1443say tpass
1444ret 0
1445end
1446say tfail
1447num get nfail 0
1448say nl
1449ret 1
1450end