code wiki / (root) / nx_ioae_files_test_20260907.nx

nx_ioae_files_test_20260907.nx source

↩ module page · 160 lines · 8634 B

1// LOCAL native reader integration. argv: existing absolute nonsymlink fixture parent. 2// Fresh private child only; no fsync, production status paths, samples, or cleanup. 3import "nx_ioae_confread_test_20260907.nx" 4import "nx_gate_verdict.nx" 5import "nx_build_canon_input_lib.nx" 6const IG_PATH: i64 = 8192 7const IG_FILE_MODE: i64 = 384 8const IG_EINVAL: i64 = 0-22 9const EFG_DIR_MODE: i64 = 448 10const EFG_PARENT_MAX: i64 = 160 11const EFG_SETUP: i64 = 90 12func ig_len(p: *u8) -> i64 { var n: i64 = 0; while p[n] != (0 as u8) { n = n + 1 } return n } 13func ig_parent(path: *u8) -> i64 { 14 let n: i64 = ig_len(path) 15 if n <= 1 { return 0 } 16 if n >= IG_PATH { return 0 } 17 if path[0] != (BCI_SLASH as u8) { return 0 } 18 if bci_relative_path(path, 1, n-1, IG_PATH-2) != 1 { return 0 } 19 let part: *u8 = sys_mmap(IG_PATH) 20 let probe: *u8 = sys_mmap(IG_PATH) 21 var i: i64 = 0 22 while i <= n { 23 var edge: i64 = 0 24 if i == n { edge = 1 } else { if i > 0 { if path[i] == (BCI_SLASH as u8) { edge = 1 } } } 25 if edge == 1 { 26 part[i] = 0 as u8 27 if sys_readlinkat(part, probe, IG_PATH) != IG_EINVAL { return 0 } 28 } 29 if i < n { part[i] = path[i] } 30 i = i + 1 31 } 32 return 1 33} 34func ig_file_equal(path: *u8, bytes: *u8, n: i64) -> i64 { 35 if n < 0 { return 0 } 36 if n >= IG_PATH { return 0 } 37 let fd: i64 = sys_openat_rd(path) 38 if fd < 0 { return 0 } 39 let buf: *u8 = sys_mmap(IG_PATH) 40 var got: i64 = 0 41 var done: i64 = 0 42 var good: i64 = 1 43 while done == 0 { 44 let r: i64 = sys_read(fd,(buf as i64+got) as *u8,n+1-got) 45 if r < 0 { good = 0; done = 1 } else { 46 if r == 0 { done = 1 } else { got = got+r; if got > n { done = 1 } } 47 } 48 } 49 if sys_close(fd) != 0 { good = 0 } 50 if got != n { good = 0 } 51 if good == 1 { var i: i64 = 0; while i < n { if buf[i] != bytes[i] { good = 0 } i = i+1 } } 52 sys_munmap(buf,IG_PATH) 53 return good 54} 55func ig_write(path: *u8, buf: *u8, n: i64) -> i64 { 56 if (path as i64) == 0 { return 0 } 57 let fd: i64 = sys_openat_wr(path, IG_FILE_MODE) 58 if fd < 0 { return 0 } 59 var w: i64 = 0 60 while w < n { 61 let got: i64 = sys_write(fd, (buf as i64+w) as *u8, n-w) 62 if got <= 0 { sys_close(fd); return 0 } 63 w = w + got 64 } 65 // Fixture visibility check only; persistence barriers belong to the subject under test. 66 let close: i64 = sys_close(fd) 67 if close != 0 { return 0 } 68 return ig_file_equal(path, buf, n) 69} 70func main(argc: i64, argv: *i64) -> i64 { 71 if argc != 2 { sys_exit(EFG_SETUP); return EFG_SETUP } 72 let parent: *u8 = argv[1] as *u8 73 if ig_len(parent) > EFG_PARENT_MAX { sys_exit(EFG_SETUP); return EFG_SETUP } 74 if ig_parent(parent) != 1 { sys_exit(EFG_SETUP); return EFG_SETUP } 75 let root: *u8 = sys_mmap(IOAE_PATH_CAP) 76 var p: i64 = ioae_join(parent,"/nishi-ioae-fixture-" as *u8,root) 77 if p < 0 { sys_exit(EFG_SETUP); return EFG_SETUP } 78 let clock: *i64 = sys_mmap(16) as *i64 79 if sys_clock_gettime_real(clock) != 0 { sys_exit(EFG_SETUP); return EFG_SETUP } 80 p = nxi_buf(root,p,clock[0]); root[p] = 45 as u8; p = p+1 81 p = nxi_buf(root,p,clock[1]); root[p] = 0 as u8 82 if sys_mkdir(root,EFG_DIR_MODE) != 0 { sys_exit(EFG_SETUP); return EFG_SETUP } 83 sys_write(1,root,p); sys_write(1,"\n" as *u8,1) 84 let path: *u8 = sys_mmap(IOAE_PATH_CAP) 85 ioae_join(root,"/record" as *u8,path) 86 let buf: *u8 = sys_mmap(IOAE_CAP) 87 let c: *i64 = gv_ctr() 88 let out: *i64 = sys_mmap(IOAE_BYTES) as *i64 89 gv_head("SHARED EVIDENCE REAL BOUNDED FILE READER" as *u8) 90 gv_check_eq("absent file",ioae_read(path,buf,IOAE_CAP),IOAE_READ_ABSENT,c) 91 gv_check_eq("directory read error",ioae_read(root,buf,IOAE_CAP),IOAE_READ_IO,c) 92 let good: *u8 = "ts=1000\nncpu=8\nblocked_confirmed=4\nbar=8\nconfirm_samples=5\nconfirm_requested=5\nconfirm_gap_ms=3000\nspan_ms=12000\nproducer=nx_ioconfirm\n" as *u8 93 let n: i64 = ioa_slen(good) 94 if ig_write(path,good,n) != 1 { sys_exit(EFG_SETUP); return EFG_SETUP } 95 gv_check_eq("complete read",ioae_read(path,buf,IOAE_CAP),n,c) 96 gv_check_eq("complete parsed fresh",ioae_select(buf,n,8,10,10,1001,900,out),IOAE_CONFIRMED,c) 97 if ig_write(path,good,0) != 1 { sys_exit(EFG_SETUP); return EFG_SETUP } 98 gv_check_eq("empty read length",ioae_read(path,buf,IOAE_CAP),0,c) 99 gv_check_eq("empty is invalid not headroom",ioae_select(buf,0,8,10,10,1001,900,out),IOAE_INVALID,c) 100 if ig_write(path,good,n-1) != 1 { sys_exit(EFG_SETUP); return EFG_SETUP } 101 let short: i64 = ioae_read(path,buf,IOAE_CAP) 102 gv_check_eq("truncated record refused",ioae_select(buf,short,8,10,10,1001,900,out),IOAE_INVALID,c) 103 let full: *u8 = sys_mmap(IOAE_CAP+1) 104 var i: i64 = 0 105 while i < IOAE_CAP+1 { full[i] = 120 as u8; i = i+1 } 106 if ig_write(path,full,IOAE_CAP) != 1 { sys_exit(EFG_SETUP); return EFG_SETUP } 107 gv_check_eq("exact cap rejected",ioae_read(path,buf,IOAE_CAP),IOAE_READ_FULL,c) 108 if ig_write(path,full,IOAE_CAP+1) != 1 { sys_exit(EFG_SETUP); return EFG_SETUP } 109 gv_check_eq("over cap rejected",ioae_read(path,buf,IOAE_CAP),IOAE_READ_FULL,c) 110 // Real policy/root resolution in the private fixture: no production fallback is reachable. 111 let parent_knowledge: *u8 = sys_mmap(IOAE_PATH_CAP) 112 let child: *u8 = sys_mmap(IOAE_PATH_CAP) 113 let child_knowledge: *u8 = sys_mmap(IOAE_PATH_CAP) 114 let parent_conf: *u8 = sys_mmap(IOAE_PATH_CAP) 115 let child_conf: *u8 = sys_mmap(IOAE_PATH_CAP) 116 let chosen: *u8 = sys_mmap(IOAE_PATH_CAP) 117 ioae_join(root,"/knowledge" as *u8,parent_knowledge) 118 ioae_join(root,"/child" as *u8,child) 119 ioae_join(root,"/child/knowledge" as *u8,child_knowledge) 120 ioae_join(root,"/knowledge/build_admit.conf" as *u8,parent_conf) 121 ioae_join(root,"/child/knowledge/build_admit.conf" as *u8,child_conf) 122 if sys_mkdir(parent_knowledge,EFG_DIR_MODE) != 0 { sys_exit(EFG_SETUP); return EFG_SETUP } 123 if sys_mkdir(child,EFG_DIR_MODE) != 0 { sys_exit(EFG_SETUP); return EFG_SETUP } 124 if sys_mkdir(child_knowledge,EFG_DIR_MODE) != 0 { sys_exit(EFG_SETUP); return EFG_SETUP } 125 if sys_chdir(child) != 0 { sys_exit(EFG_SETUP); return EFG_SETUP } 126 gv_check_eq("missing policies OFF",ioae_policy(chosen),0,c) 127 let conf: *u8 = "confirm_max_age_s=900\n" as *u8 128 if ig_write(parent_conf,conf,ioa_slen(conf)) != 1 { sys_exit(EFG_SETUP); return EFG_SETUP } 129 gv_check_eq("parent policy used on absent primary",ioae_policy(chosen),900,c) 130 gv_check_eq("parent policy provenance",ioae_eqspan(chosen,0,ioa_slen(chosen),"../knowledge/" as *u8),1,c) 131 if ig_write(child_conf,conf,ioa_slen(conf)) != 1 { sys_exit(EFG_SETUP); return EFG_SETUP } 132 gv_check_eq("primary policy takes precedence",ioae_policy(chosen),900,c) 133 gv_check_eq("primary policy provenance",ioae_eqspan(chosen,0,ioa_slen(chosen),"knowledge/" as *u8),1,c) 134 let bad: *u8 = "confirm_max_age_s=900junk\n" as *u8 135 if ig_write(child_conf,bad,ioa_slen(bad)) != 1 { sys_exit(EFG_SETUP); return EFG_SETUP } 136 gv_check_eq("malformed primary never falls through",ioae_policy(chosen),0-1,c) 137 if ig_write(child_conf,conf,0) != 1 { sys_exit(EFG_SETUP); return EFG_SETUP } 138 gv_check_eq("empty primary never falls through",ioae_policy(chosen),0-1,c) 139 let hcfg: *i64 = sys_mmap(HIO_C_BYTES) as *i64 140 let hnames: *u8 = sys_mmap(HIO_MAXP*HIO_NAMEW) 141 let heavy: *u8 = "producer fixture\nslots_per_cpu 1\nfloor 1\nmax_centi 800\nwmin 1\nwmax 1\nslot_ttl 900\n" as *u8 142 if ig_write(path,heavy,ioa_slen(heavy)) != 1 { sys_exit(EFG_SETUP); return EFG_SETUP } 143 var repeats: i64 = 0 144 var read_errors: i64 = 0 145 while repeats < 100 { 146 if hio_conf_read(path,hcfg,hnames) != 1 { read_errors = read_errors+1 } 147 if hcfg[HIO_C_NPROD] != 1 { read_errors = read_errors+1 } 148 repeats = repeats+1 149 } 150 gv_check_eq("actual repeated heavy conf reads",read_errors,0,c) 151 if ig_write(path,heavy,0) != 1 { sys_exit(EFG_SETUP); return EFG_SETUP } 152 gv_check_eq("actual empty heavy conf refuses",hio_conf_read(path,hcfg,hnames),0,c) 153 gv_check_eq("actual directory heavy conf refuses",hio_conf_read(root,hcfg,hnames),0,c) 154 gv_check_eq("actual heavy conf buffer released",efg_conf_live,0,c) 155 gv_check_eq("actual heavy conf map unmap balance",efg_conf_allocs,efg_conf_frees,c) 156 gv_check_eq("actual heavy conf identity and release",efg_conf_errors,0,c) 157 sys_munmap(hnames,HIO_MAXP*HIO_NAMEW) 158 let rc: i64 = gv_verdict("SHARED-IO-EVIDENCE-FILES",c,"real read/EOF and fixture setup; not producer durability or live admission" as *u8) 159 sys_exit(rc); return rc 160}