code wiki / _hdl_build / nx_emu_testbed_gate.nx
nx_emu_testbed_gate.nx source
↩ module page · 132 lines · 5686 B
1// nx_emu_testbed_gate.nx -- THE REFEREE for the emu testbed.
2//
3// Proves nx_emu_testbed correctly computes the live virtual-fit matrix AND can SEE every failure
4// mode (no-fabricated-green):
5//
6// POSITIVE (real laptop_profiles.tsv + the real host probe):
7// T1 healthy: probe succeeds, >=1 profile FITS virtually here, 0 never-brick (host-mode) violations.
8//
9// NEGATIVE CONTROLS (hermetic /tmp fixtures; the flag MUST fire):
10// N1 oversized : a profile needing ~100 TB RAM -> too_big >= 1
11// N2 host-mode : a profile with test_mode=host -> never-brick >= 1 (must run in the emu)
12// N3 uncovered : a profile on a non-emulatable arch -> uncovered >= 1
13//
14// GREEN only if T1 AND N1..N3. Evidence rows + verdict -> knowledge/status/emu_testbed_gate.log.
15// Sovereign: imports the testbed + nx_framed_append + nx_syscalls (no gcc). license_tier: ORIGINAL
16import "nx_emu_testbed.nx"
17import "nx_framed_append.nx"
18import "nx_syscalls.nx"
19
20const ET_LOG: *u8 = "knowledge/status/emu_testbed_gate.log"
21const ET_REAL: *u8 = "knowledge/registry/laptop_profiles.tsv"
22const ET_RECCAP: i64 = 512
23
24func et_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != 0 as u8 { n = n + 1 } sys_write(1, s, n); return 0 }
25func et_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != 0 as u8 { dst[off + i] = s[i]; i = i + 1 } return off + i }
26func et_catn(dst: *u8, off: i64, v: i64) -> i64 {
27 var m: i64 = v; var o: i64 = off
28 if m < 0 { m = 0 - m }
29 let t: *u8 = sys_mmap(28); var k: i64 = 0
30 if m == 0 { t[0] = 48 as u8; k = 1 }
31 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
32 var i: i64 = 0
33 while i < k { dst[o + i] = t[k - 1 - i]; i = i + 1 }
34 return o + k
35}
36
37func et_write_file(path: *u8, content: *u8) -> i64 {
38 let fd: i64 = sys_openat_wr(path, 0x1a4)
39 if fd < 0 { return 0 - 1 }
40 var n: i64 = 0; while content[n] != 0 as u8 { n = n + 1 }
41 sys_write(fd, content, n)
42 sys_close(fd)
43 return 0
44}
45
46func et_tmppath(out: *u8, stem: *u8, epoch: i64, pid: i64) -> i64 {
47 var o: i64 = 0
48 o = et_cat(out, o, stem)
49 o = et_catn(out, o, epoch)
50 o = et_cat(out, o, "." as *u8)
51 o = et_catn(out, o, pid)
52 o = et_cat(out, o, ".tsv" as *u8)
53 out[o] = 0 as u8
54 return o
55}
56
57func et_row(name: *u8, pass: i64) -> i64 {
58 let buf: *u8 = sys_mmap(ET_RECCAP + 16)
59 var o: i64 = 0
60 o = et_cat(buf, o, "EMUTB row=\x00" as *u8)
61 o = et_cat(buf, o, name)
62 if pass == 1 { o = et_cat(buf, o, " verdict=PASS\x00" as *u8) } else { o = et_cat(buf, o, " verdict=FAIL\x00" as *u8) }
63 buf[o] = 0 as u8
64 fa_appendz(ET_LOG, buf, ET_RECCAP)
65 et_puts(" \x00" as *u8)
66 et_puts(name)
67 if pass == 1 { et_puts(" PASS\n\x00" as *u8) } else { et_puts(" FAIL\n\x00" as *u8) }
68 return 0
69}
70
71func main() -> i64 {
72 let epoch: i64 = sys_now_realtime_sec()
73 let pid: i64 = __syscall(39, 0, 0, 0, 0, 0, 0)
74 let outs: *i64 = sys_mmap(256) as *i64
75
76 // ---- T1: real matrix + real host probe is healthy ----
77 var t1: i64 = 0
78 if tb_analyze(ET_REAL, outs) == 0 { if outs[0] >= 1 { if outs[4] >= 1 { if outs[7] == 0 { t1 = 1 } } } }
79
80 let p1: *u8 = sys_mmap(256); et_tmppath(p1, "/tmp/et_oversized." as *u8, epoch, pid)
81 let p2: *u8 = sys_mmap(256); et_tmppath(p2, "/tmp/et_hostmode." as *u8, epoch, pid)
82 let p3: *u8 = sys_mmap(256); et_tmppath(p3, "/tmp/et_uncovered." as *u8, epoch, pid)
83 // 10-col rows; field 1=arch, 2=ram_mb, 3=vcpu, 7=test_mode.
84 et_write_file(p1, "big\tx86_64\t99999999\t2\t16\tuefi\tigpu\temu\ttest\t~100TB RAM oversized\n" as *u8)
85 et_write_file(p2, "hostmode\tx86_64\t2048\t2\t16\tuefi\tigpu\thost\ttest\tbrickable on HOST forbidden\n" as *u8)
86 et_write_file(p3, "weird\tsparc64\t2048\t2\t16\tuefi\tigpu\temu\ttest\tnon-emulatable arch\n" as *u8)
87
88 // ---- N1 oversized -> too_big >= 1 ----
89 var n1: i64 = 0
90 if tb_analyze(p1, outs) == 0 { if outs[5] >= 1 { n1 = 1 } }
91 // ---- N2 host-mode -> never-brick violation >= 1 ----
92 var n2: i64 = 0
93 if tb_analyze(p2, outs) == 0 { if outs[7] >= 1 { n2 = 1 } }
94 // ---- N3 uncovered arch -> uncovered >= 1 ----
95 var n3: i64 = 0
96 if tb_analyze(p3, outs) == 0 { if outs[6] >= 1 { n3 = 1 } }
97
98 var passes: i64 = 0
99 if t1 == 1 { passes = passes + 1 }
100 if n1 == 1 { passes = passes + 1 }
101 if n2 == 1 { passes = passes + 1 }
102 if n3 == 1 { passes = passes + 1 }
103 var green: i64 = 0
104 if passes == 4 { green = 1 }
105
106 et_puts("emu-testbed gate (live host probe + 3 neg-controls)\n\x00" as *u8)
107 et_row("T1-real-matrix-fits-here\x00" as *u8, t1)
108 et_row("N1-oversized-seen \x00" as *u8, n1)
109 et_row("N2-host-mode-never-brick\x00" as *u8, n2)
110 et_row("N3-uncovered-arch-seen \x00" as *u8, n3)
111
112 let vb: *u8 = sys_mmap(ET_RECCAP + 16)
113 var o: i64 = 0
114 o = et_cat(vb, o, "EMU-TESTBED verdict=\x00" as *u8)
115 if green == 1 { o = et_cat(vb, o, "GREEN\x00" as *u8) } else { o = et_cat(vb, o, "RED\x00" as *u8) }
116 o = et_cat(vb, o, " passes=\x00" as *u8); o = et_catn(vb, o, passes); o = et_cat(vb, o, "/4\x00" as *u8)
117 if green == 0 {
118 o = et_cat(vb, o, " reason=\x00" as *u8)
119 if t1 == 0 { o = et_cat(vb, o, "real-matrix-unhealthy \x00" as *u8) }
120 if n1 == 0 { o = et_cat(vb, o, "oversized-blind \x00" as *u8) }
121 if n2 == 0 { o = et_cat(vb, o, "host-mode-blind \x00" as *u8) }
122 if n3 == 0 { o = et_cat(vb, o, "uncovered-blind \x00" as *u8) }
123 }
124 o = et_cat(vb, o, " END\x00" as *u8)
125 vb[o] = 0 as u8
126 fa_appendz(ET_LOG, vb, ET_RECCAP)
127 sys_write(1, vb, o)
128 sys_write(1, "\n\x00" as *u8, 1)
129
130 if green == 1 { return 0 }
131 return 1
132}