From 56f4d6b96a591bf3cce86efb539698c47d32b1cf Mon Sep 17 00:00:00 2001 From: Rithika SridharBabu Date: Wed, 11 Nov 2026 17:29:24 -0800 Subject: [PATCH] Handle empty cores in the VUnit backend --- edalize/vunit.py | 2 +- tests/test_vunit.py | 56 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/edalize/vunit.py b/edalize/vunit.py index 90ad72249..c214cd6bd 100644 --- a/edalize/vunit.py +++ b/edalize/vunit.py @@ -63,7 +63,7 @@ def configure_main(self): # vunit does not allow empty library name or 'work', so we use `vunit_test_runner_lib`: libraries = OrderedDict() - core_files = {} + core_files = {core: [] for core in self.edam.get("dependencies", {})} depend = {} for f in src_files: lib = f.logical_name if f.logical_name else "vunit_test_runner_lib" diff --git a/tests/test_vunit.py b/tests/test_vunit.py index e471acd53..58514958e 100644 --- a/tests/test_vunit.py +++ b/tests/test_vunit.py @@ -97,6 +97,62 @@ def subprocess_intercept(args, **kwargs): hooks.main.assert_called_with(vu_mock) +@pytest.mark.parametrize("with_source_files", [True, False]) +def test_vunit_empty_cores(tmp_path, monkeypatch, with_source_files): + import runpy + import sys + from types import ModuleType + + from edalize.edatool import get_edatool + + sources = { + "design.vhd": MagicMock(), + "dependency.vhd": MagicMock(), + } + files = ( + [ + {"name": name, "file_type": "vhdlSource", "core": core} + for name, core in ( + ("design.vhd", "design"), + ("dependency.vhd", "dependency"), + ) + ] + if with_source_files + else [] + ) + edam = { + "name": "empty_cores", + "toplevel": "top", + "files": files, + "dependencies": { + "empty": [], + "dependency": [], + "design": ["dependency", "empty"], + }, + } + backend = get_edatool("vunit")(edam=edam, work_root=str(tmp_path)) + backend.configure() + + hooks = MagicMock() + vu = hooks.create.return_value + vu.add_library.return_value.add_source_file.side_effect = lambda name: sources[name] + hooks_module = ModuleType("edalize.vunit_hooks") + hooks_module.VUnitRunner = MagicMock(return_value=hooks) + monkeypatch.setitem(sys.modules, "edalize.vunit_hooks", hooks_module) + + result = runpy.run_path(str(tmp_path / "run.py")) + + assert result["core_files"]["empty"] == [] + if with_source_files: + sources["design.vhd"].add_dependency_on.assert_any_call( + [sources["dependency.vhd"]] + ) + sources["dependency.vhd"].add_dependency_on.assert_not_called() + else: + vu.add_library.assert_not_called() + hooks.main.assert_called_once_with(vu) + + if __name__ == "__main__": from os.path import dirname import sys