nx_maint_specs_test.nx source
↩ module page · 85 lines · 3965 B
1// nx_maint_specs_test.nx -- gate for the appliance/HVAC spec catalog.
2//
3// Proves each cataloged asset runs correctly through the SAME thermal kernel
4// from its own spec data -- including the COOL-mode path (fridge/AC) the earlier
5// gates never exercised -- and that real maintenance defects are caught:
6// - fridge runs but won't get cold -> DEGRADED (food safety)
7// - dryer heats slowly (clogged vent) -> DEGRADED (fire hazard)
8// - water heater slow recovery (sediment) -> DEGRADED
9// Unknown class -> load returns 0 (loud, no fabricated spec).
10//
11// expect_exit: 0
12//
13// license_tier: ORIGINAL
14
15import "nx_syscalls_x86_64.nx"
16import "nx_maint_specs.nx"
17import "nx_maint_asset.nx"
18
19func main() -> i64 {
20 let t: *i64 = sys_mmap(128) as *i64
21 let val: *i64 = sys_mmap(128) as *i64
22 let amb: *i64 = sys_mmap(128) as *i64
23 let on: *i64 = sys_mmap(128) as *i64
24 let out: *HvacEff = sys_mmap(128) as *HvacEff
25 let spec: *AssetSpec = sys_mmap(64) as *AssetSpec
26
27 // ===== HVAC furnace spec -> efficient recovery -> EFFICIENT =======
28 if nx_maint_spec_load(NX_MAINT_CLASS_HVAC, spec) != 1 { return 1 }
29 t[0]=0; val[0]=19000; amb[0]=5000; on[0]=1
30 t[1]=600; val[1]=21000; amb[1]=5000; on[1]=1
31 t[2]=660; val[2]=21100; amb[2]=5000; on[2]=0
32 t[3]=1800; val[3]=20300; amb[3]=5000; on[3]=0
33 nx_maint_analyze(spec, t, val, amb, on, 4, out)
34 if out.verdict != NX_HVAC_EFFICIENT { return 10 }
35
36 // ===== Water heater spec: normal recovery EFFICIENT, sediment DEGRADED =
37 if nx_maint_spec_load(NX_MAINT_CLASS_WATER_HEATER, spec) != 1 { return 2 }
38 // field cross-check: real data loaded
39 if spec.target_mC != 49000 { return 20 }
40 if spec.min_resp_mC_per_min != 100 { return 21 }
41 if spec.mode != NX_HVAC_MODE_HEAT { return 22 }
42 t[0]=0; val[0]=45000; amb[0]=20000; on[0]=1
43 t[1]=600; val[1]=46200; amb[1]=20000; on[1]=1
44 t[2]=1200; val[2]=47400; amb[2]=20000; on[2]=1
45 t[3]=1800; val[3]=48600; amb[3]=20000; on[3]=1
46 nx_maint_analyze(spec, t, val, amb, on, 4, out)
47 if out.verdict != NX_HVAC_EFFICIENT { return 23 }
48 // sediment-fouled (60 mC/min) -- same timestamps, slower temperature climb
49 val[0]=45000; val[1]=45600; val[2]=46200; val[3]=46800
50 nx_maint_analyze(spec, t, val, amb, on, 4, out)
51 if out.verdict != NX_HVAC_DEGRADED_CAPACITY { return 24 }
52
53 // ===== Refrigerator spec (COOL mode) ============================
54 if nx_maint_spec_load(NX_MAINT_CLASS_REFRIGERATOR, spec) != 1 { return 3 }
55 if spec.mode != NX_HVAC_MODE_COOL { return 30 }
56 // normal pulldown 8->6 C while running -> EFFICIENT
57 t[0]=0; val[0]=8000; amb[0]=22000; on[0]=1
58 t[1]=900; val[1]=7000; amb[1]=22000; on[1]=1
59 t[2]=1800; val[2]=6000; amb[2]=22000; on[2]=1
60 nx_maint_analyze(spec, t, val, amb, on, 3, out)
61 if out.verdict != NX_HVAC_EFFICIENT { return 31 }
62 if out.resp_mC_per_min != 66 { return 32 }
63 // runs but won't get cold (weak/low charge) -> DEGRADED (food safety)
64 t[0]=0; val[0]=8000; on[0]=1
65 t[1]=1800; val[1]=7700; on[1]=1
66 nx_maint_analyze(spec, t, val, amb, on, 2, out)
67 if out.verdict != NX_HVAC_DEGRADED_CAPACITY { return 33 }
68
69 // ===== Dryer spec: normal heat EFFICIENT, clogged vent DEGRADED ==
70 if nx_maint_spec_load(NX_MAINT_CLASS_DRYER, spec) != 1 { return 4 }
71 t[0]=0; val[0]=20000; amb[0]=22000; on[0]=1
72 t[1]=1200; val[1]=50000; amb[1]=22000; on[1]=1
73 nx_maint_analyze(spec, t, val, amb, on, 2, out)
74 if out.verdict != NX_HVAC_EFFICIENT { return 40 }
75 // clogged lint vent -> slow heat -> DEGRADED (fire-hazard catch)
76 t[0]=0; val[0]=20000; on[0]=1
77 t[1]=1800; val[1]=23000; on[1]=1
78 nx_maint_analyze(spec, t, val, amb, on, 2, out)
79 if out.verdict != NX_HVAC_DEGRADED_CAPACITY { return 41 }
80
81 // ===== Unknown / non-thermal class -> load returns 0 (loud) =====
82 if nx_maint_spec_load(NX_MAINT_CLASS_PUMP, spec) != 0 { return 50 }
83
84 return 0
85}