Skip to content

Commit

Permalink
Simplifications in mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
tilk committed Nov 18, 2024
1 parent 86a7286 commit d1d631a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
4 changes: 1 addition & 3 deletions test/backend/test_retirement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
21 changes: 10 additions & 11 deletions transactron/testing/method_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())


Expand Down

0 comments on commit d1d631a

Please sign in to comment.