interplane.Get Omega
Read in your language

omega-pdf

Omega PDF: read and write PDF files in Omega

Brought by drakestapleton

branch main Branches Tags History

omega-pdf / tests / gate.om

1985 lines · 35878 bytes Raw Blame History
1om2
2note tests/gate.om: the omega-pdf 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 opdf from UNITS with that compiler (build/gate/opdf).
7note 3. Runs every case of tests/cases.txt: exit status, stdout against the oracle (see the comparators
8note and the head of cases.txt), and stderr (empty after success, exactly one line "opdf: ..." or
9note "ozip: ..." after a refusal). Cases may run an installed oracle (exec): Ghostscript as the
10note structure checker of split and merge output, pdftotext for the text of those pages.
11note 4. Builds every mutant of tests/mutants.txt (lines replaced) and requires some case to fail on it.
12note 5. Robustness (rob lines): each input cut at 64 points and changed at 256 single bytes. Every run must
13note end with exit 0 or a documented refusal code, never a trap (101..114), a signal or the time
14note limit (10 s each). PDF has no checksum over content, so an exit 0 with other output than the
15note unchanged input's is allowed and counted ("changed-exit0").
16note 6. Before step 3, builds tests/docs.om with the same compiler and runs it: publication checks of the
17note repository's own text (rules tests/docrules.txt, its own mutants tests/docmutants.txt). Its
18note output is copied here, and any exit but 0 fails the gate.
19note Exit 0 with the last line "OPDFGATE PASS ...", 1 FAIL, 3 NOT_RUN. Scratch: build/gate (recreated).
20
21text PIN "6d1b1cf5a44803389a831b67f750ea4cd1c9f53edfde9d6d9241d7352887f1f8"
22text UNITS "src/head.om vendor/omega-zip/vendor/omega-mv/seed/text/text.om vendor/omega-zip/src/io.om vendor/omega-zip/src/crc32.om vendor/omega-zip/src/inflate.om vendor/omega-zip/src/zlibd.om src/core.om src/text.om src/writer.om src/main.om"
23const TLIM long 10000000000
24const CLIM long 300000000000
25const GXH ulong 8388608
26
27global cs uchar 262144
28global csn ulong 1
29global mu uchar 65536
30global mun ulong 1
31global sr uchar 1048576
32global srn ulong 1
33global ub uchar 262144
34global ca uchar 65536
35global cb uchar 65536
36global rb uchar 1048576
37global gx uchar 16777216
38global pk uchar 4096
39global pkn ulong 1
40global pkc ulong 1
41global pa uchar 4096
42global pan ulong 1
43global pb uchar 4096
44global pbn ulong 1
45global om uchar 4096
46global omn ulong 1
47global fs ulong 32
48global fe ulong 32
49global nf ulong 1
50note cnt: 0..3 passing runs by oracle (expat, pdftotext text, external checker, exact expected file),
51note 8..11 refusals by code range (XML 60..75, package 80..89, zip engine 2..53, usage 1); 20 mutants, 21
52note killed; 30 robustness runs, 31 refused, 32 exact, 33 changed-plain, 34 failures, 35 files,
53note 36 accepted after a change (a refused PDF file that a change made well-formed); 64 + code: runs
54note refused with that code.
55global cnt ulong 256
56global stb uchar 8
57global wp uchar 4096
58global hk uint 64
59global hh uint 8
60global hv uint 8
61global hw uint 64
62global hbk uchar 64
63note a mutant: up to 4 replacements r: unit mru[r], old line mu[mro[4r] .. mro[4r+1]), new line
64note mu[mro[4r+2] .. mro[4r+3]), lines replaced mrh[r]; mrc replacements in all.
65global mru ulong 4
66global mro ulong 16
67global mrh ulong 4
68global mrc ulong 1
69global failn ulong 1
70note gv: comparator scratch offsets (see kfind, gnum, pline).
71global gv ulong 8
72
73text tnl "\n"
74text tsp " "
75text tdash "-"
76text tbuild "build"
77text tgdir "build/gate"
78text tooff "build/gate/opdf"
79text tmut "build/gate/mutant"
80text tout "build/gate/out"
81text terr "build/gate/err"
82text trob "build/gate/rob.in"
83text tref "build/gate/rob.ref"
84text tnull "/dev/null"
85text tcases "tests/cases.txt"
86text tmutf "tests/mutants.txt"
87text tdotom ".om"
88text tpre1 "opdf: "
89text tpre2 "ozip: "
90text trobw "rob"
91text tinfo "info"
92text texec "exec"
93text tsplit "split"
94text tmerge "merge"
95text tzip "zip"
96text tfail "FAIL "
97text tnotrun "OPDFGATE NOT_RUN: "
98text tbadpin "compiler sha256 is not the pin "
99text tnoomc "usage: gate OMC (run from the repository root)"
100text tcompile "build: compile failed: "
101text tio "gate: I/O error on "
102text twait "gate: fork or wait failed "
103text tshort "malformed case line "
104text tbig "gate: a file is above the comparison buffer "
105
106fn say t view uchar * to void
107r = write 1 t 0 len t
108end
109
110fn saypa to void
111r = write 1 pa 0 get pan 0
112end
113
114fn saynum v ulong to void
115b = new uchar 24 0
116x = v
117for i ulong 20
118put b sub 19 i uchar add rem x 10 48
119x = div x 10
120end
121k = ulong 0
122while lt k 19 bound 20
123if ne get b k 48
124break
125end
126k = add k 1
127end
128r = write 1 b k sub 20 k
129end
130
131fn die t view uchar * to void
132say t
133saypa
134say tnl
135exit 1
136end
137
138note ---- paths: pa and pb are built from texts and case fields ----
139fn pat t view uchar * to void
140for i ulong len t bound 4096
141put pa i get t i
142end
143put pan 0 len t
144end
145
146fn paadd t view uchar * to void
147n = get pan 0
148for i ulong len t bound 4096
149put pa add n i get t i
150end
151put pan 0 add n len t
152end
153
154fn pacs s ulong e ulong to void
155n = get pan 0
156for i ulong sub e s bound 4096
157put pa add n i get cs add s i
158end
159put pan 0 add n sub e s
160end
161
162fn pbt t view uchar * to void
163for i ulong len t bound 4096
164put pb i get t i
165end
166put pbn 0 len t
167end
168
169fn pbcs s ulong e ulong to void
170for i ulong sub e s bound 4096
171put pb i get cs add s i
172end
173put pbn 0 sub e s
174end
175
176note ---- argument packet for execprog: u16 count, then u16 length + bytes per argument ----
177fn pkreset to void
178put pkn 0 2
179put pkc 0 0
180end
181
182fn pkhdr k ulong to ulong
183n = get pkn 0
184put pk n uchar and k 255
185put pk add n 1 uchar shr k 8
186c = add get pkc 0 1
187put pkc 0 c
188put pk 0 uchar and c 255
189put pk 1 uchar shr c 8
190ret add n 2
191end
192
193fn pkt t view uchar * to void
194n = pkhdr len t
195for i ulong len t bound 4096
196put pk add n i get t i
197end
198put pkn 0 add n len t
199end
200
201fn pkpa to void
202k = get pan 0
203n = pkhdr k
204for i ulong k bound 4096
205put pk add n i get pa i
206end
207put pkn 0 add n k
208end
209
210fn pkcs s ulong e ulong to void
211n = pkhdr sub e s
212for i ulong sub e s bound 4096
213put pk add n i get cs add s i
214end
215put pkn 0 add n sub e s
216end
217
218fn pkom to void
219k = get omn 0
220n = pkhdr k
221for i ulong k bound 4096
222put pk add n i get om i
223end
224put pkn 0 add n k
225end
226
227note ---- processes ----
228fn openout to int
229fd = fopen pa 0 get pan 0 577 420
230if lt fd 0
231die tio
232end
233ret int fd
234end
235
236note reap: wait for pid at most lim ns; the status as spawn describes it.
237fn reap pid long lim long to ulong
238t0 = monons
239while true bound 100000000
240w = waitpid int pid stb 0 4 1
241if eq w pid
242s = or ulong get stb 0 shl ulong get stb 1 8
243if eq and s 127 0
244ret and shr s 8 255
245end
246ret add 1000 and s 127
247end
248if lt w 0
249die twait
250end
251if gt sub monons t0 lim
252r = killpid int pid 9
253w = waitpid int pid stb 0 4 0
254ret 2000
255end
256r = sleepns 50000
257end
258ret 2000
259end
260
261note spawn: run the packet with stdin pb (/dev/null when pbn is 0), stdout pa, stderr ep. The
262note result: exit status 0..255, 1000 + signal, or 2000 when the time limit lim (ns) was reached
263note (the child is then killed with SIGKILL and reaped).
264fn spawn ep view uchar * lim long to ulong
265fi = long -1
266if gt get pbn 0 0
267fi = fopen pb 0 get pbn 0 0 0
268else
269fi = fopen tnull 0 len tnull 0 0
270end
271if lt fi 0
272pat tnull
273die tio
274end
275fo = openout
276fx = fopen ep 0 len ep 577 420
277if lt fx 0
278die tio
279end
280pid = fork
281if lt pid 0
282die twait
283end
284if eq pid 0
285r = dupfd int fi 0 0
286r = dupfd fo 1 0
287r = dupfd int fx 2 0
288r = execprog pk 0 get pkn 0
289exit 127
290end
291r = fclose int fi
292r = fclose fo
293r = fclose int fx
294ret reap pid lim
295end
296
297note ---- files ----
298note rdinto: file pa into a big buffer (0 cs, 1 mu, 2 ub, 3 rb); the byte count.
299fn rdinto which ulong to ulong
300fd = fopen pa 0 get pan 0 0 0
301if lt fd 0
302die tio
303end
304n = ulong 0
305while true bound 1000
306r = long 0
307if eq which 0
308r = read int fd cs n sub len cs n
309end
310if eq which 1
311r = read int fd mu n sub len mu n
312end
313if eq which 2
314r = read int fd ub n sub len ub n
315end
316if eq which 3
317r = read int fd rb n sub len rb n
318end
319if lt r 0
320die tio
321end
322if eq r 0
323break
324end
325n = add n ulong r
326end
327r = fclose int fd
328ret n
329end
330
331note rdgx: file pa into gx[o .. o + GXH); the byte count (a larger file stops the gate).
332fn rdgx o ulong to ulong
333fd = fopen pa 0 get pan 0 0 0
334if lt fd 0
335die tio
336end
337n = ulong 0
338while true bound 100000
339if eq n GXH
340die tbig
341end
342r = read int fd gx add o n sub GXH n
343if lt r 0
344die tio
345end
346if eq r 0
347break
348end
349n = add n ulong r
350end
351r = fclose int fd
352ret n
353end
354
355note same: files pa and pb have equal bytes.
356fn same to bool
357fa = fopen pa 0 get pan 0 0 0
358if lt fa 0
359ret false
360end
361fb = fopen pb 0 get pbn 0 0 0
362if lt fb 0
363r = fclose int fa
364ret false
365end
366ok = true
367while true bound 1000000
368xa = read int fa ca 0 65536
369xb = read int fb cb 0 65536
370if ne xa xb
371ok = false
372break
373end
374if le xa 0
375if lt xa 0
376ok = false
377end
378break
379end
380for i ulong ulong xa
381if ne get ca i get cb i
382ok = false
383end
384end
385if not ok
386break
387end
388end
389r = fclose int fa
390r = fclose int fb
391ret ok
392end
393
394note Normalisation (text mode): ASCII whitespace runs (tab LF VT FF CR space) collapse to one space, with
395note leading and trailing whitespace removed, and the Latin ligatures U+FB00..U+FB04 (UTF-8 EF AC 80..84,
396note which Annex D names ff/fi/fl/ffi/ffl map to) are expanded to ff fi fl ffi ffl on both sides, since
397note pdftotext expands them. Nothing else is changed.
398text tlig "ff fi fl ffifffl"
399global ligo ulong 5
400global ligl ulong 5
401fn gnorm o ulong n ulong t bool to ulong
402e = add o n
403i = o
404w = o
405pending = false
406while lt i e bound 16777217
407c = get gx i
408i = add i 1
409ws = or eq c 32 and ge c 9 le c 13
410if and t ws
411pending = gt w o
412continue
413end
414if pending
415put gx w 32
416w = add w 1
417pending = false
418end
419if and t eq c 239
420k = ligat i e
421if lt k 5
422w = ligput w k
423i = add i 2
424continue
425end
426end
427put gx w c
428w = add w 1
429end
430ret sub w o
431end
432
433note ligat: gx[i .. i+2) are AC 80+k (k 0..4) after an EF byte: k, else 5.
434fn ligat i ulong e ulong to ulong
435if gt add i 2 e
436ret 5
437end
438if ne get gx i 172
439ret 5
440end
441k = sub ulong get gx add i 1 128
442if gt k 4
443ret 5
444end
445ret k
446end
447
448note ligput: the expansion of ligature k at gx[w ..); the new w.
449fn ligput w ulong k ulong to ulong
450put ligo 0 0
451put ligl 0 2
452put ligo 1 3
453put ligl 1 2
454put ligo 2 6
455put ligl 2 2
456put ligo 3 9
457put ligl 3 3
458put ligo 4 12
459put ligl 4 3
460o = get ligo k
461n = get ligl k
462for j ulong n bound 4
463put gx add w j get tlig add o j
464end
465ret add w n
466end
467
468note ncmp: stdout (build/gate/out) and the oracle file pb, both normalised (t: text mode), are equal.
469fn ncmp t bool to bool
470pat tout
471na = rdgx 0
472for i ulong get pbn 0 bound 4096
473put pa i get pb i
474end
475put pan 0 get pbn 0
476nb = rdgx GXH
477na = gnorm 0 na t
478nb = gnorm GXH nb t
479if ne na nb
480ret false
481end
482for i ulong na bound 8388608
483if ne get gx i get gx add GXH i
484ret false
485end
486end
487ret true
488end
489
490note errok: the stderr file: empty after exit 0, else exactly one line starting "opdf: " or "ozip: ".
491fn errok code ulong to bool
492fd = fopen terr 0 len terr 0 0
493if lt fd 0
494ret false
495end
496r = read int fd ca 0 65536
497c = fclose int fd
498if lt r 0
499ret false
500end
501n = ulong r
502if eq code 0
503ret eq n 0
504end
505if lt n 8
506ret false
507end
508p1 = true
509for i ulong len tpre1
510if ne get ca i get tpre1 i
511p1 = false
512end
513end
514p2 = true
515for i ulong 6
516if ne get ca i get tpre2 i
517p2 = false
518end
519end
520if not or p1 p2
521ret false
522end
523for i ulong sub n 1
524if eq get ca i 10
525ret false
526end
527end
528ret eq get ca sub n 1 10
529end
530
531fn wrrob n ulong to void
532fd = fopen trob 0 len trob 577 420
533if lt fd 0
534pat trob
535die tio
536end
537if gt n 0
538r = write int fd rb 0 n
539if ne r long n
540pat trob
541die tio
542end
543end
544r = fclose int fd
545end
546
547note ---- directories ----
548note wipe: remove the tree wp[0 .. n) (directories at most 8 deep) like rm -rf; O_DIRECTORY and
549note O_NOFOLLOW (AArch64 values 16384 and 32768), so a symbolic link is removed, never followed.
550fn wipe depth ulong n ulong to void
551fd = fopen wp 0 n 49152 0
552if lt fd 0
553r = unlink wp 0 n
554ret
555end
556d = new uchar 8192 0
557while true bound 100000
558k = getdnts int fd d 0 8192
559if le k 0
560break
561end
562o = ulong 0
563while lt o ulong k bound 8192
564dent d o n depth
565rl = or ulong get d add o 16 shl ulong get d add o 17 8
566o = add o rl
567end
568end
569r = fclose int fd
570r = rmdir wp 0 n
571end
572
573note dent: one getdents64 record at d[o ..] (name at 19, type at 18) below wp[0 .. n).
574fn dent d view uchar * o ulong n ulong depth ulong to void
575m = ulong 0
576while ne get d add add o 19 m 0 bound 256
577m = add m 1
578end
579if eq m 1
580if eq get d add o 19 46
581ret
582end
583end
584if eq m 2
585if eq get d add o 19 46
586if eq get d add o 20 46
587ret
588end
589end
590end
591put wp n 47
592b = add n 1
593c = add o 19
594for j ulong m bound 256
595put wp add b j get d add c j
596end
597q = add b m
598if and eq get d add o 18 4 lt depth 8
599wipe add depth 1 q
600ret
601end
602r = unlink wp 0 q
603end
604
605fn mkd to void
606r = makedir pa 0 get pan 0 493
607end
608
609fn wipepa to void
610for i ulong get pan 0 bound 4096
611put wp i get pa i
612end
613wipe 0 get pan 0
614end
615
616note ---- SHA-256 (FIPS 180-4 section 6.2) of the compiler ----
617text 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"
618text IVTAB "6a09e667 bb67ae85 3c6ef372 a54ff53a 510e527f 9b05688c 1f83d9ab 5be0cd19"
619
620fn hexv c uchar to uint
621if le c 57
622ret uint sub c 48
623end
624ret uint sub c 87
625end
626
627fn shainit to void
628for i ulong 64
629v = uint 0
630for j ulong 8
631v = or shl v 4 hexv get KTAB add mul i 9 j
632end
633put hk i v
634end
635for i ulong 8
636v = uint 0
637for j ulong 8
638v = or shl v 4 hexv get IVTAB add mul i 9 j
639end
640put hh i v
641end
642end
643
644fn shablk to void
645for t ulong 16
646b = mul t 4
647x = or shl uint get hbk b 24 shl uint get hbk add b 1 16
648y = or shl uint get hbk add b 2 8 uint get hbk add b 3
649put hw t or x y
650end
651for t ulong 48
652u = add t 16
653x = get hw sub u 15
654y = get hw sub u 2
655s0 = xor xor rotr x 7 rotr x 18 shr x 3
656s1 = xor xor rotr y 17 rotr y 19 shr y 10
657z = add get hw sub u 16 s0
658z = add z add get hw sub u 7 s1
659put hw u z
660end
661for i ulong 8
662put hv i get hh i
663end
664for t ulong 64
665e = get hv 4
666s1 = xor xor rotr e 6 rotr e 11 rotr e 25
667ch = xor and e get hv 5 and not e get hv 6
668t1 = add get hv 7 s1
669t1 = add t1 ch
670t1 = add t1 add get hk t get hw t
671a = get hv 0
672s0 = xor xor rotr a 2 rotr a 13 rotr a 22
673b1 = get hv 1
674c1 = get hv 2
675mj = xor xor and a b1 and a c1 and b1 c1
676put hv 7 get hv 6
677put hv 6 get hv 5
678put hv 5 e
679put hv 4 add get hv 3 t1
680put hv 3 get hv 2
681put hv 2 get hv 1
682put hv 1 a
683put hv 0 add t1 add s0 mj
684end
685for i ulong 8
686put hh i add get hh i get hv i
687end
688end
689
690fn shafile to bool
691shainit
692fd = fopen om 0 get omn 0 0 0
693if lt fd 0
694ret false
695end
696tot = ulong 0
697k = ulong 0
698while true bound 10000000
699r = read int fd ca 0 65536
700if lt r 0
701c = fclose int fd
702ret false
703end
704if eq r 0
705break
706end
707for i ulong ulong r
708put hbk k get ca i
709k = add k 1
710if eq k 64
711shablk
712k = 0
713end
714end
715tot = add tot ulong r
716end
717c = fclose int fd
718shapad k tot
719ret true
720end
721
722note shapad: the final padding (FIPS 180-4 5.1.1) after k bytes of the last block, tot bytes in all.
723fn shapad k0 ulong tot ulong to void
724k = k0
725put hbk k 128
726k = add k 1
727if gt k 56
728while lt k 64 bound 64
729put hbk k 0
730k = add k 1
731end
732shablk
733k = 0
734end
735while lt k 56 bound 64
736put hbk k 0
737k = add k 1
738end
739bl = mul tot 8
740for i ulong 8
741put hbk add 56 i uchar and shr bl mul sub 7 i 8 255
742end
743shablk
744end
745
746note pinok: the SHA-256 of the file om[0 .. omn) in lowercase hex equals PIN.
747fn pinok to bool
748if not shafile
749ret false
750end
751for i ulong 8
752v = get hh i
753for j ulong 8
754d = and shr v uint mul sub 7 j 4 15
755c = uchar add d 48
756if gt d 9
757c = uchar add d 87
758end
759if ne c get PIN add mul i 8 j
760ret false
761end
762end
763end
764ret true
765end
766
767note ---- build: UNITS concatenated (lines replaced in a mutant) and compiled ----
768note lineeq: ub[s .. e) equals the old line of replacement r.
769fn lineeq r ulong s ulong e ulong to bool
770a = get mro mul r 4
771if ne sub e s sub get mro add mul r 4 1 a
772ret false
773end
774for i ulong sub e s bound 4096
775if ne get ub add s i get mu add a i
776ret false
777end
778end
779ret true
780end
781
782note emitub: ub[s .. e) and a newline appended to sr at o; emitmu: the new line of replacement r.
783fn emitub o ulong s ulong e ulong to ulong
784for i ulong sub e s bound 65536
785put sr add o i get ub add s i
786end
787put sr add o sub e s 10
788ret add add o sub e s 1
789end
790
791note A two-byte sequence backslash n in a new line starts another line, so one replacement can be a block.
792fn emitmu o ulong r ulong to ulong
793c = get mro add mul r 4 2
794k = sub get mro add mul r 4 3 c
795w = o
796i = ulong 0
797while lt i k bound 4097
798b = get mu add c i
799if and eq b 92 lt add i 1 k
800if eq get mu add add c i 1 110
801put sr w 10
802w = add w 1
803i = add i 2
804continue
805end
806end
807put sr w b
808w = add w 1
809i = add i 1
810end
811put sr w 10
812ret add w 1
813end
814
815note repl: the replacement of unit u whose old line is ub[s .. e), or 99.
816fn repl u ulong s ulong e ulong to ulong
817for r ulong get mrc 0 bound 4
818if eq get mru r u
819if lineeq r s e
820ret r
821end
822end
823end
824ret 99
825end
826
827note addunit: unit file pa (index u) appended to sr, replacing the lines a replacement names.
828fn addunit u ulong to void
829n = rdinto 2
830o = get srn 0
831s = ulong 0
832while lt s n bound 262144
833e = s
834while lt e n bound 262144
835if eq get ub e 10
836break
837end
838e = add e 1
839end
840r = repl u s e
841if eq r 99
842o = emitub o s e
843else
844put mrh r add get mrh r 1
845o = emitmu o r
846end
847s = add e 1
848end
849put srn 0 o
850end
851
852fn unitpa s ulong e ulong to void
853for j ulong sub e s bound 4096
854put pa j get UNITS add s j
855end
856put pan 0 sub e s
857end
858
859note units: every unit of UNITS into sr; true when each replacement replaced exactly one line.
860fn units to bool
861put srn 0 0
862for r ulong 4
863put mrh r 0
864end
865k = ulong 0
866s = ulong 0
867n = len UNITS
868for i ulong add n 1 bound 4096
869c = uchar 32
870if lt i n
871c = get UNITS i
872end
873if eq c 32
874if gt i s
875unitpa s i
876addunit k
877k = add k 1
878end
879s = add i 1
880end
881end
882for r ulong get mrc 0 bound 4
883if ne get mrh r 1
884ret false
885end
886end
887ret true
888end
889
890note build: UNITS (with the current replacements, none when mrc = 0) into build/gate/NAME.om, compiled to
891note build/gate/NAME (the text bn).
892fn build bn view uchar * to bool
893if not units
894ret false
895end
896pat bn
897paadd tdotom
898fd = openout
899r = write fd sr 0 get srn 0
900c = fclose fd
901if ne r long get srn 0
902die tio
903end
904for i ulong get pan 0 bound 4096
905put pb i get pa i
906end
907put pbn 0 get pan 0
908pkreset
909pkom
910pat bn
911st = spawn terr CLIM
912if ne st 0
913ret false
914end
915r = chmod pa 0 get pan 0 493
916ret true
917end
918
919note ---- cases ----
920fn fields s ulong e ulong to void
921k = ulong 0
922i = s
923while lt i e bound 65536
924while lt i e bound 65536
925if ne get cs i 32
926break
927end
928i = add i 1
929end
930if ge i e
931break
932end
933if ge k 32
934break
935end
936put fs k i
937while lt i e bound 65536
938if eq get cs i 32
939break
940end
941i = add i 1
942end
943put fe k i
944k = add k 1
945end
946put nf 0 k
947end
948
949fn fis k ulong t view uchar * to bool
950s = get fs k
951n = sub get fe k s
952if ne n len t
953ret false
954end
955for i ulong n bound 4096
956if ne get cs add s i get t i
957ret false
958end
959end
960ret true
961end
962
963fn fnum k ulong to ulong
964v = ulong 0
965s = get fs k
966n = sub get fe k s
967for i ulong n bound 20
968c = ulong get cs add s i
969v = add mul v 10 sub c 48
970end
971ret v
972end
973
974note fmode: field k begins "t:" (1, pdftotext text oracle), "c:" (2, external checker oracle), else 0.
975fn fmode k ulong to ulong
976s = get fs k
977if lt sub get fe k s 3
978ret 0
979end
980if ne get cs add s 1 58
981ret 0
982end
983c = get cs s
984if eq c 116
985ret 1
986end
987if eq c 99
988ret 2
989end
990if eq c 105
991ret 3
992end
993if eq c 112
994ret 4
995end
996if eq c 103
997ret 5
998end
999ret 0
1000end
1001
1002fn fail1 f ulong to void
1003put failn 0 add get failn 0 1
1004say tfail
1005r = write 1 cs get fs f sub get fe f get fs f
1006say tsp
1007end
1008
1009text texit "exit "
1010text twant " want "
1011text tbytes "stdout differs from "
1012text teq "="
1013text tprev "build/gate/prev"
1014text tpg "Page "
1015text kv1 "version="
1016text ko1 "PDF version:"
1017text kv2 "pages="
1018text ko2 "Pages:"
1019text kv3 "encrypted="
1020text ko3 "Encrypted:"
1021text kv4 "Title="
1022text ko4 "Title:"
1023text kv5 "Author="
1024text ko5 "Author:"
1025text kv6 "Producer="
1026text ko6 "Producer:"
1027text kv7 "CreationDate="
1028text ko7 "CreationDate:"
1029text kmb "MediaBox:"
1030text krot "rot:"
1031text kmbe "MediaBox="
1032text krte "Rotate="
1033text tstderr "stderr is not one opdf: or ozip: line"
1034
1035note Only generated outputs below build/gate may be removed between mutant runs.
1036fn cleanout fk ulong to void
1037s = get fs fk
1038n = sub get fe fk s
1039if le n 11
1040die tshort
1041end
1042textok = true
1043for i ulong 10
1044if ne get cs add s i get tgdir i
1045textok = false
1046end
1047end
1048if not textok
1049die tshort
1050end
1051if ne get cs add s 10 47
1052die tshort
1053end
1054pat tgdir
1055put pan 0 0
1056pacs s add s n
1057r = unlink pa 0 get pan 0
1058end
1059
1060note keepprev: copy build/gate/out to build/gate/prev (the "=" expectation compares with the previous run).
1061fn keepprev to void
1062pat tout
1063n = rdinto 3
1064pat tprev
1065fd = openout
1066r = write fd rb 0 n
1067if ne r long n
1068die tio
1069end
1070r = fclose fd
1071end
1072
1073note ---- comparators over gx: stdout at 0 (na bytes), the oracle file at GXH (nb bytes) ----
1074
1075note kat: gx[p ..) starts with t (before e).
1076fn kat p ulong e ulong t view uchar * to bool
1077if gt add p len t e
1078ret false
1079end
1080for i ulong len t bound 64
1081if ne get gx add p i get t i
1082ret false
1083end
1084end
1085ret true
1086end
1087
1088note eol: the offset of the LF ending the line at p (or e).
1089fn eol p ulong e ulong to ulong
1090q = p
1091while lt q e bound 16777217
1092if eq get gx q 10
1093ret q
1094end
1095q = add q 1
1096end
1097ret e
1098end
1099
1100note skipsp: past the blanks of gx[v .. q).
1101fn skipsp v ulong q ulong to ulong
1102w = v
1103while lt w q bound 16777217
1104if ne get gx w 32
1105ret w
1106end
1107w = add w 1
1108end
1109ret w
1110end
1111
1112note kfind: the first line of gx[s .. e) that starts with t: its value (after t and blanks) in gv[k], gv[k+1].
1113fn kfind s ulong e ulong t view uchar * k ulong to bool
1114p = s
1115while lt p e bound 16777217
1116q = eol p e
1117if kat p q t
1118v = skipsp add p len t q
1119put gv k v
1120put gv add k 1 q
1121ret true
1122end
1123p = add q 1
1124end
1125ret false
1126end
1127
1128note hasbs: gx[s .. e) holds a backslash.
1129fn hasbs s ulong e ulong to bool
1130for i ulong sub e s bound 65536
1131if eq get gx add s i 92
1132ret true
1133end
1134end
1135ret false
1136end
1137
1138note ipair: my "a" value equals the oracle's "b" value; a value with a backslash (an escaped non-ASCII or
1139note control byte) is not compared (pdfinfo prints such strings decoded); an absent oracle line means empty.
1140fn ipair a view uchar * b view uchar * to bool
1141if not kfind 0 get gv 6 a 0
1142ret false
1143end
1144s = get gv 0
1145e = get gv 1
1146if hasbs s e
1147put cnt 40 add get cnt 40 1
1148ret true
1149end
1150if not kfind GXH get gv 7 b 2
1151ret eq s e
1152end
1153t = get gv 2
1154u = get gv 3
1155if ne sub e s sub u t
1156ret false
1157end
1158ret gxeq s t sub e s
1159end
1160
1161note gxeq: gx[s .. s+n) equals gx[t .. t+n).
1162fn gxeq s ulong t ulong n ulong to bool
1163for i ulong n bound 65536
1164if ne get gx add s i get gx add t i
1165ret false
1166end
1167end
1168ret true
1169end
1170
1171fn ldgx to void
1172pat tout
1173na = rdgx 0
1174for i ulong get pbn 0 bound 4096
1175put pa i get pb i
1176end
1177put pan 0 get pbn 0
1178nb = rdgx GXH
1179put gv 6 na
1180put gv 7 add GXH nb
1181end
1182
1183note icmp: info against pdfinfo -rawdates: version, page count, encryption, Title, Author, Producer, CreationDate.
1184fn icmp to bool
1185ldgx
1186ok = and ipair kv1 ko1 ipair kv2 ko2
1187ok = and ok ipair kv3 ko3
1188ok = and ok ipair kv4 ko4
1189ok = and ok ipair kv5 ko5
1190ok = and ok ipair kv6 ko6
1191ret and ok ipair kv7 ko7
1192end
1193
1194note gnum: a decimal number at gx[p ..) (optional -, digits, optional . and digits) in millionths;
1195note gv[4] = the offset after it. Digits past the sixth fraction digit are ignored.
1196fn gnum p ulong to long
1197q = p
1198while eq get gx q 32 bound 64
1199q = add q 1
1200end
1201ng = false
1202if eq get gx q 45
1203ng = true
1204q = add q 1
1205end
1206v = long 0
1207while and ge get gx q 48 le get gx q 57 bound 20
1208v = add mul v 10 long sub get gx q 48
1209q = add q 1
1210end
1211v = mul v 1000000
1212if eq get gx q 46
1213q = add q 1
1214f = long 100000
1215while and ge get gx q 48 le get gx q 57 bound 64
1216v = add v mul f long sub get gx q 48
1217f = div f 10
1218q = add q 1
1219end
1220end
1221while eq get gx q 32 bound 64
1222q = add q 1
1223end
1224put gv 4 q
1225if ng
1226ret neg v
1227end
1228ret v
1229end
1230
1231note hund: millionths rounded half away from zero to hundredths.
1232fn hund v long to long
1233if lt v 0
1234ret neg div add neg v 5000 10000
1235end
1236ret div add v 5000 10000
1237end
1238
1239note pline: my pages line at p (to q) against the oracle's "Page N MediaBox:" and "Page N rot:" lines.
1240fn pline p ulong q ulong to bool
1241n = gnum p
1242r = get gv 4
1243if not kat r q kmbe
1244ret false
1245end
1246r = add r len kmbe
1247put gv 5 ulong div n 1000000
1248okb = false
1249okr = false
1250s = GXH
1251e = get gv 7
1252while lt s e bound 16777217
1253t = eol s e
1254if kat s t tpg
1255m = gnum add s 5
1256if eq ulong div m 1000000 get gv 5
1257w = get gv 4
1258if kat w t kmb
1259okb = pbox r q add w len kmb t
1260end
1261if kat w t krot
1262okr = prot q add w len krot
1263end
1264end
1265end
1266s = add t 1
1267end
1268ret and okb okr
1269end
1270
1271note pbox: four numbers of mine at r and of the oracle at w agree to within 0.01.
1272fn pbox r ulong q ulong w ulong t ulong to bool
1273a = r
1274b = w
1275for i ulong 4
1276x = hund gnum a
1277a = get gv 4
1278y = hund gnum b
1279b = get gv 4
1280d = sub x y
1281if or gt d 1 lt d -1
1282ret false
1283end
1284end
1285ret true
1286end
1287
1288note prot: my Rotate= value modulo 360 equals the oracle's rot.
1289fn prot q ulong w ulong to bool
1290a = get gv 4
1291s = get gv 0
1292p = s
1293while lt p q bound 4096
1294if kat p q krte
1295x = div gnum add p len krte 1000000
1296y = div gnum w 1000000
1297x = rem add rem x 360 360 360
1298ret eq x y
1299end
1300p = add p 1
1301end
1302ret false
1303end
1304
1305note pcmp: every pages line agrees with pdfinfo -box, and the line count is the oracle's MediaBox count.
1306fn pcmp to bool
1307ldgx
1308p = ulong 0
1309e = get gv 6
1310k = ulong 0
1311while lt p e bound 16777217
1312q = eol p e
1313put gv 0 p
1314if not pline p q
1315ret false
1316end
1317k = add k 1
1318p = add q 1
1319end
1320c = ulong 0
1321s = GXH
1322f = get gv 7
1323while lt s f bound 16777217
1324t = eol s f
1325if kat s t tpg
1326m = gnum add s 5
1327if kat get gv 4 t kmb
1328c = add c 1
1329end
1330end
1331s = add t 1
1332end
1333ret eq c k
1334end
1335
1336note gcnt: the checker printed exactly N lines "Page K" (N from the EXPECT field "g:N").
1337fn gcnt to bool
1338pat tout
1339na = rdgx 0
1340want = ulong 0
1341for i ulong get pbn 0 bound 20
1342want = add mul want 10 sub ulong get pb i 48
1343end
1344c = ulong 0
1345p = ulong 0
1346while lt p na bound 16777217
1347q = eol p na
1348if kat p q tpg
1349c = add c 1
1350end
1351p = add q 1
1352end
1353ret eq c want
1354end
1355
1356note runcase: one run line ID EXIT STDIN EXPECT ARGS... ("-" for no stdin, or for no stdout check; EXPECT
1357note "t:FILE" or "c:FILE" compares after the stated normalisation). True when exit, stdout, stderr are right.
1358fn runcase bin view uchar * quiet bool to bool
1359ok = runcase0 bin quiet
1360note the "=" expectation of the next case compares with this case's stdout, saved only after this
1361note case's own comparison.
1362keepprev
1363ret ok
1364end
1365
1366fn runcase0 bin view uchar * quiet bool to bool
1367want = fnum 1
1368pkreset
1369start = ulong 4
1370if fis 4 texec
1371start = 6
1372pkcs get fs 5 get fe 5
1373else
1374pkt bin
1375end
1376for k ulong sub get nf 0 start bound 28
1377f = add k start
1378pkcs get fs f get fe f
1379end
1380note A run that must succeed starts without its output file; a refusal case keeps it (r-exists-2).
1381if and fis 4 tsplit eq want 0
1382cleanout 8
1383end
1384if and fis 4 tmerge eq want 0
1385cleanout 5
1386end
1387put pbn 0 0
1388if not fis 2 tdash
1389pbcs get fs 2 get fe 2
1390end
1391pat tout
1392st = spawn terr TLIM
1393if ne st want
1394if not quiet
1395fail1 0
1396say texit
1397saynum st
1398say twant
1399saynum want
1400say tnl
1401end
1402ret false
1403end
1404if not errok st
1405if not quiet
1406fail1 0
1407say tstderr
1408say tnl
1409end
1410ret false
1411end
1412if fis 3 tdash
1413ret true
1414end
1415m = fmode 3
1416ok = false
1417if fis 3 teq
1418pbt tprev
1419pat tout
1420ok = same
1421else
1422if eq m 0
1423pbcs get fs 3 get fe 3
1424pat tout
1425ok = same
1426else
1427pbcs add get fs 3 2 get fe 3
1428if le m 2
1429ok = ncmp eq m 1
1430end
1431if eq m 3
1432ok = icmp
1433end
1434if eq m 4
1435ok = pcmp
1436end
1437if eq m 5
1438ok = gcnt
1439end
1440end
1441end
1442if not ok
1443if not quiet
1444fail1 0
1445say tbytes
1446r = write 1 pb 0 get pbn 0
1447say tnl
1448end
1449ret false
1450end
1451ret true
1452end
1453
1454note ckind: the counter of a passing case: by oracle when it exits 0, else by refusal code range.
1455fn ckind to ulong
1456w = fnum 1
1457if eq w 0
1458if fis 3 teq
1459ret 5
1460end
1461if fis 3 tdash
1462ret 6
1463end
1464m = fmode 3
1465if eq m 1
1466ret 1
1467end
1468if eq m 3
1469ret 0
1470end
1471if eq m 4
1472ret 3
1473end
1474if eq m 5
1475ret 4
1476end
1477ret 2
1478end
1479if and ge w 60 le w 66
1480ret 8
1481end
1482if and ge w 67 le w 68
1483ret 9
1484end
1485if eq w 1
1486ret 11
1487end
1488ret 10
1489end
1490
1491note doline: the case line already split into fields; true when it passes (comments and rob lines pass
1492note here; rob lines run in robust).
1493fn doline bin view uchar * quiet bool count bool to bool
1494if eq get nf 0 0
1495ret true
1496end
1497if eq get cs get fs 0 35
1498ret true
1499end
1500if fis 0 trobw
1501ret true
1502end
1503if lt get nf 0 5
1504fail1 0
1505say tshort
1506say tnl
1507ret false
1508end
1509ok = runcase bin quiet
1510if and ok count
1511k = ckind
1512put cnt k add get cnt k 1
1513end
1514ret ok
1515end
1516
1517note runall: every case line against bin; the number of failures (stop: return at the first one, and
1518note the failing line stays in fs/fe for the report). With count the passing runs are counted.
1519fn runall bin view uchar * quiet bool stop bool count bool to ulong
1520bad = ulong 0
1521s = ulong 0
1522n = get csn 0
1523while lt s n bound 262144
1524e = s
1525while lt e n bound 262144
1526if eq get cs e 10
1527break
1528end
1529e = add e 1
1530end
1531fields s e
1532s = add e 1
1533if not doline bin quiet count
1534bad = add bad 1
1535if stop
1536ret bad
1537end
1538end
1539end
1540ret bad
1541end
1542
1543note ---- mutants: tests/mutants.txt lines ID|UNIT|OLD|NEW, UNIT the 0-based index in UNITS; consecutive
1544note lines with the same ID are one mutant (each of its lines must be found exactly once) ----
1545text tkilled "MUTANT killed "
1546text tsurv "MUTANT SURVIVED "
1547text tnobuild "MUTANT FAIL (a line not found exactly once, or no compile) "
1548text tby " by case "
1549text tnomut "OPDFGATE mutants not run: the unmutated build failed cases\n"
1550
1551fn bar s ulong e ulong to ulong
1552p = s
1553while lt p e bound 65536
1554if eq get mu p 124
1555ret p
1556end
1557p = add p 1
1558end
1559ret e
1560end
1561
1562fn munum s ulong e ulong to ulong
1563u = ulong 0
1564for i ulong sub e s bound 4
1565c = ulong get mu add s i
1566u = add mul u 10 sub c 48
1567end
1568ret u
1569end
1570
1571note mreport: k 0 killed (with the case that failed), 1 survived, 2 not built; the id is mu[s .. e).
1572fn mreport k ulong s ulong e ulong to void
1573if eq k 0
1574put cnt 21 add get cnt 21 1
1575say tkilled
1576r = write 1 mu s sub e s
1577say tby
1578r = write 1 cs get fs 0 sub get fe 0 get fs 0
1579say tsp
1580r = write 1 cs get fs 1 sub get fe 1 get fs 1
1581say tnl
1582ret
1583end
1584put failn 0 add get failn 0 1
1585if eq k 1
1586say tsurv
1587else
1588say tnobuild
1589end
1590r = write 1 mu s sub e s
1591say tnl
1592end
1593
1594note mrun: build and test the mutant whose replacements are set; its id is mu[s .. e).
1595fn mrun s ulong e ulong to void
1596put cnt 20 add get cnt 20 1
1597k = ulong 2
1598if build tmut
1599k = 1
1600if gt runall tmut true true false 0
1601k = 0
1602end
1603end
1604mreport k s e
1605put mrc 0 0
1606end
1607
1608note mideq: the ids mu[a .. b) and mu[c .. d) are equal.
1609fn mideq a ulong b ulong c ulong d ulong to bool
1610if ne sub b a sub d c
1611ret false
1612end
1613for i ulong sub b a bound 4096
1614if ne get mu add a i get mu add c i
1615ret false
1616end
1617end
1618ret true
1619end
1620
1621fn mutants to void
1622pat tmutf
1623n = rdinto 1
1624put mun 0 n
1625put mrc 0 0
1626is = ulong 0
1627ie = ulong 0
1628s = ulong 0
1629while lt s n bound 65536
1630e = s
1631while lt e n bound 65536
1632if eq get mu e 10
1633break
1634end
1635e = add e 1
1636end
1637p1 = bar s e
1638p2 = bar add p1 1 e
1639p3 = bar add p2 1 e
1640if lt p3 e
1641if gt get mrc 0 0
1642if not mideq is ie s p1
1643mrun is ie
1644end
1645end
1646r = get mrc 0
1647if lt r 4
1648put mru r munum add p1 1 p2
1649put mro mul r 4 add p2 1
1650put mro add mul r 4 1 p3
1651put mro add mul r 4 2 add p3 1
1652put mro add mul r 4 3 e
1653put mrc 0 add r 1
1654end
1655is = s
1656ie = p1
1657end
1658s = add e 1
1659end
1660if gt get mrc 0 0
1661mrun is ie
1662end
1663end
1664
1665note ---- robustness: rob ID KIND FILE CMD [ARG], KIND zip or xml; runs opdf CMD build/gate/rob.in [ARG] ----
1666text tcut " cut at "
1667text tflip " flip at "
1668text tcode " exit "
1669text tbase " the unchanged input exits "
1670
1671fn allowed c ulong to bool
1672if eq c 0
1673ret true
1674end
1675if and ge c 10 le c 22
1676ret true
1677end
1678if and ge c 30 le c 32
1679ret true
1680end
1681ret and ge c 60 le c 68
1682end
1683
1684note robexec: run the case's command on build/gate/rob.in with stdout to pa; the status.
1685fn robexec to ulong
1686pkreset
1687pkt tooff
1688pkcs get fs 4 get fe 4
1689pkt trob
1690if gt get nf 0 5
1691pkcs get fs 5 get fe 5
1692end
1693put pbn 0 0
1694ret spawn terr TLIM
1695end
1696
1697note robrun: one changed input; base is the unchanged input's status (its stdout is build/gate/rob.ref).
1698fn robrun base ulong what view uchar * pos ulong to void
1699pat tout
1700st = robexec
1701put cnt 30 add get cnt 30 1
1702plain = true
1703bad = false
1704if not allowed st
1705bad = true
1706else
1707if eq st 0
1708same0 = false
1709if eq base 0
1710pbt tref
1711pat tout
1712same0 = same
1713end
1714if same0
1715put cnt 32 add get cnt 32 1
1716else
1717if not plain
1718bad = true
1719else
1720if eq base 0
1721put cnt 33 add get cnt 33 1
1722else
1723put cnt 36 add get cnt 36 1
1724end
1725end
1726end
1727else
1728put cnt 31 add get cnt 31 1
1729put cnt add 64 st add get cnt add 64 st 1
1730end
1731end
1732if bad
1733put cnt 34 add get cnt 34 1
1734fail1 1
1735say what
1736saynum pos
1737say tcode
1738saynum st
1739say tnl
1740end
1741end
1742
1743fn robline to void
1744put pan 0 0
1745pacs get fs 3 get fe 3
1746n = rdinto 3
1747wrrob n
1748pat tref
1749base = robexec
1750if not allowed base
1751fail1 1
1752say tbase
1753saynum base
1754say tnl
1755ret
1756end
1757for k ulong 64
1758c = div mul n k 64
1759wrrob c
1760robrun base tcut c
1761end
1762for k ulong 256
1763p = div mul n k 256
1764if lt p n
1765v = get rb p
1766m = uchar 255
1767if eq rem k 2 0
1768m = uchar shl ulong 1 rem div k 2 8
1769end
1770put rb p xor v m
1771wrrob n
1772robrun base tflip p
1773put rb p v
1774end
1775end
1776end
1777
1778fn robust to void
1779s = ulong 0
1780n = get csn 0
1781while lt s n bound 262144
1782e = s
1783while lt e n bound 262144
1784if eq get cs e 10
1785break
1786end
1787e = add e 1
1788end
1789fields s e
1790s = add e 1
1791if ge get nf 0 5
1792if fis 0 trobw
1793put cnt 35 add get cnt 35 1
1794robline
1795end
1796end
1797end
1798end
1799
1800note ---- report ----
1801text r1 "OPDFGATE cases passed: pdfinfo-info="
1802text r2 " pdftotext="
1803text r3 " exact="
1804text r4 " pdfinfo-pages="
1805text r4b " gs-checker="
1806text r4c " same-as-previous="
1807text r4d " writes="
1808text r4e " info-strings-not-compared="
1809text r5 "; refusals passed: pdf="
1810text r6 " writer="
1811text r7 " deflate-and-io="
1812text r7b " usage="
1813text r8 "OPDFGATE mutants="
1814text r9 " killed="
1815text r10 "OPDFGATE robustness files="
1816text r11 " runs="
1817text r12 " refused="
1818text r13 " exact="
1819text r14 " changed-exit0="
1820text r14b " accepted-after-change="
1821text r15 " failures="
1822text r16 "OPDFGATE robustness exit codes:"
1823text r17 "OPDFGATE PASS cases="
1824text r18 " mutants-killed="
1825text r19 " robust-runs="
1826text r20 "OPDFGATE FAIL failures="
1827text tslsh "/"
1828text tcolon ":"
1829
1830fn report to int
1831say r1
1832saynum get cnt 0
1833say r2
1834saynum get cnt 1
1835say r3
1836saynum get cnt 2
1837say r4
1838saynum get cnt 3
1839say r4b
1840saynum get cnt 4
1841say r4c
1842saynum get cnt 5
1843say r4d
1844saynum get cnt 6
1845say r4e
1846saynum get cnt 40
1847say r5
1848saynum get cnt 8
1849say r6
1850saynum get cnt 9
1851say r7
1852saynum get cnt 10
1853say r7b
1854saynum get cnt 11
1855say tnl
1856say r8
1857saynum get cnt 20
1858say r9
1859saynum get cnt 21
1860say tnl
1861say r10
1862saynum get cnt 35
1863say r11
1864saynum get cnt 30
1865say r12
1866saynum get cnt 31
1867say r13
1868saynum get cnt 32
1869say r14
1870saynum get cnt 33
1871say r14b
1872saynum get cnt 36
1873say r15
1874saynum get cnt 34
1875say tnl
1876say r16
1877for c ulong 128
1878if gt get cnt add 64 c 0
1879say tsp
1880saynum c
1881say tcolon
1882saynum get cnt add 64 c
1883end
1884end
1885say tnl
1886t = add add add get cnt 0 get cnt 1 get cnt 2 get cnt 3
1887t = add t add add get cnt 4 get cnt 5 get cnt 6
1888t = add t add add add get cnt 8 get cnt 9 get cnt 10 get cnt 11
1889if eq get failn 0 0
1890say r17
1891saynum t
1892say r18
1893saynum get cnt 21
1894say tslsh
1895saynum get cnt 20
1896say r19
1897saynum get cnt 30
1898say tnl
1899ret 0
1900end
1901say r20
1902saynum get failn 0
1903say tnl
1904ret 1
1905end
1906
1907text tdocsrc "tests/docs.om"
1908text tdocbin "build/gate/docs"
1909text tdocout "build/gate/docs.out"
1910text tdocfail "OPDFGATE FAIL tests/docs.om (publication checks) exit "
1911
1912note docs: step 6 of the head note; a failure counts in failn.
1913fn docs to void
1914pbt tdocsrc
1915pkreset
1916pkom
1917pat tdocbin
1918st = spawn terr CLIM
1919if ne st 0
1920pat tdocbin
1921die tcompile
1922end
1923pat tdocbin
1924r = chmod pa 0 get pan 0 493
1925pkreset
1926pkpa
1927put pbn 0 0
1928pat tdocout
1929st2 = spawn terr TLIM
1930pat tdocout
1931n = rdinto 3
1932w = write 1 rb 0 n
1933if ne st2 0
1934put failn 0 add get failn 0 1
1935say tdocfail
1936saynum st2
1937say tnl
1938end
1939end
1940
1941fn main to int
1942if lt argcnt 2
1943say tnoomc
1944say tnl
1945ret 3
1946end
1947k = argread 1 om 0 4096
1948if le k 0
1949say tnoomc
1950say tnl
1951ret 3
1952end
1953put omn 0 ulong k
1954if not pinok
1955say tnotrun
1956say tbadpin
1957say PIN
1958say tnl
1959ret 3
1960end
1961pat tbuild
1962mkd
1963pat tgdir
1964wipepa
1965pat tgdir
1966mkd
1967docs
1968pat tcases
1969put csn 0 rdinto 0
1970put mrc 0 0
1971if not build tooff
1972pat tooff
1973die tcompile
1974end
1975bad = runall tooff false false true
1976keep40 = get cnt 40
1977if eq bad 0
1978mutants
1979put cnt 40 keep40
1980else
1981say tnomut
1982end
1983robust
1984ret report
1985end