|
@@ -0,0 +1,237 @@
|
|
|
|
|
+"""L11 accelerated randomized full-top soak with deterministic coverage."""
|
|
|
|
|
+
|
|
|
|
|
+from __future__ import annotations
|
|
|
|
|
+
|
|
|
|
|
+import json
|
|
|
|
|
+import os
|
|
|
|
|
+from pathlib import Path
|
|
|
|
|
+import random
|
|
|
|
|
+
|
|
|
|
|
+import cocotb
|
|
|
|
|
+from cocotb.triggers import RisingEdge, Timer
|
|
|
|
|
+
|
|
|
|
|
+from thermal_6400_uart import (
|
|
|
|
|
+ BMC_CLKS_PER_BIT,
|
|
|
|
|
+ CLOCK_NS,
|
|
|
|
|
+ GET_SNAPSHOT,
|
|
|
|
|
+ HOST_CLKS_PER_BIT,
|
|
|
|
|
+ SET_STIMULUS,
|
|
|
|
|
+ SET_STIMULUS_ACK,
|
|
|
|
|
+ SET_TARGET,
|
|
|
|
|
+ SET_TARGET_ACK,
|
|
|
|
|
+ bring_auto,
|
|
|
|
|
+ clock_cycles,
|
|
|
|
|
+ encode_frame,
|
|
|
|
|
+ get_snapshot,
|
|
|
|
|
+ host_transaction,
|
|
|
|
|
+ initialize,
|
|
|
|
|
+ pulse_tick_1s,
|
|
|
|
|
+ send_bmc_snapshot,
|
|
|
|
|
+ send_uart,
|
|
|
|
|
+ wait_for,
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+SEED = int(os.environ.get("PROD2U_SOAK_SEED", "1677779166"))
|
|
|
|
|
+ITERATIONS = int(os.environ.get("PROD2U_SOAK_ITERATIONS", "96"))
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def values(snapshot: dict[str, object], name: str) -> list[int]:
|
|
|
|
|
+ value = snapshot[name]
|
|
|
|
|
+ assert isinstance(value, list)
|
|
|
|
|
+ return [int(item) for item in value]
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+async def wait_control_epoch(dut, previous: int, label: str) -> None:
|
|
|
|
|
+ await wait_for(
|
|
|
|
|
+ dut,
|
|
|
|
|
+ lambda: int(dut.control_epoch_mon.value) != previous,
|
|
|
|
|
+ cycles=1200,
|
|
|
|
|
+ label=label,
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+async def send_noise(dut, rng: random.Random) -> None:
|
|
|
|
|
+ before_commit = int(dut.target_commit_count_mon.value)
|
|
|
|
|
+ before_response = int(dut.host_response_count_mon.value)
|
|
|
|
|
+ # A bad-CRC target-shaped frame plus arbitrary bytes must not commit or
|
|
|
|
|
+ # produce a response. Let the bounded idle unlock recover the selected port.
|
|
|
|
|
+ corrupt = bytearray(encode_frame(SET_TARGET, bytes([rng.randint(55, 75)])))
|
|
|
|
|
+ corrupt[-1] ^= 0x80
|
|
|
|
|
+ port = "rs232" if rng.randrange(2) == 0 else "ttl"
|
|
|
|
|
+ await send_uart(getattr(dut, f"host_{port}_rx"), corrupt, HOST_CLKS_PER_BIT)
|
|
|
|
|
+ await send_uart(getattr(dut, f"host_{port}_rx"), bytes(rng.randrange(256) for _ in range(5)), HOST_CLKS_PER_BIT)
|
|
|
|
|
+ await clock_cycles(dut, 1400)
|
|
|
|
|
+ assert int(dut.target_commit_count_mon.value) == before_commit
|
|
|
|
|
+ assert int(dut.host_response_count_mon.value) == before_response
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+async def recover_safe(dut) -> None:
|
|
|
|
|
+ for _ in range(4):
|
|
|
|
|
+ previous = int(dut.control_epoch_mon.value)
|
|
|
|
|
+ await send_bmc_snapshot(dut, [60] * 24)
|
|
|
|
|
+ if int(dut.control_state_mon.value) in (4, 5):
|
|
|
|
|
+ await wait_control_epoch(dut, previous, "soak recovery control pass")
|
|
|
|
|
+ await wait_for(
|
|
|
|
|
+ dut,
|
|
|
|
|
+ lambda: int(dut.global_fault_mon.value) == 0
|
|
|
|
|
+ and int(dut.lane_fault_mask_mon.value) == 0
|
|
|
|
|
+ and int(dut.control_state_mon.value) == 4,
|
|
|
|
|
+ cycles=1600,
|
|
|
|
|
+ label="soak recovery AUTO",
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+async def validate_snapshot(dut, port: str, counters: dict[str, int]) -> dict[str, object]:
|
|
|
|
|
+ snapshot = await get_snapshot(dut, port)
|
|
|
|
|
+ assert snapshot["control_state"] in range(7)
|
|
|
|
|
+ for name in ("ptc_requested", "ptc_applied", "front_requested", "front_applied", "rear_requested", "rear_applied"):
|
|
|
|
|
+ assert all(0 <= value <= 100 for value in values(snapshot, name))
|
|
|
|
|
+ if snapshot["global_fault"]:
|
|
|
|
|
+ assert values(snapshot, "ptc_applied") == [0] * 24
|
|
|
|
|
+ assert values(snapshot, "front_applied") == [100] * 4
|
|
|
|
|
+ assert values(snapshot, "rear_applied") == [100] * 4
|
|
|
|
|
+ assert int(dut.pwm_deadline_miss_mon.value) == 0
|
|
|
|
|
+ counters["get_snapshot"] += 1
|
|
|
|
|
+ return snapshot
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+@cocotb.test()
|
|
|
|
|
+async def test_accelerated_randomized_system_soak(dut):
|
|
|
|
|
+ rng = random.Random(SEED)
|
|
|
|
|
+ counters = {
|
|
|
|
|
+ "bmc_random": 0,
|
|
|
|
|
+ "invalid": 0,
|
|
|
|
|
+ "stale": 0,
|
|
|
|
|
+ "get_snapshot": 0,
|
|
|
|
|
+ "set_target": 0,
|
|
|
|
|
+ "repeated_set": 0,
|
|
|
|
|
+ "stimulus": 0,
|
|
|
|
|
+ "recovery": 0,
|
|
|
|
|
+ "epoch_wrap": 0,
|
|
|
|
|
+ "uart_noise": 0,
|
|
|
|
|
+ "reset": 0,
|
|
|
|
|
+ "hard_limit": 0,
|
|
|
|
|
+ "state_transitions": 0,
|
|
|
|
|
+ "virtual_seconds": 0,
|
|
|
|
|
+ }
|
|
|
|
|
+ dut.reset_test.value = 0
|
|
|
|
|
+ previous_state = 0
|
|
|
|
|
+ await bring_auto(dut)
|
|
|
|
|
+
|
|
|
|
|
+ # Exercise the 16-bit acquisition epoch rollover with real BMC UART frames.
|
|
|
|
|
+ dut.u_dut.u_bmc_snapshot.epoch.value = 0xFFFE
|
|
|
|
|
+ await send_bmc_snapshot(dut, [60] * 24)
|
|
|
|
|
+ assert int(dut.bmc_epoch_mon.value) == 0xFFFF
|
|
|
|
|
+ await send_bmc_snapshot(dut, [60] * 24)
|
|
|
|
|
+ assert int(dut.bmc_epoch_mon.value) == 0
|
|
|
|
|
+ counters["epoch_wrap"] += 1
|
|
|
|
|
+
|
|
|
|
|
+ for iteration in range(ITERATIONS):
|
|
|
|
|
+ action = iteration % 8
|
|
|
|
|
+ if action == 0:
|
|
|
|
|
+ temperatures: list[int | None] = [rng.randint(54, 75) for _ in range(24)]
|
|
|
|
|
+ if iteration % 16 == 0:
|
|
|
|
|
+ temperatures[rng.randrange(24)] = None
|
|
|
|
|
+ counters["invalid"] += 1
|
|
|
|
|
+ previous = int(dut.control_epoch_mon.value)
|
|
|
|
|
+ await send_bmc_snapshot(dut, temperatures)
|
|
|
|
|
+ await wait_control_epoch(dut, previous, "random BMC control pass")
|
|
|
|
|
+ counters["bmc_random"] += 1
|
|
|
|
|
+ elif action == 1:
|
|
|
|
|
+ port = "rs232" if iteration & 1 else "ttl"
|
|
|
|
|
+ target = rng.choice((58, 63, 70, 75))
|
|
|
|
|
+ kind, payload = await host_transaction(dut, port, SET_TARGET, bytes([target]))
|
|
|
|
|
+ assert (kind, payload) == (SET_TARGET_ACK, b"")
|
|
|
|
|
+ kind, payload = await host_transaction(dut, port, SET_TARGET, bytes([target]))
|
|
|
|
|
+ assert (kind, payload) == (SET_TARGET_ACK, b"")
|
|
|
|
|
+ counters["set_target"] += 2
|
|
|
|
|
+ counters["repeated_set"] += 1
|
|
|
|
|
+ await recover_safe(dut)
|
|
|
|
|
+ counters["recovery"] += 1
|
|
|
|
|
+ elif action == 2:
|
|
|
|
|
+ await pulse_tick_1s(dut, 3)
|
|
|
|
|
+ counters["virtual_seconds"] += 3
|
|
|
|
|
+ await wait_for(dut, lambda: int(dut.global_fault_mon.value) == 1, cycles=300, label="random stale clamp")
|
|
|
|
|
+ stale = await validate_snapshot(dut, "rs232", counters)
|
|
|
|
|
+ assert values(stale, "ptc_applied") == [0] * 24
|
|
|
|
|
+ counters["stale"] += 1
|
|
|
|
|
+ await recover_safe(dut)
|
|
|
|
|
+ counters["recovery"] += 1
|
|
|
|
|
+ elif action == 3:
|
|
|
|
|
+ await validate_snapshot(dut, "ttl" if iteration & 1 else "rs232", counters)
|
|
|
|
|
+ elif action == 4:
|
|
|
|
|
+ ptc = [rng.randint(0, 45) for _ in range(24)]
|
|
|
|
|
+ front = [rng.randint(20, 70) for _ in range(4)]
|
|
|
|
|
+ rear = [rng.randint(20, 70) for _ in range(4)]
|
|
|
|
|
+ duration = rng.randint(1, 3)
|
|
|
|
|
+ kind, payload = await host_transaction(
|
|
|
|
|
+ dut, "rs232", SET_STIMULUS, bytes([duration, *ptc, *front, *rear])
|
|
|
|
|
+ )
|
|
|
|
|
+ assert (kind, payload) == (SET_STIMULUS_ACK, b"")
|
|
|
|
|
+ previous = int(dut.control_epoch_mon.value)
|
|
|
|
|
+ await send_bmc_snapshot(dut, [60] * 24)
|
|
|
|
|
+ await wait_control_epoch(dut, previous, "stimulus commit")
|
|
|
|
|
+ await pulse_tick_1s(dut, duration)
|
|
|
|
|
+ counters["virtual_seconds"] += duration
|
|
|
|
|
+ assert int(dut.stimulus_active_mon.value) == 0
|
|
|
|
|
+ counters["stimulus"] += 1
|
|
|
|
|
+ elif action == 5:
|
|
|
|
|
+ await send_noise(dut, rng)
|
|
|
|
|
+ counters["uart_noise"] += 1
|
|
|
|
|
+ elif action == 6:
|
|
|
|
|
+ lane = rng.randrange(4)
|
|
|
|
|
+ temperatures = [60] * 24
|
|
|
|
|
+ temperatures[lane * 6 + rng.randrange(6)] = 77
|
|
|
|
|
+ previous = int(dut.control_epoch_mon.value)
|
|
|
|
|
+ await send_bmc_snapshot(dut, temperatures)
|
|
|
|
|
+ await wait_control_epoch(dut, previous, "hard-limit control pass")
|
|
|
|
|
+ assert int(dut.lane_fault_mask_mon.value) & (1 << lane)
|
|
|
|
|
+ snap = await validate_snapshot(dut, "ttl", counters)
|
|
|
|
|
+ assert values(snap, "ptc_applied")[lane * 6 : lane * 6 + 6] == [0] * 6
|
|
|
|
|
+ assert values(snap, "front_applied")[lane] == 100
|
|
|
|
|
+ assert values(snap, "rear_applied")[lane] == 100
|
|
|
|
|
+ counters["hard_limit"] += 1
|
|
|
|
|
+ await recover_safe(dut)
|
|
|
|
|
+ counters["recovery"] += 1
|
|
|
|
|
+ else:
|
|
|
|
|
+ # Two deterministic mid-run global resets/reconfigurations.
|
|
|
|
|
+ if iteration in (31, 63):
|
|
|
|
|
+ dut.reset_test.value = 1
|
|
|
|
|
+ await clock_cycles(dut, 4)
|
|
|
|
|
+ dut.reset_test.value = 0
|
|
|
|
|
+ await initialize(dut)
|
|
|
|
|
+ for _ in range(4):
|
|
|
|
|
+ await send_bmc_snapshot(dut, [60] * 24)
|
|
|
|
|
+ await wait_for(dut, lambda: int(dut.control_state_mon.value) == 4, cycles=1200, label="AUTO after reset")
|
|
|
|
|
+ counters["reset"] += 1
|
|
|
|
|
+ else:
|
|
|
|
|
+ await validate_snapshot(dut, "rs232", counters)
|
|
|
|
|
+
|
|
|
|
|
+ state = int(dut.control_state_mon.value)
|
|
|
|
|
+ if state != previous_state:
|
|
|
|
|
+ counters["state_transitions"] += 1
|
|
|
|
|
+ previous_state = state
|
|
|
|
|
+ assert state in range(7)
|
|
|
|
|
+ assert int(dut.pwm_deadline_miss_mon.value) == 0
|
|
|
|
|
+
|
|
|
|
|
+ final_snapshot = await validate_snapshot(dut, "ttl", counters)
|
|
|
|
|
+ assert final_snapshot["control_epoch"] >= 1
|
|
|
|
|
+ required_nonzero = (
|
|
|
|
|
+ "bmc_random", "invalid", "stale", "get_snapshot", "set_target",
|
|
|
|
|
+ "repeated_set", "stimulus", "recovery", "epoch_wrap", "uart_noise",
|
|
|
|
|
+ "reset", "hard_limit", "state_transitions", "virtual_seconds",
|
|
|
|
|
+ )
|
|
|
|
|
+ assert all(counters[name] > 0 for name in required_nonzero), counters
|
|
|
|
|
+ result = {
|
|
|
|
|
+ "schema": "prod2u-6400-soak-result-v1",
|
|
|
|
|
+ "seed": SEED,
|
|
|
|
|
+ "iterations": ITERATIONS,
|
|
|
|
|
+ "counters": counters,
|
|
|
|
|
+ "final_control_epoch": int(final_snapshot["control_epoch"]),
|
|
|
|
|
+ "final_bmc_epoch": int(final_snapshot["bmc_epoch"]),
|
|
|
|
|
+ "status": "PASS",
|
|
|
|
|
+ }
|
|
|
|
|
+ result_path = Path(os.environ["PROD2U_SOAK_RESULT"])
|
|
|
|
|
+ result_path.write_text(json.dumps(result, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
|
|
|
+ cocotb.log.info("L11_SOAK_PASS %s", json.dumps(result, sort_keys=True))
|