litex/migen/test/test_fifo.py

36 lines
996 B
Python
Raw Normal View History

import unittest
from migen.fhdl.std import *
2014-01-26 16:19:43 -05:00
from migen.genlib.fifo import SyncFIFO
from migen.test.support import SimCase, SimBench
class SyncFIFOCase(SimCase, unittest.TestCase):
class TestBench(SimBench):
def __init__(self):
self.submodules.dut = SyncFIFO([("a", 32), ("b", 32)], 2)
self.sync += [
If(self.dut.we & self.dut.writable,
self.dut.din.a.eq(self.dut.din.a + 1),
self.dut.din.b.eq(self.dut.din.b + 2)
)
]
def test_sizes(self):
self.assertEqual(flen(self.tb.dut.din_bits), 64)
self.assertEqual(flen(self.tb.dut.dout_bits), 64)
def test_run_sequence(self):
seq = list(range(20))
2014-01-26 16:19:43 -05:00
def cb(tb, tbp):
# fire re and we at "random"
2014-01-26 16:19:43 -05:00
tbp.dut.we = tbp.simulator.cycle_counter % 2 == 0
tbp.dut.re = tbp.simulator.cycle_counter % 3 == 0
# the output if valid must be correct
2014-01-26 16:19:43 -05:00
if tbp.dut.readable and tbp.dut.re:
i = seq.pop(0)
2014-01-26 16:19:43 -05:00
self.assertEqual(tbp.dut.dout.a, i)
self.assertEqual(tbp.dut.dout.b, i*2)
self.run_with(cb, 20)