2018-12-18 11:05:37 -07:00
|
|
|
import unittest
|
|
|
|
|
tests: move out of the main package.
Compared to tests in the repository root, tests in the package have
many downsides:
* Unless explicitly excluded in find_packages(), tests and their
support code effectively become a part of public API.
This, unfortunately, happened with FHDLTestCase, which was never
intended for downstream use.
* Even if explicitly excluded from the setuptools package, using
an editable install, or setting PYTHONPATH still allows accessing
the tests.
* Having a sub-package that is present in the source tree but not
exported (or, worse, exported only sometimes) is confusing.
* The name `nmigen.test` cannot be used for anything else, such as
testing utilities that *are* intended for downstream use.
2020-08-26 18:33:31 -06:00
|
|
|
from nmigen.compat import *
|
|
|
|
|
2018-12-18 11:05:37 -07:00
|
|
|
from .support import SimCase
|
|
|
|
|
|
|
|
|
|
|
|
class ConstantCase(SimCase, unittest.TestCase):
|
|
|
|
class TestBench(Module):
|
|
|
|
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),
|
|
|
|
(Signal(4), Constant(0b1100)[::-1], 0b0011),
|
|
|
|
]
|
|
|
|
self.comb += [a.eq(b) for a, b, c in self.sigs]
|
|
|
|
|
|
|
|
def test_comparisons(self):
|
|
|
|
def gen():
|
|
|
|
for s, l, v in self.tb.sigs:
|
|
|
|
s = yield s
|
|
|
|
self.assertEqual(
|
|
|
|
s, int(v),
|
|
|
|
"got {}, want {} from literal {}".format(
|
|
|
|
s, v, l))
|
|
|
|
self.run_with(gen())
|