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/gpu/nvidia/checks/gate.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 / gpu / nvidia / checks / gate.om` 1855 lines ยท 37009 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note gpu/nvidia/checks/gate.om: OMEGA-GPU-CHECKS, the gate of the Omega checks in gpu/nvidia/checks (README.md 3 note there), one slice of the port of CUDApp tests/ and tools/, in seeded Omega (Linux AArch64). Build from the 4 note repository root (OM-2 program mode; seed/ng/sha256.om supplies sh_dat, sh_init, sh_blk, sh_out, sh_dig): 5 note { printf 'om2\n'; cat seed/ng/sha256.om gpu/nvidia/checks/gate.om; } | seed/out/omc > checks-gate 6 note Run from the repository root: checks-gate OMC SCRATCH 7 note OMC the compiler under test; its sha256 must equal the first word of seed/out/omc.sha256, or nothing 8 note runs (exit 69, nothing written) 9 note SCRATCH a new directory (created 0700); SCRATCH/ and a file name of Linux NAME_MAX bytes must fit Linux 10 note PATH_MAX, and an existing directory is refused (both exit 2) 11 note Checks. gpu/nvidia/checks/checks.tsv lists every check, one per line: NAME, TABLE, then the paths of its parts, 12 note single spaces; # starts a comment line and an empty line is skipped. NAME is of A-Z a-z 0-9 _ , at least one 13 note byte and short enough that NAME and the longest suffix the gate gives it in SCRATCH fit Linux NAME_MAX, and 14 note appears once. The parts are concatenated in order, each followed by a newline, into SCRATCH/NAME.om; a line 15 note that starts with "export fn " is composed as "fn " (an exported function of a function-mode unit becomes an 16 note ordinary function of the check program; nothing else of the unit changes). OMC compiles it twice: each 17 note compile exits 0 with empty stderr and both outputs hold the same bytes. The check then runs as 18 note SCRATCH/NAME.1 TABLE > SCRATCH/NAME.out 2> SCRATCH/NAME.run.err and must exit 0 with empty stderr. 19 note Controls, each must be caught: 20 note per check: TABLE with one byte changed (the last byte of its first case line: 0..8 and a..e step up by one, 21 note 9 and f become 0, anything else becomes 0) must make the check exit 1; 22 note per row of gpu/nvidia/checks/mutants.tsv (NAME, PART, FROM, TO split by tabs; # starts a comment line, an 23 note empty line is skipped): the parts of check NAME composed again with the one line of PART that equals FROM 24 note (as composed, so "export fn " already reads "fn ") replaced by TO must compile (exit 0) and the check built 25 note from it must exit 1 on TABLE, a source mutant the check has to notice; FROM matching no line, or more than 26 note one line, of PART is a failure; 27 note a mutants.tsv row of six fields (NAME, PART, FROM, TO, EXIT, KTABLE) records a known difference that ends the 28 note check (a trap): the check as composed must exit EXIT (decimal, 1..255) on KTABLE, and the mutant (TO is the 29 note repair) must exit 0 on KTABLE, so KTABLE holds the pending C's answers and the repaired unit gives every one; 30 note either side moving fails the row; 31 note once: a compiler one byte longer fails the digest check. 32 note Inventory: every row of gpu/nvidia/checks/ports.tsv (PATH, STATUS, DETAIL split by tabs) must be the status 33 note and detail of PATH's row in gpu/nvidia/checks/INVENTORY.tsv, every other INVENTORY row must be open, the 34 note INVENTORY footer counts (files, ported, retired, blocked, open) must be its rows, and every om_ref and 35 note same_stem cell that is not - must name a .om file under gpu/ of this tree; a failure means INVENTORY.tsv was 36 note not regenerated with inventory.om after ports.tsv or the tree changed. 37 note Output: one line per check, control and the inventory, then 38 note OMEGA-GPU-CHECKS PASS|FAIL checks=N controls=C caught=K hardware=NOT_RUN, where C = 1 + the rows of checks.tsv 39 note + the rows of mutants.tsv. 40 note Exit 0 PASS, 1 FAIL, 2 bad usage or setup, 69 compiler digest refused. Every input is length-checked; a trap 41 note exit (101..114) would be a defect of this gate, never a pass. Host only: no check opens a device. 42 text t_pin "seed/out/omc.sha256" 43 text t_tab "gpu/nvidia/checks/checks.tsv" 44 text t_om ".om" 45 text t_b1 ".1" 46 text t_b2 ".2" 47 text t_e1 ".1.err" 48 text t_e2 ".2.err" 49 text t_out ".out" 50 text t_rerr ".run.err" 51 text t_bad ".bad.tsv" 52 text t_badname "checks.tsv: name outside A-Z a-z 0-9 _" 53 text t_dup "checks.tsv: name repeated, or the host refused the memory" 54 text t_empty "checks.tsv names no check" 55 text t_plus "omc-plus-one" 56 text t_usage "usage: checks-gate OMC SCRATCH (run from the omega-mv repository root)\n" 57 text t_refd "OMEGA-GPU-CHECKS REFUSED: compiler digest differs from seed/out/omc.sha256 (exit 69)\n" 58 text t_nopin "OMEGA-GPU-CHECKS INVALID: cannot read a 64-hex digest from seed/out/omc.sha256\n" 59 text t_noscr "OMEGA-GPU-CHECKS INVALID: SCRATCH exists or cannot be made\n" 60 text t_notab "OMEGA-GPU-CHECKS INVALID: cannot read gpu/nvidia/checks/checks.tsv\n" 61 text t_long "OMEGA-GPU-CHECKS INVALID: SCRATCH is too long: SCRATCH/ and a file name of Linux NAME_MAX bytes would not fit Linux PATH_MAX\n" 62 text t_ok "ok " 63 text t_fail "FAIL " 64 text t_unit "check " 65 text t_ctl "control " 66 text t_bytes " bytes=" 67 text t_sha " sha256=" 68 text t_exit " exit=" 69 text t_src "source unreadable: " 70 text t_big "output unreadable or the host refused the memory" 71 text t_cmp "compile" 72 text t_stderr " stderr not empty" 73 text t_twice " two builds differ" 74 text t_write "cannot write the composed check in SCRATCH" 75 text t_row "checks.tsv: malformed row (a name that fits Linux NAME_MAX with its longest scratch suffix, a table, at least one part)" 76 text t_plong "checks.tsv: a path does not fit Linux PATH_MAX" 77 text t_run "run" 78 text t_rstderr "run stderr not empty" 79 text t_says " says: " 80 text t_tabbad "table unreadable, or without a case line" 81 text t_mut "-table-mutated" 82 text t_caught " caught" 83 text t_esc " ESCAPED" 84 text t_kheld " known exit held, repair gives the recorded answers" 85 text t_kfix " repair does not give the recorded answers on KTABLE" 86 text t_kmoved "the check no longer exits EXIT on KTABLE (the known difference moved)" 87 text t_sum "OMEGA-GPU-CHECKS " 88 text t_pass "PASS" 89 text t_fl "FAIL" 90 text t_su " checks=" 91 text t_sc " controls=" 92 text t_sk " caught=" 93 text t_hw " hardware=NOT_RUN\n" 94 text t_mutf "gpu/nvidia/checks/mutants.tsv" 95 text t_nomut "OMEGA-GPU-CHECKS INVALID: cannot read gpu/nvidia/checks/mutants.tsv\n" 96 text t_mo ".m" 97 text t_me ".m.err" 98 text t_msrc "-source-mutant-line-" 99 text t_mrow "mutants.tsv: malformed row (NAME, PART, FROM, TO, and optionally EXIT 1..255 and KTABLE, split by tabs)" 100 text t_mnot "FROM is not a line of PART" 101 text t_muniq "FROM is more than one line of PART" 102 text t_mcmp "the mutant does not compile" 103 text t_ports "gpu/nvidia/checks/ports.tsv" 104 text t_invf "gpu/nvidia/checks/INVENTORY.tsv" 105 text t_invk "inventory " 106 text t_line " line " 107 text t_colon ": " 108 text t_invnop "cannot read gpu/nvidia/checks/ports.tsv" 109 text t_invnoi "cannot read gpu/nvidia/checks/INVENTORY.tsv" 110 text t_invrow "not PATH, STATUS, DETAIL split by tabs" 111 text t_invmiss "INVENTORY.tsv has no row for this path (regenerate it with inventory.om)" 112 text t_invdiff "INVENTORY.tsv status or detail differs from this row (regenerate it with inventory.om)" 113 text t_invcnt "INVENTORY.tsv: its ported, retired and blocked rows are not exactly the rows of ports.tsv, or a status is unknown" 114 text t_invfoot "INVENTORY.tsv: the footer counts (files, ported, retired, blocked, open) differ from its rows" 115 text t_invref "INVENTORY.tsv: an om_ref or same_stem cell names no .om file under gpu/ of this tree (regenerate it with inventory.om): " 116 text t_gpu "gpu/" 117 text t_sported "ported" 118 text t_sretired "retired" 119 text t_sblocked "blocked" 120 text t_sopen "open" 121 text t_hpath "path" 122 text t_ffiles " files=" 123 text t_fported " ported=" 124 text t_fretired " retired=" 125 text t_fblocked " blocked=" 126 text t_fopen " open=" 127 text t_invok "ok inventory gpu/nvidia/checks/INVENTORY.tsv says what ports.tsv says" 128 global g_pa uchar 4096 129 global g_scr uchar 4096 130 global g_omc uchar 4096 131 global g_nm uchar 256 132 note g_av: the argument list for execprog, a 2-byte count, then each argument as a 2-byte length and its bytes; 133 note the gate passes at most two arguments, each a path of at most len g_pa - 1 bytes (shorter than Linux 134 note PATH_MAX), so it holds 2 + 2 * (len g_pa + 1) bytes 135 global g_av uchar 8196 136 global g_b uchar * 137 global g_u uchar * 138 global g_o uchar 8192 139 global g_hx uchar 64 140 global g_pin uchar 64 141 global g_d1 uchar 32 142 global g_stb uchar 4 143 global g_n ulong 40 144 global g_seen uchar * 145 global g_tb uchar 4096 146 global g_m uchar * 147 global g_p uchar * 148 global g_ic ulong 16 149 global g_tl uchar * 150 note g_n: 0 path length, 1 omc length, 2 scratch length (with '/'), 3 argv bytes, 4 argc, 5 output length, 151 note 6 buffer length, 7 table length, 8 checks passed, 11 failures, 12 controls, 13 caught, 14 name length, 152 note 15 g_seen length, 16 check rows, 17 table path length (g_tb), 19 mutants.tsv length (g_m), 20 a mutant is 153 note being composed, 21 it was applied (1), the host refused the memory (2) or FROM is more than one line (3), 22/23 the parts of the current check in g_u, 154 note 24/25 PART, 26/27 FROM, 28/29 TO of the mutant in g_m, 30 its line in mutants.tsv, 31 ports.tsv length, 155 note 33 the mutant row has six fields (1), 34 its EXIT, 35/36 its KTABLE in g_m 156 note ---- output 157 note one output byte; g_o is written out whenever it fills, so a line of any length is printed whole 158 fn oc c ulong to void 159 n = get g_n 5 160 if ge n len g_o 161 oflush 162 n = 0 163 end 164 put g_o n uchar c 165 put g_n 5 add n 1 166 end 167 fn ot t view uchar * to void 168 for i ulong len t bound 4096 169 oc ulong get t i 170 end 171 end 172 fn onm to void 173 for i ulong get g_n 14 bound 256 174 oc ulong get g_nm i 175 end 176 end 177 fn onum v ulong to void 178 if ge v 10 179 onum div v 10 180 end 181 oc add 48 rem v 10 182 end 183 fn ohex to void 184 for j ulong 32 185 b = get sh_dig j 186 oc ulong sh_hexd uint shr b 4 187 oc ulong sh_hexd uint and b 15 188 end 189 end 190 fn ohx to void 191 for j ulong 64 192 oc ulong get g_hx j 193 end 194 end 195 fn oflush to void 196 r = write 1 g_o 0 get g_n 5 197 put g_n 5 0 198 end 199 fn onl to void 200 oc 10 201 oflush 202 end 203 note a failed check: FAIL KIND NAME then the reason; counts a failure 204 fn ofail kind view uchar * why view uchar * to void 205 ot t_fail 206 ot kind 207 onm 208 oc 32 209 ot why 210 onl 211 put g_n 11 add get g_n 11 1 212 end 213 note ---- paths: g_pa[0, g_n 0) 214 fn pclr to void 215 put g_n 0 0 216 end 217 fn pc c ulong to void 218 n = get g_n 0 219 put g_pa n uchar c 220 put g_n 0 add n 1 221 end 222 fn pt t view uchar * to void 223 for i ulong len t bound 4096 224 pc ulong get t i 225 end 226 end 227 fn pscr to void 228 for j ulong get g_n 2 bound 4096 229 pc ulong get g_scr j 230 end 231 end 232 fn pnm to void 233 for j ulong get g_n 14 bound 256 234 pc ulong get g_nm j 235 end 236 end 237 note scratch file NAME then suffix 238 fn psn suf view uchar * to void 239 pclr 240 pscr 241 pnm 242 pt suf 243 end 244 note scratch file named by a text 245 fn pst t view uchar * suf view uchar * to void 246 pclr 247 pscr 248 pt t 249 pt suf 250 end 251 note scratch file named by a text alone 252 fn psc t view uchar * to void 253 pclr 254 pscr 255 pt t 256 end 257 fn nmset t view uchar * to void 258 for i ulong len t bound 256 259 put g_nm i get t i 260 end 261 put g_n 14 len t 262 end 263 note ---- files 264 fn fopn fl ulong mode ulong to int 265 r = fopen g_pa 0 get g_n 0 int fl int mode 266 if lt r 0 267 ret -1 268 end 269 ret int r 270 end 271 fn frd to int 272 ret fopn 524288 0 273 end 274 fn fwr to int 275 ret fopn 524865 420 276 end 277 fn fexe to int 278 r = unlink g_pa 0 get g_n 0 279 ret fopn 524865 448 280 end 281 fn fclo fd int to void 282 if ge fd 0 283 r = fclose fd 284 end 285 end 286 note append the file at g_pa to g_b, growing g_b to fit; false when unreadable or the host refuses the memory 287 fn bload to bool 288 fd = frd 289 if lt fd 0 290 ret false 291 end 292 n = get g_n 6 293 ok = true 294 while true bound `9223372036854775807` 295 if ge add n 1 len g_b 296 r = enlarge g_b add add n n 65536 297 if lt r 0 298 ok = false 299 break 300 end 301 end 302 x = read fd g_b n sub len g_b n 303 if lt x 0 304 ok = false 305 break 306 end 307 if eq x 0 308 break 309 end 310 n = add n ulong x 311 end 312 fclo fd 313 put g_n 6 n 314 ret ok 315 end 316 note write g_b[0, g_n 6) to the file at g_pa (0644, or 0700 when exe) 317 fn bsave exe bool to bool 318 fd = int -1 319 if exe 320 fd = fexe 321 else 322 fd = fwr 323 end 324 if lt fd 0 325 ret false 326 end 327 n = get g_n 6 328 o = ulong 0 329 ok = true 330 while lt o n bound `9223372036854775807` 331 x = write fd g_b o sub n o 332 if le x 0 333 ok = false 334 break 335 end 336 o = add o ulong x 337 end 338 fclo fd 339 ret ok 340 end 341 note sha256 of the file at g_pa into sh_dig, read in pieces through sh_dat so a file of any size is hashed; 342 note false when unreadable 343 fn fhash to bool 344 fd = frd 345 if lt fd 0 346 ret false 347 end 348 sh_init 349 for j ulong 8 350 put sh_h j get sh_k add j 64 351 end 352 k = ulong 0 353 tot = ulong 0 354 ok = true 355 while true bound `9223372036854775807` 356 x = read fd sh_dat k sub len sh_dat k 357 if lt x 0 358 ok = false 359 break 360 end 361 if eq x 0 362 break 363 end 364 k = add k ulong x 365 tot = add tot ulong x 366 nb = div k 64 367 for b ulong nb bound 262144 368 sh_blk 0 mul b 64 369 end 370 o = mul nb 64 371 r = rem k 64 372 for j ulong r bound 64 373 put sh_dat j get sh_dat add o j 374 end 375 k = r 376 end 377 fclo fd 378 if not ok 379 ret false 380 end 381 hfin k tot 382 ret true 383 end 384 note finish the digest of a message of tot bytes whose last k (under 64) bytes are at the front of sh_dat: 385 note FIPS 180-4 padding, as sh_all of seed/ng/sha256.om does it 386 fn hfin k ulong tot ulong to void 387 for j ulong 128 388 put sh_pad j 0 389 end 390 for j ulong k bound 64 391 put sh_pad j get sh_dat j 392 end 393 put sh_pad k 128 394 e = ulong 64 395 if ge k 56 396 e = 128 397 end 398 bits = mul tot 8 399 for j ulong 8 400 put sh_pad sub sub e 1 j uchar and shr bits mul j 8 255 401 end 402 sh_blk 1 0 403 if eq e 128 404 sh_blk 1 64 405 end 406 sh_out 407 end 408 note the size of the file at g_pa, or 2^63 when unreadable 409 fn fsize to ulong 410 put g_n 6 0 411 if not bload 412 ret shl ulong 1 63 413 end 414 ret get g_n 6 415 end 416 note sh_dig equals the hex in g_hx 417 fn digeq to bool 418 for j ulong 32 419 b = get sh_dig j 420 if ne get g_hx mul j 2 sh_hexd uint shr b 4 421 ret false 422 end 423 if ne get g_hx add mul j 2 1 sh_hexd uint and b 15 424 ret false 425 end 426 end 427 ret true 428 end 429 fn dsave to void 430 for j ulong 32 431 put g_d1 j get sh_dig j 432 end 433 end 434 fn dsame to bool 435 for j ulong 32 436 if ne get g_d1 j get sh_dig j 437 ret false 438 end 439 end 440 ret true 441 end 442 note ---- processes 443 fn aclr to void 444 put g_n 3 2 445 put g_n 4 0 446 put g_av 0 0 447 put g_av 1 0 448 end 449 note append g_pa as one argument; the argument list must fit g_av, else exit 2 (see the note on g_av) 450 fn apa to void 451 p = get g_n 3 452 n = get g_n 0 453 if gt add add p 2 n len g_av 454 exit 2 455 end 456 for j ulong n bound 4096 457 put g_av add add p 2 j get g_pa j 458 end 459 put g_av p uchar and n 255 460 put g_av add p 1 uchar shr n 8 461 put g_n 3 add p add n 2 462 c = add get g_n 4 1 463 put g_n 4 c 464 put g_av 0 uchar and c 255 465 put g_av 1 uchar shr c 8 466 end 467 fn atx t view uchar * to void 468 pclr 469 pt t 470 apa 471 end 472 fn redir s int d int to void 473 if ne dupfd s d 0 long d 474 exit 127 475 end 476 end 477 note run the argument list with stdin, stdout, stderr fds (closed here): the exit code, 256 + the signal, 512 478 note when a file could not be opened, 1000 when the child passed the 600 s deadline (killed) 479 fn spawn fi int fo int fe int to ulong 480 if or lt fi 0 or lt fo 0 lt fe 0 481 fclo fi 482 fclo fo 483 fclo fe 484 ret 512 485 end 486 pid = fork 487 if lt pid 0 488 exit 2 489 end 490 if eq pid 0 491 redir fi 0 492 redir fo 1 493 redir fe 2 494 r = execprog g_av 0 get g_n 3 495 exit 127 496 end 497 fclo fi 498 fclo fo 499 fclo fe 500 t0 = monons 501 while true bound `1000000000` 502 r = waitpid int pid g_stb 0 len g_stb 1 503 if eq r pid 504 x = ulong get g_stb 0 505 if ne x 0 506 ret add 256 x 507 end 508 ret ulong get g_stb 1 509 end 510 if lt r 0 511 exit 2 512 end 513 if gt sub monons t0 `600000000000` 514 r = killpid int pid 9 515 r = waitpid int pid g_stb 0 len g_stb 0 516 ret 1000 517 end 518 q = sleepns 200000 519 end 520 exit 2 521 end 522 note OMC < SCRATCH/NAME.om > SCRATCH/NAME.SUF 2> SCRATCH/NAME.ERR 523 fn omc suf view uchar * err view uchar * to ulong 524 psn t_om 525 fi = frd 526 aclr 527 pclr 528 for j ulong get g_n 1 bound 4096 529 pc ulong get g_omc j 530 end 531 apa 532 psn suf 533 fo = fexe 534 psn err 535 fe = fwr 536 ret spawn fi fo fe 537 end 538 note ---- the compiler digest 539 note the first 64 characters of seed/out/omc.sha256 into g_pin; false unless lowercase hex 540 fn pinread to bool 541 pclr 542 pt t_pin 543 put g_n 6 0 544 if not bload 545 ret false 546 end 547 if lt get g_n 6 64 548 ret false 549 end 550 for j ulong 64 551 c = get g_b j 552 ok = or and ge c 48 le c 57 and ge c 97 le c 102 553 if not ok 554 ret false 555 end 556 put g_pin j c 557 end 558 ret true 559 end 560 note the file at g_pa hashes to g_pin 561 fn pinok to bool 562 if not fhash 563 ret false 564 end 565 for j ulong 64 566 put g_hx j get g_pin j 567 end 568 ret digeq 569 end 570 note ---- units 571 note g_u[i] is c, for i below e (never reads at or past e) 572 fn uis i ulong e ulong c ulong to bool 573 if ge i e 574 ret false 575 end 576 ret eq ulong get g_u i c 577 end 578 fn uisnt i ulong e ulong c ulong to bool 579 if ge i e 580 ret false 581 end 582 ret ne ulong get g_u i c 583 end 584 note append one newline to g_b (units.sh writes one after every part) 585 fn nl to bool 586 n = get g_n 6 587 r = enlarge g_b add n 1 588 if lt r 0 589 ret false 590 end 591 put g_b n 10 592 put g_n 6 add n 1 593 ret true 594 end 595 note a missing or unreadable part: FAIL unit NAME source unreadable: PATH (the path is in g_pa) 596 fn psrcfail to void 597 ot t_fail 598 ot t_unit 599 onm 600 oc 32 601 ot t_src 602 for q ulong get g_n 0 bound 4096 603 oc ulong get g_pa q 604 end 605 onl 606 put g_n 11 add get g_n 11 1 607 end 608 text t_export "export fn " 609 note g_b[o, g_n 6) holds one part: drop the "export " of every line that starts "export fn ", in place 610 fn unexport o ulong to void 611 n = get g_n 6 612 w = o 613 i = o 614 start = true 615 while lt i n bound `9223372036854775807` 616 if start 617 if isexp i n 618 i = add i 7 619 end 620 end 621 c = get g_b i 622 put g_b w c 623 w = add w 1 624 i = add i 1 625 start = eq c 10 626 end 627 put g_n 6 w 628 end 629 fn isexp i ulong n ulong to bool 630 if gt add i len t_export n 631 ret false 632 end 633 for j ulong len t_export 634 if ne get g_b add i j get t_export j 635 ret false 636 end 637 end 638 ret true 639 end 640 note compose the parts g_u[s, e) into g_b: each part's bytes (a line starting "export fn " kept as "fn "), then 641 note one newline; false (reported) when a part is unreadable or its path does not fit Linux PATH_MAX 642 fn compose s ulong e ulong to bool 643 put g_n 6 0 644 i = s 645 while lt i e bound `9223372036854775807` 646 while uis i e 32 bound `9223372036854775807` 647 i = add i 1 648 end 649 if ge i e 650 break 651 end 652 j = i 653 while uisnt j e 32 bound `9223372036854775807` 654 j = add j 1 655 end 656 if ge sub j i len g_pa 657 ofail t_unit t_plong 658 ret false 659 end 660 pclr 661 for q ulong sub j i bound 4096 662 pc ulong get g_u add i q 663 end 664 o0 = get g_n 6 665 if not bload 666 psrcfail 667 ret false 668 end 669 unexport o0 670 if ne get g_n 20 0 671 if mpart 672 mapply o0 673 end 674 end 675 if not nl 676 ofail t_unit t_big 677 ret false 678 end 679 i = j 680 end 681 ret true 682 end 683 note compile the composed unit twice; true when both exit 0 with empty stderr and equal bytes 684 fn build to bool 685 psn t_om 686 if not bsave false 687 ofail t_unit t_write 688 ret false 689 end 690 r1 = omc t_b1 t_e1 691 r2 = omc t_b2 t_e2 692 if or ne r1 0 ne r2 0 693 ot t_fail 694 ot t_unit 695 onm 696 oc 32 697 ot t_cmp 698 ot t_exit 699 onum r1 700 oc 47 701 onum r2 702 onl 703 put g_n 11 add get g_n 11 1 704 ret false 705 end 706 psn t_e1 707 s1 = fsize 708 psn t_e2 709 s2 = fsize 710 if or ne s1 0 ne s2 0 711 ofail t_unit t_stderr 712 ret false 713 end 714 psn t_b1 715 if not fhash 716 ofail t_unit t_big 717 ret false 718 end 719 dsave 720 psn t_b2 721 if not fhash 722 ofail t_unit t_big 723 ret false 724 end 725 if not dsame 726 ofail t_unit t_twice 727 ret false 728 end 729 psn t_b1 730 sz = fsize 731 psn t_b1 732 if not fhash 733 ofail t_unit t_big 734 ret false 735 end 736 ot t_ok 737 ot t_unit 738 onm 739 ot t_bytes 740 onum sz 741 ot t_sha 742 ohex 743 onl 744 ret true 745 end 746 note Linux NAME_MAX, the longest file name a directory entry takes (getconf NAME_MAX / gives 255) 747 fn namemax to ulong 748 ret 255 749 end 750 note the larger of m and the length of t 751 fn lmax m ulong t view uchar * to ulong 752 if gt len t m 753 ret len t 754 end 755 ret m 756 end 757 note the longest suffix the gate puts after NAME in SCRATCH 758 fn sufmax to ulong 759 m = lmax 0 t_om 760 m = lmax m t_b1 761 m = lmax m t_b2 762 m = lmax m t_e1 763 m = lmax m t_e2 764 m = lmax m t_out 765 m = lmax m t_rerr 766 m = lmax m t_bad 767 m = lmax m t_mo 768 ret lmax m t_me 769 end 770 note one table row [s, e): NAME TABLE then parts; # starts a comment line; an empty line is skipped 771 fn urow s ulong e ulong to void 772 if or eq s e eq get g_u s 35 773 ret 774 end 775 put g_n 14 0 776 k = s 777 while uisnt k e 32 bound `9223372036854775807` 778 k = add k 1 779 end 780 if or ge k e or eq k s gt sub k s sub namemax sufmax 781 ofail t_unit t_row 782 ret 783 end 784 for q ulong sub k s bound 256 785 put g_nm q get g_u add s q 786 end 787 put g_n 14 sub k s 788 put g_n 16 add get g_n 16 1 789 if not nameok 790 ofail t_unit t_badname 791 ret 792 end 793 if not nameadd 794 ofail t_unit t_dup 795 ret 796 end 797 t0 = k 798 while uis t0 e 32 bound `9223372036854775807` 799 t0 = add t0 1 800 end 801 t1 = t0 802 while uisnt t1 e 32 bound `9223372036854775807` 803 t1 = add t1 1 804 end 805 if or ge t1 e or eq t1 t0 ge sub t1 t0 len g_pa 806 ofail t_unit t_row 807 ret 808 end 809 for q ulong sub t1 t0 bound 4096 810 put g_tb q get g_u add t0 q 811 end 812 put g_n 17 sub t1 t0 813 put g_n 22 t1 814 put g_n 23 e 815 if not compose t1 e 816 ret 817 end 818 if build 819 runchk 820 end 821 end 822 note the table path into g_pa 823 fn ptab to void 824 pclr 825 for j ulong get g_n 17 bound 4096 826 pc ulong get g_tb j 827 end 828 end 829 note run SCRATCH/NAME.1 with the table file at g_pa (also its stdin); the exit as spawn gives it 830 fn runon to ulong 831 aclr 832 psn t_b1 833 apa 834 ptab 835 apa 836 fi = frd 837 psn t_out 838 fo = fwr 839 psn t_rerr 840 fe = fwr 841 ret spawn fi fo fe 842 end 843 note print the last line of SCRATCH/NAME.out 844 fn olast to void 845 psn t_out 846 put g_n 6 0 847 if not bload 848 ret 849 end 850 n = get g_n 6 851 note two ifs, not one and: Omega's and reads both sides, so get g_b sub n 1 would trap on an empty output 852 if gt n 0 853 if eq get g_b sub n 1 10 854 n = sub n 1 855 end 856 end 857 b = n 858 while gt b 0 bound `9223372036854775807` 859 if eq get g_b sub b 1 10 860 break 861 end 862 b = sub b 1 863 end 864 for j ulong sub n b bound `9223372036854775807` 865 oc ulong get g_b add b j 866 end 867 end 868 note run the check on its table: exit 0 and empty stderr pass; then the mutated-table control 869 fn runchk to void 870 put g_n 18 0 871 r = runon 872 psn t_rerr 873 s = fsize 874 if ne r 0 875 ot t_fail 876 ot t_unit 877 onm 878 oc 32 879 ot t_run 880 ot t_exit 881 onum r 882 ot t_says 883 olast 884 onl 885 put g_n 11 add get g_n 11 1 886 ret 887 end 888 if ne s 0 889 ofail t_unit t_rstderr 890 ret 891 end 892 ot t_ok 893 ot t_unit 894 onm 895 oc 32 896 ot t_run 897 ot t_says 898 olast 899 onl 900 put g_n 8 add get g_n 8 1 901 ctltab 902 mutants 903 end 904 note the last byte of the first case line of g_b[0, n) (not empty, not #); n when there is none 905 fn firstcase n ulong to ulong 906 s = ulong 0 907 while lt s n bound `9223372036854775807` 908 e = s 909 while and lt e n ne get g_b e 10 bound `9223372036854775807` 910 e = add e 1 911 end 912 if gt e s 913 if ne get g_b s 35 914 ret sub e 1 915 end 916 end 917 s = add e 1 918 end 919 ret n 920 end 921 fn mutb c ulong to ulong 922 if and ge c 48 le c 56 923 ret add c 1 924 end 925 if and ge c 97 le c 101 926 ret add c 1 927 end 928 ret 48 929 end 930 note control: the table with the last byte of its first case changed must make the check exit 1 931 fn ctltab to void 932 put g_n 12 add get g_n 12 1 933 ptab 934 put g_n 6 0 935 ok = bload 936 n = get g_n 6 937 p = firstcase n 938 if or not ok ge p n 939 ofail t_ctl t_tabbad 940 ret 941 end 942 put g_b p uchar mutb ulong get g_b p 943 psn t_bad 944 if not bsave false 945 ofail t_ctl t_write 946 ret 947 end 948 aclr 949 psn t_b1 950 apa 951 psn t_bad 952 apa 953 fi = frd 954 psn t_out 955 fo = fwr 956 psn t_rerr 957 fe = fwr 958 r = spawn fi fo fe 959 if eq r 1 960 ot t_ok 961 else 962 ot t_fail 963 end 964 ot t_ctl 965 onm 966 ot t_mut 967 if eq r 1 968 ot t_caught 969 put g_n 13 add get g_n 13 1 970 else 971 ot t_esc 972 ot t_exit 973 onum r 974 put g_n 11 add get g_n 11 1 975 end 976 onl 977 end 978 note ---- source mutants: gpu/nvidia/checks/mutants.tsv in g_m[0, g_n 19) 979 note read gpu/nvidia/checks/mutants.tsv into g_m, sized from the file 980 fn mload to bool 981 pclr 982 pt t_mutf 983 put g_n 6 0 984 if not bload 985 ret false 986 end 987 n = get g_n 6 988 r = enlarge g_m add n 1 989 if lt r 0 990 ret false 991 end 992 for q ulong n bound `9223372036854775807` 993 put g_m q get g_b q 994 end 995 put g_n 19 n 996 ret true 997 end 998 note g_m[i] is not c, for i below e (never reads at or past e) 999 fn mnot i ulong e ulong c ulong to bool 1000 if ge i e 1001 ret false 1002 end 1003 ret ne ulong get g_m i c 1004 end 1005 note g_b[i] is not c, for i below e 1006 fn bnot i ulong e ulong c ulong to bool 1007 if ge i e 1008 ret false 1009 end 1010 ret ne ulong get g_b i c 1011 end 1012 note the end of the field of g_m that starts at p: the next tab, or e 1013 fn mtab p ulong e ulong to ulong 1014 q = p 1015 while mnot q e 9 bound `9223372036854775807` 1016 q = add q 1 1017 end 1018 ret q 1019 end 1020 note g_m[s, a) is the current check's name 1021 fn mname s ulong a ulong to bool 1022 if ne sub a s get g_n 14 1023 ret false 1024 end 1025 for j ulong sub a s bound 256 1026 if ne get g_m add s j get g_nm j 1027 ret false 1028 end 1029 end 1030 ret true 1031 end 1032 note the part being composed (g_pa) is PART of the current mutant 1033 fn mpart to bool 1034 s = get g_n 24 1035 if ne sub get g_n 25 s get g_n 0 1036 ret false 1037 end 1038 for j ulong get g_n 0 bound 4096 1039 if ne get g_pa j get g_m add s j 1040 ret false 1041 end 1042 end 1043 ret true 1044 end 1045 note g_b[s, e) equals FROM of the current mutant 1046 fn mline s ulong e ulong to bool 1047 f = get g_n 26 1048 if ne sub e s sub get g_n 27 f 1049 ret false 1050 end 1051 for j ulong sub e s bound `9223372036854775807` 1052 if ne get g_b add s j get g_m add f j 1053 ret false 1054 end 1055 end 1056 ret true 1057 end 1058 note replace the line of g_b[o, g_n 6) that equals FROM by TO when exactly one does; g_n 21 says what happened 1059 fn mapply o ulong to void 1060 n = get g_n 6 1061 s = o 1062 while lt s n bound `9223372036854775807` 1063 e = s 1064 while bnot e n 10 bound `9223372036854775807` 1065 e = add e 1 1066 end 1067 if mline s e 1068 if muniq add e 1 n 1069 mrepl s e n 1070 else 1071 put g_n 21 3 1072 end 1073 ret 1074 end 1075 s = add e 1 1076 end 1077 end 1078 note no line of g_b[s, n) equals FROM 1079 fn muniq s ulong n ulong to bool 1080 while lt s n bound `9223372036854775807` 1081 e = s 1082 while bnot e n 10 bound `9223372036854775807` 1083 e = add e 1 1084 end 1085 if mline s e 1086 ret false 1087 end 1088 s = add e 1 1089 end 1090 ret true 1091 end 1092 note g_b[s, e) becomes TO; the bytes from e to n move after it (copied through g_tl, sized from them) 1093 fn mrepl s ulong e ulong n ulong to void 1094 ts = get g_n 28 1095 tl = sub get g_n 29 ts 1096 k = sub n e 1097 m = add add s tl k 1098 r = enlarge g_b add m 1 1099 if lt r 0 1100 put g_n 21 2 1101 ret 1102 end 1103 r = enlarge g_tl add k 1 1104 if lt r 0 1105 put g_n 21 2 1106 ret 1107 end 1108 mmove s e k 1109 put g_n 6 m 1110 put g_n 21 1 1111 end 1112 note g_b[e, e+k) moves through g_tl to follow TO, which is written at s 1113 fn mmove s ulong e ulong k ulong to void 1114 for a ulong k bound `9223372036854775807` 1115 put g_tl a get g_b add e a 1116 end 1117 ts = get g_n 28 1118 tl = sub get g_n 29 ts 1119 for b ulong tl bound `9223372036854775807` 1120 put g_b add s b get g_m add ts b 1121 end 1122 d = add s tl 1123 for c ulong k bound `9223372036854775807` 1124 put g_b add d c get g_tl c 1125 end 1126 end 1127 note FAIL control NAME-source-mutant-line-L WHY; counts a failure 1128 fn mfail why view uchar * to void 1129 ot t_fail 1130 ot t_ctl 1131 onm 1132 ot t_msrc 1133 onum get g_n 30 1134 oc 32 1135 ot why 1136 onl 1137 put g_n 11 add get g_n 11 1 1138 end 1139 note every row of mutants.tsv that names the current check 1140 fn mutants to void 1141 n = get g_n 19 1142 s = ulong 0 1143 line = ulong 1 1144 while lt s n bound `9223372036854775807` 1145 e = s 1146 while mnot e n 10 bound `9223372036854775807` 1147 e = add e 1 1148 end 1149 put g_n 30 line 1150 mrow s e 1151 s = add e 1 1152 line = add line 1 1153 end 1154 end 1155 fn mrow s ulong e ulong to void 1156 if eq s e 1157 ret 1158 end 1159 if eq get g_m s 35 1160 ret 1161 end 1162 a = mtab s e 1163 if not mname s a 1164 ret 1165 end 1166 put g_n 12 add get g_n 12 1 1167 b = mtab add a 1 e 1168 c = mtab add b 1 e 1169 d = mtab add c 1 e 1170 if or or ge a e ge b e ge c e 1171 mfail t_mrow 1172 ret 1173 end 1174 put g_n 33 0 1175 if lt d e 1176 if not mknown d e 1177 mfail t_mrow 1178 ret 1179 end 1180 end 1181 put g_n 24 add a 1 1182 put g_n 25 b 1183 put g_n 26 add b 1 1184 put g_n 27 c 1185 put g_n 28 add c 1 1186 put g_n 29 d 1187 mrun 1188 end 1189 note the EXIT and KTABLE fields after TO, which ends at d: EXIT 1..255 in decimal, KTABLE a path that fits g_pa 1190 fn mknown d ulong e ulong to bool 1191 f = mtab add d 1 e 1192 if ge f e 1193 ret false 1194 end 1195 if ne mtab add f 1 e e 1196 ret false 1197 end 1198 x = ulong 0 1199 p = add d 1 1200 if or eq p f gt sub f p 3 1201 ret false 1202 end 1203 while lt p f bound `9223372036854775807` 1204 c = ulong get g_m p 1205 if or lt c 48 gt c 57 1206 ret false 1207 end 1208 x = add mul x 10 sub c 48 1209 p = add p 1 1210 end 1211 if or eq x 0 gt x 255 1212 ret false 1213 end 1214 k = add f 1 1215 if or eq k e ge sub e k len g_pa 1216 ret false 1217 end 1218 put g_n 33 1 1219 put g_n 34 x 1220 put g_n 35 k 1221 put g_n 36 e 1222 ret true 1223 end 1224 note the KTABLE of the current mutant row into g_pa 1225 fn pktab to void 1226 pclr 1227 s = get g_n 35 1228 for j ulong sub get g_n 36 s bound 4096 1229 pc ulong get g_m add s j 1230 end 1231 end 1232 note run SCRATCH/NAME then suffix on KTABLE (also its stdin); the exit as spawn gives it 1233 fn runk suf view uchar * to ulong 1234 aclr 1235 psn suf 1236 apa 1237 pktab 1238 apa 1239 fi = frd 1240 psn t_out 1241 fo = fwr 1242 psn t_rerr 1243 fe = fwr 1244 ret spawn fi fo fe 1245 end 1246 note FAIL control NAME-source-mutant-line-L WHY exit=X; counts a failure 1247 fn mfailx why view uchar * x ulong to void 1248 ot t_fail 1249 ot t_ctl 1250 onm 1251 ot t_msrc 1252 onum get g_n 30 1253 oc 32 1254 ot why 1255 ot t_exit 1256 onum x 1257 onl 1258 put g_n 11 add get g_n 11 1 1259 end 1260 note compose the mutant, compile it to SCRATCH/NAME.m, run it on TABLE: exit 1 is caught; a six-field row first 1261 note runs the check on KTABLE (it must exit EXIT), then the mutant on KTABLE (it must exit 0) 1262 fn mrun to void 1263 kn = eq get g_n 33 1 1264 if kn 1265 k = runk t_b1 1266 if ne k get g_n 34 1267 mfailx t_kmoved k 1268 ret 1269 end 1270 end 1271 put g_n 20 1 1272 put g_n 21 0 1273 ok = compose get g_n 22 get g_n 23 1274 put g_n 20 0 1275 if not ok 1276 ret 1277 end 1278 if eq get g_n 21 0 1279 mfail t_mnot 1280 ret 1281 end 1282 if eq get g_n 21 3 1283 mfail t_muniq 1284 ret 1285 end 1286 if ne get g_n 21 1 1287 mfail t_big 1288 ret 1289 end 1290 psn t_om 1291 if not bsave false 1292 mfail t_write 1293 ret 1294 end 1295 r = omc t_mo t_me 1296 if ne r 0 1297 mfail t_mcmp 1298 ret 1299 end 1300 x = ulong 0 1301 want = ulong 1 1302 if kn 1303 want = 0 1304 x = runk t_mo 1305 else 1306 aclr 1307 psn t_mo 1308 apa 1309 ptab 1310 apa 1311 fi = frd 1312 psn t_out 1313 fo = fwr 1314 psn t_rerr 1315 fe = fwr 1316 x = spawn fi fo fe 1317 end 1318 if eq x want 1319 ot t_ok 1320 else 1321 ot t_fail 1322 end 1323 ot t_ctl 1324 onm 1325 ot t_msrc 1326 onum get g_n 30 1327 if eq x want 1328 if kn 1329 ot t_kheld 1330 else 1331 ot t_caught 1332 end 1333 put g_n 13 add get g_n 13 1 1334 else 1335 if kn 1336 ot t_kfix 1337 else 1338 ot t_esc 1339 end 1340 ot t_exit 1341 onum x 1342 put g_n 11 add get g_n 11 1 1343 end 1344 onl 1345 end 1346 note a unit name uses only A-Z a-z 0-9 _ (the alphabet om/units.sh gives its names), so it names a file in SCRATCH 1347 fn nameok to bool 1348 for q ulong get g_n 14 bound 256 1349 c = get g_nm q 1350 d = and ge c 48 le c 57 1351 u = and ge c 65 le c 90 1352 l = and ge c 97 le c 122 1353 ok = or or d u or l eq c 95 1354 if not ok 1355 ret false 1356 end 1357 end 1358 ret true 1359 end 1360 note record the name in g_seen (names joined by newlines, g_seen grown to fit); false when it is already there or the host refuses the memory 1361 fn nameadd to bool 1362 n = get g_n 15 1363 m = get g_n 14 1364 p = ulong 0 1365 while lt p n bound `9223372036854775807` 1366 q = p 1367 while and lt q n ne get g_seen q 10 bound `9223372036854775807` 1368 q = add q 1 1369 end 1370 if nameat p q 1371 ret false 1372 end 1373 p = add q 1 1374 end 1375 r = enlarge g_seen add add n m 1 1376 if lt r 0 1377 ret false 1378 end 1379 for j ulong m bound 256 1380 put g_seen add n j get g_nm j 1381 end 1382 put g_seen add n m 10 1383 put g_n 15 add add n m 1 1384 ret true 1385 end 1386 note g_seen[p, q) equals the current name 1387 fn nameat p ulong q ulong to bool 1388 if ne sub q p get g_n 14 1389 ret false 1390 end 1391 for j ulong sub q p bound 256 1392 if ne get g_seen add p j get g_nm j 1393 ret false 1394 end 1395 end 1396 ret true 1397 end 1398 fn table to bool 1399 pclr 1400 pt t_tab 1401 put g_n 6 0 1402 if not bload 1403 ret false 1404 end 1405 n = get g_n 6 1406 r = enlarge g_u add n 1 1407 if lt r 0 1408 ret false 1409 end 1410 for q ulong n bound `9223372036854775807` 1411 put g_u q get g_b q 1412 end 1413 put g_n 7 n 1414 s = ulong 0 1415 while lt s n bound `9223372036854775807` 1416 e = s 1417 while uisnt e n 10 bound `9223372036854775807` 1418 e = add e 1 1419 end 1420 urow s e 1421 s = add e 1 1422 end 1423 if eq get g_n 16 0 1424 nmset t_tab 1425 ofail t_unit t_empty 1426 end 1427 ret true 1428 end 1429 note ---- controls 1430 fn caught c bool what view uchar * to void 1431 put g_n 12 add get g_n 12 1 1432 nmset what 1433 if c 1434 ot t_ok 1435 ot t_ctl 1436 onm 1437 ot t_caught 1438 onl 1439 put g_n 13 add get g_n 13 1 1440 else 1441 ofail t_ctl t_esc 1442 end 1443 end 1444 note ---- INVENTORY.tsv against ports.tsv: ports.tsv in g_p[0, g_n 31), INVENTORY.tsv in g_b[0, g_n 6). 1445 note g_ic: 0..4 INVENTORY rows that are ported, retired, blocked, open, other; 5..9 the same for the INVENTORY rows 1446 note that ports.tsv rows name; 15 INVENTORY rows 1447 fn pnot i ulong e ulong c ulong to bool 1448 if ge i e 1449 ret false 1450 end 1451 ret ne ulong get g_p i c 1452 end 1453 note g_p[a, b) holds the same bytes as g_b[c, d) 1454 fn peqb a ulong b ulong c ulong d ulong to bool 1455 if ne sub b a sub d c 1456 ret false 1457 end 1458 for j ulong sub b a bound `9223372036854775807` 1459 if ne get g_p add a j get g_b add c j 1460 ret false 1461 end 1462 end 1463 ret true 1464 end 1465 note g_b[c, d) holds the bytes of t 1466 fn beqt c ulong d ulong t view uchar * to bool 1467 if ne sub d c len t 1468 ret false 1469 end 1470 for j ulong len t bound 4096 1471 if ne get g_b add c j get t j 1472 ret false 1473 end 1474 end 1475 ret true 1476 end 1477 note the end of the g_b field that starts at q: the next tab, or e 1478 fn bend q ulong e ulong to ulong 1479 p = q 1480 while bnot p e 9 bound `9223372036854775807` 1481 p = add p 1 1482 end 1483 ret p 1484 end 1485 note the start of field f (0-based) of the g_b line [s, e), or e when it has fewer fields 1486 fn bfld s ulong e ulong f ulong to ulong 1487 q = s 1488 for k ulong f bound 64 1489 q = bend q e 1490 if ge q e 1491 ret e 1492 end 1493 q = add q 1 1494 end 1495 ret q 1496 end 1497 note 0 ported, 1 retired, 2 blocked, 3 open, 4 anything else 1498 fn bstat c ulong d ulong to ulong 1499 if beqt c d t_sported 1500 ret 0 1501 end 1502 if beqt c d t_sretired 1503 ret 1 1504 end 1505 if beqt c d t_sblocked 1506 ret 2 1507 end 1508 if beqt c d t_sopen 1509 ret 3 1510 end 1511 ret 4 1512 end 1513 note the om_ref or same_stem cell g_b[c, d) is -, or names a gpu/ file of this tree ending in .om that opens 1514 note for reading (a path the host takes: shorter than Linux PATH_MAX) 1515 fn invcell c ulong d ulong to bool 1516 if eq sub d c 1 1517 if eq ulong get g_b c 45 1518 ret true 1519 end 1520 end 1521 if or lt sub d c add len t_gpu len t_om ge sub d c len g_pa 1522 ret false 1523 end 1524 if not beqt c add c len t_gpu t_gpu 1525 ret false 1526 end 1527 if not beqt sub d len t_om d t_om 1528 ret false 1529 end 1530 pclr 1531 for q ulong sub d c bound 4096 1532 pc ulong get g_b add c q 1533 end 1534 fd = frd 1535 if lt fd 0 1536 ret false 1537 end 1538 fclo fd 1539 ret true 1540 end 1541 note FAIL inventory, the reason, then the INVENTORY path g_b[s, e) 1542 fn invref s ulong e ulong to void 1543 ot t_fail 1544 ot t_invk 1545 ot t_invref 1546 for q ulong sub e s bound `9223372036854775807` 1547 oc ulong get g_b add s q 1548 end 1549 onl 1550 put g_n 11 add get g_n 11 1 1551 end 1552 fn invmsg why view uchar * to void 1553 ot t_fail 1554 ot t_invk 1555 ot why 1556 onl 1557 put g_n 11 add get g_n 11 1 1558 end 1559 fn invfail line ulong why view uchar * to void 1560 ot t_fail 1561 ot t_invk 1562 ot t_ports 1563 ot t_line 1564 onum line 1565 ot t_colon 1566 ot why 1567 onl 1568 put g_n 11 add get g_n 11 1 1569 end 1570 note count the statuses of the INVENTORY rows (not empty, not #, not the header line) 1571 fn invrows to void 1572 n = get g_n 6 1573 s = ulong 0 1574 while lt s n bound `9223372036854775807` 1575 e = s 1576 while bnot e n 10 bound `9223372036854775807` 1577 e = add e 1 1578 end 1579 if lt s e 1580 if ne ulong get g_b s 35 1581 if not beqt s bend s e t_hpath 1582 c = bfld s e 8 1583 k = bstat c bend c e 1584 put g_ic k add get g_ic k 1 1585 for f ulong 2 1586 o = bfld s e add 6 f 1587 if not invcell o bend o e 1588 invref s bend s e 1589 end 1590 end 1591 put g_ic 15 add get g_ic 15 1 1592 end 1593 end 1594 end 1595 s = add e 1 1596 end 1597 end 1598 note the start of the INVENTORY line whose first field equals g_p[a, b); g_n 6 when there is none 1599 fn invfind a ulong b ulong to ulong 1600 n = get g_n 6 1601 s = ulong 0 1602 while lt s n bound `9223372036854775807` 1603 e = s 1604 while bnot e n 10 bound `9223372036854775807` 1605 e = add e 1 1606 end 1607 if peqb a b s bend s e 1608 ret s 1609 end 1610 s = add e 1 1611 end 1612 ret n 1613 end 1614 note one ports.tsv row g_p[s, e): STATUSDETAIL must equal fields 9 and 10 of the INVENTORY row of PATH 1615 fn invport s ulong e ulong line ulong to void 1616 t1 = s 1617 while pnot t1 e 9 bound `9223372036854775807` 1618 t1 = add t1 1 1619 end 1620 if ge t1 e 1621 invfail line t_invrow 1622 ret 1623 end 1624 n = get g_n 6 1625 m = invfind s t1 1626 if ge m n 1627 invfail line t_invmiss 1628 ret 1629 end 1630 me = m 1631 while bnot me n 10 bound `9223372036854775807` 1632 me = add me 1 1633 end 1634 c = bfld m me 8 1635 x = bend bfld m me 9 me 1636 if not peqb add t1 1 e c x 1637 invfail line t_invdiff 1638 ret 1639 end 1640 k = add bstat c bend c me 5 1641 put g_ic k add get g_ic k 1 1642 end 1643 fn invports to void 1644 n = get g_n 31 1645 s = ulong 0 1646 line = ulong 1 1647 while lt s n bound `9223372036854775807` 1648 e = s 1649 while pnot e n 10 bound `9223372036854775807` 1650 e = add e 1 1651 end 1652 if lt s e 1653 if ne ulong get g_p s 35 1654 invport s e line 1655 end 1656 end 1657 s = add e 1 1658 line = add line 1 1659 end 1660 end 1661 note the footer g_b[s, e) holds t followed by the decimal want 1662 fn footnum s ulong e ulong t view uchar * want ulong to bool 1663 p = s 1664 while lt p e bound `9223372036854775807` 1665 q = add p len t 1666 if le q e 1667 if beqt p q t 1668 v = ulong 0 1669 dg = ulong 0 1670 while lt q e bound `9223372036854775807` 1671 c = ulong get g_b q 1672 if or lt c 48 gt c 57 1673 break 1674 end 1675 if ge dg 19 1676 ret false 1677 end 1678 v = add mul v 10 sub c 48 1679 q = add q 1 1680 dg = add dg 1 1681 end 1682 ret and gt dg 0 eq v want 1683 end 1684 end 1685 p = add p 1 1686 end 1687 ret false 1688 end 1689 fn invfoot to void 1690 ok = true 1691 for k ulong 3 1692 if ne get g_ic k get g_ic add k 5 1693 ok = false 1694 end 1695 end 1696 if or or ne get g_ic 4 0 ne get g_ic 8 0 ne get g_ic 9 0 1697 ok = false 1698 end 1699 if not ok 1700 invmsg t_invcnt 1701 end 1702 n = get g_n 6 1703 e = n 1704 if gt e 0 1705 if eq get g_b sub e 1 10 1706 e = sub e 1 1707 end 1708 end 1709 s = e 1710 while gt s 0 bound `9223372036854775807` 1711 if eq get g_b sub s 1 10 1712 break 1713 end 1714 s = sub s 1 1715 end 1716 f = footnum s e t_ffiles get g_ic 15 1717 f = and f footnum s e t_fported get g_ic 0 1718 f = and f footnum s e t_fretired get g_ic 1 1719 f = and f footnum s e t_fblocked get g_ic 2 1720 f = and f footnum s e t_fopen get g_ic 3 1721 if not f 1722 invmsg t_invfoot 1723 end 1724 end 1725 note INVENTORY.tsv must say what ports.tsv says: every ports.tsv row is the status and detail of its path, the 1726 note other rows are open, and the footer counts are its rows 1727 fn invchk to void 1728 pclr 1729 pt t_ports 1730 put g_n 6 0 1731 if not bload 1732 invmsg t_invnop 1733 ret 1734 end 1735 n = get g_n 6 1736 r = enlarge g_p add n 1 1737 if lt r 0 1738 invmsg t_big 1739 ret 1740 end 1741 for q ulong n bound `9223372036854775807` 1742 put g_p q get g_b q 1743 end 1744 put g_n 31 n 1745 pclr 1746 pt t_invf 1747 put g_n 6 0 1748 if not bload 1749 invmsg t_invnoi 1750 ret 1751 end 1752 for k ulong 16 1753 put g_ic k 0 1754 end 1755 f = get g_n 11 1756 invrows 1757 invports 1758 invfoot 1759 if eq get g_n 11 f 1760 ot t_invok 1761 onl 1762 end 1763 end 1764 note a compiler one byte longer must fail the digest check 1765 fn cwrong to void 1766 pclr 1767 for j ulong get g_n 1 bound 4096 1768 pc ulong get g_omc j 1769 end 1770 put g_n 6 0 1771 ok = bload 1772 n = get g_n 6 1773 put g_b n 0 1774 put g_n 6 add n 1 1775 psc t_plus 1776 ok = and ok bsave true 1777 psc t_plus 1778 c = and ok not pinok 1779 caught c t_plus 1780 end 1781 note ---- main 1782 fn ausage to int 1783 r = write 2 t_usage 0 len t_usage 1784 ret 2 1785 end 1786 fn main to int 1787 if ne argcnt 3 1788 ret ausage 1789 end 1790 r = argread 1 g_omc 0 4095 1791 if lt r 1 1792 ret ausage 1793 end 1794 put g_n 1 ulong r 1795 if not pinread 1796 r = write 2 t_nopin 0 len t_nopin 1797 ret 2 1798 end 1799 pclr 1800 for j ulong get g_n 1 bound 4096 1801 pc ulong get g_omc j 1802 end 1803 if not pinok 1804 r = write 2 t_refd 0 len t_refd 1805 ret 69 1806 end 1807 r = argread 2 g_scr 0 4094 1808 if lt r 1 1809 ret ausage 1810 end 1811 if gt add add ulong r 1 namemax sub len g_pa 1 1812 r = write 2 t_long 0 len t_long 1813 ret 2 1814 end 1815 n = ulong r 1816 x = makedir g_scr 0 n 448 1817 if ne x 0 1818 r = write 2 t_noscr 0 len t_noscr 1819 ret 2 1820 end 1821 put g_scr n 47 1822 put g_n 2 add n 1 1823 if not mload 1824 r = write 2 t_nomut 0 len t_nomut 1825 ret 2 1826 end 1827 if not table 1828 r = write 2 t_notab 0 len t_notab 1829 ret 2 1830 end 1831 invchk 1832 cwrong 1833 f = get g_n 11 1834 ot t_sum 1835 if eq f 0 1836 ot t_pass 1837 else 1838 ot t_fl 1839 end 1840 ot t_su 1841 onum get g_n 8 1842 ot t_sc 1843 onum get g_n 12 1844 ot t_sk 1845 onum get g_n 13 1846 ot t_hw 1847 oflush 1848 if ne f 0 1849 ret 1 1850 end 1851 if ne get g_n 12 get g_n 13 1852 ret 1 1853 end 1854 ret 0 1855 end