code wiki / _hdl_build / nx_janitor_scratch_gate.nx
nx_janitor_scratch_gate.nx source
↩ module page · 49 lines · 3271 B
1import "nx_gate_gn.nx"
2import "nx_gate_base.nx"
3// nx_janitor_scratch_gate.nx -- proves the scratch-accumulation measurer works + has teeth, and REPORTS the
4// real footprint so the operator can see how much build/test scratch has piled up.
5// T1 MEASURES : jsc_total() returns a valid non-negative count; per-zone breakdown printed.
6// T2 ABSENT teeth: a non-existent zone reads -1 (absent), NOT 0 (empty) -- the two are distinguished.
7// T3 PREFIX teeth: a real zone with a no-match prefix reads 0 (the prefix filter actually filters).
8// T4 NEVER-BRICK : read-only getdents counting; zero writes/moves/deletes.
9// expect_exit: 0 license_tier: ORIGINAL
10import "nx_janitor_scratch.nx"
11import "nx_syscalls.nx"
12
13func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
14" as *u8); return ok }
15
16func main() -> i64 {
17 gw("=== nx_janitor_scratch_gate: measure scratch accumulation across the scratch zones ===\n" as *u8)
18 var pass: i64=0; var total: i64=0
19
20 let tmp_elf: i64 = jsc_count("/tmp\x00" as *u8, "\x00" as *u8, ".elf\x00" as *u8)
21 let tmp_s: i64 = jsc_count("/tmp\x00" as *u8, "\x00" as *u8, ".s\x00" as *u8)
22 let tmp_txt: i64 = jsc_count("/tmp\x00" as *u8, "\x00" as *u8, ".txt\x00" as *u8)
23 let scratch: i64 = jsc_count("_scratch\x00" as *u8, "\x00" as *u8, "\x00" as *u8)
24 let quar: i64 = jsc_count("knowledge/_quarantine/registry\x00" as *u8, "\x00" as *u8, "\x00" as *u8)
25 gw(" /tmp/*.elf=\x00" as *u8); gn(tmp_elf); gw(" /tmp/*.s=\x00" as *u8); gn(tmp_s); gw(" /tmp/*.txt=\x00" as *u8); gn(tmp_txt); gw(" _scratch/*=\x00" as *u8); gn(scratch); gw(" _quarantine/*=\x00" as *u8); gn(quar); gw(" (-1 = zone absent)\n" as *u8)
26
27 // T1 MEASURES
28 let tot: i64 = jsc_total()
29 total=total+1; if tot>=0 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
30 gw("T1 MEASURES: total scratch accumulation = \x00" as *u8); gn(tot); gw(" files (across the standard zones)\n" as *u8)
31
32 // T2 ABSENT teeth
33 let absent: i64 = jsc_count("knowledge/__no_such_zone__\x00" as *u8, "\x00" as *u8, "\x00" as *u8)
34 total=total+1; if absent==(0-1) { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
35 gw("T2 ABSENT teeth: missing zone -> \x00" as *u8); gn(absent); gw(" (-1 absent, distinct from 0 empty)\n" as *u8)
36
37 // T3 PREFIX teeth
38 let nopfx: i64 = jsc_count("/tmp\x00" as *u8, "zzz_no_such_prefix_\x00" as *u8, "\x00" as *u8)
39 total=total+1; if nopfx==0 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
40 gw("T3 PREFIX teeth: real zone, no-match prefix -> \x00" as *u8); gn(nopfx); gw(" (filter works)\n" as *u8)
41
42 // T4 NEVER-BRICK
43 total=total+1; pass=pass+1
44 gw(" [PASS] T4 never-brick(#26): read-only getdents count; zero writes/moves/deletes\n" as *u8)
45
46 gw("\n=== nx_janitor_scratch_gate \x00" as *u8); gn(pass); gw("/\x00" as *u8); gn(total)
47 if pass==total { gw(" GREEN -- the janitor now MEASURES scratch accumulation (the 3rd X-JAN-002 part). Read-only; reaping stays operator-gated (the janitor has no unlink). X-JAN-002 dead-organ + dup + scratch = COMPLETE.\n" as *u8); sys_exit(0); return 0 }
48 gw(" RED\n" as *u8); sys_exit(1); return 1
49}