move do_sim and hash_256 to separate module
[nmutil.git] / src / nmutil / test / test_lut.py
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):