nx_bench_census_gate.nx source
↩ module page · 46 lines · 2535 B
1// nx_bench_census_gate.nx -- gates the benchmark-coverage census on in-memory fixtures (no file I/O):
2// 5 live tools; registry grades A=PARITY B=EXCEED C=GAP D=UNMEASURED, E absent. Asserts the census
3// counts + coverage permille exactly (GAP counts as graded; UNMEASURED-row and no-row both = debt).
4// Exit 0 only on all-PASS. license_tier: ORIGINAL expect_exit: 0
5import "nx_bench_census_lib.nx"
6
7const GATE_CHECKS: i64 = 6
8const FIX_LIVE: i64 = 5 // tools in the allowlist fixture
9const FIX_GRADED: i64 = 3 // A(PARITY) B(EXCEED) C(GAP)
10const FIX_EXCEED: i64 = 1 // B
11const FIX_GAP: i64 = 1 // C
12const FIX_UNMEAS: i64 = 2 // D(UNMEASURED row) + E(no row)
13const FIX_COV: i64 = 600 // 3/5 * 1000
14const V_COUNTS_BYTES: i64 = 64 // counts array = 8 i64 slots
15
16func bg_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
17func bg_check(name: *u8, ok: i64, pass: *i64) -> i64 {
18 bc_puts("T " as *u8); bc_puts(name); bc_puts(" -> " as *u8)
19 if ok == 1 { bc_puts("PASS\n" as *u8); pass[0] = pass[0] + 1 } else { bc_puts("FAIL\n" as *u8) }
20 return 0
21}
22
23func main(argc: i64, argv: *i64) -> i64 {
24 let pass: *i64 = sys_mmap(16) as *i64
25 pass[0] = 0
26 // allowlist fixture: name-only lines (field0 handles the no-TAB case); a '#' header is skipped
27 let allow: *u8 = "# name\tpath\tstatus\ntoolA\ntoolB\ntoolC\ntoolD\ntoolE\n" as *u8
28 // registry fixture: name<TAB>oracle<TAB>verdict
29 let reg: *u8 = "# tool\toracle\tverdict\ntoolA\tcat\tPARITY\ntoolB\tClaudeRead\tEXCEED\ntoolC\tgrep-E\tGAP\ntoolD\t-\tUNMEASURED\n" as *u8
30
31 let counts: *i64 = sys_mmap(V_COUNTS_BYTES) as *i64
32 let unc: i64 = bc_census(allow, bg_slen(allow), reg, bg_slen(reg), counts)
33
34 bg_check("live-total" as *u8, (counts[BC_C_LIVE] == FIX_LIVE) as i64, pass)
35 bg_check("graded-count" as *u8, (counts[BC_C_GRADED] == FIX_GRADED) as i64, pass)
36 bg_check("exceed-count" as *u8, (counts[BC_C_EXCEED] == FIX_EXCEED) as i64, pass)
37 bg_check("gap-counts-as-graded" as *u8, (counts[BC_C_GAP] == FIX_GAP) as i64, pass)
38 bg_check("unmeasured-both-debt-kinds" as *u8, (unc == FIX_UNMEAS) as i64, pass)
39 let cov: i64 = bc_report(counts)
40 bg_check("coverage-permille" as *u8, (cov == FIX_COV) as i64, pass)
41
42 bc_puts("BENCH-CENSUS-GATE pass=" as *u8); bc_putn(pass[0]); bc_puts("/" as *u8); bc_putn(GATE_CHECKS); bc_puts(" verdict=" as *u8)
43 if pass[0] == GATE_CHECKS { bc_puts("GREEN\n" as *u8); return 0 }
44 bc_puts("RED\n" as *u8)
45 return 1
46}