code wiki / (root) / nx_fluid_seal_test.nx

nx_fluid_seal_test.nx source

↩ module page · 84 lines · 3347 B

1// nx_fluid_seal_test.nx -- gate for the fluid/seal-integrity kernel (#4). 2// 3// Proves the seepage->leak->rapid-loss progression from pressure-decay, the 4// flow-while-isolated leak catch (a holding system that still leaks), and the 5// liar-kill: decay tracks the data (SEALED at decay 1 vs LEAK at decay 300 on 6// identical timestamps). 7// 8// expect_exit: 0 9// 10// license_tier: ORIGINAL 11 12import "nx_syscalls_x86_64.nx" 13import "nx_fluid_seal.nx" 14 15func main() -> i64 { 16 if nx_fluid_verdict_is_valid(NX_FLUID_RAPID_LOSS) != 1 { return 1 } 17 if nx_fluid_verdict_is_valid(NX_FLUID_N) != 0 { return 2 } 18 if nx_fluid_verdict_is_valid(-1) != 0 { return 3 } 19 20 let p: *i64 = sys_mmap(128) as *i64 21 let t: *i64 = sys_mmap(128) as *i64 22 let out: *FluidEff = sys_mmap(64) as *FluidEff 23 let spec: *FluidSpec = sys_mmap(64) as *FluidSpec 24 spec.test_pressure_min = 5000 25 spec.seep_decay_per_min = 50 26 spec.leak_decay_per_min = 200 27 spec.rapid_decay_per_min = 1000 28 29 // ===== SEALED: holds pressure ================================== 30 p[0]=6000; p[1]=5980; t[0]=0; t[1]=600 31 nx_fluid_analyze(p, t, 2, 0, spec, out) 32 if out.verdict != NX_FLUID_SEALED { return 10 } 33 if out.decay_per_min != 2 { return 11 } 34 35 // ===== SEEPAGE: small elevated decay =========================== 36 p[0]=6000; p[1]=5300; t[0]=0; t[1]=600 37 nx_fluid_analyze(p, t, 2, 0, spec, out) 38 if out.verdict != NX_FLUID_SEEPAGE { return 20 } 39 40 // ===== LEAK: clear decay ======================================= 41 p[0]=6000; p[1]=3000; t[0]=0; t[1]=600 42 nx_fluid_analyze(p, t, 2, 0, spec, out) 43 if out.verdict != NX_FLUID_LEAK { return 30 } 44 45 // ===== RAPID_LOSS: burst / wide-open =========================== 46 p[0]=6000; p[1]=1000; t[0]=0; t[1]=60 47 nx_fluid_analyze(p, t, 2, 0, spec, out) 48 if out.verdict != NX_FLUID_RAPID_LOSS { return 40 } 49 50 // ===== NO_PRESSURE: never reached test pressure ================ 51 p[0]=3000; p[1]=2900; t[0]=0; t[1]=600 52 nx_fluid_analyze(p, t, 2, 0, spec, out) 53 if out.verdict != NX_FLUID_NO_PRESSURE { return 50 } 54 55 // ===== FLOW-WHILE-ISOLATED: holds pressure but still leaks ====== 56 // The hidden slab-leak: decay looks SEALED, but flow is detected. 57 p[0]=6000; p[1]=5990; t[0]=0; t[1]=600 58 nx_fluid_analyze(p, t, 2, 5, spec, out) 59 if out.verdict != NX_FLUID_LEAK { return 60 } 60 61 // ===== INSUFFICIENT_DATA: one sample ============================ 62 p[0]=6000; t[0]=0 63 nx_fluid_analyze(p, t, 1, 0, spec, out) 64 if out.verdict != NX_FLUID_INSUFFICIENT_DATA { return 70 } 65 66 // ===== BAD_ARG: negative flow =================================== 67 p[0]=6000; p[1]=5990; t[0]=0; t[1]=600 68 nx_fluid_analyze(p, t, 2, 0 - 1, spec, out) 69 if out.verdict != NX_FLUID_BAD_ARG { return 80 } 70 71 // ===== LIAR-KILL: decay tracks the data ========================= 72 p[0]=6000; p[1]=5990; t[0]=0; t[1]=600 73 nx_fluid_analyze(p, t, 2, 0, spec, out) 74 if out.verdict != NX_FLUID_SEALED { return 90 } 75 let sealed_decay: i64 = out.decay_per_min 76 let sealed_verdict: i64 = out.verdict 77 p[0]=6000; p[1]=3000; t[0]=0; t[1]=600 78 nx_fluid_analyze(p, t, 2, 0, spec, out) 79 if out.verdict != NX_FLUID_LEAK { return 91 } 80 if out.decay_per_min == sealed_decay { return 92 } 81 if out.verdict == sealed_verdict { return 93 } 82 83 return 0 84}