Skip to content

Commit

Permalink
Fixes #1026.
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsAsplund committed Jun 25, 2024
1 parent 76e9732 commit 1bad679
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
23 changes: 23 additions & 0 deletions vunit/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ class ConfigurationVisitor(object):
An interface to visit simulation run configurations
"""

def __init__(self, design_unit):
self.design_unit = design_unit

def _check_enabled(self):
pass

Expand Down Expand Up @@ -258,6 +261,24 @@ def set_post_check(self, value):
for config in configs.values():
config.post_check = value

@staticmethod
def _check_architectures(design_unit):
"""
Check that an entity which has been classified as a VUnit test bench
has exactly one architecture. Raise RuntimeError otherwise.
"""
if design_unit.is_entity:
if not design_unit.architecture_names:
raise RuntimeError(f"Test bench '{design_unit.name!s}' has no architecture.")

if len(design_unit.architecture_names) > 1:
archs = ", ".join(
f"{name!s}:{Path(fname).name!s}" for name, fname in sorted(design_unit.architecture_names.items())
)
raise RuntimeError(
"Test bench not allowed to have multiple architectures. " f"Entity {design_unit.name!s} has {archs}"
)

def add_config( # pylint: disable=too-many-arguments
self,
name,
Expand All @@ -276,6 +297,8 @@ def add_config( # pylint: disable=too-many-arguments
if name in (DEFAULT_NAME, ""):
raise ValueError(f"Illegal configuration name {name!r}. Must be non-empty string")

self._check_architectures(self.design_unit)

for configs in self.get_configuration_dicts():
if name in configs:
raise RuntimeError(f"Configuration name {name!s} already defined")
Expand Down
25 changes: 2 additions & 23 deletions vunit/test/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"""

import logging
from pathlib import Path
import re
import bisect
import collections
Expand All @@ -32,8 +31,7 @@ class TestBench(ConfigurationVisitor):
"""

def __init__(self, design_unit, database=None):
ConfigurationVisitor.__init__(self)
self.design_unit = design_unit
ConfigurationVisitor.__init__(self, design_unit)
self._database = database

self._individual_tests = False
Expand Down Expand Up @@ -76,24 +74,6 @@ def get_default_config(self):
raise RuntimeError(f"Test bench {self.library_name!s}.{self.name!s} has individually configured tests")
return self._configs[DEFAULT_NAME]

@staticmethod
def _check_architectures(design_unit):
"""
Check that an entity which has been classified as a VUnit test bench
has exactly one architecture. Raise RuntimeError otherwise.
"""
if design_unit.is_entity:
if not design_unit.architecture_names:
raise RuntimeError(f"Test bench '{design_unit.name!s}' has no architecture.")

if len(design_unit.architecture_names) > 1:
archs = ", ".join(
f"{name!s}:{Path(fname).name!s}" for name, fname in sorted(design_unit.architecture_names.items())
)
raise RuntimeError(
"Test bench not allowed to have multiple architectures. " f"Entity {design_unit.name!s} has {archs}"
)

def create_tests(self, simulator_if, elaborate_only, test_list=None):
"""
Create all test cases from this test bench
Expand Down Expand Up @@ -332,10 +312,9 @@ class TestConfigurationVisitor(ConfigurationVisitor):
"""

def __init__(self, test, design_unit, enable_configuration, default_config):
ConfigurationVisitor.__init__(self)
ConfigurationVisitor.__init__(self, design_unit)
self._test = test
assert test.is_explicit
self.design_unit = design_unit
self._enable_configuration = enable_configuration
self._configs = OrderedDict({default_config.name: default_config})

Expand Down

0 comments on commit 1bad679

Please sign in to comment.