From 5ccd1799f2cdd9b1b8f2d7017aabc3f071a726c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Fri, 29 Nov 2013 02:20:29 -0700 Subject: [PATCH] genlib/coding, test/test_coding: unittests --- migen/genlib/coding.py | 12 ------ migen/test/test_coding.py | 82 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 12 deletions(-) create mode 100644 migen/test/test_coding.py diff --git a/migen/genlib/coding.py b/migen/genlib/coding.py index ed60e2f3c..94a224ea2 100644 --- a/migen/genlib/coding.py +++ b/migen/genlib/coding.py @@ -37,15 +37,3 @@ class Decoder(Module): class PriorityDecoder(Decoder): pass # same - -def _main(): - from migen.fhdl import verilog - e = Encoder(8) - print(verilog.convert(e, ios={e.i, e.o, e.n})) - pe = PriorityEncoder(8) - print(verilog.convert(pe, ios={pe.i, pe.o, pe.n})) - d = Decoder(8) - print(verilog.convert(d, ios={d.i, d.n, d.o})) - -if __name__ == "__main__": - _main() diff --git a/migen/test/test_coding.py b/migen/test/test_coding.py new file mode 100644 index 000000000..de0980500 --- /dev/null +++ b/migen/test/test_coding.py @@ -0,0 +1,82 @@ +import unittest + +from migen.fhdl.std import * +from migen.genlib.coding import * + +from migen.test.support import SimCase, SimBench + +class EncCase(SimCase): + class TestBench(SimBench): + def __init__(self): + self.submodules.dut = Encoder(8) + + def test_sizes(self): + self.assertEqual(flen(self.tb.dut.i), 8) + self.assertEqual(flen(self.tb.dut.o), 3) + self.assertEqual(flen(self.tb.dut.n), 1) + + def test_run_sequence(self): + seq = list(range(1<<8)) + cur = None + def cb(tb, s): + if seq: + s.wr(tb.dut.i, seq.pop(0)) + i = s.rd(tb.dut.i) + if s.rd(tb.dut.n): + self.assertNotIn(i, [1< 0: + self.assertEqual(i & 1<<(o - 1), 0) + self.assertGreaterEqual(i, 1<