From d1d631a601a25292f5f2e6572ba1c3b68aa550b7 Mon Sep 17 00:00:00 2001 From: Marek Materzok Date: Mon, 18 Nov 2024 18:58:12 +0100 Subject: [PATCH] Simplifications in mocking --- test/backend/test_retirement.py | 4 +--- transactron/testing/method_mock.py | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/test/backend/test_retirement.py b/test/backend/test_retirement.py index 94d252036..cf039ed13 100644 --- a/test/backend/test_retirement.py +++ b/test/backend/test_retirement.py @@ -129,8 +129,7 @@ def eff(): @def_method_mock(lambda self: self.retc.mock_rob_peek, enable=lambda self: bool(self.submit_q)) def peek_process(self): - if self.submit_q: - return self.submit_q[0] + return self.submit_q[0] async def free_reg_process(self, sim: TestbenchContext): while self.rf_exp_q: @@ -151,7 +150,6 @@ async def rat_process(self, sim: TestbenchContext): assert not self.rf_free_q async def precommit_process(self, sim: TestbenchContext): - await sim.tick() # TODO mocks inactive during first cycle while self.precommit_q: info = await self.retc.precommit_adapter.call_try(sim, rob_id=self.precommit_q[0]) assert info is not None diff --git a/transactron/testing/method_mock.py b/transactron/testing/method_mock.py index 830812aa1..9587ae19f 100644 --- a/transactron/testing/method_mock.py +++ b/transactron/testing/method_mock.py @@ -64,7 +64,9 @@ async def output_process( async def validate_arguments_process(self, sim: SimulatorContext) -> None: assert self.validate_arguments is not None sync = sim._design.lookup_domain("sync", None) # type: ignore - async for *args, clk in sim.changed(*(a for a, _ in self.adapter.validators)).edge(sync.clk, 1): + async for *args, clk, _ in ( + sim.changed(*(a for a, _ in self.adapter.validators)).edge(sync.clk, 1).edge(self.adapter.en, 1) + ): assert len(args) == len(self.adapter.validators) # TODO: remove later if clk: self._freeze = True @@ -74,27 +76,24 @@ async def validate_arguments_process(self, sim: SimulatorContext) -> None: sim.set(r, async_mock_def_helper(self, self.validate_arguments, arg)) async def effect_process(self, sim: SimulatorContext) -> None: + sim.set(self.adapter.en, self.enable()) async for *_, done in sim.tick().sample(self.adapter.done): + # Disabling the method on each cycle forces an edge when it is reenabled again. + # The method body won't be executed until the effects are done. + sim.set(self.adapter.en, False) + # First, perform pending effects, updating internal state. with sim.critical(): if done: for eff in self._effects: eff() - # Ensure that the effects of all mocks are applied - await sim.delay(1e-12) + # Ensure that the effects of all mocks are applied. Delay 0 also does this! await sim.delay(self.delay) - # Next, update combinational signals taking the new state into account. - # In case the input signals get updated later, the other processes will perform the update again. + # Next, enable the method. The output will be updated by a combinational process. self._effects = [] self._freeze = False - if self.validate_arguments is not None: - for a, r in self.adapter.validators: - sim.set(r, async_mock_def_helper(self, self.validate_arguments, sim.get(a))) - with self._context(): - ret = async_mock_def_helper(self, self.function, sim.get(self.adapter.data_out)) - sim.set(self.adapter.data_in, ret) sim.set(self.adapter.en, self.enable())