interplane.Get Omega
Read in your language

omega-zip

omega-zip: ZIP archive reader in seeded Omega (store and deflate, CRC-32, fail-closed refusals)

Brought by drakestapleton

branch main Branches Tags History

omega-zip / tests / gate.om

1335 lines · 23475 bytes Raw Blame History
1om2
2note tests/gate.om: the omega-zip gate. Run from the repository root:
3note OMC < tests/gate.om > build/gate-bin && chmod +x build/gate-bin && build/gate-bin OMC
4note 1. Refuses (NOT_RUN, exit 3) unless the compiler's SHA-256 is the pin PIN below (and in the file
5note PIN); SHA-256 (FIPS 180-4) is computed here.
6note 2. Builds ozip from UNITS with that compiler (build/gate/ozip).
7note 3. Runs every case of tests/cases.txt: exit status, stdout bytes against the oracle's bytes, and
8note stderr (empty on success, exactly one line "ozip: ..." on a refusal).
9note 4. Builds every mutant of tests/mutants.txt (one source line replaced) and requires that some case
10note fails against it (the mutant is killed).
11note 5. Robustness (rob lines): each input cut at 64 points and changed at 256 single bytes. Every run
12note must end with exit 0 or a documented refusal code, never a trap (101..114), a signal or the
13note time limit (10 s each). An exit 0 must give the oracle's bytes, except for raw DEFLATE, which
14note has no checksum (such runs are counted as "decoded-raw").
15note Exit 0 with the last line "OZIPGATE PASS ...", 1 FAIL, 3 NOT_RUN. Scratch: build/gate (recreated).
16
17text PIN "6d1b1cf5a44803389a831b67f750ea4cd1c9f53edfde9d6d9241d7352887f1f8"
18text UNITS "src/head.om vendor/omega-mv/seed/text/text.om src/io.om src/crc32.om src/inflate.om src/zlibd.om src/unzip.om src/main.om"
19const TLIM long 10000000000
20const CLIM long 300000000000
21
22global cs uchar 262144
23global csn ulong 1
24global mu uchar 65536
25global mun ulong 1
26global sr uchar 1048576
27global srn ulong 1
28global ub uchar 262144
29global ca uchar 65536
30global cb uchar 65536
31global rb uchar 1048576
32global pk uchar 4096
33global pkn ulong 1
34global pkc ulong 1
35global pa uchar 4096
36global pan ulong 1
37global pb uchar 4096
38global pbn ulong 1
39global om uchar 4096
40global omn ulong 1
41global fs ulong 32
42global fe ulong 32
43global nf ulong 1
44note cnt: 0..3 passing runs crc32/inflate/zlib/zip with exit 0, 8..11 the same with a refusal code;
45note 20 mutants, 21 killed; 30 robustness runs, 31 refused, 32 exact, 33 decoded-raw, 34 failures,
46note 35 robustness files; 64 + code: robustness refusals by exit code.
47global cnt ulong 128
48global stb uchar 8
49global wp uchar 4096
50global hk uint 64
51global hh uint 8
52global hv uint 8
53global hw uint 64
54global hbk uchar 64
55note mcur: the mutant's old line mu[0 .. 1) and new line mu[2 .. 3) offsets.
56global mcur ulong 4
57global failn ulong 1
58
59text tnl "\n"
60text tsp " "
61text tdash "-"
62text tbuild "build"
63text tgdir "build/gate"
64text txdir "build/gate/x"
65text tozip "build/gate/ozip"
66text tmut "build/gate/mutant"
67text tout "build/gate/out"
68text terr "build/gate/err"
69text trob "build/gate/rob.in"
70text tnull "/dev/null"
71text tcases "tests/cases.txt"
72text tmutf "tests/mutants.txt"
73text tdotom ".om"
74text tslash "/"
75text tozpre "ozip: "
76text tat "@"
77text txcmp "xcmp"
78text txabs "xabsent"
79text trobw "rob"
80text tcrc "crc32"
81text tinfl "inflate"
82text tzlib "zlib"
83text tpm "p"
84text tfail "FAIL "
85text tnotrun "OZIPGATE NOT_RUN: "
86text tbadpin "compiler sha256 is not the pin "
87text tnoomc "usage: gate OMC (run from the repository root)"
88text tcompile "build: compile failed: "
89text tio "gate: I/O error on "
90text twait "gate: fork or wait failed "
91text tshort "malformed case line "
92
93fn say t view uchar * to void
94r = write 1 t 0 len t
95end
96
97fn saypa to void
98r = write 1 pa 0 get pan 0
99end
100
101fn saynum v ulong to void
102b = new uchar 24 0
103x = v
104for i ulong 20
105put b sub 19 i uchar add rem x 10 48
106x = div x 10
107end
108k = ulong 0
109while lt k 19 bound 20
110if ne get b k 48
111break
112end
113k = add k 1
114end
115r = write 1 b k sub 20 k
116end
117
118fn die t view uchar * to void
119say t
120saypa
121say tnl
122exit 1
123end
124
125note ---- paths: pa and pb are built from texts and case fields ----
126fn pat t view uchar * to void
127for i ulong len t bound 4096
128put pa i get t i
129end
130put pan 0 len t
131end
132
133fn paadd t view uchar * to void
134n = get pan 0
135for i ulong len t bound 4096
136put pa add n i get t i
137end
138put pan 0 add n len t
139end
140
141fn pacs s ulong e ulong to void
142n = get pan 0
143for i ulong sub e s bound 4096
144put pa add n i get cs add s i
145end
146put pan 0 add n sub e s
147end
148
149fn pbt t view uchar * to void
150for i ulong len t bound 4096
151put pb i get t i
152end
153put pbn 0 len t
154end
155
156fn pbcs s ulong e ulong to void
157for i ulong sub e s bound 4096
158put pb i get cs add s i
159end
160put pbn 0 sub e s
161end
162
163note ---- argument packet for execprog: u16 count, then u16 length + bytes per argument ----
164fn pkreset to void
165put pkn 0 2
166put pkc 0 0
167end
168
169fn pkhdr k ulong to ulong
170n = get pkn 0
171put pk n uchar and k 255
172put pk add n 1 uchar shr k 8
173c = add get pkc 0 1
174put pkc 0 c
175put pk 0 uchar and c 255
176put pk 1 uchar shr c 8
177ret add n 2
178end
179
180fn pkt t view uchar * to void
181n = pkhdr len t
182for i ulong len t bound 4096
183put pk add n i get t i
184end
185put pkn 0 add n len t
186end
187
188fn pkpa to void
189k = get pan 0
190n = pkhdr k
191for i ulong k bound 4096
192put pk add n i get pa i
193end
194put pkn 0 add n k
195end
196
197fn pkcs s ulong e ulong to void
198n = pkhdr sub e s
199for i ulong sub e s bound 4096
200put pk add n i get cs add s i
201end
202put pkn 0 add n sub e s
203end
204
205fn pkom to void
206k = get omn 0
207n = pkhdr k
208for i ulong k bound 4096
209put pk add n i get om i
210end
211put pkn 0 add n k
212end
213
214note ---- processes ----
215fn openout to int
216fd = fopen pa 0 get pan 0 577 420
217if lt fd 0
218die tio
219end
220ret int fd
221end
222
223note reap: wait for pid at most lim ns; the status as spawn describes it.
224fn reap pid long lim long to ulong
225t0 = monons
226while true bound 100000000
227w = waitpid int pid stb 0 4 1
228if eq w pid
229s = or ulong get stb 0 shl ulong get stb 1 8
230if eq and s 127 0
231ret and shr s 8 255
232end
233ret add 1000 and s 127
234end
235if lt w 0
236die twait
237end
238if gt sub monons t0 lim
239r = killpid int pid 9
240w = waitpid int pid stb 0 4 0
241ret 2000
242end
243r = sleepns 50000
244end
245ret 2000
246end
247
248note spawn: run the packet with stdin pb (/dev/null when pbn is 0), stdout pa, stderr ep. The
249note result: exit status 0..255, 1000 + signal, or 2000 when the time limit lim (ns) was reached
250note (the child is then killed with SIGKILL and reaped).
251fn spawn ep view uchar * lim long to ulong
252fi = long -1
253if gt get pbn 0 0
254fi = fopen pb 0 get pbn 0 0 0
255else
256fi = fopen tnull 0 len tnull 0 0
257end
258if lt fi 0
259pat tnull
260die tio
261end
262fo = openout
263fx = fopen ep 0 len ep 577 420
264if lt fx 0
265die tio
266end
267pid = fork
268if lt pid 0
269die twait
270end
271if eq pid 0
272r = dupfd int fi 0 0
273r = dupfd fo 1 0
274r = dupfd int fx 2 0
275r = execprog pk 0 get pkn 0
276exit 127
277end
278r = fclose int fi
279r = fclose fo
280r = fclose int fx
281ret reap pid lim
282end
283
284note ---- files ----
285note rdinto: file pa into a big buffer (0 cs, 1 mu, 2 ub, 3 rb); the byte count.
286fn rdinto which ulong to ulong
287fd = fopen pa 0 get pan 0 0 0
288if lt fd 0
289die tio
290end
291n = ulong 0
292while true bound 1000
293r = long 0
294if eq which 0
295r = read int fd cs n sub len cs n
296end
297if eq which 1
298r = read int fd mu n sub len mu n
299end
300if eq which 2
301r = read int fd ub n sub len ub n
302end
303if eq which 3
304r = read int fd rb n sub len rb n
305end
306if lt r 0
307die tio
308end
309if eq r 0
310break
311end
312n = add n ulong r
313end
314r = fclose int fd
315ret n
316end
317
318note same: files pa and pb have equal bytes.
319fn same to bool
320fa = fopen pa 0 get pan 0 0 0
321if lt fa 0
322ret false
323end
324fb = fopen pb 0 get pbn 0 0 0
325if lt fb 0
326r = fclose int fa
327ret false
328end
329ok = true
330while true bound 1000000
331xa = read int fa ca 0 65536
332xb = read int fb cb 0 65536
333if ne xa xb
334ok = false
335break
336end
337if le xa 0
338if lt xa 0
339ok = false
340end
341break
342end
343for i ulong ulong xa
344if ne get ca i get cb i
345ok = false
346end
347end
348if not ok
349break
350end
351end
352r = fclose int fa
353r = fclose int fb
354ret ok
355end
356
357note errok: the stderr file: empty after exit 0, else exactly one line starting "ozip: ".
358fn errok code ulong to bool
359fd = fopen terr 0 len terr 0 0
360if lt fd 0
361ret false
362end
363r = read int fd ca 0 65536
364c = fclose int fd
365if lt r 0
366ret false
367end
368n = ulong r
369if eq code 0
370ret eq n 0
371end
372if lt n 8
373ret false
374end
375for i ulong 6
376if ne get ca i get tozpre i
377ret false
378end
379end
380for i ulong sub n 1
381if eq get ca i 10
382ret false
383end
384end
385ret eq get ca sub n 1 10
386end
387
388fn wrrob n ulong to void
389fd = fopen trob 0 len trob 577 420
390if lt fd 0
391pat trob
392die tio
393end
394if gt n 0
395r = write int fd rb 0 n
396if ne r long n
397pat trob
398die tio
399end
400end
401r = fclose int fd
402end
403
404note ---- directories ----
405note wipe: remove the tree wp[0 .. n) (directories at most 8 deep) like rm -rf; O_DIRECTORY and
406note O_NOFOLLOW (AArch64 values 16384 and 32768), so a symbolic link is removed, never followed.
407fn wipe depth ulong n ulong to void
408fd = fopen wp 0 n 49152 0
409if lt fd 0
410r = unlink wp 0 n
411ret
412end
413d = new uchar 8192 0
414while true bound 100000
415k = getdnts int fd d 0 8192
416if le k 0
417break
418end
419o = ulong 0
420while lt o ulong k bound 8192
421dent d o n depth
422rl = or ulong get d add o 16 shl ulong get d add o 17 8
423o = add o rl
424end
425end
426r = fclose int fd
427r = rmdir wp 0 n
428end
429
430note dent: one getdents64 record at d[o ..] (name at 19, type at 18) below wp[0 .. n).
431fn dent d view uchar * o ulong n ulong depth ulong to void
432m = ulong 0
433while ne get d add add o 19 m 0 bound 256
434m = add m 1
435end
436if eq m 1
437if eq get d add o 19 46
438ret
439end
440end
441if eq m 2
442if eq get d add o 19 46
443if eq get d add o 20 46
444ret
445end
446end
447end
448put wp n 47
449b = add n 1
450c = add o 19
451for j ulong m bound 256
452put wp add b j get d add c j
453end
454q = add b m
455if and eq get d add o 18 4 lt depth 8
456wipe add depth 1 q
457ret
458end
459r = unlink wp 0 q
460end
461
462fn mkd to void
463r = makedir pa 0 get pan 0 493
464end
465
466fn wipepa to void
467for i ulong get pan 0 bound 4096
468put wp i get pa i
469end
470wipe 0 get pan 0
471end
472
473note ---- SHA-256 (FIPS 180-4 section 6.2) of the compiler ----
474text 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"
475text IVTAB "6a09e667 bb67ae85 3c6ef372 a54ff53a 510e527f 9b05688c 1f83d9ab 5be0cd19"
476
477fn hexv c uchar to uint
478if le c 57
479ret uint sub c 48
480end
481ret uint sub c 87
482end
483
484fn shainit to void
485for i ulong 64
486v = uint 0
487for j ulong 8
488v = or shl v 4 hexv get KTAB add mul i 9 j
489end
490put hk i v
491end
492for i ulong 8
493v = uint 0
494for j ulong 8
495v = or shl v 4 hexv get IVTAB add mul i 9 j
496end
497put hh i v
498end
499end
500
501fn shablk to void
502for t ulong 16
503b = mul t 4
504x = or shl uint get hbk b 24 shl uint get hbk add b 1 16
505y = or shl uint get hbk add b 2 8 uint get hbk add b 3
506put hw t or x y
507end
508for t ulong 48
509u = add t 16
510x = get hw sub u 15
511y = get hw sub u 2
512s0 = xor xor rotr x 7 rotr x 18 shr x 3
513s1 = xor xor rotr y 17 rotr y 19 shr y 10
514z = add get hw sub u 16 s0
515z = add z add get hw sub u 7 s1
516put hw u z
517end
518for i ulong 8
519put hv i get hh i
520end
521for t ulong 64
522e = get hv 4
523s1 = xor xor rotr e 6 rotr e 11 rotr e 25
524ch = xor and e get hv 5 and not e get hv 6
525t1 = add get hv 7 s1
526t1 = add t1 ch
527t1 = add t1 add get hk t get hw t
528a = get hv 0
529s0 = xor xor rotr a 2 rotr a 13 rotr a 22
530b1 = get hv 1
531c1 = get hv 2
532mj = xor xor and a b1 and a c1 and b1 c1
533put hv 7 get hv 6
534put hv 6 get hv 5
535put hv 5 e
536put hv 4 add get hv 3 t1
537put hv 3 get hv 2
538put hv 2 get hv 1
539put hv 1 a
540put hv 0 add t1 add s0 mj
541end
542for i ulong 8
543put hh i add get hh i get hv i
544end
545end
546
547note pinok: the SHA-256 of the file om[0 .. omn) in lowercase hex equals PIN.
548fn shafile to bool
549shainit
550fd = fopen om 0 get omn 0 0 0
551if lt fd 0
552ret false
553end
554tot = ulong 0
555k = ulong 0
556while true bound 10000000
557r = read int fd ca 0 65536
558if lt r 0
559c = fclose int fd
560ret false
561end
562if eq r 0
563break
564end
565for i ulong ulong r
566put hbk k get ca i
567k = add k 1
568if eq k 64
569shablk
570k = 0
571end
572end
573tot = add tot ulong r
574end
575c = fclose int fd
576shapad k tot
577ret true
578end
579
580note shapad: the final padding (FIPS 180-4 5.1.1) after k bytes of the last block, tot bytes in all.
581fn shapad k0 ulong tot ulong to void
582k = k0
583put hbk k 128
584k = add k 1
585if gt k 56
586while lt k 64 bound 64
587put hbk k 0
588k = add k 1
589end
590shablk
591k = 0
592end
593while lt k 56 bound 64
594put hbk k 0
595k = add k 1
596end
597bl = mul tot 8
598for i ulong 8
599put hbk add 56 i uchar and shr bl mul sub 7 i 8 255
600end
601shablk
602end
603
604fn pinok to bool
605if not shafile
606ret false
607end
608for i ulong 8
609v = get hh i
610for j ulong 8
611d = and shr v uint mul sub 7 j 4 15
612c = uchar add d 48
613if gt d 9
614c = uchar add d 87
615end
616if ne c get PIN add mul i 8 j
617ret false
618end
619end
620end
621ret true
622end
623
624note ---- build: UNITS concatenated (one line replaced in a mutant) and compiled ----
625note addunit: unit file pa appended to sr; with rep, each line equal to mu[mcur0 .. mcur1) is
626note replaced by mu[mcur2 .. mcur3). The number of lines replaced.
627note lineeq: ub[s .. e) equals the mutant's old line mu[mcur0 .. mcur1).
628fn lineeq s ulong e ulong to bool
629a = get mcur 0
630if ne sub e s sub get mcur 1 a
631ret false
632end
633for i ulong sub e s bound 4096
634if ne get ub add s i get mu add a i
635ret false
636end
637end
638ret true
639end
640
641note emitub: ub[s .. e) and a newline appended to sr at o; emitmu: the new line mu[mcur2 .. mcur3).
642fn emitub o ulong s ulong e ulong to ulong
643for i ulong sub e s bound 65536
644put sr add o i get ub add s i
645end
646put sr add o sub e s 10
647ret add add o sub e s 1
648end
649
650fn emitmu o ulong to ulong
651c = get mcur 2
652k = sub get mcur 3 c
653for i ulong k bound 4096
654put sr add o i get mu add c i
655end
656put sr add o k 10
657ret add add o k 1
658end
659
660fn addunit rep bool to ulong
661n = rdinto 2
662o = get srn 0
663s = ulong 0
664hits = ulong 0
665while lt s n bound 262144
666e = s
667while lt e n bound 262144
668if eq get ub e 10
669break
670end
671e = add e 1
672end
673m = false
674if rep
675m = lineeq s e
676end
677if m
678hits = add hits 1
679o = emitmu o
680else
681o = emitub o s e
682end
683s = add e 1
684end
685put srn 0 o
686ret hits
687end
688
689note build: UNITS into build/gate/NAME.om, compiled to build/gate/NAME (the text out); unit is the
690note index of the mutated unit, or 99 for none (then no line may be replaced, and none is).
691fn unitpa s ulong e ulong to void
692for j ulong sub e s bound 4096
693put pa j get UNITS add s j
694end
695put pan 0 sub e s
696end
697
698fn units unit ulong to ulong
699put srn 0 0
700hits = ulong 0
701k = ulong 0
702s = ulong 0
703n = len UNITS
704for i ulong add n 1 bound 4096
705c = uchar 32
706if lt i n
707c = get UNITS i
708end
709if eq c 32
710if gt i s
711unitpa s i
712hits = add hits addunit eq k unit
713k = add k 1
714end
715s = add i 1
716end
717end
718ret hits
719end
720
721fn build bn view uchar * unit ulong to bool
722hits = units unit
723if ne unit 99
724if ne hits 1
725ret false
726end
727end
728pat bn
729paadd tdotom
730fd = openout
731r = write fd sr 0 get srn 0
732c = fclose fd
733if ne r long get srn 0
734die tio
735end
736for i ulong get pan 0 bound 4096
737put pb i get pa i
738end
739put pbn 0 get pan 0
740pkreset
741pkom
742pat bn
743st = spawn terr CLIM
744if ne st 0
745ret false
746end
747r = chmod pa 0 get pan 0 493
748ret true
749end
750
751note ---- cases ----
752fn fields s ulong e ulong to void
753k = ulong 0
754i = s
755while lt i e bound 65536
756while lt i e bound 65536
757if ne get cs i 32
758break
759end
760i = add i 1
761end
762if ge i e
763break
764end
765if ge k 32
766break
767end
768put fs k i
769while lt i e bound 65536
770if eq get cs i 32
771break
772end
773i = add i 1
774end
775put fe k i
776k = add k 1
777end
778put nf 0 k
779end
780
781fn fis k ulong t view uchar * to bool
782s = get fs k
783n = sub get fe k s
784if ne n len t
785ret false
786end
787for i ulong n bound 4096
788if ne get cs add s i get t i
789ret false
790end
791end
792ret true
793end
794
795fn fnum k ulong to ulong
796v = ulong 0
797s = get fs k
798n = sub get fe k s
799for i ulong n bound 20
800c = ulong get cs add s i
801v = add mul v 10 sub c 48
802end
803ret v
804end
805
806note xpath: pa = build/gate/x/ID, ID being field f.
807fn xpath f ulong to void
808pat txdir
809paadd tslash
810pacs get fs f get fe f
811end
812
813fn fail1 f ulong to void
814put failn 0 add get failn 0 1
815say tfail
816r = write 1 cs get fs f sub get fe f get fs f
817say tsp
818end
819
820text texit "exit "
821text twant " want "
822text tbytes "stdout differs from "
823text tstderr "stderr is not one ozip: line"
824text tdiff "differs from "
825text texists "exists: "
826
827note runcase: one run line ID EXIT STDIN EXPECT ARGS... ("-" for no stdin, or for no stdout check;
828note an argument "@" becomes build/gate/x/ID). True when exit, stdout and stderr are right.
829fn runcase bin view uchar * quiet bool to bool
830want = fnum 1
831pkreset
832pkt bin
833for k ulong sub get nf 0 4 bound 28
834f = add k 4
835if fis f tat
836xpath 0
837pkpa
838else
839pkcs get fs f get fe f
840end
841end
842put pbn 0 0
843if not fis 2 tdash
844pbcs get fs 2 get fe 2
845end
846pat tout
847st = spawn terr TLIM
848if ne st want
849if not quiet
850fail1 0
851say texit
852saynum st
853say twant
854saynum want
855say tnl
856end
857ret false
858end
859if not errok st
860if not quiet
861fail1 0
862say tstderr
863say tnl
864end
865ret false
866end
867if not fis 3 tdash
868pbcs get fs 3 get fe 3
869pat tout
870if not same
871if not quiet
872fail1 0
873say tbytes
874r = write 1 pb 0 get pbn 0
875say tnl
876end
877ret false
878end
879end
880ret true
881end
882
883note xcheck: "xcmp ID NAME EXPECTED" (the extracted file equals EXPECTED) and "xabsent ID RELPATH"
884note (nothing exists at build/gate/x/ID/RELPATH).
885fn xcheck quiet bool to bool
886xpath 1
887paadd tslash
888pacs get fs 2 get fe 2
889if fis 0 txcmp
890pbcs get fs 3 get fe 3
891if not same
892if not quiet
893fail1 1
894say tdiff
895r = write 1 pb 0 get pbn 0
896say tnl
897end
898ret false
899end
900ret true
901end
902r = faccess pa 0 get pan 0 0
903if eq r 0
904if not quiet
905fail1 1
906say texists
907saypa
908say tnl
909end
910ret false
911end
912ret true
913end
914
915note runall: every case line against bin; the number of failures (stop: return at the first one).
916note With count the passing runs are counted by kind into cnt.
917note doline: the case line already split into fields; true when it passes (comments and rob lines
918note pass here; rob lines run in robust).
919fn doline bin view uchar * quiet bool count bool to bool
920if eq get nf 0 0
921ret true
922end
923if eq get cs get fs 0 35
924ret true
925end
926if fis 0 trobw
927ret true
928end
929if fis 0 txcmp
930ret xcheck quiet
931end
932if fis 0 txabs
933ret xcheck quiet
934end
935if lt get nf 0 5
936fail1 0
937say tshort
938say tnl
939ret false
940end
941xpath 0
942mkd
943ok = runcase bin quiet
944k = ulong 3
945if fis 4 tcrc
946k = 0
947end
948if fis 4 tinfl
949k = 1
950end
951if fis 4 tzlib
952k = 2
953end
954if ne fnum 1 0
955k = add k 8
956end
957if and ok count
958put cnt k add get cnt k 1
959end
960ret ok
961end
962
963note runall: every case line against bin; the number of failures (stop: return at the first one).
964note With count the passing runs are counted by kind into cnt.
965fn runall bin view uchar * quiet bool stop bool count bool to ulong
966pat txdir
967wipepa
968pat txdir
969mkd
970bad = ulong 0
971s = ulong 0
972n = get csn 0
973while lt s n bound 262144
974e = s
975while lt e n bound 262144
976if eq get cs e 10
977break
978end
979e = add e 1
980end
981fields s e
982s = add e 1
983if not doline bin quiet count
984bad = add bad 1
985if stop
986ret bad
987end
988end
989end
990ret bad
991end
992
993note ---- mutants: tests/mutants.txt lines ID|UNIT|OLD|NEW, UNIT the 0-based index in UNITS ----
994text tkilled "MUTANT killed "
995text tsurv "MUTANT SURVIVED "
996text tnobuild "MUTANT FAIL (line not found exactly once, or no compile) "
997text tby " by case "
998text tnomut "OZIPGATE mutants not run: the unmutated build failed cases\n"
999
1000fn bar s ulong e ulong to ulong
1001p = s
1002while lt p e bound 65536
1003if eq get mu p 124
1004ret p
1005end
1006p = add p 1
1007end
1008ret e
1009end
1010
1011fn munum s ulong e ulong to ulong
1012u = ulong 0
1013for i ulong sub e s bound 4
1014c = ulong get mu add s i
1015u = add mul u 10 sub c 48
1016end
1017ret u
1018end
1019
1020note mreport: k 0 killed (with the case that failed), 1 survived, 2 not built; the id is mu[s .. e).
1021fn mreport k ulong s ulong e ulong to void
1022if eq k 0
1023put cnt 21 add get cnt 21 1
1024say tkilled
1025r = write 1 mu s sub e s
1026say tby
1027r = write 1 cs get fs 0 sub get fe 0 get fs 0
1028say tsp
1029r = write 1 cs get fs 1 sub get fe 1 get fs 1
1030say tnl
1031ret
1032end
1033put failn 0 add get failn 0 1
1034if eq k 1
1035say tsurv
1036else
1037say tnobuild
1038end
1039r = write 1 mu s sub e s
1040say tnl
1041end
1042
1043fn mutants to void
1044pat tmutf
1045n = rdinto 1
1046put mun 0 n
1047s = ulong 0
1048while lt s n bound 65536
1049e = s
1050while lt e n bound 65536
1051if eq get mu e 10
1052break
1053end
1054e = add e 1
1055end
1056p1 = bar s e
1057p2 = bar add p1 1 e
1058p3 = bar add p2 1 e
1059if lt p3 e
1060put cnt 20 add get cnt 20 1
1061u = munum add p1 1 p2
1062put mcur 0 add p2 1
1063put mcur 1 p3
1064put mcur 2 add p3 1
1065put mcur 3 e
1066k = ulong 2
1067if build tmut u
1068k = 1
1069if gt runall tmut true true false 0
1070k = 0
1071end
1072end
1073mreport k s p1
1074end
1075s = add e 1
1076end
1077end
1078
1079note ---- robustness: rob ID MODE FILE EXPECTED ----
1080text tcut " cut at "
1081text tflip " flip at "
1082text tcode " exit "
1083
1084fn allowed c ulong to bool
1085if eq c 0
1086ret true
1087end
1088if and ge c 10 le c 22
1089ret true
1090end
1091if and ge c 30 le c 32
1092ret true
1093end
1094if and ge c 40 le c 53
1095ret true
1096end
1097ret false
1098end
1099
1100note robrun: one changed input in build/gate/rob.in; mode 1 inflate, 2 zlib (both on stdin), 3 p.
1101fn robrun mode ulong what view uchar * pos ulong to void
1102pkreset
1103pkt tozip
1104put pbn 0 0
1105if eq mode 1
1106pkt tinfl
1107pbt trob
1108end
1109if eq mode 2
1110pkt tzlib
1111pbt trob
1112end
1113if eq mode 3
1114pkt tpm
1115pkt trob
1116end
1117pat tout
1118st = spawn terr TLIM
1119put cnt 30 add get cnt 30 1
1120bad = false
1121if not allowed st
1122bad = true
1123else
1124if eq st 0
1125pbcs get fs 4 get fe 4
1126pat tout
1127if same
1128put cnt 32 add get cnt 32 1
1129else
1130if eq mode 1
1131put cnt 33 add get cnt 33 1
1132else
1133bad = true
1134end
1135end
1136else
1137put cnt 31 add get cnt 31 1
1138put cnt add 64 st add get cnt add 64 st 1
1139end
1140end
1141if bad
1142put cnt 34 add get cnt 34 1
1143fail1 1
1144say what
1145saynum pos
1146say tcode
1147saynum st
1148say tnl
1149end
1150end
1151
1152fn robline to void
1153mode = ulong 1
1154if fis 2 tzlib
1155mode = 2
1156end
1157if fis 2 tpm
1158mode = 3
1159end
1160put pan 0 0
1161pacs get fs 3 get fe 3
1162n = rdinto 3
1163for k ulong 64
1164c = div mul n k 64
1165wrrob c
1166robrun mode tcut c
1167end
1168for k ulong 256
1169p = div mul n k 256
1170if lt p n
1171v = get rb p
1172m = uchar 255
1173if eq rem k 2 0
1174m = uchar shl ulong 1 rem div k 2 8
1175end
1176put rb p xor v m
1177wrrob n
1178robrun mode tflip p
1179put rb p v
1180end
1181end
1182end
1183
1184fn robust to void
1185s = ulong 0
1186n = get csn 0
1187while lt s n bound 262144
1188e = s
1189while lt e n bound 262144
1190if eq get cs e 10
1191break
1192end
1193e = add e 1
1194end
1195fields s e
1196s = add e 1
1197if eq get nf 0 5
1198if fis 0 trobw
1199put cnt 35 add get cnt 35 1
1200robline
1201end
1202end
1203end
1204end
1205
1206note ---- report ----
1207text r1 "OZIPGATE cases passed: crc32="
1208text r2 " inflate="
1209text r3 " zlib="
1210text r4 " zip="
1211text r5 "; refusals passed: inflate="
1212text r7 " other="
1213text r8 "OZIPGATE mutants="
1214text r9 " killed="
1215text r10 "OZIPGATE robustness files="
1216text r11 " runs="
1217text r12 " refused="
1218text r13 " exact="
1219text r14 " decoded-raw="
1220text r15 " failures="
1221text r16 "OZIPGATE robustness exit codes:"
1222text r17 "OZIPGATE PASS cases="
1223text r18 " mutants-killed="
1224text r19 " robust-runs="
1225text r20 "OZIPGATE FAIL failures="
1226text tslsh "/"
1227text tcolon ":"
1228
1229fn report to int
1230say r1
1231saynum get cnt 0
1232say r2
1233saynum get cnt 1
1234say r3
1235saynum get cnt 2
1236say r4
1237saynum get cnt 3
1238say r5
1239saynum get cnt 9
1240say r3
1241saynum get cnt 10
1242say r4
1243saynum get cnt 11
1244say r7
1245saynum get cnt 8
1246say tnl
1247say r8
1248saynum get cnt 20
1249say r9
1250saynum get cnt 21
1251say tnl
1252say r10
1253saynum get cnt 35
1254say r11
1255saynum get cnt 30
1256say r12
1257saynum get cnt 31
1258say r13
1259saynum get cnt 32
1260say r14
1261saynum get cnt 33
1262say r15
1263saynum get cnt 34
1264say tnl
1265say r16
1266for c ulong 64
1267if gt get cnt add 64 c 0
1268say tsp
1269saynum c
1270say tcolon
1271saynum get cnt add 64 c
1272end
1273end
1274say tnl
1275t = add add add get cnt 0 get cnt 1 get cnt 2 get cnt 3
1276t = add t add add add get cnt 8 get cnt 9 get cnt 10 get cnt 11
1277if eq get failn 0 0
1278say r17
1279saynum t
1280say r18
1281saynum get cnt 21
1282say tslsh
1283saynum get cnt 20
1284say r19
1285saynum get cnt 30
1286say tnl
1287ret 0
1288end
1289say r20
1290saynum get failn 0
1291say tnl
1292ret 1
1293end
1294
1295fn main to int
1296if lt argcnt 2
1297say tnoomc
1298say tnl
1299ret 3
1300end
1301k = argread 1 om 0 4096
1302if le k 0
1303say tnoomc
1304say tnl
1305ret 3
1306end
1307put omn 0 ulong k
1308if not pinok
1309say tnotrun
1310say tbadpin
1311say PIN
1312say tnl
1313ret 3
1314end
1315pat tbuild
1316mkd
1317pat tgdir
1318wipepa
1319pat tgdir
1320mkd
1321pat tcases
1322put csn 0 rdinto 0
1323if not build tozip 99
1324pat tozip
1325die tcompile
1326end
1327bad = runall tozip false false true
1328if eq bad 0
1329mutants
1330else
1331say tnomut
1332end
1333robust
1334ret report
1335end