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