Просмотр исходного кода

update soak to current 6400 contract

root 3 месяцев назад
Родитель
Сommit
7da5289fbf
2 измененных файлов с 69 добавлено и 48 удалено
  1. 68 47
      tests/cocotb/test_6400_v1_soak.py
  2. 1 1
      tools/run_6400_soak.py

+ 68 - 47
tests/cocotb/test_6400_v1_soak.py

@@ -8,23 +8,20 @@ from pathlib import Path
 import random
 
 import cocotb
-from cocotb.triggers import RisingEdge, Timer
+from cocotb.triggers import RisingEdge, Timer, with_timeout
 
 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,
+    ACK_NACK,
+    SET_ALL,
+    SET_PID_TARGET,
     clock_cycles,
     encode_frame,
     get_snapshot,
     host_transaction,
-    initialize,
     pulse_tick_1s,
     send_bmc_snapshot,
     send_uart,
@@ -60,12 +57,24 @@ async def wait_host_idle(dut) -> None:
     )
 
 
-async def set_target(dut, port: str, target: int) -> None:
+async def initialize_current(dut) -> None:
+    dut.host_rs232_rx.value = 1
+    dut.host_ttl_rx.value = 1
+    dut.bmc_rs232_rx.value = 1
+    dut.tick_1s_test.value = 0
+    dut.bmc_epoch_override_enable.value = 0
+    dut.bmc_epoch_override_value.value = 0
+    await with_timeout(RisingEdge(dut.rst_n_mon), 1, "ms")
+    await clock_cycles(dut, 50)
+    assert int(dut.control_state_mon.value) == 0
+
+
+async def set_pid_target(dut, port: str, target: int) -> None:
     try:
-        kind, payload = await host_transaction(dut, port, SET_TARGET, bytes([target]))
+        kind, payload = await host_transaction(dut, port, SET_PID_TARGET, bytes([target]))
     except BaseException:
         cocotb.log.error(
-            "SET_TARGET_TIMEOUT port=%s target=%d locked=%d selected=%d "
+            "SET_PID_TARGET_TIMEOUT port=%s target=%d locked=%d selected=%d "
             "rx_valid=%d rx_error=%d frame_valid=%d frame_ready=%d command_busy=%d "
             "target_commits=%d responses=%d",
             port,
@@ -81,7 +90,12 @@ async def set_target(dut, port: str, target: int) -> None:
             int(dut.host_response_count_mon.value),
         )
         raise
-    assert (kind, payload) == (SET_TARGET_ACK, b"")
+    assert (kind, payload) == (ACK_NACK, bytes((1, SET_PID_TARGET, 0, 0)))
+
+
+async def set_all(dut, port: str, vector: bytes) -> None:
+    kind, payload = await host_transaction(dut, port, SET_ALL, vector)
+    assert (kind, payload) == (ACK_NACK, bytes((1, SET_ALL, 0, 0)))
 
 
 async def send_noise(dut, rng: random.Random) -> None:
@@ -90,7 +104,7 @@ async def send_noise(dut, rng: random.Random) -> None:
     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 = bytearray(encode_frame(SET_PID_TARGET, bytes([rng.randint(55, 70)])))
     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)
@@ -105,28 +119,35 @@ 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):
+        if int(dut.control_state_mon.value) == 2:
             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,
+        and int(dut.control_state_mon.value) == 2,
         cycles=1600,
-        label="soak recovery AUTO",
+        label="soak recovery PID",
     )
 
 
 async def validate_snapshot(dut, port: str, counters: dict[str, int]) -> dict[str, object]:
     await wait_host_idle(dut)
     snapshot = await get_snapshot(dut, port)
-    assert snapshot["control_state"] in range(7)
+    assert snapshot["control_state"] in range(3)
     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"]:
+    lane_faults = int(snapshot["lane_fault_mask"])
+    if lane_faults:
+        for lane in range(4):
+            if lane_faults & (1 << lane):
+                assert values(snapshot, "ptc_applied")[lane * 6 : lane * 6 + 6] == [0] * 6
+                assert values(snapshot, "front_applied")[lane] == 100
+                assert values(snapshot, "rear_applied")[lane] == 100
+    elif 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 values(snapshot, "front_applied") == [20] * 4
+        assert values(snapshot, "rear_applied") == [20] * 4
     assert int(dut.pwm_deadline_miss_mon.value) == 0
     counters["get_snapshot"] += 1
     return snapshot
@@ -140,9 +161,9 @@ async def test_accelerated_randomized_system_soak(dut):
         "invalid": 0,
         "stale": 0,
         "get_snapshot": 0,
-        "set_target": 0,
+        "set_pid_target": 0,
         "repeated_set": 0,
-        "stimulus": 0,
+        "set_all": 0,
         "recovery": 0,
         "epoch_wrap": 0,
         "uart_noise": 0,
@@ -153,9 +174,14 @@ async def test_accelerated_randomized_system_soak(dut):
     }
     dut.reset_test.value = 0
     previous_state = 0
-    await bring_auto(dut)
+    await initialize_current(dut)
+    await pulse_tick_1s(dut, 30)
+    await wait_for(dut, lambda: int(dut.control_state_mon.value) == 2,
+                   cycles=300, label="SAFE watchdog to PID")
+    for _ in range(4):
+        await send_bmc_snapshot(dut, [60] * 24)
 
-    # The soak-only wrapper starts at 0xfffa, so bring_auto's four real BMC
+    # The soak-only wrapper starts at 0xfffa, so the first four real BMC
     # frames leave the active epoch at 0xfffe. Two more frames cross the wrap.
     assert int(dut.bmc_epoch_mon.value) == 0xFFFE
     await send_bmc_snapshot(dut, [60] * 24)
@@ -185,14 +211,12 @@ async def test_accelerated_randomized_system_soak(dut):
             counters["bmc_random"] += 1
         elif action == 1:
             port = "rs232" if iteration & 1 else "ttl"
-            # SET_TARGET accepts only 0 or 20..70. Keep this positive path
-            # entirely legal; invalid-target silent drops are covered by L4.
             target = rng.choice((58, 63, 67, 70))
             await wait_host_idle(dut)
-            await set_target(dut, port, target)
+            await set_pid_target(dut, port, target)
             await wait_host_idle(dut)
-            await set_target(dut, port, target)
-            counters["set_target"] += 2
+            await set_pid_target(dut, port, target)
+            counters["set_pid_target"] += 2
             counters["repeated_set"] += 1
             await recover_safe(dut)
             counters["recovery"] += 1
@@ -209,21 +233,17 @@ async def test_accelerated_randomized_system_soak(dut):
             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)
+            front = [rng.randint(0, 100) for _ in range(4)]
+            rear = [rng.randint(0, 100) for _ in range(4)]
+            vector = bytes([*ptc, *front, *rear])
             await wait_host_idle(dut)
-            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
+            await set_all(dut, "rs232", vector)
+            assert int(dut.control_state_mon.value) == 1
+            snap = await validate_snapshot(dut, "ttl", counters)
+            assert values(snap, "ptc_requested") == ptc
+            assert values(snap, "front_requested") == front
+            assert values(snap, "rear_requested") == rear
+            counters["set_all"] += 1
         elif action == 5:
             await send_noise(dut, rng)
             counters["uart_noise"] += 1
@@ -248,10 +268,11 @@ async def test_accelerated_randomized_system_soak(dut):
                 dut.reset_test.value = 1
                 await clock_cycles(dut, 4)
                 dut.reset_test.value = 0
-                await initialize(dut)
+                await initialize_current(dut)
+                await pulse_tick_1s(dut, 30)
                 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")
+                await wait_for(dut, lambda: int(dut.control_state_mon.value) == 2, cycles=1200, label="PID after reset")
                 counters["reset"] += 1
             else:
                 await validate_snapshot(dut, "rs232", counters)
@@ -260,14 +281,14 @@ async def test_accelerated_randomized_system_soak(dut):
         if state != previous_state:
             counters["state_transitions"] += 1
             previous_state = state
-        assert state in range(7)
+        assert state in range(3)
         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",
+        "bmc_random", "invalid", "stale", "get_snapshot", "set_pid_target",
+        "repeated_set", "set_all", "recovery", "epoch_wrap", "uart_noise",
         "reset", "hard_limit", "state_transitions", "virtual_seconds",
     )
     assert all(counters[name] > 0 for name in required_nonzero), counters

+ 1 - 1
tools/run_6400_soak.py

@@ -62,7 +62,7 @@ def main() -> int:
             hdl_toplevel="prod2u_6400_v1_cocotb_top",
             build_dir=run_root / "build",
             build_args=["-g2012", "-I", str(ROOT)],
-            parameters={"ENABLE_STIMULUS": 1, "BMC_INITIAL_EPOCH": 0xFFFA},
+            parameters={"BMC_INITIAL_EPOCH": 0xFFFA},
             always=True,
         )
         result_path = Path(runner.test(