test/coding: use new API
This commit is contained in:
parent
12cd390c0b
commit
4a3a1bc5b0
|
@ -3,11 +3,11 @@ import unittest
|
||||||
from migen import *
|
from migen import *
|
||||||
from migen.genlib.coding import *
|
from migen.genlib.coding import *
|
||||||
|
|
||||||
from migen.test.support import SimCase, SimBench
|
from migen.test.support import SimCase
|
||||||
|
|
||||||
|
|
||||||
class EncCase(SimCase, unittest.TestCase):
|
class EncCase(SimCase, unittest.TestCase):
|
||||||
class TestBench(SimBench):
|
class TestBench(Module):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.submodules.dut = Encoder(8)
|
self.submodules.dut = Encoder(8)
|
||||||
|
|
||||||
|
@ -18,18 +18,20 @@ class EncCase(SimCase, unittest.TestCase):
|
||||||
|
|
||||||
def test_run_sequence(self):
|
def test_run_sequence(self):
|
||||||
seq = list(range(1<<8))
|
seq = list(range(1<<8))
|
||||||
def cb(tb, tbp):
|
def gen():
|
||||||
if seq:
|
for _ in range(256):
|
||||||
tbp.dut.i = seq.pop(0)
|
if seq:
|
||||||
if tbp.dut.n:
|
yield self.tb.dut.i, seq.pop(0)
|
||||||
self.assertNotIn(tbp.dut.i, [1<<i for i in range(8)])
|
if (yield self.tb.dut.n):
|
||||||
else:
|
self.assertNotIn((yield self.tb.dut.i), [1<<i for i in range(8)])
|
||||||
self.assertEqual(tbp.dut.i, 1<<tbp.dut.o)
|
else:
|
||||||
self.run_with(cb, 256)
|
self.assertEqual((yield self.tb.dut.i), 1<<(yield self.tb.dut.o))
|
||||||
|
yield
|
||||||
|
self.run_with(gen())
|
||||||
|
|
||||||
|
|
||||||
class PrioEncCase(SimCase, unittest.TestCase):
|
class PrioEncCase(SimCase, unittest.TestCase):
|
||||||
class TestBench(SimBench):
|
class TestBench(Module):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.submodules.dut = PriorityEncoder(8)
|
self.submodules.dut = PriorityEncoder(8)
|
||||||
|
|
||||||
|
@ -40,22 +42,24 @@ class PrioEncCase(SimCase, unittest.TestCase):
|
||||||
|
|
||||||
def test_run_sequence(self):
|
def test_run_sequence(self):
|
||||||
seq = list(range(1<<8))
|
seq = list(range(1<<8))
|
||||||
def cb(tb, tbp):
|
def gen():
|
||||||
if seq:
|
for _ in range(256):
|
||||||
tbp.dut.i = seq.pop(0)
|
if seq:
|
||||||
i = tbp.dut.i
|
yield self.tb.dut.i, seq.pop(0)
|
||||||
if tbp.dut.n:
|
i = yield self.tb.dut.i
|
||||||
self.assertEqual(i, 0)
|
if (yield self.tb.dut.n):
|
||||||
else:
|
self.assertEqual(i, 0)
|
||||||
o = tbp.dut.o
|
else:
|
||||||
if o > 0:
|
o = yield self.tb.dut.o
|
||||||
self.assertEqual(i & 1<<(o - 1), 0)
|
if o > 0:
|
||||||
self.assertGreaterEqual(i, 1<<o)
|
self.assertEqual(i & 1<<(o - 1), 0)
|
||||||
self.run_with(cb, 256)
|
self.assertGreaterEqual(i, 1<<o)
|
||||||
|
yield
|
||||||
|
self.run_with(gen())
|
||||||
|
|
||||||
|
|
||||||
class DecCase(SimCase, unittest.TestCase):
|
class DecCase(SimCase, unittest.TestCase):
|
||||||
class TestBench(SimBench):
|
class TestBench(Module):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.submodules.dut = Decoder(8)
|
self.submodules.dut = Decoder(8)
|
||||||
|
|
||||||
|
@ -66,22 +70,23 @@ class DecCase(SimCase, unittest.TestCase):
|
||||||
|
|
||||||
def test_run_sequence(self):
|
def test_run_sequence(self):
|
||||||
seq = list(range(8*2))
|
seq = list(range(8*2))
|
||||||
def cb(tb, tbp):
|
def gen():
|
||||||
if seq:
|
for _ in range(256):
|
||||||
i = seq.pop()
|
if seq:
|
||||||
tbp.dut.i = i//2
|
i = seq.pop()
|
||||||
tbp.dut.n = i%2
|
yield self.tb.dut.i, i//2
|
||||||
i = tbp.dut.i
|
yield self.tb.dut.n, i%2
|
||||||
o = tbp.dut.o
|
i = yield self.tb.dut.i
|
||||||
if tbp.dut.n:
|
o = yield self.tb.dut.o
|
||||||
self.assertEqual(o, 0)
|
if (yield self.tb.dut.n):
|
||||||
else:
|
self.assertEqual(o, 0)
|
||||||
self.assertEqual(o, 1<<i)
|
else:
|
||||||
self.run_with(cb, 256)
|
self.assertEqual(o, 1<<i)
|
||||||
|
self.run_with(gen())
|
||||||
|
|
||||||
|
|
||||||
class SmallPrioEncCase(SimCase, unittest.TestCase):
|
class SmallPrioEncCase(SimCase, unittest.TestCase):
|
||||||
class TestBench(SimBench):
|
class TestBench(Module):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.submodules.dut = PriorityEncoder(1)
|
self.submodules.dut = PriorityEncoder(1)
|
||||||
|
|
||||||
|
@ -92,15 +97,17 @@ class SmallPrioEncCase(SimCase, unittest.TestCase):
|
||||||
|
|
||||||
def test_run_sequence(self):
|
def test_run_sequence(self):
|
||||||
seq = list(range(1))
|
seq = list(range(1))
|
||||||
def cb(tb, tbp):
|
def gen():
|
||||||
if seq:
|
for _ in range(5):
|
||||||
tbp.dut.i = seq.pop(0)
|
if seq:
|
||||||
i = tbp.dut.i
|
yield self.tb.dut.i, seq.pop(0)
|
||||||
if tbp.dut.n:
|
i = yield self.tb.dut.i
|
||||||
self.assertEqual(i, 0)
|
if (yield self.tb.dut.n):
|
||||||
else:
|
self.assertEqual(i, 0)
|
||||||
o = tbp.dut.o
|
else:
|
||||||
if o > 0:
|
o = yield self.tb.dut.o
|
||||||
self.assertEqual(i & 1<<(o - 1), 0)
|
if o > 0:
|
||||||
self.assertGreaterEqual(i, 1<<o)
|
self.assertEqual(i & 1<<(o - 1), 0)
|
||||||
self.run_with(cb, 5)
|
self.assertGreaterEqual(i, 1<<o)
|
||||||
|
yield
|
||||||
|
self.run_with(gen())
|
||||||
|
|
Loading…
Reference in New Issue