nx_mvault_caption_gate.nx source
↩ module page · 70 lines · 3034 B
1// nx_mvault_caption_gate.nx -- proves the comprehensive per-item capture:
2// measurement + tag + caption persist under one CID, read back exact, and the
3// per-item field index enumerates all three.
4// (Build with a clean /tmp store; run-exit == 0 means GREEN.)
5
6import "nx_syscalls.nx"
7import "nx_mvault_tag.nx"
8import "nx_mvault_measure.nx"
9import "nx_mvault_caption.nx"
10
11func slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
12func streq_n(a: *u8, alen: i64, b: *u8, blen: i64) -> i64 {
13 if alen != blen { return 0 }
14 var i: i64 = 0
15 while i < alen { if a[i] != b[i] { return 0 } i = i + 1 }
16 return 1
17}
18
19func main(argc: i64, argv: *i64) -> i64 {
20 var fails: i64 = 0
21 let prefix: *u8 = "/tmp/mvault_cap_gate-" as *u8
22 let cid: *u8 = "nxc1-ab12cd34ef5678900123456789abcdef0123456789abcdef0123456789abcdef" as *u8
23
24 // build a measurement, a tag, a caption (B7/B8)
25 let val: *u8 = sys_mmap(64)
26 mv_ratio_str(val, 700, 1000)
27 let ax_hwr: *u8 = "hip_waist_ratio" as *u8
28 let meas: *u8 = sys_mmap(128)
29 mv_meas_make(meas, ax_hwr, val, MV_LEG_MATH, 920) // hip_waist_ratio=700/1000@math#920
30 let ns_perf: *u8 = "performer" as *u8
31 let v_elara: *u8 = "elara" as *u8
32 let tag: *u8 = sys_mmap(128)
33 mv_tag_make(tag, ns_perf, v_elara) // performer:elara
34 let cap_text: *u8 = "a woman on a bed" as *u8
35 let cap: *u8 = sys_mmap(256)
36 mv_caption_make(cap, MV_CAP_NATURAL, cap_text) // cap:natural:a woman on a bed
37
38 // persist all three under the item CID
39 let f_meas: *u8 = "meas:hip_waist_ratio" as *u8
40 let f_tag: *u8 = "tag:0" as *u8
41 let f_cap: *u8 = "cap:natural" as *u8
42 if mv_cap_put(prefix, cid, f_meas, meas, slen(meas)) < 0 { fails = fails + 1 }
43 if mv_cap_put(prefix, cid, f_tag, tag, slen(tag)) < 0 { fails = fails + 1 }
44 if mv_cap_put(prefix, cid, f_cap, cap, slen(cap)) < 0 { fails = fails + 1 }
45
46 // read each back exact
47 let gp: *i64 = sys_mmap(16) as *i64
48 let gl: *i64 = sys_mmap(16) as *i64
49 if mv_cap_get(prefix, cid, f_meas, gp, gl) != 1 { fails = fails + 1 }
50 if streq_n(gp[0] as *u8, gl[0], meas, slen(meas)) != 1 { fails = fails + 1 }
51 if mv_cap_get(prefix, cid, f_tag, gp, gl) != 1 { fails = fails + 1 }
52 if streq_n(gp[0] as *u8, gl[0], tag, slen(tag)) != 1 { fails = fails + 1 }
53 if mv_cap_get(prefix, cid, f_cap, gp, gl) != 1 { fails = fails + 1 }
54 if streq_n(gp[0] as *u8, gl[0], cap, slen(cap)) != 1 { fails = fails + 1 }
55
56 // the per-item field index enumerates all three (3 newlines)
57 let fbuf: *u8 = sys_mmap(65536)
58 let fl: i64 = mv_cap_fields(prefix, cid, fbuf, 65536)
59 var nl: i64 = 0
60 var i: i64 = 0
61 while i < fl { if fbuf[i] == (10 as u8) { nl = nl + 1 } i = i + 1 }
62 if nl != 3 { fails = fails + 1 }
63
64 if fails == 0 {
65 sys_write(1, "MVAULT-CAPTION-GATE GREEN capture-assembled\n" as *u8, 44)
66 return 0
67 }
68 sys_write(1, "MVAULT-CAPTION-GATE RED\n" as *u8, 24)
69 return 1
70}