back.pysim: warn if simulation is not run.

This would have prevented 3ea35b85.
This commit is contained in:
whitequark 2018-12-29 15:02:04 +00:00
parent 92a96e1644
commit 849c649259
2 changed files with 16 additions and 0 deletions

View file

@ -1,5 +1,6 @@
import math import math
import inspect import inspect
import warnings
from contextlib import contextmanager from contextlib import contextmanager
from bitarray import bitarray from bitarray import bitarray
from vcd import VCDWriter from vcd import VCDWriter
@ -365,6 +366,8 @@ class Simulator:
self._gtkw_file = gtkw_file self._gtkw_file = gtkw_file
self._traces = traces self._traces = traces
self._run_called = False
while not isinstance(self._fragment, Fragment): while not isinstance(self._fragment, Fragment):
self._fragment = self._fragment.get_fragment(platform=None) self._fragment = self._fragment.get_fragment(platform=None)
@ -755,10 +758,14 @@ class Simulator:
return False return False
def run(self): def run(self):
self._run_called = True
while self.step(): while self.step():
pass pass
def run_until(self, deadline, run_passive=False): def run_until(self, deadline, run_passive=False):
self._run_called = True
while self._timestamp < deadline: while self._timestamp < deadline:
if not self.step(run_passive): if not self.step(run_passive):
return False return False
@ -766,6 +773,9 @@ class Simulator:
return True return True
def __exit__(self, *args): def __exit__(self, *args):
if not self._run_called:
warnings.warn("Simulation created, but not run", UserWarning)
if self._vcd_writer: if self._vcd_writer:
vcd_timestamp = (self._timestamp + self._delta) / self._epsilon vcd_timestamp = (self._timestamp + self._delta) / self._epsilon
self._vcd_writer.close(vcd_timestamp) self._vcd_writer.close(vcd_timestamp)

View file

@ -530,3 +530,9 @@ class SimulatorIntegrationTestCase(FHDLTestCase):
self.assertEqual((yield self.rdport.data), 0x33) self.assertEqual((yield self.rdport.data), 0x33)
sim.add_clock(1e-6) sim.add_clock(1e-6)
sim.add_process(process) sim.add_process(process)
def test_wrong_not_run(self):
with self.assertWarns(UserWarning,
msg="Simulation created, but not run"):
with Simulator(Fragment()) as sim:
pass