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