|
|
@@ -3,15 +3,18 @@
|
|
|
from __future__ import annotations
|
|
|
|
|
|
import cocotb
|
|
|
-from cocotb.triggers import Timer, with_timeout
|
|
|
+from cocotb.triggers import ReadOnly, RisingEdge, Timer, with_timeout
|
|
|
|
|
|
from thermal_6400_uart import (
|
|
|
BMC_CLKS_PER_BIT,
|
|
|
CLOCK_NS,
|
|
|
+ GET_SNAPSHOT,
|
|
|
+ GET_SNAPSHOT_ACK,
|
|
|
HOST_CLKS_PER_BIT,
|
|
|
SET_STIMULUS,
|
|
|
SET_TARGET,
|
|
|
SET_TARGET_ACK,
|
|
|
+ SNAPSHOT_DATA,
|
|
|
bring_auto,
|
|
|
check_pwm_timing,
|
|
|
encode_frame,
|
|
|
@@ -34,7 +37,53 @@ def duties(snapshot: dict[str, object], name: str) -> list[int]:
|
|
|
@cocotb.test()
|
|
|
async def test_control_dual_host_sensor_safety_and_snapshot(dut):
|
|
|
pwm_timing = cocotb.start_soon(check_pwm_timing(dut))
|
|
|
- await bring_auto(dut)
|
|
|
+ await bring_auto(dut, verify_boot=True)
|
|
|
+
|
|
|
+ # GET is one locked two-frame transaction. Traffic on the alternate Host
|
|
|
+ # after ACK must not change port_sel, unlock snapshot banks, or commit a
|
|
|
+ # command before the 0x42 DATA frame's final physical stop bit retires.
|
|
|
+ get_state = {"ack": False, "done": False}
|
|
|
+
|
|
|
+ async def receive_locked_get() -> tuple[int, bytes]:
|
|
|
+ ack = await receive_frame(dut.host_ttl_tx)
|
|
|
+ assert ack == (GET_SNAPSHOT_ACK, b"")
|
|
|
+ get_state["ack"] = True
|
|
|
+ data = await receive_frame(dut.host_ttl_tx)
|
|
|
+ get_state["done"] = True
|
|
|
+ return data
|
|
|
+
|
|
|
+ target_before_locked_get = int(dut.current_target_mon.value)
|
|
|
+ get_task = cocotb.start_soon(receive_locked_get())
|
|
|
+ await send_uart(dut.host_ttl_rx, encode_frame(GET_SNAPSHOT), HOST_CLKS_PER_BIT)
|
|
|
+ while not get_state["ack"]:
|
|
|
+ await RisingEdge(dut.sys_clk)
|
|
|
+ assert int(dut.host_locked_mon.value) == 1
|
|
|
+ assert int(dut.host_port_sel_mon.value) == 1
|
|
|
+ assert int(dut.u_dut.snapshot_locked.value) == 1
|
|
|
+ alternate = cocotb.start_soon(
|
|
|
+ send_uart(dut.host_rs232_rx, encode_frame(SET_TARGET, b"\x46"), HOST_CLKS_PER_BIT)
|
|
|
+ )
|
|
|
+ while not get_state["done"]:
|
|
|
+ await RisingEdge(dut.sys_clk)
|
|
|
+ await ReadOnly()
|
|
|
+ assert int(dut.host_locked_mon.value) == 1
|
|
|
+ assert int(dut.host_port_sel_mon.value) == 1
|
|
|
+ assert int(dut.u_dut.snapshot_locked.value) == 1
|
|
|
+ data_kind, data_payload = await with_timeout(get_task, 5, "ms")
|
|
|
+ assert data_kind == SNAPSHOT_DATA and len(data_payload) == 193
|
|
|
+ # receive_frame completes at the center of the final stop bit; lock must
|
|
|
+ # still be present until uart_tx byte_done at the end of that stop bit.
|
|
|
+ assert int(dut.host_locked_mon.value) == 1
|
|
|
+ assert int(dut.u_dut.snapshot_locked.value) == 1
|
|
|
+ await alternate
|
|
|
+ await wait_for(
|
|
|
+ dut,
|
|
|
+ lambda: int(dut.host_locked_mon.value) == 0
|
|
|
+ and int(dut.u_dut.snapshot_locked.value) == 0,
|
|
|
+ cycles=100,
|
|
|
+ label="GET final-stop unlock",
|
|
|
+ )
|
|
|
+ assert int(dut.current_target_mon.value) == target_before_locked_get
|
|
|
|
|
|
# Production must silently reject the identification-only command.
|
|
|
rejected_payload = bytes([2, *([20] * 32)])
|
|
|
@@ -149,6 +198,39 @@ async def test_control_dual_host_sensor_safety_and_snapshot(dut):
|
|
|
assert duties(hard, "front_applied")[0] == 100
|
|
|
assert duties(hard, "rear_applied")[0] == 100
|
|
|
|
|
|
+ # Repeating a legal target while the lane hard fault is active must ACK
|
|
|
+ # but cannot reduce its applied airflow or its physical connector request.
|
|
|
+ old_control_epoch = int(dut.control_epoch_mon.value)
|
|
|
+ kind, payload = await host_transaction(dut, "rs232", SET_TARGET, b"\x41")
|
|
|
+ assert (kind, payload) == (SET_TARGET_ACK, b"")
|
|
|
+ await wait_for(
|
|
|
+ dut,
|
|
|
+ lambda: int(dut.control_epoch_mon.value) > old_control_epoch,
|
|
|
+ cycles=1000,
|
|
|
+ label="hard-fault repeated target safe commit",
|
|
|
+ )
|
|
|
+ hard_after_target = await get_snapshot(dut, "ttl")
|
|
|
+ assert int(hard_after_target["lane_fault_mask"]) & 1
|
|
|
+ assert duties(hard_after_target, "front_applied")[0] == 100
|
|
|
+ assert duties(hard_after_target, "rear_applied")[0] == 100
|
|
|
+ for _ in range(2):
|
|
|
+ await wait_for(dut, lambda: int(dut.pwm_boundary_mon.value) == 1,
|
|
|
+ cycles=600, label="hard-fault physical fan boundary")
|
|
|
+ await Timer(CLOCK_NS, units="ns")
|
|
|
+ assert not (int(dut.front_fan_pwm_out.value) & 0x1)
|
|
|
+ assert int(dut.rear_fan_pwm_out.value) & 0x1
|
|
|
+
|
|
|
+ # Requalify acquisition while retaining the hot lane, so the stale test
|
|
|
+ # below starts from an admitted runtime state rather than startup gating.
|
|
|
+ for _ in range(4):
|
|
|
+ await send_bmc_snapshot(dut, [77, *([60] * 23)])
|
|
|
+ await wait_for(
|
|
|
+ dut,
|
|
|
+ lambda: int(dut.control_state_mon.value) == 5,
|
|
|
+ cycles=1000,
|
|
|
+ label="hard-fault runtime requalification",
|
|
|
+ )
|
|
|
+
|
|
|
# Three explicit age ticks without a new BMC epoch create global stale.
|
|
|
await pulse_tick_1s(dut, 3)
|
|
|
await wait_for(
|
|
|
@@ -163,6 +245,28 @@ async def test_control_dual_host_sensor_safety_and_snapshot(dut):
|
|
|
assert duties(stale, "front_applied") == [100] * 4
|
|
|
assert duties(stale, "rear_applied") == [100] * 4
|
|
|
|
|
|
+ # A legal target during global stale also ACKs without weakening the
|
|
|
+ # already-applied all-fan safety request.
|
|
|
+ old_control_epoch = int(dut.control_epoch_mon.value)
|
|
|
+ kind, payload = await host_transaction(dut, "ttl", SET_TARGET, b"\x41")
|
|
|
+ assert (kind, payload) == (SET_TARGET_ACK, b"")
|
|
|
+ await wait_for(
|
|
|
+ dut,
|
|
|
+ lambda: int(dut.control_epoch_mon.value) > old_control_epoch,
|
|
|
+ cycles=1000,
|
|
|
+ label="stale target safe commit",
|
|
|
+ )
|
|
|
+ stale_after_target = await get_snapshot(dut, "rs232")
|
|
|
+ assert stale_after_target["global_fault"] == 1
|
|
|
+ assert duties(stale_after_target, "front_applied") == [100] * 4
|
|
|
+ assert duties(stale_after_target, "rear_applied") == [100] * 4
|
|
|
+ for _ in range(2):
|
|
|
+ await wait_for(dut, lambda: int(dut.pwm_boundary_mon.value) == 1,
|
|
|
+ cycles=600, label="stale physical fan boundary")
|
|
|
+ await Timer(CLOCK_NS, units="ns")
|
|
|
+ assert int(dut.front_fan_pwm_out.value) == 0x0
|
|
|
+ assert int(dut.rear_fan_pwm_out.value) == 0xF
|
|
|
+
|
|
|
# Three complete safe epochs retain the clamp through the release commit;
|
|
|
# the following epoch resumes only the normal slew-limited ramp.
|
|
|
for _ in range(3):
|