Skip to content

Commit

Permalink
Async announcement test (incorrect, but it was like this before)
Browse files Browse the repository at this point in the history
  • Loading branch information
tilk committed Nov 12, 2024
1 parent d068792 commit 4f2c296
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions test/backend/test_annoucement.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
from functools import reduce

from amaranth import *
from amaranth_types.types import TestbenchContext
from transactron.lib import FIFO, AdapterTrans, Adapter, ManyToOneConnectTrans
from coreblocks.backend.annoucement import ResultAnnouncement
from coreblocks.interface.layouts import *
from coreblocks.params import GenParams
from coreblocks.params.configurations import test_core_config
from transactron.testing import TestCaseWithSimulator, TestbenchIO
from transactron.testing import TestCaseWithSimulator, AsyncTestbenchIO


class BackendTestCircuit(Elaboratable):
Expand Down Expand Up @@ -37,7 +38,7 @@ def elaborate(self, platform):
get_results.append(fifo.read)
m.submodules[f"fu_fifo_{i}"] = fifo

fifo_in = TestbenchIO(AdapterTrans(fifo.write))
fifo_in = AsyncTestbenchIO(AdapterTrans(fifo.write))
m.submodules[f"fu_fifo_{i}_in"] = fifo_in
self.fu_fifo_ins.append(fifo_in)

Expand All @@ -49,11 +50,11 @@ def elaborate(self, platform):
)

# Create stubs for interfaces used by result announcement
self.rs_announce_val_tbio = TestbenchIO(Adapter(i=self.lay_rs_write, o=self.lay_rs_write))
self.rs_announce_val_tbio = AsyncTestbenchIO(Adapter(i=self.lay_rs_write, o=self.lay_rs_write))
m.submodules.rs_announce_val_tbio = self.rs_announce_val_tbio
self.rf_announce_val_tbio = TestbenchIO(Adapter(i=self.lay_rf_write, o=self.lay_rf_write))
self.rf_announce_val_tbio = AsyncTestbenchIO(Adapter(i=self.lay_rf_write, o=self.lay_rf_write))
m.submodules.rf_announce_val_tbio = self.rf_announce_val_tbio
self.rob_mark_done_tbio = TestbenchIO(Adapter(i=self.lay_rob_mark_done, o=self.lay_rob_mark_done))
self.rob_mark_done_tbio = AsyncTestbenchIO(Adapter(i=self.lay_rob_mark_done, o=self.lay_rob_mark_done))
m.submodules.rob_mark_done_tbio = self.rob_mark_done_tbio

# Create result announcement
Expand Down Expand Up @@ -104,32 +105,33 @@ def generate_producer(self, i: int):
results to its output FIFO. This records will be next serialized by FUArbiter.
"""

def producer():
async def producer(sim: TestbenchContext):
inputs = self.fu_inputs[i]
for rob_id, result, rp_dst in inputs:
io: TestbenchIO = self.m.fu_fifo_ins[i]
yield from io.call_init(rob_id=rob_id, result=result, rp_dst=rp_dst)
yield from self.random_wait(self.max_wait)
io: AsyncTestbenchIO = self.m.fu_fifo_ins[i]
io.call_init(sim, rob_id=rob_id, result=result, rp_dst=rp_dst)
await self.async_random_wait(sim, self.max_wait)
self.producer_end[i] = True

return producer

def consumer(self):
yield from self.m.rs_announce_val_tbio.enable()
yield from self.m.rob_mark_done_tbio.enable()
async def consumer(self, sim: TestbenchContext):
# TODO: this test doesn't do anything, fix it!
self.m.rs_announce_val_tbio.enable(sim)
self.m.rob_mark_done_tbio.enable(sim)
while reduce(and_, self.producer_end, True):
# All 3 methods (in RF, RS and ROB) need to be enabled for the result
# announcement transaction to take place. We want to have at least one
# method disabled most of the time, so that the transaction is performed
# only when we enable it inside the loop. Otherwise the transaction could
# get executed at any time, particularly when we wouldn't be monitoring it
yield from self.m.rf_announce_val_tbio.enable()
self.m.rf_announce_val_tbio.enable(sim)

rf_result = yield from self.m.rf_announce_val_tbio.method_argument()
rs_result = yield from self.m.rs_announce_val_tbio.method_argument()
rob_result = yield from self.m.rob_mark_done_tbio.method_argument()
rf_result = self.m.rf_announce_val_tbio.get_outputs(sim)
rs_result = self.m.rs_announce_val_tbio.get_outputs(sim)
rob_result = self.m.rob_mark_done_tbio.get_outputs(sim)

yield from self.m.rf_announce_val_tbio.disable()
self.m.rf_announce_val_tbio.disable(sim)

assert rf_result is not None
assert rs_result is not None
Expand All @@ -144,20 +146,20 @@ def consumer(self):
del self.expected_output[t]
else:
self.expected_output[t] -= 1
yield from self.random_wait(self.max_wait)
await self.async_random_wait(sim, self.max_wait)

def test_one_out(self):
self.fu_count = 1
self.initialize()
with self.run_simulation(self.m) as sim:
sim.add_process(self.consumer)
sim.add_testbench(self.consumer)
for i in range(self.fu_count):
sim.add_process(self.generate_producer(i))
sim.add_testbench(self.generate_producer(i))

def test_many_out(self):
self.fu_count = 4
self.initialize()
with self.run_simulation(self.m) as sim:
sim.add_process(self.consumer)
sim.add_testbench(self.consumer)
for i in range(self.fu_count):
sim.add_process(self.generate_producer(i))
sim.add_testbench(self.generate_producer(i))

0 comments on commit 4f2c296

Please sign in to comment.