move do_sim and hash_256 to separate module
authorJacob Lifshay <programmerjake@gmail.com>
Fri, 17 Dec 2021 01:37:26 +0000 (17:37 -0800)
committerJacob Lifshay <programmerjake@gmail.com>
Fri, 17 Dec 2021 01:37:26 +0000 (17:37 -0800)
src/nmutil/sim_util.py [new file with mode: 0644]
src/nmutil/test/test_lut.py

diff --git a/src/nmutil/sim_util.py b/src/nmutil/sim_util.py
new file mode 100644 (file)
index 0000000..643c32e
--- /dev/null
@@ -0,0 +1,27 @@
+# SPDX-License-Identifier: LGPL-3-or-later
+# See Notices.txt for copyright information
+
+from contextlib import contextmanager
+from hashlib import sha256
+from nmutil.get_test_path import get_test_path
+from nmigen.sim import Simulator
+
+
+def hash_256(v):
+    return int.from_bytes(
+        sha256(bytes(v, encoding='utf-8')).digest(),
+        byteorder='little'
+    )
+
+
+@contextmanager
+def do_sim(test_case, dut, traces=()):
+    sim = Simulator(dut)
+    path = get_test_path(test_case, "sim_test_out")
+    path.parent.mkdir(parents=True, exist_ok=True)
+    vcd_path = path.with_suffix(".vcd")
+    gtkw_path = path.with_suffix(".gtkw")
+    with sim.write_vcd(vcd_path.open("wt", encoding="utf-8"),
+                       gtkw_path.open("wt", encoding="utf-8"),
+                       traces=traces):
+        yield sim
index 00e3ea411dc802e3aec6ac5ab501fbed52dd873b..b30c4b7c801158e531a9619beead852a9b14d1c6 100644 (file)
@@ -1,35 +1,13 @@
 # SPDX-License-Identifier: LGPL-3-or-later
 # See Notices.txt for copyright information
 
-from contextlib import contextmanager
 import unittest
-from hashlib import sha256
 from nmigen.hdl.ast import AnyConst, Assert, Signal
 from nmigen.hdl.dsl import Module
 from nmutil.formaltest import FHDLTestCase
-from nmutil.get_test_path import get_test_path
 from nmutil.lut import BitwiseMux, BitwiseLut, TreeBitwiseLut
-from nmigen.sim import Simulator, Delay
-
-
-@contextmanager
-def do_sim(test_case, dut, traces=()):
-    sim = Simulator(dut)
-    path = get_test_path(test_case, "sim_test_out")
-    path.parent.mkdir(parents=True, exist_ok=True)
-    vcd_path = path.with_suffix(".vcd")
-    gtkw_path = path.with_suffix(".gtkw")
-    with sim.write_vcd(vcd_path.open("wt", encoding="utf-8"),
-                       gtkw_path.open("wt", encoding="utf-8"),
-                       traces=traces):
-        yield sim
-
-
-def hash_256(v):
-    return int.from_bytes(
-        sha256(bytes(v, encoding='utf-8')).digest(),
-        byteorder='little'
-    )
+from nmigen.sim import Delay
+from nmutil.sim_util import do_sim, hash_256
 
 
 class TestBitwiseMux(FHDLTestCase):