code wiki / _hdl_build / nx_research_pool_admission_t68b.nx

nx_research_pool_admission_t68b.nx source

↩ module page · 78 lines · 4707 B

1// nx_research_pool.nx -- GATE for the engine's folded-in R2+R3 (rf_slot_* semaphore + polite rf_fetch_bank). 2// The bounded-parallel + polite logic now lives IN nx_research_engine, so EVERY researcher inherits it (DRY); 3// this organ is the gate that PROVES it: resource-sized slots, descriptor-owned exclusion, acquire/release, polite fetch. 4// (Was the R2/R3 prototype; superseded once the mechanism was folded into the engine.) 5// license_tier: ORIGINAL expect_exit: 0 6import "nx_research_engine_admission_t68.nx" 7const K_MAGIC_8388608: i64 = 8388608 8 9func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 10func gn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0} 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} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 } 11 12func main() -> i64 { 13 let fixture: *u8 = sys_mmap(512) 14 var o: i64 = rf_scat(fixture, 0, "/tmp/research-pool-t68-" as *u8) 15 let ds: *u8 = sys_mmap(32); var v: i64 = sys_now_realtime_us(); var k: i64 = 0 16 while v > 0 { ds[k] = (48 + (v % 10)) as u8; k = k + 1; v = v / 10 } 17 while k > 0 { k = k - 1; fixture[o] = ds[k]; o = o + 1 } 18 fixture[o] = 0 as u8 19 if sys_mkdir(fixture, 0x1ed) != 0 { return 90 } 20 if sys_chdir(fixture) != 0 { return 91 } 21 gp("fixture=" as *u8); gp(fixture); gp("\n" as *u8) 22 sys_mkdir("knowledge" as *u8, 0x1ed); sys_mkdir("knowledge/status" as *u8, 0x1ed) 23 sys_mkdir("knowledge/fetched" as *u8, 0x1ed); sys_mkdir("knowledge/library" as *u8, 0x1ed) 24 let store: *TrustStore = 0 as *TrustStore 25 let dir: *u8 = "knowledge/status/research_slots" as *u8 26 sys_mkdir(dir, 0x1ed) 27 let n: i64 = rf_nslots() 28 gp("=== nx_research_pool GATE -- engine R2+R3 (polite + bounded-parallel) ===\n" as *u8) 29 gp("free_mb=" as *u8); gn(rf_free_mb()); gp(" concurrency slots N=" as *u8); gn(n); gp("\n" as *u8) 30 var pass: i64 = 0; var total: i64 = 0 31 32 // T1: resource sizing sane (1..MAX) 33 var t1: i64 = 0; if n >= 1 { if n <= RF_MAX_SLOTS { t1 = 1 } } 34 total=total+1; if t1==1 { pass=pass+1; gp(" PASS T1 slots sized 1..MAX\n" as *u8) } else { gp(" FAIL T1\n" as *u8) } 35 36 // T2: descriptor-owned exclusion -- a 2nd lock on the SAME slot must be DENIED (this is what bounds concurrency) 37 let p: *u8 = sys_mmap(512); rf_slotpath(dir, 0, p) 38 let a: i64 = rf_slot_lock(p) 39 let b: i64 = rf_slot_lock(p) 40 var t2: i64 = 0; if a >= 0 { if b == RF_SLOT_BUSY { t2 = 1 } } 41 if a >= 0 { rf_slot_release(dir, 0, a) } 42 if b >= 0 { sys_close(b) } 43 total=total+1; if t2==1 { pass=pass+1; gp(" PASS T2 descriptor-owned slot exclusion (2nd acquire denied)\n" as *u8) } else { gp(" FAIL T2\n" as *u8) } 44 45 // T3: acquire/release roundtrip through the semaphore 46 let idx: *i64 = sys_mmap(16) as *i64 47 let fd: i64 = rf_slot_acquire(dir, n, idx) 48 var t3: i64 = 0 49 if fd >= 0 { 50 let picked: i64 = idx[0] 51 let released: i64 = rf_slot_release(dir, picked, fd) 52 if picked >= 0 { if picked < n { if released == 0 { 53 rf_slotpath(dir, picked, p) 54 let again: i64 = rf_slot_lock(p) 55 if again >= 0 { if rf_slot_release(dir, picked, again) == 0 { t3 = 1 } } 56 } } } 57 } 58 total=total+1; if t3==1 { pass=pass+1; gp(" PASS T3 acquire/release roundtrip (slot " as *u8); gn(idx[0]); gp(")\n" as *u8) } else { gp(" FAIL T3\n" as *u8) } 59 60 // T4: local cached raw through actual bank API; network admission is covered by the engine gate 61 let cap: i64 = K_MAGIC_8388608; let out: *u8 = sys_mmap(cap) 62 rf_save("knowledge/fetched/rp_gate_r6b.raw" as *u8, "<p>local fixture</p>" as *u8, 20) 63 let r: i64 = rf_fetch_bank("" as *u8, "rp_gate_r6b" as *u8, store, out, cap) 64 let checked: *i64 = sys_mmap(16) as *i64 65 let text: *u8 = sys_read_file("knowledge/library/rp_gate_r6b.txt" as *u8, checked) 66 var t4: i64 = 0 67 if r == 1 { if (text as i64) != 0 { if checked[0] == 14 { 68 let expected: *u8 = "local fixture " as *u8 69 var j: i64 = 0; var same: i64 = 1 70 while j < checked[0] { if text[j] != expected[j] { same = 0 } j = j + 1 } 71 if same == 1 { t4 = 1 } 72 } } } 73 total=total+1; if t4==1 { pass=pass+1; gp(" PASS T4 retained local raw fixture -> banked\n" as *u8) } else { gp(" FAIL T4 fetch\n" as *u8) } 74 75 gp("---- nx_research_pool GATE: " as *u8); gn(pass); gp(" / " as *u8); gn(total); gp(" ----\n" as *u8) 76 if pass==total { gp("verdict=GREEN (private slot ownership and local banking validated; network workload not exercised)\n" as *u8); return 0 } 77 gp("verdict=RED\n" as *u8); return 1 78}