code wiki / _hdl_build / nx_seat_hub_gate.nx
nx_seat_hub_gate.nx source
↩ module page · 135 lines · 6402 B
1// nx_seat_hub_gate.nx -- GATE for the S2b hub-frame wrapper (5 teeth, 3 negative controls).
2// PREREQ: stage first: _offc/nx_seat_hub.elf + _offc/nx_fix_echo.elf. Run from nxc2 root.
3// The wrapper is judged OFFLINE against controlled bodies (nx_fix_echo stands in for
4// nx_mcp_call; hubconf mcpelf= points at it, capfile= is a dummy) -- the LIVE hub tooth is a
5// separate one-shot run (network gates flake; live proof is banked, not gated).
6// SELF-EXEC CHAIN (one wrapper fork per process): argv = [self] [stage] [pass].
7// Teeth: T1 checkin HELD accepted | T2 NEG checkin CONTENDED refused | T3 NEG garbage/empty
8// body refused | T4 checkout done=1 accepted | T5 NEG checkout marker-absent refused.
9// Verdict: NX-SEAT-HUB-GATE pass=N/5 verdict=GREEN|RED (exit 0 iff 5/5).
10// license_tier: ORIGINAL No hw writes (Rule 26).
11import "nx_seat_drive_lib.nx"
12import "nx_seg_store.nx"
13import "nx_deploy_lib.nx"
14import "nx_syscalls.nx"
15
16func hg_atoi(s: *u8) -> i64 {
17 var v: i64 = 0
18 var i: i64 = 0
19 while s[i] != (0 as u8) {
20 let c: i64 = s[i] as i64
21 if c >= 48 { if c <= 57 { v = v * 10 + (c - 48) } }
22 i = i + 1
23 }
24 return v
25}
26
27func hg_itoa(dst: *u8, v: i64) -> i64 {
28 var m: i64 = v
29 let t: *u8 = sys_mmap(24)
30 var k: i64 = 0
31 if m == 0 { t[0] = 48 as u8; k = 1 }
32 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
33 var i: i64 = 0
34 while i < k { dst[i] = t[k - 1 - i]; i = i + 1 }
35 dst[k] = 0 as u8
36 return k
37}
38
39func hg_len(s: *u8) -> i64 {
40 var n: i64 = 0
41 while s[n] != (0 as u8) { n = n + 1 }
42 return n
43}
44
45// run the wrapper on a hubconf; returns wrapper exit code
46func hg_run(confp: *u8, outp: *u8) -> i64 {
47 let av: *i64 = sys_mmap(64) as *i64
48 av[0] = confp as i64
49 av[1] = "hg-ws" as *u8 as i64
50 av[2] = "hg-actor" as *u8 as i64
51 return dep_run_capture("_offc/nx_seat_hub.elf" as *u8, av, 3, outp)
52}
53
54func main(argc: i64, argv: *i64) -> i64 {
55 var stage: i64 = 1
56 var pass: i64 = 0
57 if argc >= 2 { let ss: *u8 = argv[1] as *u8; stage = hg_atoi(ss) }
58 if argc >= 3 { let ps: *u8 = argv[2] as *u8; pass = hg_atoi(ps) }
59 if stage < 1 { stage = 1 }
60
61 if stage == 1 {
62 let body: *u8 = "HTTP status=200\n--- body ---\nCHECKIN ws=hg-ws claim=HELD kickoff=1 note=x\n" as *u8
63 ss_writefile("/tmp/shg_body1.txt" as *u8, body, hg_len(body))
64 let conf: *u8 = "mcpelf=_offc/nx_fix_echo.elf\nurl=/tmp/shg_body1.txt\ncapfile=/tmp/shg_dummy.cap\nverb=checkin\nttl=120\nnote=t1\noutfile=/tmp/shg_t1.out\n" as *u8
65 ss_writefile("/tmp/shg_t1.conf" as *u8, conf, hg_len(conf))
66 let rc: i64 = hg_run("/tmp/shg_t1.conf" as *u8, "/tmp/shg_t1.cap.out" as *u8)
67 if rc == 0 { sd_w("T1 checkin-held PASS\n" as *u8); pass = pass + 1 } else { sd_w("T1 checkin-held FAIL\n" as *u8) }
68 }
69 if stage == 2 {
70 let body: *u8 = "HTTP status=200\n--- body ---\nCHECKIN ws=hg-ws claim=CONTENDED holder=other-seat\n" as *u8
71 ss_writefile("/tmp/shg_body2.txt" as *u8, body, hg_len(body))
72 let conf: *u8 = "mcpelf=_offc/nx_fix_echo.elf\nurl=/tmp/shg_body2.txt\ncapfile=/tmp/shg_dummy.cap\nverb=checkin\nttl=120\nnote=t2\noutfile=/tmp/shg_t2.out\n" as *u8
73 ss_writefile("/tmp/shg_t2.conf" as *u8, conf, hg_len(conf))
74 let rc: i64 = hg_run("/tmp/shg_t2.conf" as *u8, "/tmp/shg_t2.cap.out" as *u8)
75 if rc == 3 { sd_w("T2 neg-contended PASS\n" as *u8); pass = pass + 1 } else { sd_w("T2 neg-contended FAIL\n" as *u8) }
76 }
77 if stage == 3 {
78 // transport-flake body: HTML error page, no marker anywhere
79 let body: *u8 = "<html><body>502 relay lost the response</body></html>\n" as *u8
80 ss_writefile("/tmp/shg_body3.txt" as *u8, body, hg_len(body))
81 let conf: *u8 = "mcpelf=_offc/nx_fix_echo.elf\nurl=/tmp/shg_body3.txt\ncapfile=/tmp/shg_dummy.cap\nverb=checkin\nttl=120\nnote=t3\noutfile=/tmp/shg_t3.out\n" as *u8
82 ss_writefile("/tmp/shg_t3.conf" as *u8, conf, hg_len(conf))
83 let rc: i64 = hg_run("/tmp/shg_t3.conf" as *u8, "/tmp/shg_t3.cap.out" as *u8)
84 if rc == 3 { sd_w("T3 neg-flake-body PASS\n" as *u8); pass = pass + 1 } else { sd_w("T3 neg-flake-body FAIL\n" as *u8) }
85 }
86 if stage == 4 {
87 let body: *u8 = "HTTP status=200\n--- body ---\nCHECKOUT ws=hg-ws done=1 release-rc=0 NX-CLAIMS RELEASED\n" as *u8
88 ss_writefile("/tmp/shg_body4.txt" as *u8, body, hg_len(body))
89 let conf: *u8 = "mcpelf=_offc/nx_fix_echo.elf\nurl=/tmp/shg_body4.txt\ncapfile=/tmp/shg_dummy.cap\nverb=checkout\nnote=t4\noutfile=/tmp/shg_t4.out\n" as *u8
90 ss_writefile("/tmp/shg_t4.conf" as *u8, conf, hg_len(conf))
91 let rc: i64 = hg_run("/tmp/shg_t4.conf" as *u8, "/tmp/shg_t4.cap.out" as *u8)
92 if rc == 0 { sd_w("T4 checkout-done PASS\n" as *u8); pass = pass + 1 } else { sd_w("T4 checkout-done FAIL\n" as *u8) }
93 }
94 if stage == 5 {
95 // checkout body WITHOUT done=1 (e.g. release refused) must be refused
96 let body: *u8 = "HTTP status=200\n--- body ---\nCHECKOUT ws=hg-ws done=0 release-rc=4\n" as *u8
97 ss_writefile("/tmp/shg_body5.txt" as *u8, body, hg_len(body))
98 let conf: *u8 = "mcpelf=_offc/nx_fix_echo.elf\nurl=/tmp/shg_body5.txt\ncapfile=/tmp/shg_dummy.cap\nverb=checkout\nnote=t5\noutfile=/tmp/shg_t5.out\n" as *u8
99 ss_writefile("/tmp/shg_t5.conf" as *u8, conf, hg_len(conf))
100 let rc: i64 = hg_run("/tmp/shg_t5.conf" as *u8, "/tmp/shg_t5.cap.out" as *u8)
101 if rc == 3 { sd_w("T5 neg-checkout-undone PASS\n" as *u8); pass = pass + 1 } else { sd_w("T5 neg-checkout-undone FAIL\n" as *u8) }
102 }
103
104 if stage >= 5 {
105 sd_w("NX-SEAT-HUB-GATE pass=" as *u8)
106 let pb: *u8 = sys_mmap(24)
107 hg_itoa(pb, pass)
108 sd_w(pb)
109 if pass == 5 {
110 sd_w("/5 verdict=GREEN\n" as *u8)
111 sys_exit(0)
112 return 0
113 }
114 sd_w("/5 verdict=RED\n" as *u8)
115 sys_exit(1)
116 return 1
117 }
118
119 let self: *u8 = argv[0] as *u8
120 let sb: *u8 = sys_mmap(24)
121 hg_itoa(sb, stage + 1)
122 let pb2: *u8 = sys_mmap(24)
123 hg_itoa(pb2, pass)
124 let nav: *i64 = sys_mmap(40) as *i64
125 nav[0] = self as i64
126 nav[1] = sb as i64
127 nav[2] = pb2 as i64
128 nav[3] = 0
129 let envp: *i64 = sys_mmap(16) as *i64
130 envp[0] = 0
131 sys_execve(self, nav, envp)
132 sd_w("SHG-EXEC-FAIL\n" as *u8)
133 sys_exit(1)
134 return 1
135}