فهرست منبع

Force cocotb Icarus simulator stop after test completion.

Generated with Devin.
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Codex Resource Selftest 4 ماه پیش
والد
کامیت
74e7782d83
1فایلهای تغییر یافته به همراه10 افزوده شده و 17 حذف شده
  1. 10 17
      tests/cocotb/test_prod2u_door_temp_uart_e2e.py

+ 10 - 17
tests/cocotb/test_prod2u_door_temp_uart_e2e.py

@@ -5,7 +5,9 @@ wire boundary: bytes are serialized as 8N1 bits at 217 system clocks/bit.
 """
 """
 
 
 import cocotb
 import cocotb
-from cocotb.triggers import Event, First, NextTimeStep, ReadOnly, ReadWrite, RisingEdge, SimTimeoutError, Timer, with_timeout
+import cocotb.simulator as simulator
+from cocotb.clock import Clock
+from cocotb.triggers import Event, NextTimeStep, ReadOnly, ReadWrite, RisingEdge, SimTimeoutError, with_timeout
 
 
 
 
 CLKS_PER_BIT = 217
 CLKS_PER_BIT = 217
@@ -101,19 +103,7 @@ async def wait_for_stage(awaitable, timeout_ms: int, stage: str, byte_index: int
         ) from exc
         ) from exc
 
 
 
 
-async def run_clock(dut, stop_event: Event) -> None:
-    while not stop_event.is_set():
-        dut.sys_clk.value = 0
-        await Timer(20, units="ns")
-        if stop_event.is_set():
-            break
-        dut.sys_clk.value = 1
-        await Timer(20, units="ns")
-
-
-def stop_background_task(task, stop_event=None) -> None:
-    if stop_event is not None:
-        stop_event.set()
+def stop_background_task(task) -> None:
     if task is None:
     if task is None:
         return
         return
     if hasattr(task, "cancel"):
     if hasattr(task, "cancel"):
@@ -124,13 +114,12 @@ def stop_background_task(task, stop_event=None) -> None:
 
 
 @cocotb.test()
 @cocotb.test()
 async def test_set_all_get_temperature_over_real_uart(dut):
 async def test_set_all_get_temperature_over_real_uart(dut):
-    clock_stop = Event()
     clock_task = None
     clock_task = None
     observer_task = None
     observer_task = None
     observed = {"x": 0, "y": 0, "overlap": False}
     observed = {"x": 0, "y": 0, "overlap": False}
     motor_completion = Event()
     motor_completion = Event()
     try:
     try:
-        clock_task = cocotb.start_soon(run_clock(dut, clock_stop))
+        clock_task = cocotb.start_soon(Clock(dut.sys_clk, 40, unit="ns").start())
         observer_task = cocotb.start_soon(
         observer_task = cocotb.start_soon(
             observe_motor_steps(dut, observed, motor_completion)
             observe_motor_steps(dut, observed, motor_completion)
         )
         )
@@ -184,4 +173,8 @@ async def test_set_all_get_temperature_over_real_uart(dut):
         assert set(response[4:31]) == {0xFF}
         assert set(response[4:31]) == {0xFF}
     finally:
     finally:
         stop_background_task(observer_task)
         stop_background_task(observer_task)
-        stop_background_task(clock_task, clock_stop)
+        stop_background_task(clock_task)
+        try:
+            simulator.stop_simulator()
+        except Exception:
+            pass