cocotb 1.9.2__cp311-cp311-win32.whl → 2.0.0b1__cp311-cp311-win32.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of cocotb might be problematic. Click here for more details.

Files changed (155) hide show
  1. cocotb/{ANSI.py → _ANSI.py} +5 -25
  2. cocotb/__init__.py +76 -332
  3. cocotb/_base_triggers.py +513 -0
  4. cocotb/_bridge.py +187 -0
  5. cocotb/_decorators.py +515 -0
  6. cocotb/_deprecation.py +3 -3
  7. cocotb/_exceptions.py +7 -0
  8. cocotb/_extended_awaitables.py +419 -0
  9. cocotb/_gpi_triggers.py +382 -0
  10. cocotb/_init.py +295 -0
  11. cocotb/_outcomes.py +54 -0
  12. cocotb/_profiling.py +46 -0
  13. cocotb/_py_compat.py +100 -29
  14. cocotb/_scheduler.py +454 -0
  15. cocotb/_test.py +245 -0
  16. cocotb/_test_factory.py +309 -0
  17. cocotb/_test_functions.py +42 -0
  18. cocotb/_typing.py +7 -0
  19. cocotb/_utils.py +296 -0
  20. cocotb/_version.py +3 -7
  21. cocotb/_xunit_reporter.py +66 -0
  22. cocotb/clock.py +271 -108
  23. cocotb/handle.py +1342 -795
  24. cocotb/libs/cocotb.dll +0 -0
  25. cocotb/libs/cocotb.exp +0 -0
  26. cocotb/libs/cocotb.lib +0 -0
  27. cocotb/libs/cocotbfli_modelsim.dll +0 -0
  28. cocotb/libs/cocotbfli_modelsim.exp +0 -0
  29. cocotb/libs/cocotbfli_modelsim.lib +0 -0
  30. cocotb/libs/cocotbutils.dll +0 -0
  31. cocotb/libs/cocotbutils.exp +0 -0
  32. cocotb/libs/cocotbutils.lib +0 -0
  33. cocotb/libs/cocotbvhpi_aldec.dll +0 -0
  34. cocotb/libs/cocotbvhpi_aldec.exp +0 -0
  35. cocotb/libs/cocotbvhpi_aldec.lib +0 -0
  36. cocotb/libs/cocotbvhpi_modelsim.dll +0 -0
  37. cocotb/libs/cocotbvhpi_modelsim.exp +0 -0
  38. cocotb/libs/cocotbvhpi_modelsim.lib +0 -0
  39. cocotb/libs/cocotbvpi_aldec.dll +0 -0
  40. cocotb/libs/cocotbvpi_aldec.exp +0 -0
  41. cocotb/libs/cocotbvpi_aldec.lib +0 -0
  42. cocotb/libs/cocotbvpi_ghdl.dll +0 -0
  43. cocotb/libs/cocotbvpi_ghdl.exp +0 -0
  44. cocotb/libs/cocotbvpi_ghdl.lib +0 -0
  45. cocotb/libs/cocotbvpi_icarus.exp +0 -0
  46. cocotb/libs/cocotbvpi_icarus.lib +0 -0
  47. cocotb/libs/cocotbvpi_icarus.vpl +0 -0
  48. cocotb/libs/cocotbvpi_modelsim.dll +0 -0
  49. cocotb/libs/cocotbvpi_modelsim.exp +0 -0
  50. cocotb/libs/cocotbvpi_modelsim.lib +0 -0
  51. cocotb/libs/embed.dll +0 -0
  52. cocotb/libs/embed.exp +0 -0
  53. cocotb/libs/embed.lib +0 -0
  54. cocotb/libs/gpi.dll +0 -0
  55. cocotb/libs/gpi.exp +0 -0
  56. cocotb/libs/gpi.lib +0 -0
  57. cocotb/libs/gpilog.dll +0 -0
  58. cocotb/libs/gpilog.exp +0 -0
  59. cocotb/libs/gpilog.lib +0 -0
  60. cocotb/libs/pygpilog.dll +0 -0
  61. cocotb/libs/pygpilog.exp +0 -0
  62. cocotb/libs/pygpilog.lib +0 -0
  63. cocotb/{log.py → logging.py} +105 -110
  64. cocotb/queue.py +103 -57
  65. cocotb/regression.py +667 -712
  66. cocotb/result.py +17 -188
  67. cocotb/share/def/aldec.exp +0 -0
  68. cocotb/share/def/aldec.lib +0 -0
  69. cocotb/share/def/ghdl.exp +0 -0
  70. cocotb/share/def/ghdl.lib +0 -0
  71. cocotb/share/def/icarus.exp +0 -0
  72. cocotb/share/def/icarus.lib +0 -0
  73. cocotb/share/def/modelsim.def +1 -0
  74. cocotb/share/def/modelsim.exp +0 -0
  75. cocotb/share/def/modelsim.lib +0 -0
  76. cocotb/share/include/cocotb_utils.h +6 -29
  77. cocotb/share/include/embed.h +5 -28
  78. cocotb/share/include/gpi.h +137 -92
  79. cocotb/share/include/gpi_logging.h +221 -142
  80. cocotb/share/include/py_gpi_logging.h +7 -4
  81. cocotb/share/include/vpi_user_ext.h +4 -26
  82. cocotb/share/lib/verilator/verilator.cpp +59 -54
  83. cocotb/simulator.cp311-win32.exp +0 -0
  84. cocotb/simulator.cp311-win32.lib +0 -0
  85. cocotb/simulator.cp311-win32.pyd +0 -0
  86. cocotb/simulator.pyi +107 -0
  87. cocotb/task.py +434 -212
  88. cocotb/triggers.py +55 -1092
  89. cocotb/types/__init__.py +25 -47
  90. cocotb/types/_abstract_array.py +151 -0
  91. cocotb/types/_array.py +264 -0
  92. cocotb/types/_logic.py +296 -0
  93. cocotb/types/_logic_array.py +834 -0
  94. cocotb/types/{range.py → _range.py} +36 -44
  95. cocotb/types/_resolve.py +76 -0
  96. cocotb/utils.py +119 -587
  97. cocotb-2.0.0b1.dist-info/METADATA +60 -0
  98. cocotb-2.0.0b1.dist-info/RECORD +143 -0
  99. {cocotb-1.9.2.dist-info → cocotb-2.0.0b1.dist-info}/WHEEL +1 -1
  100. cocotb-2.0.0b1.dist-info/entry_points.txt +2 -0
  101. {cocotb-1.9.2.dist-info → cocotb-2.0.0b1.dist-info}/top_level.txt +1 -0
  102. cocotb_tools/__init__.py +0 -0
  103. cocotb_tools/_coverage.py +33 -0
  104. cocotb_tools/_vendor/__init__.py +3 -0
  105. cocotb_tools/check_results.py +65 -0
  106. cocotb_tools/combine_results.py +152 -0
  107. cocotb_tools/config.py +241 -0
  108. {cocotb → cocotb_tools}/ipython_support.py +29 -22
  109. cocotb_tools/makefiles/Makefile.deprecations +27 -0
  110. {cocotb/share → cocotb_tools}/makefiles/Makefile.inc +82 -54
  111. {cocotb/share → cocotb_tools}/makefiles/Makefile.sim +8 -33
  112. {cocotb/share → cocotb_tools}/makefiles/simulators/Makefile.activehdl +9 -16
  113. cocotb_tools/makefiles/simulators/Makefile.cvc +61 -0
  114. cocotb_tools/makefiles/simulators/Makefile.dsim +39 -0
  115. {cocotb/share → cocotb_tools}/makefiles/simulators/Makefile.ghdl +13 -42
  116. cocotb_tools/makefiles/simulators/Makefile.icarus +80 -0
  117. cocotb_tools/makefiles/simulators/Makefile.ius +93 -0
  118. cocotb_tools/makefiles/simulators/Makefile.modelsim +9 -0
  119. cocotb_tools/makefiles/simulators/Makefile.nvc +60 -0
  120. cocotb_tools/makefiles/simulators/Makefile.questa +29 -0
  121. cocotb/share/makefiles/simulators/Makefile.questa → cocotb_tools/makefiles/simulators/Makefile.questa-compat +26 -54
  122. cocotb_tools/makefiles/simulators/Makefile.questa-qisqrun +149 -0
  123. {cocotb/share → cocotb_tools}/makefiles/simulators/Makefile.riviera +17 -56
  124. cocotb_tools/makefiles/simulators/Makefile.vcs +65 -0
  125. {cocotb/share → cocotb_tools}/makefiles/simulators/Makefile.verilator +15 -22
  126. {cocotb/share → cocotb_tools}/makefiles/simulators/Makefile.xcelium +20 -52
  127. cocotb_tools/py.typed +0 -0
  128. {cocotb → cocotb_tools}/runner.py +794 -361
  129. cocotb/_sim_versions.py → cocotb_tools/sim_versions.py +16 -21
  130. pygpi/entry.py +34 -17
  131. pygpi/py.typed +0 -0
  132. cocotb/binary.py +0 -858
  133. cocotb/config.py +0 -289
  134. cocotb/decorators.py +0 -332
  135. cocotb/memdebug.py +0 -35
  136. cocotb/outcomes.py +0 -56
  137. cocotb/scheduler.py +0 -1099
  138. cocotb/share/makefiles/Makefile.deprecations +0 -12
  139. cocotb/share/makefiles/simulators/Makefile.cvc +0 -94
  140. cocotb/share/makefiles/simulators/Makefile.icarus +0 -111
  141. cocotb/share/makefiles/simulators/Makefile.ius +0 -125
  142. cocotb/share/makefiles/simulators/Makefile.modelsim +0 -32
  143. cocotb/share/makefiles/simulators/Makefile.nvc +0 -64
  144. cocotb/share/makefiles/simulators/Makefile.vcs +0 -98
  145. cocotb/types/array.py +0 -309
  146. cocotb/types/logic.py +0 -292
  147. cocotb/types/logic_array.py +0 -298
  148. cocotb/wavedrom.py +0 -199
  149. cocotb/xunit_reporter.py +0 -80
  150. cocotb-1.9.2.dist-info/METADATA +0 -168
  151. cocotb-1.9.2.dist-info/RECORD +0 -121
  152. cocotb-1.9.2.dist-info/entry_points.txt +0 -2
  153. /cocotb/{_vendor/__init__.py → py.typed} +0 -0
  154. {cocotb-1.9.2.dist-info → cocotb-2.0.0b1.dist-info/licenses}/LICENSE +0 -0
  155. {cocotb → cocotb_tools}/_vendor/distutils_version.py +0 -0
@@ -1,33 +1,13 @@
1
+ # Copyright cocotb contributors
1
2
  # Copyright (c) 2013, 2018 Potential Ventures Ltd
2
3
  # Copyright (c) 2013 SolarFlare Communications Inc
3
- # All rights reserved.
4
- #
5
- # Redistribution and use in source and binary forms, with or without
6
- # modification, are permitted provided that the following conditions are met:
7
- # * Redistributions of source code must retain the above copyright
8
- # notice, this list of conditions and the following disclaimer.
9
- # * Redistributions in binary form must reproduce the above copyright
10
- # notice, this list of conditions and the following disclaimer in the
11
- # documentation and/or other materials provided with the distribution.
12
- # * Neither the name of Potential Ventures Ltd,
13
- # SolarFlare Communications Inc nor the
14
- # names of its contributors may be used to endorse or promote products
15
- # derived from this software without specific prior written permission.
16
- #
17
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
- # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
- # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
- # DISCLAIMED. IN NO EVENT SHALL POTENTIAL VENTURES LTD BE LIABLE FOR ANY
21
- # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
- # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
- # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
- # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
- # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
- # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4
+ # Licensed under the Revised BSD License, see LICENSE for details.
5
+ # SPDX-License-Identifier: BSD-3-Clause
27
6
 
28
7
  """
29
- Some constants for doing ANSI stuff.
8
+ Some constants for doing ANSI stuff.
30
9
  """
10
+
31
11
  # flake8: noqa (skip this file for flake8: pypi.python.org/pypi/flake8)
32
12
  _ESCAPE = "\033["
33
13
 
cocotb/__init__.py CHANGED
@@ -1,371 +1,115 @@
1
+ # Copyright cocotb contributors
1
2
  # Copyright (c) 2013 Potential Ventures Ltd
2
3
  # Copyright (c) 2013 SolarFlare Communications Inc
3
- # All rights reserved.
4
+ # Licensed under the Revised BSD License, see LICENSE for details.
5
+ # SPDX-License-Identifier: BSD-3-Clause
6
+ from typing import TYPE_CHECKING, Dict, List, Union
4
7
 
5
- # Redistribution and use in source and binary forms, with or without
6
- # modification, are permitted provided that the following conditions are met:
7
- # * Redistributions of source code must retain the above copyright
8
- # notice, this list of conditions and the following disclaimer.
9
- # * Redistributions in binary form must reproduce the above copyright
10
- # notice, this list of conditions and the following disclaimer in the
11
- # documentation and/or other materials provided with the distribution.
12
- # * Neither the name of Potential Ventures Ltd,
13
- # SolarFlare Communications Inc nor the
14
- # names of its contributors may be used to endorse or promote products
15
- # derived from this software without specific prior written permission.
16
-
17
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
- # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
- # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
- # DISCLAIMED. IN NO EVENT SHALL POTENTIAL VENTURES LTD BE LIABLE FOR ANY
21
- # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
- # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
- # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
- # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
- # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
- # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
-
28
- """
29
- Cocotb is a coroutine, cosimulation framework for writing testbenches in Python.
30
-
31
- See https://docs.cocotb.org for full documentation
32
- """
33
- import logging
34
- import os
35
- import random
36
- import sys
37
- import threading
38
- import time
39
- import warnings
40
- from collections.abc import Coroutine
41
- from typing import Dict, List, Optional, Union
42
-
43
- import cocotb.handle
44
- from cocotb._deprecation import deprecated
45
- from cocotb.log import default_config
46
- from cocotb.regression import RegressionManager
47
- from cocotb.scheduler import Scheduler
48
- from cocotb.task import Task
49
-
50
- from ._version import __version__
51
-
52
- # Things we want in the cocotb namespace
53
- from cocotb.decorators import ( # isort: skip # noqa: F401
54
- coroutine,
55
- external,
56
- function,
8
+ from cocotb._decorators import (
9
+ parametrize,
57
10
  test,
58
11
  )
59
- from cocotb.log import _filter_from_c, _log_from_c # isort: skip # noqa: F401
12
+ from cocotb._test import create_task, start, start_soon
13
+ from cocotb._test_functions import pass_test
14
+
15
+ from ._version import __version__ as _version
16
+
17
+ if TYPE_CHECKING:
18
+ from logging import Logger
19
+ from types import SimpleNamespace
20
+
21
+ from cocotb._scheduler import Scheduler
22
+ from cocotb.handle import SimHandleBase
23
+ from cocotb.regression import RegressionManager
24
+
25
+ __all__ = (
26
+ "RANDOM_SEED",
27
+ "SIM_NAME",
28
+ "SIM_VERSION",
29
+ "__version__",
30
+ "argv",
31
+ "create_task",
32
+ "is_simulation",
33
+ "log",
34
+ "packages",
35
+ "parametrize",
36
+ "pass_test",
37
+ "plusargs",
38
+ "start",
39
+ "start_soon",
40
+ "test",
41
+ "top",
42
+ )
60
43
 
44
+ # Set __module__ on re-exports
45
+ test.__module__ = __name__
46
+ start_soon.__module__ = __name__
47
+ start.__module__ = __name__
48
+ create_task.__module__ = __name__
49
+ parametrize.__module__ = __name__
50
+ pass_test.__module__ = __name__
61
51
 
62
- def _setup_logging() -> None:
63
- default_config()
64
- global log
65
- log = logging.getLogger(__name__)
66
52
 
53
+ __version__ = _version
54
+ """The version of cocotb."""
67
55
 
68
- # Singleton scheduler instance
69
- # NB this cheekily ensures a singleton since we're replacing the reference
70
- # so that cocotb.scheduler gives you the singleton instance and not the
71
- # scheduler package
72
56
 
73
- scheduler: Optional[Scheduler] = None
74
- """The global scheduler instance.
57
+ log: "Logger"
58
+ """An easily accessible :class:`~logging.Logger` for the user.
75
59
 
76
- This is guaranteed to hold a value at test time.
77
- """
60
+ This logger defaults to the :data:`logging.INFO` log level.
78
61
 
79
- regression_manager: Optional[RegressionManager] = None
80
- """The global regression manager instance.
81
-
82
- This is guaranteed to hold a value at test time.
62
+ .. versionchanged:: 2.0
63
+ This was previously the ``"cocotb"`` Logger.
64
+ It is now a Logger under the ``"test"`` namespace.
83
65
  """
84
66
 
85
- argv: Optional[List[str]] = None
86
- """The argument list as seen by the simulator.
87
-
88
- This is guaranteed to hold a value at test time.
89
- """
67
+ _scheduler_inst: "Scheduler"
68
+ """The global scheduler instance."""
90
69
 
91
- argc: Optional[int] = None
92
- """The length of :data:`cocotb.argv`.
70
+ _regression_manager: "RegressionManager"
71
+ """The global regression manager instance."""
93
72
 
94
- This is guaranteed to hold a value at test time.
95
- """
73
+ argv: List[str]
74
+ """The argument list as seen by the simulator."""
96
75
 
97
- plusargs: Optional[Dict[str, Union[bool, str]]] = None
76
+ plusargs: Dict[str, Union[bool, str]]
98
77
  """A dictionary of "plusargs" handed to the simulation.
99
78
 
100
- See :make:var:`PLUSARGS` for details.
101
- This is guaranteed to hold a value at test time.
79
+ See :make:var:`COCOTB_PLUSARGS` for details.
102
80
  """
103
81
 
104
- LANGUAGE: Optional[str] = os.getenv("TOPLEVEL_LANG")
105
- """The value of :make:var:`TOPLEVEL_LANG`.
106
-
107
- This is guaranteed to hold a value at test time.
108
- """
82
+ packages: "SimpleNamespace"
83
+ """A :class:`python:types.SimpleNamespace` of package handles.
109
84
 
110
- SIM_NAME: Optional[str] = None
111
- """The running simulator product information.
85
+ This will be populated with handles at test time if packages can be discovered
86
+ via the GPI.
112
87
 
113
- ``None`` if :mod:`cocotb` was not loaded from a simulator.
88
+ .. versionadded:: 2.0
114
89
  """
115
90
 
116
- SIM_VERSION: Optional[str] = None
117
- """The version of the running simulator.
91
+ SIM_NAME: str
92
+ """The product information of the running simulator."""
118
93
 
119
- ``None`` if :mod:`cocotb` was not loaded from a simulator."""
94
+ SIM_VERSION: str
95
+ """The version of the running simulator."""
120
96
 
121
- RANDOM_SEED: Optional[int] = None
97
+ RANDOM_SEED: int
122
98
  """
123
- The value passed to the Python default random number generator.
99
+ The value passed to the Python global random number generator.
124
100
 
125
- See :envvar:`RANDOM_SEED` for details on how the value is computed.
101
+ See :envvar:`COCOTB_RANDOM_SEED` for details on how the value is computed.
126
102
  This is guaranteed to hold a value at test time.
127
103
  """
128
104
 
129
- _library_coverage = None
130
- """ used for cocotb library coverage """
131
-
132
- top: Optional[cocotb.handle.SimHandleBase] = None
105
+ top: "SimHandleBase"
133
106
  r"""
134
- A handle to the :envvar:`TOPLEVEL` entity/module.
107
+ A handle to the :envvar:`COCOTB_TOPLEVEL` entity/module.
135
108
 
136
109
  This is equivalent to the :term:`DUT` parameter given to cocotb tests, so it can be used wherever that variable can be used.
137
110
  It is particularly useful for extracting information about the :term:`DUT` in module-level class and function definitions;
138
111
  and in parameters to :class:`.TestFactory`\ s.
139
- ``None`` if :mod:`cocotb` was not loaded from a simulator.
140
112
  """
141
113
 
142
-
143
- def fork(coro: Union[Task, Coroutine]) -> Task:
144
- """
145
- Schedule a coroutine to be run concurrently. See :ref:`coroutines` for details on its use.
146
-
147
- .. deprecated:: 1.7.0
148
- This function has been deprecated in favor of :func:`cocotb.start_soon` and :func:`cocotb.start`.
149
- In most cases you can simply substitute ``cocotb.fork`` with ``cocotb.start_soon``.
150
- For more information on when to use ``start_soon`` vs ``start`` see :ref:`coroutines`.
151
- """
152
- warnings.warn(
153
- "cocotb.fork has been deprecated in favor of cocotb.start_soon and cocotb.start.\n"
154
- "In most cases you can simply substitute cocotb.fork with cocotb.start_soon.\n"
155
- "For more information about when you would want to use cocotb.start see the docs,\n"
156
- "https://docs.cocotb.org/en/latest/coroutines.html#concurrent-execution",
157
- DeprecationWarning,
158
- stacklevel=2,
159
- )
160
- return scheduler._add(coro)
161
-
162
-
163
- def start_soon(coro: Union[Task, Coroutine]) -> Task:
164
- """
165
- Schedule a coroutine to be run concurrently.
166
-
167
- Note that this is not an async function,
168
- and the new task will not execute until the calling task yields control.
169
-
170
- .. versionadded:: 1.6.0
171
- """
172
- return scheduler.start_soon(coro)
173
-
174
-
175
- async def start(coro: Union[Task, Coroutine]) -> Task:
176
- """
177
- Schedule a coroutine to be run concurrently, then yield control to allow pending tasks to execute.
178
-
179
- The calling task will resume execution before control is returned to the simulator.
180
-
181
- .. versionadded:: 1.6.0
182
- """
183
- task = scheduler.start_soon(coro)
184
- await cocotb.triggers.NullTrigger()
185
- return task
186
-
187
-
188
- def create_task(coro: Union[Task, Coroutine]) -> Task:
189
- """
190
- Construct a coroutine into a Task without scheduling the Task.
191
-
192
- The Task can later be scheduled with :func:`cocotb.fork`, :func:`cocotb.start`, or
193
- :func:`cocotb.start_soon`.
194
-
195
- .. versionadded:: 1.6.0
196
- """
197
- return cocotb.scheduler.create_task(coro)
198
-
199
-
200
- # FIXME is this really required?
201
- _rlock = threading.RLock()
202
-
203
-
204
- def mem_debug(port):
205
- import cocotb.memdebug
206
-
207
- cocotb.memdebug.start(port)
208
-
209
-
210
- def _initialise_testbench(argv_): # pragma: no cover
211
- """Initialize testbench.
212
-
213
- This function is called after the simulator has elaborated all
214
- entities and is ready to run the test.
215
-
216
- The test must be defined by the environment variables
217
- :envvar:`MODULE` and :envvar:`TESTCASE`.
218
- """
219
- with _rlock:
220
-
221
- if "COCOTB_LIBRARY_COVERAGE" in os.environ:
222
- import coverage
223
-
224
- global _library_coverage
225
- _library_coverage = coverage.coverage(
226
- data_file=".coverage.cocotb",
227
- config_file=False,
228
- branch=True,
229
- include=["{}/*".format(os.path.dirname(__file__))],
230
- )
231
- _library_coverage.start()
232
-
233
- _initialise_testbench_(argv_)
234
-
235
-
236
- def _initialise_testbench_(argv_):
237
- # The body of this function is split in two because no coverage is collected on
238
- # the function that starts the coverage. By splitting it in two we get coverage
239
- # on most of the function.
240
-
241
- global argc, argv
242
- argv = argv_
243
- argc = len(argv)
244
-
245
- root_name = os.getenv("TOPLEVEL")
246
- if root_name is not None:
247
- root_name = root_name.strip()
248
- if root_name == "":
249
- root_name = None
250
- elif "." in root_name:
251
- # Skip any library component of the toplevel
252
- root_name = root_name.split(".", 1)[1]
253
-
254
- # sys.path normally includes "" (the current directory), but does not appear to when python is embedded.
255
- # Add it back because users expect to be able to import files in their test directory.
256
- # TODO: move this to gpi_embed.cpp
257
- sys.path.insert(0, "")
258
-
259
- _setup_logging()
260
-
261
- # From https://www.python.org/dev/peps/pep-0565/#recommended-filter-settings-for-test-runners
262
- # If the user doesn't want to see these, they can always change the global
263
- # warning settings in their test module.
264
- if not sys.warnoptions:
265
- warnings.simplefilter("default")
266
-
267
- from cocotb import simulator
268
-
269
- global SIM_NAME, SIM_VERSION
270
- SIM_NAME = simulator.get_simulator_product().strip()
271
- SIM_VERSION = simulator.get_simulator_version().strip()
272
-
273
- cocotb.log.info(f"Running on {SIM_NAME} version {SIM_VERSION}")
274
-
275
- memcheck_port = os.getenv("MEMCHECK")
276
- if memcheck_port is not None:
277
- mem_debug(int(memcheck_port))
278
-
279
- log.info(
280
- "Running tests with cocotb v%s from %s"
281
- % (__version__, os.path.dirname(__file__))
282
- )
283
-
284
- # Create the base handle type
285
-
286
- _process_plusargs()
287
-
288
- # Seed the Python random number generator to make this repeatable
289
- global RANDOM_SEED
290
- RANDOM_SEED = os.getenv("RANDOM_SEED")
291
-
292
- if RANDOM_SEED is None:
293
- if "ntb_random_seed" in plusargs:
294
- RANDOM_SEED = eval(plusargs["ntb_random_seed"])
295
- elif "seed" in plusargs:
296
- RANDOM_SEED = eval(plusargs["seed"])
297
- else:
298
- RANDOM_SEED = int(time.time())
299
- log.info("Seeding Python random module with %d" % (RANDOM_SEED))
300
- else:
301
- RANDOM_SEED = int(RANDOM_SEED)
302
- log.info("Seeding Python random module with supplied seed %d" % (RANDOM_SEED))
303
- random.seed(RANDOM_SEED)
304
-
305
- # Setup DUT object
306
- from cocotb import simulator
307
-
308
- handle = simulator.get_root_handle(root_name)
309
- if not handle:
310
- raise RuntimeError(f"Can not find root handle ({root_name})")
311
-
312
- global top
313
- top = cocotb.handle.SimHandle(handle)
314
-
315
- global regression_manager
316
- try:
317
- regression_manager = RegressionManager.from_discovery(top)
318
- except BaseException as e:
319
- log.error(e)
320
- simulator.stop_simulator()
321
- _stop_library_coverage()
322
- return # pragma: no cover
323
-
324
- global scheduler
325
- scheduler = Scheduler(handle_result=regression_manager._handle_result)
326
-
327
- # start Regression Manager
328
- regression_manager._execute()
329
-
330
-
331
- def _stop_library_coverage() -> None:
332
- if _library_coverage is not None:
333
- # TODO: move this once we have normal shutdown behavior to _sim_event
334
- _library_coverage.stop()
335
- _library_coverage.save() # pragma: no cover
336
-
337
-
338
- def _sim_event(message):
339
- """Function that can be called externally to signal an event."""
340
- from cocotb.result import SimFailure
341
-
342
- # We simply return here as the simulator will exit
343
- # so no cleanup is needed
344
- msg = f"Failing test at simulator request before test run completion: {message}"
345
- if scheduler is not None:
346
- scheduler.log.error(msg)
347
- scheduler._finish_scheduler(SimFailure(msg))
348
- else:
349
- log.error(msg)
350
- _stop_library_coverage()
351
-
352
-
353
- @deprecated("This function is now private")
354
- def process_plusargs() -> None:
355
-
356
- _process_plusargs()
357
-
358
-
359
- def _process_plusargs() -> None:
360
-
361
- global plusargs
362
-
363
- plusargs = {}
364
-
365
- for option in cocotb.argv:
366
- if option.startswith("+"):
367
- if option.find("=") != -1:
368
- (name, value) = option[1:].split("=", 1)
369
- plusargs[name] = value
370
- else:
371
- plusargs[option[1:]] = True
114
+ is_simulation: bool = False
115
+ """``True`` if cocotb was loaded in a simulation."""