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/mailhand/blob/main/tests/gate.om # mailhand mailhand: agents look after a person's email in seeded Omega. Maildir + MIME parsing, JSONL CLI and MCP, rule triage, policy-gated sending, hash-chained audit. Free (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 `mailhand / tests / gate.om` 1972 lines ยท 34930 bytes Raw Blame History 1 note mailhand scenario gate. Structure adapted from omega-zip `74e9e36d` tests/gate.om. 2 note Stores replace whole-file arrays; explicit disk-backed stacks replace recursive tree walks. 3 note execprog forces 65536 packet bytes/1024 args; PATH_MAX 4096. No input-size/depth caps. 4 note Every child has 120 seconds; compilation has 300 seconds; expiration fails, never passes. 5 const GA_CASE ulong 0 6 const GA_FIELDS ulong 1 7 const GA_EXP ulong 2 8 const GA_NAMES ulong 3 9 const GA_STACK ulong 4 10 const GA_FILE ulong 5 11 const GA_MUT ulong 7 12 const GA_UNITS ulong 8 13 const GA_SRC ulong 9 14 const GA_ROOT ulong 10 15 const GA_SCEN ulong 11 16 const GA_OMC ulong 12 17 const GA_SPEC ulong 13 18 const GA_BIN ulong 14 19 const GA_OLD ulong 15 20 const GA_NEW ulong 16 21 const GA_PATH ulong 17 22 const GA_LAST ulong 18 23 const GA_TMP ulong 19 24 note GA_ROB: the input of the running rob step (store 6, unused elsewhere in the gate). 25 const GA_ROB ulong 6 26 global ga_v ulong 32 27 global ga_packet uchar 65536 28 global ga_pn ulong 2 29 global ga_in uchar 4096 30 global ga_out uchar 4096 31 global ga_err uchar 4096 32 global ga_io ulong 3 33 global ga_pinv uchar 104 34 text ga_pinf "PIN" 35 text ga_pinmv "omega-mv " 36 text ga_pinomc "omc-sha256 " 37 text ga_badpin "MHGATE NOT_RUN PIN is not \"omega-mv <40 hex>\\nomc-sha256 <64 hex>\\n\"\n" 38 text ga_gitbin "/usr/bin/git" 39 text ga_lsfiles "ls-files" 40 text ga_pinlsfail "MHGATE pincheck: git ls-files failed\n" 41 text ga_pinsum "MHGATE pincheck files=" 42 text ga_pinbad " restated=" 43 text ga_pinhit "PINCHECK restates the pin: " 44 text ga_nl "\n" 45 text ga_slash "/" 46 text ga_empty "" 47 text ga_null "/dev/null" 48 text ga_build "build" 49 text ga_dir "build/gate" 50 text ga_sdir "build/gate/s" 51 text ga_stail "/s/" 52 text ga_cases "tests/scenarios" 53 text ga_muts "tests/mutants.txt" 54 text ga_srcunits "build/gen/src/UNITS" 55 text ga_sinkunits "src/SINK_UNITS" 56 text ga_mh "build/gate/mailhand" 57 text ga_sink "build/gate/mailhand-sink" 58 text ga_mutbin "build/gate/mutant" 59 text ga_unitfile "build/gate/source.om" 60 text ga_stdout "build/gate/out" 61 text ga_stderr "build/gate/err" 62 text ga_bgout "build/gate/sink.out" 63 text ga_bgerr "build/gate/sink.err" 64 text ga_txt ".txt" 65 text ga_om2 "om2" 66 text ga_export "export fn " 67 text ga_fn "fn " 68 text ga_header "om2\n" 69 text ga_run "run" 70 text ga_bg "bg" 71 text ga_wait "wait" 72 text ga_mkdir "mkdir" 73 text ga_copy "copy" 74 text ga_write "write" 75 text ga_append "append" 76 text ga_symlink "symlink" 77 text ga_flip "flip" 78 text ga_gen "gen" 79 text ga_outeq "out-eq" 80 text ga_outhas "out-has" 81 text ga_outnot "out-not" 82 text ga_outlines "out-lines" 83 text ga_errhas "err-has" 84 text ga_fileeq "file-eq" 85 text ga_filehas "file-has" 86 text ga_filenot "file-not" 87 text ga_exists "exists" 88 text ga_absent "absent" 89 text ga_robw "rob" 90 text ga_parse "parse" 91 text ga_robin "/rob.in" 92 text ga_krefused "\"refused\"" 93 text ga_robfailt "ROB FAIL " 94 text ga_cutw " cut " 95 text ga_xorw " xor " 96 text ga_zerow " zero " 97 text ga_exitw " exit " 98 text ga_robrep "rob " 99 text ga_runsw " runs=" 100 text ga_okw " ok=" 101 text ga_refw " refused=" 102 text ga_robtot "MHGATE rob runs=" 103 text ga_outsha "out-sha256" 104 text ga_maxns "max-ns" 105 text ga_slow "slow: actual=" 106 text ga_ns " ns threshold=" 107 text ga_dash "-" 108 text ga_sep "--" 109 text ga_mhw "mh" 110 text ga_sinkw "sink" 111 text ga_fail "FAIL " 112 text ga_pass "PASS " 113 text ga_step " step " 114 text ga_reason ": " 115 text ga_ioerr "I/O or path failure" 116 text ga_badline "unknown or malformed step" 117 text ga_mismatch "check mismatch" 118 text ga_badexit "process exit mismatch (actual=" 119 text ga_want " expected=" 120 text ga_close ")" 121 text ga_mutfail "MUTANT FAIL " 122 text ga_mutkill "MUTANT killed " 123 text ga_mutsurv "MUTANT SURVIVED " 124 text ga_finalpass "MHGATE PASS scenarios=" 125 text ga_finalfail "MHGATE FAIL scenarios=" 126 text ga_steps " steps=" 127 text ga_mutcount " mutants-killed=" 128 text ga_notrun "MHGATE NOT_RUN compiler sha256 is not the omc-sha256 of PIN\n" 129 text ga_usage "usage: gate OMC [SCENARIO-DIRECTORY [MUTANTS-FILE]]\n" 130 text ga_buildfail "MHGATE FAIL build\n" 131 text ga_sinknote "MHGATE sink NOT_RUN: src/SINK_UNITS absent\n" 132 text ga_srvunits "build/gen/tests/srv/UNITS" 133 text ga_srvbin "build/gate/srv" 134 text ga_srvw "srv" 135 text ga_srvnote "MHGATE srv NOT_RUN: tests/srv/UNITS absent\n" 136 text ga_errnot "err-not" 137 text ga_treenot "tree-not" 138 text ga_genpre "tests/units/" 139 text ga_genout "build/gate/gen-" 140 text ga_lockf "build/gate/lock" 141 text ga_lockwait "MHGATE waiting for build/gate/lock (another gate run holds it)\n" 142 text ga_timeout "MHGATE limits: run=120s compile=300s\n" 143 144 fn ga_say t view uchar * to void 145 o_raw t 146 o_flush 147 end 148 fn ga_num n ulong to void 149 o_digits n 150 o_flush 151 end 152 fn ga_print s ulong to void 153 r = s_wfd s 1 154 end 155 fn ga_die t view uchar * to void 156 ga_say t 157 ga_say ga_nl 158 exit 1 159 end 160 note ga_new: a fresh memfd store; a store loaded read-only by s_file cannot be reset in place. 161 fn ga_new s ulong to void 162 if not s_mem s 163 ga_die ga_ioerr 164 end 165 end 166 fn ga_uput s ulong v ulong to void 167 for i ulong 8 168 if not s_add s uchar and shr v mul i 8 255 169 ga_die ga_ioerr 170 end 171 end 172 end 173 fn ga_uget s ulong p ulong to ulong 174 v = ulong 0 175 for i ulong 8 176 v = or v shl ulong s_get s add p i mul i 8 177 end 178 ret v 179 end 180 fn ga_eol s ulong p ulong to ulong 181 q = p 182 while lt q s_len s bound `9223372036854775807` 183 if eq s_get s q 10 184 break 185 end 186 q = add q 1 187 end 188 ret q 189 end 190 fn ga_equal a ulong ao ulong b ulong bo ulong n ulong to bool 191 for i ulong n bound `9223372036854775807` 192 if ne s_get a add ao i s_get b add bo i 193 ret false 194 end 195 end 196 ret true 197 end 198 fn ga_path s ulong to void 199 p_reset 200 p_s s 0 s_len s 201 end 202 fn ga_pt t view uchar * to void 203 p_reset 204 p_t t 205 end 206 fn ga_savepath s ulong to void 207 ga_new s 208 for i ulong get gv VPL bound 4096 209 z = s_add s get gp i 210 end 211 end 212 fn ga_load s ulong to bool 213 ret eq s_file s 0 214 end 215 fn ga_numrange s ulong p ulong n ulong to ulong 216 v = ulong 0 217 if eq n 0 218 ga_die ga_badline 219 end 220 for i ulong n bound `9223372036854775807` 221 c = s_get s add p i 222 if or lt c 48 gt c 57 223 ga_die ga_badline 224 end 225 if gt v div sub ulong `18446744073709551615` ulong sub c 48 10 226 ga_die ga_badline 227 end 228 v = add mul v 10 ulong sub c 48 229 end 230 ret v 231 end 232 note Fields retain offsets into the scenario, no fixed field-count array. 233 fn ga_fields a ulong b ulong to void 234 ga_new GA_FIELDS 235 p = a 236 while lt p b bound `9223372036854775807` 237 if or eq s_get GA_CASE p 32 eq s_get GA_CASE p 9 238 p = add p 1 239 continue 240 end 241 q = p 242 while lt q b bound `9223372036854775807` 243 c = s_get GA_CASE q 244 if or eq c 32 eq c 9 245 break 246 end 247 q = add q 1 248 end 249 ga_uput GA_FIELDS p 250 ga_uput GA_FIELDS sub q p 251 p = q 252 end 253 put ga_v 0 div s_len GA_FIELDS 16 254 put ga_v 1 b 255 end 256 fn ga_fo i ulong to ulong 257 ret ga_uget GA_FIELDS mul i 16 258 end 259 fn ga_fnlen i ulong to ulong 260 ret ga_uget GA_FIELDS add mul i 16 8 261 end 262 fn ga_is i ulong t view uchar * to bool 263 if ge i get ga_v 0 264 ret false 265 end 266 ret s_eqt GA_CASE ga_fo i ga_fnlen i t 267 end 268 fn ga_fnum i ulong to ulong 269 ret ga_numrange GA_CASE ga_fo i ga_fnlen i 270 end 271 note Expand @S scenario, @B absolute build/gate, @R repo; decode \n, \t, \r, \\. 272 fn ga_expand p0 ulong n ulong to void 273 ga_new GA_EXP 274 p = p0 275 e = add p n 276 while lt p e bound `9223372036854775807` 277 c = s_get GA_CASE p 278 if lt add p 1 e 279 if eq c 64 280 k = s_get GA_CASE add p 1 281 if or or eq k 83 eq k 66 eq k 82 282 s_adds GA_EXP GA_ROOT 0 s_len GA_ROOT 283 if ne k 82 284 s_addt GA_EXP ga_slash 285 s_addt GA_EXP ga_dir 286 end 287 if eq k 83 288 s_addt GA_EXP ga_stail 289 s_adds GA_EXP GA_SCEN 0 s_len GA_SCEN 290 end 291 p = add p 2 292 continue 293 end 294 end 295 if and eq c 92 eq get ga_v 31 1 296 k = s_get GA_CASE add p 1 297 if eq k 110 298 c = 10 299 end 300 if eq k 116 301 c = 9 302 end 303 if eq k 114 304 c = 13 305 end 306 if eq k 92 307 c = 92 308 end 309 if or or eq k 110 eq k 116 or eq k 114 eq k 92 310 p = add p 1 311 end 312 end 313 end 314 if not s_add GA_EXP c 315 ga_die ga_ioerr 316 end 317 p = add p 1 318 end 319 end 320 fn ga_field i ulong to void 321 ga_expand ga_fo i ga_fnlen i 322 end 323 fn ga_rest i ulong to void 324 p = ga_fo i 325 ga_expand p sub get ga_v 1 p 326 end 327 fn ga_fpath i ulong to void 328 ga_field i 329 ga_path GA_EXP 330 end 331 note mkdir -p walks path components; kernel PATH_MAX is checked by core. 332 fn ga_mkp to bool 333 if not p_ok 334 ret false 335 end 336 n = get gv VPL 337 for i ulong n bound 4096 338 if eq get gp i 47 339 if gt i 0 340 r = makedir gp 0 i 448 341 if and lt r 0 ne r -17 342 ret false 343 end 344 end 345 end 346 end 347 r = makedir gp 0 n 448 348 ret or eq r 0 eq r -17 349 end 350 note Stack entries: path bytes, u64 path length, u64 post marker. 351 fn ga_push post ulong to void 352 n = get gv VPL 353 for i ulong n bound 4096 354 z = s_add GA_STACK get gp i 355 end 356 ga_uput GA_STACK n 357 ga_uput GA_STACK post 358 end 359 fn ga_pop to ulong 360 n = s_len GA_STACK 361 post = ga_uget GA_STACK sub n 8 362 m = ga_uget GA_STACK sub n 16 363 p_reset 364 p_s GA_STACK sub sub n 16 m m 365 s_trunc GA_STACK sub sub n 16 m 366 ret post 367 end 368 fn ga_wipe to bool 369 ga_new GA_STACK 370 ga_push 0 371 while gt s_len GA_STACK 0 bound `9223372036854775807` 372 post = ga_pop 373 if eq post 1 374 r = rmdir gp 0 get gv VPL 375 if lt r 0 376 ret false 377 end 378 continue 379 end 380 k = p_kind 381 if eq k 0 382 continue 383 end 384 if ne k 1 385 if lt p_unlink 0 386 ret false 387 end 388 continue 389 end 390 ga_push 1 391 if not d_open 0 392 ret false 393 end 394 p_save 395 while d_next 0 bound `9223372036854775807` 396 p_restore 397 p_c 47 398 p_dn 399 if not p_ok 400 d_close 0 401 ret false 402 end 403 ga_push 0 404 end 405 d_close 0 406 end 407 ret true 408 end 409 note Copy tree using explicit source stack and root-prefix replacement; symlinks copied as links. 410 fn ga_copyone prefix ulong to bool 411 ga_savepath GA_PATH 412 k = p_kind 413 ga_new GA_TMP 414 s_adds GA_TMP GA_NEW 0 s_len GA_NEW 415 s_adds GA_TMP GA_PATH prefix sub s_len GA_PATH prefix 416 if eq k 1 417 if not d_open 0 418 ret false 419 end 420 p_save 421 while d_next 0 bound `9223372036854775807` 422 p_restore 423 p_c 47 424 p_dn 425 if not p_ok 426 d_close 0 427 ret false 428 end 429 ga_push 0 430 end 431 d_close 0 432 ga_path GA_TMP 433 ret ga_mkp 434 end 435 if eq k 2 436 ga_path GA_PATH 437 if not ga_load GA_FILE 438 ret false 439 end 440 ga_path GA_TMP 441 fd = fopen gp 0 get gv VPL 577 384 442 if lt fd 0 443 ret false 444 end 445 r = s_wfd GA_FILE int fd 446 z = fclose int fd 447 ret and eq r 0 eq z 0 448 end 449 if eq k 3 450 ret ga_copylink 451 end 452 ret false 453 end 454 fn ga_copytree to bool 455 ga_new GA_STACK 456 ga_path GA_OLD 457 n = get gv VPL 458 ga_push 0 459 while gt s_len GA_STACK 0 bound `9223372036854775807` 460 z = ga_pop 461 if not ga_copyone n 462 ret false 463 end 464 end 465 ret true 466 end 467 note Two-path packets use compiler's 4096-byte packed-list boundary. 468 fn ga_linkstores a ulong b ulong to bool 469 buf = new uchar 4096 0 470 na = s_len a 471 nb = s_len b 472 n = add add na nb 6 473 if gt n 4096 474 ret false 475 end 476 put buf 0 2 477 put buf 2 uchar and na 255 478 put buf 3 uchar shr na 8 479 for i ulong na bound 4096 480 put buf add 4 i s_get a i 481 end 482 q = add na 4 483 put buf q uchar and nb 255 484 put buf add q 1 uchar shr nb 8 485 for i ulong nb bound 4096 486 put buf add add q 2 i s_get b i 487 end 488 ret eq symlnk buf 0 n 0 489 end 490 fn ga_copylink to bool 491 b = new uchar 4096 0 492 ga_path GA_PATH 493 r = readlnk gp 0 get gv VPL b 0 4096 494 if or lt r 0 eq r 4096 495 ret false 496 end 497 ga_new GA_FILE 498 s_addt GA_FILE part b 0 ulong r 499 ret ga_linkstores GA_FILE GA_TMP 500 end 501 note Process packet: fail before any host trap if its fixed wire representation is too large. 502 fn ga_pkreset to void 503 put ga_pn 0 2 504 put ga_pn 1 0 505 end 506 fn ga_pk s ulong to void 507 n = s_len s 508 p = get ga_pn 0 509 c = add get ga_pn 1 1 510 if or gt c 1024 gt add add p n 2 65536 511 ga_die ga_badline 512 end 513 put ga_packet p uchar and n 255 514 put ga_packet add p 1 uchar and shr n 8 255 515 for i ulong n bound 65536 516 b = s_get s i 517 if eq b 0 518 ga_die ga_badline 519 end 520 put ga_packet add add p 2 i b 521 end 522 put ga_pn 0 add add p n 2 523 put ga_pn 1 c 524 put ga_packet 0 uchar and c 255 525 put ga_packet 1 uchar shr c 8 526 end 527 fn ga_pkt t view uchar * to void 528 ga_new GA_TMP 529 s_addt GA_TMP t 530 ga_pk GA_TMP 531 end 532 fn ga_stream which ulong s ulong to void 533 n = s_len s 534 if or eq n 0 ge n 4096 535 ga_die ga_ioerr 536 end 537 for i ulong n bound 4096 538 c = s_get s i 539 if eq which 0 540 put ga_in i c 541 end 542 if eq which 1 543 put ga_out i c 544 end 545 if eq which 2 546 put ga_err i c 547 end 548 end 549 put ga_io which n 550 end 551 fn ga_streamt which ulong t view uchar * to void 552 ga_new GA_TMP 553 s_addt GA_TMP t 554 ga_stream which GA_TMP 555 end 556 fn ga_reap pid long lim long to ulong 557 b = new uchar 4 0 558 t0 = monons 559 while true bound `9223372036854775807` 560 w = waitpid int pid b 0 4 1 561 if eq w pid 562 st = le32b b 0 563 if eq and st 127 0 564 ret and shr st 8 255 565 end 566 ret add 1000 and st 127 567 end 568 if lt w 0 569 if ne w -4 570 ret 3000 571 end 572 end 573 if gt sub monons t0 lim 574 r = killpid int pid 9 575 w = waitpid int pid b 0 4 0 576 ret 2000 577 end 578 r = sleepns 50000 579 end 580 ret 2000 581 end 582 fn ga_spawn background bool lim long to ulong 583 put ga_v 12 ulong monons 584 fi = fopen ga_in 0 get ga_io 0 0 0 585 fo = fopen ga_out 0 get ga_io 1 577 384 586 fe = fopen ga_err 0 get ga_io 2 577 384 587 if or or lt fi 0 lt fo 0 lt fe 0 588 ga_die ga_ioerr 589 end 590 pid = fork 591 if lt pid 0 592 ga_die ga_ioerr 593 end 594 if eq pid 0 595 if lt dupfd int fi 0 0 0 596 exit 126 597 end 598 if lt dupfd int fo 1 0 0 599 exit 126 600 end 601 if lt dupfd int fe 2 0 0 602 exit 126 603 end 604 r = execprog ga_packet 0 get ga_pn 0 605 exit 127 606 end 607 z = fclose int fi 608 z = fclose int fo 609 z = fclose int fe 610 if background 611 put ga_v 8 ulong pid 612 put ga_v 14 get ga_v 12 613 ret 0 614 end 615 st = ga_reap pid lim 616 put ga_v 13 sub ulong monons get ga_v 12 617 ret st 618 end 619 fn ga_normalio to void 620 ga_streamt 0 ga_null 621 ga_streamt 1 ga_stdout 622 ga_streamt 2 ga_stderr 623 end 624 fn ga_badstatus st ulong to bool 625 if ge st 1000 626 ret true 627 end 628 ret and ge st 101 le st 114 629 end 630 note Build the exact listed units, removing om2 lines and normalizing export fn like build.sh. 631 fn ga_unit s ulong e ulong mutated bool to ulong 632 ga_pt ga_empty 633 p_s GA_UNITS s sub e s 634 if not ga_load GA_FILE 635 ga_die ga_ioerr 636 end 637 rep = false 638 if mutated 639 rep = ga_equal GA_UNITS s GA_SPEC 0 sub e s 640 if ne sub e s s_len GA_SPEC 641 rep = false 642 end 643 end 644 hits = ulong 0 645 p = ulong 0 646 while lt p s_len GA_FILE bound `9223372036854775807` 647 q = ga_eol GA_FILE p 648 n = sub q p 649 if not s_eqt GA_FILE p n ga_om2 650 match = false 651 if rep 652 if eq n s_len GA_OLD 653 match = ga_equal GA_FILE p GA_OLD 0 n 654 end 655 end 656 if match 657 hits = add hits 1 658 k = get ga_v 20 659 if and ne k 0 ne hits k 660 match = false 661 end 662 end 663 if match 664 s_adds GA_SRC GA_NEW 0 s_len GA_NEW 665 else 666 if ge n len ga_export 667 if s_eqt GA_FILE p len ga_export ga_export 668 s_addt GA_SRC ga_fn 669 p = add p len ga_export 670 end 671 end 672 s_adds GA_SRC GA_FILE p sub q p 673 end 674 s_addt GA_SRC ga_nl 675 end 676 p = add q 1 677 end 678 ret hits 679 end 680 fn ga_compile units view uchar * binary view uchar * mutated bool to bool 681 ga_pt units 682 if not ga_load GA_UNITS 683 ret false 684 end 685 ga_new GA_SRC 686 s_addt GA_SRC ga_header 687 p = ulong 0 688 hits = ulong 0 689 while lt p s_len GA_UNITS bound `9223372036854775807` 690 q = ga_eol GA_UNITS p 691 if gt q p 692 if ne s_get GA_UNITS p 35 693 hits = add hits ga_unit p q mutated 694 end 695 end 696 p = add q 1 697 end 698 if mutated 699 if eq hits 0 700 ret false 701 end 702 if ne get ga_v 20 0 703 if ne hits get ga_v 21 704 ret false 705 end 706 end 707 end 708 ga_pt ga_unitfile 709 fd = fopen gp 0 get gv VPL 577 384 710 if lt fd 0 711 ret false 712 end 713 r = s_wfd GA_SRC int fd 714 z = fclose int fd 715 if ne r 0 716 ret false 717 end 718 ga_pkreset 719 ga_pk GA_OMC 720 ga_streamt 0 ga_unitfile 721 ga_streamt 1 binary 722 ga_streamt 2 ga_stderr 723 st = ga_spawn false `300000000000` 724 if ne st 0 725 ga_pt ga_stderr 726 if ga_load GA_FILE 727 ga_print GA_FILE 728 end 729 ret false 730 end 731 ga_pt binary 732 ret eq chmod gp 0 get gv VPL 493 0 733 end 734 fn ga_pinok to bool 735 d = new uchar 32 0 736 if not ga_pinread 737 ga_say ga_badpin 738 ret false 739 end 740 ga_path GA_OMC 741 if not ga_load GA_FILE 742 ret false 743 end 744 sha_s GA_FILE 0 s_len GA_FILE d 745 ga_new GA_TMP 746 s_addhex GA_TMP d 747 for i ulong 64 748 if ne s_get GA_TMP i get ga_pinv add 40 i 749 ret false 750 end 751 end 752 ret true 753 end 754 755 note ga_pinread: PIN is exactly "omega-mv <40 hex>\nomc-sha256 <64 hex>\n"; the values go to ga_pinv 756 note (0..39 the omega-mv revision, 40..103 the omc sha256) 757 fn ga_pinread to bool 758 ga_pt ga_pinf 759 if not ga_load GA_FILE 760 ret false 761 end 762 if ne s_len GA_FILE 126 763 ret false 764 end 765 if not s_eqt GA_FILE 0 9 ga_pinmv 766 ret false 767 end 768 if not s_eqt GA_FILE 50 11 ga_pinomc 769 ret false 770 end 771 if or ne s_get GA_FILE 49 10 ne s_get GA_FILE 125 10 772 ret false 773 end 774 for i ulong 40 775 c = s_get GA_FILE add 9 i 776 if not ga_ishex c 777 ret false 778 end 779 put ga_pinv i c 780 end 781 for i ulong 64 782 c = s_get GA_FILE add 61 i 783 if not ga_ishex c 784 ret false 785 end 786 put ga_pinv add 40 i c 787 end 788 ret true 789 end 790 791 fn ga_ishex c uchar to bool 792 ret or and ge c 48 le c 57 and ge c 97 le c 102 793 end 794 795 fn ga_isword c uchar to bool 796 if or and ge c 48 le c 57 and ge c 97 le c 122 797 ret true 798 end 799 ret or and ge c 65 le c 90 eq c 95 800 end 801 802 note ---- pincheck: no tracked file (git ls-files) other than PIN restates the pin: a whole hex word of 803 note at least 7 digits that is a prefix of the omega-mv revision or of the omc sha256 is a finding ---- 804 fn ga_pincheck to ulong 805 ga_pkreset 806 ga_pkt ga_gitbin 807 ga_pkt ga_lsfiles 808 ga_normalio 809 st = ga_spawn false `120000000000` 810 if ne st 0 811 ga_say ga_pinlsfail 812 ret 1 813 end 814 ga_pt ga_stdout 815 if not ga_load GA_SRC 816 ret 1 817 end 818 files = ulong 0 819 bad = ulong 0 820 n = s_len GA_SRC 821 p = ulong 0 822 while lt p n bound `9223372036854775807` 823 q = ga_eol GA_SRC p 824 if gt q p 825 files = add files 1 826 bad = add bad ga_scanpin p q 827 end 828 p = add q 1 829 end 830 ga_say ga_pinsum 831 ga_num files 832 ga_say ga_pinbad 833 ga_num bad 834 ga_say ga_nl 835 ret bad 836 end 837 838 fn ga_scanpin p ulong q ulong to ulong 839 if s_eqt GA_SRC p sub q p ga_pinf 840 ret 0 841 end 842 p_reset 843 p_s GA_SRC p sub q p 844 if ne p_kind 2 845 ret 0 846 end 847 if not ga_load GA_FILE 848 ret 0 849 end 850 n = s_len GA_FILE 851 bad = ulong 0 852 i = ulong 0 853 prev = uchar 32 854 while lt i n bound `9223372036854775807` 855 c = s_get GA_FILE i 856 if and ga_ishex c not ga_isword prev 857 e = i 858 while lt e n bound `9223372036854775807` 859 if not ga_ishex s_get GA_FILE e 860 break 861 end 862 e = add e 1 863 end 864 if ga_restates i e n 865 bad = add bad 1 866 end 867 i = e 868 prev = s_get GA_FILE sub e 1 869 continue 870 end 871 prev = c 872 i = add i 1 873 end 874 if gt bad 0 875 ga_say ga_pinhit 876 ga_new GA_TMP 877 s_adds GA_TMP GA_SRC p sub q p 878 ga_print GA_TMP 879 ga_say ga_nl 880 end 881 ret bad 882 end 883 884 fn ga_restates s ulong e ulong n ulong to bool 885 l = sub e s 886 if lt l 7 887 ret false 888 end 889 if lt e n 890 if ga_isword s_get GA_FILE e 891 ret false 892 end 893 end 894 ret or ga_pinpfx s l 0 40 ga_pinpfx s l 40 64 895 end 896 897 fn ga_pinpfx s ulong l ulong o ulong m ulong to bool 898 if gt l m 899 ret false 900 end 901 for i ulong l bound 64 902 if ne s_get GA_FILE add s i get ga_pinv add o i 903 ret false 904 end 905 end 906 ret true 907 end 908 909 note Scenario actions and checks. 910 fn ga_process background bool to bool 911 start = ulong 4 912 want = ulong 0 913 if background 914 if ne get ga_v 8 0 915 ret false 916 end 917 start = 1 918 else 919 if lt get ga_v 0 5 920 ret false 921 end 922 if not ga_is 3 ga_sep 923 ret false 924 end 925 want = ga_fnum 1 926 end 927 ga_pkreset 928 if ga_is start ga_mhw 929 ga_pk GA_BIN 930 else 931 if ga_is start ga_srvw 932 ga_pkt ga_srvbin 933 else 934 if ga_is start ga_sinkw 935 ga_pkt ga_sink 936 else 937 ga_field start 938 ga_pk GA_EXP 939 end 940 end 941 end 942 i = add start 1 943 while lt i get ga_v 0 bound `9223372036854775807` 944 ga_field i 945 ga_pk GA_EXP 946 i = add i 1 947 end 948 ga_normalio 949 if background 950 ga_streamt 1 ga_bgout 951 ga_streamt 2 ga_bgerr 952 else 953 if not ga_is 2 ga_dash 954 ga_field 2 955 ga_stream 0 GA_EXP 956 end 957 end 958 st = ga_spawn background `120000000000` 959 put ga_v 9 st 960 put ga_v 10 want 961 if ga_badstatus st 962 ret false 963 end 964 ret eq st want 965 end 966 fn ga_waitstep to bool 967 if eq get ga_v 8 0 968 ret false 969 end 970 st = ga_reap long get ga_v 8 `120000000000` 971 put ga_v 13 sub ulong monons get ga_v 14 972 put ga_v 8 0 973 put ga_v 9 st 974 want = ulong 0 975 if gt get ga_v 0 1 976 want = ga_fnum 1 977 end 978 put ga_v 10 want 979 if ga_badstatus st 980 ret false 981 end 982 note wait changes last stdout/stderr to the sink's files by copying streaming. 983 ga_pt ga_bgout 984 if not ga_load GA_FILE 985 ret false 986 end 987 ga_pt ga_stdout 988 if not ga_savefile false 989 ret false 990 end 991 ga_pt ga_bgerr 992 if not ga_load GA_FILE 993 ret false 994 end 995 ga_pt ga_stderr 996 if not ga_savefile false 997 ret false 998 end 999 ret eq st want 1000 end 1001 fn ga_savefile append bool to bool 1002 fl = int 577 1003 if append 1004 fl = 1089 1005 end 1006 if not p_ok 1007 ret false 1008 end 1009 fd = fopen gp 0 get gv VPL fl 384 1010 if lt fd 0 1011 ret false 1012 end 1013 r = s_wfd GA_FILE int fd 1014 z = fclose int fd 1015 ret and eq r 0 eq z 0 1016 end 1017 fn ga_writefile append bool to bool 1018 put ga_v 31 1 1019 if gt get ga_v 0 2 1020 ga_rest 2 1021 else 1022 ga_new GA_EXP 1023 end 1024 put ga_v 31 0 1025 ga_new GA_FILE 1026 s_adds GA_FILE GA_EXP 0 s_len GA_EXP 1027 ga_fpath 1 1028 ret ga_savefile append 1029 end 1030 fn ga_flipfile to bool 1031 b = new uchar 1 0 1032 ga_fpath 1 1033 fd = fopen gp 0 get gv VPL 32770 0 1034 if lt fd 0 1035 ret false 1036 end 1037 p = ga_fnum 2 1038 r = pread int fd b 0 1 long p 1039 if ne r 1 1040 z = fclose int fd 1041 ret false 1042 end 1043 put b 0 xor get b 0 1 1044 r = pwrite int fd b 0 1 long p 1045 z = fclose int fd 1046 ret and eq r 1 eq z 0 1047 end 1048 fn ga_copyaction to bool 1049 ga_field 1 1050 ga_new GA_OLD 1051 s_adds GA_OLD GA_EXP 0 s_len GA_EXP 1052 ga_field 2 1053 ga_new GA_NEW 1054 s_adds GA_NEW GA_EXP 0 s_len GA_EXP 1055 ret ga_copytree 1056 end 1057 fn ga_linkaction to bool 1058 ga_field 1 1059 ga_new GA_OLD 1060 s_adds GA_OLD GA_EXP 0 s_len GA_EXP 1061 ga_field 2 1062 ret ga_linkstores GA_OLD GA_EXP 1063 end 1064 fn ga_fileequal a ulong b ulong to bool 1065 if ne s_len a s_len b 1066 ret false 1067 end 1068 ret ga_equal a 0 b 0 s_len a 1069 end 1070 note Contains works on stores, including patterns and files larger than a cache window. 1071 fn ga_contains a ulong b ulong to bool 1072 n = s_len a 1073 m = s_len b 1074 if gt m n 1075 ret false 1076 end 1077 p = ulong 0 1078 while le p sub n m bound `9223372036854775807` 1079 if ga_equal a p b 0 m 1080 ret true 1081 end 1082 p = add p 1 1083 end 1084 ret false 1085 end 1086 fn ga_check to bool 1087 isfile = or or ga_is 0 ga_fileeq ga_is 0 ga_filehas ga_is 0 ga_filenot 1088 if isfile 1089 ga_fpath 1 1090 else 1091 ga_pt ga_stdout 1092 if or ga_is 0 ga_errhas ga_is 0 ga_errnot 1093 ga_pt ga_stderr 1094 end 1095 end 1096 if not ga_load GA_FILE 1097 ret false 1098 end 1099 if ga_is 0 ga_outlines 1100 n = ulong 0 1101 for i ulong s_len GA_FILE bound `9223372036854775807` 1102 if eq s_get GA_FILE i 10 1103 n = add n 1 1104 end 1105 end 1106 ret eq n ga_fnum 1 1107 end 1108 arg = ulong 1 1109 if isfile 1110 arg = 2 1111 end 1112 if or ga_is 0 ga_outeq ga_is 0 ga_fileeq 1113 ga_fpath arg 1114 if not ga_load GA_TMP 1115 ret false 1116 end 1117 ret ga_fileequal GA_FILE GA_TMP 1118 end 1119 ga_rest arg 1120 ok = ga_contains GA_FILE GA_EXP 1121 if or or ga_is 0 ga_outnot ga_is 0 ga_filenot ga_is 0 ga_errnot 1122 ret not ok 1123 end 1124 ret ok 1125 end 1126 note gen KIND PATH ARGS: build tests/units/KIND.txt -> build/gate/gen-KIND then run ARGS PATH. 1127 note mkbig interface is KIND OUTFILE: gen mkbig OUTFILE KIND. 1128 fn ga_genstep to bool 1129 ub = new uchar 4096 0 1130 bb = new uchar 4096 0 1131 ga_field 1 1132 ga_pt ga_genpre 1133 p_s GA_EXP 0 s_len GA_EXP 1134 p_t ga_txt 1135 un = get gv VPL 1136 for i ulong un bound 4096 1137 put ub i get gp i 1138 end 1139 ga_pt ga_genout 1140 p_s GA_EXP 0 s_len GA_EXP 1141 bn = get gv VPL 1142 for i ulong bn bound 4096 1143 put bb i get gp i 1144 end 1145 if not ga_compile part ub 0 un part bb 0 bn false 1146 ret false 1147 end 1148 ga_pkreset 1149 ga_pkt part bb 0 bn 1150 i = ulong 3 1151 while lt i get ga_v 0 bound `9223372036854775807` 1152 ga_field i 1153 ga_pk GA_EXP 1154 i = add i 1 1155 end 1156 ga_field 2 1157 ga_pk GA_EXP 1158 ga_normalio 1159 st = ga_spawn false `120000000000` 1160 put ga_v 9 st 1161 put ga_v 10 0 1162 ret eq st 0 1163 end 1164 fn ga_shaout to bool 1165 d = new uchar 32 0 1166 ga_pt ga_stdout 1167 if not ga_load GA_FILE 1168 ret false 1169 end 1170 sha_s GA_FILE 0 s_len GA_FILE d 1171 ga_new GA_TMP 1172 s_addhex GA_TMP d 1173 ga_field 1 1174 ret ga_fileequal GA_TMP GA_EXP 1175 end 1176 note ---- rob FILE: robustness of "mh parse" (adapted from omega-zip `74e9e36d` robline) ---- 1177 note FILE cut at 64 evenly spaced lengths k*(n-1)/63 (0 and n-1 included), and changed at 256 evenly 1178 note spaced bytes k*n/256 (xor 255; every 4th position, k rem 4 = 3, also set to 0). Each input is 1179 note written fresh to @S/rob.in and fed to "mh parse" on stdin. A run passes with exit 0, or exit 4 1180 note with exactly one JSONL line containing "refused"; a trap (101..114), a signal, the time limit or 1181 note any other exit fails. ga_v: 22 quiet, 23..26 runs/ok/refused/failed of the step, 27..29 totals. 1182 fn ga_wrbuf fd int b view uchar * k ulong to bool 1183 w = ulong 0 1184 while lt w k bound `9223372036854775807` 1185 r = write fd b w sub k w 1186 if le r 0 1187 ret false 1188 end 1189 w = add w ulong r 1190 end 1191 ret true 1192 end 1193 fn ga_robcopy fd int n ulong to bool 1194 b = new uchar 65536 0 1195 o = ulong 0 1196 while lt o n bound `9223372036854775807` 1197 m = sub n o 1198 if gt m 65536 1199 m = 65536 1200 end 1201 k = s_read GA_ROB o part b 0 m 1202 if eq k 0 1203 ret false 1204 end 1205 if not ga_wrbuf fd b k 1206 ret false 1207 end 1208 o = add o k 1209 end 1210 ret true 1211 end 1212 note ga_robwrite: @S/rob.in = the first n bytes of GA_ROB; mode 1 xors byte p with 255, mode 2 zeroes it. 1213 fn ga_robwrite n ulong p ulong mode ulong to bool 1214 b = new uchar 1 0 1215 ga_scenariopath 1216 p_t ga_robin 1217 fd = fopen gp 0 get gv VPL 577 384 1218 if lt fd 0 1219 ret false 1220 end 1221 ok = ga_robcopy int fd n 1222 if ok 1223 if ne mode 0 1224 if eq mode 1 1225 put b 0 xor s_get GA_ROB p 255 1226 end 1227 r = pwrite int fd b 0 1 long p 1228 ok = eq r 1 1229 end 1230 end 1231 z = fclose int fd 1232 ret and ok eq z 0 1233 end 1234 note ga_onerefusal: stdout is exactly one LF-terminated line that contains "refused". 1235 fn ga_onerefusal to bool 1236 ga_pt ga_stdout 1237 if not ga_load GA_FILE 1238 ret false 1239 end 1240 n = s_len GA_FILE 1241 if eq n 0 1242 ret false 1243 end 1244 if ne s_get GA_FILE sub n 1 10 1245 ret false 1246 end 1247 c = ulong 0 1248 for i ulong n bound `9223372036854775807` 1249 if eq s_get GA_FILE i 10 1250 c = add c 1 1251 end 1252 end 1253 if ne c 1 1254 ret false 1255 end 1256 ga_new GA_EXP 1257 s_addt GA_EXP ga_krefused 1258 ret ga_contains GA_FILE GA_EXP 1259 end 1260 note ga_robrun: "mh parse" < @S/rob.in; 0 ok, 1 a defined refusal, 2 a failure (status in ga_v 9). 1261 fn ga_robrun to ulong 1262 ga_pkreset 1263 ga_pk GA_BIN 1264 ga_pkt ga_parse 1265 ga_normalio 1266 ga_scenariopath 1267 p_t ga_robin 1268 ga_savepath GA_TMP 1269 ga_stream 0 GA_TMP 1270 st = ga_spawn false `120000000000` 1271 put ga_v 9 st 1272 if eq st 0 1273 ret 0 1274 end 1275 if ne st 4 1276 ret 2 1277 end 1278 if ga_onerefusal 1279 ret 1 1280 end 1281 ret 2 1282 end 1283 fn ga_rawfield i ulong to void 1284 p = ga_fo i 1285 for j ulong ga_fnlen i bound `9223372036854775807` 1286 o_b s_get GA_CASE add p j 1287 end 1288 o_flush 1289 end 1290 fn ga_robfail mode ulong pos ulong to void 1291 if eq get ga_v 22 1 1292 ret 1293 end 1294 ga_say ga_robfailt 1295 ga_rawfield 1 1296 if eq mode 0 1297 ga_say ga_cutw 1298 end 1299 if eq mode 1 1300 ga_say ga_xorw 1301 end 1302 if eq mode 2 1303 ga_say ga_zerow 1304 end 1305 ga_num pos 1306 ga_say ga_exitw 1307 ga_num get ga_v 9 1308 ga_say ga_nl 1309 end 1310 fn ga_robinc k ulong to void 1311 put ga_v k add get ga_v k 1 1312 end 1313 note ga_robone: one changed input (length n; byte p changed by mode, see ga_robwrite). 1314 fn ga_robone n ulong p ulong mode ulong to bool 1315 if not ga_robwrite n p mode 1316 ga_die ga_ioerr 1317 end 1318 r = ga_robrun 1319 ga_robinc 23 1320 if eq r 0 1321 ga_robinc 24 1322 ret true 1323 end 1324 if eq r 1 1325 ga_robinc 25 1326 ret true 1327 end 1328 ga_robinc 26 1329 if eq mode 0 1330 ga_robfail mode n 1331 else 1332 ga_robfail mode p 1333 end 1334 ret false 1335 end 1336 fn ga_robsum to void 1337 if eq get ga_v 22 1 1338 ret 1339 end 1340 for i ulong 3 1341 put ga_v add 27 i add get ga_v add 27 i get ga_v add 23 i 1342 end 1343 ga_say ga_robrep 1344 ga_rawfield 1 1345 ga_say ga_runsw 1346 ga_num get ga_v 23 1347 ga_say ga_okw 1348 ga_num get ga_v 24 1349 ga_say ga_refw 1350 ga_num get ga_v 25 1351 ga_say ga_nl 1352 end 1353 note ga_robcuts / ga_robbytes: the two families; quiet (mutant) runs stop at the first failure. 1354 fn ga_robcuts n ulong to bool 1355 m = ulong 0 1356 if gt n 0 1357 m = sub n 1 1358 end 1359 q = div m 63 1360 r = rem m 63 1361 ok = true 1362 for k ulong 64 1363 c = add mul q k div mul r k 63 1364 if not ga_robone c c 0 1365 ok = false 1366 if eq get ga_v 22 1 1367 ret false 1368 end 1369 end 1370 end 1371 ret ok 1372 end 1373 fn ga_robbytes n ulong to bool 1374 q = div n 256 1375 r = rem n 256 1376 ok = true 1377 for k ulong 256 1378 p = add mul q k div mul r k 256 1379 if lt p n 1380 if not ga_robone n p 1 1381 ok = false 1382 end 1383 if eq rem k 4 3 1384 if not ga_robone n p 2 1385 ok = false 1386 end 1387 end 1388 if not ok 1389 if eq get ga_v 22 1 1390 ret false 1391 end 1392 end 1393 end 1394 end 1395 ret ok 1396 end 1397 fn ga_robstep to bool 1398 if ne get ga_v 0 2 1399 ret false 1400 end 1401 for i ulong 4 1402 put ga_v add 23 i 0 1403 end 1404 ga_fpath 1 1405 if not ga_load GA_ROB 1406 ret false 1407 end 1408 n = s_len GA_ROB 1409 ok = ga_robcuts n 1410 if ok 1411 ok = ga_robbytes n 1412 else 1413 if ne get ga_v 22 1 1414 z = ga_robbytes n 1415 end 1416 end 1417 ga_robsum 1418 s_close GA_ROB 1419 ret ok 1420 end 1421 fn ga_action to bool 1422 if ga_is 0 ga_robw 1423 ret ga_robstep 1424 end 1425 if ga_is 0 ga_outsha 1426 ret ga_shaout 1427 end 1428 if ga_is 0 ga_maxns 1429 ret le get ga_v 13 ga_fnum 1 1430 end 1431 if ga_is 0 ga_run 1432 ret ga_process false 1433 end 1434 if ga_is 0 ga_bg 1435 ret ga_process true 1436 end 1437 if ga_is 0 ga_wait 1438 ret ga_waitstep 1439 end 1440 if ga_is 0 ga_gen 1441 ret ga_genstep 1442 end 1443 if ga_is 0 ga_mkdir 1444 ga_fpath 1 1445 ret ga_mkp 1446 end 1447 if ga_is 0 ga_copy 1448 ret ga_copyaction 1449 end 1450 if ga_is 0 ga_write 1451 ret ga_writefile false 1452 end 1453 if ga_is 0 ga_append 1454 ret ga_writefile true 1455 end 1456 if ga_is 0 ga_flip 1457 ret ga_flipfile 1458 end 1459 if ga_is 0 ga_symlink 1460 ret ga_linkaction 1461 end 1462 if or ga_is 0 ga_exists ga_is 0 ga_absent 1463 ga_fpath 1 1464 k = p_kind 1465 if ga_is 0 ga_exists 1466 ret ne k 0 1467 end 1468 ret eq k 0 1469 end 1470 if or or ga_is 0 ga_outeq ga_is 0 ga_outhas ga_is 0 ga_outnot 1471 ret ga_check 1472 end 1473 if or or ga_is 0 ga_outlines ga_is 0 ga_errhas ga_is 0 ga_fileeq 1474 ret ga_check 1475 end 1476 if ga_is 0 ga_errnot 1477 ret ga_check 1478 end 1479 if ga_is 0 ga_treenot 1480 ret ga_treestep 1481 end 1482 if or ga_is 0 ga_filehas ga_is 0 ga_filenot 1483 ret ga_check 1484 end 1485 ret false 1486 end 1487 fn ga_stopbg to void 1488 if ne get ga_v 8 0 1489 z = killpid int get ga_v 8 9 1490 st = ga_reap long get ga_v 8 `120000000000` 1491 put ga_v 8 0 1492 end 1493 end 1494 fn ga_scenariopath to void 1495 ga_pt ga_sdir 1496 p_t ga_slash 1497 p_s GA_SCEN 0 s_len GA_SCEN 1498 end 1499 note ga_line: the failing step's text, from its first field to the end of the line. 1500 fn ga_line to void 1501 p = ga_fo 0 1502 for i ulong sub get ga_v 1 p bound `9223372036854775807` 1503 o_b s_get GA_CASE add p i 1504 end 1505 o_flush 1506 end 1507 fn ga_scenario quiet bool to bool 1508 put ga_v 22 0 1509 if quiet 1510 put ga_v 22 1 1511 end 1512 ga_scenariopath 1513 if not ga_wipe 1514 ga_die ga_ioerr 1515 end 1516 ga_scenariopath 1517 if not ga_mkp 1518 ga_die ga_ioerr 1519 end 1520 s_close GA_CASE 1521 ga_path GA_LAST 1522 p_t ga_slash 1523 p_s GA_SCEN 0 s_len GA_SCEN 1524 if not ga_load GA_CASE 1525 ga_die ga_ioerr 1526 end 1527 p = ulong 0 1528 steps = ulong 0 1529 while lt p s_len GA_CASE bound `9223372036854775807` 1530 q = ga_eol GA_CASE p 1531 ga_fields p q 1532 p = add q 1 1533 if eq get ga_v 0 0 1534 continue 1535 end 1536 if eq s_get GA_CASE ga_fo 0 35 1537 continue 1538 end 1539 steps = add steps 1 1540 if not ga_action 1541 ga_stopbg 1542 if not quiet 1543 ga_say ga_fail 1544 ga_print GA_SCEN 1545 ga_say ga_step 1546 ga_num steps 1547 ga_say ga_reason 1548 if or ga_is 0 ga_run ga_is 0 ga_wait 1549 ga_say ga_badexit 1550 ga_num get ga_v 9 1551 ga_say ga_want 1552 ga_num get ga_v 10 1553 ga_say ga_close 1554 else 1555 if ga_is 0 ga_maxns 1556 ga_say ga_slow 1557 ga_num get ga_v 13 1558 ga_say ga_ns 1559 ga_num ga_fnum 1 1560 else 1561 ga_say ga_mismatch 1562 ga_say ga_reason 1563 ga_line 1564 end 1565 end 1566 ga_say ga_nl 1567 end 1568 ret false 1569 end 1570 end 1571 if ne get ga_v 8 0 1572 ga_stopbg 1573 if not quiet 1574 ga_say ga_fail 1575 ga_print GA_SCEN 1576 ga_say ga_reason 1577 ga_say ga_wait 1578 ga_say ga_nl 1579 end 1580 ret false 1581 end 1582 if not quiet 1583 put ga_v 2 add get ga_v 2 1 1584 put ga_v 3 add get ga_v 3 steps 1585 ga_say ga_pass 1586 ga_print GA_SCEN 1587 ga_say ga_steps 1588 ga_num steps 1589 ga_say ga_nl 1590 end 1591 ret true 1592 end 1593 note Directory names stored as newline records. Lexical successor search gives deterministic sorting. 1594 fn ga_names to bool 1595 ga_new GA_NAMES 1596 ga_path GA_LAST 1597 if not d_open 0 1598 ret false 1599 end 1600 while d_next 0 bound `9223372036854775807` 1601 n = get gv VDNL 1602 if lt n 4 1603 continue 1604 end 1605 q = get gv VDNO 1606 if ne get gde add q sub n 4 46 1607 continue 1608 end 1609 if ne get gde add q sub n 3 116 1610 continue 1611 end 1612 if ne get gde add q sub n 2 120 1613 continue 1614 end 1615 if ne get gde add q sub n 1 116 1616 continue 1617 end 1618 for i ulong n bound 256 1619 z = s_add GA_NAMES get gde add q i 1620 end 1621 s_addt GA_NAMES ga_nl 1622 end 1623 d_close 0 1624 ret true 1625 end 1626 fn ga_cmp ao ulong an ulong b ulong bo ulong bn ulong to int 1627 n = an 1628 if lt bn n 1629 n = bn 1630 end 1631 for i ulong n bound `9223372036854775807` 1632 ac = s_get GA_NAMES add ao i 1633 bc = s_get b add bo i 1634 if lt ac bc 1635 ret -1 1636 end 1637 if gt ac bc 1638 ret 1 1639 end 1640 end 1641 if lt an bn 1642 ret -1 1643 end 1644 if gt an bn 1645 ret 1 1646 end 1647 ret 0 1648 end 1649 fn ga_nextname to bool 1650 best = s_len GA_NAMES 1651 bestn = ulong 0 1652 p = ulong 0 1653 while lt p s_len GA_NAMES bound `9223372036854775807` 1654 q = ga_eol GA_NAMES p 1655 n = sub q p 1656 if gt ga_cmp p n GA_SCEN 0 s_len GA_SCEN 0 1657 if eq best s_len GA_NAMES 1658 best = p 1659 bestn = n 1660 else 1661 if lt ga_cmp p n GA_NAMES best bestn 0 1662 best = p 1663 bestn = n 1664 end 1665 end 1666 end 1667 p = add q 1 1668 end 1669 if eq best s_len GA_NAMES 1670 ret false 1671 end 1672 ga_new GA_SCEN 1673 s_adds GA_SCEN GA_NAMES best bestn 1674 ret true 1675 end 1676 fn ga_all quiet bool to ulong 1677 ga_new GA_SCEN 1678 bad = ulong 0 1679 while ga_nextname bound `9223372036854775807` 1680 if not ga_scenario quiet 1681 bad = add bad 1 1682 if quiet 1683 ret bad 1684 end 1685 end 1686 end 1687 ret bad 1688 end 1689 fn ga_bar p0 ulong e ulong to ulong 1690 p = p0 1691 while lt p e bound `9223372036854775807` 1692 if eq s_get GA_MUT p 124 1693 ret p 1694 end 1695 p = add p 1 1696 end 1697 ret e 1698 end 1699 note ga_occ: the optional fifth mutant field K/T: replace only occurrence K of OLD, and refuse the 1700 note mutant unless OLD occurs exactly T times in its file (so a moved line cannot hit another call). 1701 fn ga_occ p ulong e ulong to void 1702 q = p 1703 while lt q e bound `9223372036854775807` 1704 if eq s_get GA_MUT q 47 1705 break 1706 end 1707 q = add q 1 1708 end 1709 if ge q e 1710 ga_die ga_badline 1711 end 1712 put ga_v 20 ga_numrange GA_MUT p sub q p 1713 put ga_v 21 ga_numrange GA_MUT add q 1 sub sub e q 1 1714 if or eq get ga_v 20 0 gt get ga_v 20 get ga_v 21 1715 ga_die ga_badline 1716 end 1717 end 1718 fn ga_mutant p ulong e ulong to bool 1719 a = ga_bar p e 1720 b = ga_bar add a 1 e 1721 c = ga_bar add b 1 e 1722 if ge c e 1723 ret false 1724 end 1725 ga_new GA_SPEC 1726 s_adds GA_SPEC GA_MUT add a 1 sub sub b a 1 1727 ga_new GA_OLD 1728 s_adds GA_OLD GA_MUT add b 1 sub sub c b 1 1729 d = ga_bar add c 1 e 1730 ga_new GA_NEW 1731 s_adds GA_NEW GA_MUT add c 1 sub sub d c 1 1732 put ga_v 20 0 1733 put ga_v 21 0 1734 if lt d e 1735 ga_occ add d 1 e 1736 end 1737 put ga_v 5 add get ga_v 5 1 1738 ok = false 1739 if eq get ga_v 11 0 1740 ok = ga_compile ga_srcunits ga_mutbin true 1741 else 1742 ok = false 1743 end 1744 if not ok 1745 ga_say ga_mutfail 1746 else 1747 ga_new GA_BIN 1748 s_addt GA_BIN ga_mutbin 1749 bad = ga_all true 1750 if gt bad 0 1751 put ga_v 6 add get ga_v 6 1 1752 ga_say ga_mutkill 1753 else 1754 ok = false 1755 ga_say ga_mutsurv 1756 end 1757 end 1758 for i ulong sub a p bound `9223372036854775807` 1759 o_b s_get GA_MUT add p i 1760 end 1761 o_flush 1762 ga_say ga_nl 1763 ret ok 1764 end 1765 fn ga_mutants to bool 1766 ok = true 1767 p = ulong 0 1768 while lt p s_len GA_MUT bound `9223372036854775807` 1769 q = ga_eol GA_MUT p 1770 if gt q p 1771 if ne s_get GA_MUT p 35 1772 if not ga_mutant p q 1773 ok = false 1774 end 1775 end 1776 end 1777 p = add q 1 1778 end 1779 ret ok 1780 end 1781 fn ga_argstore i ulong s ulong to bool 1782 b = new uchar 131072 0 1783 r = argread i b 0 131072 1784 if le r 0 1785 ret false 1786 end 1787 ga_new s 1788 s_addt s part b 0 ulong r 1789 ret true 1790 end 1791 note ga_lock: one gate run at a time owns build/gate; the lock is released when the process exits. 1792 fn ga_lock to void 1793 ga_pt ga_lockf 1794 fd = fopen gp 0 get gv VPL 577 384 1795 if lt fd 0 1796 ga_die ga_ioerr 1797 end 1798 r = flock int fd 6 1799 if eq r -11 1800 ga_say ga_lockwait 1801 r = flock int fd 2 1802 end 1803 if ne r 0 1804 ga_die ga_ioerr 1805 end 1806 end 1807 fn main to int 1808 b = new uchar 4096 0 1809 if lt argcnt 2 1810 ga_say ga_usage 1811 ret 3 1812 end 1813 if not ga_argstore 1 GA_OMC 1814 ga_say ga_usage 1815 ret 3 1816 end 1817 if not ga_pinok 1818 ga_say ga_notrun 1819 ret 3 1820 end 1821 r = cwd b 0 4096 1822 if le r 0 1823 ga_die ga_ioerr 1824 end 1825 ga_new GA_ROOT 1826 s_addt GA_ROOT part b 0 sub ulong r 1 1827 ga_new GA_LAST 1828 s_addt GA_LAST ga_cases 1829 if gt argcnt 2 1830 if not ga_argstore 2 GA_LAST 1831 ga_die ga_badline 1832 end 1833 end 1834 ga_pt ga_build 1835 if not ga_mkp 1836 ga_die ga_ioerr 1837 end 1838 ga_pt ga_dir 1839 if not ga_mkp 1840 ga_die ga_ioerr 1841 end 1842 ga_lock 1843 ga_say ga_timeout 1844 if not ga_compile ga_srcunits ga_mh false 1845 ga_say ga_buildfail 1846 ret 1 1847 end 1848 ga_pt ga_sinkunits 1849 if eq p_kind 0 1850 ga_say ga_sinknote 1851 else 1852 if not ga_compile ga_sinkunits ga_sink false 1853 ga_say ga_buildfail 1854 ret 1 1855 end 1856 end 1857 ga_pt ga_srvunits 1858 if eq p_kind 0 1859 ga_say ga_srvnote 1860 else 1861 if not ga_compile ga_srvunits ga_srvbin false 1862 ga_say ga_buildfail 1863 ret 1 1864 end 1865 end 1866 if not ga_names 1867 ga_die ga_ioerr 1868 end 1869 if eq s_len GA_NAMES 0 1870 ga_die ga_badline 1871 end 1872 ga_new GA_BIN 1873 s_addt GA_BIN ga_mh 1874 bad = ga_pincheck 1875 bad = add bad ga_all false 1876 if eq bad 0 1877 if gt argcnt 3 1878 if not ga_argstore 3 GA_TMP 1879 ga_die ga_badline 1880 end 1881 ga_path GA_TMP 1882 else 1883 ga_pt ga_muts 1884 end 1885 if not ga_load GA_MUT 1886 ga_die ga_ioerr 1887 end 1888 if not ga_mutants 1889 bad = add bad 1 1890 end 1891 end 1892 if gt get ga_v 27 0 1893 ga_say ga_robtot 1894 ga_num get ga_v 27 1895 ga_say ga_okw 1896 ga_num get ga_v 28 1897 ga_say ga_refw 1898 ga_num get ga_v 29 1899 ga_say ga_nl 1900 end 1901 if eq bad 0 1902 ga_say ga_finalpass 1903 else 1904 ga_say ga_finalfail 1905 end 1906 ga_num get ga_v 2 1907 ga_say ga_steps 1908 ga_num get ga_v 3 1909 ga_say ga_mutcount 1910 ga_num get ga_v 6 1911 ga_say ga_slash 1912 ga_num get ga_v 5 1913 ga_say ga_nl 1914 if ne bad 0 1915 ret 1 1916 end 1917 ret 0 1918 end 1919 note ga_treestep: "tree-not DIR TEXT": no regular file under DIR (symlinks are not followed) contains 1920 note TEXT; used for the credential leak scan. A hit prints "tree-not hit: PATH" and fails the step. 1921 text ga_treehit "tree-not hit: " 1922 fn ga_treestep to bool 1923 ga_rest 2 1924 ga_new GA_TMP 1925 s_adds GA_TMP GA_EXP 0 s_len GA_EXP 1926 if eq s_len GA_TMP 0 1927 ret false 1928 end 1929 ga_fpath 1 1930 if ne p_kind 1 1931 ret false 1932 end 1933 ga_new GA_STACK 1934 ga_push 0 1935 while gt s_len GA_STACK 0 bound `9223372036854775807` 1936 z = ga_pop 1937 k = p_kind 1938 if eq k 2 1939 if not ga_load GA_FILE 1940 ret false 1941 end 1942 if ga_contains GA_FILE GA_TMP 1943 ga_say ga_treehit 1944 ga_new GA_FILE 1945 for i ulong get gv VPL bound 4096 1946 zb = s_add GA_FILE get gp i 1947 end 1948 ga_print GA_FILE 1949 ga_say ga_nl 1950 ret false 1951 end 1952 end 1953 if eq k 1 1954 if not d_open 0 1955 ret false 1956 end 1957 p_save 1958 while d_next 0 bound `9223372036854775807` 1959 p_restore 1960 p_c 47 1961 p_dn 1962 if not p_ok 1963 d_close 0 1964 ret false 1965 end 1966 ga_push 0 1967 end 1968 d_close 0 1969 end 1970 end 1971 ret true 1972 end