2015-09-06 19:51:59 -04:00
|
|
|
import unittest
|
|
|
|
|
2015-09-16 23:08:40 -04:00
|
|
|
from migen import *
|
|
|
|
from migen.test.support import SimCase
|
2015-09-06 19:51:59 -04:00
|
|
|
|
|
|
|
|
|
|
|
class ConstantCase(SimCase, unittest.TestCase):
|
2015-09-16 23:08:40 -04:00
|
|
|
class TestBench(Module):
|
2015-09-06 19:51:59 -04:00
|
|
|
def __init__(self):
|
|
|
|
self.sigs = [
|
|
|
|
(Signal(3), Constant(0), 0),
|
|
|
|
(Signal(3), Constant(5), 5),
|
|
|
|
(Signal(3), Constant(1, 2), 1),
|
|
|
|
(Signal(3), Constant(-1, 7), 7),
|
|
|
|
(Signal(3), Constant(0b10101)[:3], 0b101),
|
|
|
|
(Signal(3), Constant(0b10101)[1:4], 0b10),
|
2015-09-17 02:38:55 -04:00
|
|
|
(Signal(4), Constant(0b1100)[::-1], 0b0011),
|
2015-09-06 19:51:59 -04:00
|
|
|
]
|
|
|
|
self.comb += [a.eq(b) for a, b, c in self.sigs]
|
|
|
|
|
|
|
|
def test_comparisons(self):
|
2015-09-16 23:08:40 -04:00
|
|
|
def gen():
|
|
|
|
for s, l, v in self.tb.sigs:
|
|
|
|
s = yield s
|
2015-09-06 19:51:59 -04:00
|
|
|
self.assertEqual(
|
|
|
|
s, int(v),
|
|
|
|
"got {}, want {} from literal {}".format(
|
|
|
|
s, v, l))
|
2015-09-16 23:08:40 -04:00
|
|
|
self.run_with(gen())
|