code wiki / _hdl_build / nx_build_gate_test.nx

nx_build_gate_test.nx source

↩ module page · 47 lines · 3858 B

1// nx_build_gate_test.nx -- the team honestly knows its build limits (proven by the real __umulhi64 gap). 2// a plain test (needs BASE) on the available BASE compiler -> BUILDABLE 3// the file-based TLS daemon (needs G2) on the BASE compiler -> NEEDS_BOOTSTRAP (G2 source in repo) 4// ...with the build container reachable -> route = BUILD_ENV (low risk) 5// ...with no build env + a chicken-and-egg G2 source -> BLOCKED 6// Exit 0 on 7/7. license_tier: ORIGINAL 7 8import "nx_build_gate.nx" 9import "nx_syscalls.nx" 10 11func bt_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 12func bt_num(v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64=v; if m<0 {m=0-m}; let t: *u8 = sys_mmap(28); var k: i64=0; if m==0 {t[0]=48;k=1}; while m>0 {t[k]=48+(m%10); m=m/10; k=k+1}; var i: i64=0; while i<k {bb[i]=t[k-1-i]; i=i+1}; sys_write(1, bb, k); return 0 } 13 14func main() -> i64 { 15 bt_puts("=== BUILD GATE: the team knows what it can/can't build (real __umulhi64 gap) ===\n" as *u8) 16 // available compiler = BASE (pre-G2 nx_cc_known_good.elf) 17 let avail: i64 = BG_FEAT_BASE 18 // a plain capability test needs only BASE 19 let v_plain: i64 = bg_verdict(BG_FEAT_BASE, avail, 1) 20 // the TLS daemon needs G2; G2 compiler source IS in the repo (nx_parse.nx handles __umulhi64) 21 let boot: i64 = bg_bootstrappable(1, 0) // source in repo, assume no chicken-egg 22 let v_tls: i64 = bg_verdict(BG_FEAT_G2, avail, boot) 23 let risk: i64 = bg_carries_miscompile_risk(v_tls) 24 let route_env: i64 = bg_route(v_tls, 1) // build container reachable 25 let route_boot: i64 = bg_route(v_tls, 0) // no build env 26 // a true chicken-and-egg (G2 source needs G2) with no build env -> BLOCKED 27 let v_blocked: i64 = bg_verdict(BG_FEAT_G2, avail, bg_bootstrappable(1, 1)) 28 29 bt_puts(" plain test (needs BASE) -> verdict=" as *u8); bt_num(v_plain); bt_puts(" (2=BUILDABLE)\n" as *u8) 30 bt_puts(" TLS daemon (needs G2) -> verdict=" as *u8); bt_num(v_tls); bt_puts(" (1=NEEDS_BOOTSTRAP) miscompile-risk=" as *u8); bt_num(risk); bt_puts("\n" as *u8) 31 bt_puts(" route w/ build-env=" as *u8); bt_num(route_env); bt_puts(" (1=use the BUILD CONTAINER, low risk) w/o=" as *u8); bt_num(route_boot); bt_puts(" (2=bootstrap, higher risk)\n" as *u8) 32 bt_puts(" chicken-and-egg + no env -> verdict=" as *u8); bt_num(v_blocked); bt_puts(" (0=BLOCKED)\n" as *u8) 33 34 let r: *i64 = sys_mmap(8*8) as *i64 35 r[0] = 0; if v_plain == BG_BUILDABLE { r[0] = 1 } // simple things build directly 36 r[1] = 0; if v_tls == BG_NEEDS_BOOTSTRAP { r[1] = 1 } // the TLS daemon honestly NOT directly buildable 37 r[2] = 0; if risk == 1 { r[2] = 1 } // bootstrapping carries miscompile risk 38 r[3] = 0; if route_env == BG_ROUTE_BUILD_ENV { r[3] = 1 } // preferred unblock = the build container 39 r[4] = 0; if route_boot == BG_ROUTE_BOOTSTRAP { r[4] = 1 } // fallback = bootstrap 40 r[5] = 0; if v_blocked == BG_BLOCKED { r[5] = 1 } // chicken-egg + no env = blocked (honest) 41 r[6] = 0; if bg_directly_buildable(BG_FEAT_G2, BG_FEAT_BASE) == 0 { if bg_directly_buildable(BG_FEAT_BASE, BG_FEAT_BASE) == 1 { r[6] = 1 } } 42 var pass: i64 = 0; var i: i64 = 0 43 while i < 7 { pass = pass + r[i]; i = i + 1 } 44 bt_puts("----\n passed " as *u8); bt_num(pass); bt_puts("/7\n" as *u8) 45 if pass == 7 { bt_puts(" KNOWS ITS LIMITS: the team can't directly build the TLS daemon (pre-G2 compiler), names the gap (__umulhi64/G2), and routes to the low-risk BUILD CONTAINER over a risky bootstrap-on-prod. No corner cut, no blind compiler swap.\n" as *u8); sys_exit(0); return 0 } 46 bt_puts(" FAIL\n" as *u8); sys_exit(1); return 1 47}