code wiki / _hdl_build / _ad_selfmeasure_test.nx
_ad_selfmeasure_test.nx source
↩ module page · 58 lines · 2469 B
1// _ad_selfmeasure_test.nx -- GATE for DAEMON-SIL-R1 (daemon self-measurement).
2// Drives adc_beat against a 1-target test conf and asserts the AUTORUN-BEAT row
3// now carries the self-measurement fields (improvements_landed/driven/regressions/
4// beat_cost_s) -- the honest rank-D baseline made visible. Additive-only proof.
5// Imports ONLY nx_ad_core (it re-exports nx_syscalls; a SECOND direct nx_syscalls
6// import is the documented NXASM rc=6 landmine on this module). license_tier: ORIGINAL
7import "nx_ad_core.nx"
8
9func t_contains(hay: *u8, n: i64, needle: *u8) -> i64 {
10 var nl: i64 = 0
11 while needle[nl] != (0 as u8) { nl = nl + 1 }
12 if nl == 0 { return 1 }
13 var i: i64 = 0
14 while i + nl <= n {
15 var j: i64 = 0
16 var m: i64 = 1
17 while j < nl {
18 if hay[i + j] != needle[j] { m = 0; j = nl } else { j = j + 1 }
19 }
20 if m == 1 { return 1 }
21 i = i + 1
22 }
23 return 0
24}
25
26func t_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
27
28func main() -> i64 {
29 let conf: *u8 = "knowledge/status/_ad_test.conf" as *u8
30 let out: *u8 = "knowledge/status/_ad_test.out" as *u8
31 let log: *u8 = "knowledge/status/_ad_test.log" as *u8
32
33 // one beat through the real core (re-proves the cheap target once)
34 adc_beat(conf, out, log)
35
36 let buf: *u8 = sys_mmap(65536)
37 let fd: i64 = sys_openat_rd(log)
38 if fd < 0 { t_w("DAEMON-SIL-R1 GATE: RED reason=no-log\n" as *u8); sys_exit(1); return 1 }
39 var n: i64 = 0
40 var r: i64 = sys_read(fd, buf, 65535)
41 while r > 0 { n = n + r; r = sys_read(fd, buf + n, 65535 - n) }
42 sys_close(fd)
43
44 var ok: i64 = 1
45 if t_contains(buf, n, "AUTORUN-BEAT" as *u8) == 0 { ok = 0 }
46 if t_contains(buf, n, "improvements_landed=0" as *u8) == 0 { ok = 0 }
47 if t_contains(buf, n, "driven=0" as *u8) == 0 { ok = 0 }
48 if t_contains(buf, n, "regressions=" as *u8) == 0 { ok = 0 }
49 if t_contains(buf, n, "beat_cost_s=" as *u8) == 0 { ok = 0 }
50 // guardrail preserved: the historical fields must still be present (API-stable)
51 if t_contains(buf, n, "rung_rc=" as *u8) == 0 { ok = 0 }
52 if t_contains(buf, n, "targets=" as *u8) == 0 { ok = 0 }
53
54 if ok == 1 { t_w("DAEMON-SIL-R1 GATE: GREEN self-measure-fields-emitted + historical-fields-preserved\n" as *u8); sys_exit(0); return 0 }
55 t_w("DAEMON-SIL-R1 GATE: RED reason=missing-field\n" as *u8)
56 sys_exit(1)
57 return 1
58}