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/bench/omc_efficiency/selftest.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 / bench / omc_efficiency / selftest.om` 1077 lines ยท 19552 bytes Raw Blame History 1 note OMC-EFF conductor self-test (PROTOCOL.md, PROTOCOL-2.md, PROTOCOL-3.md), the Omega port of the former 2 note selftest.sh. It proves the conductor's checks can fail. No measured timing value is printed: wall, 3 note runtime and counter columns are only tested for presence, and runtime=123 comes from a synthetic 4 note fixture program. 5 note 6 note selftest OMC HERE SCRATCH 7 note OMC absolute path of the omc that builds the conductor, the kernels and the fixtures 8 note HERE absolute path of bench/omc_efficiency 9 note SCRATCH a directory that must not exist; it is created and becomes the working directory 10 note 11 note gcc runs as /usr/bin/gcc -B/usr/bin/ with an empty environment (execprog passes none). 12 note One line per check: PASS NAME rc=N EXPECTED, FAIL NAME rc=N EXPECTED got LINE, or NOT_RUN NAME REASON. 13 note Last line: SELFTEST fails=N not_run=N. Exit 0 when fails is 0, 1 otherwise, 2 for bad usage. 14 note counters_nonzero is NOT_RUN when /proc/sys/kernel/perf_event_paranoid is above 2 (unprivileged perf 15 note stat cannot count); NOT_RUN is reported, never counted as a pass. 16 om2 17 text tcond "conductor" 18 text tcondom "/conductor.om" 19 text tkern "/kernels/" 20 text twant "/want/" 21 text tom ".om" 22 text tc ".c" 23 text tout ".out" 24 text tsrc "src/" 25 text twd "want/" 26 text tbo "bin/omc/" 27 text tb2 "bin/cO2/" 28 text tb0 "bin/cO0/" 29 text tbn "bin/neg/" 30 text tfib "fib" 31 text tsieve "sieve" 32 text tom2 "om2/" 33 text tkom2 "/kernels/om2/" 34 text tnull "/dev/null" 35 text tcerr "child.err" 36 text tparan "/proc/sys/kernel/perf_event_paranoid" 37 text tdir1 "src" 38 text tdir2 "want" 39 text tdir3 "bin" 40 text tdir4 "bin/omc" 41 text tdir5 "bin/cO2" 42 text tdir6 "bin/cO0" 43 text tdir7 "bin/neg" 44 text tdir8 "src/om2" 45 text tdir9 "want/om2" 46 text tdir10 "bin/omc/om2" 47 text tdir11 "bin/cO2/om2" 48 text tdir12 "bin/cO0/om2" 49 text tdir13 "bin/neg/om2" 50 text tgo2 "/usr/bin/gcc -B/usr/bin/ -O2 -static -o" 51 text tgo0 "/usr/bin/gcc -B/usr/bin/ -O0 -static -o" 52 text tsp " " 53 text tnl "\n" 54 text tq "'" 55 text twrong "`39088168`\n" 56 text tx "x" 57 text frt0 "text ta \"`39088169`\\n\"\nfn main to int\nw = write 1 ta 0 len ta\nret 0\nend\n" 58 text frtb "text ta \"`39088169`\\n\"\ntext tb \"12x\\n\"\nfn main to int\nw = write 1 ta 0 len ta\nv = write 2 tb 0 len tb\nret 0\nend\n" 59 text frt1 "text ta \"`39088169`\\n\"\ntext tb \"123\\n\"\nfn main to int\nw = write 1 ta 0 len ta\nv = write 2 tb 0 len tb\nret 0\nend\n" 60 text frtc "fn main to int\nx = argcnt\nif gt x 0\ntrap 5\nend\nret 0\nend\n" 61 text tfxd "fx/" 62 text tn0 "nort" 63 text tnb "badrt" 64 text tn1 "rt123" 65 text tnc "crash" 66 text tfibo "fib.out" 67 text tkeepw "want.keep" 68 text tkeep2 "cO2.keep" 69 text tkeepd "cO2." 70 text tkeepn "keep" 71 text tP "P" 72 text tT "T" 73 text tH "H" 74 text tfxs "fx/src.om" 75 text tdirf "fx" 76 text rclean "./conductor run 1 0 7 1 4 omc cO2 cO0 neg fib sieve" 77 text rfib "./conductor run 1 0 7 1 4 omc cO2 cO0 neg fib" 78 text rbld "./conductor build 1 0 9 @ 3 omc cO2 cO0 fib" 79 text rom2 "./conductor run 1 0 7 1 4 omc cO2 cO0 neg om2/fib" 80 text rusage "./conductor run 1 0" 81 text rseed0 "./conductor run 1 0 0 1 4 omc cO2 cO0 neg fib" 82 text fok "ok.raw" 83 text fnc1 "nc1.raw" 84 text fnc2 "nc2.raw" 85 text fnc3 "nc3.raw" 86 text fb "b.raw" 87 text fnc4 "nc4.raw" 88 text fnc5 "nc5.raw" 89 text fok2 "ok2.raw" 90 text fnc6 "nc6.raw" 91 text fnc7 "nc7.raw" 92 text fom2 "om2.raw" 93 text fnull "/dev/null" 94 text n1 "clean_run" 95 text n2 "counters_nonzero" 96 text n3 "runtime_present" 97 text n4 "wrong_want" 98 text n5 "control_matches" 99 text n6 "wrong_reference" 100 text n7 "clean_build" 101 text n8 "no_runtime_line" 102 text n9 "bad_runtime_line" 103 text n10 "runtime_read_exactly" 104 text n11 "control_same_output_no_runtime_line" 105 text n12 "control_crashes" 106 text n13 "om2_profile_rows" 107 text n14 "om2_source_compiled" 108 text n15 "usage" 109 text n16 "seed_zero" 110 text n17 "counters_flag" 111 text tS "S rows=" 112 text tok " ok=" 113 text tfail " fail=" 114 text tdet " ctl_detected=" 115 text tmiss " ctl_missed=" 116 text tzr "zero_rows=" 117 text tbt "bad_T_rows=" 118 text trt " runtime=" 119 text tunl " unlabelled=" 120 text tdiff "om2_bytes=differs" 121 text tsame "om2_bytes=same" 122 text tcon "counters=on" 123 text tcoff "counters=off" 124 text tpass "PASS " 125 text tfl "FAIL " 126 text tnr "NOT_RUN " 127 text tparn " perf_event_paranoid>2" 128 text trc " rc=" 129 text tgot " got " 130 text tend "SELFTEST fails=" 131 text tnrun " not_run=" 132 text tneg "neg" 133 text tcO2 "cO2" 134 text tone "1" 135 text tzero "0" 136 text tofib "om2/fib" 137 text tusg "usage: selftest OMC HERE SCRATCH (absolute OMC and HERE; SCRATCH must not exist)\n" 138 text tsetup "selftest: setup step failed: " 139 note gpb: path or argument being built; gin/gou: the child's stdin and stdout paths; gpk: exec packet; 140 note glb: output line; gex: expected text of the current check; gfb, gf2: whole files 141 global gpb uchar 4096 142 global gpbn ulong 1 143 global gin uchar 4096 144 global ginn ulong 1 145 global gou uchar 4096 146 global goun ulong 1 147 global gpk uchar 8192 148 global gpkn ulong 1 149 global gpkc ulong 1 150 global glb uchar 4096 151 global glbn ulong 1 152 global gex uchar 1024 153 global gexn ulong 1 154 global gfb uchar `4194304` 155 global gf2 uchar `4194304` 156 global gst uchar 4 157 global gcnt ulong 5 158 note gcnt: 0 fails, 1 not_run, 2 counters on (1) / off (0), 3 bytes held by cpfrom, 4 exit code chk expects 159 160 note ---- path builder 161 fn pbclr to void 162 put gpbn 0 0 163 end 164 fn pbtext t view uchar * to void 165 n = get gpbn 0 166 if gt add n len t 4096 167 trap 9 168 end 169 for i ulong len t 170 put gpb add n i get t i 171 end 172 put gpbn 0 add n len t 173 end 174 fn pbarg idx ulong to void 175 n = get gpbn 0 176 r = argread idx gpb n sub 4096 n 177 if lt r 0 178 trap 9 179 end 180 put gpbn 0 add n ulong r 181 end 182 fn pbset t view uchar * to void 183 pbclr 184 pbtext t 185 end 186 note copy gpb into gin (stdin path) or gou (stdout path) 187 fn setin to void 188 n = get gpbn 0 189 for i ulong n 190 put gin i get gpb i 191 end 192 put ginn 0 n 193 end 194 fn setout to void 195 n = get gpbn 0 196 for i ulong n 197 put gou i get gpb i 198 end 199 put goun 0 n 200 end 201 202 note ---- exec packet: u16 count, then records (u16 length, bytes); pkpush adds gpb as one record 203 fn pkreset to void 204 put gpk 0 0 205 put gpk 1 0 206 put gpkn 0 2 207 put gpkc 0 0 208 end 209 fn pkpush to void 210 n = get gpkn 0 211 m = get gpbn 0 212 if gt add add n m 2 8192 213 trap 9 214 end 215 put gpk n uchar and m 255 216 put gpk add n 1 uchar shr m 8 217 for i ulong m 218 put gpk add add n 2 i get gpb i 219 end 220 put gpkn 0 add add n m 2 221 c = add get gpkc 0 1 222 put gpkc 0 c 223 put gpk 0 uchar and c 255 224 put gpk 1 uchar shr c 8 225 end 226 note pkline: one record per space-separated word of t; the word @ stands for argument 1 (OMC) 227 fn pkline t view uchar * to void 228 pkreset 229 pbclr 230 for i ulong len t 231 c = get t i 232 if eq c 32 233 pkword 234 pbclr 235 else 236 put gpb get gpbn 0 c 237 put gpbn 0 add get gpbn 0 1 238 end 239 end 240 pkword 241 end 242 fn pkword to void 243 if eq get gpbn 0 0 244 ret 245 end 246 if and eq get gpbn 0 1 eq get gpb 0 64 247 pbclr 248 pbarg 1 249 end 250 pkpush 251 end 252 253 note ---- output line and expected text 254 fn lbtext t view uchar * to void 255 n = get glbn 0 256 if gt add n len t 4096 257 trap 9 258 end 259 for i ulong len t 260 put glb add n i get t i 261 end 262 put glbn 0 add n len t 263 end 264 fn lbnum v ulong to void 265 d = new uchar 24 0 266 p = ulong 24 267 x = v 268 while gt x 9 269 p = sub p 1 270 put d p uchar add rem x 10 48 271 x = div x 10 272 end 273 p = sub p 1 274 put d p uchar add x 48 275 n = get glbn 0 276 for i ulong sub 24 p 277 put glb add n i get d add p i 278 end 279 put glbn 0 add n sub 24 p 280 end 281 fn lbflush to void 282 lbtext tnl 283 w = write 1 glb 0 get glbn 0 284 put glbn 0 0 285 end 286 note move the line built so far into gex (the expected text of the next check) 287 fn lbtoex to void 288 n = get glbn 0 289 if gt n 1024 290 trap 9 291 end 292 for i ulong n 293 put gex i get glb i 294 end 295 put gexn 0 n 296 put glbn 0 0 297 end 298 299 note ---- files: rdin reads the file named by gpb into gfb (or gf2 when two is true); returns the size, 300 note `4194305` when it does not fit, `4194306` when it cannot be opened 301 fn rdin two bool to ulong 302 fd = fopen gpb 0 get gpbn 0 0 0 303 if lt fd 0 304 ret `4194306` 305 end 306 n = ulong 0 307 going = true 308 while going bound `999999999` 309 r = rdpart fd n two 310 if le r 0 311 going = false 312 else 313 n = add n ulong r 314 if eq n `4194304` 315 going = false 316 end 317 end 318 end 319 c = fclose int fd 320 if eq n `4194304` 321 ret `4194305` 322 end 323 ret n 324 end 325 fn rdpart fd long n ulong two bool to long 326 if two 327 ret read int fd gf2 n sub `4194304` n 328 end 329 ret read int fd gfb n sub `4194304` n 330 end 331 note write gfb[0 .. n) to the file named by gpb, then chmod it to mode; false on any failure 332 fn wrfb n ulong mode int to bool 333 fd = fopen gpb 0 get gpbn 0 577 mode 334 if lt fd 0 335 ret false 336 end 337 w = write int fd gfb 0 n 338 c = fclose int fd 339 if ne w long n 340 ret false 341 end 342 m = chmod gpb 0 get gpbn 0 mode 343 ret true 344 end 345 fn wrtext t view uchar * to bool 346 for i ulong len t 347 put gfb i get t i 348 end 349 ret wrfb len t 420 350 end 351 note copy the file at gpb (source) to the path pbset/pbtext builds next; cpbegin reads, cpend writes 352 fn cpbegin to ulong 353 n = rdin false 354 if ge n `4194305` 355 setfail tsetup 356 end 357 ret n 358 end 359 fn cpend n ulong to void 360 if not wrfb n 493 361 setfail tsetup 362 end 363 end 364 fn setfail t view uchar * to void 365 lbtext t 366 w = write 2 glb 0 get glbn 0 367 w2 = write 2 gpb 0 get gpbn 0 368 w3 = write 2 tnl 0 1 369 exit 1 370 end 371 372 note ---- one child: stdin gin, stdout gou, stderr child.err, exec gpk; returns the exit status 373 fn child to void 374 fi = fopen gin 0 get ginn 0 0 0 375 if lt fi 0 376 exit 120 377 end 378 r = dupfd int fi 0 0 379 if ne r 0 380 exit 121 381 end 382 fo = fopen gou 0 get goun 0 577 493 383 if lt fo 0 384 exit 122 385 end 386 r = dupfd int fo 1 0 387 if ne r 1 388 exit 123 389 end 390 fe = fopen tcerr 0 len tcerr 577 420 391 if lt fe 0 392 exit 124 393 end 394 r = dupfd int fe 2 0 395 if ne r 2 396 exit 125 397 end 398 r = execprog gpk 0 get gpkn 0 399 exit 126 400 end 401 fn runpk to ulong 402 pid = fork 403 if lt pid 0 404 trap 9 405 end 406 if eq pid 0 407 child 408 exit 127 409 end 410 r = waitpid int pid gst 0 4 0 411 if ne r pid 412 trap 9 413 end 414 s0 = ulong get gst 0 415 if ne and s0 127 0 416 ret add 1000 and s0 127 417 end 418 ret ulong get gst 1 419 end 420 note run the command line t with stdin /dev/null and stdout into file o 421 fn runline t view uchar * o view uchar * to ulong 422 pkline t 423 pbset tnull 424 setin 425 pbset o 426 setout 427 ret runpk 428 end 429 note omc < (path in gin) > (path in gou); exit status 430 fn omcrun to ulong 431 pkreset 432 pbclr 433 pbarg 1 434 pkpush 435 ret runpk 436 end 437 438 note ---- setup helpers 439 fn mkd t view uchar * to void 440 pbset t 441 r = makedir gpb 0 get gpbn 0 493 442 if lt r 0 443 setfail tsetup 444 end 445 end 446 note omc HERE/kernels/[om2/]CASE.om -> bin/omc/[om2/]CASE 447 fn bomc c view uchar * o2 bool to void 448 pbclr 449 pbarg 2 450 if o2 451 pbtext tkom2 452 else 453 pbtext tkern 454 end 455 pbtext c 456 pbtext tom 457 setin 458 pbset tbo 459 if o2 460 pbtext tom2 461 end 462 pbtext c 463 setout 464 if ne omcrun 0 465 setfail tsetup 466 end 467 end 468 note HERE/kernels/CASE.EXT -> src/CASE.EXT 469 fn cpsrc c view uchar * x view uchar * to void 470 pbclr 471 pbarg 2 472 pbtext tkern 473 pbtext c 474 pbtext x 475 n = cpbegin 476 pbset tsrc 477 pbtext c 478 pbtext x 479 cpend n 480 end 481 note gcc -Ox -static of src/CASE.c -> bin/cOx/CASE 482 fn gccone c view uchar * g view uchar * b view uchar * to void 483 pkline g 484 pbset b 485 pbtext c 486 pkpush 487 pbset tsrc 488 pbtext c 489 pbtext tc 490 pkpush 491 pbset tnull 492 setin 493 pbset tcerr 494 setout 495 if ne runpk 0 496 setfail tsetup 497 end 498 end 499 note copy a file in two steps: cpfrom reads (a1 a2) into gfb, cpto writes it to (b1 b2) 500 fn cpfrom a1 view uchar * a2 view uchar * to void 501 pbset a1 502 pbtext a2 503 put gcnt 3 cpbegin 504 end 505 fn cpto b1 view uchar * b2 view uchar * to void 506 pbset b1 507 pbtext b2 508 cpend get gcnt 3 509 end 510 note want/[om2/]CASE.out from HERE/want/CASE.out 511 fn cpwant c view uchar * o2 bool to void 512 pbclr 513 pbarg 2 514 pbtext twant 515 pbtext c 516 pbtext tout 517 n = cpbegin 518 pbset twd 519 if o2 520 pbtext tom2 521 end 522 pbtext c 523 pbtext tout 524 cpend n 525 end 526 note fixture program: source text s compiled by OMC into fx/NAME 527 fn fixture s view uchar * name view uchar * to void 528 pbset tfxs 529 if not wrtext s 530 setfail tsetup 531 end 532 setin 533 pbset tfxd 534 pbtext name 535 setout 536 if ne omcrun 0 537 setfail tsetup 538 end 539 end 540 541 note ---- reading raw rows: the last line of gfb[0 .. n) equals gex 542 fn lastis n ulong to bool 543 e = n 544 if and gt e 0 eq get gfb sub e 1 10 545 e = sub e 1 546 end 547 s = e 548 while and gt s 0 ne get gfb sub s 1 10 bound `999999999` 549 s = sub s 1 550 end 551 m = get gexn 0 552 if ne sub e s m 553 ret false 554 end 555 for i ulong m 556 if ne get gfb add s i get gex i 557 ret false 558 end 559 end 560 ret true 561 end 562 note append the last line of gfb[0 .. n) to glb 563 fn lblast n ulong to void 564 e = n 565 if and gt e 0 eq get gfb sub e 1 10 566 e = sub e 1 567 end 568 s = e 569 while and gt s 0 ne get gfb sub s 1 10 bound `999999999` 570 s = sub s 1 571 end 572 for i ulong sub e s bound `4194304` 573 m = get glbn 0 574 if lt m 4000 575 put glb m get gfb add s i 576 put glbn 0 add m 1 577 end 578 end 579 end 580 note fields of the line of gfb starting at s: starts in fs, lengths in fl; returns the field count 581 fn fields s ulong n ulong fs edit ulong 16 fl edit ulong 16 to ulong 582 k = ulong 0 583 i = s 584 going = true 585 while going bound `999999999` 586 if or ge i n eq get gfb i 10 587 going = false 588 else 589 if eq get gfb i 32 590 i = add i 1 591 else 592 j = fend i n 593 if lt k 16 594 put fs k i 595 put fl k sub j i 596 end 597 k = add k 1 598 i = j 599 end 600 end 601 end 602 ret k 603 end 604 fn fend i ulong n ulong to ulong 605 j = i 606 while lt j n bound `999999999` 607 c = get gfb j 608 if or eq c 32 eq c 10 609 ret j 610 end 611 j = add j 1 612 end 613 ret j 614 end 615 note field f equals text t 616 fn feq fs view ulong 16 fl view ulong 16 f ulong t view uchar * to bool 617 if ne get fl f len t 618 ret false 619 end 620 s = get fs f 621 for i ulong len t 622 if ne get gfb add s i get t i 623 ret false 624 end 625 end 626 ret true 627 end 628 fn fnum fs view ulong 16 fl view ulong 16 f ulong to ulong 629 v = ulong 0 630 s = get fs f 631 for i ulong get fl f 632 c = get gfb add s i 633 if or lt c 48 gt c 57 634 ret `18446744073709551615` 635 end 636 v = add mul v 10 ulong sub c 48 637 end 638 ret v 639 end 640 note scan the rows of gfb[0 .. n): kind 1 counts P rows with a zero counter, 2 counts T rows of a 641 note non-control arm without a valid runtime, 3 counts T/P rows not labelled om2/fib, 4 returns the 642 note runtime of the cO2 T row, 5 returns 1 when the H row ends with counters=on 643 fn scan n ulong kind ulong to ulong 644 fs = new ulong 16 0 645 fl = new ulong 16 0 646 cnt = ulong 0 647 s = ulong 0 648 while lt s n bound `999999999` 649 k = fields s n fs fl 650 if gt k 0 651 cnt = add cnt rowis kind k fs fl 652 end 653 s = nextln s n 654 end 655 ret cnt 656 end 657 fn nextln s ulong n ulong to ulong 658 i = s 659 while lt i n bound `999999999` 660 if eq get gfb i 10 661 ret add i 1 662 end 663 i = add i 1 664 end 665 ret n 666 end 667 fn rowis kind ulong k ulong fs view ulong 16 fl view ulong 16 to ulong 668 if gt k 16 669 ret 0 670 end 671 if eq kind 1 672 ret rowp k fs fl 673 end 674 if eq kind 2 675 ret rowt k fs fl 676 end 677 if eq kind 3 678 if or feq fs fl 0 tT feq fs fl 0 tP 679 if not feq fs fl 3 tofib 680 ret 1 681 end 682 end 683 ret 0 684 end 685 if eq kind 4 686 if and and feq fs fl 0 tT feq fs fl 4 tcO2 eq k 10 687 ret fnum fs fl 9 688 end 689 ret 0 690 end 691 if and feq fs fl 0 tH gt k 0 692 if feq fs fl sub k 1 tcon 693 ret 1 694 end 695 end 696 ret 0 697 end 698 fn rowp k ulong fs view ulong 16 fl view ulong 16 to ulong 699 if and feq fs fl 0 tP eq k 10 700 if or eq fnum fs fl 6 0 eq fnum fs fl 7 0 701 ret 1 702 end 703 end 704 ret 0 705 end 706 fn rowt k ulong fs view ulong 16 fl view ulong 16 to ulong 707 if and feq fs fl 0 tT not feq fs fl 4 tneg 708 if ne k 10 709 ret 1 710 end 711 if or not feq fs fl 8 tone feq fs fl 9 tzero 712 ret 1 713 end 714 end 715 ret 0 716 end 717 718 note ---- checks 719 fn report ok bool name view uchar * rc ulong gotn ulong to void 720 if ok 721 lbtext tpass 722 else 723 lbtext tfl 724 put gcnt 0 add get gcnt 0 1 725 end 726 lbtext name 727 lbtext trc 728 lbnum rc 729 lbtext tsp 730 m = get glbn 0 731 for i ulong get gexn 0 732 put glb add m i get gex i 733 end 734 put glbn 0 add m get gexn 0 735 if not ok 736 lbtext tgot 737 lbtext tq 738 if lt gotn `4194305` 739 lblast gotn 740 end 741 lbtext tq 742 end 743 lbflush 744 end 745 note expected summary: T-part (rows ok fail) plus P-part when counters are on, then detected, missed 746 fn exsum tr ulong tk ulong tf ulong pr ulong pk ulong pf ulong to void 747 r = tr 748 o = tk 749 f = tf 750 if eq get gcnt 2 1 751 r = add r pr 752 o = add o pk 753 f = add f pf 754 end 755 lbtext tS 756 lbnum r 757 lbtext tok 758 lbnum o 759 lbtext tfail 760 lbnum f 761 end 762 fn exctl d ulong m ulong to void 763 lbtext tdet 764 lbnum d 765 lbtext tmiss 766 lbnum m 767 end 768 note run the line t into raw file o, expect exit gcnt[4] and the summary already built in glb 769 fn chk name view uchar * t view uchar * o view uchar * to void 770 lbtoex 771 rc = runline t o 772 pbset o 773 n = rdin false 774 ok = and eq rc get gcnt 4 lt n `4194305` 775 if ok 776 ok = lastis n 777 end 778 report ok name rc n 779 end 780 fn chkrc name view uchar * t view uchar * wrc ulong to void 781 lbtoex 782 rc = runline t fnull 783 report eq rc wrc name rc `4194306` 784 end 785 fn chkval name view uchar * ok bool to void 786 lbtoex 787 report ok name 0 `4194306` 788 end 789 790 note ---- the checks, in the order of the former selftest.sh, plus the two OMC-EFF-4 control checks 791 fn part1 to void 792 exsum 8 6 0 6 6 0 793 exctl 2 0 794 put gcnt 4 0 795 chk n1 rclean fok 796 pbset fok 797 n = rdin false 798 if eq get gcnt 2 1 799 z = scan n 1 800 lbtext tzr 801 lbnum z 802 chkval n2 eq z 0 803 else 804 lbtext tnr 805 lbtext n2 806 lbtext tparn 807 lbflush 808 put gcnt 1 add get gcnt 1 1 809 end 810 z2 = scan n 2 811 lbtext tbt 812 lbnum z2 813 chkval n3 eq z2 0 814 f = scan n 5 815 if eq f 1 816 lbtext tcon 817 else 818 lbtext tcoff 819 end 820 chkval n17 eq f get gcnt 2 821 end 822 fn part2 to void 823 pbset twd 824 pbtext tfibo 825 n = cpbegin 826 pbset tkeepw 827 cpend n 828 pbset twd 829 pbtext tfibo 830 if not wrtext twrong 831 setfail tsetup 832 end 833 exsum 4 0 3 3 0 3 834 exctl 1 0 835 put gcnt 4 1 836 chk n4 rfib fnc1 837 pbset tkeepw 838 m2 = cpbegin 839 pbset twd 840 pbtext tfibo 841 cpend m2 842 cpfrom tbo tfib 843 cpto tbn tfib 844 exsum 4 3 0 3 3 0 845 exctl 0 1 846 chk n5 rfib fnc2 847 end 848 fn part3 to void 849 cpfrom tbo tsieve 850 cpto tbn tfib 851 pbset tb2 852 pbtext tfib 853 n = cpbegin 854 pbset tkeep2 855 cpend n 856 put gfb n 120 857 pbset tb2 858 pbtext tfib 859 cpend add n 1 860 exsum 3 2 1 0 0 0 861 exctl 0 0 862 chk n6 rbld fnc3 863 cpfrom tkeepd tkeepn 864 cpto tb2 tfib 865 exsum 3 3 0 0 0 0 866 exctl 0 0 867 put gcnt 4 0 868 chk n7 rbld fb 869 end 870 fn part4 to void 871 cpfrom tfxd tn0 872 cpto tb2 tfib 873 exsum 4 2 1 3 3 0 874 exctl 1 0 875 put gcnt 4 1 876 chk n8 rfib fnc4 877 cpfrom tfxd tnb 878 cpto tb2 tfib 879 exsum 4 2 1 3 3 0 880 exctl 1 0 881 chk n9 rfib fnc5 882 cpfrom tfxd tn1 883 cpto tb2 tfib 884 rc = runline rfib fok2 885 pbset fok2 886 n = rdin false 887 v = scan n 4 888 exsum 4 3 0 3 3 0 889 exctl 1 0 890 lbtoex 891 ok = and and eq rc 0 lastis n eq v 123 892 exsum 4 3 0 3 3 0 893 exctl 1 0 894 lbtext trt 895 lbnum 123 896 lbtoex 897 report ok n10 rc n 898 cpfrom tkeepd tkeepn 899 cpto tb2 tfib 900 end 901 fn part5 to void 902 cpfrom tfxd tn0 903 cpto tbn tfib 904 exsum 4 3 1 3 3 0 905 exctl 0 0 906 put gcnt 4 1 907 chk n11 rfib fnc6 908 cpfrom tfxd tnc 909 cpto tbn tfib 910 exsum 4 3 1 3 3 0 911 exctl 0 0 912 chk n12 rfib fnc7 913 cpfrom tbo tsieve 914 cpto tbn tfib 915 end 916 fn part6 to void 917 bomc tfib true 918 cpfrom tb2 tfib 919 cpto tb2 tofib 920 cpfrom tb0 tfib 921 cpto tb0 tofib 922 cpfrom tbo tsieve 923 cpto tbn tofib 924 rc = runline rom2 fom2 925 pbset fom2 926 n = rdin false 927 u = scan n 3 928 exsum 4 3 0 3 3 0 929 exctl 1 0 930 lbtoex 931 ok = and and eq rc 0 eq u 0 lastis n 932 exsum 4 3 0 3 3 0 933 exctl 1 0 934 lbtext tunl 935 lbnum u 936 lbtoex 937 report ok n13 rc n 938 lbtext tdiff 939 chkval n14 not om2same 940 chkrc n15 rusage 2 941 chkrc n16 rseed0 2 942 end 943 fn om2same to bool 944 pbset tbo 945 pbtext tofib 946 a = rdin false 947 pbset tbo 948 pbtext tfib 949 b = rdin true 950 if or ne a b ge a `4194305` 951 ret false 952 end 953 for i ulong a bound `4194304` 954 if ne get gfb i get gf2 i 955 ret false 956 end 957 end 958 ret true 959 end 960 961 note ---- main 962 fn perfok to ulong 963 b = new uchar 32 0 964 fd = fopen tparan 0 len tparan 0 0 965 if lt fd 0 966 ret 0 967 end 968 n = read int fd b 0 32 969 c = fclose int fd 970 if lt n 2 971 ret 0 972 end 973 if eq get b 0 45 974 ret 1 975 end 976 v = get b 0 977 if and ge v 48 le v 50 978 if eq get b 1 10 979 ret 1 980 end 981 end 982 ret 0 983 end 984 fn absarg idx ulong to bool 985 b = new uchar 4096 0 986 r = argread idx b 0 4096 987 if lt r 1 988 ret false 989 end 990 ret eq get b 0 47 991 end 992 fn setup to void 993 if ne argcnt 4 994 w = write 2 tusg 0 len tusg 995 exit 2 996 end 997 if or not absarg 1 not absarg 2 998 w2 = write 2 tusg 0 len tusg 999 exit 2 1000 end 1001 pbclr 1002 pbarg 3 1003 r = makedir gpb 0 get gpbn 0 493 1004 if lt r 0 1005 w3 = write 2 tusg 0 len tusg 1006 exit 2 1007 end 1008 r2 = chdir gpb 0 get gpbn 0 1009 if ne r2 0 1010 setfail tsetup 1011 end 1012 put gcnt 2 perfok 1013 mkdirs 1014 pbclr 1015 pbarg 2 1016 pbtext tcondom 1017 setin 1018 pbset tcond 1019 setout 1020 if ne omcrun 0 1021 setfail tsetup 1022 end 1023 arms tfib 1024 arms tsieve 1025 cpwant tfib true 1026 note the control arm of each case is the other case's program: correct bytes, wrong answer 1027 cpfrom tbo tsieve 1028 cpto tbn tfib 1029 cpfrom tbo tfib 1030 cpto tbn tsieve 1031 fixture frt0 tn0 1032 fixture frtb tnb 1033 fixture frt1 tn1 1034 fixture frtc tnc 1035 end 1036 fn arms c view uchar * to void 1037 cpsrc c tom 1038 cpsrc c tc 1039 bomc c false 1040 gccone c tgo2 tb2 1041 gccone c tgo0 tb0 1042 cpwant c false 1043 end 1044 fn mkdirs to void 1045 mkd tdir1 1046 mkd tdir2 1047 mkd tdir3 1048 mkd tdir4 1049 mkd tdir5 1050 mkd tdir6 1051 mkd tdir7 1052 mkd tdir8 1053 mkd tdir9 1054 mkd tdir10 1055 mkd tdir11 1056 mkd tdir12 1057 mkd tdir13 1058 mkd tdirf 1059 end 1060 fn main to int 1061 setup 1062 part1 1063 part2 1064 part3 1065 part4 1066 part5 1067 part6 1068 lbtext tend 1069 lbnum get gcnt 0 1070 lbtext tnrun 1071 lbnum get gcnt 1 1072 lbflush 1073 if eq get gcnt 0 0 1074 ret 0 1075 end 1076 ret 1 1077 end