From 239859d95b449bcda2a68e711e2438086e7386c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Boczar?= Date: Thu, 12 Mar 2020 17:04:22 +0100 Subject: [PATCH] test: add tests for _LiteDRAMPatternGenerator --- test/test_bist.py | 160 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 158 insertions(+), 2 deletions(-) diff --git a/test/test_bist.py b/test/test_bist.py index 372fa8e..0fdf1cf 100644 --- a/test/test_bist.py +++ b/test/test_bist.py @@ -11,8 +11,8 @@ from litex.soc.interconnect.stream import * from litedram.common import * from litedram.frontend.bist import * -from litedram.frontend.bist import _LiteDRAMBISTGenerator -from litedram.frontend.bist import _LiteDRAMBISTChecker +from litedram.frontend.bist import _LiteDRAMBISTGenerator, _LiteDRAMBISTChecker, \ + _LiteDRAMPatternGenerator, _LiteDRAMPatternChecker from test.common import * @@ -166,6 +166,162 @@ class TestBIST(unittest.TestCase): mem_expected[4:4+8] = list(range(16, 24)) self.assertEqual(dut.mem.mem, mem_expected) + def pattern_generator_test(self, pattern, mem_expected, data_width, mem_depth): + class DUT(Module): + def __init__(self, init): + self.write_port = LiteDRAMNativeWritePort(address_width=32, data_width=data_width) + self.submodules.generator = _LiteDRAMPatternGenerator(self.write_port, init=init) + self.mem = DRAMMemory(data_width, mem_depth) + + def main_generator(dut): + generator = GenCheckDriver(dut.generator) + + yield from generator.reset() + yield from generator.run() + yield + + dut = DUT(init=pattern) + + generators = [ + main_generator(dut), + dut.mem.write_handler(dut.write_port), + ] + run_simulation(dut, generators, vcd_name='/tmp/sim.vcd') + + assert len(mem_expected) == mem_depth + self.assertEqual(dut.mem.mem, mem_expected) + + def test_pattern_generator_8bit(self): + pattern = [ + # address, data + (0x00, 0xaa), + (0x05, 0xbb), + (0x02, 0xcc), + (0x07, 0xdd), + ] + expected = [ + # data, address + 0xaa, # 0x00 + 0x00, # 0x01 + 0xcc, # 0x02 + 0x00, # 0x03 + 0x00, # 0x04 + 0xbb, # 0x05 + 0x00, # 0x06 + 0xdd, # 0x07 + ] + self.pattern_generator_test(pattern, expected, data_width=8, mem_depth=8) + + def test_pattern_generator_64bit(self): + pattern = [ + # address, data + (0x00, 0x0ddf00dbadc0ffee), + (0x05, 0xabadcafebaadf00d), + (0x02, 0xcafefeedfeedface), + (0x07, 0xdeadc0debaadbeef), + ] + expected = [ + # data, address + 0x0ddf00dbadc0ffee, # 0x00 + 0x0000000000000000, # 0x08 + 0xcafefeedfeedface, # 0x10 + 0x0000000000000000, # 0x18 + 0x0000000000000000, # 0x20 + 0xabadcafebaadf00d, # 0x28 + 0x0000000000000000, # 0x30 + 0xdeadc0debaadbeef, # 0x38 + ] + self.pattern_generator_test(pattern, expected, data_width=64, mem_depth=8) + + def test_pattern_generator_aligned(self): + pattern = [ + # address, data + (0x00, 0xabadcafe), + (0x07, 0xbaadf00d), + (0x02, 0xcafefeed), + (0x01, 0xdeadc0de), + ] + expected = [ + # data, address + 0xabadcafe, # 0x00 + 0xdeadc0de, # 0x04 + 0xcafefeed, # 0x08 + 0x00000000, # 0x0c + 0x00000000, # 0x10 + 0x00000000, # 0x14 + 0x00000000, # 0x18 + 0xbaadf00d, # 0x1c + ] + self.pattern_generator_test(pattern, expected, data_width=32, mem_depth=8) + + def test_pattern_generator_not_aligned(self): + pattern = [ + # address, data + (0x00, 0xabadcafe), + (0x07, 0xbaadf00d), + (0x02, 0xcafefeed), + (0x01, 0xdeadc0de), + ] + expected = [ + # data, address + 0xabadcafe, # 0x00 + 0xdeadc0de, # 0x04 + 0xcafefeed, # 0x08 + 0x00000000, # 0x0c + 0x00000000, # 0x10 + 0x00000000, # 0x14 + 0x00000000, # 0x18 + 0xbaadf00d, # 0x1c + ] + self.pattern_generator_test(pattern, expected, data_width=32, mem_depth=8) + + def test_pattern_generator_overwriting(self): + pattern = [ + # address, data + (0x00, 0xabadcafe), + (0x07, 0xbaadf00d), + (0x00, 0xcafefeed), + (0x07, 0xdeadc0de), + ] + expected = [ + # data, address + 0xcafefeed, # 0x00 + 0x00000000, # 0x04 + 0x00000000, # 0x08 + 0x00000000, # 0x0c + 0x00000000, # 0x10 + 0x00000000, # 0x14 + 0x00000000, # 0x18 + 0xdeadc0de, # 0x1c + ] + self.pattern_generator_test(pattern, expected, data_width=32, mem_depth=8) + + def test_pattern_generator_sequential(self): + length = 64 + prng = random.Random(42) + address = [a for a in range(length)] + data = prng.choices(range(2**32 - 1), k=length) + pattern = list(zip(address, data)) + + expected = [0x00000000] * 128 + for adr, data in pattern: + expected[adr] = data + + self.pattern_generator_test(pattern, expected, data_width=32, mem_depth=128) + + def test_pattern_generator_random(self): + length = 64 + prng = random.Random(42) + address = [a for a in prng.sample(range(128), k=length)] + data = prng.choices(range(2**32 - 1), k=length) + pattern = list(zip(address, data)) + + expected = [0x00000000] * 128 + for adr, data in pattern: + expected[adr] = data + + self.pattern_generator_test(pattern, expected, data_width=32, mem_depth=128) + def test_bist(self): class DUT(Module): def __init__(self):