| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- """Unit tests for 6400 V1.1 standalone branch (No-MCU + BMC NET + Adaptive PID)."""
- from __future__ import annotations
- import sys
- from pathlib import Path
- ROOT = Path(__file__).resolve().parents[2]
- if str(ROOT / "tools") not in sys.path:
- sys.path.insert(0, str(ROOT / "tools"))
- import v11_bmc_net as bmc_net
- import v11_adaptive_pid as pid
- import v11_nomcu_gui as v11_gui
- def test_fips197_aes128_and_oem_dimm_parser():
- res = bmc_net.self_test_crypto_and_decoder()
- assert res["aes128_fips197_kat"] == "PASS"
- assert res["oem_dimm_parser"] == "PASS"
- def test_6400_v11_wire_codec_and_diag_format3():
- # Golden 32B standby SET_ALL
- f = v11_gui.encode_frame(0x01, bytes([0] * 24 + [20] * 8))
- assert f[:4] == bytes([0xA5, 0x5A, 0x01, 0x20])
- assert f[-2:] == bytes([0xE7, 0x0A])
- # 83B GET_DATA (BMC=24xFF, CT27 live) + 20B DIAG format=3 board_id=0x61
- get_pl = bytes([10] * 24 + [30] * 4 + [35] * 4 + [0xFF] * 24 + [28 + (i % 5) for i in range(27)])
- diag_pl = bytes([3, 0x61, 3, 3, 0, 0x27, 0x10, 1, 0x49, 1, 0, 0x80, 0x0C, 25, 0xFF, 1, 1, 0, 0, 0x10])
- dec = v11_gui.V11StreamDecoder()
- # Feed byte-by-byte with leading noise
- stream = b"\xAA\xBB\xA5\x00" + v11_gui.encode_frame(0x42, get_pl) + v11_gui.encode_frame(0x52, diag_pl)
- frames = []
- for i in range(0, len(stream), 7):
- frames.extend(dec.feed(stream[i : i + 7]))
- assert len(frames) == 2
- g = v11_gui.decode_v11_get_data(frames[0][1])
- assert g["ptc"] == [10] * 24 and g["front"] == [30] * 4 and g["rear"] == [35] * 4
- assert all(x is None for x in g["bmc_cpld"])
- assert g["ct"][0] == 28.0 and g["ct"][1] == 29.0
- d = v11_gui.decode_v11_diagnostic(frames[1][1])
- assert d["supported"] is True and d["format"] == 3 and d["board_id"] == 0x61
- assert d["firmware_version"] == "3.3.0" and d["duty_bank_valid"] is True
- def test_adaptive_pid_convergence_disturbance_budget_and_dropout():
- res = v11_gui.run_self_test()
- assert res["status"] == "PASS"
- assert res["overall_passed_at_s"] is not None
- assert res["max_overshoot_c"] < 3.0
- assert res["bmc_dropout_ct_fallback"] is True
- for err in res["final_abs_errors_c"].values():
- assert err < 1.2
- def test_bumpless_auto_manual_and_spatial_uniformity_trim():
- cfg = pid.AdaptivePidConfig(uniformity_spread_c=2.0, uniformity_ptc_trim_pct=10.0)
- ctrl = pid.AdaptiveThermalController(cfg)
- ctrl.reset(initial_ptc=[40] * 24, initial_front=[25] * 4, initial_rear=[25] * 4)
- # Manual step
- dimms = [55.0, 56.0, 58.0, 60.0, 62.0, 64.0] * 4 # 9 C spread inside each chamber!
- cts = [50.0] * 27
- out_man = ctrl.step(dt_s=1.0, bmc_dimm_temps_c=dimms, ct_temps_c=cts, bmc_ok=True)
- assert out_man["chambers"][1]["regime"] == "MANUAL"
- # Bumpless engage AUTO: first step must stay smooth (bounded by slew limit)
- ctrl.set_auto_mode(True)
- out_auto = ctrl.step(dt_s=1.0, bmc_dimm_temps_c=dimms, ct_temps_c=cts, bmc_ok=True)
- assert abs(out_auto["chambers"][1]["ptc_cmd"] - 40.0) <= cfg.max_ptc_slew_per_s + 0.1
- # Cooler DIMM0 gets higher PTC duty than hotter DIMM5 in same chamber
- assert out_auto["ptc_24"][0] > out_auto["ptc_24"][5]
- # Below fan_intervention_ref_temp_c (55 C), preheat fan floor stays 20%
- assert out_auto["front_4"][0] == 20
- # Once chamber air reaches 58 C (> 55 C intervention), 9 C DIMM spread triggers mixing fan boost
- out_hot = ctrl.step(dt_s=1.0, bmc_dimm_temps_c=dimms, ct_temps_c=[58.0] * 27, bmc_ok=True)
- assert out_hot["front_4"][0] > 20
|