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 / bench / omc_efficiency / selftest.om

1077 lines · 19552 bytes Raw Blame History
1note OMC-EFF conductor self-test (PROTOCOL.md, PROTOCOL-2.md, PROTOCOL-3.md), the Omega port of the former
2note selftest.sh. It proves the conductor's checks can fail. No measured timing value is printed: wall,
3note runtime and counter columns are only tested for presence, and runtime=123 comes from a synthetic
4note fixture program.
5note
6note selftest OMC HERE SCRATCH
7note OMC absolute path of the omc that builds the conductor, the kernels and the fixtures
8note HERE absolute path of bench/omc_efficiency
9note SCRATCH a directory that must not exist; it is created and becomes the working directory
10note
11note gcc runs as /usr/bin/gcc -B/usr/bin/ with an empty environment (execprog passes none).
12note One line per check: PASS NAME rc=N EXPECTED, FAIL NAME rc=N EXPECTED got LINE, or NOT_RUN NAME REASON.
13note Last line: SELFTEST fails=N not_run=N. Exit 0 when fails is 0, 1 otherwise, 2 for bad usage.
14note counters_nonzero is NOT_RUN when /proc/sys/kernel/perf_event_paranoid is above 2 (unprivileged perf
15note stat cannot count); NOT_RUN is reported, never counted as a pass.
16om2
17text tcond "conductor"
18text tcondom "/conductor.om"
19text tkern "/kernels/"
20text twant "/want/"
21text tom ".om"
22text tc ".c"
23text tout ".out"
24text tsrc "src/"
25text twd "want/"
26text tbo "bin/omc/"
27text tb2 "bin/cO2/"
28text tb0 "bin/cO0/"
29text tbn "bin/neg/"
30text tfib "fib"
31text tsieve "sieve"
32text tom2 "om2/"
33text tkom2 "/kernels/om2/"
34text tnull "/dev/null"
35text tcerr "child.err"
36text tparan "/proc/sys/kernel/perf_event_paranoid"
37text tdir1 "src"
38text tdir2 "want"
39text tdir3 "bin"
40text tdir4 "bin/omc"
41text tdir5 "bin/cO2"
42text tdir6 "bin/cO0"
43text tdir7 "bin/neg"
44text tdir8 "src/om2"
45text tdir9 "want/om2"
46text tdir10 "bin/omc/om2"
47text tdir11 "bin/cO2/om2"
48text tdir12 "bin/cO0/om2"
49text tdir13 "bin/neg/om2"
50text tgo2 "/usr/bin/gcc -B/usr/bin/ -O2 -static -o"
51text tgo0 "/usr/bin/gcc -B/usr/bin/ -O0 -static -o"
52text tsp " "
53text tnl "\n"
54text tq "'"
55text twrong "39088168\n"
56text tx "x"
57text frt0 "text ta \"39088169\\n\"\nfn main to int\nw = write 1 ta 0 len ta\nret 0\nend\n"
58text frtb "text ta \"39088169\\n\"\ntext tb \"12x\\n\"\nfn main to int\nw = write 1 ta 0 len ta\nv = write 2 tb 0 len tb\nret 0\nend\n"
59text frt1 "text ta \"39088169\\n\"\ntext tb \"123\\n\"\nfn main to int\nw = write 1 ta 0 len ta\nv = write 2 tb 0 len tb\nret 0\nend\n"
60text frtc "fn main to int\nx = argcnt\nif gt x 0\ntrap 5\nend\nret 0\nend\n"
61text tfxd "fx/"
62text tn0 "nort"
63text tnb "badrt"
64text tn1 "rt123"
65text tnc "crash"
66text tfibo "fib.out"
67text tkeepw "want.keep"
68text tkeep2 "cO2.keep"
69text tkeepd "cO2."
70text tkeepn "keep"
71text tP "P"
72text tT "T"
73text tH "H"
74text tfxs "fx/src.om"
75text tdirf "fx"
76text rclean "./conductor run 1 0 7 1 4 omc cO2 cO0 neg fib sieve"
77text rfib "./conductor run 1 0 7 1 4 omc cO2 cO0 neg fib"
78text rbld "./conductor build 1 0 9 @ 3 omc cO2 cO0 fib"
79text rom2 "./conductor run 1 0 7 1 4 omc cO2 cO0 neg om2/fib"
80text rusage "./conductor run 1 0"
81text rseed0 "./conductor run 1 0 0 1 4 omc cO2 cO0 neg fib"
82text fok "ok.raw"
83text fnc1 "nc1.raw"
84text fnc2 "nc2.raw"
85text fnc3 "nc3.raw"
86text fb "b.raw"
87text fnc4 "nc4.raw"
88text fnc5 "nc5.raw"
89text fok2 "ok2.raw"
90text fnc6 "nc6.raw"
91text fnc7 "nc7.raw"
92text fom2 "om2.raw"
93text fnull "/dev/null"
94text n1 "clean_run"
95text n2 "counters_nonzero"
96text n3 "runtime_present"
97text n4 "wrong_want"
98text n5 "control_matches"
99text n6 "wrong_reference"
100text n7 "clean_build"
101text n8 "no_runtime_line"
102text n9 "bad_runtime_line"
103text n10 "runtime_read_exactly"
104text n11 "control_same_output_no_runtime_line"
105text n12 "control_crashes"
106text n13 "om2_profile_rows"
107text n14 "om2_source_compiled"
108text n15 "usage"
109text n16 "seed_zero"
110text n17 "counters_flag"
111text tS "S rows="
112text tok " ok="
113text tfail " fail="
114text tdet " ctl_detected="
115text tmiss " ctl_missed="
116text tzr "zero_rows="
117text tbt "bad_T_rows="
118text trt " runtime="
119text tunl " unlabelled="
120text tdiff "om2_bytes=differs"
121text tsame "om2_bytes=same"
122text tcon "counters=on"
123text tcoff "counters=off"
124text tpass "PASS "
125text tfl "FAIL "
126text tnr "NOT_RUN "
127text tparn " perf_event_paranoid>2"
128text trc " rc="
129text tgot " got "
130text tend "SELFTEST fails="
131text tnrun " not_run="
132text tneg "neg"
133text tcO2 "cO2"
134text tone "1"
135text tzero "0"
136text tofib "om2/fib"
137text tusg "usage: selftest OMC HERE SCRATCH (absolute OMC and HERE; SCRATCH must not exist)\n"
138text tsetup "selftest: setup step failed: "
139note gpb: path or argument being built; gin/gou: the child's stdin and stdout paths; gpk: exec packet;
140note glb: output line; gex: expected text of the current check; gfb, gf2: whole files
141global gpb uchar 4096
142global gpbn ulong 1
143global gin uchar 4096
144global ginn ulong 1
145global gou uchar 4096
146global goun ulong 1
147global gpk uchar 8192
148global gpkn ulong 1
149global gpkc ulong 1
150global glb uchar 4096
151global glbn ulong 1
152global gex uchar 1024
153global gexn ulong 1
154global gfb uchar 4194304
155global gf2 uchar 4194304
156global gst uchar 4
157global gcnt ulong 5
158note gcnt: 0 fails, 1 not_run, 2 counters on (1) / off (0), 3 bytes held by cpfrom, 4 exit code chk expects
159
160note ---- path builder
161fn pbclr to void
162put gpbn 0 0
163end
164fn pbtext t view uchar * to void
165n = get gpbn 0
166if gt add n len t 4096
167trap 9
168end
169for i ulong len t
170put gpb add n i get t i
171end
172put gpbn 0 add n len t
173end
174fn pbarg idx ulong to void
175n = get gpbn 0
176r = argread idx gpb n sub 4096 n
177if lt r 0
178trap 9
179end
180put gpbn 0 add n ulong r
181end
182fn pbset t view uchar * to void
183pbclr
184pbtext t
185end
186note copy gpb into gin (stdin path) or gou (stdout path)
187fn setin to void
188n = get gpbn 0
189for i ulong n
190put gin i get gpb i
191end
192put ginn 0 n
193end
194fn setout to void
195n = get gpbn 0
196for i ulong n
197put gou i get gpb i
198end
199put goun 0 n
200end
201
202note ---- exec packet: u16 count, then records (u16 length, bytes); pkpush adds gpb as one record
203fn pkreset to void
204put gpk 0 0
205put gpk 1 0
206put gpkn 0 2
207put gpkc 0 0
208end
209fn pkpush to void
210n = get gpkn 0
211m = get gpbn 0
212if gt add add n m 2 8192
213trap 9
214end
215put gpk n uchar and m 255
216put gpk add n 1 uchar shr m 8
217for i ulong m
218put gpk add add n 2 i get gpb i
219end
220put gpkn 0 add add n m 2
221c = add get gpkc 0 1
222put gpkc 0 c
223put gpk 0 uchar and c 255
224put gpk 1 uchar shr c 8
225end
226note pkline: one record per space-separated word of t; the word @ stands for argument 1 (OMC)
227fn pkline t view uchar * to void
228pkreset
229pbclr
230for i ulong len t
231c = get t i
232if eq c 32
233pkword
234pbclr
235else
236put gpb get gpbn 0 c
237put gpbn 0 add get gpbn 0 1
238end
239end
240pkword
241end
242fn pkword to void
243if eq get gpbn 0 0
244ret
245end
246if and eq get gpbn 0 1 eq get gpb 0 64
247pbclr
248pbarg 1
249end
250pkpush
251end
252
253note ---- output line and expected text
254fn lbtext t view uchar * to void
255n = get glbn 0
256if gt add n len t 4096
257trap 9
258end
259for i ulong len t
260put glb add n i get t i
261end
262put glbn 0 add n len t
263end
264fn lbnum v ulong to void
265d = new uchar 24 0
266p = ulong 24
267x = v
268while gt x 9
269p = sub p 1
270put d p uchar add rem x 10 48
271x = div x 10
272end
273p = sub p 1
274put d p uchar add x 48
275n = get glbn 0
276for i ulong sub 24 p
277put glb add n i get d add p i
278end
279put glbn 0 add n sub 24 p
280end
281fn lbflush to void
282lbtext tnl
283w = write 1 glb 0 get glbn 0
284put glbn 0 0
285end
286note move the line built so far into gex (the expected text of the next check)
287fn lbtoex to void
288n = get glbn 0
289if gt n 1024
290trap 9
291end
292for i ulong n
293put gex i get glb i
294end
295put gexn 0 n
296put glbn 0 0
297end
298
299note ---- files: rdin reads the file named by gpb into gfb (or gf2 when two is true); returns the size,
300note 4194305 when it does not fit, 4194306 when it cannot be opened
301fn rdin two bool to ulong
302fd = fopen gpb 0 get gpbn 0 0 0
303if lt fd 0
304ret 4194306
305end
306n = ulong 0
307going = true
308while going bound 999999999
309r = rdpart fd n two
310if le r 0
311going = false
312else
313n = add n ulong r
314if eq n 4194304
315going = false
316end
317end
318end
319c = fclose int fd
320if eq n 4194304
321ret 4194305
322end
323ret n
324end
325fn rdpart fd long n ulong two bool to long
326if two
327ret read int fd gf2 n sub 4194304 n
328end
329ret read int fd gfb n sub 4194304 n
330end
331note write gfb[0 .. n) to the file named by gpb, then chmod it to mode; false on any failure
332fn wrfb n ulong mode int to bool
333fd = fopen gpb 0 get gpbn 0 577 mode
334if lt fd 0
335ret false
336end
337w = write int fd gfb 0 n
338c = fclose int fd
339if ne w long n
340ret false
341end
342m = chmod gpb 0 get gpbn 0 mode
343ret true
344end
345fn wrtext t view uchar * to bool
346for i ulong len t
347put gfb i get t i
348end
349ret wrfb len t 420
350end
351note copy the file at gpb (source) to the path pbset/pbtext builds next; cpbegin reads, cpend writes
352fn cpbegin to ulong
353n = rdin false
354if ge n 4194305
355setfail tsetup
356end
357ret n
358end
359fn cpend n ulong to void
360if not wrfb n 493
361setfail tsetup
362end
363end
364fn setfail t view uchar * to void
365lbtext t
366w = write 2 glb 0 get glbn 0
367w2 = write 2 gpb 0 get gpbn 0
368w3 = write 2 tnl 0 1
369exit 1
370end
371
372note ---- one child: stdin gin, stdout gou, stderr child.err, exec gpk; returns the exit status
373fn child to void
374fi = fopen gin 0 get ginn 0 0 0
375if lt fi 0
376exit 120
377end
378r = dupfd int fi 0 0
379if ne r 0
380exit 121
381end
382fo = fopen gou 0 get goun 0 577 493
383if lt fo 0
384exit 122
385end
386r = dupfd int fo 1 0
387if ne r 1
388exit 123
389end
390fe = fopen tcerr 0 len tcerr 577 420
391if lt fe 0
392exit 124
393end
394r = dupfd int fe 2 0
395if ne r 2
396exit 125
397end
398r = execprog gpk 0 get gpkn 0
399exit 126
400end
401fn runpk to ulong
402pid = fork
403if lt pid 0
404trap 9
405end
406if eq pid 0
407child
408exit 127
409end
410r = waitpid int pid gst 0 4 0
411if ne r pid
412trap 9
413end
414s0 = ulong get gst 0
415if ne and s0 127 0
416ret add 1000 and s0 127
417end
418ret ulong get gst 1
419end
420note run the command line t with stdin /dev/null and stdout into file o
421fn runline t view uchar * o view uchar * to ulong
422pkline t
423pbset tnull
424setin
425pbset o
426setout
427ret runpk
428end
429note omc < (path in gin) > (path in gou); exit status
430fn omcrun to ulong
431pkreset
432pbclr
433pbarg 1
434pkpush
435ret runpk
436end
437
438note ---- setup helpers
439fn mkd t view uchar * to void
440pbset t
441r = makedir gpb 0 get gpbn 0 493
442if lt r 0
443setfail tsetup
444end
445end
446note omc HERE/kernels/[om2/]CASE.om -> bin/omc/[om2/]CASE
447fn bomc c view uchar * o2 bool to void
448pbclr
449pbarg 2
450if o2
451pbtext tkom2
452else
453pbtext tkern
454end
455pbtext c
456pbtext tom
457setin
458pbset tbo
459if o2
460pbtext tom2
461end
462pbtext c
463setout
464if ne omcrun 0
465setfail tsetup
466end
467end
468note HERE/kernels/CASE.EXT -> src/CASE.EXT
469fn cpsrc c view uchar * x view uchar * to void
470pbclr
471pbarg 2
472pbtext tkern
473pbtext c
474pbtext x
475n = cpbegin
476pbset tsrc
477pbtext c
478pbtext x
479cpend n
480end
481note gcc -Ox -static of src/CASE.c -> bin/cOx/CASE
482fn gccone c view uchar * g view uchar * b view uchar * to void
483pkline g
484pbset b
485pbtext c
486pkpush
487pbset tsrc
488pbtext c
489pbtext tc
490pkpush
491pbset tnull
492setin
493pbset tcerr
494setout
495if ne runpk 0
496setfail tsetup
497end
498end
499note copy a file in two steps: cpfrom reads (a1 a2) into gfb, cpto writes it to (b1 b2)
500fn cpfrom a1 view uchar * a2 view uchar * to void
501pbset a1
502pbtext a2
503put gcnt 3 cpbegin
504end
505fn cpto b1 view uchar * b2 view uchar * to void
506pbset b1
507pbtext b2
508cpend get gcnt 3
509end
510note want/[om2/]CASE.out from HERE/want/CASE.out
511fn cpwant c view uchar * o2 bool to void
512pbclr
513pbarg 2
514pbtext twant
515pbtext c
516pbtext tout
517n = cpbegin
518pbset twd
519if o2
520pbtext tom2
521end
522pbtext c
523pbtext tout
524cpend n
525end
526note fixture program: source text s compiled by OMC into fx/NAME
527fn fixture s view uchar * name view uchar * to void
528pbset tfxs
529if not wrtext s
530setfail tsetup
531end
532setin
533pbset tfxd
534pbtext name
535setout
536if ne omcrun 0
537setfail tsetup
538end
539end
540
541note ---- reading raw rows: the last line of gfb[0 .. n) equals gex
542fn lastis n ulong to bool
543e = n
544if and gt e 0 eq get gfb sub e 1 10
545e = sub e 1
546end
547s = e
548while and gt s 0 ne get gfb sub s 1 10 bound 999999999
549s = sub s 1
550end
551m = get gexn 0
552if ne sub e s m
553ret false
554end
555for i ulong m
556if ne get gfb add s i get gex i
557ret false
558end
559end
560ret true
561end
562note append the last line of gfb[0 .. n) to glb
563fn lblast n ulong to void
564e = n
565if and gt e 0 eq get gfb sub e 1 10
566e = sub e 1
567end
568s = e
569while and gt s 0 ne get gfb sub s 1 10 bound 999999999
570s = sub s 1
571end
572for i ulong sub e s bound 4194304
573m = get glbn 0
574if lt m 4000
575put glb m get gfb add s i
576put glbn 0 add m 1
577end
578end
579end
580note fields of the line of gfb starting at s: starts in fs, lengths in fl; returns the field count
581fn fields s ulong n ulong fs edit ulong 16 fl edit ulong 16 to ulong
582k = ulong 0
583i = s
584going = true
585while going bound 999999999
586if or ge i n eq get gfb i 10
587going = false
588else
589if eq get gfb i 32
590i = add i 1
591else
592j = fend i n
593if lt k 16
594put fs k i
595put fl k sub j i
596end
597k = add k 1
598i = j
599end
600end
601end
602ret k
603end
604fn fend i ulong n ulong to ulong
605j = i
606while lt j n bound 999999999
607c = get gfb j
608if or eq c 32 eq c 10
609ret j
610end
611j = add j 1
612end
613ret j
614end
615note field f equals text t
616fn feq fs view ulong 16 fl view ulong 16 f ulong t view uchar * to bool
617if ne get fl f len t
618ret false
619end
620s = get fs f
621for i ulong len t
622if ne get gfb add s i get t i
623ret false
624end
625end
626ret true
627end
628fn fnum fs view ulong 16 fl view ulong 16 f ulong to ulong
629v = ulong 0
630s = get fs f
631for i ulong get fl f
632c = get gfb add s i
633if or lt c 48 gt c 57
634ret 18446744073709551615
635end
636v = add mul v 10 ulong sub c 48
637end
638ret v
639end
640note scan the rows of gfb[0 .. n): kind 1 counts P rows with a zero counter, 2 counts T rows of a
641note non-control arm without a valid runtime, 3 counts T/P rows not labelled om2/fib, 4 returns the
642note runtime of the cO2 T row, 5 returns 1 when the H row ends with counters=on
643fn scan n ulong kind ulong to ulong
644fs = new ulong 16 0
645fl = new ulong 16 0
646cnt = ulong 0
647s = ulong 0
648while lt s n bound 999999999
649k = fields s n fs fl
650if gt k 0
651cnt = add cnt rowis kind k fs fl
652end
653s = nextln s n
654end
655ret cnt
656end
657fn nextln s ulong n ulong to ulong
658i = s
659while lt i n bound 999999999
660if eq get gfb i 10
661ret add i 1
662end
663i = add i 1
664end
665ret n
666end
667fn rowis kind ulong k ulong fs view ulong 16 fl view ulong 16 to ulong
668if gt k 16
669ret 0
670end
671if eq kind 1
672ret rowp k fs fl
673end
674if eq kind 2
675ret rowt k fs fl
676end
677if eq kind 3
678if or feq fs fl 0 tT feq fs fl 0 tP
679if not feq fs fl 3 tofib
680ret 1
681end
682end
683ret 0
684end
685if eq kind 4
686if and and feq fs fl 0 tT feq fs fl 4 tcO2 eq k 10
687ret fnum fs fl 9
688end
689ret 0
690end
691if and feq fs fl 0 tH gt k 0
692if feq fs fl sub k 1 tcon
693ret 1
694end
695end
696ret 0
697end
698fn rowp k ulong fs view ulong 16 fl view ulong 16 to ulong
699if and feq fs fl 0 tP eq k 10
700if or eq fnum fs fl 6 0 eq fnum fs fl 7 0
701ret 1
702end
703end
704ret 0
705end
706fn rowt k ulong fs view ulong 16 fl view ulong 16 to ulong
707if and feq fs fl 0 tT not feq fs fl 4 tneg
708if ne k 10
709ret 1
710end
711if or not feq fs fl 8 tone feq fs fl 9 tzero
712ret 1
713end
714end
715ret 0
716end
717
718note ---- checks
719fn report ok bool name view uchar * rc ulong gotn ulong to void
720if ok
721lbtext tpass
722else
723lbtext tfl
724put gcnt 0 add get gcnt 0 1
725end
726lbtext name
727lbtext trc
728lbnum rc
729lbtext tsp
730m = get glbn 0
731for i ulong get gexn 0
732put glb add m i get gex i
733end
734put glbn 0 add m get gexn 0
735if not ok
736lbtext tgot
737lbtext tq
738if lt gotn 4194305
739lblast gotn
740end
741lbtext tq
742end
743lbflush
744end
745note expected summary: T-part (rows ok fail) plus P-part when counters are on, then detected, missed
746fn exsum tr ulong tk ulong tf ulong pr ulong pk ulong pf ulong to void
747r = tr
748o = tk
749f = tf
750if eq get gcnt 2 1
751r = add r pr
752o = add o pk
753f = add f pf
754end
755lbtext tS
756lbnum r
757lbtext tok
758lbnum o
759lbtext tfail
760lbnum f
761end
762fn exctl d ulong m ulong to void
763lbtext tdet
764lbnum d
765lbtext tmiss
766lbnum m
767end
768note run the line t into raw file o, expect exit gcnt[4] and the summary already built in glb
769fn chk name view uchar * t view uchar * o view uchar * to void
770lbtoex
771rc = runline t o
772pbset o
773n = rdin false
774ok = and eq rc get gcnt 4 lt n 4194305
775if ok
776ok = lastis n
777end
778report ok name rc n
779end
780fn chkrc name view uchar * t view uchar * wrc ulong to void
781lbtoex
782rc = runline t fnull
783report eq rc wrc name rc 4194306
784end
785fn chkval name view uchar * ok bool to void
786lbtoex
787report ok name 0 4194306
788end
789
790note ---- the checks, in the order of the former selftest.sh, plus the two OMC-EFF-4 control checks
791fn part1 to void
792exsum 8 6 0 6 6 0
793exctl 2 0
794put gcnt 4 0
795chk n1 rclean fok
796pbset fok
797n = rdin false
798if eq get gcnt 2 1
799z = scan n 1
800lbtext tzr
801lbnum z
802chkval n2 eq z 0
803else
804lbtext tnr
805lbtext n2
806lbtext tparn
807lbflush
808put gcnt 1 add get gcnt 1 1
809end
810z2 = scan n 2
811lbtext tbt
812lbnum z2
813chkval n3 eq z2 0
814f = scan n 5
815if eq f 1
816lbtext tcon
817else
818lbtext tcoff
819end
820chkval n17 eq f get gcnt 2
821end
822fn part2 to void
823pbset twd
824pbtext tfibo
825n = cpbegin
826pbset tkeepw
827cpend n
828pbset twd
829pbtext tfibo
830if not wrtext twrong
831setfail tsetup
832end
833exsum 4 0 3 3 0 3
834exctl 1 0
835put gcnt 4 1
836chk n4 rfib fnc1
837pbset tkeepw
838m2 = cpbegin
839pbset twd
840pbtext tfibo
841cpend m2
842cpfrom tbo tfib
843cpto tbn tfib
844exsum 4 3 0 3 3 0
845exctl 0 1
846chk n5 rfib fnc2
847end
848fn part3 to void
849cpfrom tbo tsieve
850cpto tbn tfib
851pbset tb2
852pbtext tfib
853n = cpbegin
854pbset tkeep2
855cpend n
856put gfb n 120
857pbset tb2
858pbtext tfib
859cpend add n 1
860exsum 3 2 1 0 0 0
861exctl 0 0
862chk n6 rbld fnc3
863cpfrom tkeepd tkeepn
864cpto tb2 tfib
865exsum 3 3 0 0 0 0
866exctl 0 0
867put gcnt 4 0
868chk n7 rbld fb
869end
870fn part4 to void
871cpfrom tfxd tn0
872cpto tb2 tfib
873exsum 4 2 1 3 3 0
874exctl 1 0
875put gcnt 4 1
876chk n8 rfib fnc4
877cpfrom tfxd tnb
878cpto tb2 tfib
879exsum 4 2 1 3 3 0
880exctl 1 0
881chk n9 rfib fnc5
882cpfrom tfxd tn1
883cpto tb2 tfib
884rc = runline rfib fok2
885pbset fok2
886n = rdin false
887v = scan n 4
888exsum 4 3 0 3 3 0
889exctl 1 0
890lbtoex
891ok = and and eq rc 0 lastis n eq v 123
892exsum 4 3 0 3 3 0
893exctl 1 0
894lbtext trt
895lbnum 123
896lbtoex
897report ok n10 rc n
898cpfrom tkeepd tkeepn
899cpto tb2 tfib
900end
901fn part5 to void
902cpfrom tfxd tn0
903cpto tbn tfib
904exsum 4 3 1 3 3 0
905exctl 0 0
906put gcnt 4 1
907chk n11 rfib fnc6
908cpfrom tfxd tnc
909cpto tbn tfib
910exsum 4 3 1 3 3 0
911exctl 0 0
912chk n12 rfib fnc7
913cpfrom tbo tsieve
914cpto tbn tfib
915end
916fn part6 to void
917bomc tfib true
918cpfrom tb2 tfib
919cpto tb2 tofib
920cpfrom tb0 tfib
921cpto tb0 tofib
922cpfrom tbo tsieve
923cpto tbn tofib
924rc = runline rom2 fom2
925pbset fom2
926n = rdin false
927u = scan n 3
928exsum 4 3 0 3 3 0
929exctl 1 0
930lbtoex
931ok = and and eq rc 0 eq u 0 lastis n
932exsum 4 3 0 3 3 0
933exctl 1 0
934lbtext tunl
935lbnum u
936lbtoex
937report ok n13 rc n
938lbtext tdiff
939chkval n14 not om2same
940chkrc n15 rusage 2
941chkrc n16 rseed0 2
942end
943fn om2same to bool
944pbset tbo
945pbtext tofib
946a = rdin false
947pbset tbo
948pbtext tfib
949b = rdin true
950if or ne a b ge a 4194305
951ret false
952end
953for i ulong a bound 4194304
954if ne get gfb i get gf2 i
955ret false
956end
957end
958ret true
959end
960
961note ---- main
962fn perfok to ulong
963b = new uchar 32 0
964fd = fopen tparan 0 len tparan 0 0
965if lt fd 0
966ret 0
967end
968n = read int fd b 0 32
969c = fclose int fd
970if lt n 2
971ret 0
972end
973if eq get b 0 45
974ret 1
975end
976v = get b 0
977if and ge v 48 le v 50
978if eq get b 1 10
979ret 1
980end
981end
982ret 0
983end
984fn absarg idx ulong to bool
985b = new uchar 4096 0
986r = argread idx b 0 4096
987if lt r 1
988ret false
989end
990ret eq get b 0 47
991end
992fn setup to void
993if ne argcnt 4
994w = write 2 tusg 0 len tusg
995exit 2
996end
997if or not absarg 1 not absarg 2
998w2 = write 2 tusg 0 len tusg
999exit 2
1000end
1001pbclr
1002pbarg 3
1003r = makedir gpb 0 get gpbn 0 493
1004if lt r 0
1005w3 = write 2 tusg 0 len tusg
1006exit 2
1007end
1008r2 = chdir gpb 0 get gpbn 0
1009if ne r2 0
1010setfail tsetup
1011end
1012put gcnt 2 perfok
1013mkdirs
1014pbclr
1015pbarg 2
1016pbtext tcondom
1017setin
1018pbset tcond
1019setout
1020if ne omcrun 0
1021setfail tsetup
1022end
1023arms tfib
1024arms tsieve
1025cpwant tfib true
1026note the control arm of each case is the other case's program: correct bytes, wrong answer
1027cpfrom tbo tsieve
1028cpto tbn tfib
1029cpfrom tbo tfib
1030cpto tbn tsieve
1031fixture frt0 tn0
1032fixture frtb tnb
1033fixture frt1 tn1
1034fixture frtc tnc
1035end
1036fn arms c view uchar * to void
1037cpsrc c tom
1038cpsrc c tc
1039bomc c false
1040gccone c tgo2 tb2
1041gccone c tgo0 tb0
1042cpwant c false
1043end
1044fn mkdirs to void
1045mkd tdir1
1046mkd tdir2
1047mkd tdir3
1048mkd tdir4
1049mkd tdir5
1050mkd tdir6
1051mkd tdir7
1052mkd tdir8
1053mkd tdir9
1054mkd tdir10
1055mkd tdir11
1056mkd tdir12
1057mkd tdir13
1058mkd tdirf
1059end
1060fn main to int
1061setup
1062part1
1063part2
1064part3
1065part4
1066part5
1067part6
1068lbtext tend
1069lbnum get gcnt 0
1070lbtext tnrun
1071lbnum get gcnt 1
1072lbflush
1073if eq get gcnt 0 0
1074ret 0
1075end
1076ret 1
1077end