test_6400_v1_identification_integration.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. """Identification-profile stimulus lifetime and safety integration."""
  2. from __future__ import annotations
  3. import cocotb
  4. from thermal_6400_uart import (
  5. SET_STIMULUS,
  6. SET_STIMULUS_ACK,
  7. bring_auto,
  8. get_snapshot,
  9. host_transaction,
  10. pulse_tick_1s,
  11. send_bmc_snapshot,
  12. wait_for,
  13. )
  14. def array(snapshot: dict[str, object], name: str) -> list[int]:
  15. value = snapshot[name]
  16. assert isinstance(value, list)
  17. return [int(item) for item in value]
  18. @cocotb.test()
  19. async def test_identification_stimulus_expires_and_safety_preempts(dut):
  20. await bring_auto(dut)
  21. ptc = [20 + (index % 3) for index in range(24)]
  22. front = [20, 30, 40, 50]
  23. rear = [50, 40, 30, 20]
  24. stimulus = bytes([2, *ptc, *front, *rear])
  25. kind, payload = await host_transaction(dut, "rs232", SET_STIMULUS, stimulus)
  26. assert (kind, payload) == (SET_STIMULUS_ACK, b"")
  27. assert int(dut.stimulus_active_mon.value) == 1
  28. old_control_epoch = int(dut.control_epoch_mon.value)
  29. await send_bmc_snapshot(dut, [60] * 24)
  30. await wait_for(
  31. dut,
  32. lambda: int(dut.control_epoch_mon.value) > old_control_epoch,
  33. cycles=1000,
  34. label="stimulus output commit",
  35. )
  36. active = await get_snapshot(dut, "ttl")
  37. assert array(active, "ptc_requested") == ptc
  38. assert array(active, "ptc_applied") == ptc
  39. assert array(active, "front_requested") == front
  40. assert array(active, "front_applied") == front
  41. assert array(active, "rear_requested") == rear
  42. assert array(active, "rear_applied") == rear
  43. await pulse_tick_1s(dut)
  44. assert int(dut.stimulus_active_mon.value) == 1
  45. await pulse_tick_1s(dut)
  46. assert int(dut.stimulus_active_mon.value) == 0
  47. old_control_epoch = int(dut.control_epoch_mon.value)
  48. await send_bmc_snapshot(dut, [60] * 24)
  49. await wait_for(
  50. dut,
  51. lambda: int(dut.control_epoch_mon.value) > old_control_epoch,
  52. cycles=1000,
  53. label="autonomous resume after stimulus expiry",
  54. )
  55. resumed = await get_snapshot(dut, "rs232")
  56. assert resumed["control_state"] == 4
  57. assert array(resumed, "ptc_applied") != ptc
  58. # A fresh stimulus is terminated immediately by the 77 C lane override.
  59. stimulus = bytes([3, *([35] * 24), *([25] * 4), *([45] * 4)])
  60. kind, payload = await host_transaction(dut, "ttl", SET_STIMULUS, stimulus)
  61. assert (kind, payload) == (SET_STIMULUS_ACK, b"")
  62. assert int(dut.stimulus_active_mon.value) == 1
  63. # Per-channel thermal protection has priority over an active stimulus.
  64. old_control_epoch = int(dut.control_epoch_mon.value)
  65. await send_bmc_snapshot(dut, [74, *([60] * 23)])
  66. await wait_for(
  67. dut,
  68. lambda: int(dut.control_epoch_mon.value) > old_control_epoch,
  69. cycles=1000,
  70. label="soft-limit stimulus preemption",
  71. )
  72. soft = await get_snapshot(dut, "rs232")
  73. assert int(dut.stimulus_active_mon.value) == 1
  74. assert array(soft, "ptc_applied")[0] < 35
  75. assert array(soft, "ptc_applied")[1:6] == [35] * 5
  76. assert array(soft, "front_applied")[0] == 80
  77. assert array(soft, "rear_applied")[0] == 80
  78. old_control_epoch = int(dut.control_epoch_mon.value)
  79. await send_bmc_snapshot(dut, [76, *([60] * 23)])
  80. await wait_for(
  81. dut,
  82. lambda: int(dut.control_epoch_mon.value) > old_control_epoch,
  83. cycles=1000,
  84. label="pretrip stimulus preemption",
  85. )
  86. pretrip = await get_snapshot(dut, "ttl")
  87. assert int(dut.stimulus_active_mon.value) == 1
  88. assert array(pretrip, "ptc_applied")[0] == 0
  89. assert array(pretrip, "front_applied")[0] == 80
  90. assert array(pretrip, "rear_applied")[0] == 80
  91. await send_bmc_snapshot(dut, [77, *([60] * 23)])
  92. await wait_for(
  93. dut,
  94. lambda: int(dut.stimulus_active_mon.value) == 0
  95. and bool(int(dut.lane_fault_mask_mon.value) & 1),
  96. cycles=1000,
  97. label="hard-limit stimulus preemption",
  98. )
  99. hard = await get_snapshot(dut, "rs232")
  100. assert array(hard, "ptc_applied")[:6] == [0] * 6
  101. assert array(hard, "front_applied")[0] == 100
  102. assert array(hard, "rear_applied")[0] == 100