"""
def __init__(self, name=None, reset_less=False, async_reset=False):
if name is None:
- name = tracer.get_var_name()
- if name is None:
- raise ValueError("Clock domain name must be specified explicitly")
+ try:
+ name = tracer.get_var_name()
+ except tracer.NameNotFound:
+ raise ValueError("Clock domain name must be specified explicitly")
if name.startswith("cd_"):
name = name[3:]
self.name = name
--- /dev/null
+from ..fhdl.cd import *
+from .tools import *
+
+
+class ClockDomainCase(FHDLTestCase):
+ def test_name(self):
+ pix = ClockDomain()
+ self.assertEqual(pix.name, "pix")
+ cd_pix = ClockDomain()
+ self.assertEqual(pix.name, "pix")
+ dom = [ClockDomain("foo")][0]
+ self.assertEqual(dom.name, "foo")
+ with self.assertRaises(ValueError,
+ msg="Clock domain name must be specified explicitly"):
+ ClockDomain()
+
+ 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)
-import unittest
+from ..fhdl.ast import *
+from .tools import *
-from nmigen.fhdl.ast import *
-
-class ValueTestCase(unittest.TestCase):
+class ValueTestCase(FHDLTestCase):
def test_wrap(self):
self.assertIsInstance(Value.wrap(0), Const)
self.assertIsInstance(Value.wrap(True), Const)
Const(31)["str"]
-class ConstTestCase(unittest.TestCase):
+class ConstTestCase(FHDLTestCase):
def test_shape(self):
self.assertEqual(Const(0).shape(), (0, False))
self.assertEqual(Const(1).shape(), (1, False))
hash(Const(0))
-class OperatorTestCase(unittest.TestCase):
+class OperatorTestCase(FHDLTestCase):
def test_invert(self):
v = ~Const(0, 4)
self.assertEqual(repr(v), "(~ (const 4'd0))")
hash(Const(0) + Const(0))
-class SliceTestCase(unittest.TestCase):
+class SliceTestCase(FHDLTestCase):
def test_shape(self):
s1 = Const(10)[2]
self.assertEqual(s1.shape(), (1, False))
self.assertEqual(repr(s1), "(slice (const 4'd10) 2:3)")
-class CatTestCase(unittest.TestCase):
+class CatTestCase(FHDLTestCase):
def test_shape(self):
c1 = Cat(Const(10))
self.assertEqual(c1.shape(), (4, False))
self.assertEqual(repr(c1), "(cat (const 4'd10) (const 1'd1))")
-class ReplTestCase(unittest.TestCase):
+class ReplTestCase(FHDLTestCase):
def test_shape(self):
r1 = Repl(Const(10), 3)
self.assertEqual(r1.shape(), (12, False))
self.assertEqual(repr(r1), "(repl (const 4'd10) 3)")
-class SignalTestCase(unittest.TestCase):
+class SignalTestCase(FHDLTestCase):
def test_shape(self):
s1 = Signal()
self.assertEqual(s1.shape(), (1, False))
self.assertEqual(s5.shape(), (4, False))
-class ClockSignalTestCase(unittest.TestCase):
+class ClockSignalTestCase(FHDLTestCase):
def test_domain(self):
s1 = ClockSignal()
self.assertEqual(s1.domain, "sync")
self.assertEqual(repr(s1), "(clk sync)")
-class ResetSignalTestCase(unittest.TestCase):
+class ResetSignalTestCase(FHDLTestCase):
def test_domain(self):
s1 = ResetSignal()
self.assertEqual(s1.domain, "sync")