cocotb 1.9.2__cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.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 (89) hide show
  1. cocotb/ANSI.py +92 -0
  2. cocotb/__init__.py +371 -0
  3. cocotb/_deprecation.py +36 -0
  4. cocotb/_py_compat.py +63 -0
  5. cocotb/_sim_versions.py +145 -0
  6. cocotb/_vendor/__init__.py +0 -0
  7. cocotb/_vendor/distutils_version.py +346 -0
  8. cocotb/_version.py +8 -0
  9. cocotb/binary.py +858 -0
  10. cocotb/clock.py +174 -0
  11. cocotb/config.py +289 -0
  12. cocotb/decorators.py +332 -0
  13. cocotb/handle.py +1175 -0
  14. cocotb/ipython_support.py +92 -0
  15. cocotb/libs/libcocotb.so +0 -0
  16. cocotb/libs/libcocotbfli_modelsim.so +0 -0
  17. cocotb/libs/libcocotbutils.so +0 -0
  18. cocotb/libs/libcocotbvhpi_aldec.so +0 -0
  19. cocotb/libs/libcocotbvhpi_ius.so +0 -0
  20. cocotb/libs/libcocotbvhpi_modelsim.so +0 -0
  21. cocotb/libs/libcocotbvhpi_nvc.so +0 -0
  22. cocotb/libs/libcocotbvpi_aldec.so +0 -0
  23. cocotb/libs/libcocotbvpi_ghdl.so +0 -0
  24. cocotb/libs/libcocotbvpi_icarus.vpl +0 -0
  25. cocotb/libs/libcocotbvpi_ius.so +0 -0
  26. cocotb/libs/libcocotbvpi_modelsim.so +0 -0
  27. cocotb/libs/libcocotbvpi_vcs.so +0 -0
  28. cocotb/libs/libcocotbvpi_verilator.so +0 -0
  29. cocotb/libs/libembed.so +0 -0
  30. cocotb/libs/libgpi.so +0 -0
  31. cocotb/libs/libgpilog.so +0 -0
  32. cocotb/libs/libpygpilog.so +0 -0
  33. cocotb/log.py +303 -0
  34. cocotb/memdebug.py +35 -0
  35. cocotb/outcomes.py +56 -0
  36. cocotb/queue.py +179 -0
  37. cocotb/regression.py +933 -0
  38. cocotb/result.py +209 -0
  39. cocotb/runner.py +1400 -0
  40. cocotb/scheduler.py +1099 -0
  41. cocotb/share/def/.gitignore +2 -0
  42. cocotb/share/def/README.md +4 -0
  43. cocotb/share/def/aldec.def +61 -0
  44. cocotb/share/def/ghdl.def +43 -0
  45. cocotb/share/def/icarus.def +43 -0
  46. cocotb/share/def/modelsim.def +137 -0
  47. cocotb/share/include/cocotb_utils.h +93 -0
  48. cocotb/share/include/embed.h +56 -0
  49. cocotb/share/include/exports.h +20 -0
  50. cocotb/share/include/gpi.h +265 -0
  51. cocotb/share/include/gpi_logging.h +212 -0
  52. cocotb/share/include/py_gpi_logging.h +30 -0
  53. cocotb/share/include/vhpi_user_ext.h +26 -0
  54. cocotb/share/include/vpi_user_ext.h +55 -0
  55. cocotb/share/lib/verilator/verilator.cpp +196 -0
  56. cocotb/share/makefiles/Makefile.deprecations +12 -0
  57. cocotb/share/makefiles/Makefile.inc +176 -0
  58. cocotb/share/makefiles/Makefile.sim +113 -0
  59. cocotb/share/makefiles/simulators/Makefile.activehdl +79 -0
  60. cocotb/share/makefiles/simulators/Makefile.cvc +94 -0
  61. cocotb/share/makefiles/simulators/Makefile.ghdl +113 -0
  62. cocotb/share/makefiles/simulators/Makefile.icarus +111 -0
  63. cocotb/share/makefiles/simulators/Makefile.ius +125 -0
  64. cocotb/share/makefiles/simulators/Makefile.modelsim +32 -0
  65. cocotb/share/makefiles/simulators/Makefile.nvc +64 -0
  66. cocotb/share/makefiles/simulators/Makefile.questa +171 -0
  67. cocotb/share/makefiles/simulators/Makefile.riviera +183 -0
  68. cocotb/share/makefiles/simulators/Makefile.vcs +98 -0
  69. cocotb/share/makefiles/simulators/Makefile.verilator +86 -0
  70. cocotb/share/makefiles/simulators/Makefile.xcelium +136 -0
  71. cocotb/simulator.cpython-313-i386-linux-gnu.so +0 -0
  72. cocotb/task.py +325 -0
  73. cocotb/triggers.py +1104 -0
  74. cocotb/types/__init__.py +50 -0
  75. cocotb/types/array.py +309 -0
  76. cocotb/types/logic.py +292 -0
  77. cocotb/types/logic_array.py +298 -0
  78. cocotb/types/range.py +198 -0
  79. cocotb/utils.py +698 -0
  80. cocotb/wavedrom.py +199 -0
  81. cocotb/xunit_reporter.py +80 -0
  82. cocotb-1.9.2.dist-info/LICENSE +28 -0
  83. cocotb-1.9.2.dist-info/METADATA +168 -0
  84. cocotb-1.9.2.dist-info/RECORD +89 -0
  85. cocotb-1.9.2.dist-info/WHEEL +8 -0
  86. cocotb-1.9.2.dist-info/entry_points.txt +2 -0
  87. cocotb-1.9.2.dist-info/top_level.txt +21 -0
  88. pygpi/__init__.py +0 -0
  89. pygpi/entry.py +26 -0
cocotb/decorators.py ADDED
@@ -0,0 +1,332 @@
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. Supports
144
+ construction with or without having the type called.
145
+
146
+ So:
147
+
148
+ @MyClass(construction, args='go here')
149
+ def this_is_passed_as_f(...):
150
+ pass
151
+
152
+ ends up calling
153
+
154
+ MyClass.__init__(this_is_passed_as_f, construction, args='go here')
155
+ """
156
+
157
+ def __call__(cls, *args, **kwargs):
158
+ if len(args) == 1 and callable(args[0]): # case without parenthesis
159
+ f = args[0]
160
+ return type.__call__(cls, f, **kwargs)
161
+
162
+ # case with parenthesis
163
+ def decorator(f):
164
+ # fall back to the normal way of constructing an object, now that
165
+ # we have all the arguments
166
+ return type.__call__(cls, f, *args, **kwargs)
167
+
168
+ return decorator
169
+
170
+
171
+ @public
172
+ class test(coroutine, metaclass=_decorator_helper):
173
+ """
174
+ Decorator to mark a Callable which returns a Coroutine as a test.
175
+
176
+ The test decorator provides a test timeout, and allows us to mark tests as skipped
177
+ or expecting errors or failures.
178
+ Tests are evaluated in the order they are defined in a test module.
179
+
180
+ Used as ``@cocotb.test(...)``.
181
+
182
+ Args:
183
+ timeout_time (numbers.Real or decimal.Decimal, optional):
184
+ Simulation time duration before timeout occurs.
185
+
186
+ .. versionadded:: 1.3
187
+
188
+ .. note::
189
+ Test timeout is intended for protection against deadlock.
190
+ Users should use :class:`~cocotb.triggers.with_timeout` if they require a
191
+ more general-purpose timeout mechanism.
192
+
193
+ timeout_unit (str, optional):
194
+ Units of timeout_time, accepts any units that :class:`~cocotb.triggers.Timer` does.
195
+
196
+ .. versionadded:: 1.3
197
+
198
+ .. deprecated:: 1.5
199
+ Using ``None`` as the *timeout_unit* argument is deprecated, use ``'step'`` instead.
200
+
201
+ expect_fail (bool, optional):
202
+ If ``True`` and the test fails a functional check via an ``assert`` statement, :class:`pytest.raises`,
203
+ :class:`pytest.warns`, or :class:`pytest.deprecated_call` the test is considered to have passed.
204
+ If ``True`` and the test passes successfully, the test is considered to have failed.
205
+
206
+ expect_error (exception type or tuple of exception types, optional):
207
+ Mark the result as a pass only if one of the exception types is raised in the test.
208
+ This is primarily for cocotb internal regression use for when a simulator error is expected.
209
+
210
+ Users are encouraged to use the following idiom instead::
211
+
212
+ @cocotb.test()
213
+ async def my_test(dut):
214
+ try:
215
+ await thing_that_should_fail()
216
+ except ExceptionIExpect:
217
+ pass
218
+ else:
219
+ assert False, "Exception did not occur"
220
+
221
+ .. versionchanged:: 1.3
222
+ Specific exception types can be expected
223
+
224
+ .. deprecated:: 1.5
225
+ Passing a :class:`bool` value is now deprecated.
226
+ Pass a specific :class:`Exception` or a tuple of Exceptions instead.
227
+
228
+ skip (bool, optional):
229
+ Don't execute this test as part of the regression. Test can still be run
230
+ manually by setting :make:var:`TESTCASE`.
231
+
232
+ stage (int)
233
+ Order tests logically into stages, where multiple tests can share a stage.
234
+ Defaults to 0.
235
+ """
236
+
237
+ _id_count = 0 # used by the RegressionManager to sort tests in definition order
238
+
239
+ def __init__(
240
+ self,
241
+ f,
242
+ timeout_time=None,
243
+ timeout_unit="step",
244
+ expect_fail=False,
245
+ expect_error=(),
246
+ skip=False,
247
+ stage=0,
248
+ ):
249
+
250
+ if timeout_unit is None:
251
+ warnings.warn(
252
+ 'Using timeout_unit=None is deprecated, use timeout_unit="step" instead.',
253
+ DeprecationWarning,
254
+ stacklevel=2,
255
+ )
256
+ timeout_unit = "step" # don't propagate deprecated value
257
+ self._id = self._id_count
258
+ type(self)._id_count += 1
259
+
260
+ if timeout_time is not None:
261
+ co = coroutine(f)
262
+
263
+ @functools.wraps(f)
264
+ async def f(*args, **kwargs):
265
+ running_co = co(*args, **kwargs)
266
+
267
+ try:
268
+ res = await cocotb.triggers.with_timeout(
269
+ running_co, self.timeout_time, self.timeout_unit
270
+ )
271
+ except cocotb.result.SimTimeoutError:
272
+ running_co.kill()
273
+ raise
274
+ else:
275
+ return res
276
+
277
+ super().__init__(f)
278
+
279
+ self.timeout_time = timeout_time
280
+ self.timeout_unit = timeout_unit
281
+ self.expect_fail = expect_fail
282
+ if isinstance(expect_error, bool):
283
+ warnings.warn(
284
+ "Passing bool values to `except_error` option of `cocotb.test` is deprecated. "
285
+ "Pass a specific Exception type instead",
286
+ DeprecationWarning,
287
+ stacklevel=2,
288
+ )
289
+ if expect_error is True:
290
+ expect_error = (BaseException,)
291
+ elif expect_error is False:
292
+ expect_error = ()
293
+ self.expect_error = expect_error
294
+ self.skip = skip
295
+ self.stage = stage
296
+ self.im_test = True # For auto-regressions
297
+ self.name = self._func.__name__
298
+
299
+ def __call__(self, *args, **kwargs):
300
+ inst = self._func(*args, **kwargs)
301
+ coro = _RunningTest(inst, self)
302
+ return coro
303
+
304
+
305
+ if sys.version_info < (3, 7):
306
+ Task = _Task
307
+ RunningTask = _Task
308
+ RunningCoroutine = _RunningCoroutine
309
+ RunningTest = _RunningTest
310
+ else:
311
+
312
+ def __getattr__(attr: str) -> typing.Any:
313
+ if attr in ("Task", "RunningTask"):
314
+ warnings.warn(
315
+ f"The class {attr} has been renamed to cocotb.task.Task.",
316
+ DeprecationWarning,
317
+ stacklevel=2,
318
+ )
319
+ attr = "_Task"
320
+ elif attr in ("RunningCoroutine", "RunningTest"):
321
+ warnings.warn(
322
+ f"The class {attr} is now private. Update all uses to the parent class cocotb.task.Task.",
323
+ DeprecationWarning,
324
+ stacklevel=2,
325
+ )
326
+ attr = f"_{attr}"
327
+ try:
328
+ return globals()[attr]
329
+ except KeyError:
330
+ raise AttributeError(
331
+ f"module {__name__!r} has no attribute {attr!r}"
332
+ ) from None