Skip to content

Commit

Permalink
Add global alias for DUT parameter
Browse files Browse the repository at this point in the history
This feature will allow users to parameterize module-level classes and
functions, and arguments to `TestFactory`s.
  • Loading branch information
ktbarrett committed Oct 20, 2020
1 parent 6eb637a commit fe605fa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cocotb/__init__.py
Expand Up @@ -128,6 +128,16 @@ def _reopen_stream_with_buffering(stream_name):
_library_coverage = None
""" used for cocotb library coverage """

top = None # type: cocotb.handle.SimHandleBase
"""
A handle to the :envvar:`TOPLEVEL` entity/module.
This is equivalent to the :term:`DUT` parameter given to cocotb tests, so it can be used wherever that variable can be used.
It is particularly useful for extracting information about the :term:`DUT` in module-level class and function definitions;
and in parameters to :class:`~cocotb.regression.TestFactory`s.
``None`` if :mod:`cocotb` was not loaded from a simulator.
"""


def fork(coro):
""" Schedule a coroutine to be run concurrently. See :ref:`coroutines` for details on its use. """
Expand Down Expand Up @@ -238,11 +248,12 @@ def _initialise_testbench(argv_):
if not handle:
raise RuntimeError("Can not find root handle ({})".format(root_name))

dut = cocotb.handle.SimHandle(handle)
global top
top = cocotb.handle.SimHandle(handle)

# start Regression Manager
global regression_manager
regression_manager = RegressionManager.from_discovery(dut)
regression_manager = RegressionManager.from_discovery(top)
regression_manager.execute()

_rlock.release()
Expand Down
2 changes: 2 additions & 0 deletions documentation/source/library_reference.rst
Expand Up @@ -369,6 +369,8 @@ Other Runtime Information

.. autodata:: cocotb.LANGUAGE

.. autodata:: cocotb.top


Signal Tracer for WaveDrom
--------------------------
Expand Down
1 change: 1 addition & 0 deletions documentation/source/newsfragments/2134.feature.rst
@@ -0,0 +1 @@
Made the handle to :envvar:`TOPLEVEL`, typically seen as the first argument to a cocotb test function, available globally as :data:`cocotb.top`.

0 comments on commit fe605fa

Please sign in to comment.