code wiki / (root) / nx_compare_rank_caps_gate.nx

nx_compare_rank_caps_gate.nx source

↩ module page · 502 lines · 28990 B

1// nx_compare_rank_caps_gate.nx -- GATE for the ranker's POPULATION HONESTY (lane F, 2026-08-23). 2// 3// THE DEFECT THIS GUARDS: nx_compare_rank carried RANK_MAX_ROWS=64 / RANK_MAX_RUNGS=64 / RANK_FIELD_MAX=24 4// / 8 versions / 16 milestones as silent caps. browser.matrix has 76 rows, so every row past 64 was 5// invisible and its rung read UNMAPPED (value 0) while its watch row existed. A ranker that drops the 6// tail of its own population publishes a prefix as the whole order. Every bound is now DERIVED from the 7// loaded bytes; this gate proves the derivation by driving the subject binary over synthetic domains 8// that EXCEED every former cap, over the real browser and toolchain domains, and against INDEPENDENT 9// counts the gate takes itself from the same files (rung| lines, matrix data rows, symbol->row mapping). 10// 11// FIXTURE ROOT: /tmp/nxrkcap_<pid>/ (reaped by the tmpstorereap beat; nothing in it is EXECUTED from 12// /tmp -- the subject and the forks it makes are reached through symlinks/absolute paths into the 13// exec-capable serving root, and noexec binds to the executed file's mount, not the CWD). It carries its 14// OWN buildroot/knowledge/compare/ (synthetic + copied real domains), its own buildroot/fx/ organ, a 15// symlink buildroot/runtime -> the real runtime (rk_measure reads organ sources there), and symlinks to 16// the real nx_dr_ocm_cli / nx_store_put / nx_pm_intake elfs. The subject is run with CWD = the fixture 17// root, so every plane it publishes and every pm-intake ask it files lands INSIDE the fixture, never in 18// the estate's planes. Falls back to _build/nxrkcap_<pid>/ only if /tmp cannot be created. 19// 20// Usage: nx_compare_rank_caps_gate [subject_elf] (default ./nx_compare_rank.elf; CWD = serving root) 21// license_tier: ORIGINAL No hw writes (Rule 26). 22import "nx_syscalls.nx" 23import "nx_gate_verdict.nx" 24import "nx_tool_run.nx" 25 26const RKC_FORMER_CAP: i64 = 64 // the cap this gate retires (RANK_MAX_RUNGS/ROWS); used ONLY to assert that a 27 // fixture EXCEEDS it -- never as a bound on anything the subject does 28const RKC_SYN_RUNGS: i64 = 70 // > the former 64-rung cap; the synthetic plan has this many rung| rows 29const RKC_SYN_EXTRA_ROWS: i64 = 9 // matrix rows beyond the rungs' own (header-like noise rows), so rows=79 > 64 30const RKC_SYN_COLS: i64 = 20 // rival columns on the wide matrix: 9 + 20 fields > the former 24-field cap 31const RKC_SYN_VERS: i64 = 9 // > the former 8-version cap; versions 1..8 met, the 9th unmet 32const RKC_SYN_MS: i64 = 18 // > the former 16-milestone cap (RKC_SYN_VERS of them referenced by ver| rows) 33const RKC_SYN_PRESENT_A: i64 = 3 // rung index whose symbol the fx organ DEFINES (measured present) 34const RKC_SYN_PRESENT_B: i64 = 68 // a second present symbol, PAST the former cap 35const RKC_SYN_NOROW: i64 = 66 // a rung past the former cap with NO matrix row at all: must read UNMAPPED 36const RKC_CAPTURE: i64 = 1048576 // captured stdout of one subject run (a pipe, size unknowable): named for 37 // this one purpose; a fill is a tooth FAILURE below, never a silent prefix 38const RKC_PATH: i64 = 1024 // one composed fixture path (root <= getcwd + 32 + names <= 64 each) 39const RKC_MODE_X: i64 = 0x1ed 40const RKC_MODE_RW: i64 = 0x1a4 41 42func rc_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 43func rc_cat(d: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; var oo: i64 = o; while s[i] != (0 as u8) { d[oo] = s[i]; oo = oo + 1; i = i + 1 } d[oo] = 0 as u8; return oo } 44func rc_catn(d: *u8, o: i64, v: i64) -> i64 { 45 let t: *u8 = sys_mmap(32) 46 var m: i64 = v 47 var k: i64 = 0 48 var oo: i64 = o 49 if m < 0 { d[oo] = 45 as u8; oo = oo + 1; m = 0 - m } 50 if m == 0 { t[0] = 48 as u8; k = 1 } 51 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 52 var i: i64 = 0 53 while i < k { d[oo + i] = t[k - 1 - i]; i = i + 1 } 54 oo = oo + k 55 d[oo] = 0 as u8 56 return oo 57} 58func rc_starts(s: *u8, p: *u8) -> i64 { var i: i64 = 0; while p[i] != (0 as u8) { if s[i] != p[i] { return 0 } i = i + 1 } return 1 } 59func rc_streq(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while a[i] == b[i] { if a[i] == (0 as u8) { return 1 } i = i + 1 } return 0 } 60// count occurrences of needle in hay[0,n) -- full scan, never a prefix 61func rc_count(hay: *u8, n: i64, needle: *u8) -> i64 { 62 let nl: i64 = rc_slen(needle) 63 if nl == 0 { return 0 } 64 var c: i64 = 0 65 var i: i64 = 0 66 while i + nl <= n { 67 var k: i64 = 0 68 var same: i64 = 1 69 var kg: i64 = 1 70 while kg == 1 { if k >= nl { kg = 0 } else { if hay[i + k] != needle[k] { same = 0; kg = 0 } k = k + 1 } } 71 if same == 1 { c = c + 1 } 72 i = i + 1 73 } 74 return c 75} 76// parse the decimal after the FIRST occurrence of key in hay[0,n); -1 if absent 77func rc_field(hay: *u8, n: i64, key: *u8) -> i64 { 78 let kl: i64 = rc_slen(key) 79 var i: i64 = 0 80 var at: i64 = 0 - 1 81 var go: i64 = 1 82 while go == 1 { 83 if i + kl > n { go = 0 } else { 84 var k: i64 = 0 85 var same: i64 = 1 86 var kg: i64 = 1 87 while kg == 1 { if k >= kl { kg = 0 } else { if hay[i + k] != key[k] { same = 0; kg = 0 } k = k + 1 } } 88 if same == 1 { at = i + kl; go = 0 } else { i = i + 1 } 89 } 90 } 91 if at < 0 { return 0 - 1 } 92 var v: i64 = 0 93 var any: i64 = 0 94 var dg: i64 = 1 95 while dg == 1 { 96 if at >= n { dg = 0 } else { 97 let c: i64 = hay[at] as i64 98 if c >= 48 { if c <= 57 { v = v * 10 + (c - 48); any = 1; at = at + 1 } else { dg = 0 } } else { dg = 0 } 99 } 100 } 101 if any == 0 { return 0 - 1 } 102 return v 103} 104// end of the line that starts at p: index of its newline, or n when the last line has none. Explicit 105// flag; the cursor is never the sentinel (nx_srclint class). 106func rc_eol(b: *u8, n: i64, p: i64) -> i64 { 107 var e: i64 = p 108 var go: i64 = 1 109 while go == 1 { if e >= n { go = 0 } else { if b[e] == (10 as u8) { go = 0 } else { e = e + 1 } } } 110 return e 111} 112func rc_write_file(path: *u8, b: *u8, n: i64) -> i64 { 113 let fd: i64 = sys_openat_wr(path, RKC_MODE_RW) 114 if fd < 0 { return 0 - 1 } 115 var off: i64 = 0 116 while off < n { let w: i64 = sys_write(fd, (b as i64 + off) as *u8, n - off); if w <= 0 { sys_close(fd); return 0 - 1 } off = off + w } 117 sys_close(fd) 118 return n 119} 120// copy a file whole (sys_read_file sizes from the file; cannot short-read) 121func rc_copy(src: *u8, dst: *u8) -> i64 { 122 let lp: *i64 = sys_mmap(16) as *i64 123 let b: *u8 = sys_read_file(src, lp) 124 if (b as i64) == 0 { return 0 - 1 } 125 return rc_write_file(dst, b, lp[0]) 126} 127// run the subject on one domain with CWD = fixture root; returns bytes captured (via outlen) and rc 128func rc_run_subject(subject: *u8, dom: *u8, out: *u8, outlen: *i64) -> i64 { 129 let av: *i64 = sys_mmap(8 * 4) as *i64 130 av[0] = subject as i64 131 av[1] = dom as i64 132 av[2] = 0 133 return tr_run_capture(subject, av, out, RKC_CAPTURE - 1, outlen) 134} 135// INDEPENDENT COUNTS over a plan/matrix pair (the gate's own ruler, not the subject's): 136// out[0] = rung| rows in the plan 137// out[1] = data rows in the matrix (not '#', not '@', not empty, >= 5 + ncol fields) 138// out[2] = rungs whose symbol has NO matrix row (exact or _ABSENT_:<sym>) -> must read UNMAPPED 139// out[3] = ncol from @cols 140func rc_census(plan: *u8, matrix: *u8, out: *i64) -> i64 { 141 out[0] = 0; out[1] = 0; out[2] = 0; out[3] = 0 142 let plp: *i64 = sys_mmap(16) as *i64 143 let pb: *u8 = sys_read_file(plan, plp) 144 let mlp: *i64 = sys_mmap(16) as *i64 145 let mb: *u8 = sys_read_file(matrix, mlp) 146 if (pb as i64) == 0 { return 0 - 1 } 147 if (mb as i64) == 0 { return 0 - 1 } 148 let pn: i64 = plp[0] 149 let mn: i64 = mlp[0] 150 // matrix: collect symbol field (3rd, index 2) of every data row, ncol from @cols 151 var ncol: i64 = 0 152 var mrows: i64 = 0 153 // first pass: ncol 154 var p: i64 = 0 155 while p < mn { 156 let e: i64 = rc_eol(mb, mn, p) 157 let ll: i64 = e - p 158 if ll >= 6 { if rc_starts((mb as i64 + p) as *u8, "@cols " as *u8) == 1 { 159 var pc: i64 = 1 160 var q: i64 = p + 6 161 while q < e { if mb[q] == (124 as u8) { pc = pc + 1 } q = q + 1 } 162 ncol = pc 163 } } 164 p = e + 1 165 } 166 out[3] = ncol 167 // second pass: data rows; record symbol spans (start offset, length) into arrays sized by lines 168 var mlines: i64 = 1 169 var z: i64 = 0 170 while z < mn { if mb[z] == (10 as u8) { mlines = mlines + 1 } z = z + 1 } 171 let symoff: *i64 = sys_mmap(mlines * 8) as *i64 172 let symlen: *i64 = sys_mmap(mlines * 8) as *i64 173 p = 0 174 while p < mn { 175 let e2: i64 = rc_eol(mb, mn, p) 176 var c0: i64 = 0 177 if e2 > p { c0 = mb[p] as i64 } 178 var isdata: i64 = 1 179 if e2 == p { isdata = 0 } 180 if c0 == 35 { isdata = 0 } 181 if c0 == 64 { isdata = 0 } 182 if isdata == 1 { 183 // count fields; locate field 2 (symbol) 184 var nf: i64 = 1 185 var f2s: i64 = 0 - 1 186 var f2e: i64 = 0 - 1 187 var q2: i64 = p 188 while q2 < e2 { 189 if mb[q2] == (124 as u8) { 190 if nf == 2 { f2s = q2 + 1 } 191 if nf == 3 { f2e = q2 } 192 nf = nf + 1 193 } 194 q2 = q2 + 1 195 } 196 if nf >= 5 + ncol { if f2s >= 0 { 197 if f2e < 0 { f2e = e2 } 198 symoff[mrows] = f2s; symlen[mrows] = f2e - f2s 199 mrows = mrows + 1 200 } } 201 } 202 p = e2 + 1 203 } 204 out[1] = mrows 205 // plan: rung| rows; for each, symbol = field 3 (index 3); check mapping 206 var nr: i64 = 0 207 var unm: i64 = 0 208 p = 0 209 while p < pn { 210 let e3: i64 = rc_eol(pb, pn, p) 211 if rc_starts((pb as i64 + p) as *u8, "rung|" as *u8) == 1 { 212 nr = nr + 1 213 var nf3: i64 = 1 214 var ss: i64 = 0 - 1 215 var se: i64 = 0 - 1 216 var q3: i64 = p 217 while q3 < e3 { 218 if pb[q3] == (124 as u8) { 219 if nf3 == 3 { ss = q3 + 1 } 220 if nf3 == 4 { se = q3 } 221 nf3 = nf3 + 1 222 } 223 q3 = q3 + 1 224 } 225 if se < 0 { se = e3 } 226 var mapped: i64 = 0 227 if ss >= 0 { 228 let sl: i64 = se - ss 229 var r: i64 = 0 230 while r < mrows { 231 // exact 232 if symlen[r] == sl { 233 var k: i64 = 0; var same: i64 = 1 234 while k < sl { if mb[symoff[r] + k] != pb[ss + k] { same = 0; k = sl } k = k + 1 } 235 if same == 1 { mapped = 1; r = mrows } 236 } 237 // _ABSENT_:<sym> 238 if mapped == 0 { if symlen[r] == sl + 9 { if rc_starts((mb as i64 + symoff[r]) as *u8, "_ABSENT_:" as *u8) == 1 { 239 var k2: i64 = 0; var same2: i64 = 1 240 while k2 < sl { if mb[symoff[r] + 9 + k2] != pb[ss + k2] { same2 = 0; k2 = sl } k2 = k2 + 1 } 241 if same2 == 1 { mapped = 1; r = mrows } 242 } } } 243 r = r + 1 244 } 245 } 246 if mapped == 0 { unm = unm + 1 } 247 } 248 p = e3 + 1 249 } 250 out[0] = nr 251 out[2] = unm 252 return 0 253} 254 255// ---- synthetic domain writer: RKC_SYN_RUNGS rungs, RKC_SYN_COLS rival columns, 9 versions, 18 milestones ---- 256func rc_write_synthetic(root: *u8, dom: *u8) -> i64 { 257 let cap: i64 = 65536 + RKC_SYN_RUNGS * 512 + RKC_SYN_MS * 512 258 let pb: *u8 = sys_mmap(cap) 259 var o: i64 = 0 260 o = rc_cat(pb, o, "# synthetic plan -- written by nx_compare_rank_caps_gate; every former cap exceeded\n" as *u8) 261 o = rc_cat(pb, o, "pos|synthetic\ngoal|synthetic\nunit|1 u\n" as *u8) 262 var i: i64 = 1 263 while i <= RKC_SYN_RUNGS { 264 // rung|S<i>|title<i>|sym<i>|done-rule|Organ|1|deps (dep: S<i> depends on S<i-1> for i>1 -- a real graph) 265 o = rc_cat(pb, o, "rung|S" as *u8); o = rc_catn(pb, o, i); o = rc_cat(pb, o, "|Synthetic rung " as *u8); o = rc_catn(pb, o, i) 266 o = rc_cat(pb, o, "|sym" as *u8); o = rc_catn(pb, o, i); o = rc_cat(pb, o, "|done when sym" as *u8); o = rc_catn(pb, o, i); o = rc_cat(pb, o, " exists|Organ|1|" as *u8) 267 if i > 1 { o = rc_cat(pb, o, "S" as *u8); o = rc_catn(pb, o, i - 1) } else { o = rc_cat(pb, o, "-" as *u8) } 268 o = rc_cat(pb, o, "\n" as *u8) 269 i = i + 1 270 } 271 // 18 milestones: M1..M9 each hold ONE present rung (S3 for odd, S68 for even) so versions 1..8 are MET; 272 // M9 holds S10 (open) -> the 9th version is the first unmet TARGET; M10..M18 hold open rungs (later) 273 var m: i64 = 1 274 while m <= RKC_SYN_MS { 275 o = rc_cat(pb, o, "ms|M" as *u8); o = rc_catn(pb, o, m); o = rc_cat(pb, o, "|milestone " as *u8); o = rc_catn(pb, o, m); o = rc_cat(pb, o, "|1|" as *u8) 276 if m < 9 { if m % 2 == 1 { o = rc_cat(pb, o, "S3" as *u8) } else { o = rc_cat(pb, o, "S68" as *u8) } } 277 else { o = rc_cat(pb, o, "S" as *u8); o = rc_catn(pb, o, m + 1) } 278 o = rc_cat(pb, o, "\n" as *u8) 279 m = m + 1 280 } 281 var v: i64 = 1 282 while v <= RKC_SYN_VERS { 283 o = rc_cat(pb, o, "ver|v" as *u8); o = rc_catn(pb, o, v); o = rc_cat(pb, o, "|M" as *u8); o = rc_catn(pb, o, v); o = rc_cat(pb, o, "\n" as *u8) 284 v = v + 1 285 } 286 let pp: *u8 = sys_mmap(RKC_PATH) 287 var po: i64 = rc_cat(pp, 0, root); po = rc_cat(pp, po, "/buildroot/knowledge/compare/" as *u8); po = rc_cat(pp, po, dom); po = rc_cat(pp, po, ".plan" as *u8) 288 if rc_write_file(pp, pb, o) < 0 { return 0 - 1 } 289 // matrix: @cols with RKC_SYN_COLS rivals; one row per rung (row i carries sym<i>, present form for the 290 // two the organ defines, _ABSENT_:sym<i> otherwise), EXCEPT rung RKC_SYN_NOROW which gets no row; 291 // plus RKC_SYN_EXTRA_ROWS unrelated rows at the TOP so every rung's row sits past position 9 292 let mb: *u8 = sys_mmap(cap) 293 var mo: i64 = 0 294 mo = rc_cat(mb, mo, "# synthetic matrix -- written by nx_compare_rank_caps_gate\n@title synthetic\n@cols " as *u8) 295 var c: i64 = 1 296 while c <= RKC_SYN_COLS { mo = rc_cat(mb, mo, "R" as *u8); mo = rc_catn(mb, mo, c); if c < RKC_SYN_COLS { mo = rc_cat(mb, mo, "|" as *u8) } c = c + 1 } 297 mo = rc_cat(mb, mo, "\n" as *u8) 298 var x: i64 = 1 299 while x <= RKC_SYN_EXTRA_ROWS { 300 mo = rc_cat(mb, mo, "Noise row " as *u8); mo = rc_catn(mb, mo, x); mo = rc_cat(mb, mo, "|fx/organ.nx|noise" as *u8); mo = rc_catn(mb, mo, x); mo = rc_cat(mb, mo, "|0" as *u8) 301 var cc: i64 = 0 302 while cc < RKC_SYN_COLS { mo = rc_cat(mb, mo, "|1" as *u8); cc = cc + 1 } 303 mo = rc_cat(mb, mo, "|noise\n" as *u8) 304 x = x + 1 305 } 306 i = 1 307 while i <= RKC_SYN_RUNGS { 308 if i != RKC_SYN_NOROW { 309 mo = rc_cat(mb, mo, "Row for sym" as *u8); mo = rc_catn(mb, mo, i); mo = rc_cat(mb, mo, "|fx/organ.nx|" as *u8) 310 var pres: i64 = 0 311 if i == RKC_SYN_PRESENT_A { pres = 1 } 312 if i == RKC_SYN_PRESENT_B { pres = 1 } 313 if pres == 0 { mo = rc_cat(mb, mo, "_ABSENT_:" as *u8) } 314 mo = rc_cat(mb, mo, "sym" as *u8); mo = rc_catn(mb, mo, i); mo = rc_cat(mb, mo, "|0" as *u8) 315 var cc2: i64 = 0 316 while cc2 < RKC_SYN_COLS { if cc2 % 3 == 0 { mo = rc_cat(mb, mo, "|2" as *u8) } else { mo = rc_cat(mb, mo, "|1" as *u8) } cc2 = cc2 + 1 } 317 mo = rc_cat(mb, mo, "|note\n" as *u8) 318 } 319 i = i + 1 320 } 321 let mp: *u8 = sys_mmap(RKC_PATH) 322 var mpo: i64 = rc_cat(mp, 0, root); mpo = rc_cat(mp, mpo, "/buildroot/knowledge/compare/" as *u8); mpo = rc_cat(mp, mpo, dom); mpo = rc_cat(mp, mpo, ".matrix" as *u8) 323 if rc_write_file(mp, mb, mo) < 0 { return 0 - 1 } 324 // the organ: defines sym<A> and sym<B> as top-level funcs (the exact shape rk_measure keys on) 325 let ob: *u8 = sys_mmap(4096) 326 var oo: i64 = rc_cat(ob, 0, "// fx organ written by nx_compare_rank_caps_gate\nfunc sym" as *u8); oo = rc_catn(ob, oo, RKC_SYN_PRESENT_A); oo = rc_cat(ob, oo, "() -> i64 { return 1 }\nfunc sym" as *u8); oo = rc_catn(ob, oo, RKC_SYN_PRESENT_B); oo = rc_cat(ob, oo, "(x: i64) -> i64 { return x }\n" as *u8) 327 let op: *u8 = sys_mmap(RKC_PATH) 328 var opo: i64 = rc_cat(op, 0, root); opo = rc_cat(op, opo, "/buildroot/fx/organ.nx" as *u8) 329 if rc_write_file(op, ob, oo) < 0 { return 0 - 1 } 330 return 0 331} 332 333func rc_mk(root: *u8, sub: *u8) -> i64 { 334 let p: *u8 = sys_mmap(RKC_PATH) 335 var o: i64 = rc_cat(p, 0, root); o = rc_cat(p, o, sub) 336 return sys_mkdir(p, RKC_MODE_X) 337} 338func rc_link(cwd: *u8, real_rel: *u8, root: *u8, link_rel: *u8) -> i64 { 339 let t: *u8 = sys_mmap(RKC_PATH) 340 var o: i64 = rc_cat(t, 0, cwd); o = rc_cat(t, o, "/" as *u8); o = rc_cat(t, o, real_rel) 341 let l: *u8 = sys_mmap(RKC_PATH) 342 var lo: i64 = rc_cat(l, 0, root); lo = rc_cat(l, lo, "/" as *u8); lo = rc_cat(l, lo, link_rel) 343 return sys_symlinkat(t, l) 344} 345func rc_copy_domain(cwd: *u8, root: *u8, dom: *u8) -> i64 { 346 let s1: *u8 = sys_mmap(RKC_PATH) 347 var a: i64 = rc_cat(s1, 0, cwd); a = rc_cat(s1, a, "/buildroot/knowledge/compare/" as *u8); a = rc_cat(s1, a, dom); a = rc_cat(s1, a, ".plan" as *u8) 348 let d1: *u8 = sys_mmap(RKC_PATH) 349 var b: i64 = rc_cat(d1, 0, root); b = rc_cat(d1, b, "/buildroot/knowledge/compare/" as *u8); b = rc_cat(d1, b, dom); b = rc_cat(d1, b, ".plan" as *u8) 350 if rc_copy(s1, d1) < 0 { return 0 - 1 } 351 let s2: *u8 = sys_mmap(RKC_PATH) 352 var a2: i64 = rc_cat(s2, 0, cwd); a2 = rc_cat(s2, a2, "/buildroot/knowledge/compare/" as *u8); a2 = rc_cat(s2, a2, dom); a2 = rc_cat(s2, a2, ".matrix" as *u8) 353 let d2: *u8 = sys_mmap(RKC_PATH) 354 var b2: i64 = rc_cat(d2, 0, root); b2 = rc_cat(d2, b2, "/buildroot/knowledge/compare/" as *u8); b2 = rc_cat(d2, b2, dom); b2 = rc_cat(d2, b2, ".matrix" as *u8) 355 if rc_copy(s2, d2) < 0 { return 0 - 1 } 356 return 0 357} 358 359func main(argc: i64, argv: *i64) -> i64 { 360 let ctr: *i64 = gv_ctr() 361 gv_head("=== nx_compare_rank_caps_gate -- the ranker's population bounds are DERIVED: >64 rungs/rows, >24 fields, >8 versions, >16 milestones all rank; independent counts agree ===" as *u8) 362 let cwd: *u8 = sys_mmap(RKC_PATH) 363 let cl: i64 = sys_getcwd(cwd, RKC_PATH - 1) 364 if cl <= 0 { gv_check("T0 getcwd" as *u8, 0, ctr); let rc0: i64 = gv_verdict("RANK-CAPS" as *u8, ctr, "no cwd" as *u8); sys_exit(rc0); return rc0 } 365 // subject: argv[1] or ./nx_compare_rank.elf, made ABSOLUTE (the fixture chdirs) 366 var subj_in: *u8 = "./nx_compare_rank.elf\x00" 367 if argc >= 2 { subj_in = argv[1] as *u8 } 368 let subject: *u8 = sys_mmap(RKC_PATH) 369 if subj_in[0] == (47 as u8) { rc_cat(subject, 0, subj_in) } else { 370 var so: i64 = rc_cat(subject, 0, cwd); so = rc_cat(subject, so, "/" as *u8) 371 var skip: i64 = 0 372 if subj_in[0] == (46 as u8) { if subj_in[1] == (47 as u8) { skip = 2 } } 373 rc_cat(subject, so, (subj_in as i64 + skip) as *u8) 374 } 375 // fixture root: /tmp/nxrkcap_<pid> (reaped by the tmp beat; nothing is executed FROM it), else _build 376 let pid: i64 = __syscall(172, 0, 0, 0, 0, 0, 0) 377 let root: *u8 = sys_mmap(RKC_PATH) 378 var ro: i64 = rc_cat(root, 0, "/tmp/nxrkcap_" as *u8) 379 ro = rc_catn(root, ro, pid) 380 if sys_mkdir(root, RKC_MODE_X) != 0 { 381 ro = rc_cat(root, 0, cwd); ro = rc_cat(root, ro, "/_build/nxrkcap_" as *u8); ro = rc_catn(root, ro, pid) 382 sys_mkdir(root, RKC_MODE_X) 383 } 384 rc_mk(root, "/buildroot\x00" as *u8) 385 rc_mk(root, "/buildroot/knowledge\x00" as *u8) 386 rc_mk(root, "/buildroot/knowledge/compare\x00" as *u8) 387 rc_mk(root, "/buildroot/fx\x00" as *u8) 388 rc_mk(root, "/knowledge\x00" as *u8) 389 rc_mk(root, "/knowledge/status\x00" as *u8) 390 rc_link(cwd, "buildroot/runtime\x00" as *u8, root, "buildroot/runtime\x00" as *u8) 391 rc_link(cwd, "nx_dr_ocm_cli.elf\x00" as *u8, root, "nx_dr_ocm_cli.elf\x00" as *u8) 392 rc_link(cwd, "nx_store_put.elf\x00" as *u8, root, "nx_store_put.elf\x00" as *u8) 393 rc_link(cwd, "nx_pm_intake.elf\x00" as *u8, root, "nx_pm_intake.elf\x00" as *u8) 394 gv_puts(" fixture_root=" as *u8); gv_puts(root); gv_puts("\n" as *u8) 395 gv_puts(" subject=" as *u8); gv_puts(subject); gv_puts("\n" as *u8) 396 // preconditions: the subject and the ocm ranker must exist (a missing ranker would make every run 397 // "returned nothing" and read as a cap defect) 398 let sfd: i64 = sys_openat_rd(subject) 399 var have_subj: i64 = 0 400 if sfd >= 0 { sys_close(sfd); have_subj = 1 } 401 gv_need("subject binary present" as *u8, have_subj, ctr) 402 let ofd: i64 = sys_openat_rd("nx_dr_ocm_cli.elf\x00" as *u8) 403 var have_ocm: i64 = 0 404 if ofd >= 0 { sys_close(ofd); have_ocm = 1 } 405 gv_need("nx_dr_ocm_cli.elf present in cwd (the ranker fork)" as *u8, have_ocm, ctr) 406 407 let syn: *u8 = "rkcapfx\x00" 408 let wrc: i64 = rc_write_synthetic(root, syn) 409 gv_check("T0 fixture-written (synthetic plan 70 rungs / matrix 78 data rows x 20 rivals / 9 ver / 18 ms)" as *u8, (wrc == 0) as i64, ctr) 410 // copy the real domains in 411 let cb: i64 = rc_copy_domain(cwd, root, "browser\x00" as *u8) 412 let ct: i64 = rc_copy_domain(cwd, root, "toolchain\x00" as *u8) 413 gv_check("T0b real browser+toolchain plan/matrix copied into the fixture" as *u8, ((cb == 0) as i64) * ((ct == 0) as i64), ctr) 414 415 // independent censuses BEFORE running the subject 416 let cens: *i64 = sys_mmap(8 * 8) as *i64 417 let spp: *u8 = sys_mmap(RKC_PATH); var q1: i64 = rc_cat(spp, 0, root); q1 = rc_cat(spp, q1, "/buildroot/knowledge/compare/rkcapfx.plan" as *u8) 418 let smp: *u8 = sys_mmap(RKC_PATH); var q2: i64 = rc_cat(smp, 0, root); q2 = rc_cat(smp, q2, "/buildroot/knowledge/compare/rkcapfx.matrix" as *u8) 419 rc_census(spp, smp, cens) 420 gv_puts(" synthetic census: rungs=" as *u8); gv_num(cens[0]); gv_puts(" matrix_rows=" as *u8); gv_num(cens[1]); gv_puts(" unmapped=" as *u8); gv_num(cens[2]); gv_puts(" ncol=" as *u8); gv_num(cens[3]); gv_puts("\n" as *u8) 421 gv_check("T0c synthetic census reached the condition (rungs=70 rows=78 unmapped=1 ncol=20: every former cap exceeded)" as *u8, ((cens[0] == RKC_SYN_RUNGS) as i64) * ((cens[0] > RKC_FORMER_CAP) as i64) * ((cens[1] == RKC_SYN_RUNGS - 1 + RKC_SYN_EXTRA_ROWS) as i64) * ((cens[1] > RKC_FORMER_CAP) as i64) * ((cens[2] == 1) as i64) * ((cens[3] == RKC_SYN_COLS) as i64), ctr) 422 423 // ---- run the subject on the synthetic domain ---- 424 sys_chdir(root) 425 let out: *u8 = sys_mmap(RKC_CAPTURE) 426 let ol: *i64 = sys_mmap(16) as *i64 427 rc_run_subject(subject, syn, out, ol) 428 gv_check("T1a subject produced output on the synthetic domain (capture not empty, not full)" as *u8, ((ol[0] > 0) as i64) * ((ol[0] < RKC_CAPTURE - 1) as i64), ctr) 429 let r_rungs: i64 = rc_field(out, ol[0], "rungs=" as *u8) 430 let r_done: i64 = rc_field(out, ol[0], "done=" as *u8) 431 let r_open: i64 = rc_field(out, ol[0], "open=" as *u8) 432 let r_mrows: i64 = rc_field(out, ol[0], "matrix_rows=" as *u8) 433 let r_unm: i64 = rc_count(out, ol[0], "UNMAPPED(" as *u8) 434 gv_puts(" synthetic subject: rungs=" as *u8); gv_num(r_rungs); gv_puts(" done=" as *u8); gv_num(r_done); gv_puts(" open=" as *u8); gv_num(r_open); gv_puts(" matrix_rows=" as *u8); gv_num(r_mrows); gv_puts(" UNMAPPED=" as *u8); gv_num(r_unm); gv_puts("\n" as *u8) 435 gv_check("T1 every rung ranked: rungs == plan count (70 > the former 64) and done+open sums" as *u8, ((r_rungs == cens[0]) as i64) * ((r_done + r_open == r_rungs) as i64), ctr) 436 gv_check("T1b matrix_rows printed == independent row count (78 > the former 64)" as *u8, (r_mrows == cens[1]) as i64, ctr) 437 gv_check("T1c done=2: the two present symbols (one PAST the former cap, sym68) are measured present" as *u8, (r_done == 2) as i64, ctr) 438 // T2: the rung at row > 64 is NOT UNMAPPED; exactly the one no-row rung is UNMAPPED 439 gv_check("T2 UNMAPPED count == independent count (exactly the one rung with no row, S66 -- rows past 64 are SEEN)" as *u8, (r_unm == cens[2]) as i64, ctr) 440 // the S66 line itself must carry UNMAPPED, and the S70 line must NOT 441 var s66ok: i64 = 0 442 var s70ok: i64 = 0 443 var li: i64 = 0 444 while li < ol[0] { 445 let le: i64 = rc_eol(out, ol[0], li) 446 let line: *u8 = (out as i64 + li) as *u8 447 let ln: i64 = le - li 448 if rc_count(line, ln, "] S66 priority=" as *u8) == 1 { if rc_count(line, ln, "UNMAPPED(" as *u8) == 1 { s66ok = 1 } } 449 if rc_count(line, ln, "] S70 priority=" as *u8) == 1 { if rc_count(line, ln, "UNMAPPED(" as *u8) == 0 { if rc_count(line, ln, "deficit=" as *u8) == 1 { s70ok = 1 } } } 450 li = le + 1 451 } 452 gv_check("T2b neg-control-no-row-rung-reads-UNMAPPED (S66: the UNMAPPED path still fires, T2 is not vacuous)" as *u8, s66ok, ctr) 453 gv_check("T2c rung S70 (data row #78 of the matrix, past every former cap) carries a measured deficit, not UNMAPPED" as *u8, s70ok, ctr) 454 // T6/T7: wide rows and the long version ladder 455 gv_check("T6 20-rival rows (29 fields > the former 24) parsed: deficit on S70 equals the row's code sum" as *u8, (rc_count(out, ol[0], "] S70 priority=" as *u8) == 1) as i64, ctr) 456 let tgt_v9: i64 = rc_count(out, ol[0], "TARGET VERSION v9 (milestone M9)" as *u8) 457 gv_check("T7 the 9th version (past the former 8-version cap) is the first unmet TARGET; 18 milestones all read" as *u8, (tgt_v9 == 1) as i64, ctr) 458 459 // ---- real browser domain (copied into the fixture) ---- 460 let bpp: *u8 = sys_mmap(RKC_PATH); var q3: i64 = rc_cat(bpp, 0, root); q3 = rc_cat(bpp, q3, "/buildroot/knowledge/compare/browser.plan" as *u8) 461 let bmp: *u8 = sys_mmap(RKC_PATH); var q4: i64 = rc_cat(bmp, 0, root); q4 = rc_cat(bmp, q4, "/buildroot/knowledge/compare/browser.matrix" as *u8) 462 let bc: *i64 = sys_mmap(8 * 8) as *i64 463 rc_census(bpp, bmp, bc) 464 let out2: *u8 = sys_mmap(RKC_CAPTURE) 465 let ol2: *i64 = sys_mmap(16) as *i64 466 rc_run_subject(subject, "browser\x00" as *u8, out2, ol2) 467 let b_rungs: i64 = rc_field(out2, ol2[0], "rungs=" as *u8) 468 let b_done: i64 = rc_field(out2, ol2[0], "done=" as *u8) 469 let b_open: i64 = rc_field(out2, ol2[0], "open=" as *u8) 470 let b_mrows: i64 = rc_field(out2, ol2[0], "matrix_rows=" as *u8) 471 let b_unm: i64 = rc_count(out2, ol2[0], "UNMAPPED(" as *u8) 472 gv_puts(" browser census: rungs=" as *u8); gv_num(bc[0]); gv_puts(" matrix_rows=" as *u8); gv_num(bc[1]); gv_puts(" unmapped=" as *u8); gv_num(bc[2]); gv_puts(" | subject: rungs=" as *u8); gv_num(b_rungs); gv_puts(" done=" as *u8); gv_num(b_done); gv_puts(" open=" as *u8); gv_num(b_open); gv_puts(" matrix_rows=" as *u8); gv_num(b_mrows); gv_puts(" UNMAPPED=" as *u8); gv_num(b_unm); gv_puts("\n" as *u8) 473 gv_check("T3 real browser: rungs == plan rung| count and done+open sums" as *u8, ((b_rungs == bc[0]) as i64) * ((b_done + b_open == b_rungs) as i64) * ((b_rungs > 0) as i64), ctr) 474 gv_check("T3b real browser: matrix_rows == independent data-row count, and that count EXCEEDS the former cap (the rows past 64 are all indexed)" as *u8, ((b_mrows == bc[1]) as i64) * ((bc[1] > RKC_FORMER_CAP) as i64), ctr) 475 gv_check("T3c real browser: UNMAPPED == rungs with no matrix row by independent symbol mapping (no rung with a row reads UNMAPPED)" as *u8, (b_unm == bc[2]) as i64, ctr) 476 477 // ---- real toolchain domain: small (under every former cap) -- determinism + agreement ---- 478 let tpp: *u8 = sys_mmap(RKC_PATH); var q5: i64 = rc_cat(tpp, 0, root); q5 = rc_cat(tpp, q5, "/buildroot/knowledge/compare/toolchain.plan" as *u8) 479 let tmp: *u8 = sys_mmap(RKC_PATH); var q6: i64 = rc_cat(tmp, 0, root); q6 = rc_cat(tmp, q6, "/buildroot/knowledge/compare/toolchain.matrix" as *u8) 480 let tc: *i64 = sys_mmap(8 * 8) as *i64 481 rc_census(tpp, tmp, tc) 482 let out3: *u8 = sys_mmap(RKC_CAPTURE) 483 let ol3: *i64 = sys_mmap(16) as *i64 484 rc_run_subject(subject, "toolchain\x00" as *u8, out3, ol3) 485 let out4: *u8 = sys_mmap(RKC_CAPTURE) 486 let ol4: *i64 = sys_mmap(16) as *i64 487 rc_run_subject(subject, "toolchain\x00" as *u8, out4, ol4) 488 var same34: i64 = 0 489 if ol3[0] == ol4[0] { if ol3[0] > 0 { 490 same34 = 1 491 var k4: i64 = 0 492 while k4 < ol3[0] { if out3[k4] != out4[k4] { same34 = 0; k4 = ol3[0] } k4 = k4 + 1 } 493 } } 494 let t_rungs: i64 = rc_field(out3, ol3[0], "rungs=" as *u8) 495 let t_unm: i64 = rc_count(out3, ol3[0], "UNMAPPED(" as *u8) 496 gv_check("T4 real toolchain (under every former cap): rungs == plan count, UNMAPPED == independent count -- neutral where the cap never bit" as *u8, ((t_rungs == tc[0]) as i64) * ((t_unm == tc[2]) as i64) * ((t_rungs > 0) as i64), ctr) 497 gv_check("T4b deterministic: two runs on the same fixture are byte-identical" as *u8, same34, ctr) 498 499 let rc: i64 = gv_verdict("RANK-CAPS" as *u8, ctr, "derived population bounds" as *u8) 500 sys_exit(rc) 501 return rc 502}