From d967c208f8d9e0ced09b47e823cb4c6c91f55008 Mon Sep 17 00:00:00 2001 From: Lenny Truong Date: Mon, 9 Jan 2023 13:45:49 -0800 Subject: [PATCH 01/10] [Config] Add flags to debug mode --- magma/circuit.py | 4 ++-- magma/config.py | 13 +++++++++++++ magma/debug.py | 4 ++-- tests/test_config.py | 11 +++++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 tests/test_config.py diff --git a/magma/circuit.py b/magma/circuit.py index c01f826b1..ef2ac9b37 100644 --- a/magma/circuit.py +++ b/magma/circuit.py @@ -27,7 +27,7 @@ pass from magma.clock import is_clock_or_nested_clock, Clock, ClockTypes -from magma.config import get_debug_mode, set_debug_mode, config, RuntimeConfig +from magma.config import get_debug_mode, set_debug_mode, config, DebugConfig from magma.definition_context import ( DefinitionContext, definition_context_manager, @@ -63,7 +63,7 @@ _logger = root_logger() -config.register(use_namer_dict=RuntimeConfig(False)) +config.register(use_namer_dict=DebugConfig(False)) class _SyntaxStyle(enum.Enum): diff --git a/magma/config.py b/magma/config.py index 9a5963d14..cffa21fde 100644 --- a/magma/config.py +++ b/magma/config.py @@ -55,8 +55,13 @@ def reset(self, default=None): self.set(value) +class DebugConfig(RuntimeConfig): + pass + + class ConfigManager: __entries = {} + __debug_entries = [] def __init__(self, **kwargs): self._register(**kwargs) @@ -66,6 +71,8 @@ def _register(self, **kwargs): if key in ConfigManager.__entries: raise RuntimeError(f"Config with key '{key}' already exists") ConfigManager.__entries[key] = value + if isinstance(value, DebugConfig): + ConfigManager.__debug_entries.append(key) def register(self, **kwargs): self._register(**kwargs) @@ -73,7 +80,13 @@ def register(self, **kwargs): def __get(self, key): return ConfigManager.__entries[key].get() + def __set_debug_mode(self, value): + for key in self.__debug_entries: + self.__set(key, value) + def __set(self, key, value): + if key == "debug_mode": + self.__set_debug_mode(value) ConfigManager.__entries[key].set(value) def __getattr__(self, key): diff --git a/magma/debug.py b/magma/debug.py index 5525ed4c8..bdd0e9d21 100644 --- a/magma/debug.py +++ b/magma/debug.py @@ -2,7 +2,7 @@ import uinspect import collections -from magma.config import config, RuntimeConfig +from magma.config import config, DebugConfig @dataclass @@ -15,7 +15,7 @@ class _DebugInfo: debug_info = _DebugInfo -config.register(use_uinspect=RuntimeConfig(True)) +config.register(use_uinspect=DebugConfig(True)) def get_debug_info(frames_to_skip): diff --git a/tests/test_config.py b/tests/test_config.py new file mode 100644 index 000000000..f293f7680 --- /dev/null +++ b/tests/test_config.py @@ -0,0 +1,11 @@ +import magma as m + + +def test_config_debug(): + def _check(val: bool): + m.config.config.debug_mode = val + for field in ["use_uinspect", "use_namer_dict", "debug_mode"]: + assert getattr(m.config.config, field) is val + + for val in [True, False]: + _check(val) From e1e09bb51e6b75549937e94b54c99028f78941f1 Mon Sep 17 00:00:00 2001 From: Lenny Truong Date: Mon, 9 Jan 2023 14:07:17 -0800 Subject: [PATCH 02/10] Reset default mode for other tests --- tests/test_config.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_config.py b/tests/test_config.py index f293f7680..e90a02082 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -9,3 +9,6 @@ def _check(val: bool): for val in [True, False]: _check(val) + + # Reset default + m.config.config.use_uinspect = True From 0497cc9e0ec511c321d42379247f6cc81d0e6e0d Mon Sep 17 00:00:00 2001 From: Lenny Truong Date: Mon, 9 Jan 2023 14:32:52 -0800 Subject: [PATCH 03/10] Update default logic --- magma/logging.py | 2 ++ tests/test_circuit/test_debug_circuit.py | 2 ++ tests/test_circuit/test_define.py | 3 ++ .../test_old_io_syntax_define.py | 3 ++ tests/test_dot/test_dot.py | 1 + tests/test_simulator/test_mdb.py | 35 +++++++++--------- tests/test_type/test_type_errors.py | 24 ++++++------- tests/test_wire/test_errors.py | 36 +++++++++---------- tests/test_wire/test_unwire.py | 2 -- 9 files changed, 59 insertions(+), 49 deletions(-) diff --git a/magma/logging.py b/magma/logging.py index 031e4d75d..97e4a2ba7 100644 --- a/magma/logging.py +++ b/magma/logging.py @@ -35,6 +35,8 @@ def _get_source_line(filename, lineno): def _attach_debug_info(msg, debug_info): file = debug_info.filename + if file is None: + return msg line = debug_info.lineno line_info = _make_bold(f"{make_relative(file)}:{line}") msg = f"{line_info}: {msg}" diff --git a/tests/test_circuit/test_debug_circuit.py b/tests/test_circuit/test_debug_circuit.py index 59178bc03..6625b8fa5 100644 --- a/tests/test_circuit/test_debug_circuit.py +++ b/tests/test_circuit/test_debug_circuit.py @@ -9,6 +9,7 @@ class Foo(m.DebugCircuit): io = m.IO(I=m.In(m.Bit)) assert m.config.get_debug_mode() is False + m.config.config.use_uinspect = True def test_debug_generator(): @@ -21,3 +22,4 @@ def __init__(self, n: int): Foo(4) assert m.config.get_debug_mode() is False + m.config.config.use_uinspect = True diff --git a/tests/test_circuit/test_define.py b/tests/test_circuit/test_define.py index 3af6e1c0c..3f938c00d 100644 --- a/tests/test_circuit/test_define.py +++ b/tests/test_circuit/test_define.py @@ -43,6 +43,7 @@ class Main(m.Circuit): m.compile("build/test_simple_def_class", Main, output=target) m.set_codegen_debug_info(False) m.config.set_debug_mode(False) + m.config.config.use_uinspect = True assert check_files_equal(__file__, f"build/test_simple_def_class.{suffix}", f"gold/test_simple_def_class.{suffix}") @@ -73,6 +74,7 @@ class main(m.Circuit): m.compile("build/test_for_loop_def", main, output=target) m.set_codegen_debug_info(False) m.config.set_debug_mode(False) + m.config.config.use_uinspect = True assert check_files_equal(__file__, f"build/test_for_loop_def.{suffix}", f"gold/test_for_loop_def.{suffix}") @@ -103,6 +105,7 @@ class main(m.Circuit): m.compile("build/test_interleaved_instance_wiring", main, output=target) m.set_codegen_debug_info(False) m.config.set_debug_mode(False) + m.config.config.use_uinspect = True assert check_files_equal(__file__, f"build/test_interleaved_instance_wiring.{suffix}", f"gold/test_interleaved_instance_wiring.{suffix}") diff --git a/tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py b/tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py index 0d4634df1..2d791ce3d 100644 --- a/tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py +++ b/tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py @@ -49,6 +49,7 @@ def definition(io): m.compile("build/test_simple_def_class", Main, output=target) m.set_codegen_debug_info(False) m.config.set_debug_mode(False) + m.config.config.use_uinspect = True assert check_files_equal(__file__, f"build/test_simple_def_class.{suffix}", f"gold/test_simple_def_class.{suffix}") @@ -82,6 +83,7 @@ def test_for_loop_def(target, suffix): m.compile("build/test_for_loop_def", main, output=target) m.set_codegen_debug_info(False) m.config.set_debug_mode(False) + m.config.config.use_uinspect = True assert check_files_equal(__file__, f"build/test_for_loop_def.{suffix}", f"gold/test_for_loop_def.{suffix}") @@ -115,6 +117,7 @@ def test_interleaved_instance_wiring(target, suffix): m.compile("build/test_interleaved_instance_wiring", main, output=target) m.set_codegen_debug_info(False) m.config.set_debug_mode(False) + m.config.config.use_uinspect = True assert check_files_equal(__file__, f"build/test_interleaved_instance_wiring.{suffix}", f"gold/test_interleaved_instance_wiring.{suffix}") diff --git a/tests/test_dot/test_dot.py b/tests/test_dot/test_dot.py index e32a10c36..837f391bb 100644 --- a/tests/test_dot/test_dot.py +++ b/tests/test_dot/test_dot.py @@ -16,6 +16,7 @@ class main(Circuit): compile("build/dot", main, output='dot') m.config.set_debug_mode(False) + m.config.config.use_namer_dict = True # reset default # FIXME: Do equality check. # Let's not check for equality / check in gold until we've finalized this format. # assert magma_check_files_equal(__file__, "build/dot.dot", "gold/dot.dot") diff --git a/tests/test_simulator/test_mdb.py b/tests/test_simulator/test_mdb.py index 55f5d2e41..1500c3a3c 100644 --- a/tests/test_simulator/test_mdb.py +++ b/tests/test_simulator/test_mdb.py @@ -16,7 +16,7 @@ def get_out(capsys): def FFs(n): return [PRIM_FF() for i in range(n)] - + def Register(n): args = ["I", In(Array[n, Bit]), "O", Out(Array[n, Bit])] + ClockInterface(False, False, False) @@ -26,23 +26,23 @@ class RegCircuit(m.Circuit): ffs = join(FFs(n)) wire(io.I, ffs.D) wire(ffs.Q, io.O) - + return RegCircuit() - + def IncOne(n): def sim_inc_one(self, value_store, state_store): I = value_store.get_value(self.I) n = len(I) val = seq2int(I) + 1 - + cout = val > ((1 << n) - 1) val = val % (1 << n) - + seq = int2seq(val, len(I)) seq = [bool(s) for s in seq] value_store.set_value(self.O, seq) value_store.set_value(self.COUT, cout) - + args = ["I", In(Array[n, Bit]), "O", Out(Array[n, Bit]), "COUT", Out(Bit)] class _Circuit(Circuit): name = 'IncOne' + str(n) @@ -52,36 +52,36 @@ class _Circuit(Circuit): simulate = sim_inc_one return _Circuit() - + def TestCounter(n): args = [] - + args += ["O", Array[n, Out(Bit)]] args += ["COUT", Out(Bit)] - + args += ClockInterface(False, False, False) - + class Counter(m.Circuit): name = 'Counter' + str(n) io = m.IO(**dict(zip(args[::2], args[1::2]))) - + inc = IncOne(n) reg = Register(n) reg.name = "reg" - + wire(reg.O, inc.I) wire(inc.O, reg.I) wire(reg.O, io.O) - + wire(inc.COUT, io.COUT) - + drive_undriven_other_clock_types_in_inst(Counter, Counter.reg) - + return Counter() - + args = ['O', Array[5, Out(Bit)], 'COUT', Out(Bit)] args += ClockInterface(False, False, False) - + class testcircuit(Circuit): name = "Test" io = IO(**dict(zip(args[::2], args[1::2]))) @@ -124,3 +124,4 @@ class testcircuit(Circuit): console.runcmd("p self.counter.reg.O") assert get_out(capsys) == "2" m.config.set_debug_mode(False) + m.config.config.use_uinspect = True diff --git a/tests/test_type/test_type_errors.py b/tests/test_type/test_type_errors.py index bb1e0891c..cba64ef48 100644 --- a/tests/test_type/test_type_errors.py +++ b/tests/test_type/test_type_errors.py @@ -4,7 +4,7 @@ def test_array_lengths(caplog): - m.config.set_debug_mode(True) + m.config.config.use_namer_dict = True class Buf(Circuit): name = "Buf" io = IO(I=In(Array[8, Bit]), O=Out(Array[8, Bit])) @@ -18,11 +18,11 @@ class main(Circuit): \033[1mtests/test_type/test_type_errors.py:16\033[0m: Cannot wire main.O (Array[(7, In(Bit))]) to main.buf.I (Array[(8, In(Bit))]) >> wire(io.O, buf.I)""" assert has_error(caplog, msg) - m.config.set_debug_mode(False) + m.config.config.use_namer_dict = False def test_array_to_bit(caplog): - m.config.set_debug_mode(True) + m.config.config.use_namer_dict = True class Buf(Circuit): name = "Buf" io = IO(I=In(Array[8, Bit]), O=Out(Array[8, Bit])) @@ -36,11 +36,11 @@ class main(Circuit): \033[1mtests/test_type/test_type_errors.py:34\033[0m: Cannot wire main.O (In(Bit)) to main.buf.I (Array[(8, In(Bit))]) >> wire(io.O, buf.I)""" assert has_error(caplog, msg) - m.config.set_debug_mode(False) + m.config.config.use_namer_dict = False def test_bit_to_array(caplog): - m.config.set_debug_mode(True) + m.config.config.use_namer_dict = True class Buf(Circuit): name = "Buf" io = IO(I=In(Bit), O=Out(Array[8, Bit])) @@ -54,7 +54,7 @@ class main(Circuit): \033[1mtests/test_type/test_type_errors.py:51\033[0m: Cannot wire main.buf.I (type=In(Bit)) to main.O (type=Array[7, In(Bit)]) because main.buf.I is not an Array >> wire(buf.I, main.O)""" assert has_error(caplog, msg) - m.config.set_debug_mode(False) + m.config.config.use_namer_dict = False class I(m.Product): @@ -63,7 +63,7 @@ class I(m.Product): def test_tuple_to_array(caplog): - m.config.set_debug_mode(True) + m.config.config.use_namer_dict = True class Buf(Circuit): name = "Buf" io = IO(I=In(I), O=Out(Array[8, Bit])) @@ -77,11 +77,11 @@ class main(Circuit): \033[1mtests/test_type/test_type_errors.py:75\033[0m: Cannot wire main.O (In(Bit)) to main.buf.I (Tuple(a=In(Bit),b=In(Bit))) >> wire(io.O, buf.I)""" assert has_error(caplog, msg) - m.config.set_debug_mode(False) + m.config.config.use_namer_dict = False def test_bad_tuples(caplog): - m.config.set_debug_mode(True) + m.config.config.use_namer_dict = True class O(m.Product): c = m.In(m.Bit) d = m.In(m.Bit) @@ -99,11 +99,11 @@ class main(Circuit): \033[1mtests/test_type/test_type_errors.py:97\033[0m: Cannot wire main.O (Tuple(c=In(Bit),d=In(Bit))) to main.buf.I (Tuple(a=In(Bit),b=In(Bit))) >> wire(io.O, buf.I)""" assert has_error(caplog, msg) - m.config.set_debug_mode(False) + m.config.config.use_namer_dict = False def test_bit_to_array(caplog): - m.config.set_debug_mode(True) + m.config.config.use_namer_dict = True class Buf(Circuit): name = "Buf" io = IO(I=In(Array[8, Bit]), O=Out(Array[8, Bit])) @@ -117,4 +117,4 @@ class main(Circuit): \033[1mtests/test_type/test_type_errors.py:115\033[0m: Cannot wire main.buf.I (Array[(8, In(Bit))]) to main.O (In(Bit)) >> wire(buf.I, io.O)""" assert has_error(caplog, msg) - m.config.set_debug_mode(False) + m.config.config.use_namer_dict = False diff --git a/tests/test_wire/test_errors.py b/tests/test_wire/test_errors.py index 937dd7d0d..27637d121 100644 --- a/tests/test_wire/test_errors.py +++ b/tests/test_wire/test_errors.py @@ -9,7 +9,7 @@ def test_input_as_output(caplog): - magma.config.set_debug_mode(True) + magma.config.config.use_namer_dict = True class Buf(Circuit): name = "Buf" io = IO(I=In(Bit), O=Out(Bit)) @@ -23,11 +23,11 @@ class main(Circuit): \033[1mtests/test_wire/test_errors.py:21\033[0m: Cannot wire main.O (In(Bit)) to main.buf.I (In(Bit)) >> wire(io.O, buf.I)""" assert has_error(caplog, msg) - magma.config.set_debug_mode(False) + magma.config.config.use_namer_dict = False def test_output_as_input(caplog): - magma.config.set_debug_mode(True) + magma.config.config.use_namer_dict = True class A(Circuit): name = "A" io = IO(I=In(Bit), O=Out(Bit)) @@ -41,11 +41,11 @@ class main(Circuit): \033[1mtests/test_wire/test_errors.py:39\033[0m: Cannot wire main.I (Out(Bit)) to main.a.O (Out(Bit)) >> wire(io.I, a.O)""" assert has_error(caplog, msg) - magma.config.set_debug_mode(False) + magma.config.config.use_namer_dict = False def test_multiple_outputs_to_input_warning(caplog): - magma.config.set_debug_mode(True) + magma.config.config.use_namer_dict = True class A(Circuit): name = "A" io = IO(I=In(Bit), O=Out(Bit)) @@ -60,11 +60,11 @@ class main(Circuit): \033[1mtests/test_wire/test_errors.py:58\033[0m: Wiring multiple outputs to same wire, using last connection. Input: main.a.I, Old Output: main.I[0], New Output: main.I[1] >> wire(io.I[1], a.I)""" assert has_warning(caplog, msg) - magma.config.set_debug_mode(False) + magma.config.config.use_namer_dict = False def test_multiple_outputs_circuit(caplog): - magma.config.set_debug_mode(True) + magma.config.config.use_namer_dict = True class A(Circuit): name = "A" io = IO(I=In(Bit), O=Out(Bit), U=Out(Bit)) @@ -78,11 +78,11 @@ class main(Circuit): \033[1mtests/test_wire/test_errors.py:76\033[0m: Can only wire circuits with one output; circuit `main.a` has outputs ['O', 'U'] >> wire(a, io.I)""" assert has_error(caplog, msg) - magma.config.set_debug_mode(False) + magma.config.config.use_namer_dict = False def test_mismatch_outputs_circuit(caplog): - magma.config.set_debug_mode(True) + magma.config.config.use_namer_dict = True class A(Circuit): name = "A" io = IO(I=In(Bit), J=In(Bit), O=Out(Bit), U=Out(Bit)) @@ -99,11 +99,11 @@ class Foo(Circuit): \033[1mtests/test_wire/test_errors.py:97\033[0m: Number of inputs is not equal to the number of outputs, expected 2 inputs, got 1. Only 1 will be wired. >> a(main)""" assert has_warning(caplog, msg) - magma.config.set_debug_mode(False) + magma.config.config.use_namer_dict = False def test_no_inputs_circuit(caplog): - magma.config.set_debug_mode(True) + magma.config.config.use_namer_dict = True class A(Circuit): name = "A" io = IO(O=Out(Bit), U=Out(Bit)) @@ -117,11 +117,11 @@ class main(Circuit): \033[1mtests/test_wire/test_errors.py:115\033[0m: Wiring an output to a circuit with no input arguments, skipping >> wire(io.I, a)""" assert has_warning(caplog, msg) - magma.config.set_debug_mode(False) + magma.config.config.use_namer_dict = False def test_multiple_inputs_circuit(caplog): - magma.config.set_debug_mode(True) + magma.config.config.use_namer_dict = True class A(Circuit): name = "A" io = IO(I=In(Bit), J=In(Bit), O=Out(Bit), U=Out(Bit)) @@ -135,11 +135,11 @@ class main(Circuit): \033[1mtests/test_wire/test_errors.py:133\033[0m: Wiring an output to a circuit with more than one input argument, using the first input main.a.I >> wire(io.I, a)""" assert has_warning(caplog, msg) - magma.config.set_debug_mode(False) + magma.config.config.use_namer_dict = False def test_no_key(caplog): - magma.config.set_debug_mode(True) + magma.config.config.use_namer_dict = True class A(Circuit): name = "A" io = IO(I=In(Bit), J=In(Bit), O=Out(Bit), U=Out(Bit)) @@ -154,11 +154,11 @@ class main(Circuit): >> a(K=io.I)""" assert has_warning(caplog, msg) - magma.config.set_debug_mode(False) + magma.config.config.use_namer_dict = False def test_const_array_error(caplog): - magma.config.set_debug_mode(True) + magma.config.config.use_namer_dict = True class Buf(Circuit): name = "Buf" io = IO(I=In(Array[1, Bit]), O=Out(Array[1, Bit])) @@ -176,7 +176,7 @@ class main(Circuit): >> wire(1, buf.I)""" assert caplog.records[0].msg == msg assert has_error(caplog, msg) - magma.config.set_debug_mode(False) + magma.config.config.use_namer_dict = False @wrap_with_context_manager(logging_level("DEBUG")) diff --git a/tests/test_wire/test_unwire.py b/tests/test_wire/test_unwire.py index ee4f3474c..fe575804e 100644 --- a/tests/test_wire/test_unwire.py +++ b/tests/test_wire/test_unwire.py @@ -29,10 +29,8 @@ def test_unwire_basic(T, func, caplog): @pytest.mark.parametrize('T', Ts) @pytest.mark.parametrize('func', funcs[2:4]) def test_unwire_undriven(T, func, caplog): - m.config.set_debug_mode(True) x, y = T(name="Foo"), T() func(x, y) - m.config.set_debug_mode(False) def make_expcted_log(value_str): return f"""\ From 2cb7ca6bab322a4cdfad94bd111b8cd60b58a8f4 Mon Sep 17 00:00:00 2001 From: Lenny Truong Date: Mon, 9 Jan 2023 14:38:19 -0800 Subject: [PATCH 04/10] Update debug info logic for circuit --- magma/circuit.py | 10 ++-------- tests/test_circuit/gold/test_for_loop_def.json | 3 ++- .../gold/test_interleaved_instance_wiring.json | 3 ++- tests/test_circuit/gold/test_simple_def.json | 3 ++- .../test_circuit/gold/test_simple_def_class.json | 3 ++- tests/test_circuit/test_define.py | 15 ++++++--------- .../test_old_io_syntax_define.py | 15 ++++++--------- 7 files changed, 22 insertions(+), 30 deletions(-) diff --git a/magma/circuit.py b/magma/circuit.py index ef2ac9b37..4d50687aa 100644 --- a/magma/circuit.py +++ b/magma/circuit.py @@ -14,8 +14,7 @@ from .common import deprecated, setattrs, OrderedIdentitySet from .interface import * from .wire import * -from .config import get_debug_mode, set_debug_mode -from .debug import get_debug_info, debug_info +from .debug import get_debug_info from .is_definition import isdefinition from .placer import Placer, StagedPlacer from magma.syntax.combinational import combinational @@ -293,12 +292,7 @@ def __new__(metacls, name, bases, dct): # If in debug_mode is active and debug_info is not supplied, attach # callee stack info. dct.setdefault("debug_info", None) - if get_debug_mode() and not dct["debug_info"]: - callee_frame = inspect.getframeinfo( - inspect.currentframe().f_back.f_back) - module = inspect.getmodule(inspect.stack()[2][0]) - dct["debug_info"] = debug_info(callee_frame.filename, - callee_frame.lineno, module) + dct["debug_info"] = get_debug_info(4) cls = type.__new__(metacls, name, bases, dct) diff --git a/tests/test_circuit/gold/test_for_loop_def.json b/tests/test_circuit/gold/test_for_loop_def.json index 23454ddd0..69b39d35f 100644 --- a/tests/test_circuit/gold/test_for_loop_def.json +++ b/tests/test_circuit/gold/test_for_loop_def.json @@ -7,7 +7,8 @@ ["I0","BitIn"], ["I1","BitIn"], ["O","Bit"] - ]] + ]], + "metadata":{"filename":"tests/test_circuit/test_define.py","lineno":"8"} }, "main":{ "type":["Record",[ diff --git a/tests/test_circuit/gold/test_interleaved_instance_wiring.json b/tests/test_circuit/gold/test_interleaved_instance_wiring.json index 85622e98d..d6298687b 100644 --- a/tests/test_circuit/gold/test_interleaved_instance_wiring.json +++ b/tests/test_circuit/gold/test_interleaved_instance_wiring.json @@ -7,7 +7,8 @@ ["I0","BitIn"], ["I1","BitIn"], ["O","Bit"] - ]] + ]], + "metadata":{"filename":"tests/test_circuit/test_define.py","lineno":"8"} }, "main":{ "type":["Record",[ diff --git a/tests/test_circuit/gold/test_simple_def.json b/tests/test_circuit/gold/test_simple_def.json index ca2cc4ff4..5197b0d5d 100644 --- a/tests/test_circuit/gold/test_simple_def.json +++ b/tests/test_circuit/gold/test_simple_def.json @@ -7,7 +7,8 @@ ["I0","BitIn"], ["I1","BitIn"], ["O","Bit"] - ]] + ]], + "metadata":{"filename":"tests/test_circuit/test_define.py","lineno":"8"} }, "main":{ "type":["Record",[ diff --git a/tests/test_circuit/gold/test_simple_def_class.json b/tests/test_circuit/gold/test_simple_def_class.json index 13cdd76b9..0e2b7f7b6 100644 --- a/tests/test_circuit/gold/test_simple_def_class.json +++ b/tests/test_circuit/gold/test_simple_def_class.json @@ -7,7 +7,8 @@ ["I0","BitIn"], ["I1","BitIn"], ["O","Bit"] - ]] + ]], + "metadata":{"filename":"tests/test_circuit/test_define.py","lineno":"8"} }, "Main":{ "type":["Record",[ diff --git a/tests/test_circuit/test_define.py b/tests/test_circuit/test_define.py index 3f938c00d..4b04ed047 100644 --- a/tests/test_circuit/test_define.py +++ b/tests/test_circuit/test_define.py @@ -13,7 +13,7 @@ class And2(m.Circuit): @pytest.mark.parametrize("target,suffix", [("verilog", "v"), ("coreir", "json")]) def test_simple_def(target, suffix): - m.config.set_debug_mode(True) + m.config.config.use_namer_dict = True m.set_codegen_debug_info(True) class main(m.Circuit): @@ -42,8 +42,7 @@ class Main(m.Circuit): # Create a fresh context for second compilation. m.compile("build/test_simple_def_class", Main, output=target) m.set_codegen_debug_info(False) - m.config.set_debug_mode(False) - m.config.config.use_uinspect = True + m.config.config.use_namer_dict = False assert check_files_equal(__file__, f"build/test_simple_def_class.{suffix}", f"gold/test_simple_def_class.{suffix}") @@ -51,7 +50,7 @@ class Main(m.Circuit): @pytest.mark.parametrize("target,suffix", [("verilog", "v"), ("coreir", "json")]) def test_for_loop_def(target, suffix): - m.config.set_debug_mode(True) + m.config.config.use_namer_dict = True m.set_codegen_debug_info(True) class main(m.Circuit): @@ -73,8 +72,7 @@ class main(m.Circuit): m.compile("build/test_for_loop_def", main, output=target) m.set_codegen_debug_info(False) - m.config.set_debug_mode(False) - m.config.config.use_uinspect = True + m.config.config.use_namer_dict = False assert check_files_equal(__file__, f"build/test_for_loop_def.{suffix}", f"gold/test_for_loop_def.{suffix}") @@ -82,7 +80,7 @@ class main(m.Circuit): @pytest.mark.parametrize("target,suffix", [("verilog", "v"), ("coreir", "json")]) def test_interleaved_instance_wiring(target, suffix): - m.config.set_debug_mode(True) + m.config.config.use_namer_dict = True m.set_codegen_debug_info(True) class main(m.Circuit): @@ -104,8 +102,7 @@ class main(m.Circuit): m.compile("build/test_interleaved_instance_wiring", main, output=target) m.set_codegen_debug_info(False) - m.config.set_debug_mode(False) - m.config.config.use_uinspect = True + m.config.config.use_namer_dict = False assert check_files_equal(__file__, f"build/test_interleaved_instance_wiring.{suffix}", f"gold/test_interleaved_instance_wiring.{suffix}") diff --git a/tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py b/tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py index 2d791ce3d..5859801e3 100644 --- a/tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py +++ b/tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py @@ -14,7 +14,7 @@ @pytest.mark.parametrize("target,suffix", [("verilog", "v"), ("coreir", "json")]) def test_simple_def(target, suffix): - m.config.set_debug_mode(True) + m.config.config.use_namer_dict = True m.set_codegen_debug_info(True) with pytest.warns(DeprecationWarning): And2 = m.DeclareCircuit('And2', "I0", m.In(m.Bit), "I1", m.In(m.Bit), @@ -48,8 +48,7 @@ def definition(io): # Create a fresh context for second compilation. m.compile("build/test_simple_def_class", Main, output=target) m.set_codegen_debug_info(False) - m.config.set_debug_mode(False) - m.config.config.use_uinspect = True + m.config.config.use_namer_dict = False assert check_files_equal(__file__, f"build/test_simple_def_class.{suffix}", f"gold/test_simple_def_class.{suffix}") @@ -57,7 +56,7 @@ def definition(io): @pytest.mark.parametrize("target,suffix", [("verilog", "v"), ("coreir", "json")]) def test_for_loop_def(target, suffix): - m.config.set_debug_mode(True) + m.config.config.use_namer_dict = True m.set_codegen_debug_info(True) with pytest.warns(DeprecationWarning): And2 = m.DeclareCircuit('And2', "I0", m.In(m.Bit), "I1", m.In(m.Bit), @@ -82,8 +81,7 @@ def test_for_loop_def(target, suffix): m.compile("build/test_for_loop_def", main, output=target) m.set_codegen_debug_info(False) - m.config.set_debug_mode(False) - m.config.config.use_uinspect = True + m.config.config.use_namer_dict = False assert check_files_equal(__file__, f"build/test_for_loop_def.{suffix}", f"gold/test_for_loop_def.{suffix}") @@ -91,7 +89,7 @@ def test_for_loop_def(target, suffix): @pytest.mark.parametrize("target,suffix", [("verilog", "v"), ("coreir", "json")]) def test_interleaved_instance_wiring(target, suffix): - m.config.set_debug_mode(True) + m.config.config.use_namer_dict = True m.set_codegen_debug_info(True) with pytest.warns(DeprecationWarning): And2 = m.DeclareCircuit('And2', "I0", m.In(m.Bit), "I1", m.In(m.Bit), @@ -116,8 +114,7 @@ def test_interleaved_instance_wiring(target, suffix): m.compile("build/test_interleaved_instance_wiring", main, output=target) m.set_codegen_debug_info(False) - m.config.set_debug_mode(False) - m.config.config.use_uinspect = True + m.config.config.use_namer_dict = False assert check_files_equal(__file__, f"build/test_interleaved_instance_wiring.{suffix}", f"gold/test_interleaved_instance_wiring.{suffix}") From 0282dbdceaa5a00782730bd5220327e705306fa0 Mon Sep 17 00:00:00 2001 From: Lenny Truong Date: Mon, 9 Jan 2023 14:47:41 -0800 Subject: [PATCH 05/10] Update tests --- magma/circuit.py | 4 ++- tests/test_circuit/test_new_style_syntax.py | 25 +++++++++++++------ .../gold/test_memory_basic.mlir | 2 +- tests/test_type/top.json | 11 +++++--- tests/test_type/top.v | 2 ++ 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/magma/circuit.py b/magma/circuit.py index 4d50687aa..bf0607b14 100644 --- a/magma/circuit.py +++ b/magma/circuit.py @@ -292,7 +292,9 @@ def __new__(metacls, name, bases, dct): # If in debug_mode is active and debug_info is not supplied, attach # callee stack info. dct.setdefault("debug_info", None) - dct["debug_info"] = get_debug_info(4) + if not dct["debug_info"]: + # Don't use setdefault to avoid get_debug_info call if possible + dct["debug_info"] = get_debug_info(4) cls = type.__new__(metacls, name, bases, dct) diff --git a/tests/test_circuit/test_new_style_syntax.py b/tests/test_circuit/test_new_style_syntax.py index 3cad531a6..718810653 100644 --- a/tests/test_circuit/test_new_style_syntax.py +++ b/tests/test_circuit/test_new_style_syntax.py @@ -55,7 +55,10 @@ class _Foo(m.Circuit): io = None # doesn't matter what the value of io is. _check_foo_interface(_Foo) - expected = "'IO' and 'io' should not both be specified, ignoring 'io'" + expected = """\ +tests/test_circuit/test_new_style_syntax.py:53: 'IO' and 'io' should not both be specified, ignoring 'io' +>> class _Foo(m.Circuit):\ +""" assert has_warning(caplog, expected) @@ -75,7 +78,10 @@ class _Foo(m.Circuit): io.x @= 0 assert m.isdefinition(_Foo) - assert has_error(caplog, "_Foo.O not driven") + assert has_error(caplog, """\ +tests/test_circuit/test_new_style_syntax.py:74: _Foo.O not driven +>> class _Foo(m.Circuit):\ +""") assert has_error(caplog, "_Foo.O") assert has_error(caplog, " _Foo.O[0]: Connected") assert has_error(caplog, " _Foo.O[1]: Unconnected") @@ -107,12 +113,12 @@ class _Foo(m.Circuit): assert not m.isdefinition(_Foo) assert has_error(caplog, """\ -tests/test_circuit/test_new_style_syntax.py:104: Cannot wire _Foo.I (Out(Bit)) to _Foo.O (Out(Bit)) +tests/test_circuit/test_new_style_syntax.py:110: Cannot wire _Foo.I (Out(Bit)) to _Foo.O (Out(Bit)) >> m.wire(io.I, io.O)\ """) assert has_error(caplog, """\ -tests/test_circuit/test_new_style_syntax.py:105: Cannot wire _Foo.I (Out(Bit)) to _Foo.O1 (In(Bits[1])) +tests/test_circuit/test_new_style_syntax.py:111: Cannot wire _Foo.I (Out(Bit)) to _Foo.O1 (In(Bits[1])) >> m.wire(io.I, io.O1)\ """) @@ -131,19 +137,22 @@ class _Foo(m.Circuit): assert has_error( caplog, """\ -tests/test_circuit/test_new_style_syntax.py:129: Cannot wire _Foo.I (Out(Bit)) to _Foo._Bar_inst0.I (In(Bits[1])) +tests/test_circuit/test_new_style_syntax.py:135: Cannot wire _Foo.I (Out(Bit)) to _Foo._Bar_inst0.I (In(Bits[1])) >> m.wire(io.I, bar.I)\ """) assert has_error( caplog, """\ -tests/test_circuit/test_new_style_syntax.py:130: Cannot wire _Foo._Bar_inst0.O (Out(Bits[1])) to _Foo.O (In(Bit)) +tests/test_circuit/test_new_style_syntax.py:136: Cannot wire _Foo._Bar_inst0.O (Out(Bits[1])) to _Foo.O (In(Bit)) >> m.wire(bar.O, io.O)\ """) - assert has_error(caplog, "_Foo.O not driven") + assert has_error(caplog, """\ +tests/test_circuit/test_new_style_syntax.py:131: _Foo.O not driven +>> class _Foo(m.Circuit):\ +""") assert has_error(caplog, "_Foo.O: Unconnected") assert has_error(caplog, """\ -tests/test_circuit/test_new_style_syntax.py:128: _Foo._Bar_inst0.I not driven +tests/test_circuit/test_new_style_syntax.py:134: _Foo._Bar_inst0.I not driven >> bar = _Bar()\ """) assert has_error(caplog, "_Foo._Bar_inst0.I: Unconnected") diff --git a/tests/test_primitives/gold/test_memory_basic.mlir b/tests/test_primitives/gold/test_memory_basic.mlir index a149d8c6f..a5e5b9ce2 100644 --- a/tests/test_primitives/gold/test_memory_basic.mlir +++ b/tests/test_primitives/gold/test_memory_basic.mlir @@ -32,7 +32,7 @@ module attributes {circt.loweringOptions = "locationInfoStyle=none"} { sv.bpassign %9, %0 : i1 } } - %10 = hw.instance "Memory_inst0" @Memory(RADDR: %raddr: i2, CLK: %clk: i1, WADDR: %4: i2, WDATA: %5: i5, WE: %6: i1) -> (RDATA: i5) + %10 = hw.instance "Mem4x5" @Memory(RADDR: %raddr: i2, CLK: %clk: i1, WADDR: %4: i2, WDATA: %5: i5, WE: %6: i1) -> (RDATA: i5) hw.output %10 : i5 } } diff --git a/tests/test_type/top.json b/tests/test_type/top.json index cf9fe3b08..d509d7a57 100644 --- a/tests/test_type/top.json +++ b/tests/test_type/top.json @@ -5,7 +5,8 @@ "MyCircuit":{ "type":["Record",[ ["IFC0",["Record",[["port0",["Array",5,"Bit"]],["port1",["Array",5,"Bit"]],["port2",["Array",5,["Array",2,"Bit"]]],["port3",["Array",5,"Bit"]],["port4","Bit"],["port5","Bit"],["port7","Bit"],["port8","Bit"],["port9","Bit"],["port10",["Array",3,"Bit"]]]]] - ]] + ]], + "metadata":{"filename":"tests/test_type/test_tuple.py","lineno":"264"} }, "Top":{ "type":["Record",[ @@ -13,12 +14,14 @@ ]], "instances":{ "MyCircuit_inst0":{ - "modref":"global.MyCircuit" + "modref":"global.MyCircuit", + "metadata":{"filename":"tests/test_type/test_tuple.py","lineno":"271"} } }, "connections":[ - ["self.IFC1.port4","MyCircuit_inst0.IFC0.port4"] - ] + ["self.IFC1.port4","MyCircuit_inst0.IFC0.port4",{"filename":"tests/test_type/test_tuple.py","lineno":"271"}] + ], + "metadata":{"filename":"tests/test_type/test_tuple.py","lineno":"269"} } } } diff --git a/tests/test_type/top.v b/tests/test_type/top.v index ce475058f..1b2f22524 100644 --- a/tests/test_type/top.v +++ b/tests/test_type/top.v @@ -2,6 +2,7 @@ module Top ( output IFC1_port4 ); +// Module `Top` defined at tests/test_type/test_tuple.py:269 wire [4:0] MyCircuit_inst0_IFC0_port0; wire [4:0] MyCircuit_inst0_IFC0_port1; wire [2:0] MyCircuit_inst0_IFC0_port10; @@ -12,6 +13,7 @@ wire MyCircuit_inst0_IFC0_port5; wire MyCircuit_inst0_IFC0_port7; wire MyCircuit_inst0_IFC0_port8; wire MyCircuit_inst0_IFC0_port9; +// Instance `MyCircuit_inst0` created at tests/test_type/test_tuple.py:271 MyCircuit MyCircuit_inst0 ( .IFC0_port0(MyCircuit_inst0_IFC0_port0), .IFC0_port1(MyCircuit_inst0_IFC0_port1), From 1ea5463ad60ef6f39523276ede94a1b4df1e8570 Mon Sep 17 00:00:00 2001 From: Lenny Truong Date: Tue, 10 Jan 2023 09:35:53 -0800 Subject: [PATCH 06/10] Update old tests --- .../gold/test_for_loop_def.json | 30 ++++++++-------- .../gold/test_for_loop_def.v | 36 +++++++++---------- .../test_interleaved_instance_wiring.json | 24 ++++++------- .../gold/test_interleaved_instance_wiring.v | 28 +++++++-------- .../test_old_io_syntax_define.py | 15 ++++---- 5 files changed, 68 insertions(+), 65 deletions(-) diff --git a/tests/test_deprecated/test_old_io_syntax/gold/test_for_loop_def.json b/tests/test_deprecated/test_old_io_syntax/gold/test_for_loop_def.json index 902f1cac1..ab4b7e015 100644 --- a/tests/test_deprecated/test_old_io_syntax/gold/test_for_loop_def.json +++ b/tests/test_deprecated/test_old_io_syntax/gold/test_for_loop_def.json @@ -8,7 +8,7 @@ ["I1","BitIn"], ["O","Bit"] ]], - "metadata":{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"62"} + "metadata":{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"63"} }, "main":{ "type":["Record",[ @@ -18,33 +18,33 @@ "instances":{ "and2_0":{ "modref":"global.And2", - "metadata":{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"69"} + "metadata":{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"70"} }, "and2_1":{ "modref":"global.And2", - "metadata":{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"69"} + "metadata":{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"70"} }, "and2_2":{ "modref":"global.And2", - "metadata":{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"69"} + "metadata":{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"70"} }, "and2_3":{ "modref":"global.And2", - "metadata":{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"69"} + "metadata":{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"70"} } }, "connections":[ - ["self.I.0","and2_0.I0",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"71"}], - ["self.I.1","and2_0.I1",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"72"}], - ["and2_1.I0","and2_0.O",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"74"}], - ["self.I.1","and2_1.I1",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"75"}], - ["and2_2.I0","and2_1.O",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"74"}], - ["self.I.1","and2_2.I1",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"75"}], - ["and2_3.I0","and2_2.O",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"74"}], - ["self.I.1","and2_3.I1",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"75"}], - ["self.O","and2_3.O",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"78"}] + ["self.I.0","and2_0.I0",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"72"}], + ["self.I.1","and2_0.I1",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"73"}], + ["and2_1.I0","and2_0.O",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"75"}], + ["self.I.1","and2_1.I1",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"76"}], + ["and2_2.I0","and2_1.O",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"75"}], + ["self.I.1","and2_2.I1",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"76"}], + ["and2_3.I0","and2_2.O",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"75"}], + ["self.I.1","and2_3.I1",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"76"}], + ["self.O","and2_3.O",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"79"}] ], - "metadata":{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"65"} + "metadata":{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"66"} } } } diff --git a/tests/test_deprecated/test_old_io_syntax/gold/test_for_loop_def.v b/tests/test_deprecated/test_old_io_syntax/gold/test_for_loop_def.v index 85fc18034..0a191e825 100644 --- a/tests/test_deprecated/test_old_io_syntax/gold/test_for_loop_def.v +++ b/tests/test_deprecated/test_old_io_syntax/gold/test_for_loop_def.v @@ -1,30 +1,30 @@ -// Defined at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:65 +// Defined at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:66 module main (input [1:0] I, output O); wire and2_0_O; wire and2_1_O; wire and2_2_O; wire and2_3_O; -// Instanced at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:69 -// Argument I0(I[0]) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:71 -// Argument I1(I[1]) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:72 -// Argument O(and2_0_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:74 +// Instanced at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:70 +// Argument I0(I[0]) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:72 +// Argument I1(I[1]) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:73 +// Argument O(and2_0_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:75 And2 and2_0 (.I0(I[0]), .I1(I[1]), .O(and2_0_O)); -// Instanced at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:69 -// Argument I0(and2_0_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:74 -// Argument I1(I[1]) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:75 -// Argument O(and2_1_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:74 +// Instanced at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:70 +// Argument I0(and2_0_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:75 +// Argument I1(I[1]) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:76 +// Argument O(and2_1_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:75 And2 and2_1 (.I0(and2_0_O), .I1(I[1]), .O(and2_1_O)); -// Instanced at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:69 -// Argument I0(and2_1_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:74 -// Argument I1(I[1]) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:75 -// Argument O(and2_2_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:74 +// Instanced at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:70 +// Argument I0(and2_1_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:75 +// Argument I1(I[1]) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:76 +// Argument O(and2_2_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:75 And2 and2_2 (.I0(and2_1_O), .I1(I[1]), .O(and2_2_O)); -// Instanced at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:69 -// Argument I0(and2_2_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:74 -// Argument I1(I[1]) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:75 -// Argument O(and2_3_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:78 +// Instanced at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:70 +// Argument I0(and2_2_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:75 +// Argument I1(I[1]) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:76 +// Argument O(and2_3_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:79 And2 and2_3 (.I0(and2_2_O), .I1(I[1]), .O(and2_3_O)); -// Wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:78 +// Wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:79 assign O = and2_3_O; endmodule diff --git a/tests/test_deprecated/test_old_io_syntax/gold/test_interleaved_instance_wiring.json b/tests/test_deprecated/test_old_io_syntax/gold/test_interleaved_instance_wiring.json index 08a6664f0..314d50a45 100644 --- a/tests/test_deprecated/test_old_io_syntax/gold/test_interleaved_instance_wiring.json +++ b/tests/test_deprecated/test_old_io_syntax/gold/test_interleaved_instance_wiring.json @@ -8,7 +8,7 @@ ["I1","BitIn"], ["O","Bit"] ]], - "metadata":{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"95"} + "metadata":{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"97"} }, "main":{ "type":["Record",[ @@ -18,27 +18,27 @@ "instances":{ "and2_0":{ "modref":"global.And2", - "metadata":{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"100"} + "metadata":{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"102"} }, "and2_1":{ "modref":"global.And2", - "metadata":{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"101"} + "metadata":{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"103"} }, "and2_2":{ "modref":"global.And2", - "metadata":{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"107"} + "metadata":{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"109"} } }, "connections":[ - ["self.I.0","and2_0.I0",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"103"}], - ["self.I.1","and2_0.I1",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"104"}], - ["and2_1.I0","and2_0.O",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"105"}], - ["self.I.1","and2_1.I1",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"106"}], - ["and2_2.I0","and2_1.O",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"108"}], - ["self.I.0","and2_2.I1",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"109"}], - ["self.O","and2_2.O",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"111"}] + ["self.I.0","and2_0.I0",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"105"}], + ["self.I.1","and2_0.I1",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"106"}], + ["and2_1.I0","and2_0.O",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"107"}], + ["self.I.1","and2_1.I1",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"108"}], + ["and2_2.I0","and2_1.O",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"110"}], + ["self.I.0","and2_2.I1",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"111"}], + ["self.O","and2_2.O",{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"113"}] ], - "metadata":{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"98"} + "metadata":{"filename":"tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py","lineno":"100"} } } } diff --git a/tests/test_deprecated/test_old_io_syntax/gold/test_interleaved_instance_wiring.v b/tests/test_deprecated/test_old_io_syntax/gold/test_interleaved_instance_wiring.v index 61a3f2503..0c8f0c2f9 100644 --- a/tests/test_deprecated/test_old_io_syntax/gold/test_interleaved_instance_wiring.v +++ b/tests/test_deprecated/test_old_io_syntax/gold/test_interleaved_instance_wiring.v @@ -1,24 +1,24 @@ -// Defined at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:98 +// Defined at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:100 module main (input [1:0] I, output O); wire and2_0_O; wire and2_1_O; wire and2_2_O; -// Instanced at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:100 -// Argument I0(I[0]) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:103 -// Argument I1(I[1]) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:104 -// Argument O(and2_0_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:105 -And2 and2_0 (.I0(I[0]), .I1(I[1]), .O(and2_0_O)); -// Instanced at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:101 -// Argument I0(and2_0_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:105 +// Instanced at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:102 +// Argument I0(I[0]) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:105 // Argument I1(I[1]) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:106 -// Argument O(and2_1_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:108 +// Argument O(and2_0_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:107 +And2 and2_0 (.I0(I[0]), .I1(I[1]), .O(and2_0_O)); +// Instanced at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:103 +// Argument I0(and2_0_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:107 +// Argument I1(I[1]) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:108 +// Argument O(and2_1_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:110 And2 and2_1 (.I0(and2_0_O), .I1(I[1]), .O(and2_1_O)); -// Instanced at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:107 -// Argument I0(and2_1_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:108 -// Argument I1(I[0]) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:109 -// Argument O(and2_2_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:111 +// Instanced at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:109 +// Argument I0(and2_1_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:110 +// Argument I1(I[0]) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:111 +// Argument O(and2_2_O) wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:113 And2 and2_2 (.I0(and2_1_O), .I1(I[0]), .O(and2_2_O)); -// Wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:111 +// Wired at tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py:113 assign O = and2_2_O; endmodule diff --git a/tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py b/tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py index 5859801e3..2d791ce3d 100644 --- a/tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py +++ b/tests/test_deprecated/test_old_io_syntax/test_old_io_syntax_define.py @@ -14,7 +14,7 @@ @pytest.mark.parametrize("target,suffix", [("verilog", "v"), ("coreir", "json")]) def test_simple_def(target, suffix): - m.config.config.use_namer_dict = True + m.config.set_debug_mode(True) m.set_codegen_debug_info(True) with pytest.warns(DeprecationWarning): And2 = m.DeclareCircuit('And2', "I0", m.In(m.Bit), "I1", m.In(m.Bit), @@ -48,7 +48,8 @@ def definition(io): # Create a fresh context for second compilation. m.compile("build/test_simple_def_class", Main, output=target) m.set_codegen_debug_info(False) - m.config.config.use_namer_dict = False + m.config.set_debug_mode(False) + m.config.config.use_uinspect = True assert check_files_equal(__file__, f"build/test_simple_def_class.{suffix}", f"gold/test_simple_def_class.{suffix}") @@ -56,7 +57,7 @@ def definition(io): @pytest.mark.parametrize("target,suffix", [("verilog", "v"), ("coreir", "json")]) def test_for_loop_def(target, suffix): - m.config.config.use_namer_dict = True + m.config.set_debug_mode(True) m.set_codegen_debug_info(True) with pytest.warns(DeprecationWarning): And2 = m.DeclareCircuit('And2', "I0", m.In(m.Bit), "I1", m.In(m.Bit), @@ -81,7 +82,8 @@ def test_for_loop_def(target, suffix): m.compile("build/test_for_loop_def", main, output=target) m.set_codegen_debug_info(False) - m.config.config.use_namer_dict = False + m.config.set_debug_mode(False) + m.config.config.use_uinspect = True assert check_files_equal(__file__, f"build/test_for_loop_def.{suffix}", f"gold/test_for_loop_def.{suffix}") @@ -89,7 +91,7 @@ def test_for_loop_def(target, suffix): @pytest.mark.parametrize("target,suffix", [("verilog", "v"), ("coreir", "json")]) def test_interleaved_instance_wiring(target, suffix): - m.config.config.use_namer_dict = True + m.config.set_debug_mode(True) m.set_codegen_debug_info(True) with pytest.warns(DeprecationWarning): And2 = m.DeclareCircuit('And2', "I0", m.In(m.Bit), "I1", m.In(m.Bit), @@ -114,7 +116,8 @@ def test_interleaved_instance_wiring(target, suffix): m.compile("build/test_interleaved_instance_wiring", main, output=target) m.set_codegen_debug_info(False) - m.config.config.use_namer_dict = False + m.config.set_debug_mode(False) + m.config.config.use_uinspect = True assert check_files_equal(__file__, f"build/test_interleaved_instance_wiring.{suffix}", f"gold/test_interleaved_instance_wiring.{suffix}") From 1b74d74a196867e1c8abe24fbf21ce489b0041a7 Mon Sep 17 00:00:00 2001 From: Lenny Truong Date: Tue, 10 Jan 2023 09:46:20 -0800 Subject: [PATCH 07/10] Update tuple tests --- tests/test_errors/test_tuple_errors.py | 17 +++++++++-------- tests/test_type/top.json | 11 ++++------- tests/test_type/top.v | 2 -- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/tests/test_errors/test_tuple_errors.py b/tests/test_errors/test_tuple_errors.py index cfe89ef08..10955cb1c 100644 --- a/tests/test_errors/test_tuple_errors.py +++ b/tests/test_errors/test_tuple_errors.py @@ -19,7 +19,7 @@ class Foo(m.Circuit): with pytest.raises(Exception) as e: m.compile("build/Foo", Foo) - assert caplog.messages[0] == "Foo.A not driven" + assert "Foo.A not driven" in caplog.messages[0] assert caplog.messages[1] == "Foo.A" assert caplog.messages[2] == " Foo.A.x: Connected" assert caplog.messages[3] == " Foo.A.y: Unconnected" @@ -42,7 +42,7 @@ class Foo(m.Circuit): with pytest.raises(Exception) as e: m.compile("build/Foo", Foo) - assert caplog.messages[0] == "Foo.A not driven" + assert "Foo.A not driven" in caplog.messages[0] assert caplog.messages[1] == "Foo.A" assert caplog.messages[2] == " Foo.A.x: Connected" assert caplog.messages[3] == " Foo.A.y: Unconnected" @@ -66,7 +66,7 @@ class Foo(m.Circuit): with pytest.raises(Exception) as e: m.compile("build/Foo", Foo) - assert caplog.messages[0] == "Foo.A not driven" + assert "Foo.A not driven" in caplog.messages[0] assert caplog.messages[1] == "Foo.A" assert caplog.messages[2] == " Foo.A.x: Connected" assert caplog.messages[3] == " Foo.A.y" @@ -88,7 +88,7 @@ class Foo(m.Circuit): with pytest.raises(Exception) as e: m.compile("build/Foo", Foo) - assert caplog.messages[0] == "Foo.A not driven" + assert "Foo.A not driven" in caplog.messages[0] assert caplog.messages[1] == "Foo.A" assert caplog.messages[2] == " Foo.A[0]" assert caplog.messages[3] == " Foo.A[0].x: Connected" @@ -125,7 +125,7 @@ class Foo(m.Circuit): tests/test_errors/test_tuple_errors.py:110: Cannot wire Bits[3](2) (Out(Bits[3])) to Foo.A.y (In(Bits[4])) >> io.A.y @= m.bits(2, 3)\ """) - assert caplog.messages[2] == "Foo.A not driven" + assert "Foo.A not driven" in caplog.messages[2] assert caplog.messages[3] == "Foo.A: Unconnected" @@ -164,7 +164,8 @@ class Foo(m.Circuit): m.compile("build/Foo", Foo) assert str(e.value) == "Found circuit with errors: Foo" expected = """\ -Foo.A.y not driven +\x1b[1mtests/test_errors/test_tuple_errors.py:157\x1b[0m: Foo.A.y not driven +>> class Foo(m.Circuit): Foo.A.y Foo.A.y[0]: Connected Foo.A.y[1]: Unconnected\ @@ -188,10 +189,10 @@ class Bar(m.Circuit): foo.I @= io.I io.O @= foo.z.x - assert caplog.messages[0] == "Bar.z.x not driven" + assert "Bar.z.x not driven" in caplog.messages[0] assert caplog.messages[1] == "Bar.z.x: Unconnected" assert has_error(caplog, """\ -tests/test_errors/test_tuple_errors.py:187: Foo_inst0.z.y not driven +tests/test_errors/test_tuple_errors.py:188: Foo_inst0.z.y not driven >> foo = Foo()\ """) diff --git a/tests/test_type/top.json b/tests/test_type/top.json index d509d7a57..cf9fe3b08 100644 --- a/tests/test_type/top.json +++ b/tests/test_type/top.json @@ -5,8 +5,7 @@ "MyCircuit":{ "type":["Record",[ ["IFC0",["Record",[["port0",["Array",5,"Bit"]],["port1",["Array",5,"Bit"]],["port2",["Array",5,["Array",2,"Bit"]]],["port3",["Array",5,"Bit"]],["port4","Bit"],["port5","Bit"],["port7","Bit"],["port8","Bit"],["port9","Bit"],["port10",["Array",3,"Bit"]]]]] - ]], - "metadata":{"filename":"tests/test_type/test_tuple.py","lineno":"264"} + ]] }, "Top":{ "type":["Record",[ @@ -14,14 +13,12 @@ ]], "instances":{ "MyCircuit_inst0":{ - "modref":"global.MyCircuit", - "metadata":{"filename":"tests/test_type/test_tuple.py","lineno":"271"} + "modref":"global.MyCircuit" } }, "connections":[ - ["self.IFC1.port4","MyCircuit_inst0.IFC0.port4",{"filename":"tests/test_type/test_tuple.py","lineno":"271"}] - ], - "metadata":{"filename":"tests/test_type/test_tuple.py","lineno":"269"} + ["self.IFC1.port4","MyCircuit_inst0.IFC0.port4"] + ] } } } diff --git a/tests/test_type/top.v b/tests/test_type/top.v index 1b2f22524..ce475058f 100644 --- a/tests/test_type/top.v +++ b/tests/test_type/top.v @@ -2,7 +2,6 @@ module Top ( output IFC1_port4 ); -// Module `Top` defined at tests/test_type/test_tuple.py:269 wire [4:0] MyCircuit_inst0_IFC0_port0; wire [4:0] MyCircuit_inst0_IFC0_port1; wire [2:0] MyCircuit_inst0_IFC0_port10; @@ -13,7 +12,6 @@ wire MyCircuit_inst0_IFC0_port5; wire MyCircuit_inst0_IFC0_port7; wire MyCircuit_inst0_IFC0_port8; wire MyCircuit_inst0_IFC0_port9; -// Instance `MyCircuit_inst0` created at tests/test_type/test_tuple.py:271 MyCircuit MyCircuit_inst0 ( .IFC0_port0(MyCircuit_inst0_IFC0_port0), .IFC0_port1(MyCircuit_inst0_IFC0_port1), From 2ba6e0df587b8350f961ffa8d714089bd5bf08e5 Mon Sep 17 00:00:00 2001 From: Lenny Truong Date: Tue, 10 Jan 2023 09:52:46 -0800 Subject: [PATCH 08/10] Fix magma debug section logic --- magma/testing/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/magma/testing/utils.py b/magma/testing/utils.py index 3d6d3956d..646dd8fbf 100644 --- a/magma/testing/utils.py +++ b/magma/testing/utils.py @@ -44,12 +44,14 @@ def check_files_equal(callee_file, file1_name, file2_name): class _MagmaDebugSection: def __init__(self): self.__restore = get_debug_mode() + self.__restore_uinspect = config.use_uinspect def __enter__(self): set_debug_mode(True) def __exit__(self, typ, value, traceback): set_debug_mode(self.__restore) + config.use_uinspect = self.__restore_uinspect def magma_debug_section(): From 34fa962c9d86c1ae3f257bc8f0b15af0d0016b78 Mon Sep 17 00:00:00 2001 From: Lenny Truong Date: Tue, 10 Jan 2023 10:01:41 -0800 Subject: [PATCH 09/10] Fix reset --- tests/test_dot/test_dot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_dot/test_dot.py b/tests/test_dot/test_dot.py index 837f391bb..896f90937 100644 --- a/tests/test_dot/test_dot.py +++ b/tests/test_dot/test_dot.py @@ -16,7 +16,7 @@ class main(Circuit): compile("build/dot", main, output='dot') m.config.set_debug_mode(False) - m.config.config.use_namer_dict = True # reset default + m.config.config.use_uinspect = True # reset default # FIXME: Do equality check. # Let's not check for equality / check in gold until we've finalized this format. # assert magma_check_files_equal(__file__, "build/dot.dot", "gold/dot.dot") From 87bca3ba0942e0d8a06b87c76d9cdb29d3d9700b Mon Sep 17 00:00:00 2001 From: Lenny Truong Date: Tue, 10 Jan 2023 10:07:47 -0800 Subject: [PATCH 10/10] Update array tests --- tests/test_errors/test_array_errors.py | 6 +++--- tests/test_primitives/gold/test_memory_basic.mlir | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_errors/test_array_errors.py b/tests/test_errors/test_array_errors.py index 067ec980b..cc34fe598 100644 --- a/tests/test_errors/test_array_errors.py +++ b/tests/test_errors/test_array_errors.py @@ -15,7 +15,7 @@ class Foo(m.Circuit): with pytest.raises(Exception) as e: m.compile("build/Foo", Foo) - assert caplog.messages[0] == "Foo.A not driven" + assert "Foo.A not driven" in caplog.messages[0] assert caplog.messages[1] == "Foo.A" assert caplog.messages[2] == " Foo.A[0]: Connected" assert caplog.messages[3] == " Foo.A[1]: Unconnected" @@ -30,7 +30,7 @@ class Foo(m.Circuit): with pytest.raises(Exception) as e: m.compile("build/Foo", Foo) - assert caplog.messages[0] == "Foo.A not driven" + assert "Foo.A not driven" in caplog.messages[0] assert caplog.messages[1] == "Foo.A" assert caplog.messages[2] == " Foo.A[0]: Connected" assert caplog.messages[3] == " Foo.A[1]: Unconnected" @@ -46,7 +46,7 @@ class Foo(m.Circuit): with pytest.raises(Exception) as e: m.compile("build/Foo", Foo) - assert caplog.messages[0] == "Foo.A not driven" + assert "Foo.A not driven" in caplog.messages[0] assert caplog.messages[1] == "Foo.A" assert caplog.messages[2] == " Foo.A[0]: Connected" assert caplog.messages[3] == " Foo.A[1]" diff --git a/tests/test_primitives/gold/test_memory_basic.mlir b/tests/test_primitives/gold/test_memory_basic.mlir index a5e5b9ce2..a149d8c6f 100644 --- a/tests/test_primitives/gold/test_memory_basic.mlir +++ b/tests/test_primitives/gold/test_memory_basic.mlir @@ -32,7 +32,7 @@ module attributes {circt.loweringOptions = "locationInfoStyle=none"} { sv.bpassign %9, %0 : i1 } } - %10 = hw.instance "Mem4x5" @Memory(RADDR: %raddr: i2, CLK: %clk: i1, WADDR: %4: i2, WDATA: %5: i5, WE: %6: i1) -> (RDATA: i5) + %10 = hw.instance "Memory_inst0" @Memory(RADDR: %raddr: i2, CLK: %clk: i1, WADDR: %4: i2, WDATA: %5: i5, WE: %6: i1) -> (RDATA: i5) hw.output %10 : i5 } }