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-mv/blob/main/bridge/omega-bridge/tests/native/x86/check_receipt_test.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / bridge / omega-bridge / tests / native / x86 / check_receipt_test.om` 964 lines ยท 18024 bytes Raw Blame History 1 om2 2 note check_receipt_test.om: the gate for tests/native/x86/check_physical_receipt.om (DRA-104). 3 note usage: check_receipt_test OMC WORKDIR, run from the repository root. OMC must be the seeded omc 4 note (omega-mv `e5b32567`, sha256 `2c824805`...); WORKDIR is an empty scratch directory this program fills. 5 note It compiles the checker with OMC, then runs it on every committed fixture and compares the whole 6 note output with tests/native/x86/receipt-fixtures/expected/NAME.out, which the replaced Python checker 7 note (git `6d5c0ddb`, ORACLE, not shipped) produced; then runs the cases that need a scratch copy (one log 8 note byte appended, renamed receipt, missing receipt, argument counts) by exit status and one line. 9 note Negative controls: two mutants of the checker (the log sha256 comparison always passing, the 10 note EMULATED scan switched off) are compiled and must each fail at least one case. 11 note Output: CHECK-RECEIPT-TEST PASS (exit 0) or FAIL lines and CHECK-RECEIPT-TEST FAIL (exit 1); 12 note a wrong compiler hash exits 65, a usage or setup error exits 2. 13 global fbuf uchar `4194304` 14 global hexo uchar 64 15 global eb uchar `1048576` 16 global ob uchar `1048576` 17 global pk uchar 4096 18 global wd uchar 4096 19 global omc uchar 4096 20 global pa uchar 4096 21 global pb uchar 4096 22 global cb uchar 4096 23 global gv ulong 16 24 const WDN ulong 0 25 const OMN ulong 1 26 const PKN ulong 2 27 const PAN ulong 3 28 const PBN ulong 4 29 const BAD ulong 5 30 const CAUGHT ulong 6 31 const CASES ulong 7 32 const FCAP ulong `4194304` 33 const CBN ulong 8 34 const MUT ulong 9 35 const ON ulong 10 36 note SHA-256 (FIPS 180-4) of fbuf[0..n), digest as 64 lowercase hex bytes in hexo[0..64). 37 note The schedule, round and padding code is copied from omega-mv `e5b32567` om/sha256/sha256-om2.om 38 note (Apache-2.0), changed only to read the message from the global fbuf instead of an unsized view. 39 fn kinit k edit uint 64 to void 40 put k 0 0x428a2f98 41 put k 1 0x71374491 42 put k 2 0xb5c0fbcf 43 put k 3 0xe9b5dba5 44 put k 4 0x3956c25b 45 put k 5 0x59f111f1 46 put k 6 0x923f82a4 47 put k 7 0xab1c5ed5 48 put k 8 0xd807aa98 49 put k 9 0x12835b01 50 put k 10 0x243185be 51 put k 11 0x550c7dc3 52 put k 12 0x72be5d74 53 put k 13 0x80deb1fe 54 put k 14 0x9bdc06a7 55 put k 15 0xc19bf174 56 put k 16 0xe49b69c1 57 put k 17 0xefbe4786 58 put k 18 0x0fc19dc6 59 put k 19 0x240ca1cc 60 put k 20 0x2de92c6f 61 put k 21 0x4a7484aa 62 put k 22 0x5cb0a9dc 63 put k 23 0x76f988da 64 put k 24 0x983e5152 65 put k 25 0xa831c66d 66 put k 26 0xb00327c8 67 put k 27 0xbf597fc7 68 put k 28 0xc6e00bf3 69 put k 29 0xd5a79147 70 put k 30 0x06ca6351 71 put k 31 0x14292967 72 put k 32 0x27b70a85 73 put k 33 0x2e1b2138 74 put k 34 0x4d2c6dfc 75 put k 35 0x53380d13 76 put k 36 0x650a7354 77 put k 37 0x766a0abb 78 put k 38 0x81c2c92e 79 put k 39 0x92722c85 80 put k 40 0xa2bfe8a1 81 put k 41 0xa81a664b 82 put k 42 0xc24b8b70 83 put k 43 0xc76c51a3 84 put k 44 0xd192e819 85 put k 45 0xd6990624 86 put k 46 0xf40e3585 87 put k 47 0x106aa070 88 put k 48 0x19a4c116 89 put k 49 0x1e376c08 90 put k 50 0x2748774c 91 put k 51 0x34b0bcb5 92 put k 52 0x391c0cb3 93 put k 53 0x4ed8aa4a 94 put k 54 0x5b9cca4f 95 put k 55 0x682e6ff3 96 put k 56 0x748f82ee 97 put k 57 0x78a5636f 98 put k 58 0x84c87814 99 put k 59 0x8cc70208 100 put k 60 0x90befffa 101 put k 61 0xa4506ceb 102 put k 62 0xbef9a3f7 103 put k 63 0xc67178f2 104 end 105 fn iv s edit uint 8 to void 106 put s 0 0x6a09e667 107 put s 1 0xbb67ae85 108 put s 2 0x3c6ef372 109 put s 3 0xa54ff53a 110 put s 4 0x510e527f 111 put s 5 0x9b05688c 112 put s 6 0x1f83d9ab 113 put s 7 0x5be0cd19 114 end 115 fn sched w edit uint 64 o ulong to void 116 q = ulong 0 117 x = uint 0 118 y = uint 0 119 for i ulong 16 unroll 120 q = add o mul i 4 121 x = uint get fbuf q 122 x = or shl x 8 uint get fbuf add q 1 123 x = or shl x 8 uint get fbuf add q 2 124 put w i or shl x 8 uint get fbuf add q 3 125 end 126 for i ulong 48 unroll 127 x = get w add i 1 128 y = get w add i 14 129 x = add add get w i get w add i 9 xor xor rotr x 7 rotr x 18 shr x 3 130 put w add i 16 add x xor xor rotr y 17 rotr y 19 shr y 10 131 end 132 end 133 fn schedp w edit uint 64 p view uchar 128 o ulong to void 134 q = ulong 0 135 x = uint 0 136 y = uint 0 137 for i ulong 16 unroll 138 q = add o mul i 4 139 x = uint get p q 140 x = or shl x 8 uint get p add q 1 141 x = or shl x 8 uint get p add q 2 142 put w i or shl x 8 uint get p add q 3 143 end 144 for i ulong 48 unroll 145 x = get w add i 1 146 y = get w add i 14 147 x = add add get w i get w add i 9 xor xor rotr x 7 rotr x 18 shr x 3 148 put w add i 16 add x xor xor rotr y 17 rotr y 19 shr y 10 149 end 150 end 151 fn rounds s edit uint 8 w view uint 64 kt view uint 64 to void 152 a = get s 0 153 b = get s 1 154 c = get s 2 155 d = get s 3 156 e = get s 4 157 f = get s 5 158 g = get s 6 159 h = get s 7 160 t = uint 0 161 for i ulong 64 unroll 162 h = add h get kt i 163 h = add h get w i 164 t = xor rotr e 6 rotr e 11 165 t = xor t rotr e 25 166 h = add h t 167 h = add h xor g and e xor f g 168 d = add d h 169 t = xor rotr a 2 rotr a 13 170 t = xor t rotr a 22 171 h = add h t 172 t = and c or a b 173 h = add h or and a b t 174 t = h 175 h = g 176 g = f 177 f = e 178 e = d 179 d = c 180 c = b 181 b = a 182 a = t 183 end 184 put s 0 add get s 0 a 185 put s 1 add get s 1 b 186 put s 2 add get s 2 c 187 put s 3 add get s 3 d 188 put s 4 add get s 4 e 189 put s 5 add get s 5 f 190 put s 6 add get s 6 g 191 put s 7 add get s 7 h 192 end 193 text hexd "`0123456789abcdef`" 194 fn hexout s view uint 8 to void 195 for i ulong 8 196 v = get s i 197 for j2 ulong 8 198 sh = sub uint 28 mul uint j2 4 199 d = ulong and shr v sh 15 200 q = add mul i 8 j2 201 put hexo q get hexd d 202 end 203 end 204 end 205 fn tailblk s edit uint 8 w edit uint 64 kt view uint 64 n ulong to void 206 p = new uchar 128 0 207 off = shl shr n 6 6 208 k = sub n off 209 for i ulong k 210 put p i get fbuf add off i 211 end 212 put p k 0x80 213 e = ulong 64 214 if ge k 56 215 e = 128 216 end 217 bits = shl n 3 218 for i ulong 8 unroll 219 put p sub e add i 1 uchar and shr bits mul i 8 0xff 220 end 221 schedp w view p 0 222 rounds s view w kt 223 if eq e 128 224 schedp w view p 64 225 rounds s view w kt 226 end 227 end 228 fn shafbuf n ulong to void 229 s = new uint 8 0 230 w = new uint 64 0 231 kt = new uint 64 0 232 kinit kt 233 iv s 234 nbl = shr n 6 235 j = ulong 0 236 while lt j nbl bound 999999 237 sched w shl j 6 238 rounds s view w view kt 239 j = add j 1 240 end 241 tailblk s w view kt n 242 hexout view s 243 end 244 245 text tline "\n" 246 fn say t view uchar * to void 247 w = write 1 t 0 len t 248 end 249 fn sayln t view uchar * to void 250 say t 251 say tline 252 end 253 note ---- path builder: pa = WORKDIR "/" name ---- 254 fn pab b uchar to void 255 k = get gv PAN 256 put pa k b 257 put gv PAN add k 1 258 end 259 fn pat t view uchar * to void 260 for i ulong len t 261 pab get t i 262 end 263 end 264 fn wpath t view uchar * to void 265 put gv PAN 0 266 k = get gv WDN 267 for i ulong k 268 pab get wd i 269 end 270 pab 47 271 pat t 272 end 273 fn pbcopy to void 274 k = get gv PAN 275 for i ulong k 276 put pb i get pa i 277 end 278 put gv PBN k 279 end 280 note ---- packed argument list in pk: u16 count, then u16 length and bytes per argument ---- 281 fn pkstart to void 282 put pk 0 0 283 put pk 1 0 284 put gv PKN 2 285 end 286 fn pkb b uchar to void 287 k = get gv PKN 288 put pk k b 289 put gv PKN add k 1 290 end 291 fn pkcnt to void 292 c = add ulong get pk 0 shl ulong get pk 1 8 293 c = add c 1 294 put pk 0 uchar and c 255 295 put pk 1 uchar shr c 8 296 end 297 fn pkt t view uchar * to void 298 pkcnt 299 n = len t 300 pkb uchar and n 255 301 pkb uchar shr n 8 302 for i ulong n 303 pkb get t i 304 end 305 end 306 fn pkpa to void 307 pkcnt 308 n = get gv PAN 309 pkb uchar and n 255 310 pkb uchar shr n 8 311 for i ulong n 312 pkb get pa i 313 end 314 end 315 note ---- files ---- 316 fn rdinto t view uchar * to long 317 fd = fopen t 0 len t 0 0 318 if lt fd 0 319 ret fd 320 end 321 n = ulong 0 322 go = true 323 while go bound 999999 324 r = read int fd fbuf n sub FCAP n 325 if le r 0 326 go = false 327 else 328 n = add n ulong r 329 end 330 if eq n FCAP 331 go = false 332 end 333 end 334 c = fclose int fd 335 ret long n 336 end 337 fn rdpa to long 338 fd = fopen pa 0 get gv PAN 0 0 339 if lt fd 0 340 ret fd 341 end 342 n = ulong 0 343 go = true 344 while go bound 999999 345 r = read int fd fbuf n sub FCAP n 346 if le r 0 347 go = false 348 else 349 n = add n ulong r 350 end 351 if eq n FCAP 352 go = false 353 end 354 end 355 c = fclose int fd 356 ret long n 357 end 358 fn wrpa n ulong to bool 359 fd = fopen pa 0 get gv PAN 577 420 360 if lt fd 0 361 ret false 362 end 363 o = ulong 0 364 while lt o n bound 999999 365 w = write int fd fbuf o sub n o 366 if le w 0 367 c = fclose int fd 368 ret false 369 end 370 o = add o ulong w 371 end 372 c2 = fclose int fd 373 ret true 374 end 375 note copy file t (relative to the repository root) to pa 376 fn cpto t view uchar * to bool 377 n = rdinto t 378 if lt n 0 379 ret false 380 end 381 ret wrpa ulong n 382 end 383 note ---- child processes: stdin, stdout and stderr redirected, exit status returned ---- 384 fn waitst pid long to long 385 st = new uchar 8 0 386 r = waitpid int pid st 0 8 0 387 if lt r 0 388 ret -1 389 end 390 s = ulong get st 0 391 if ne and s 127 0 392 ret long add 1000 and s 127 393 end 394 ret long get st 1 395 end 396 note run pk with stdin from pb (or /dev/null when PBN is 0) and stdout to pa; stderr to WORKDIR/err 397 text tnull "/dev/null" 398 text terr "err" 399 fn spawn to long 400 pid = fork 401 if lt pid 0 402 ret -1 403 end 404 if eq pid 0 405 i = int 0 406 if eq get gv PBN 0 407 i = int fopen tnull 0 len tnull 0 0 408 else 409 i = int fopen pb 0 get gv PBN 0 0 410 end 411 o = int fopen pa 0 get gv PAN 577 493 412 if or lt i 0 lt o 0 413 exit 120 414 end 415 d0 = dupfd i 0 0 416 d1 = dupfd o 1 0 417 wpath terr 418 e = int fopen pa 0 get gv PAN 577 420 419 d2 = dupfd e 2 0 420 x = execprog pk 0 get gv PKN 421 exit 121 422 end 423 ret waitst pid 424 end 425 426 fn pkbuf which ulong to void 427 pkcnt 428 n = get gv OMN 429 if eq which 1 430 n = get gv CBN 431 end 432 pkb uchar and n 255 433 pkb uchar shr n 8 434 for i ulong n 435 if eq which 1 436 pkb get cb i 437 else 438 pkb get omc i 439 end 440 end 441 end 442 note compile the source at pb into pa with the seeded compiler 443 fn compile to bool 444 pkstart 445 pkbuf 0 446 rc = spawn 447 ret eq rc 0 448 end 449 fn setcb to void 450 k = get gv PAN 451 for i ulong k 452 put cb i get pa i 453 end 454 put gv CBN k 455 end 456 note ---- one case: the checker's stdout is read into ob (ON bytes) ---- 457 text tout "out" 458 fn runchk to long 459 put gv PBN 0 460 wpath tout 461 rc = spawn 462 n = rdpa 463 put gv ON 0 464 if ge n 0 465 for i ulong ulong n 466 put ob i get fbuf i 467 end 468 put gv ON ulong n 469 end 470 ret rc 471 end 472 text tfcase "FAIL case " 473 text tgotrc " exit " 474 fn bad name view uchar * rc long to void 475 put gv BAD add get gv BAD 1 476 if eq get gv MUT 0 477 say tfcase 478 say name 479 say tgotrc 480 v = ulong rc 481 if lt rc 0 482 v = 999 483 end 484 sayn v 485 say tline 486 end 487 end 488 fn sayn v ulong to void 489 d = new uchar 24 0 490 x = v 491 k = ulong 0 492 go = true 493 while go bound 30 494 put d k uchar add 48 rem x 10 495 k = add k 1 496 x = div x 10 497 go = gt x 0 498 end 499 while gt k 0 bound 30 500 k = sub k 1 501 w = write 1 d k 1 502 end 503 end 504 fn hasob t view uchar * to bool 505 n = get gv ON 506 m = len t 507 if lt n m 508 ret false 509 end 510 s = ulong 0 511 while le s sub n m bound 999999 512 ok = true 513 for i ulong m 514 if ok 515 if ne get ob add s i get t i 516 ok = false 517 end 518 end 519 end 520 if ok 521 ret true 522 end 523 s = add s 1 524 end 525 ret false 526 end 527 text tacc "PHYSICAL-RECEIPT ACCEPTED" 528 text texp "tests/native/x86/receipt-fixtures/expected/" 529 text tdotout ".out" 530 note compare the output with the golden file; its verdict line sets the expected exit status 531 fn golden name view uchar * to void 532 rc = runchk 533 put gv PAN 0 534 pat texp 535 pat name 536 pat tdotout 537 n = rdpa 538 if lt n 0 539 bad name -2 540 ret 541 end 542 k = ulong n 543 ok = eq k get gv ON 544 for i ulong k 545 put eb i get fbuf i 546 end 547 if ok 548 for i ulong k 549 if ne get eb i get ob i 550 ok = false 551 end 552 end 553 end 554 want = long 1 555 put gv ON k 556 for i ulong k 557 put ob i get eb i 558 end 559 if hasob tacc 560 want = 0 561 end 562 if or not ok ne rc want 563 bad name rc 564 end 565 end 566 fn pkchk to void 567 pkstart 568 pkbuf 1 569 end 570 text tfx "tests/native/x86/receipt-fixtures/" 571 text tev "evidence/" 572 text taccl "tests/native/x86/receipt-fixtures/accept/native-x86-physical-`be8c5130`" 573 fn g1 name view uchar * r view uchar * to void 574 pkchk 575 pkt r 576 golden name 577 end 578 text tedge "tests/native/x86/receipt-fixtures/edge/" 579 text tpj "/native-x86-physical-`be8c5130`.json" 580 text tedp "edge-" 581 fn gedge e view uchar * to void 582 pkchk 583 put gv PAN 0 584 pat tedge 585 pat e 586 pat tpj 587 pkpa 588 pkt taccl 589 put gv PAN 0 590 pat tedp 591 pat e 592 k = get gv PAN 593 for i ulong k 594 put pb i get pa i 595 end 596 put gv PBN k 597 gedge2 k 598 end 599 fn gedge2 k ulong to void 600 nm = new uchar 4096 0 601 for i ulong k 602 put nm i get pb i 603 end 604 golden part nm 0 k 605 end 606 607 note ---- scratch cases ---- 608 text tapp "app" 609 text tappd "app/native-x86-physical-`be8c5130`" 610 text tappj "app/native-x86-physical-`be8c5130`.json" 611 text tappr "app/receipt.json" 612 text tnone "none.json" 613 text taccj "tests/native/x86/receipt-fixtures/accept/native-x86-physical-`be8c5130`.json" 614 text tl0 "x86-native.log" 615 text tl1 "x86-native-controls.log" 616 text tl2 "x86-native-wrongpin.log" 617 text tl3 "x86-native-mut.log" 618 text tsl "/" 619 text tcopy "scratch-copy-accepted" 620 text tren "renamed-receipt" 621 text tappc "appended-log-byte" 622 text tmiss "missing-receipt" 623 text tinv "invalid-json" 624 text tu0 "usage-no-argument" 625 text tu3 "usage-three-arguments" 626 text tvren "PHYSICAL-RECEIPT REJECTED (1 failed: file name carries the x86 pin prefix)\n" 627 text tvapp "PHYSICAL-RECEIPT REJECTED (1 failed: log x86-native-mut.log sha256 matches receipt)\n" 628 text tvmiss "FAIL receipt is readable JSON (open or read failed: errno 2)\n" 629 text tvinv "FAIL receipt is readable JSON (invalid JSON near byte 13)\n" 630 text tinvp "tests/native/x86/receipt-fixtures/edge/invalid-json/native-x86-physical-`be8c5130`.json" 631 fn cplog t view uchar * to bool 632 put gv PAN 0 633 pat taccl 634 pat tsl 635 pat t 636 n = rdpa 637 if lt n 0 638 ret false 639 end 640 wpath tappd 641 pat tsl 642 pat t 643 ret wrpa ulong n 644 end 645 fn expect name view uchar * want long line view uchar * to void 646 rc = runchk 647 if or ne rc want not hasob line 648 bad name rc 649 end 650 end 651 fn setup to bool 652 wpath tapp 653 m = makedir pa 0 get gv PAN 493 654 wpath tappd 655 m2 = makedir pa 0 get gv PAN 493 656 wpath tappj 657 if not cpto taccj 658 ret false 659 end 660 wpath tappr 661 if not cpto taccj 662 ret false 663 end 664 ok = and and cplog tl0 cplog tl1 and cplog tl2 cplog tl3 665 ret ok 666 end 667 fn pkw t view uchar * to void 668 wpath t 669 pkpa 670 end 671 fn appendbyte to bool 672 wpath tappd 673 pat tsl 674 pat tl3 675 n = rdpa 676 if lt n 0 677 ret false 678 end 679 put fbuf ulong n 120 680 ret wrpa add ulong n 1 681 end 682 fn scratch to void 683 pkchk 684 pkw tappj 685 expect tcopy 0 tacc 686 pkchk 687 pkw tappr 688 pkw tappd 689 expect tren 1 tvren 690 pkchk 691 pkw tnone 692 expect tmiss 1 tvmiss 693 pkchk 694 pkt tinvp 695 expect tinv 1 tvinv 696 pkchk 697 rc = runchk 698 if or ne rc 2 ne get gv ON 0 699 bad tu0 rc 700 end 701 pkchk 702 pkt tinvp 703 pkt tinvp 704 pkt tinvp 705 rc2 = runchk 706 if or ne rc2 2 ne get gv ON 0 707 bad tu3 rc2 708 end 709 end 710 fn scratch2 to void 711 pkchk 712 pkw tappj 713 expect tappc 1 tvapp 714 end 715 text tg1 "committed-`be8c5130`" 716 text tr1 "evidence/native-x86-`be8c5130`.json" 717 text tg2 "emulated-receipt" 718 text tr2 "evidence/native-x86-physical-checker/emulated-receipt.json" 719 text tg3 "forged-receipt-evidence" 720 text tr3 "evidence/native-x86-physical-checker/forged-receipt.json" 721 text tg4 "accept" 722 text tg5 "forged" 723 text tr5 "tests/native/x86/receipt-fixtures/forged/native-x86-physical-`be8c5130`.json" 724 text te1 "dup-key-last-wins" 725 text te2 "dup-key-dead-emulated" 726 text te3 "escaped-label" 727 text te4 "repr-strings" 728 text te5 "repr-nested" 729 text te6 "exit-forms" 730 text te7 "exit-wrong-types" 731 text te8 "schema-true" 732 text te9 "three-commands" 733 text te10 "host-not-object" 734 text te11 "blank-fields" 735 text te12 "emulated-in-key" 736 text te13 "not-object" 737 note every case; the scratch copy must be fresh (setup) and the byte is appended last 738 fn allcases to bool 739 if not setup 740 ret false 741 end 742 g1 tg1 tr1 743 g1 tg2 tr2 744 g1 tg3 tr3 745 g1 tg4 taccj 746 g1 tg5 tr5 747 gedge te1 748 gedge te2 749 gedge te3 750 gedge te4 751 gedge te5 752 gedge te6 753 gedge te7 754 gedge te8 755 gedge te9 756 gedge te10 757 gedge te11 758 gedge te12 759 gedge te13 760 scratch 761 if not appendbyte 762 ret false 763 end 764 scratch2 765 ret true 766 end 767 note ---- checker mutants (negative controls) ---- 768 text tsrc "tests/native/x86/check_physical_receipt.om" 769 text tm1a "if ne get pool add o i get hexo i\nok = false" 770 text tm1b "if ne get pool add o i get hexo i\nok = true" 771 text tm2a "chk tnoemu not sayemu" 772 text tm2b "chk tnoemu true" 773 text tm1 "m1.om" 774 text tm1x "m1" 775 text tm2 "m2.om" 776 text tm2x "m2" 777 fn atf p ulong t view uchar * n ulong to bool 778 if gt add p len t n 779 ret false 780 end 781 for i ulong len t 782 if ne get fbuf add p i get t i 783 ret false 784 end 785 end 786 ret true 787 end 788 fn putb o ulong b view uchar * to ulong 789 for i ulong len b 790 put eb add o i get b i 791 end 792 ret add o len b 793 end 794 note write the checker source with the one occurrence of a replaced by b to pa; false unless exactly one 795 fn subst a view uchar * b view uchar * n ulong to ulong 796 hits = ulong 0 797 o = ulong 0 798 p = ulong 0 799 while lt p n bound 999999 800 if atf p a n 801 hits = add hits 1 802 o = putb o b 803 p = add p len a 804 else 805 put eb o get fbuf p 806 o = add o 1 807 p = add p 1 808 end 809 end 810 if ne hits 1 811 ret 0 812 end 813 ret o 814 end 815 fn mutate a view uchar * b view uchar * to bool 816 pan = get gv PAN 817 put gv PBN pan 818 for i ulong pan 819 put pb i get pa i 820 end 821 r = rdinto tsrc 822 if lt r 0 823 ret false 824 end 825 o = subst a b ulong r 826 if eq o 0 827 ret false 828 end 829 for i ulong o 830 put fbuf i get eb i 831 end 832 pbn = get gv PBN 833 for i ulong pbn 834 put pa i get pb i 835 end 836 put gv PAN pbn 837 ret wrpa o 838 end 839 840 text tusage "usage: check_receipt_test OMC WORKDIR (run from the repository root)\n" 841 text tpin "`2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`" 842 text twrong "CHECK-RECEIPT-TEST FAIL omc sha256 is not the seeded omega-mv `e5b32567` compiler `2c824805`\n" 843 text tsetup "CHECK-RECEIPT-TEST FAIL setup: " 844 text tcpr "cpr" 845 text tccomp "compiling the checker" 846 text tmcomp "building a mutant" 847 text tscr "copying the scratch fixtures" 848 text tnc "FAIL mutant not caught: " 849 text tmc "MUTANT " 850 text tmby " caught by " 851 text tmcases " failing cases" 852 text tpass "CHECK-RECEIPT-TEST PASS (18 golden outputs, 7 scratch cases, 2 of 2 checker mutants caught)\n" 853 text tfail "CHECK-RECEIPT-TEST FAIL\n" 854 fn setupfail t view uchar * to int 855 say tsetup 856 sayln t 857 ret 2 858 end 859 fn rdarg i ulong which ulong to bool 860 if eq which 0 861 r = argread i omc 0 4096 862 put gv OMN ulong r 863 ret gt r 0 864 end 865 r2 = argread i wd 0 4096 866 put gv WDN ulong r2 867 ret gt r2 0 868 end 869 fn omcok to bool 870 put gv PAN 0 871 k = get gv OMN 872 for i ulong k 873 pab get omc i 874 end 875 n = rdpa 876 if lt n 0 877 ret false 878 end 879 shafbuf ulong n 880 for i ulong 64 881 if ne get hexo i get tpin i 882 ret false 883 end 884 end 885 ret true 886 end 887 note compile pb into WORKDIR/bin and make it the checker under test 888 fn build bin view uchar * to bool 889 wpath bin 890 if not compile 891 ret false 892 end 893 setcb 894 ret true 895 end 896 fn mutant src view uchar * bin view uchar * which ulong to int 897 wpath src 898 ok = false 899 if eq which 1 900 ok = mutate tm1a tm1b 901 else 902 ok = mutate tm2a tm2b 903 end 904 if not ok 905 ret 2 906 end 907 pbcopy 908 if not build bin 909 ret 2 910 end 911 put gv MUT 1 912 put gv BAD 0 913 if not allcases 914 ret 2 915 end 916 put gv MUT 0 917 if gt get gv BAD 0 918 say tmc 919 say src 920 say tmby 921 sayn get gv BAD 922 sayln tmcases 923 ret 1 924 end 925 say tnc 926 sayln src 927 ret 0 928 end 929 fn main to int 930 if ne argcnt 3 931 w = write 2 tusage 0 len tusage 932 ret 2 933 end 934 if not and rdarg 1 0 rdarg 2 1 935 w2 = write 2 tusage 0 len tusage 936 ret 2 937 end 938 if not omcok 939 say twrong 940 ret 65 941 end 942 put gv PAN 0 943 pat tsrc 944 pbcopy 945 if not build tcpr 946 ret setupfail tccomp 947 end 948 put gv BAD 0 949 if not allcases 950 ret setupfail tscr 951 end 952 cb1 = get gv BAD 953 m1 = mutant tm1 tm1x 1 954 m2 = mutant tm2 tm2x 2 955 if or eq m1 2 eq m2 2 956 ret setupfail tmcomp 957 end 958 if and eq cb1 0 and eq m1 1 eq m2 1 959 say tpass 960 ret 0 961 end 962 say tfail 963 ret 1 964 end