Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lekcyjna123 authored Apr 15, 2024
1 parent 00302d2 commit a5dc003
Show file tree
Hide file tree
Showing 13 changed files with 2,691 additions and 0 deletions.
Empty file added test/core/__init__.py
Empty file.
447 changes: 447 additions & 0 deletions test/core/test_transactions.py

Large diffs are not rendered by default.

Empty file added test/lib/__init__.py
Empty file.
79 changes: 79 additions & 0 deletions test/lib/test_fifo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from amaranth import *
from amaranth.sim import Settle

from transactron.lib import AdapterTrans, BasicFifo

from transactron.testing import TestCaseWithSimulator, TestbenchIO, data_layout
from collections import deque
from parameterized import parameterized_class
import random


class BasicFifoTestCircuit(Elaboratable):
def __init__(self, depth):
self.depth = depth

def elaborate(self, platform):
m = Module()

m.submodules.fifo = self.fifo = BasicFifo(layout=data_layout(8), depth=self.depth)

m.submodules.fifo_read = self.fifo_read = TestbenchIO(AdapterTrans(self.fifo.read))
m.submodules.fifo_write = self.fifo_write = TestbenchIO(AdapterTrans(self.fifo.write))
m.submodules.fifo_clear = self.fifo_clear = TestbenchIO(AdapterTrans(self.fifo.clear))

return m


@parameterized_class(
("name", "depth"),
[
("notpower", 5),
("power", 4),
],
)
class TestBasicFifo(TestCaseWithSimulator):
depth: int

def test_randomized(self):
fifoc = BasicFifoTestCircuit(depth=self.depth)
expq = deque()

cycles = 256
random.seed(42)

self.done = False

def source():
for _ in range(cycles):
if random.randint(0, 1):
yield # random delay

v = random.randint(0, (2**fifoc.fifo.width) - 1)
yield from fifoc.fifo_write.call(data=v)
expq.appendleft(v)

if random.random() < 0.005:
yield from fifoc.fifo_clear.call()
yield Settle()
expq.clear()

self.done = True

def target():
while not self.done or expq:
if random.randint(0, 1):
yield

yield from fifoc.fifo_read.call_init()
yield

v = yield from fifoc.fifo_read.call_result()
if v is not None:
assert v["data"] == expq.pop()

yield from fifoc.fifo_read.disable()

with self.run_simulation(fifoc) as sim:
sim.add_sync_process(source)
sim.add_sync_process(target)
Loading

0 comments on commit a5dc003

Please sign in to comment.