Skip to content

Commit d1330d6

Browse files
committed
Added documentation for the handling of VHDL configurations.
1 parent 6bc3001 commit d1330d6

6 files changed

Lines changed: 82 additions & 13 deletions

File tree

docs/py/ui.rst

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,31 @@ pre_config and post_check :ref:`callback functions <pre_and_post_hooks>`.
2424
User :ref:`attributes <attributes>` can also be added as a part of a
2525
configuration.
2626

27-
Configurations can either be unique for each test case or must be
28-
common for the entire test bench depending on the situation. For test
29-
benches without test such as `tb_example` in the User Guide the
30-
configuration is common for the entire test bench. For test benches
31-
containing tests such as `tb_example_many` the configuration is done
32-
for each test case. If the ``run_all_in_same_sim`` attribute has been used
27+
VHDL configurations for test bench entities are automatically discovered
28+
and added to the set of configurations created in Python.
29+
30+
Python-defined configurations can either be unique for each test case or
31+
must be common for the entire test bench depending on the situation.
32+
For test benches without tests such as `tb_example` in the User Guide
33+
the configuration is common for the entire test bench. For test benches
34+
containing tests such as `tb_example_many` the configuration is done for
35+
each test case. If the ``run_all_in_same_sim`` attribute has been used
3336
configuration is performed at the test bench level even if there are
3437
individual test within since they must run in the same simulation.
3538

36-
In a VUnit all test benches and test cases are created with an unnamed default
39+
In VUnit all test benches and test cases are created with an unnamed default
3740
configuration which is modified by different methods such as ``set_generic`` etc.
3841
In addition to the unnamed default configuration multiple named configurations
39-
can be derived from it by using the ``add_config`` method. The default
40-
configuration is only run if there are no named configurations.
42+
can be derived from it by using the ``add_config`` method or by defining a
43+
VHDL configuration. The default configuration is only run if there are no
44+
named configurations.
45+
46+
Named configurations can be retrieved from test benches and tests using the
47+
``get_configs`` methods and then modified using methods such as ``set_pre_config``.
48+
This is especially useful for VHDL configurations which are automatically
49+
detected and added without any of the configuration capabilities provided
50+
by the Python API. Note that generics can't be added to a VHDL-defined
51+
configuration as that is not allowed in VHDL.
4152

4253
.. _attributes:
4354

docs/py/vunit.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ Test
3030

3131
.. autoclass:: vunit.ui.test.Test()
3232

33+
Configuration
34+
-------------
35+
36+
.. autoclass:: vunit.ui.configuration.Configuration()
37+
:inherited-members:
38+
3339
Results
3440
-------
3541

@@ -46,4 +52,4 @@ Results
4652
The name of the simulation option (See :ref:`Simulation options <sim_options>`)
4753

4854
.. |configurations| replace::
49-
:ref:`configurations <configurations>`
55+
:ref:`configurations <configurations>`

docs/run/user_guide.rst

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ A (close to) minimal VUnit testbench looks like this
2323
context vunit_lib.vunit_context;
2424
2525
entity tb_minimal is
26-
generic (runner_cfg : string := runner_cfg_default);
26+
generic (runner_cfg : string);
2727
end entity;
2828
2929
architecture tb of tb_minimal is
@@ -40,8 +40,7 @@ It has the following important properties
4040

4141
- The VUnit functionality is located in the ``vunit_lib`` library and is included with the library and context
4242
statements in the first two lines.
43-
- The ``runner_cfg`` generic is used to control the testbench from PR. If the testbench is used standalone you will
44-
need a default value, ``runner_cfg_default``, for the generic. Note that the generic **must** be named
43+
- The ``runner_cfg`` generic is used to control the testbench from PR. Note that the generic **must** be named
4544
``runner_cfg`` for the testbench to be recognized by PR (there is an exception which we'll get to later).
4645
- Every VUnit testbench has a main controlling process. It's labelled ``test_runner`` in this example but the name
4746
is not important. The process starts by setting up VUnit using the ``test_runner_setup`` procedure with
@@ -637,6 +636,43 @@ the ability to read error counters based on assert statements. Failures like div
637636
operations are other examples that won't be handle gracefully in this mode and not something that VHDL-2017 will
638637
solve.
639638

639+
Testbenches with VHDL Configurations
640+
------------------------------------
641+
642+
If there are VHDL configurations defined for the testbench entity, each configuration, and not the testbench
643+
entity, defines a top-level for the simulation. VUnit automatically detects these VHDL configurations and treat
644+
them as a special case of the larger testbench configuration concept provided by VUnit, see
645+
:ref:`configurations <configurations>`.
646+
647+
VHDL doesn't allow setting generics when the top-level is a VHDL configuration which prevents the `runner_cfg`
648+
generic to be set by PR. To work around this limitation PR provides a `runner.cfg` file containing the same
649+
information. This file is read by `test_runner_setup` whenever its `runner_cfg` parameter is set to
650+
`null_runner_cfg`. An example is shown below.
651+
652+
.. code-block:: vhdl
653+
654+
library vunit_lib;
655+
context vunit_lib.vunit_context;
656+
657+
entity tb_minimal is
658+
generic (runner_cfg : string := null_runner_cfg);
659+
end entity;
660+
661+
architecture tb of tb_minimal is
662+
begin
663+
test_runner : process
664+
begin
665+
test_runner_setup(runner, runner_cfg);
666+
667+
...
668+
669+
test_runner_cleanup(runner);
670+
end process;
671+
end architecture;
672+
673+
Note that the `runner_cfg` generic must remain present since this is the token used by VUnit test scanning
674+
to distinguish testbench entities from other entities.
675+
640676
Special Paths
641677
-------------
642678

vunit/ui/configuration.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ def get_configuration_dicts(self):
3535
return self._selected_cfg_dicts
3636

3737
def add_config(self, *args, **kwargs):
38+
"""
39+
This method is inherited from the superclass but not defined for this class. New
40+
configurations are added to :class:`.TestBench` or :class:`.Test` objects.
41+
"""
3842
raise RuntimeError(
3943
f"{type(self)} do not allow addition of new configurations, only modification of existing ones."
4044
)

vunit/ui/test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ def add_config( # pylint: disable=too-many-arguments
9090
)
9191

9292
def get_configs(self, pattern="*"):
93+
"""
94+
Get test configurations matching pattern.
95+
96+
:param pattern: A wildcard pattern matching the configuration name(s).
97+
:returns: A :class:`.Configuration` object
98+
"""
9399
return Configuration(self._test_case, pattern)
94100

95101
def set_attribute(self, name, value):

vunit/ui/testbench.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ def add_config( # pylint: disable=too-many-arguments
185185
)
186186

187187
def get_configs(self, pattern="*"):
188+
"""
189+
Get test bench configurations matching pattern.
190+
191+
:param pattern: A wildcard pattern matching the configuration name(s).
192+
:returns: A :class:`.Configuration` object
193+
"""
188194
return Configuration(self._test_bench, pattern)
189195

190196
def test(self, name):

0 commit comments

Comments
 (0)