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