code wiki / _hdl_build / nx_engineer_build_gate_test.nx
nx_engineer_build_gate_test.nx source
↩ module page · 47 lines · 2591 B
1// nx_engineer_build_gate_test.nx -- prove the ENGINEER's managed build gate: it runs the
2// four-pillar pipeline (compile -> scan -> heal -> link -> run) and classifies honestly,
3// healing the miscompile when the probe finds it. The gate is the standing owner of this
4// discipline going forward. Known answer: clean PASS, badsrc COMPILE-FAIL, a real test PASS.
5
6import "nx_engineer_build_gate.nx"
7
8func eb_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
9func eb_num(v: i64) -> i64 {
10 let bb: *u8 = sys_mmap(28); var m: i64 = v; if m < 0 { m = 0 - m }
11 let t: *u8 = sys_mmap(28); var k: i64 = 0
12 if m == 0 { t[0] = 48; k = 1 }
13 while m > 0 { t[k] = 48 + (m % 10); m = m / 10; k = k + 1 }
14 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 }
15 sys_write(1, bb, k); return 0
16}
17func tally(r: *i64, n: i64) -> i64 { var ec: i64 = 0; var i: i64 = 0; while i < n { if r[i] != 1 { if ec == 0 { ec = i + 1 } } i = i + 1 } return ec }
18
19func ebg_one(src: *u8, label: *u8, expect: i64, r: *i64, slot: i64) -> i64 {
20 let kg: *u8 = "_offc/nx_cc_known_good.elf" as *u8
21 let out: *i64 = sys_mmap(8 * 4) as *i64
22 let v: i64 = eng_build_gate(kg, src, "/tmp/ebg.s" as *u8, "/tmp/ebg_heal.s" as *u8, "/tmp/ebg.elf" as *u8, 0 as *u8, out)
23 eb_puts(" gate " as *u8); eb_puts(label); eb_puts(" -> " as *u8); eb_puts(ebg_verdict_name(v))
24 if out[0] > 0 { eb_puts(" (Doctor healed " as *u8); eb_num(out[0]); eb_puts(" reg(s) across a call)" as *u8) }
25 eb_puts("\n" as *u8)
26 r[slot] = 0; if v == expect { r[slot] = 1 }
27 return 0
28}
29
30func run_all(r: *i64) -> i64 {
31 ebg_one("runtime/_hdl_build/nx_eng_clean.nx" as *u8, "clean " as *u8, EBG_PASS, r, 0)
32 ebg_one("runtime/_hdl_build/nx_eng_badsrc.nx" as *u8, "badsrc " as *u8, EBG_COMPILE_FAIL, r, 1)
33 ebg_one("runtime/_hdl_build/nx_u128_test.nx" as *u8, "u128test" as *u8, EBG_PASS, r, 2)
34 return 3
35}
36
37func main() -> i64 {
38 eb_puts("=== ENGINEER managed build gate: compile->scan->heal->link->run, four pillars in one step ===\n" as *u8)
39 let r: *i64 = sys_mmap(8 * 8) as *i64
40 let nk: i64 = run_all(r)
41 eb_puts("----------------------------------------------------------------\n" as *u8)
42 eb_puts(" the Engineer now owns the four-pillar miscompile discipline: every build is compiled, probed for\n" as *u8)
43 eb_puts(" the live-across-call clobber, healed if found, then linked + run + classified -- one step, no hand-patching.\n" as *u8)
44 let ec: i64 = tally(r, nk)
45 sys_exit(ec)
46 return ec
47}