| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- """Identification-profile stimulus lifetime and safety integration."""
- from __future__ import annotations
- import cocotb
- from thermal_6400_uart import (
- SET_STIMULUS,
- SET_STIMULUS_ACK,
- bring_auto,
- get_snapshot,
- host_transaction,
- pulse_tick_1s,
- send_bmc_snapshot,
- wait_for,
- )
- def array(snapshot: dict[str, object], name: str) -> list[int]:
- value = snapshot[name]
- assert isinstance(value, list)
- return [int(item) for item in value]
- @cocotb.test()
- async def test_identification_stimulus_expires_and_safety_preempts(dut):
- await bring_auto(dut)
- ptc = [20 + (index % 3) for index in range(24)]
- front = [20, 30, 40, 50]
- rear = [50, 40, 30, 20]
- stimulus = bytes([2, *ptc, *front, *rear])
- kind, payload = await host_transaction(dut, "rs232", SET_STIMULUS, stimulus)
- assert (kind, payload) == (SET_STIMULUS_ACK, b"")
- assert int(dut.stimulus_active_mon.value) == 1
- old_control_epoch = int(dut.control_epoch_mon.value)
- await send_bmc_snapshot(dut, [60] * 24)
- await wait_for(
- dut,
- lambda: int(dut.control_epoch_mon.value) > old_control_epoch,
- cycles=1000,
- label="stimulus output commit",
- )
- active = await get_snapshot(dut, "ttl")
- assert array(active, "ptc_requested") == ptc
- assert array(active, "ptc_applied") == ptc
- assert array(active, "front_requested") == front
- assert array(active, "front_applied") == front
- assert array(active, "rear_requested") == rear
- assert array(active, "rear_applied") == rear
- await pulse_tick_1s(dut)
- assert int(dut.stimulus_active_mon.value) == 1
- await pulse_tick_1s(dut)
- assert int(dut.stimulus_active_mon.value) == 0
- old_control_epoch = int(dut.control_epoch_mon.value)
- await send_bmc_snapshot(dut, [60] * 24)
- await wait_for(
- dut,
- lambda: int(dut.control_epoch_mon.value) > old_control_epoch,
- cycles=1000,
- label="autonomous resume after stimulus expiry",
- )
- resumed = await get_snapshot(dut, "rs232")
- assert resumed["control_state"] == 4
- assert array(resumed, "ptc_applied") != ptc
- # A fresh stimulus is terminated immediately by the 77 C lane override.
- stimulus = bytes([3, *([35] * 24), *([25] * 4), *([45] * 4)])
- kind, payload = await host_transaction(dut, "ttl", SET_STIMULUS, stimulus)
- assert (kind, payload) == (SET_STIMULUS_ACK, b"")
- assert int(dut.stimulus_active_mon.value) == 1
- # Per-channel thermal protection has priority over an active stimulus.
- old_control_epoch = int(dut.control_epoch_mon.value)
- await send_bmc_snapshot(dut, [74, *([60] * 23)])
- await wait_for(
- dut,
- lambda: int(dut.control_epoch_mon.value) > old_control_epoch,
- cycles=1000,
- label="soft-limit stimulus preemption",
- )
- soft = await get_snapshot(dut, "rs232")
- assert int(dut.stimulus_active_mon.value) == 1
- assert array(soft, "ptc_applied")[0] < 35
- assert array(soft, "ptc_applied")[1:6] == [35] * 5
- assert array(soft, "front_applied")[0] == 80
- assert array(soft, "rear_applied")[0] == 80
- old_control_epoch = int(dut.control_epoch_mon.value)
- await send_bmc_snapshot(dut, [76, *([60] * 23)])
- await wait_for(
- dut,
- lambda: int(dut.control_epoch_mon.value) > old_control_epoch,
- cycles=1000,
- label="pretrip stimulus preemption",
- )
- pretrip = await get_snapshot(dut, "ttl")
- assert int(dut.stimulus_active_mon.value) == 1
- assert array(pretrip, "ptc_applied")[0] == 0
- assert array(pretrip, "front_applied")[0] == 80
- assert array(pretrip, "rear_applied")[0] == 80
- await send_bmc_snapshot(dut, [77, *([60] * 23)])
- await wait_for(
- dut,
- lambda: int(dut.stimulus_active_mon.value) == 0
- and bool(int(dut.lane_fault_mask_mon.value) & 1),
- cycles=1000,
- label="hard-limit stimulus preemption",
- )
- hard = await get_snapshot(dut, "rs232")
- assert array(hard, "ptc_applied")[:6] == [0] * 6
- assert array(hard, "front_applied")[0] == 100
- assert array(hard, "rear_applied")[0] == 100
|