nx_vessel_faults_test.nx source
↩ module page · 47 lines · 2097 B
1// nx_vessel_faults_test.nx -- smoke for nx_vessel_faults (H2, fault injection).
2//
3// Proves the device fails SAFE under every injected hardware fault:
4// - NOMINAL regulates to the setpoint band (harness is valid) (1-2)
5// - HEATER-STUCK-ON without the fuse RUNS AWAY past 60 C (fault is real) (3)
6// - HEATER-STUCK-ON with the independent fuse is CONTAINED (4)
7// - SENSOR-STUCK-LOW (controller blind) is still CONTAINED by the fuse (5)
8// - POWER-LOSS never reaches temperature -> batch detectably failed (6)
9// Exit code = failed assertion number; 0 = all pass.
10
11import "nx_syscalls.nx"
12import "nx_ferment_safety.nx"
13import "nx_ferment_thermal.nx"
14import "nx_vessel_thermal.nx"
15import "nx_vessel_io.nx"
16import "nx_vessel_faults.nx"
17
18func main() -> i64 {
19 let env: *NxFermentSafetyEnvelope = nx_ferment_safety_envelope_default(1)
20 let twin: *NxVesselThermal = nx_vessel_thermal_new(16744, 50000, 1000, 20000)
21 let fin: *i64 = (sys_mmap(8)) as *i64
22
23 // --- 1. NOMINAL: regulates to the setpoint band ---
24 nx_vessel_fault_run(env, twin, NX_VFAULT_NONE, 60000, 800, fin)
25 if fin[0] < 39000 { return 1 }
26 if fin[0] > 47000 { return 2 }
27
28 // --- 2. HEATER STUCK ON, NO cutoff: runs away past 60 C (fault is real,
29 // cutoff is necessary) ---
30 let m_nocut: i64 = nx_vessel_fault_run(env, twin, NX_VFAULT_HEATER_STUCK_ON, 0, 800, fin)
31 if m_nocut <= 60000 { return 3 }
32
33 // --- 3. HEATER STUCK ON, WITH the independent fuse: contained ---
34 let m_cut: i64 = nx_vessel_fault_run(env, twin, NX_VFAULT_HEATER_STUCK_ON, 60000, 800, fin)
35 if m_cut >= 61000 { return 4 }
36
37 // --- 4. SENSOR STUCK LOW (controller is blind, commands full heat):
38 // the fuse catches what the controller cannot ---
39 let m_sensor: i64 = nx_vessel_fault_run(env, twin, NX_VFAULT_SENSOR_STUCK_LOW, 60000, 800, fin)
40 if m_sensor >= 61000 { return 5 }
41
42 // --- 5. POWER LOSS: drifts to ambient, never ferments -> flagged ---
43 nx_vessel_fault_run(env, twin, NX_VFAULT_POWER_LOSS, 60000, 800, fin)
44 if fin[0] > 30000 { return 6 }
45
46 return 0
47}