fhdl.xfrm: add test for ControlInserter with subfragments.
authorwhitequark <cz@m-labs.hk>
Thu, 13 Dec 2018 08:45:10 +0000 (08:45 +0000)
committerwhitequark <cz@m-labs.hk>
Thu, 13 Dec 2018 08:45:10 +0000 (08:45 +0000)
nmigen/test/test_fhdl_xfrm.py

index f7e45ad954858153effa7505f33a88fe32e8e627..b5696013303123930d03d4afa13ba274c887e526 100644 (file)
@@ -142,3 +142,36 @@ class CEInserterTestCase(unittest.TestCase):
             )
         )
         """)
+
+    def test_ce_subfragment(self):
+        f1 = Fragment()
+        f1.add_statements(
+            self.s1.eq(1)
+        )
+        f1.drive(self.s1, "sync")
+
+        f2 = Fragment()
+        f2.add_statements(
+            self.s2.eq(1)
+        )
+        f2.drive(self.s2, "sync")
+        f1.add_subfragment(f2)
+
+        f1 = CEInserter(self.c1)(f1)
+        (f2, _), = f1.subfragments
+        self.assertRepr(f1.statements, """
+        (
+            (eq (sig s1) (const 1'd1))
+            (switch (sig c1)
+                (case 0 (eq (sig s1) (sig s1)))
+            )
+        )
+        """)
+        self.assertRepr(f2.statements, """
+        (
+            (eq (sig s2) (const 1'd1))
+            (switch (sig c1)
+                (case 0 (eq (sig s2) (sig s2)))
+            )
+        )
+        """)