cocotb 1.9.2__cp311-cp311-win_amd64.whl → 2.0.0rc2__cp311-cp311-win_amd64.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 (161) hide show
  1. cocotb/_ANSI.py +65 -0
  2. cocotb/__init__.py +81 -327
  3. cocotb/_base_triggers.py +515 -0
  4. cocotb/_bridge.py +186 -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 +385 -0
  10. cocotb/_init.py +301 -0
  11. cocotb/_outcomes.py +54 -0
  12. cocotb/_profiling.py +46 -0
  13. cocotb/_py_compat.py +114 -29
  14. cocotb/_scheduler.py +448 -0
  15. cocotb/_test.py +248 -0
  16. cocotb/_test_factory.py +312 -0
  17. cocotb/_test_functions.py +42 -0
  18. cocotb/_typing.py +7 -0
  19. cocotb/_utils.py +274 -0
  20. cocotb/_version.py +3 -7
  21. cocotb/_xunit_reporter.py +66 -0
  22. cocotb/clock.py +353 -108
  23. cocotb/debug.py +24 -0
  24. cocotb/handle.py +1370 -793
  25. cocotb/libs/cocotb.dll +0 -0
  26. cocotb/libs/cocotb.exp +0 -0
  27. cocotb/libs/cocotb.lib +0 -0
  28. cocotb/libs/cocotbfli_modelsim.dll +0 -0
  29. cocotb/libs/cocotbfli_modelsim.exp +0 -0
  30. cocotb/libs/cocotbfli_modelsim.lib +0 -0
  31. cocotb/libs/cocotbutils.dll +0 -0
  32. cocotb/libs/cocotbutils.exp +0 -0
  33. cocotb/libs/cocotbutils.lib +0 -0
  34. cocotb/libs/cocotbvhpi_aldec.dll +0 -0
  35. cocotb/libs/cocotbvhpi_aldec.exp +0 -0
  36. cocotb/libs/cocotbvhpi_aldec.lib +0 -0
  37. cocotb/libs/cocotbvhpi_modelsim.dll +0 -0
  38. cocotb/libs/cocotbvhpi_modelsim.exp +0 -0
  39. cocotb/libs/cocotbvhpi_modelsim.lib +0 -0
  40. cocotb/libs/cocotbvpi_aldec.dll +0 -0
  41. cocotb/libs/cocotbvpi_aldec.exp +0 -0
  42. cocotb/libs/cocotbvpi_aldec.lib +0 -0
  43. cocotb/libs/cocotbvpi_ghdl.dll +0 -0
  44. cocotb/libs/cocotbvpi_ghdl.exp +0 -0
  45. cocotb/libs/cocotbvpi_ghdl.lib +0 -0
  46. cocotb/libs/cocotbvpi_icarus.exp +0 -0
  47. cocotb/libs/cocotbvpi_icarus.lib +0 -0
  48. cocotb/libs/cocotbvpi_icarus.vpl +0 -0
  49. cocotb/libs/cocotbvpi_modelsim.dll +0 -0
  50. cocotb/libs/cocotbvpi_modelsim.exp +0 -0
  51. cocotb/libs/cocotbvpi_modelsim.lib +0 -0
  52. cocotb/libs/embed.dll +0 -0
  53. cocotb/libs/embed.exp +0 -0
  54. cocotb/libs/embed.lib +0 -0
  55. cocotb/libs/gpi.dll +0 -0
  56. cocotb/libs/gpi.exp +0 -0
  57. cocotb/libs/gpi.lib +0 -0
  58. cocotb/libs/gpilog.dll +0 -0
  59. cocotb/libs/gpilog.exp +0 -0
  60. cocotb/libs/gpilog.lib +0 -0
  61. cocotb/libs/pygpilog.dll +0 -0
  62. cocotb/libs/pygpilog.exp +0 -0
  63. cocotb/libs/pygpilog.lib +0 -0
  64. cocotb/logging.py +424 -0
  65. cocotb/queue.py +103 -57
  66. cocotb/regression.py +680 -717
  67. cocotb/result.py +17 -188
  68. cocotb/share/def/aldec.exp +0 -0
  69. cocotb/share/def/aldec.lib +0 -0
  70. cocotb/share/def/ghdl.exp +0 -0
  71. cocotb/share/def/ghdl.lib +0 -0
  72. cocotb/share/def/icarus.exp +0 -0
  73. cocotb/share/def/icarus.lib +0 -0
  74. cocotb/share/def/modelsim.def +1 -0
  75. cocotb/share/def/modelsim.exp +0 -0
  76. cocotb/share/def/modelsim.lib +0 -0
  77. cocotb/share/include/cocotb_utils.h +9 -32
  78. cocotb/share/include/embed.h +7 -30
  79. cocotb/share/include/gpi.h +331 -137
  80. cocotb/share/include/gpi_logging.h +221 -142
  81. cocotb/share/include/py_gpi_logging.h +8 -5
  82. cocotb/share/include/vpi_user_ext.h +4 -26
  83. cocotb/share/lib/verilator/verilator.cpp +80 -67
  84. cocotb/simtime.py +230 -0
  85. cocotb/simulator.cp311-win_amd64.exp +0 -0
  86. cocotb/simulator.cp311-win_amd64.lib +0 -0
  87. cocotb/simulator.cp311-win_amd64.pyd +0 -0
  88. cocotb/simulator.pyi +107 -0
  89. cocotb/task.py +478 -213
  90. cocotb/triggers.py +55 -1092
  91. cocotb/types/__init__.py +28 -47
  92. cocotb/types/_abstract_array.py +151 -0
  93. cocotb/types/_array.py +295 -0
  94. cocotb/types/_indexing.py +17 -0
  95. cocotb/types/_logic.py +333 -0
  96. cocotb/types/_logic_array.py +868 -0
  97. cocotb/types/{range.py → _range.py} +47 -48
  98. cocotb/types/_resolve.py +76 -0
  99. cocotb/utils.py +58 -646
  100. cocotb-2.0.0rc2.dist-info/METADATA +60 -0
  101. cocotb-2.0.0rc2.dist-info/RECORD +146 -0
  102. {cocotb-1.9.2.dist-info → cocotb-2.0.0rc2.dist-info}/WHEEL +1 -1
  103. cocotb-2.0.0rc2.dist-info/entry_points.txt +2 -0
  104. {cocotb-1.9.2.dist-info → cocotb-2.0.0rc2.dist-info/licenses}/LICENSE +1 -0
  105. {cocotb-1.9.2.dist-info → cocotb-2.0.0rc2.dist-info}/top_level.txt +1 -0
  106. cocotb_tools/__init__.py +0 -0
  107. cocotb_tools/_coverage.py +33 -0
  108. cocotb_tools/_vendor/__init__.py +3 -0
  109. cocotb_tools/check_results.py +65 -0
  110. cocotb_tools/combine_results.py +152 -0
  111. cocotb_tools/config.py +241 -0
  112. {cocotb → cocotb_tools}/ipython_support.py +29 -22
  113. cocotb_tools/makefiles/Makefile.deprecations +27 -0
  114. {cocotb/share → cocotb_tools}/makefiles/Makefile.inc +77 -55
  115. {cocotb/share → cocotb_tools}/makefiles/Makefile.sim +16 -33
  116. {cocotb/share → cocotb_tools}/makefiles/simulators/Makefile.activehdl +9 -16
  117. cocotb_tools/makefiles/simulators/Makefile.cvc +61 -0
  118. cocotb_tools/makefiles/simulators/Makefile.dsim +39 -0
  119. {cocotb/share → cocotb_tools}/makefiles/simulators/Makefile.ghdl +13 -42
  120. cocotb_tools/makefiles/simulators/Makefile.icarus +80 -0
  121. cocotb_tools/makefiles/simulators/Makefile.ius +93 -0
  122. cocotb_tools/makefiles/simulators/Makefile.modelsim +9 -0
  123. cocotb_tools/makefiles/simulators/Makefile.nvc +60 -0
  124. cocotb_tools/makefiles/simulators/Makefile.questa +29 -0
  125. cocotb/share/makefiles/simulators/Makefile.questa → cocotb_tools/makefiles/simulators/Makefile.questa-compat +26 -54
  126. cocotb_tools/makefiles/simulators/Makefile.questa-qisqrun +149 -0
  127. {cocotb/share → cocotb_tools}/makefiles/simulators/Makefile.riviera +17 -56
  128. cocotb_tools/makefiles/simulators/Makefile.vcs +65 -0
  129. {cocotb/share → cocotb_tools}/makefiles/simulators/Makefile.verilator +15 -22
  130. {cocotb/share → cocotb_tools}/makefiles/simulators/Makefile.xcelium +20 -52
  131. cocotb_tools/py.typed +0 -0
  132. cocotb_tools/runner.py +1868 -0
  133. cocotb/_sim_versions.py → cocotb_tools/sim_versions.py +16 -21
  134. pygpi/entry.py +34 -18
  135. pygpi/py.typed +0 -0
  136. cocotb/ANSI.py +0 -92
  137. cocotb/binary.py +0 -858
  138. cocotb/config.py +0 -289
  139. cocotb/decorators.py +0 -332
  140. cocotb/log.py +0 -303
  141. cocotb/memdebug.py +0 -35
  142. cocotb/outcomes.py +0 -56
  143. cocotb/runner.py +0 -1400
  144. cocotb/scheduler.py +0 -1099
  145. cocotb/share/makefiles/Makefile.deprecations +0 -12
  146. cocotb/share/makefiles/simulators/Makefile.cvc +0 -94
  147. cocotb/share/makefiles/simulators/Makefile.icarus +0 -111
  148. cocotb/share/makefiles/simulators/Makefile.ius +0 -125
  149. cocotb/share/makefiles/simulators/Makefile.modelsim +0 -32
  150. cocotb/share/makefiles/simulators/Makefile.nvc +0 -64
  151. cocotb/share/makefiles/simulators/Makefile.vcs +0 -98
  152. cocotb/types/array.py +0 -309
  153. cocotb/types/logic.py +0 -292
  154. cocotb/types/logic_array.py +0 -298
  155. cocotb/wavedrom.py +0 -199
  156. cocotb/xunit_reporter.py +0 -80
  157. cocotb-1.9.2.dist-info/METADATA +0 -168
  158. cocotb-1.9.2.dist-info/RECORD +0 -121
  159. cocotb-1.9.2.dist-info/entry_points.txt +0 -2
  160. /cocotb/{_vendor/__init__.py → py.typed} +0 -0
  161. {cocotb → cocotb_tools}/_vendor/distutils_version.py +0 -0
cocotb/_ANSI.py ADDED
@@ -0,0 +1,65 @@
1
+ # Copyright cocotb contributors
2
+ # Copyright (c) 2013, 2018 Potential Ventures Ltd
3
+ # Copyright (c) 2013 SolarFlare Communications Inc
4
+ # Licensed under the Revised BSD License, see LICENSE for details.
5
+ # SPDX-License-Identifier: BSD-3-Clause
6
+
7
+ from cocotb._py_compat import StrEnum
8
+
9
+ _ESCAPE = "\033["
10
+
11
+
12
+ class ANSI(StrEnum):
13
+ """ANSI escape codes for coloring output.
14
+
15
+ The color names supported are ``[BRIGHT_]{BLACK|RED|GREEN|YELLOW|BLUE|MAGENTA|CYAN|WHITE}{_FG|_BG}``.
16
+
17
+ Variables that end in ``_FG`` will color the character or symbol ("foreground")
18
+ and variables that end in ``_BG`` will color the background.
19
+
20
+ Foreground and background colors can be combined together with a ``+``.
21
+ Setting a new foreground color will override the previous foreground, likewise with background colors.
22
+
23
+ Use ``DEFAULT_FG`` and ``DEFAULT_BG`` to reset the coloring to the default colors for the foreground and background, respectively.
24
+ Or use ``DEFAULT`` to reset both.
25
+ """
26
+
27
+ DEFAULT_FG = _ESCAPE + "39m"
28
+ DEFAULT_BG = _ESCAPE + "49m"
29
+ DEFAULT = DEFAULT_BG + DEFAULT_FG
30
+
31
+ BLACK_FG = _ESCAPE + "30m"
32
+ RED_FG = _ESCAPE + "31m"
33
+ GREEN_FG = _ESCAPE + "32m"
34
+ YELLOW_FG = _ESCAPE + "33m"
35
+ BLUE_FG = _ESCAPE + "34m"
36
+ MAGENTA_FG = _ESCAPE + "35m"
37
+ CYAN_FG = _ESCAPE + "36m"
38
+ WHITE_FG = _ESCAPE + "37m"
39
+
40
+ BLACK_BG = _ESCAPE + "40m"
41
+ RED_BG = _ESCAPE + "41m"
42
+ GREEN_BG = _ESCAPE + "42m"
43
+ YELLOW_BG = _ESCAPE + "43m"
44
+ BLUE_BG = _ESCAPE + "44m"
45
+ MAGENTA_BG = _ESCAPE + "45m"
46
+ CYAN_BG = _ESCAPE + "46m"
47
+ WHITE_BG = _ESCAPE + "47m"
48
+
49
+ BRIGHT_BLACK_FG = _ESCAPE + "90m"
50
+ BRIGHT_RED_FG = _ESCAPE + "91m"
51
+ BRIGHT_GREEN_FG = _ESCAPE + "92m"
52
+ BRIGHT_YELLOW_FG = _ESCAPE + "93m"
53
+ BRIGHT_BLUE_FG = _ESCAPE + "94m"
54
+ BRIGHT_MAGENTA_FG = _ESCAPE + "95m"
55
+ BRIGHT_CYAN_FG = _ESCAPE + "96m"
56
+ BRIGHT_WHITE_FG = _ESCAPE + "97m"
57
+
58
+ BRIGHT_BLACK_BG = _ESCAPE + "100m"
59
+ BRIGHT_RED_BG = _ESCAPE + "101m"
60
+ BRIGHT_GREEN_BG = _ESCAPE + "102m"
61
+ BRIGHT_YELLOW_BG = _ESCAPE + "103m"
62
+ BRIGHT_BLUE_BG = _ESCAPE + "104m"
63
+ BRIGHT_MAGENTA_BG = _ESCAPE + "105m"
64
+ BRIGHT_CYAN_BG = _ESCAPE + "106m"
65
+ BRIGHT_WHITE_BG = _ESCAPE + "107m"
cocotb/__init__.py CHANGED
@@ -1,371 +1,125 @@
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
-
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
4
+ # Licensed under the Revised BSD License, see LICENSE for details.
5
+ # SPDX-License-Identifier: BSD-3-Clause
36
6
  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
7
+ from typing import TYPE_CHECKING, Dict, List, Union
42
8
 
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,
9
+ from cocotb._decorators import (
10
+ parametrize,
57
11
  test,
58
12
  )
59
- from cocotb.log import _filter_from_c, _log_from_c # isort: skip # noqa: F401
13
+ from cocotb._test import create_task, start, start_soon
14
+ from cocotb._test_functions import pass_test
15
+
16
+ from ._version import __version__ as _version
17
+
18
+ if TYPE_CHECKING:
19
+ from logging import Logger
20
+ from types import SimpleNamespace
21
+
22
+ from cocotb._scheduler import Scheduler
23
+ from cocotb.handle import SimHandleBase
24
+ from cocotb.regression import RegressionManager
25
+
26
+ __all__ = (
27
+ "RANDOM_SEED",
28
+ "SIM_NAME",
29
+ "SIM_VERSION",
30
+ "__version__",
31
+ "argv",
32
+ "create_task",
33
+ "is_simulation",
34
+ "log",
35
+ "packages",
36
+ "parametrize",
37
+ "pass_test",
38
+ "plusargs",
39
+ "start",
40
+ "start_soon",
41
+ "test",
42
+ "top",
43
+ )
60
44
 
45
+ # Set __module__ on re-exports
46
+ test.__module__ = __name__
47
+ start_soon.__module__ = __name__
48
+ start.__module__ = __name__
49
+ create_task.__module__ = __name__
50
+ parametrize.__module__ = __name__
51
+ pass_test.__module__ = __name__
61
52
 
62
- def _setup_logging() -> None:
63
- default_config()
64
- global log
65
- log = logging.getLogger(__name__)
66
53
 
54
+ __version__: str = _version
55
+ """The version of cocotb."""
67
56
 
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
57
 
73
- scheduler: Optional[Scheduler] = None
74
- """The global scheduler instance.
58
+ log: "Logger"
59
+ """An easily accessible :class:`~logging.Logger` for the user.
75
60
 
76
- This is guaranteed to hold a value at test time.
77
- """
61
+ This logger defaults to the :data:`logging.INFO` log level.
78
62
 
79
- regression_manager: Optional[RegressionManager] = None
80
- """The global regression manager instance.
81
-
82
- This is guaranteed to hold a value at test time.
63
+ .. versionchanged:: 2.0
64
+ This was previously the ``"cocotb"`` Logger.
65
+ It is now a Logger under the ``"test"`` namespace.
83
66
  """
84
67
 
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
- """
68
+ _scheduler_inst: "Scheduler"
69
+ """The global scheduler instance."""
90
70
 
91
- argc: Optional[int] = None
92
- """The length of :data:`cocotb.argv`.
71
+ _regression_manager: "RegressionManager"
72
+ """The global regression manager instance."""
93
73
 
94
- This is guaranteed to hold a value at test time.
95
- """
74
+ argv: List[str]
75
+ """The argument list as seen by the simulator."""
96
76
 
97
- plusargs: Optional[Dict[str, Union[bool, str]]] = None
77
+ plusargs: Dict[str, Union[bool, str]]
98
78
  """A dictionary of "plusargs" handed to the simulation.
99
79
 
100
- See :make:var:`PLUSARGS` for details.
101
- This is guaranteed to hold a value at test time.
80
+ See :envvar:`COCOTB_PLUSARGS` for details.
102
81
  """
103
82
 
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
- """
83
+ packages: "SimpleNamespace"
84
+ """A :class:`python:types.SimpleNamespace` of package handles.
109
85
 
110
- SIM_NAME: Optional[str] = None
111
- """The running simulator product information.
86
+ This will be populated with handles at test time if packages can be discovered
87
+ via the GPI.
112
88
 
113
- ``None`` if :mod:`cocotb` was not loaded from a simulator.
89
+ .. versionadded:: 2.0
114
90
  """
115
91
 
116
- SIM_VERSION: Optional[str] = None
117
- """The version of the running simulator.
92
+ SIM_NAME: str
93
+ """The product information of the running simulator."""
118
94
 
119
- ``None`` if :mod:`cocotb` was not loaded from a simulator."""
95
+ SIM_VERSION: str
96
+ """The version of the running simulator."""
120
97
 
121
- RANDOM_SEED: Optional[int] = None
98
+ RANDOM_SEED: int
122
99
  """
123
- The value passed to the Python default random number generator.
100
+ The value passed to the Python global random number generator.
124
101
 
125
- See :envvar:`RANDOM_SEED` for details on how the value is computed.
102
+ See :envvar:`COCOTB_RANDOM_SEED` for details on how the value is computed.
126
103
  This is guaranteed to hold a value at test time.
127
104
  """
128
105
 
129
- _library_coverage = None
130
- """ used for cocotb library coverage """
131
-
132
- top: Optional[cocotb.handle.SimHandleBase] = None
106
+ top: "SimHandleBase"
133
107
  r"""
134
- A handle to the :envvar:`TOPLEVEL` entity/module.
108
+ A handle to the :envvar:`COCOTB_TOPLEVEL` entity/module.
135
109
 
136
110
  This is equivalent to the :term:`DUT` parameter given to cocotb tests, so it can be used wherever that variable can be used.
137
111
  It is particularly useful for extracting information about the :term:`DUT` in module-level class and function definitions;
138
112
  and in parameters to :class:`.TestFactory`\ s.
139
- ``None`` if :mod:`cocotb` was not loaded from a simulator.
140
113
  """
141
114
 
115
+ is_simulation: bool = False
116
+ """``True`` if cocotb was loaded in a simulation."""
142
117
 
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
118
 
207
- cocotb.memdebug.start(port)
119
+ if sys.version_info < (3, 8):
120
+ import warnings
208
121
 
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__))
122
+ warnings.warn(
123
+ "Support for Python versions < 3.8 will be dropped in version 2.1",
124
+ FutureWarning,
282
125
  )
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