back.pysim: don't crash when trying to drive a nonexistent domain clock.
authorwhitequark <cz@m-labs.hk>
Fri, 23 Aug 2019 08:37:59 +0000 (08:37 +0000)
committerwhitequark <cz@m-labs.hk>
Fri, 23 Aug 2019 08:37:59 +0000 (08:37 +0000)
nmigen/back/pysim.py
nmigen/test/test_sim.py

index 25189d7f60b688d5b34fc53a0dbfdc3c32176f60..8471b51806ded606ac4a68a774a6be22fba6528f 100644 (file)
@@ -451,6 +451,10 @@ class Simulator:
         for domain_obj in self._domains:
             if not domain_obj.local and domain_obj.name == domain:
                 clk = domain_obj.clk
+                break
+        else:
+            raise ValueError("Domain '{}' is not present in simulation"
+                             .format(domain))
         def clk_process():
             yield Passive()
             yield Delay(phase)
index e7d759dbaccc5b1d002873754787e5c94140fd18..c9cdcb79ec969aae319145805e3ca662642f3e7c 100644 (file)
@@ -413,6 +413,13 @@ class SimulatorIntegrationTestCase(FHDLTestCase):
                     msg="Domain 'sync' already has a clock driving it"):
                 sim.add_clock(1)
 
+    def test_add_clock_wrong(self):
+        m = Module()
+        with self.assertSimulation(m) as sim:
+            with self.assertRaises(ValueError,
+                    msg="Domain 'sync' is not present in simulation"):
+                sim.add_clock(1)
+
     def test_eq_signal_unused_wrong(self):
         self.setUp_lhs_rhs()
         self.s = Signal()