code wiki / _hdl_build / nx_cidr_gate.nx
nx_cidr_gate.nx source
↩ module page · 44 lines · 3104 B
1import "nx_gate_gn.nx"
2import "nx_gate_base.nx"
3// nx_cidr_gate.nx -- verifies the UNIFIED nx_cidr lib after the merge: the longest-prefix tiering (kept) AND the
4// a.b.c.d/N notation parser + canonicalize (merged in from the former runtime/ smoke). Proves no functionality
5// was lost in resolving the shadow collision. expect_exit: 0 license_tier: ORIGINAL
6import "nx_cidr.nx"
7import "nx_syscalls.nx"
8
9func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
10" as *u8); return ok }
11
12func main() -> i64 {
13 gw("=== nx_cidr_gate: unified lib keeps BOTH notation-parsing and longest-prefix tiering ===\n" as *u8)
14 var pass: i64=0; var total: i64=0
15
16 // T1 MERGED-IN: cidr_parse the notation "10.0.0.0/8"
17 let ip: *i64=sys_mmap(16) as *i64; let pfx: *i64=sys_mmap(16) as *i64
18 let rc: i64=cidr_parse("10.0.0.0/8\x00" as *u8, 10, ip, pfx)
19 total=total+1; if rc==0 { if pfx[0]==8 { if ip[0]==0x0A000000 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) }
20 gw("T1 PARSE (merged): '10.0.0.0/8' -> ip ok, prefix=\x00" as *u8); gn(pfx[0]); gw("\n" as *u8)
21
22 // T2 containment + canonicalize
23 let c1: i64=cidr_contains(ip[0], 8, 0x0A010203); let c0: i64=cidr_contains(ip[0], 8, 0xC0A80101)
24 let na: i64=cidr_network_address(0x0A010203, 8)
25 total=total+1; if c1==1 { if c0==0 { if na==0x0A000000 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) }
26 gw("T2 CONTAINS/CANON (merged): 10.1.2.3 in /8(\x00" as *u8); gn(c1); gw("), 192.168.1.1 not(\x00" as *u8); gn(c0); gw("), canon ok\n" as *u8)
27
28 // T3 KEPT: longest-prefix tiering -- /16 beats /8 for 10.1.2.3
29 let nets: *i64=sys_mmap(16) as *i64; let pfxs: *i64=sys_mmap(16) as *i64; let tiers: *i64=sys_mmap(16) as *i64
30 nets[0]=0x0A000000; pfxs[0]=8; tiers[0]=1
31 nets[1]=0x0A010000; pfxs[1]=16; tiers[1]=2
32 let tier: i64=cidr_tier(0x0A010203, nets, pfxs, tiers, 2, 0)
33 total=total+1; if tier==2 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
34 gw("T3 TIER (kept): longest-prefix /16 wins over /8 -> tier=\x00" as *u8); gn(tier); gw(" (expect 2)\n" as *u8)
35
36 // T4 the lib also still has cidr_match + cidr_ip (no API lost)
37 let m1: i64=cidr_match(0x0A010203, 0x0A000000, 8); let ipx: i64=cidr_ip("10.0.0.0\x00" as *u8)
38 total=total+1; if m1==1 { if ipx==0x0A000000 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) }
39 gw("T4 ORIGINAL API kept: cidr_match(\x00" as *u8); gn(m1); gw("), cidr_ip ok\n" as *u8)
40
41 gw("\n=== nx_cidr_gate \x00" as *u8); gn(pass); gw("/\x00" as *u8); gn(total)
42 if pass==total { gw(" GREEN -- the merge GREW the capability (parse + canonicalize + tier + match + ip) with ZERO functionality lost. The collision can now be resolved (rename the redundant smoke).\n" as *u8); sys_exit(0); return 0 }
43 gw(" RED\n" as *u8); sys_exit(1); return 1
44}