code wiki / (root) / nx_memory_gate.nx

nx_memory_gate.nx source

↩ module page · 60 lines · 3216 B

1// nx_memory_gate.nx -- gates the consolidated memory tool on a REAL fixture seg-store (authored via the 2// canonical ss_begin/ss_add/ss_commit + ss_next_segid): latest-version get, absent vs TOMBSTONED 3// discrimination, version-history count, registry-index readback, store discovery + live segment count. 4// Runner must clean /tmp/memgate first. Exit 0 only on all-PASS. license_tier: ORIGINAL expect_exit: 0 5import "nx_memory_lib.nx" 6 7const GATE_CHECKS: i64 = 7 8const DIR_MODE: i64 = 0x1ed // 0755 9const V2_LEN: i64 = 2 // len("v2") -- the LATEST k1 value 10const HIST_N: i64 = 2 // k1 versions authored 11const IDX_LEN: i64 = 6 // len("k1\nk2\n") 12const FIX_SEGS: i64 = 4 // commits authored below 13const TOMB_KIND: i64 = 2 // seg-store tombstone record kind 14 15func mg_check(name: *u8, ok: i64, pass: *i64) -> i64 { 16 mx_puts("T " as *u8); mx_puts(name); mx_puts(" -> " as *u8) 17 if ok == 1 { mx_puts("PASS\n" as *u8); pass[0] = pass[0] + 1 } else { mx_puts("FAIL\n" as *u8) } 18 return 0 19} 20func mg_commit1(prefix: *u8, key: *u8, val: *u8, kind: i64) -> i64 { 21 let w: *i64 = ss_begin() 22 ss_add(w, kind, key, val, mx_slen(val)) 23 return ss_commit(prefix, w, ss_next_segid(prefix)) 24} 25 26func main(argc: i64, argv: *i64) -> i64 { 27 let pass: *i64 = sys_mmap(16) as *i64 28 pass[0] = 0 29 sys_mkdir("/tmp/memgate" as *u8, DIR_MODE) 30 let P: *u8 = "/tmp/memgate/mg-" as *u8 31 // author the fixture store: k1 twice (v1 then v2), k2 + the index in one commit, k3 tombstone 32 mg_commit1(P, "k1" as *u8, "v1" as *u8, 1) 33 mg_commit1(P, "k1" as *u8, "v2" as *u8, 1) 34 let w3: *i64 = ss_begin() 35 ss_add(w3, 1, "k2" as *u8, "zz" as *u8, V2_LEN) 36 ss_add(w3, 1, "__idx__" as *u8, "k1\nk2\n" as *u8, IDX_LEN) 37 ss_commit(P, w3, ss_next_segid(P)) 38 mg_commit1(P, "k3" as *u8, "xx" as *u8, TOMB_KIND) 39 40 // T1 get resolves the LATEST version (v2, not v1) 41 mg_check("get-latest-version" as *u8, (mx_get(P, "k1" as *u8) == V2_LEN) as i64, pass) 42 // T2 absent key is graceful + distinct 43 mg_check("get-absent" as *u8, (mx_get(P, "nope" as *u8) == (0 - 1)) as i64, pass) 44 // T3 tombstoned key is distinct from absent (delete semantics surfaced honestly) 45 mg_check("get-tombstoned-distinct" as *u8, (mx_get(P, "k3" as *u8) == 0 - (3 as i64)) as i64, pass) 46 // T4 history counts every version of k1 47 mg_check("history-count" as *u8, (mx_history(P, "k1" as *u8) == HIST_N) as i64, pass) 48 // T5 index readback (a registry's id list is just a key) 49 mg_check("index-readback" as *u8, (mx_index(P, "__idx__" as *u8) == IDX_LEN) as i64, pass) 50 // T6 store discovery finds exactly this store 51 mg_check("stores-discovers" as *u8, (mx_stores("/tmp/memgate" as *u8) == 1) as i64, pass) 52 // T7 the discovered store reports the true (uncapped) segment count 53 let sp: *i64 = sys_mmap(16) as *i64 54 mg_check("stores-true-segcount" as *u8, (ss_manifest_dyn(P, sp) == FIX_SEGS) as i64, pass) 55 56 mx_puts("MEMORY-GATE pass=" as *u8); mx_putn(pass[0]); mx_puts("/" as *u8); mx_putn(GATE_CHECKS); mx_puts(" verdict=" as *u8) 57 if pass[0] == GATE_CHECKS { mx_puts("GREEN\n" as *u8); return 0 } 58 mx_puts("RED\n" as *u8) 59 return 1 60}