cocotb 1.7.2__tar.gz → 1.8.0rc1__tar.gz
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-1.7.2/cocotb.egg-info → cocotb-1.8.0rc1}/PKG-INFO +24 -9
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/README.md +23 -8
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/__init__.py +7 -18
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/_sim_versions.py +16 -1
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/_version.py +1 -1
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/clock.py +8 -3
- cocotb-1.8.0rc1/cocotb/decorators.py +326 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/ipython_support.py +3 -1
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/regression.py +32 -14
- cocotb-1.8.0rc1/cocotb/runner.py +1033 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/scheduler.py +35 -18
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/def/modelsim.def +2 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/include/embed.h +1 -2
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/include/gpi.h +10 -15
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/include/vpi_user_ext.h +3 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/lib/embed/embed.cpp +3 -3
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/lib/embed/gpi_embed.cpp +17 -20
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/lib/fli/FliCbHdl.cpp +26 -4
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/lib/fli/FliImpl.cpp +20 -9
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/lib/fli/FliImpl.h +38 -20
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/lib/fli/FliObjHdl.cpp +18 -10
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/lib/gpi/GpiCbHdl.cpp +9 -24
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/lib/gpi/GpiCommon.cpp +36 -35
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/lib/gpi/gpi_priv.h +27 -16
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/lib/simulator/simulatormodule.cpp +1 -1
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/lib/verilator/verilator.cpp +8 -4
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/lib/vhpi/VhpiCbHdl.cpp +21 -13
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/lib/vhpi/VhpiImpl.cpp +28 -16
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/lib/vhpi/VhpiImpl.h +33 -18
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/lib/vpi/VpiCbHdl.cpp +17 -10
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/lib/vpi/VpiImpl.cpp +20 -12
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/lib/vpi/VpiImpl.h +32 -17
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/makefiles/Makefile.inc +16 -4
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/makefiles/Makefile.sim +2 -2
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/makefiles/simulators/Makefile.icarus +19 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/makefiles/simulators/Makefile.ius +12 -1
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/makefiles/simulators/Makefile.questa +2 -1
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/makefiles/simulators/Makefile.riviera +4 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/makefiles/simulators/Makefile.vcs +4 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/makefiles/simulators/Makefile.verilator +5 -1
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/makefiles/simulators/Makefile.xcelium +5 -1
- cocotb-1.7.2/cocotb/decorators.py → cocotb-1.8.0rc1/cocotb/task.py +16 -295
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/triggers.py +23 -7
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/types/logic_array.py +34 -3
- {cocotb-1.7.2 → cocotb-1.8.0rc1/cocotb.egg-info}/PKG-INFO +24 -9
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb.egg-info/SOURCES.txt +1 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/setup.cfg +6 -1
- cocotb-1.7.2/cocotb/runner.py +0 -948
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/LICENSE +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/MANIFEST.in +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/ANSI.py +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/_deprecation.py +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/_py_compat.py +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/_vendor/README.md +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/_vendor/__init__.py +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/_vendor/distutils_version.py +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/_vendor/fli/acc_user.h +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/_vendor/fli/acc_vhdl.h +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/_vendor/fli/mti.h +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/_vendor/tcl/license.terms +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/_vendor/tcl/tcl.h +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/_vendor/tcl/tclDecls.h +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/_vendor/tcl/tclPlatDecls.h +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/_vendor/vhpi/vhpi_user.h +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/_vendor/vpi/sv_vpi_user.h +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/_vendor/vpi/vpi_user.h +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/binary.py +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/config.py +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/handle.py +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/log.py +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/memdebug.py +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/outcomes.py +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/queue.py +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/result.py +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/def/.gitignore +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/def/README.md +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/def/aldec.def +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/def/ghdl.def +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/def/icarus.def +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/include/cocotb_utils.h +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/include/exports.h +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/include/gpi_logging.h +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/include/py_gpi_logging.h +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/include/vhpi_user_ext.h +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/lib/gpi_log/gpi_logging.cpp +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/lib/py_gpi_log/py_gpi_logging.cpp +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/lib/utils/cocotb_utils.cpp +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/makefiles/Makefile.deprecations +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/makefiles/simulators/Makefile.activehdl +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/makefiles/simulators/Makefile.cvc +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/makefiles/simulators/Makefile.ghdl +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/share/makefiles/simulators/Makefile.modelsim +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/types/__init__.py +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/types/array.py +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/types/logic.py +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/types/range.py +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/utils.py +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/wavedrom.py +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb/xunit_reporter.py +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb.egg-info/dependency_links.txt +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb.egg-info/entry_points.txt +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb.egg-info/requires.txt +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb.egg-info/top_level.txt +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/cocotb_build_libs.py +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/pygpi/__init__.py +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/pygpi/entry.py +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/pyproject.toml +0 -0
- {cocotb-1.7.2 → cocotb-1.8.0rc1}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: cocotb
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.8.0rc1
|
|
4
4
|
Summary: cocotb is a coroutine based cosimulation library for writing VHDL and Verilog testbenches in Python.
|
|
5
5
|
Home-page: https://www.cocotb.org
|
|
6
6
|
Author: Chris Higgs, Stuart Hodgson
|
|
@@ -37,8 +37,7 @@ License-File: LICENSE
|
|
|
37
37
|
* Read the [documentation](https://docs.cocotb.org)
|
|
38
38
|
* Get involved:
|
|
39
39
|
* [Raise a bug / request an enhancement](https://github.com/cocotb/cocotb/issues/new) (Requires a GitHub account)
|
|
40
|
-
* [Join the
|
|
41
|
-
* [Join the Gitter chat room](https://gitter.im/cocotb)
|
|
40
|
+
* [Join the Gitter chat room](https://gitter.im/cocotb/Lobby)
|
|
42
41
|
|
|
43
42
|
## Installation
|
|
44
43
|
|
|
@@ -96,22 +95,38 @@ An example of a simple randomized cocotb testbench:
|
|
|
96
95
|
# test_dff.py
|
|
97
96
|
|
|
98
97
|
import random
|
|
98
|
+
|
|
99
99
|
import cocotb
|
|
100
100
|
from cocotb.clock import Clock
|
|
101
|
-
from cocotb.triggers import
|
|
101
|
+
from cocotb.triggers import RisingEdge
|
|
102
|
+
from cocotb.types import LogicArray
|
|
102
103
|
|
|
103
104
|
@cocotb.test()
|
|
104
|
-
async def
|
|
105
|
-
"""
|
|
105
|
+
async def dff_simple_test(dut):
|
|
106
|
+
"""Test that d propagates to q"""
|
|
107
|
+
|
|
108
|
+
# Assert initial output is unknown
|
|
109
|
+
assert LogicArray(dut.q.value) == LogicArray("X")
|
|
110
|
+
# Set initial input value to prevent it from floating
|
|
111
|
+
dut.d.value = 0
|
|
106
112
|
|
|
107
113
|
clock = Clock(dut.clk, 10, units="us") # Create a 10us period clock on port clk
|
|
108
|
-
|
|
114
|
+
# Start the clock. Start it low to avoid issues on the first RisingEdge
|
|
115
|
+
cocotb.start_soon(clock.start(start_high=False))
|
|
109
116
|
|
|
117
|
+
# Synchronize with the clock. This will regisiter the initial `d` value
|
|
118
|
+
await RisingEdge(dut.clk)
|
|
119
|
+
expected_val = 0 # Matches initial input value
|
|
110
120
|
for i in range(10):
|
|
111
121
|
val = random.randint(0, 1)
|
|
112
122
|
dut.d.value = val # Assign the random value val to the input port d
|
|
113
|
-
await
|
|
114
|
-
assert dut.q.value ==
|
|
123
|
+
await RisingEdge(dut.clk)
|
|
124
|
+
assert dut.q.value == expected_val, f"output q was incorrect on the {i}th cycle"
|
|
125
|
+
expected_val = val # Save random value for next RisingEdge
|
|
126
|
+
|
|
127
|
+
# Check the final input on the next clock
|
|
128
|
+
await RisingEdge(dut.clk)
|
|
129
|
+
assert dut.q.value == expected_val, "output q was incorrect on the last cycle"
|
|
115
130
|
```
|
|
116
131
|
|
|
117
132
|
A simple Makefile:
|
|
@@ -9,8 +9,7 @@
|
|
|
9
9
|
* Read the [documentation](https://docs.cocotb.org)
|
|
10
10
|
* Get involved:
|
|
11
11
|
* [Raise a bug / request an enhancement](https://github.com/cocotb/cocotb/issues/new) (Requires a GitHub account)
|
|
12
|
-
* [Join the
|
|
13
|
-
* [Join the Gitter chat room](https://gitter.im/cocotb)
|
|
12
|
+
* [Join the Gitter chat room](https://gitter.im/cocotb/Lobby)
|
|
14
13
|
|
|
15
14
|
## Installation
|
|
16
15
|
|
|
@@ -68,22 +67,38 @@ An example of a simple randomized cocotb testbench:
|
|
|
68
67
|
# test_dff.py
|
|
69
68
|
|
|
70
69
|
import random
|
|
70
|
+
|
|
71
71
|
import cocotb
|
|
72
72
|
from cocotb.clock import Clock
|
|
73
|
-
from cocotb.triggers import
|
|
73
|
+
from cocotb.triggers import RisingEdge
|
|
74
|
+
from cocotb.types import LogicArray
|
|
74
75
|
|
|
75
76
|
@cocotb.test()
|
|
76
|
-
async def
|
|
77
|
-
"""
|
|
77
|
+
async def dff_simple_test(dut):
|
|
78
|
+
"""Test that d propagates to q"""
|
|
79
|
+
|
|
80
|
+
# Assert initial output is unknown
|
|
81
|
+
assert LogicArray(dut.q.value) == LogicArray("X")
|
|
82
|
+
# Set initial input value to prevent it from floating
|
|
83
|
+
dut.d.value = 0
|
|
78
84
|
|
|
79
85
|
clock = Clock(dut.clk, 10, units="us") # Create a 10us period clock on port clk
|
|
80
|
-
|
|
86
|
+
# Start the clock. Start it low to avoid issues on the first RisingEdge
|
|
87
|
+
cocotb.start_soon(clock.start(start_high=False))
|
|
81
88
|
|
|
89
|
+
# Synchronize with the clock. This will regisiter the initial `d` value
|
|
90
|
+
await RisingEdge(dut.clk)
|
|
91
|
+
expected_val = 0 # Matches initial input value
|
|
82
92
|
for i in range(10):
|
|
83
93
|
val = random.randint(0, 1)
|
|
84
94
|
dut.d.value = val # Assign the random value val to the input port d
|
|
85
|
-
await
|
|
86
|
-
assert dut.q.value ==
|
|
95
|
+
await RisingEdge(dut.clk)
|
|
96
|
+
assert dut.q.value == expected_val, f"output q was incorrect on the {i}th cycle"
|
|
97
|
+
expected_val = val # Save random value for next RisingEdge
|
|
98
|
+
|
|
99
|
+
# Check the final input on the next clock
|
|
100
|
+
await RisingEdge(dut.clk)
|
|
101
|
+
assert dut.q.value == expected_val, "output q was incorrect on the last cycle"
|
|
87
102
|
```
|
|
88
103
|
|
|
89
104
|
A simple Makefile:
|
|
@@ -45,12 +45,12 @@ from cocotb._deprecation import deprecated
|
|
|
45
45
|
from cocotb.log import default_config
|
|
46
46
|
from cocotb.regression import RegressionManager
|
|
47
47
|
from cocotb.scheduler import Scheduler
|
|
48
|
+
from cocotb.task import Task
|
|
48
49
|
|
|
49
50
|
from ._version import __version__
|
|
50
51
|
|
|
51
52
|
# Things we want in the cocotb namespace
|
|
52
53
|
from cocotb.decorators import ( # isort: skip # noqa: F401
|
|
53
|
-
Task,
|
|
54
54
|
coroutine,
|
|
55
55
|
external,
|
|
56
56
|
function,
|
|
@@ -322,26 +322,15 @@ def _initialise_testbench_(argv_):
|
|
|
322
322
|
regression_manager._execute()
|
|
323
323
|
|
|
324
324
|
|
|
325
|
-
def _sim_event(
|
|
325
|
+
def _sim_event(message):
|
|
326
326
|
"""Function that can be called externally to signal an event."""
|
|
327
|
-
# SIM_INFO = 0
|
|
328
|
-
SIM_TEST_FAIL = 1
|
|
329
|
-
SIM_FAIL = 2
|
|
330
327
|
from cocotb.result import SimFailure
|
|
331
328
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
elif level is SIM_FAIL:
|
|
338
|
-
# We simply return here as the simulator will exit
|
|
339
|
-
# so no cleanup is needed
|
|
340
|
-
msg = f"Failing test at simulator request before test run completion: {message}"
|
|
341
|
-
scheduler.log.error(msg)
|
|
342
|
-
scheduler._finish_scheduler(SimFailure(msg))
|
|
343
|
-
else:
|
|
344
|
-
scheduler.log.error("Unsupported sim event")
|
|
329
|
+
# We simply return here as the simulator will exit
|
|
330
|
+
# so no cleanup is needed
|
|
331
|
+
msg = f"Failing test at simulator request before test run completion: {message}"
|
|
332
|
+
scheduler.log.error(msg)
|
|
333
|
+
scheduler._finish_scheduler(SimFailure(msg))
|
|
345
334
|
|
|
346
335
|
|
|
347
336
|
@deprecated("This function is now private")
|
|
@@ -68,9 +68,24 @@ class QuestaVersion(LooseVersion):
|
|
|
68
68
|
True
|
|
69
69
|
>>> QuestaVersion("2020.1 2020.01") > QuestaVersion("10.7c 2018.08")
|
|
70
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
|
|
71
75
|
"""
|
|
72
76
|
|
|
73
|
-
|
|
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)
|
|
74
89
|
|
|
75
90
|
|
|
76
91
|
class RivieraVersion(LooseVersion):
|
|
@@ -29,6 +29,9 @@
|
|
|
29
29
|
|
|
30
30
|
import itertools
|
|
31
31
|
import warnings
|
|
32
|
+
from decimal import Decimal
|
|
33
|
+
from numbers import Real
|
|
34
|
+
from typing import Union
|
|
32
35
|
|
|
33
36
|
from cocotb.log import SimLog
|
|
34
37
|
from cocotb.triggers import Timer
|
|
@@ -114,7 +117,9 @@ class Clock(BaseClock):
|
|
|
114
117
|
Using ``None`` as the *units* argument is deprecated, use ``'step'`` instead.
|
|
115
118
|
"""
|
|
116
119
|
|
|
117
|
-
def __init__(
|
|
120
|
+
def __init__(
|
|
121
|
+
self, signal, period: Union[float, Real, Decimal], units: str = "step"
|
|
122
|
+
):
|
|
118
123
|
BaseClock.__init__(self, signal)
|
|
119
124
|
if units is None:
|
|
120
125
|
warnings.warn(
|
|
@@ -124,8 +129,8 @@ class Clock(BaseClock):
|
|
|
124
129
|
)
|
|
125
130
|
units = "step" # don't propagate deprecated value
|
|
126
131
|
self.period = get_sim_steps(period, units)
|
|
127
|
-
self.half_period = get_sim_steps(period / 2
|
|
128
|
-
self.frequency = 1
|
|
132
|
+
self.half_period = get_sim_steps(period / 2, units)
|
|
133
|
+
self.frequency = 1 / get_time_from_sim_steps(self.period, units="us")
|
|
129
134
|
self.hdl = None
|
|
130
135
|
self.signal = signal
|
|
131
136
|
self.coro = None
|
|
@@ -0,0 +1,326 @@
|
|
|
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
|
+
import functools
|
|
29
|
+
import sys
|
|
30
|
+
import typing
|
|
31
|
+
import warnings
|
|
32
|
+
|
|
33
|
+
import cocotb
|
|
34
|
+
import cocotb.triggers
|
|
35
|
+
from cocotb.log import SimLog
|
|
36
|
+
from cocotb.task import Task as _Task # noqa: F401
|
|
37
|
+
from cocotb.task import _RunningCoroutine, _RunningTest
|
|
38
|
+
from cocotb.utils import lazy_property
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def public(f):
|
|
42
|
+
"""Use a decorator to avoid retyping function/class names.
|
|
43
|
+
|
|
44
|
+
* Based on an idea by Duncan Booth:
|
|
45
|
+
http://groups.google.com/group/comp.lang.python/msg/11cbb03e09611b8a
|
|
46
|
+
* Improved via a suggestion by Dave Angel:
|
|
47
|
+
http://groups.google.com/group/comp.lang.python/msg/3d400fb22d8a42e1
|
|
48
|
+
"""
|
|
49
|
+
all = sys.modules[f.__module__].__dict__.setdefault("__all__", [])
|
|
50
|
+
if f.__name__ not in all: # Prevent duplicates if run from an IDE.
|
|
51
|
+
all.append(f.__name__)
|
|
52
|
+
return f
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
public(public) # Emulate decorating ourself
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class coroutine:
|
|
59
|
+
"""Decorator class that allows us to provide common coroutine mechanisms:
|
|
60
|
+
|
|
61
|
+
``log`` methods will log to ``cocotb.coroutine.name``.
|
|
62
|
+
|
|
63
|
+
:meth:`~cocotb.task.Task.join` method returns an event which will fire when the coroutine exits.
|
|
64
|
+
|
|
65
|
+
Used as ``@cocotb.coroutine``.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
def __init__(self, func):
|
|
69
|
+
self._func = func
|
|
70
|
+
functools.update_wrapper(self, func)
|
|
71
|
+
|
|
72
|
+
@lazy_property
|
|
73
|
+
def log(self):
|
|
74
|
+
return SimLog(f"cocotb.coroutine.{self._func.__qualname__}.{id(self)}")
|
|
75
|
+
|
|
76
|
+
def __call__(self, *args, **kwargs):
|
|
77
|
+
return _RunningCoroutine(self._func(*args, **kwargs), self)
|
|
78
|
+
|
|
79
|
+
def __get__(self, obj, owner=None):
|
|
80
|
+
"""Permit the decorator to be used on class methods
|
|
81
|
+
and standalone functions"""
|
|
82
|
+
return type(self)(self._func.__get__(obj, owner))
|
|
83
|
+
|
|
84
|
+
def __iter__(self):
|
|
85
|
+
return self
|
|
86
|
+
|
|
87
|
+
def __str__(self):
|
|
88
|
+
return str(self._func.__qualname__)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@public
|
|
92
|
+
class function:
|
|
93
|
+
"""Decorator class that allows a function to block.
|
|
94
|
+
|
|
95
|
+
This allows a coroutine that consumes simulation time
|
|
96
|
+
to be called by a thread started with :class:`cocotb.external`;
|
|
97
|
+
in other words, to internally block while externally
|
|
98
|
+
appear to yield.
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
def __init__(self, func):
|
|
102
|
+
self._coro = cocotb.coroutine(func)
|
|
103
|
+
|
|
104
|
+
@lazy_property
|
|
105
|
+
def log(self):
|
|
106
|
+
return SimLog(f"cocotb.function.{self._coro.__qualname__}.{id(self)}")
|
|
107
|
+
|
|
108
|
+
def __call__(self, *args, **kwargs):
|
|
109
|
+
return cocotb.scheduler._queue_function(self._coro(*args, **kwargs))
|
|
110
|
+
|
|
111
|
+
def __get__(self, obj, owner=None):
|
|
112
|
+
"""Permit the decorator to be used on class methods
|
|
113
|
+
and standalone functions"""
|
|
114
|
+
return type(self)(self._coro._func.__get__(obj, owner))
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@public
|
|
118
|
+
class external:
|
|
119
|
+
"""Decorator to apply to an external function to enable calling from cocotb.
|
|
120
|
+
|
|
121
|
+
This turns a normal function that isn't a coroutine into a blocking coroutine.
|
|
122
|
+
Currently, this creates a new execution thread for each function that is
|
|
123
|
+
called.
|
|
124
|
+
Scope for this to be streamlined to a queue in future.
|
|
125
|
+
"""
|
|
126
|
+
|
|
127
|
+
def __init__(self, func):
|
|
128
|
+
self._func = func
|
|
129
|
+
self._log = SimLog(f"cocotb.external.{self._func.__qualname__}.{id(self)}")
|
|
130
|
+
|
|
131
|
+
def __call__(self, *args, **kwargs):
|
|
132
|
+
return cocotb.scheduler._run_in_executor(self._func, *args, **kwargs)
|
|
133
|
+
|
|
134
|
+
def __get__(self, obj, owner=None):
|
|
135
|
+
"""Permit the decorator to be used on class methods
|
|
136
|
+
and standalone functions"""
|
|
137
|
+
return type(self)(self._func.__get__(obj, owner))
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class _decorator_helper(type):
|
|
141
|
+
"""
|
|
142
|
+
Metaclass that allows a type to be constructed using decorator syntax,
|
|
143
|
+
passing the decorated function as the first argument.
|
|
144
|
+
|
|
145
|
+
So:
|
|
146
|
+
|
|
147
|
+
@MyClass(construction, args='go here')
|
|
148
|
+
def this_is_passed_as_f(...):
|
|
149
|
+
pass
|
|
150
|
+
|
|
151
|
+
ends up calling
|
|
152
|
+
|
|
153
|
+
MyClass.__init__(this_is_passed_as_f, construction, args='go here')
|
|
154
|
+
"""
|
|
155
|
+
|
|
156
|
+
def __call__(cls, *args, **kwargs):
|
|
157
|
+
def decorator(f):
|
|
158
|
+
# fall back to the normal way of constructing an object, now that
|
|
159
|
+
# we have all the arguments
|
|
160
|
+
return type.__call__(cls, f, *args, **kwargs)
|
|
161
|
+
|
|
162
|
+
return decorator
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
@public
|
|
166
|
+
class test(coroutine, metaclass=_decorator_helper):
|
|
167
|
+
"""
|
|
168
|
+
Decorator to mark a Callable which returns a Coroutine as a test.
|
|
169
|
+
|
|
170
|
+
The test decorator provides a test timeout, and allows us to mark tests as skipped
|
|
171
|
+
or expecting errors or failures.
|
|
172
|
+
Tests are evaluated in the order they are defined in a test module.
|
|
173
|
+
|
|
174
|
+
Used as ``@cocotb.test(...)``.
|
|
175
|
+
|
|
176
|
+
Args:
|
|
177
|
+
timeout_time (numbers.Real or decimal.Decimal, optional):
|
|
178
|
+
Simulation time duration before timeout occurs.
|
|
179
|
+
|
|
180
|
+
.. versionadded:: 1.3
|
|
181
|
+
|
|
182
|
+
.. note::
|
|
183
|
+
Test timeout is intended for protection against deadlock.
|
|
184
|
+
Users should use :class:`~cocotb.triggers.with_timeout` if they require a
|
|
185
|
+
more general-purpose timeout mechanism.
|
|
186
|
+
|
|
187
|
+
timeout_unit (str, optional):
|
|
188
|
+
Units of timeout_time, accepts any units that :class:`~cocotb.triggers.Timer` does.
|
|
189
|
+
|
|
190
|
+
.. versionadded:: 1.3
|
|
191
|
+
|
|
192
|
+
.. deprecated:: 1.5
|
|
193
|
+
Using ``None`` as the *timeout_unit* argument is deprecated, use ``'step'`` instead.
|
|
194
|
+
|
|
195
|
+
expect_fail (bool, optional):
|
|
196
|
+
If ``True`` and the test fails a functional check via an ``assert`` statement, :class:`pytest.raises`,
|
|
197
|
+
:class:`pytest.warns`, or :class:`pytest.deprecated_call` the test is considered to have passed.
|
|
198
|
+
If ``True`` and the test passes successfully, the test is considered to have failed.
|
|
199
|
+
|
|
200
|
+
expect_error (exception type or tuple of exception types, optional):
|
|
201
|
+
Mark the result as a pass only if one of the exception types is raised in the test.
|
|
202
|
+
This is primarily for cocotb internal regression use for when a simulator error is expected.
|
|
203
|
+
|
|
204
|
+
Users are encouraged to use the following idiom instead::
|
|
205
|
+
|
|
206
|
+
@cocotb.test()
|
|
207
|
+
async def my_test(dut):
|
|
208
|
+
try:
|
|
209
|
+
await thing_that_should_fail()
|
|
210
|
+
except ExceptionIExpect:
|
|
211
|
+
pass
|
|
212
|
+
else:
|
|
213
|
+
assert False, "Exception did not occur"
|
|
214
|
+
|
|
215
|
+
.. versionchanged:: 1.3
|
|
216
|
+
Specific exception types can be expected
|
|
217
|
+
|
|
218
|
+
.. deprecated:: 1.5
|
|
219
|
+
Passing a :class:`bool` value is now deprecated.
|
|
220
|
+
Pass a specific :class:`Exception` or a tuple of Exceptions instead.
|
|
221
|
+
|
|
222
|
+
skip (bool, optional):
|
|
223
|
+
Don't execute this test as part of the regression. Test can still be run
|
|
224
|
+
manually by setting :make:var:`TESTCASE`.
|
|
225
|
+
|
|
226
|
+
stage (int)
|
|
227
|
+
Order tests logically into stages, where multiple tests can share a stage.
|
|
228
|
+
Defaults to 0.
|
|
229
|
+
"""
|
|
230
|
+
|
|
231
|
+
_id_count = 0 # used by the RegressionManager to sort tests in definition order
|
|
232
|
+
|
|
233
|
+
def __init__(
|
|
234
|
+
self,
|
|
235
|
+
f,
|
|
236
|
+
timeout_time=None,
|
|
237
|
+
timeout_unit="step",
|
|
238
|
+
expect_fail=False,
|
|
239
|
+
expect_error=(),
|
|
240
|
+
skip=False,
|
|
241
|
+
stage=0,
|
|
242
|
+
):
|
|
243
|
+
|
|
244
|
+
if timeout_unit is None:
|
|
245
|
+
warnings.warn(
|
|
246
|
+
'Using timeout_unit=None is deprecated, use timeout_unit="step" instead.',
|
|
247
|
+
DeprecationWarning,
|
|
248
|
+
stacklevel=2,
|
|
249
|
+
)
|
|
250
|
+
timeout_unit = "step" # don't propagate deprecated value
|
|
251
|
+
self._id = self._id_count
|
|
252
|
+
type(self)._id_count += 1
|
|
253
|
+
|
|
254
|
+
if timeout_time is not None:
|
|
255
|
+
co = coroutine(f)
|
|
256
|
+
|
|
257
|
+
@functools.wraps(f)
|
|
258
|
+
async def f(*args, **kwargs):
|
|
259
|
+
running_co = co(*args, **kwargs)
|
|
260
|
+
|
|
261
|
+
try:
|
|
262
|
+
res = await cocotb.triggers.with_timeout(
|
|
263
|
+
running_co, self.timeout_time, self.timeout_unit
|
|
264
|
+
)
|
|
265
|
+
except cocotb.result.SimTimeoutError:
|
|
266
|
+
running_co.kill()
|
|
267
|
+
raise
|
|
268
|
+
else:
|
|
269
|
+
return res
|
|
270
|
+
|
|
271
|
+
super().__init__(f)
|
|
272
|
+
|
|
273
|
+
self.timeout_time = timeout_time
|
|
274
|
+
self.timeout_unit = timeout_unit
|
|
275
|
+
self.expect_fail = expect_fail
|
|
276
|
+
if isinstance(expect_error, bool):
|
|
277
|
+
warnings.warn(
|
|
278
|
+
"Passing bool values to `except_error` option of `cocotb.test` is deprecated. "
|
|
279
|
+
"Pass a specific Exception type instead",
|
|
280
|
+
DeprecationWarning,
|
|
281
|
+
stacklevel=2,
|
|
282
|
+
)
|
|
283
|
+
if expect_error is True:
|
|
284
|
+
expect_error = (BaseException,)
|
|
285
|
+
elif expect_error is False:
|
|
286
|
+
expect_error = ()
|
|
287
|
+
self.expect_error = expect_error
|
|
288
|
+
self.skip = skip
|
|
289
|
+
self.stage = stage
|
|
290
|
+
self.im_test = True # For auto-regressions
|
|
291
|
+
self.name = self._func.__name__
|
|
292
|
+
|
|
293
|
+
def __call__(self, *args, **kwargs):
|
|
294
|
+
inst = self._func(*args, **kwargs)
|
|
295
|
+
coro = _RunningTest(inst, self)
|
|
296
|
+
return coro
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
if sys.version_info < (3, 7):
|
|
300
|
+
Task = _Task
|
|
301
|
+
RunningTask = _Task
|
|
302
|
+
RunningCoroutine = _RunningCoroutine
|
|
303
|
+
RunningTest = _RunningTest
|
|
304
|
+
else:
|
|
305
|
+
|
|
306
|
+
def __getattr__(attr: str) -> typing.Any:
|
|
307
|
+
if attr in ("Task", "RunningTask"):
|
|
308
|
+
warnings.warn(
|
|
309
|
+
f"The class {attr} has been renamed to cocotb.task.Task.",
|
|
310
|
+
DeprecationWarning,
|
|
311
|
+
stacklevel=2,
|
|
312
|
+
)
|
|
313
|
+
attr = "_Task"
|
|
314
|
+
elif attr in ("RunningCoroutine", "RunningTest"):
|
|
315
|
+
warnings.warn(
|
|
316
|
+
f"The class {attr} is now private. Update all uses to the parent class cocotb.task.Task.",
|
|
317
|
+
DeprecationWarning,
|
|
318
|
+
stacklevel=2,
|
|
319
|
+
)
|
|
320
|
+
attr = f"_{attr}"
|
|
321
|
+
try:
|
|
322
|
+
return globals()[attr]
|
|
323
|
+
except KeyError:
|
|
324
|
+
raise AttributeError(
|
|
325
|
+
f"module {__name__!r} has no attribute {attr!r}"
|
|
326
|
+
) from None
|
|
@@ -61,7 +61,9 @@ async def embed(user_ns: dict = {}):
|
|
|
61
61
|
c = load_default_config()
|
|
62
62
|
c.TerminalInteractiveShell.loop_runner = lambda x: _runner(shell, x)
|
|
63
63
|
c.TerminalInteractiveShell.autoawait = True
|
|
64
|
-
|
|
64
|
+
# Python3 checks SQLite DB accesses to ensure process ID matches the one that opened the DB and is not propogated
|
|
65
|
+
# because we launch IPython in a different process, this will cause unnecessary warnings, so disable the PID check
|
|
66
|
+
c.HistoryAccessor.connection_options = {"check_same_thread": False}
|
|
65
67
|
# create a shell with access to the dut, and cocotb pre-imported
|
|
66
68
|
shell = IPython.terminal.embed.InteractiveShellEmbed(
|
|
67
69
|
user_ns=default_ns,
|