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.hdl.cd import *
|
|
|
|
|
2019-10-13 12:53:38 -06:00
|
|
|
from .utils import *
|
2018-12-13 02:19:16 -07:00
|
|
|
|
|
|
|
|
2018-12-20 23:07:16 -07:00
|
|
|
class ClockDomainTestCase(FHDLTestCase):
|
2018-12-13 02:19:16 -07:00
|
|
|
def test_name(self):
|
2018-12-13 08:24:55 -07:00
|
|
|
sync = ClockDomain()
|
|
|
|
self.assertEqual(sync.name, "sync")
|
|
|
|
self.assertEqual(sync.clk.name, "clk")
|
|
|
|
self.assertEqual(sync.rst.name, "rst")
|
2019-08-19 14:46:46 -06:00
|
|
|
self.assertEqual(sync.local, False)
|
2018-12-13 02:19:16 -07:00
|
|
|
pix = ClockDomain()
|
|
|
|
self.assertEqual(pix.name, "pix")
|
2018-12-13 08:24:55 -07:00
|
|
|
self.assertEqual(pix.clk.name, "pix_clk")
|
|
|
|
self.assertEqual(pix.rst.name, "pix_rst")
|
2018-12-13 02:19:16 -07:00
|
|
|
cd_pix = ClockDomain()
|
|
|
|
self.assertEqual(pix.name, "pix")
|
|
|
|
dom = [ClockDomain("foo")][0]
|
|
|
|
self.assertEqual(dom.name, "foo")
|
2020-07-28 13:35:25 -06:00
|
|
|
with self.assertRaisesRegex(ValueError,
|
|
|
|
r"^Clock domain name must be specified explicitly$"):
|
2018-12-13 02:19:16 -07:00
|
|
|
ClockDomain()
|
2019-08-19 14:46:46 -06:00
|
|
|
cd_reset = ClockDomain(local=True)
|
|
|
|
self.assertEqual(cd_reset.local, True)
|
2018-12-13 02:19:16 -07:00
|
|
|
|
2019-08-31 16:05:48 -06:00
|
|
|
def test_edge(self):
|
|
|
|
sync = ClockDomain()
|
|
|
|
self.assertEqual(sync.clk_edge, "pos")
|
|
|
|
sync = ClockDomain(clk_edge="pos")
|
|
|
|
self.assertEqual(sync.clk_edge, "pos")
|
|
|
|
sync = ClockDomain(clk_edge="neg")
|
|
|
|
self.assertEqual(sync.clk_edge, "neg")
|
|
|
|
|
|
|
|
def test_edge_wrong(self):
|
2020-07-28 13:35:25 -06:00
|
|
|
with self.assertRaisesRegex(ValueError,
|
|
|
|
r"^Domain clock edge must be one of 'pos' or 'neg', not 'xxx'$"):
|
2019-08-31 16:05:48 -06:00
|
|
|
ClockDomain("sync", clk_edge="xxx")
|
|
|
|
|
2018-12-13 02:19:16 -07:00
|
|
|
def test_with_reset(self):
|
|
|
|
pix = ClockDomain()
|
|
|
|
self.assertIsNotNone(pix.clk)
|
|
|
|
self.assertIsNotNone(pix.rst)
|
|
|
|
self.assertFalse(pix.async_reset)
|
|
|
|
|
|
|
|
def test_without_reset(self):
|
|
|
|
pix = ClockDomain(reset_less=True)
|
|
|
|
self.assertIsNotNone(pix.clk)
|
|
|
|
self.assertIsNone(pix.rst)
|
|
|
|
self.assertFalse(pix.async_reset)
|
|
|
|
|
|
|
|
def test_async_reset(self):
|
|
|
|
pix = ClockDomain(async_reset=True)
|
|
|
|
self.assertIsNotNone(pix.clk)
|
|
|
|
self.assertIsNotNone(pix.rst)
|
|
|
|
self.assertTrue(pix.async_reset)
|
2018-12-13 08:24:55 -07:00
|
|
|
|
|
|
|
def test_rename(self):
|
|
|
|
sync = ClockDomain()
|
|
|
|
self.assertEqual(sync.name, "sync")
|
|
|
|
self.assertEqual(sync.clk.name, "clk")
|
|
|
|
self.assertEqual(sync.rst.name, "rst")
|
|
|
|
sync.rename("pix")
|
|
|
|
self.assertEqual(sync.name, "pix")
|
|
|
|
self.assertEqual(sync.clk.name, "pix_clk")
|
|
|
|
self.assertEqual(sync.rst.name, "pix_rst")
|
2018-12-14 03:56:53 -07:00
|
|
|
|
|
|
|
def test_rename_reset_less(self):
|
|
|
|
sync = ClockDomain(reset_less=True)
|
|
|
|
self.assertEqual(sync.name, "sync")
|
|
|
|
self.assertEqual(sync.clk.name, "clk")
|
|
|
|
sync.rename("pix")
|
|
|
|
self.assertEqual(sync.name, "pix")
|
|
|
|
self.assertEqual(sync.clk.name, "pix_clk")
|
2019-07-08 04:26:49 -06:00
|
|
|
|
|
|
|
def test_wrong_name_comb(self):
|
2020-07-28 13:35:25 -06:00
|
|
|
with self.assertRaisesRegex(ValueError,
|
|
|
|
r"^Domain 'comb' may not be clocked$"):
|
2019-07-08 04:26:49 -06:00
|
|
|
comb = ClockDomain()
|