code wiki / (root) / nx_print_runtime_runout_test.nx

nx_print_runtime_runout_test.nx source

↩ module page · 61 lines · 2553 B

1// nx_print_runtime_runout_test.nx -- filament runout edge detection. 2// 3// Closed-form invariants: 4// (a) Steady-0 (filament present): no fire across many steps 5// (b) 0->1 edge: fires exactly once 6// (c) Steady-1 (already triggered): does NOT re-fire 7// (d) 1->0 transition (operator reloaded filament): no fire 8// (e) 0->1 again after reload: fires again 9// (f) Truthy normalization (sensor_triggered = 42 treated as 1) 10// (g) Null monitor returns NONE 11// 12// expect_exit: 0 13// license_tier: ORIGINAL 14 15import "nx_syscalls.nx" 16import "nx_print_runtime_monitor.nx" 17 18const Q14: i64 = 16384 19 20func main() -> i64 { 21 let m: *NxRuntimeMonitor = nx_runtime_monitor_new(5000, 3, 5 * Q14, 2 * Q14) 22 if (m as i64) == 0 { return 5 } 23 24 // ===== (a) Steady-0: no fire ===== 25 if nx_runtime_monitor_step_runout(m, 0) != NX_RT_ISSUE_NONE { return 10 } 26 if nx_runtime_monitor_step_runout(m, 0) != NX_RT_ISSUE_NONE { return 11 } 27 if nx_runtime_monitor_step_runout(m, 0) != NX_RT_ISSUE_NONE { return 12 } 28 if m.n_issues_total != 0 { return 13 } 29 30 // ===== (b) 0->1 edge: fires once ===== 31 let v_fire: i64 = nx_runtime_monitor_step_runout(m, 1) 32 if v_fire != NX_RT_ISSUE_FILAMENT_RUNOUT { return 20 } 33 if m.n_issues_total != 1 { return 21 } 34 if nx_runtime_monitor_last_issue(m) != NX_RT_ISSUE_FILAMENT_RUNOUT { return 22 } 35 36 // ===== (c) Steady-1: does NOT re-fire ===== 37 if nx_runtime_monitor_step_runout(m, 1) != NX_RT_ISSUE_NONE { return 30 } 38 if nx_runtime_monitor_step_runout(m, 1) != NX_RT_ISSUE_NONE { return 31 } 39 if m.n_issues_total != 1 { return 32 } 40 41 // ===== (d) 1->0 transition: no fire (recovery) ===== 42 if nx_runtime_monitor_step_runout(m, 0) != NX_RT_ISSUE_NONE { return 40 } 43 if m.n_issues_total != 1 { return 41 } 44 45 // ===== (e) 0->1 again: fires again ===== 46 let v_fire2: i64 = nx_runtime_monitor_step_runout(m, 1) 47 if v_fire2 != NX_RT_ISSUE_FILAMENT_RUNOUT { return 50 } 48 if m.n_issues_total != 2 { return 51 } 49 50 // ===== (f) Truthy normalization ===== 51 let m2: *NxRuntimeMonitor = nx_runtime_monitor_new(5000, 3, 5 * Q14, 2 * Q14) 52 if nx_runtime_monitor_step_runout(m2, 42) != NX_RT_ISSUE_FILAMENT_RUNOUT { return 60 } 53 // Now last_runout_state == 1; another 42 should NOT re-fire. 54 if nx_runtime_monitor_step_runout(m2, 42) != NX_RT_ISSUE_NONE { return 61 } 55 56 // ===== (g) Null monitor returns NONE ===== 57 let v_null: i64 = nx_runtime_monitor_step_runout(0 as *NxRuntimeMonitor, 1) 58 if v_null != NX_RT_ISSUE_NONE { return 70 } 59 60 return 0 61}