cocotb 1.9.2__cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.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.
- cocotb/ANSI.py +92 -0
- cocotb/__init__.py +371 -0
- cocotb/_deprecation.py +36 -0
- cocotb/_py_compat.py +63 -0
- cocotb/_sim_versions.py +145 -0
- cocotb/_vendor/__init__.py +0 -0
- cocotb/_vendor/distutils_version.py +346 -0
- cocotb/_version.py +8 -0
- cocotb/binary.py +858 -0
- cocotb/clock.py +174 -0
- cocotb/config.py +289 -0
- cocotb/decorators.py +332 -0
- cocotb/handle.py +1175 -0
- cocotb/ipython_support.py +92 -0
- cocotb/libs/libcocotb.so +0 -0
- cocotb/libs/libcocotbfli_modelsim.so +0 -0
- cocotb/libs/libcocotbutils.so +0 -0
- cocotb/libs/libcocotbvhpi_aldec.so +0 -0
- cocotb/libs/libcocotbvhpi_ius.so +0 -0
- cocotb/libs/libcocotbvhpi_modelsim.so +0 -0
- cocotb/libs/libcocotbvhpi_nvc.so +0 -0
- cocotb/libs/libcocotbvpi_aldec.so +0 -0
- cocotb/libs/libcocotbvpi_ghdl.so +0 -0
- cocotb/libs/libcocotbvpi_icarus.vpl +0 -0
- cocotb/libs/libcocotbvpi_ius.so +0 -0
- cocotb/libs/libcocotbvpi_modelsim.so +0 -0
- cocotb/libs/libcocotbvpi_vcs.so +0 -0
- cocotb/libs/libcocotbvpi_verilator.so +0 -0
- cocotb/libs/libembed.so +0 -0
- cocotb/libs/libgpi.so +0 -0
- cocotb/libs/libgpilog.so +0 -0
- cocotb/libs/libpygpilog.so +0 -0
- cocotb/log.py +303 -0
- cocotb/memdebug.py +35 -0
- cocotb/outcomes.py +56 -0
- cocotb/queue.py +179 -0
- cocotb/regression.py +933 -0
- cocotb/result.py +209 -0
- cocotb/runner.py +1400 -0
- cocotb/scheduler.py +1099 -0
- cocotb/share/def/.gitignore +2 -0
- cocotb/share/def/README.md +4 -0
- cocotb/share/def/aldec.def +61 -0
- cocotb/share/def/ghdl.def +43 -0
- cocotb/share/def/icarus.def +43 -0
- cocotb/share/def/modelsim.def +137 -0
- cocotb/share/include/cocotb_utils.h +93 -0
- cocotb/share/include/embed.h +56 -0
- cocotb/share/include/exports.h +20 -0
- cocotb/share/include/gpi.h +265 -0
- cocotb/share/include/gpi_logging.h +212 -0
- cocotb/share/include/py_gpi_logging.h +30 -0
- cocotb/share/include/vhpi_user_ext.h +26 -0
- cocotb/share/include/vpi_user_ext.h +55 -0
- cocotb/share/lib/verilator/verilator.cpp +196 -0
- cocotb/share/makefiles/Makefile.deprecations +12 -0
- cocotb/share/makefiles/Makefile.inc +176 -0
- cocotb/share/makefiles/Makefile.sim +113 -0
- cocotb/share/makefiles/simulators/Makefile.activehdl +79 -0
- cocotb/share/makefiles/simulators/Makefile.cvc +94 -0
- cocotb/share/makefiles/simulators/Makefile.ghdl +113 -0
- cocotb/share/makefiles/simulators/Makefile.icarus +111 -0
- cocotb/share/makefiles/simulators/Makefile.ius +125 -0
- cocotb/share/makefiles/simulators/Makefile.modelsim +32 -0
- cocotb/share/makefiles/simulators/Makefile.nvc +64 -0
- cocotb/share/makefiles/simulators/Makefile.questa +171 -0
- cocotb/share/makefiles/simulators/Makefile.riviera +183 -0
- cocotb/share/makefiles/simulators/Makefile.vcs +98 -0
- cocotb/share/makefiles/simulators/Makefile.verilator +86 -0
- cocotb/share/makefiles/simulators/Makefile.xcelium +136 -0
- cocotb/simulator.cpython-313-x86_64-linux-gnu.so +0 -0
- cocotb/task.py +325 -0
- cocotb/triggers.py +1104 -0
- cocotb/types/__init__.py +50 -0
- cocotb/types/array.py +309 -0
- cocotb/types/logic.py +292 -0
- cocotb/types/logic_array.py +298 -0
- cocotb/types/range.py +198 -0
- cocotb/utils.py +698 -0
- cocotb/wavedrom.py +199 -0
- cocotb/xunit_reporter.py +80 -0
- cocotb-1.9.2.dist-info/LICENSE +28 -0
- cocotb-1.9.2.dist-info/METADATA +168 -0
- cocotb-1.9.2.dist-info/RECORD +89 -0
- cocotb-1.9.2.dist-info/WHEEL +6 -0
- cocotb-1.9.2.dist-info/entry_points.txt +2 -0
- cocotb-1.9.2.dist-info/top_level.txt +21 -0
- pygpi/__init__.py +0 -0
- pygpi/entry.py +26 -0
cocotb/ANSI.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# Copyright (c) 2013, 2018 Potential Ventures Ltd
|
|
2
|
+
# 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
|
+
Some constants for doing ANSI stuff.
|
|
30
|
+
"""
|
|
31
|
+
# flake8: noqa (skip this file for flake8: pypi.python.org/pypi/flake8)
|
|
32
|
+
_ESCAPE = "\033["
|
|
33
|
+
|
|
34
|
+
# see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
|
|
35
|
+
|
|
36
|
+
DEFAULT_FG = _ESCAPE + "39m"
|
|
37
|
+
DEFAULT_BG = _ESCAPE + "49m"
|
|
38
|
+
DEFAULT = DEFAULT_BG + DEFAULT_FG
|
|
39
|
+
|
|
40
|
+
BLACK_FG = _ESCAPE + "30m"
|
|
41
|
+
RED_FG = _ESCAPE + "31m"
|
|
42
|
+
GREEN_FG = _ESCAPE + "32m"
|
|
43
|
+
YELLOW_FG = _ESCAPE + "33m"
|
|
44
|
+
BLUE_FG = _ESCAPE + "34m"
|
|
45
|
+
MAGENTA_FG = _ESCAPE + "35m"
|
|
46
|
+
CYAN_FG = _ESCAPE + "36m"
|
|
47
|
+
WHITE_FG = _ESCAPE + "37m"
|
|
48
|
+
|
|
49
|
+
BLACK_BG = _ESCAPE + "40m"
|
|
50
|
+
RED_BG = _ESCAPE + "41m"
|
|
51
|
+
GREEN_BG = _ESCAPE + "42m"
|
|
52
|
+
YELLOW_BG = _ESCAPE + "43m"
|
|
53
|
+
BLUE_BG = _ESCAPE + "44m"
|
|
54
|
+
MAGENTA_BG = _ESCAPE + "45m"
|
|
55
|
+
CYAN_BG = _ESCAPE + "46m"
|
|
56
|
+
WHITE_BG = _ESCAPE + "47m"
|
|
57
|
+
|
|
58
|
+
BRIGHT_BLACK_FG = _ESCAPE + "90m"
|
|
59
|
+
BRIGHT_RED_FG = _ESCAPE + "91m"
|
|
60
|
+
BRIGHT_GREEN_FG = _ESCAPE + "92m"
|
|
61
|
+
BRIGHT_YELLOW_FG = _ESCAPE + "93m"
|
|
62
|
+
BRIGHT_BLUE_FG = _ESCAPE + "94m"
|
|
63
|
+
BRIGHT_MAGENTA_FG = _ESCAPE + "95m"
|
|
64
|
+
BRIGHT_CYAN_FG = _ESCAPE + "96m"
|
|
65
|
+
BRIGHT_WHITE_FG = _ESCAPE + "97m"
|
|
66
|
+
|
|
67
|
+
BRIGHT_BLACK_BG = _ESCAPE + "100m"
|
|
68
|
+
BRIGHT_RED_BG = _ESCAPE + "101m"
|
|
69
|
+
BRIGHT_GREEN_BG = _ESCAPE + "102m"
|
|
70
|
+
BRIGHT_YELLOW_BG = _ESCAPE + "103m"
|
|
71
|
+
BRIGHT_BLUE_BG = _ESCAPE + "104m"
|
|
72
|
+
BRIGHT_MAGENTA_BG = _ESCAPE + "105m"
|
|
73
|
+
BRIGHT_CYAN_BG = _ESCAPE + "106m"
|
|
74
|
+
BRIGHT_WHITE_BG = _ESCAPE + "107m"
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
COLOR_DEFAULT = DEFAULT
|
|
78
|
+
|
|
79
|
+
COLOR_WARNING = YELLOW_FG
|
|
80
|
+
COLOR_ERROR = RED_FG
|
|
81
|
+
COLOR_CRITICAL = RED_BG + BLACK_FG
|
|
82
|
+
COLOR_TEST = BLUE_FG
|
|
83
|
+
COLOR_PASSED = GREEN_FG
|
|
84
|
+
COLOR_SKIPPED = YELLOW_FG
|
|
85
|
+
COLOR_FAILED = RED_FG
|
|
86
|
+
|
|
87
|
+
COLOR_HILITE_SUMMARY = WHITE_FG + RED_BG
|
|
88
|
+
COLOR_HILITE_HEXDIFF_DEFAULT = YELLOW_FG
|
|
89
|
+
COLOR_HILITE_HEXDIFF_1 = CYAN_FG
|
|
90
|
+
COLOR_HILITE_HEXDIFF_2 = RED_FG
|
|
91
|
+
COLOR_HILITE_HEXDIFF_3 = MAGENTA_BG
|
|
92
|
+
COLOR_HILITE_HEXDIFF_4 = CYAN_BG + BLACK_FG
|
cocotb/__init__.py
ADDED
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
# Copyright (c) 2013 Potential Ventures Ltd
|
|
2
|
+
# 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
|
|
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,
|
|
57
|
+
test,
|
|
58
|
+
)
|
|
59
|
+
from cocotb.log import _filter_from_c, _log_from_c # isort: skip # noqa: F401
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _setup_logging() -> None:
|
|
63
|
+
default_config()
|
|
64
|
+
global log
|
|
65
|
+
log = logging.getLogger(__name__)
|
|
66
|
+
|
|
67
|
+
|
|
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
|
+
|
|
73
|
+
scheduler: Optional[Scheduler] = None
|
|
74
|
+
"""The global scheduler instance.
|
|
75
|
+
|
|
76
|
+
This is guaranteed to hold a value at test time.
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
regression_manager: Optional[RegressionManager] = None
|
|
80
|
+
"""The global regression manager instance.
|
|
81
|
+
|
|
82
|
+
This is guaranteed to hold a value at test time.
|
|
83
|
+
"""
|
|
84
|
+
|
|
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
|
+
"""
|
|
90
|
+
|
|
91
|
+
argc: Optional[int] = None
|
|
92
|
+
"""The length of :data:`cocotb.argv`.
|
|
93
|
+
|
|
94
|
+
This is guaranteed to hold a value at test time.
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
plusargs: Optional[Dict[str, Union[bool, str]]] = None
|
|
98
|
+
"""A dictionary of "plusargs" handed to the simulation.
|
|
99
|
+
|
|
100
|
+
See :make:var:`PLUSARGS` for details.
|
|
101
|
+
This is guaranteed to hold a value at test time.
|
|
102
|
+
"""
|
|
103
|
+
|
|
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
|
+
"""
|
|
109
|
+
|
|
110
|
+
SIM_NAME: Optional[str] = None
|
|
111
|
+
"""The running simulator product information.
|
|
112
|
+
|
|
113
|
+
``None`` if :mod:`cocotb` was not loaded from a simulator.
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
SIM_VERSION: Optional[str] = None
|
|
117
|
+
"""The version of the running simulator.
|
|
118
|
+
|
|
119
|
+
``None`` if :mod:`cocotb` was not loaded from a simulator."""
|
|
120
|
+
|
|
121
|
+
RANDOM_SEED: Optional[int] = None
|
|
122
|
+
"""
|
|
123
|
+
The value passed to the Python default random number generator.
|
|
124
|
+
|
|
125
|
+
See :envvar:`RANDOM_SEED` for details on how the value is computed.
|
|
126
|
+
This is guaranteed to hold a value at test time.
|
|
127
|
+
"""
|
|
128
|
+
|
|
129
|
+
_library_coverage = None
|
|
130
|
+
""" used for cocotb library coverage """
|
|
131
|
+
|
|
132
|
+
top: Optional[cocotb.handle.SimHandleBase] = None
|
|
133
|
+
r"""
|
|
134
|
+
A handle to the :envvar:`TOPLEVEL` entity/module.
|
|
135
|
+
|
|
136
|
+
This is equivalent to the :term:`DUT` parameter given to cocotb tests, so it can be used wherever that variable can be used.
|
|
137
|
+
It is particularly useful for extracting information about the :term:`DUT` in module-level class and function definitions;
|
|
138
|
+
and in parameters to :class:`.TestFactory`\ s.
|
|
139
|
+
``None`` if :mod:`cocotb` was not loaded from a simulator.
|
|
140
|
+
"""
|
|
141
|
+
|
|
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
|
cocotb/_deprecation.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Copyright cocotb contributors
|
|
2
|
+
# Licensed under the Revised BSD License, see LICENSE for details.
|
|
3
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
4
|
+
|
|
5
|
+
import functools
|
|
6
|
+
import warnings
|
|
7
|
+
from typing import Any, Callable, Type, TypeVar
|
|
8
|
+
|
|
9
|
+
AnyCallableT = TypeVar("AnyCallableT", bound=Callable[..., object])
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def deprecated(
|
|
13
|
+
msg: str, category: Type[Warning] = DeprecationWarning
|
|
14
|
+
) -> Callable[[AnyCallableT], AnyCallableT]:
|
|
15
|
+
"""Emits a DeprecationWarning when the decorated function is called.
|
|
16
|
+
|
|
17
|
+
This decorator works on normal functions, methods, and properties.
|
|
18
|
+
Usage on properties requires the ``@property`` decorator to appear outside the
|
|
19
|
+
``@deprecated`` decorator.
|
|
20
|
+
Concrete classes can be deprecated by decorating their ``__init__`` or ``__new__``
|
|
21
|
+
method.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
msg: the deprecation message
|
|
25
|
+
category: the warning class to use
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
def decorator(f: AnyCallableT) -> AnyCallableT:
|
|
29
|
+
@functools.wraps(f)
|
|
30
|
+
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
31
|
+
warnings.warn(msg, category=category, stacklevel=2)
|
|
32
|
+
return f(*args, **kwargs)
|
|
33
|
+
|
|
34
|
+
return wrapper
|
|
35
|
+
|
|
36
|
+
return decorator
|
cocotb/_py_compat.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Copyright (c) cocotb contributors
|
|
2
|
+
# All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
|
6
|
+
# * Redistributions of source code must retain the above copyright
|
|
7
|
+
# notice, this list of conditions and the following disclaimer.
|
|
8
|
+
# * Redistributions in binary form must reproduce the above copyright
|
|
9
|
+
# notice, this list of conditions and the following disclaimer in the
|
|
10
|
+
# documentation and/or other materials provided with the distribution.
|
|
11
|
+
# * Neither the name of the copyright holder nor the
|
|
12
|
+
# names of its contributors may be used to endorse or promote products
|
|
13
|
+
# derived from this software without specific prior written permission.
|
|
14
|
+
#
|
|
15
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
16
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
17
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
18
|
+
# DISCLAIMED. IN NO EVENT SHALL POTENTIAL VENTURES LTD BE LIABLE FOR ANY
|
|
19
|
+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
20
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
21
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
22
|
+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
23
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
24
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
25
|
+
"""
|
|
26
|
+
Backports and compatibility shims for newer python features.
|
|
27
|
+
|
|
28
|
+
These are for internal use - users should use a third party library like `six`
|
|
29
|
+
if they want to use these shims in their own code
|
|
30
|
+
"""
|
|
31
|
+
import sys
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# backport of Python 3.7's contextlib.nullcontext
|
|
35
|
+
class nullcontext:
|
|
36
|
+
"""Context manager that does no additional processing.
|
|
37
|
+
Used as a stand-in for a normal context manager, when a particular
|
|
38
|
+
block of code is only sometimes used with a normal context manager:
|
|
39
|
+
|
|
40
|
+
cm = optional_cm if condition else nullcontext()
|
|
41
|
+
with cm:
|
|
42
|
+
# Perform operation, using optional_cm if condition is True
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
def __init__(self, enter_result=None):
|
|
46
|
+
self.enter_result = enter_result
|
|
47
|
+
|
|
48
|
+
def __enter__(self):
|
|
49
|
+
return self.enter_result
|
|
50
|
+
|
|
51
|
+
def __exit__(self, *excinfo):
|
|
52
|
+
pass
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# On python 3.7 onwards, `dict` is guaranteed to preserve insertion order.
|
|
56
|
+
# Since `OrderedDict` is a little slower that `dict`, we prefer the latter
|
|
57
|
+
# when possible.
|
|
58
|
+
if sys.version_info[:2] >= (3, 7):
|
|
59
|
+
insertion_ordered_dict = dict
|
|
60
|
+
else:
|
|
61
|
+
import collections
|
|
62
|
+
|
|
63
|
+
insertion_ordered_dict = collections.OrderedDict
|
cocotb/_sim_versions.py
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# Copyright cocotb contributors
|
|
2
|
+
# Licensed under the Revised BSD License, see LICENSE for details.
|
|
3
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
Classes to compare simulation versions.
|
|
7
|
+
|
|
8
|
+
These are for cocotb-internal use only.
|
|
9
|
+
|
|
10
|
+
.. warning::
|
|
11
|
+
These classes silently allow comparing versions of different simulators.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from cocotb._vendor.distutils_version import LooseVersion
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ActivehdlVersion(LooseVersion):
|
|
18
|
+
"""Version numbering class for Aldec Active-HDL.
|
|
19
|
+
|
|
20
|
+
NOTE: unsupported versions exist, e.g.
|
|
21
|
+
ActivehdlVersion("10.5a.12.6914") > ActivehdlVersion("10.5.216.6767")
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class CvcVersion(LooseVersion):
|
|
28
|
+
"""Version numbering class for Tachyon DA CVC.
|
|
29
|
+
|
|
30
|
+
Example:
|
|
31
|
+
>>> CvcVersion("OSS_CVC_7.00b-x86_64-rhel6x of 07/07/14 (Linux-elf)") > CvcVersion("OSS_CVC_7.00a-x86_64-rhel6x of 07/07/14 (Linux-elf)")
|
|
32
|
+
True
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
pass
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class GhdlVersion(LooseVersion):
|
|
39
|
+
"""Version numbering class for GHDL."""
|
|
40
|
+
|
|
41
|
+
pass
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class IcarusVersion(LooseVersion):
|
|
45
|
+
"""Version numbering class for Icarus Verilog.
|
|
46
|
+
|
|
47
|
+
Example:
|
|
48
|
+
>>> IcarusVersion("11.0 (devel)") > IcarusVersion("10.3 (stable)")
|
|
49
|
+
True
|
|
50
|
+
>>> IcarusVersion("10.3 (stable)") <= IcarusVersion("10.3 (stable)")
|
|
51
|
+
True
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
pass
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class ModelsimVersion(LooseVersion):
|
|
58
|
+
"""Version numbering class for Mentor ModelSim."""
|
|
59
|
+
|
|
60
|
+
pass
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class QuestaVersion(LooseVersion):
|
|
64
|
+
"""Version numbering class for Mentor Questa.
|
|
65
|
+
|
|
66
|
+
Example:
|
|
67
|
+
>>> QuestaVersion("10.7c 2018.08") > QuestaVersion("10.7b 2018.06")
|
|
68
|
+
True
|
|
69
|
+
>>> QuestaVersion("2020.1 2020.01") > QuestaVersion("10.7c 2018.08")
|
|
70
|
+
True
|
|
71
|
+
>>> QuestaVersion("2020.1 2020.01") == QuestaVersion("2020.1")
|
|
72
|
+
True
|
|
73
|
+
>>> QuestaVersion("2023.1_2 2023.03") > QuestaVersion("2023.1_1")
|
|
74
|
+
True
|
|
75
|
+
"""
|
|
76
|
+
|
|
77
|
+
def parse(self, vstring):
|
|
78
|
+
# A Questa version string, as returned by the simulator, consists of two
|
|
79
|
+
# space-separated parts. The first part is the actual version number,
|
|
80
|
+
# the second part seems to be the year and month of the initial release.
|
|
81
|
+
# We only need the first part, which is also used in public
|
|
82
|
+
# communication by Siemens.
|
|
83
|
+
try:
|
|
84
|
+
first_component = vstring.split(" ", 1)[0]
|
|
85
|
+
except IndexError:
|
|
86
|
+
first_component = vstring
|
|
87
|
+
|
|
88
|
+
super().parse(first_component)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class RivieraVersion(LooseVersion):
|
|
92
|
+
"""Version numbering class for Aldec Riviera-PRO.
|
|
93
|
+
|
|
94
|
+
Example:
|
|
95
|
+
>>> RivieraVersion("2019.10.138.7537") == RivieraVersion("2019.10.138.7537")
|
|
96
|
+
True
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
pass
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class VcsVersion(LooseVersion):
|
|
103
|
+
"""Version numbering class for Synopsys VCS.
|
|
104
|
+
|
|
105
|
+
Example:
|
|
106
|
+
>>> VcsVersion("Q-2020.03-1_Full64") > VcsVersion("K-2015.09_Full64")
|
|
107
|
+
True
|
|
108
|
+
"""
|
|
109
|
+
|
|
110
|
+
pass
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class VerilatorVersion(LooseVersion):
|
|
114
|
+
"""Version numbering class for Verilator.
|
|
115
|
+
|
|
116
|
+
Example:
|
|
117
|
+
>>> VerilatorVersion("4.032 2020-04-04") > VerilatorVersion("4.031 devel")
|
|
118
|
+
True
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
pass
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class XceliumVersion(LooseVersion):
|
|
125
|
+
"""Version numbering class for Cadence Xcelium.
|
|
126
|
+
|
|
127
|
+
Example:
|
|
128
|
+
>>> XceliumVersion("20.06-g183") > XceliumVersion("20.03-s002")
|
|
129
|
+
True
|
|
130
|
+
>>> XceliumVersion("20.07-e501") > XceliumVersion("20.06-g183")
|
|
131
|
+
True
|
|
132
|
+
"""
|
|
133
|
+
|
|
134
|
+
pass
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class IusVersion(XceliumVersion): # inherit everything from Xcelium
|
|
138
|
+
"""Version numbering class for Cadence IUS.
|
|
139
|
+
|
|
140
|
+
Example:
|
|
141
|
+
>>> IusVersion("15.20-s050") > IusVersion("15.20-s049")
|
|
142
|
+
True
|
|
143
|
+
"""
|
|
144
|
+
|
|
145
|
+
pass
|