code wiki / (root) / nx_portability_gate.nx

nx_portability_gate.nx source

↩ module page · 42 lines · 2586 B

1// nx_portability_gate.nx -- gates the portability linter (v_scan_port) on synthetic fixtures: a clean 2// logic buffer PASSes; raw /proc + /tmp + __syscall( each counted; a //-comment naming "/proc" is NOT 3// flagged (documentation may cite the law); a string-literal coupling IS flagged (couplings live in 4// strings). Asserts the scanner's RETURN COUNTS directly. Exit 0 only on all-PASS. 5// license_tier: ORIGINAL expect_exit: 0 6// (this file is *_gate.nx = structurally EXEMPT from the linter itself -- fixtures NAME couplings) 7import "nx_verify_port_core.nx" 8 9const GATE_CHECKS: i64 = 5 10const FIX_MIXED: i64 = 3 // fixture C: /proc + /tmp + __syscall( 11 12func pg_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 13func pg_check(name: *u8, ok: i64, pass: *i64) -> i64 { 14 vp_puts("T " as *u8); vp_puts(name); vp_puts(" -> " as *u8) 15 if ok == 1 { vp_puts("PASS\n" as *u8); pass[0] = pass[0] + 1 } else { vp_puts("FAIL\n" as *u8) } 16 return 0 17} 18 19func main(argc: i64, argv: *i64) -> i64 { 20 let pass: *i64 = sys_mmap(16) as *i64 21 pass[0] = 0 22 // A: clean logic -- no couplings 23 let a: *u8 = "func f(x: i64) -> i64 { let b: *u8 = sys_mmap(64); return x }\n" as *u8 24 pg_check("clean-logic-zero" as *u8, (vp_scan(a, pg_slen(a)) == 0) as i64, pass) 25 // B: one raw /proc string literal 26 let b: *u8 = "func g() -> i64 { let p: *u8 = \"/proc/self/stat\" as *u8; return 0 }\n" as *u8 27 pg_check("proc-string-flagged" as *u8, (vp_scan(b, pg_slen(b)) == 1) as i64, pass) 28 // C: mixed -- /proc + /tmp + raw __syscall( 29 let c: *u8 = "let x: *u8 = \"/proc/stat\" as *u8\nlet y: *u8 = \"/tmp/x.log\" as *u8\nlet r: i64 = __syscall(1, 0, 0, 0, 0, 0, 0)\n" as *u8 30 pg_check("mixed-three-counted" as *u8, (vp_scan(c, pg_slen(c)) == FIX_MIXED) as i64, pass) 31 // D: a comment NAMING /proc is documentation, not coupling 32 let d: *u8 = "// this module deliberately avoids \"/proc\" (see NISHI_PORTABILITY)\nfunc h() -> i64 { return 1 }\n" as *u8 33 pg_check("comment-not-flagged" as *u8, (vp_scan(d, pg_slen(d)) == 0) as i64, pass) 34 // E: /sys and /dev also count 35 let e: *u8 = "let s: *u8 = \"/sys/class/net\" as *u8\nlet v: *u8 = \"/dev/null\" as *u8\n" as *u8 36 pg_check("sys-dev-counted" as *u8, (vp_scan(e, pg_slen(e)) == GATE_CHECKS - FIX_MIXED) as i64, pass) 37 38 vp_puts("PORTABILITY-GATE pass=" as *u8); vp_putn(pass[0]); vp_puts("/" as *u8); vp_putn(GATE_CHECKS); vp_puts(" verdict=" as *u8) 39 if pass[0] == GATE_CHECKS { vp_puts("GREEN\n" as *u8); return 0 } 40 vp_puts("RED\n" as *u8) 41 return 1 42}