test_6400_v11_nomcu_pid.py 3.5 KB

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