interplane.Get Omega
Read in your language

omega-mp4

omega-mp4: ovideo, an MP4 reader written in Omega (Apache-2.0)

Brought by drakestapleton

branch main Branches Tags History

omega-mp4 / tests / gate.om

1588 lines · 26751 bytes Raw Blame History
1om2
2note OVIDEOGATE. Compose tests/gate.om tests/oracle.om, compile with PIN, run from repository root.
3note Reuses OmegaPdf gate process, SHA256, composition and line-mutation mechanisms.
4note Generated fixtures must exist under build/gate; this gate never removes that directory.
5note Before the cases it builds tests/docs.om with the same compiler and runs it: publication checks of
6note the repository's own text (rules tests/docrules.txt, its own mutants tests/docmutants.txt). Its
7note output is copied here, and any exit but 0 fails the gate.
8text PIN "6d1b1cf5a44803389a831b67f750ea4cd1c9f53edfde9d6d9241d7352887f1f8"
9text UNITS "src/io.om src/box.om src/info.om src/plan.om src/write.om src/main.om"
10const TLIM long 10000000000
11const CLIM long 10000000000
12const GXH ulong 8388608
13
14global cs uchar 262144
15global csn ulong 1
16global mu uchar 65536
17global mun ulong 1
18global sr uchar 1048576
19global srn ulong 1
20global ub uchar 262144
21global ca uchar 65536
22global cb uchar 65536
23global rb uchar 1048576
24global gx uchar 16777216
25global pk uchar 4096
26global pkn ulong 1
27global pkc ulong 1
28global pa uchar 4096
29global pan ulong 1
30global pb uchar 4096
31global pbn ulong 1
32global om uchar 4096
33global omn ulong 1
34global fs ulong 32
35global fe ulong 32
36global nf ulong 1
37note cnt: 0 passing cases, 20 mutants run, 21 mutants killed, 30 robustness runs, 35 robustness
38note files; the other indices are unused (robustness exit codes are counted in rhist).
39global cnt ulong 256
40global stb uchar 8
41global wp uchar 4096
42global hk uint 64
43global hh uint 8
44global hv uint 8
45global hw uint 64
46global hbk uchar 64
47note a mutant: up to 4 replacements r: unit mru[r], old line mu[mro[4r] .. mro[4r+1]), new line
48note mu[mro[4r+2] .. mro[4r+3]), lines replaced mrh[r]; mrc replacements in all.
49global mru ulong 4
50global mro ulong 16
51global mrh ulong 4
52global mrc ulong 1
53global mrl ulong 4
54global failn ulong 1
55note gv: comparator scratch offsets (see kfind, gnum, pline).
56global gv ulong 8
57
58text tnl "\n"
59text tsp " "
60text tdash "-"
61text tbuild "build"
62text tgdir "build/gate"
63text tooff "build/gate/ovideo"
64text tmut "build/gate/mutant"
65text tout "build/gate/out"
66text terr "build/gate/err"
67text trob "build/gate/rob.in"
68text tref "build/gate/rob.ref"
69text tnull "/dev/null"
70text tcases "tests/cases.txt"
71text tmutf "tests/mutants.txt"
72text tdotom ".om"
73text tpre1 "ovideo: "
74text trobw "rob"
75text tinfo "info"
76text texec "exec"
77text tsplit "trim"
78text tmerge "join"
79text tzip "zip"
80text tfail "OVIDEOGATE FAIL "
81text tnotrun "OVIDEOGATE NOT_RUN: "
82text tbadpin "compiler sha256 is not the pin "
83text tnoomc "usage: gate OMC (run from the repository root)"
84text tcompile "build: compile failed: "
85text tio "gate: I/O error on "
86text twait "gate: fork or wait failed "
87text tshort "malformed case line "
88text tbig "gate: a file is above the comparison buffer "
89
90fn say t view uchar * to void
91r = write 1 t 0 len t
92end
93
94fn saypa to void
95r = write 1 pa 0 get pan 0
96end
97
98fn saynum v ulong to void
99b = new uchar 24 0
100x = v
101for i ulong 20
102put b sub 19 i uchar add rem x 10 48
103x = div x 10
104end
105k = ulong 0
106while lt k 19 bound 20
107if ne get b k 48
108break
109end
110k = add k 1
111end
112r = write 1 b k sub 20 k
113end
114
115fn die t view uchar * to void
116say t
117saypa
118say tnl
119exit 1
120end
121
122note ---- paths: pa and pb are built from texts and case fields ----
123fn pat t view uchar * to void
124for i ulong len t bound 4096
125put pa i get t i
126end
127put pan 0 len t
128end
129
130fn paadd t view uchar * to void
131n = get pan 0
132for i ulong len t bound 4096
133put pa add n i get t i
134end
135put pan 0 add n len t
136end
137
138fn pacs s ulong e ulong to void
139n = get pan 0
140for i ulong sub e s bound 4096
141put pa add n i get cs add s i
142end
143put pan 0 add n sub e s
144end
145
146fn pbt t view uchar * to void
147for i ulong len t bound 4096
148put pb i get t i
149end
150put pbn 0 len t
151end
152
153fn pbcs s ulong e ulong to void
154for i ulong sub e s bound 4096
155put pb i get cs add s i
156end
157put pbn 0 sub e s
158end
159
160note ---- argument packet for execprog: u16 count, then u16 length + bytes per argument ----
161fn pkreset to void
162put pkn 0 2
163put pkc 0 0
164end
165
166fn pkhdr k ulong to ulong
167n = get pkn 0
168put pk n uchar and k 255
169put pk add n 1 uchar shr k 8
170c = add get pkc 0 1
171put pkc 0 c
172put pk 0 uchar and c 255
173put pk 1 uchar shr c 8
174ret add n 2
175end
176
177fn pkt t view uchar * to void
178n = pkhdr len t
179for i ulong len t bound 4096
180put pk add n i get t i
181end
182put pkn 0 add n len t
183end
184
185fn pkpa to void
186k = get pan 0
187n = pkhdr k
188for i ulong k bound 4096
189put pk add n i get pa i
190end
191put pkn 0 add n k
192end
193
194fn pkcs s ulong e ulong to void
195n = pkhdr sub e s
196for i ulong sub e s bound 4096
197put pk add n i get cs add s i
198end
199put pkn 0 add n sub e s
200end
201
202fn pkom to void
203k = get omn 0
204n = pkhdr k
205for i ulong k bound 4096
206put pk add n i get om i
207end
208put pkn 0 add n k
209end
210
211note ---- processes ----
212fn openout to int
213fd = fopen pa 0 get pan 0 577 420
214if lt fd 0
215die tio
216end
217ret int fd
218end
219
220note reap: wait for pid at most lim ns; the status as spawn describes it.
221fn reap pid long lim long to ulong
222t0 = monons
223while true bound 100000000
224w = waitpid int pid stb 0 4 1
225if eq w pid
226s = or ulong get stb 0 shl ulong get stb 1 8
227if eq and s 127 0
228ret and shr s 8 255
229end
230ret add 1000 and s 127
231end
232if lt w 0
233die twait
234end
235if gt sub monons t0 lim
236r = killpid int pid 9
237w = waitpid int pid stb 0 4 0
238ret 2000
239end
240r = sleepns 50000
241end
242ret 2000
243end
244
245note spawn: run the packet with stdin pb (/dev/null when pbn is 0), stdout pa, stderr ep. The
246note result: exit status 0..255, 1000 + signal, or 2000 when the time limit lim (ns) was reached
247note (the child is then killed with SIGKILL and reaped).
248fn spawn ep view uchar * lim long to ulong
249fi = long -1
250if gt get pbn 0 0
251fi = fopen pb 0 get pbn 0 0 0
252else
253fi = fopen tnull 0 len tnull 0 0
254end
255if lt fi 0
256pat tnull
257die tio
258end
259fo = openout
260fx = fopen ep 0 len ep 577 420
261if lt fx 0
262die tio
263end
264pid = fork
265if lt pid 0
266die twait
267end
268if eq pid 0
269r = dupfd int fi 0 0
270r = dupfd fo 1 0
271r = dupfd int fx 2 0
272r = execprog pk 0 get pkn 0
273exit 127
274end
275r = fclose int fi
276r = fclose fo
277r = fclose int fx
278ret reap pid lim
279end
280
281note ---- files ----
282note rdinto: file pa into a big buffer (0 cs, 1 mu, 2 ub, 3 rb); the byte count.
283fn rdinto which ulong to ulong
284fd = fopen pa 0 get pan 0 0 0
285if lt fd 0
286die tio
287end
288n = ulong 0
289while true bound 1000
290r = long 0
291if eq which 0
292r = read int fd cs n sub len cs n
293end
294if eq which 1
295r = read int fd mu n sub len mu n
296end
297if eq which 2
298r = read int fd ub n sub len ub n
299end
300if eq which 3
301r = read int fd rb n sub len rb n
302end
303if lt r 0
304die tio
305end
306if eq r 0
307break
308end
309n = add n ulong r
310end
311r = fclose int fd
312ret n
313end
314
315note rdgx: file pa into gx[o .. o + GXH); the byte count (a larger file stops the gate).
316fn rdgx o ulong to ulong
317fd = fopen pa 0 get pan 0 0 0
318if lt fd 0
319die tio
320end
321n = ulong 0
322while true bound 100000
323if eq n GXH
324die tbig
325end
326r = read int fd gx add o n sub GXH n
327if lt r 0
328die tio
329end
330if eq r 0
331break
332end
333n = add n ulong r
334end
335r = fclose int fd
336ret n
337end
338
339note same: files pa and pb have equal bytes.
340fn same to bool
341fa = fopen pa 0 get pan 0 0 0
342if lt fa 0
343ret false
344end
345fb = fopen pb 0 get pbn 0 0 0
346if lt fb 0
347r = fclose int fa
348ret false
349end
350ok = true
351while true bound 1000000
352xa = read int fa ca 0 65536
353xb = read int fb cb 0 65536
354if ne xa xb
355ok = false
356break
357end
358if le xa 0
359if lt xa 0
360ok = false
361end
362break
363end
364for i ulong ulong xa
365if ne get ca i get cb i
366ok = false
367end
368end
369if not ok
370break
371end
372end
373r = fclose int fa
374r = fclose int fb
375ret ok
376end
377
378note errok: the stderr file: empty after exit 0, else exactly one line: "ovideo: ", a message, a newline.
379fn errok code ulong to bool
380fd = fopen terr 0 len terr 0 0
381if lt fd 0
382ret false
383end
384r = read int fd ca 0 65536
385c = fclose int fd
386if lt r 0
387ret false
388end
389n = ulong r
390if eq code 0
391ret eq n 0
392end
393if lt n add len tpre1 2
394ret false
395end
396for i ulong len tpre1
397if ne get ca i get tpre1 i
398ret false
399end
400end
401for i ulong sub n 1
402if eq get ca i 10
403ret false
404end
405end
406ret eq get ca sub n 1 10
407end
408
409note ---- SHA-256 (FIPS 180-4 section 6.2) of the compiler ----
410text KTAB "428a2f98 71374491 b5c0fbcf e9b5dba5 3956c25b 59f111f1 923f82a4 ab1c5ed5 d807aa98 12835b01 243185be 550c7dc3 72be5d74 80deb1fe 9bdc06a7 c19bf174 e49b69c1 efbe4786 0fc19dc6 240ca1cc 2de92c6f 4a7484aa 5cb0a9dc 76f988da 983e5152 a831c66d b00327c8 bf597fc7 c6e00bf3 d5a79147 06ca6351 14292967 27b70a85 2e1b2138 4d2c6dfc 53380d13 650a7354 766a0abb 81c2c92e 92722c85 a2bfe8a1 a81a664b c24b8b70 c76c51a3 d192e819 d6990624 f40e3585 106aa070 19a4c116 1e376c08 2748774c 34b0bcb5 391c0cb3 4ed8aa4a 5b9cca4f 682e6ff3 748f82ee 78a5636f 84c87814 8cc70208 90befffa a4506ceb bef9a3f7 c67178f2"
411text IVTAB "6a09e667 bb67ae85 3c6ef372 a54ff53a 510e527f 9b05688c 1f83d9ab 5be0cd19"
412
413fn hexv c uchar to uint
414if le c 57
415ret uint sub c 48
416end
417ret uint sub c 87
418end
419
420fn shainit to void
421for i ulong 64
422v = uint 0
423for j ulong 8
424v = or shl v 4 hexv get KTAB add mul i 9 j
425end
426put hk i v
427end
428for i ulong 8
429v = uint 0
430for j ulong 8
431v = or shl v 4 hexv get IVTAB add mul i 9 j
432end
433put hh i v
434end
435end
436
437fn shablk to void
438for t ulong 16
439b = mul t 4
440x = or shl uint get hbk b 24 shl uint get hbk add b 1 16
441y = or shl uint get hbk add b 2 8 uint get hbk add b 3
442put hw t or x y
443end
444for t ulong 48
445u = add t 16
446x = get hw sub u 15
447y = get hw sub u 2
448s0 = xor xor rotr x 7 rotr x 18 shr x 3
449s1 = xor xor rotr y 17 rotr y 19 shr y 10
450z = add get hw sub u 16 s0
451z = add z add get hw sub u 7 s1
452put hw u z
453end
454for i ulong 8
455put hv i get hh i
456end
457for t ulong 64
458e = get hv 4
459s1 = xor xor rotr e 6 rotr e 11 rotr e 25
460ch = xor and e get hv 5 and not e get hv 6
461t1 = add get hv 7 s1
462t1 = add t1 ch
463t1 = add t1 add get hk t get hw t
464a = get hv 0
465s0 = xor xor rotr a 2 rotr a 13 rotr a 22
466b1 = get hv 1
467c1 = get hv 2
468mj = xor xor and a b1 and a c1 and b1 c1
469put hv 7 get hv 6
470put hv 6 get hv 5
471put hv 5 e
472put hv 4 add get hv 3 t1
473put hv 3 get hv 2
474put hv 2 get hv 1
475put hv 1 a
476put hv 0 add t1 add s0 mj
477end
478for i ulong 8
479put hh i add get hh i get hv i
480end
481end
482
483fn shafile to bool
484shainit
485fd = fopen om 0 get omn 0 0 0
486if lt fd 0
487ret false
488end
489tot = ulong 0
490k = ulong 0
491while true bound 10000000
492r = read int fd ca 0 65536
493if lt r 0
494c = fclose int fd
495ret false
496end
497if eq r 0
498break
499end
500for i ulong ulong r
501put hbk k get ca i
502k = add k 1
503if eq k 64
504shablk
505k = 0
506end
507end
508tot = add tot ulong r
509end
510c = fclose int fd
511shapad k tot
512ret true
513end
514
515note shapad: the final padding (FIPS 180-4 5.1.1) after k bytes of the last block, tot bytes in all.
516fn shapad k0 ulong tot ulong to void
517k = k0
518put hbk k 128
519k = add k 1
520if gt k 56
521while lt k 64 bound 64
522put hbk k 0
523k = add k 1
524end
525shablk
526k = 0
527end
528while lt k 56 bound 64
529put hbk k 0
530k = add k 1
531end
532bl = mul tot 8
533for i ulong 8
534put hbk add 56 i uchar and shr bl mul sub 7 i 8 255
535end
536shablk
537end
538
539note pinok: the SHA-256 of the file om[0 .. omn) in lowercase hex equals PIN.
540fn pinok to bool
541if not shafile
542ret false
543end
544for i ulong 8
545v = get hh i
546for j ulong 8
547d = and shr v uint mul sub 7 j 4 15
548c = uchar add d 48
549if gt d 9
550c = uchar add d 87
551end
552if ne c get PIN add mul i 8 j
553ret false
554end
555end
556end
557ret true
558end
559
560note ---- build: UNITS concatenated (lines replaced in a mutant) and compiled ----
561note lineeq: ub[s .. e) equals the old line of replacement r.
562fn lineeq r ulong s ulong e ulong to bool
563a = get mro mul r 4
564if ne sub e s sub get mro add mul r 4 1 a
565ret false
566end
567for i ulong sub e s bound 4096
568if ne get ub add s i get mu add a i
569ret false
570end
571end
572ret true
573end
574
575note emitub: ub[s .. e) and a newline appended to sr at o; emitmu: the new line of replacement r.
576fn emitub o ulong s ulong e ulong to ulong
577for i ulong sub e s bound 65536
578put sr add o i get ub add s i
579end
580put sr add o sub e s 10
581ret add add o sub e s 1
582end
583
584note A two-byte sequence backslash n in a new line starts another line, so one replacement can be a block.
585fn emitmu o ulong r ulong to ulong
586c = get mro add mul r 4 2
587k = sub get mro add mul r 4 3 c
588w = o
589i = ulong 0
590while lt i k bound 4097
591b = get mu add c i
592if and eq b 92 lt add i 1 k
593if eq get mu add add c i 1 110
594put sr w 10
595w = add w 1
596i = add i 2
597continue
598end
599end
600put sr w b
601w = add w 1
602i = add i 1
603end
604put sr w 10
605ret add w 1
606end
607
608note repl: the replacement of unit u whose old line is ub[s .. e), or 99.
609fn repl u ulong line ulong s ulong e ulong to ulong
610for r ulong get mrc 0 bound 4
611if and eq get mru r u eq get mrl r line
612if lineeq r s e
613ret r
614end
615end
616end
617ret 99
618end
619
620note addunit: unit file pa (index u) appended to sr, replacing the lines a replacement names.
621fn addunit u ulong to void
622n = rdinto 2
623o = get srn 0
624s = ulong 0
625line = ulong 0
626while lt s n bound 262144
627e = s
628while lt e n bound 262144
629if eq get ub e 10
630break
631end
632e = add e 1
633end
634line = add line 1
635r = repl u line s e
636if eq r 99
637o = emitub o s e
638else
639put mrh r add get mrh r 1
640o = emitmu o r
641end
642s = add e 1
643end
644put srn 0 o
645end
646
647fn unitpa s ulong e ulong to void
648for j ulong sub e s bound 4096
649put pa j get UNITS add s j
650end
651put pan 0 sub e s
652end
653
654note units: every unit of UNITS into sr; true when each replacement replaced exactly one line.
655fn units to bool
656put srn 0 0
657for r ulong 4
658put mrh r 0
659end
660k = ulong 0
661s = ulong 0
662n = len UNITS
663for i ulong add n 1 bound 4096
664c = uchar 32
665if lt i n
666c = get UNITS i
667end
668if eq c 32
669if gt i s
670unitpa s i
671addunit k
672k = add k 1
673end
674s = add i 1
675end
676end
677for r ulong get mrc 0 bound 4
678if ne get mrh r 1
679ret false
680end
681end
682ret true
683end
684
685note build: UNITS (with the current replacements, none when mrc = 0) into build/gate/NAME.om, compiled to
686note build/gate/NAME (the text bn).
687fn build bn view uchar * to bool
688if not units
689ret false
690end
691pat bn
692paadd tdotom
693fd = openout
694r = write fd sr 0 get srn 0
695c = fclose fd
696if ne r long get srn 0
697die tio
698end
699for i ulong get pan 0 bound 4096
700put pb i get pa i
701end
702put pbn 0 get pan 0
703pkreset
704pkom
705pat bn
706st = spawn terr CLIM
707if ne st 0
708ret false
709end
710r = chmod pa 0 get pan 0 493
711ret true
712end
713
714fn fields s ulong e ulong to void
715k = ulong 0
716i = s
717while lt i e bound 65536
718while lt i e bound 65536
719if ne get cs i 32
720break
721end
722i = add i 1
723end
724if ge i e
725break
726end
727if ge k 32
728break
729end
730put fs k i
731while lt i e bound 65536
732if eq get cs i 32
733break
734end
735i = add i 1
736end
737put fe k i
738k = add k 1
739end
740put nf 0 k
741end
742
743fn fis k ulong t view uchar * to bool
744s = get fs k
745n = sub get fe k s
746if ne n len t
747ret false
748end
749for i ulong n bound 4096
750if ne get cs add s i get t i
751ret false
752end
753end
754ret true
755end
756
757fn fnum k ulong to ulong
758v = ulong 0
759s = get fs k
760n = sub get fe k s
761for i ulong n bound 20
762c = ulong get cs add s i
763v = add mul v 10 sub c 48
764end
765ret v
766end
767
768fn fail1 f ulong to void
769put failn 0 add get failn 0 1
770say tfail
771r = write 1 cs get fs f sub get fe f get fs f
772say tsp
773end
774
775
776text texit "exit "
777text twant " want "
778text tsfull "/dev/full"
779text torerr "oracle or output differs"
780text tlimit "gate capacity exceeded"
781text tpartial "partial output after refusal"
782text tneed "missing required coverage"
783text trobout "build/gate/rob.mp4"
784text tzero "0"
785text tend "@99999999"
786text tdump "dump"
787text twhole "whole"
788global rhist ulong 256
789global rsig ulong 1
790global rtmo ulong 1
791global ckn ulong 8
792text tgenw "gen"
793text tmkc "build/gate/mkcases"
794text tmksrc "tests/mkcases.om"
795text tco64 "build/gate/co64.mp4"
796global cov ulong 64
797global rbfd int 1
798global rbz ulong 1
799global rex ulong 128
800global ren ulong 1
801
802fn fpath k ulong to void
803put pan 0 0
804pacs get fs k get fe k
805end
806
807note cleanout only removes gate-owned outputs, never corpus or arbitrary case arguments.
808fn cleanout fk ulong to void
809fpath fk
810if le get pan 0 len tgdir
811die tshort
812end
813for i ulong len tgdir bound 4096
814if ne get pa i get tgdir i
815die tshort
816end
817end
818if ne get pa len tgdir 47
819die tshort
820end
821r = unlink pa 0 get pan 0
822end
823
824fn absent fk ulong to bool
825fpath fk
826r = fopen pa 0 get pan 0 0 0
827if ge r 0
828c = fclose int r
829ret false
830end
831ret eq r -2
832end
833
834fn sizezero t view uchar * to bool
835fd = fopen t 0 len t 0 0
836if lt fd 0
837ret false
838end
839n = fseek int fd 0 2
840r = fclose int fd
841ret eq n 0
842end
843
844fn runcase bin view uchar * quiet bool to bool
845want = fnum 1
846outarg = ulong 0
847if fis 4 tsplit
848outarg = 8
849end
850if fis 4 tmerge
851outarg = 5
852end
853if gt outarg 0
854if ne want 5
855cleanout outarg
856end
857end
858pkreset
859pkt bin
860for k ulong sub get nf 0 4 bound 28
861f = add k 4
862pkcs get fs f get fe f
863end
864put pbn 0 0
865pat tout
866if fis 3 tsfull
867pat tsfull
868end
869st = spawn terr TLIM
870ok = eq st want
871if ok
872ok = errok st
873end
874if and ok gt st 0
875if gt outarg 0
876if ne want 5
877ok = absent outarg
878end
879end
880end
881if and ok eq st 0
882ok = ocase
883end
884if and and ok eq st 5 gt outarg 0
885fpath outarg
886pbt tco64
887ok = same
888end
889if and ok ne st 0
890if not fis 3 tsfull
891ok = sizezero tout
892end
893end
894if not ok
895if not quiet
896fail1 0
897say texit
898saynum st
899say twant
900saynum want
901say tsp
902say torerr
903say tnl
904end
905end
906ret ok
907end
908
909fn ocase to bool
910if fis 4 tinfo
911ret oinfo_cmp 5
912end
913if fis 4 tdump
914ret odump 5
915end
916if fis 4 tsplit
917ret otrim
918end
919if fis 4 tmerge
920ret ojoin
921end
922ret false
923end
924
925note gen OUT SRC MODE: tests/mkcases.om (parent-owned generator) builds a fixture below build/gate.
926fn mkbuild to bool
927pbt tmksrc
928pkreset
929pkom
930pat tmkc
931st = spawn terr CLIM
932if ne st 0
933ret false
934end
935r = chmod tmkc 0 len tmkc 493
936ret true
937end
938fn gens to void
939s = ulong 0
940n = get csn 0
941while lt s n bound 262144
942e = s
943while lt e n bound 262144
944if eq get cs e 10
945break
946end
947e = add e 1
948end
949fields s e
950s = add e 1
951if and eq get nf 0 4 fis 0 tgenw
952put ckn 7 add get ckn 7 1
953cleanout 1
954pkreset
955pkt tmkc
956pkcs get fs 2 get fe 2
957pkcs get fs 1 get fe 1
958pkcs get fs 3 get fe 3
959put pbn 0 0
960pat tout
961st = spawn terr TLIM
962if ne st 0
963fail1 1
964say texit
965saynum st
966say tnl
967end
968end
969end
970end
971
972fn doline bin view uchar * quiet bool count bool to bool
973if eq get nf 0 0
974ret true
975end
976if fis 0 tgenw
977ret true
978end
979if eq get cs get fs 0 35
980ret true
981end
982if fis 0 trobw
983ret true
984end
985if lt get nf 0 5
986die tshort
987end
988if count
989ckind
990end
991ok = runcase bin quiet
992if and ok count
993put cnt 0 add get cnt 0 1
994v = fnum 1
995if lt v 64
996put cov v add get cov v 1
997end
998end
999ret ok
1000end
1001
1002note ckind (report only): executed case kinds 0 info, 1 dump, 2 trim, 3 whole, 4 join,
1003note 5 refusal (expected exit nonzero), 6 other exit-0 command; gen lines are counted in gens (7).
1004fn ckind to void
1005k = ulong 6
1006if fis 4 tinfo
1007k = 0
1008end
1009if fis 4 tdump
1010k = 1
1011end
1012if fis 4 tsplit
1013k = 2
1014if fis 2 twhole
1015k = 3
1016end
1017end
1018if fis 4 tmerge
1019k = 4
1020end
1021if ne fnum 1 0
1022k = 5
1023end
1024put ckn k add get ckn k 1
1025end
1026
1027fn runall bin view uchar * quiet bool stop bool count bool to ulong
1028bad = ulong 0
1029s = ulong 0
1030n = get csn 0
1031while lt s n bound 262144
1032e = s
1033while lt e n bound 262144
1034if eq get cs e 10
1035break
1036end
1037e = add e 1
1038end
1039fields s e
1040s = add e 1
1041if not doline bin quiet count
1042bad = add bad 1
1043if stop
1044ret bad
1045end
1046end
1047end
1048ret bad
1049end
1050note ---- mutants: tests/mutants.txt lines ID|UNIT|LINE|OLD|NEW, UNIT the 0-based index in UNITS and
1051note LINE 1-based; that line must equal OLD exactly, else the mutant is not built (fail closed) ----
1052text tkilled "OVIDEOGATE MUTANT killed "
1053text tsurv "OVIDEOGATE MUTANT SURVIVED "
1054text tnobuild "OVIDEOGATE MUTANT FAIL (a line not found exactly once, or no compile) "
1055text tby " by case "
1056text tnomut "OVIDEOGATE mutants not run: the unmutated build failed cases\n"
1057
1058fn bar s ulong e ulong to ulong
1059p = s
1060while lt p e bound 65536
1061if eq get mu p 124
1062ret p
1063end
1064p = add p 1
1065end
1066ret e
1067end
1068
1069fn munum s ulong e ulong to ulong
1070u = ulong 0
1071for i ulong sub e s bound 4
1072c = ulong get mu add s i
1073u = add mul u 10 sub c 48
1074end
1075ret u
1076end
1077
1078note mreport: k 0 killed (with the case that failed), 1 survived, 2 not built; the id is mu[s .. e).
1079fn mreport k ulong s ulong e ulong to void
1080if eq k 0
1081put cnt 21 add get cnt 21 1
1082say tkilled
1083r = write 1 mu s sub e s
1084say tby
1085r = write 1 cs get fs 0 sub get fe 0 get fs 0
1086say tsp
1087r = write 1 cs get fs 1 sub get fe 1 get fs 1
1088say tnl
1089ret
1090end
1091put failn 0 add get failn 0 1
1092if eq k 1
1093say tsurv
1094else
1095say tnobuild
1096end
1097r = write 1 mu s sub e s
1098say tnl
1099end
1100
1101note mrun: build and test the mutant whose replacements are set; its id is mu[s .. e).
1102fn mrun s ulong e ulong to void
1103put cnt 20 add get cnt 20 1
1104k = ulong 2
1105if build tmut
1106k = 1
1107if gt runall tmut true true false 0
1108k = 0
1109end
1110end
1111mreport k s e
1112put mrc 0 0
1113end
1114
1115note mideq: the ids mu[a .. b) and mu[c .. d) are equal.
1116fn mideq a ulong b ulong c ulong d ulong to bool
1117if ne sub b a sub d c
1118ret false
1119end
1120for i ulong sub b a bound 4096
1121if ne get mu add a i get mu add c i
1122ret false
1123end
1124end
1125ret true
1126end
1127
1128fn mutants to void
1129pat tmutf
1130n = rdinto 1
1131put mun 0 n
1132put mrc 0 0
1133is = ulong 0
1134ie = ulong 0
1135s = ulong 0
1136while lt s n bound 65536
1137e = s
1138while lt e n bound 65536
1139if eq get mu e 10
1140break
1141end
1142e = add e 1
1143end
1144p1 = bar s e
1145p2 = bar add p1 1 e
1146p3 = bar add p2 1 e
1147p4 = bar add p3 1 e
1148if lt p4 e
1149if gt get mrc 0 0
1150if not mideq is ie s p1
1151mrun is ie
1152end
1153end
1154r = get mrc 0
1155if lt r 4
1156put mru r munum add p1 1 p2
1157put mrl r munum add p2 1 p3
1158put mro mul r 4 add p3 1
1159put mro add mul r 4 1 p4
1160put mro add mul r 4 2 add p4 1
1161put mro add mul r 4 3 e
1162put mrc 0 add r 1
1163end
1164is = s
1165ie = p1
1166end
1167s = add e 1
1168end
1169if gt get mrc 0 0
1170mrun is ie
1171end
1172end
1173
1174
1175note Sparse robustness uses Linux SEEK_DATA/SEEK_HOLE. No hole is materialized.
1176note Every changed input is cloned from occupied extents; cuts are in logical file coordinates,
1177note flips are distributed over occupied extents, including the post-4GiB moov and payload.
1178fn allowed c ulong to bool
1179if or eq c 0 eq c 1
1180ret true
1181end
1182if or eq c 2 eq c 5
1183ret true
1184end
1185if or or eq c 20 eq c 22 eq c 23
1186ret true
1187end
1188if and ge c 30 le c 36
1189ret true
1190end
1191if and ge c 40 le c 43
1192ret true
1193end
1194ret eq c 60
1195end
1196
1197fn rextent to void
1198put ren 0 0
1199p = ulong 0
1200fd = get rbfd 0
1201while lt p get rbz 0 bound 64
1202q = fseek fd long p 3
1203if eq q -6
1204break
1205end
1206if lt q 0
1207die tio
1208end
1209h = fseek fd q 4
1210if le h q
1211die tio
1212end
1213k = get ren 0
1214put rex mul k 2 ulong q
1215put rex add mul k 2 1 ulong h
1216put ren 0 add k 1
1217p = ulong h
1218end
1219end
1220
1221fn rclone cut ulong to void
1222fd = fopen trob 0 len trob 577 420
1223if lt fd 0
1224die tio
1225end
1226for k ulong get ren 0 bound 64
1227p = get rex mul k 2
1228e = get rex add mul k 2 1
1229if gt e cut
1230e = cut
1231end
1232while lt p e bound 1000000
1233n = sub e p
1234if gt n len rb
1235n = len rb
1236end
1237r = pread get rbfd 0 rb 0 n long p
1238if ne r long n
1239die tio
1240end
1241r = pwrite int fd rb 0 n long p
1242if ne r long n
1243die tio
1244end
1245p = add p n
1246end
1247end
1248r = ftrunc int fd long cut
1249if lt r 0
1250die tio
1251end
1252r = fclose int fd
1253end
1254
1255fn rflip pos ulong k ulong to void
1256fd = fopen trob 0 len trob 2 0
1257if lt fd 0
1258die tio
1259end
1260r = pread int fd rb 0 1 long pos
1261if ne r 1
1262die tio
1263end
1264put rb 0 xor get rb 0 uchar shl ulong 1 rem k 8
1265r = pwrite int fd rb 0 1 long pos
1266if ne r 1
1267die tio
1268end
1269r = fclose int fd
1270end
1271
1272fn robrun to void
1273r = unlink trobout 0 len trobout
1274pkreset
1275pkt tooff
1276pkt tsplit
1277pkt trob
1278pkt tzero
1279pkt tend
1280pkt trobout
1281put pbn 0 0
1282pat tout
1283st = spawn terr TLIM
1284put cnt 30 add get cnt 30 1
1285if lt st 256
1286put rhist st add get rhist st 1
1287end
1288if and ge st 1000 lt st 2000
1289put rsig 0 add get rsig 0 1
1290end
1291if eq st 2000
1292put rtmo 0 add get rtmo 0 1
1293end
1294ok = allowed st
1295if ok
1296ok = errok st
1297end
1298if ok
1299ok = sizezero tout
1300end
1301fd = fopen trobout 0 len trobout 0 0
1302if ge fd 0
1303r = fclose int fd
1304if ne st 0
1305ok = false
1306end
1307else
1308if eq st 0
1309ok = false
1310end
1311end
1312if not ok
1313fail1 1
1314say texit
1315saynum st
1316say tnl
1317end
1318end
1319
1320fn robline to void
1321fpath 2
1322fd = fopen pa 0 get pan 0 0 0
1323if lt fd 0
1324die tio
1325end
1326put rbfd 0 int fd
1327z = fseek int fd 0 2
1328if le z 0
1329die tio
1330end
1331put rbz 0 ulong z
1332rextent
1333rcuts ulong z
1334rflips ulong z
1335r = fclose int fd
1336end
1337
1338fn rcuts z ulong to void
1339for k ulong 64
1340rclone div mul z k 64
1341robrun
1342end
1343end
1344
1345fn roccup to ulong
1346occ = ulong 0
1347for k ulong get ren 0 bound 64
1348b = get rex mul k 2
1349e = get rex add mul k 2 1
1350occ = add occ sub e b
1351end
1352ret occ
1353end
1354
1355fn rflips z ulong to void
1356occ = roccup
1357if eq occ 0
1358die tio
1359end
1360for k ulong 256
1361rclone z
1362rpick div mul occ k 256 k
1363robrun
1364end
1365end
1366
1367fn rpick p0 ulong k ulong to void
1368p = p0
1369for j ulong get ren 0 bound 64
1370a = get rex mul j 2
1371n = sub get rex add mul j 2 1 a
1372if lt p n
1373rflip add a p k
1374ret
1375end
1376p = sub p n
1377end
1378end
1379
1380fn robust to void
1381s = ulong 0
1382n = get csn 0
1383while lt s n bound 262144
1384e = s
1385while lt e n bound 262144
1386if eq get cs e 10
1387break
1388end
1389e = add e 1
1390end
1391fields s e
1392s = add e 1
1393if eq get nf 0 3
1394if fis 0 trobw
1395put cnt 35 add get cnt 35 1
1396robline
1397end
1398end
1399end
1400end
1401
1402text tcodes "1 2 5 20 22 23 30 31 32 33 34 35 36 40 41 42 43 60"
1403text rh1 "OVIDEOGATE robustness exit codes:"
1404text rh2 " signals:"
1405text rh3 " timeouts:"
1406text rk1 "OVIDEOGATE cases by kind: info="
1407text rk2 " dump="
1408text rk3 " trim="
1409text rk4 " whole="
1410text rk5 " join="
1411text rk6 " refusal="
1412text rk7 " gen="
1413text tcolon ":"
1414text r17 "OVIDEOGATE PASS cases="
1415text r18 " mutants-killed="
1416text r19 " robust-runs="
1417text r20 "OVIDEOGATE FAIL failures="
1418note NMUT: the number of mutants in tests/mutants.txt; the gate fails unless all of them ran and were killed.
1419const NMUT ulong 8
1420text tslsh "/"
1421fn rhists to void
1422say rh1
1423for c ulong 256
1424if gt get rhist c 0
1425say tsp
1426saynum c
1427say tcolon
1428saynum get rhist c
1429end
1430end
1431say rh2
1432saynum get rsig 0
1433say rh3
1434saynum get rtmo 0
1435say tnl
1436end
1437
1438fn rkinds to void
1439say rk1
1440saynum get ckn 0
1441say rk2
1442saynum get ckn 1
1443say rk3
1444saynum get ckn 2
1445say rk4
1446saynum get ckn 3
1447say rk5
1448saynum get ckn 4
1449say rk6
1450saynum get ckn 5
1451say rk7
1452saynum get ckn 7
1453say tnl
1454end
1455
1456fn report to int
1457v = ulong 0
1458for i ulong add len tcodes 1 bound 256
1459c = uchar 32
1460if lt i len tcodes
1461c = get tcodes i
1462end
1463if eq c 32
1464if eq get cov v 0
1465put failn 0 add get failn 0 1
1466say tfail
1467say tneed
1468say tsp
1469saynum v
1470say tnl
1471end
1472v = 0
1473else
1474v = add mul v 10 sub ulong c 48
1475end
1476end
1477rkinds
1478rhists
1479if ne get cnt 20 NMUT
1480put failn 0 add get failn 0 1
1481end
1482if ne get cnt 21 NMUT
1483put failn 0 add get failn 0 1
1484end
1485if lt get cnt 35 14
1486put failn 0 add get failn 0 1
1487end
1488if ne get cnt 30 mul get cnt 35 320
1489put failn 0 add get failn 0 1
1490end
1491if eq get failn 0 0
1492say r17
1493saynum get cnt 0
1494say r18
1495saynum get cnt 21
1496say tslsh
1497saynum get cnt 20
1498say r19
1499saynum get cnt 30
1500say tnl
1501ret 0
1502end
1503say r20
1504saynum get failn 0
1505say tnl
1506ret 1
1507end
1508
1509text tdocsrc "tests/docs.om"
1510text tdocbin "build/gate/docs"
1511text tdocout "build/gate/docs.out"
1512text tdocfail "OVIDEOGATE FAIL tests/docs.om (publication checks) exit "
1513
1514note docs: the publication checks of the head note; a failure counts in failn.
1515fn docs to void
1516pbt tdocsrc
1517pkreset
1518pkom
1519pat tdocbin
1520st = spawn terr CLIM
1521if ne st 0
1522pat tdocbin
1523die tcompile
1524end
1525pat tdocbin
1526r = chmod pa 0 get pan 0 493
1527pkreset
1528pkpa
1529put pbn 0 0
1530pat tdocout
1531st2 = spawn terr TLIM
1532pat tdocout
1533n = rdinto 3
1534w = write 1 rb 0 n
1535if ne st2 0
1536put failn 0 add get failn 0 1
1537say tdocfail
1538saynum st2
1539say tnl
1540end
1541end
1542
1543fn main to int
1544if ne argcnt 2
1545say tnotrun
1546say tnoomc
1547say tnl
1548ret 3
1549end
1550k = argread 1 om 0 4096
1551if le k 0
1552say tnotrun
1553say tnoomc
1554say tnl
1555ret 3
1556end
1557put omn 0 ulong k
1558if not pinok
1559say tnotrun
1560say tbadpin
1561say PIN
1562say tnl
1563ret 3
1564end
1565r = makedir tbuild 0 len tbuild 493
1566r = makedir tgdir 0 len tgdir 493
1567docs
1568pat tcases
1569put csn 0 rdinto 0
1570put mrc 0 0
1571if not build tooff
1572pat tooff
1573die tcompile
1574end
1575if not mkbuild
1576pat tmkc
1577die tcompile
1578end
1579gens
1580bad = runall tooff false false true
1581if eq bad 0
1582mutants
1583else
1584say tnomut
1585end
1586robust
1587ret report
1588end