code wiki / _hdl_build / nx_store_collision_check_gate.nx

nx_store_collision_check_gate.nx source

↩ module page · 61 lines · 3295 B

1// nx_store_collision_check_gate.nx -- gate for acl F745. Fixtures built with explicit tab(9)/nl(10) 2// bytes (NishiLang string literals don't carry \t). Captures stdout via tr_run_capture + substring 3// matches the verdict. T1 reused id -> COLLISION (positive) ; T2 unique ids -> CLEAN (NEG-CONTROL). 4// Runs _offc/nx_store_collision_check.elf (staged first). license_tier: ORIGINAL expect_exit: 0 5import "nx_tool_run.nx" 6 7func g_w(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 } 8func g_wn(fd: i64, v: i64) -> i64 { var m: i64 = v; if m < 0 { g_w(fd, "-" as *u8); m = 0 - m } let t: *u8 = sys_mmap(28); var k: i64 = 0; if m == 0 { t[0] = 48 as u8; k = 1 } while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } let o: *u8 = sys_mmap(28); var i: i64 = 0; while i < k { o[i] = t[k - 1 - i]; i = i + 1 } sys_write(fd, o, k); return 0 } 9func g_bytes(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 } 10func g_ch(fd: i64, c: i64) -> i64 { let b: *u8 = sys_mmap(2); b[0] = c as u8; sys_write(fd, b, 1); return 0 } 11func g_row(fd: i64, id: *u8, val: *u8) -> i64 { g_bytes(fd, id); g_ch(fd, 9); g_bytes(fd, val); g_ch(fd, 10); return 0 } 12func g_has(buf: *u8, n: i64, pat: *u8) -> i64 { 13 var pl: i64 = 0 14 while pat[pl] != (0 as u8) { pl = pl + 1 } 15 if pl == 0 { return 0 } 16 var i: i64 = 0 17 while i + pl <= n { 18 var k: i64 = 0 19 var m: i64 = 1 20 while k < pl { if buf[i + k] != pat[k] { m = 0; k = pl } else { k = k + 1 } } 21 if m == 1 { return 1 } 22 i = i + 1 23 } 24 return 0 25} 26func g_run(path: *u8, out: *u8, ocap: i64, ol: *i64) -> i64 { 27 let av: *i64 = sys_mmap(64) as *i64 28 av[0] = "_offc/nx_store_collision_check.elf" as i64 29 av[1] = "dupid" as i64 30 av[2] = path as i64 31 av[3] = "0" as i64 32 av[4] = 0 33 return tr_run_capture("_offc/nx_store_collision_check.elf" as *u8, av, out, ocap, ol) 34} 35func main() -> i64 { 36 let fd1: i64 = sys_openat_wr("/tmp/scc_dup" as *u8, 0x1a4) 37 g_row(fd1, "F1" as *u8, "alpha" as *u8); g_row(fd1, "F2" as *u8, "bravo" as *u8); g_row(fd1, "F1" as *u8, "charlie" as *u8) 38 sys_close(fd1) 39 let fd2: i64 = sys_openat_wr("/tmp/scc_clean" as *u8, 0x1a4) 40 g_row(fd2, "F1" as *u8, "alpha" as *u8); g_row(fd2, "F2" as *u8, "bravo" as *u8); g_row(fd2, "F3" as *u8, "charlie" as *u8) 41 sys_close(fd2) 42 let ocap: i64 = 4096 43 let out: *u8 = sys_mmap(ocap) 44 let ol: *i64 = sys_mmap(16) as *i64 45 var pass: i64 = 0 46 var tot: i64 = 0 47 48 tot = tot + 1 49 g_run("/tmp/scc_dup" as *u8, out, ocap, ol) 50 if g_has(out, ol[0], "verdict=COLLISION" as *u8) == 1 { pass = pass + 1; g_w(1, "T1 reused-id->COLLISION PASS\n" as *u8) } else { g_w(1, "T1 FAIL\n" as *u8) } 51 52 tot = tot + 1 53 g_run("/tmp/scc_clean" as *u8, out, ocap, ol) 54 if g_has(out, ol[0], "verdict=CLEAN" as *u8) == 1 { pass = pass + 1; g_w(1, "T2 unique-ids->CLEAN PASS (neg-control)\n" as *u8) } else { g_w(1, "T2 FAIL\n" as *u8) } 55 56 g_w(1, "STORE-COLLISION-GATE pass=" as *u8); g_wn(1, pass); g_w(1, "/" as *u8); g_wn(1, tot) 57 if pass == tot { g_w(1, " verdict=GREEN\n" as *u8); sys_exit(0); return 0 } 58 g_w(1, " verdict=RED\n" as *u8) 59 sys_exit(1) 60 return 1 61}