hc99 commited on
Commit
362a075
·
verified ·
1 Parent(s): ce676f7

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. testbed/cocotb__cocotb/.gitpod.Dockerfile +56 -0
  2. testbed/cocotb__cocotb/CONTRIBUTING.md +537 -0
  3. testbed/cocotb__cocotb/tests/benchmark.py +62 -0
  4. testbed/cocotb__cocotb/tests/sxs.ps1 +15 -0
  5. testbed/cocotb__cocotb/tests/test_cases/issue_253/issue_253.py +28 -0
  6. testbed/cocotb__cocotb/tests/test_cases/issue_330/Makefile +33 -0
  7. testbed/cocotb__cocotb/tests/test_cases/issue_330/issue_330.py +72 -0
  8. testbed/cocotb__cocotb/tests/test_cases/issue_588/Makefile +31 -0
  9. testbed/cocotb__cocotb/tests/test_cases/issue_588/issue_588.py +29 -0
  10. testbed/cocotb__cocotb/tests/test_cases/issue_768_a/Makefile +3 -0
  11. testbed/cocotb__cocotb/tests/test_cases/issue_768_b/Makefile +3 -0
  12. testbed/cocotb__cocotb/tests/test_cases/issue_768_b/issue_768.py +21 -0
  13. testbed/cocotb__cocotb/tests/test_cases/issue_857/Makefile +31 -0
  14. testbed/cocotb__cocotb/tests/test_cases/issue_892/Makefile +33 -0
  15. testbed/cocotb__cocotb/tests/test_cases/test_external/Makefile +33 -0
  16. testbed/cocotb__cocotb/tests/test_cases/test_iteration_vhdl/test_iteration.py +158 -0
  17. testbed/cocotb__cocotb/tests/test_cases/test_long_log_msg/.gitignore +1 -0
  18. testbed/cocotb__cocotb/tests/test_cases/test_long_log_msg/Makefile +39 -0
  19. testbed/cocotb__cocotb/tests/test_cases/test_long_log_msg/test.vhd +14 -0
  20. testbed/cocotb__cocotb/tests/test_cases/test_long_log_msg/test_long_log_msg.py +10 -0
  21. testbed/cocotb__cocotb/tests/test_cases/test_module_var_empty/Makefile +15 -0
  22. testbed/cocotb__cocotb/tests/test_cases/test_module_var_messy/Makefile +15 -0
  23. testbed/cocotb__cocotb/tests/test_cases/test_module_var_messy/test_nothing.py +1 -0
  24. testbed/cocotb__cocotb/tests/test_cases/test_module_without_tests/Makefile +15 -0
  25. testbed/cocotb__cocotb/tests/test_cases/test_multi_dimension_array/test_cocotb_array.py +185 -0
  26. testbed/cocotb__cocotb/tests/test_cases/test_multi_level_module_path/Makefile +11 -0
  27. testbed/cocotb__cocotb/tests/test_cases/test_multi_level_module_path/__init__.py +0 -0
  28. testbed/cocotb__cocotb/tests/test_cases/test_multi_level_module_path/test_package/__init__.py +0 -0
  29. testbed/cocotb__cocotb/tests/test_cases/test_multi_level_module_path/test_package/test_module_path.py +12 -0
  30. testbed/cocotb__cocotb/tests/test_cases/test_package/Makefile +46 -0
  31. testbed/cocotb__cocotb/tests/test_cases/test_package/cocotb_package.sv +11 -0
  32. testbed/cocotb__cocotb/tests/test_cases/test_package/test_package.py +60 -0
  33. testbed/cocotb__cocotb/tests/test_cases/test_packed_union/Makefile +21 -0
  34. testbed/cocotb__cocotb/tests/test_cases/test_packed_union/test_packed_union.py +21 -0
  35. testbed/cocotb__cocotb/tests/test_cases/test_packed_union/test_packed_union.sv +12 -0
  36. testbed/cocotb__cocotb/tests/test_cases/test_plusargs/plusargs.py +44 -0
  37. testbed/cocotb__cocotb/tests/test_cases/test_seed/Makefile +10 -0
  38. testbed/cocotb__cocotb/tests/test_cases/test_seed/test_other.py +11 -0
  39. testbed/cocotb__cocotb/tests/test_cases/test_seed/test_seed.py +25 -0
  40. testbed/cocotb__cocotb/tests/test_cases/test_select_testcase/Makefile +10 -0
  41. testbed/cocotb__cocotb/tests/test_cases/test_select_testcase/x_tests.py +6 -0
  42. testbed/cocotb__cocotb/tests/test_cases/test_select_testcase/y_tests.py +6 -0
  43. testbed/cocotb__cocotb/tests/test_cases/test_select_testcase/y_tests_again.py +6 -0
  44. testbed/cocotb__cocotb/tests/test_cases/test_select_testcase_error/Makefile +12 -0
  45. testbed/cocotb__cocotb/tests/test_cases/test_select_testcase_error/x_tests.py +6 -0
  46. testbed/cocotb__cocotb/tests/test_cases/test_skipped/Makefile +22 -0
  47. testbed/cocotb__cocotb/tests/test_cases/test_skipped/test_skipped.py +15 -0
  48. testbed/cocotb__cocotb/tests/test_cases/test_sv_interface/Makefile +28 -0
  49. testbed/cocotb__cocotb/tests/test_cases/test_sv_interface/test_sv_if.py +15 -0
  50. testbed/cocotb__cocotb/tests/test_cases/test_sv_interface/top.sv +17 -0
testbed/cocotb__cocotb/.gitpod.Dockerfile ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM gitpod/workspace-full-vnc
2
+
3
+ USER gitpod
4
+
5
+ ## Install Python with --enable-shared
6
+ ARG PYTHON_VERSION=3.9.2
7
+ RUN rm -rf ${HOME}/.pyenv/versions/${PYTHON_VERSION}
8
+ RUN PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install ${PYTHON_VERSION}
9
+ RUN pyenv global ${PYTHON_VERSION}
10
+
11
+ RUN pip3 install --upgrade pip
12
+
13
+ # Install extra packages
14
+ RUN pip3 install -U pytest flake8 pylint pytype mypy gcovr cherrypy dowser
15
+
16
+ # Re-synchronize the OS package index
17
+ RUN sudo apt-get update
18
+
19
+ # Install all needed packages for all simulators
20
+ RUN sudo apt-get install -y perl make flex gnat gtkwave swig autoconf g++ bison libfl2 libfl-dev ccache libgoogle-perftools-dev numactl perl-doc
21
+ RUN sudo rm -rf /var/lib/apt/lists/*
22
+
23
+ ## Install Icarus Verilog
24
+ RUN brew install icarus-verilog
25
+
26
+ ## Install Verilator
27
+ #ENV VERILATOR_BRANCH=stable
28
+ ENV VERILATOR_BRANCH=v4.106
29
+
30
+ RUN git clone https://github.com/verilator/verilator.git --branch ${VERILATOR_BRANCH} verilator \
31
+ && unset VERILATOR_ROOT \
32
+ && cd verilator \
33
+ && autoconf \
34
+ && ./configure \
35
+ && make --silent \
36
+ && sudo make --silent install \
37
+ && cd .. \
38
+ && rm -rf verilator
39
+
40
+ ## Install GHDL
41
+ ENV GHDL_BRANCH=v1.0.0
42
+ RUN git clone https://github.com/ghdl/ghdl.git --depth=1 --branch ${GHDL_BRANCH} ghdl \
43
+ && cd ghdl \
44
+ && ./configure \
45
+ && make --silent \
46
+ && sudo make --silent install \
47
+ && cd .. \
48
+ && rm -rf ghdl
49
+
50
+ # Install cvc
51
+ RUN git clone https://github.com/cambridgehackers/open-src-cvc.git --depth=1 cvc \
52
+ && cd cvc/src \
53
+ && make -f makefile.cvc64 --silent \
54
+ && sudo cp cvc64 /usr/local/bin \
55
+ && cd ../.. \
56
+ && rm -rf cvc
testbed/cocotb__cocotb/CONTRIBUTING.md ADDED
@@ -0,0 +1,537 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Cocotb Contribution Guidelines
2
+
3
+ Welcome to the cocotb development!
4
+ We are an inclusive community with the common goal of improving the cocotb, a coroutine based cosimulation library for writing VHDL and Verilog testbenches in Python.
5
+ This guide explains how to contribute to cocotb, and documents the processes we agreed on to manage the project.
6
+ All processes in this document are designed to streamline the development effort, to avoid bottlenecks, and to ultimately give a pleasant experience to all involved.
7
+
8
+
9
+ ## Getting Help
10
+
11
+ Cocotb is a diverse and challenging project to contribute to.
12
+ If you ever feel lost, out of your depth, or simply want to know more, the [cocotb Gitter channel](https://gitter.im/cocotb/Lobby) is actively watched by many cocotb users, contributors, and maintainers.
13
+ It is a good idea if you are unsure whether your problem or question is worthy of a Github Issue to first post it to the Gitter channel.
14
+ You may also ask questions in [Github issues](https://github.com/cocotb/cocotb/issues).
15
+ If you don't receive any response on the Gitter channel or a Github issue, or you want help privately, you may directly contact a [maintainer](#maintainers).
16
+
17
+
18
+ ## What to Work On
19
+
20
+ There is *a lot* of work to do on this project, no matter your area of expertise or skill level.
21
+
22
+ If you are a beginner there are several [Github issues](https://github.com/cocotb/cocotb/issues) marked [`good first issue`](https://github.com/cocotb/cocotb/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22) you can look at.
23
+ There are also a number of things you can work on that aren't in Github issues and don't require in-depth knowledge of the cocotb internals.
24
+ They including the following:
25
+
26
+ * Documentation improvements
27
+ * Managing Github issues and the Gitter channel
28
+ * Testing and coverage improvements
29
+
30
+ Cocotb is still not perfect. There are plenty of [bug fixes](https://github.com/cocotb/cocotb/issues?q=is%3Aopen+is%3Aissue+label%3Atype%3Abug) and [features](https://github.com/cocotb/cocotb/issues?q=is%3Aopen+is%3Aissue+label%3Atype%3Afeature) that can be worked on.
31
+ Most of these are recorded as Github issues.
32
+
33
+
34
+ ### Documentation
35
+
36
+ Cocotb's documentation is always open to improvements.
37
+ Improving documentation will help users better understand and use cocotb;
38
+ and may decrease the number of questions the Gitter channel and Github issue page.
39
+ Updating documentation requires knowledge of:
40
+
41
+ * [reStructuredText](https://docutils.sourceforge.io/rst.html)
42
+ * [Sphinx documentation generator](https://www.sphinx-doc.org/en/master/)
43
+ * [Markdown](https://www.markdownguide.org/)
44
+ * [How to architect documentation](https://documentation.divio.com/)
45
+
46
+ Some documentation should be located in the official documentation on [Read the Docs/RTD](https://docs.cocotb.org/en/latest/),
47
+ while the rest belongs on the [Wiki](https://github.com/cocotb/cocotb/wiki).
48
+ There are several ways to improve the documentation:
49
+
50
+ * Better documenting core functionality (RTD)
51
+ * Documenting common "gotchas" (RTD)
52
+ * Documenting difficult and niche use cases (Wiki)
53
+ * Documenting common design patterns (Wiki)
54
+ * Documenting internal components (Wiki)
55
+
56
+ See the documentation on [building the documentation](#building-documentation-locally) and the [guidelines on submitting pull requests](#patch-requirements).
57
+ Documentation improvements typically require no maintainer pre-approval; you can simply work on the documentation and open a pull request.
58
+ Documentation on the Wiki does not require a pull request; any user with a Github account can contribute to it.
59
+ Please be responsible with that power.
60
+
61
+
62
+ ### Project Management
63
+
64
+ The cocotb project is [fairly popular](https://larsasplund.github.io/github-facts/verification-practices.html#frameworks) and the
65
+ [Gitter channel](https://gitter.im/cocotb/Lobby) and
66
+ [Github issues](https://github.com/cocotb/cocotb) page receive a fair amount of traffic;
67
+ which is only expected to increase.
68
+ People are needed to categorize issues and pull requests, and respond to questions.
69
+ Working this task is the quickest way to learn how cocotb works.
70
+ Tending to this task requires the following:
71
+
72
+ * people skills
73
+ * an understanding of the scope of cocotb
74
+ * general understanding about how cocotb works
75
+
76
+ Someone working this task should set notifications on the Gitter channel to be notified of any new comments.
77
+ They should also "watch" the Github repo by selecting the "Watching" notification level button in the upper right corner of the main Github page.
78
+ Finally, they should notify the maintainers that they are able and willing to accept questions.
79
+
80
+ To be able to add labels and close issues and PRs you will need special permissions.
81
+ Contact a [maintainer](#maintainer) if you are interested in receiving these permissions.
82
+ They will be granted according to the project's need and the requestor's familiarity with cocotb.
83
+ Once you have those permissions, see the guidelines on [managing issues and pull requests](#Managing-of-Issues-and-Pull-Requests).
84
+
85
+ This task can also be done without special repo permissions, by just commenting on the issue or PR.
86
+ This is especially helpful for Github issues about bugs.
87
+ If you can duplicate the bug or confirm the bug report is invalid, that helps maintainers *a lot*.
88
+
89
+
90
+ ### Tests and Coverage
91
+
92
+ Cocotb has a suite of unit tests (located in the `tests` directory) and examples (located in the `examples` directory) which are functional acceptance tests.
93
+ If a pull request cannot pass *all* of these tests, it will likely be rejected.
94
+ To ensure cocotb only includes the highest quality code, these test should be exhaustive.
95
+ We use code coverage as a quantifiable metric of the "exhaustiveness" of these tests, and wish to improve this metric.
96
+
97
+ Working on this task requires a familiarity with:
98
+
99
+ * Cocotb's core functionality
100
+ * How to write Verilog and VHDL
101
+ * How to write cocotb tests in Python
102
+ * (Optionally) [codecov](https://docs.codecov.io/docs); coverage aggregator and Github bot
103
+ * (Optionally) the [coverage](https://coverage.readthedocs.io/en/latest/) module, for Python code coverage
104
+ * (Optionally) [gcov](https://gcc.gnu.org/onlinedocs/gcc/Gcov.html), for C++ code coverage
105
+ * (Optionally) [Github Actions](https://docs.github.com/en/free-pro-team@latest/actions), for automatic acceptance testing
106
+
107
+ Cocotb's regression tests can be improved by:
108
+
109
+ * Testing more of cocotb's core functionality
110
+ * Testing corner cases left out of the current set of tests (identified by looking at code coverage)
111
+ * Increasing the matrix of simulators, operating system, and Python installations tested in CI
112
+
113
+ Testing improvements don't require maintainer pre-approval, but require a pull request.
114
+ Please see the [guidelines on submitting pull requests](#patch-requirements).
115
+
116
+
117
+ ### Features
118
+
119
+ Cocotb is still in development and new features are still welcome and appreciated;
120
+ as long as they stay [in scope](#Architecture-and-Scope-of-Cocotb).
121
+ Cocotb is comprised of several major codebases, each requiring different sets of skills and development process.
122
+ Instead of including that breakdown here, it is done in the [internal documentation](https://github.com/cocotb/cocotb/wiki/cocotb-Internals).
123
+
124
+ Small improvements to existing features generally do not require maintainer pre-approval.
125
+ Large changes, approximately >150 LOC changed, and new features generally require maintainer pre-approval.
126
+ If a change is deemed too large for the main repo, or out of scope,
127
+ please feel free to make it an [extension](https://docs.cocotb.org/en/latest/extensions.html).
128
+
129
+ ***New features must not break existing features.***
130
+
131
+ Feature changes require full coverage of the added feature.
132
+ This likely requires adding new unit tests to the `tests` directory.
133
+ Issue-specific test directories will not be accepted, unless a special HDL entity is required.
134
+ Instead, place the test in an existing test suite (`test_cocotb`, `test_discovery`, etc.).
135
+
136
+ Features should generally follow the following design principles:
137
+
138
+ * Something the user cannot do without assistance of cocotb-specific code
139
+ * Orthogonal to existing features
140
+ * Easily composed with existing features
141
+ * Limited in scope and impervious to scope creep
142
+
143
+
144
+ ### Bugfixes
145
+
146
+ **!WARNING!** Bugfixing cocotb is not for the faint of heart!
147
+
148
+ Bugs happen.
149
+ cocotb supports many simulators that have inconsistent support for the procedural interfaces cocotb depends on,
150
+ and it has a number of features that aren't wholly tested yet.
151
+ There are likely many bugs lurking, waiting to be found;
152
+ which is why increasing testing and code coverage is important.
153
+ Working on bugfixing can be very challenging, depending on the cause of the bug.
154
+ In general, bugfixing requires knowledge of:
155
+
156
+ * How cocotb works
157
+ * [cocotb's debugging utilities](https://github.com/cocotb/cocotb/wiki/Debugging-HOW-TOs#cocotb-debugging-functionality)
158
+ * (Optional) Simulator interfaces (VPI, VHPI, and FLI)
159
+ * (Optional) Python debugging tools ([pdb](https://github.com/cocotb/cocotb/wiki/Debugging-HOW-TOs#using-a-remote-python-debugger), [dowser](https://github.com/cocotb/cocotb/wiki/Debugging-HOW-TOs#debugging-python-memory-usage))
160
+ * (Optional) C/C++ debugging tools ([gdb](https://github.com/cocotb/cocotb/wiki/Debugging-HOW-TOs#using-a-remote-cc-debugger), [valgrind](https://github.com/cocotb/cocotb/wiki/Debugging-HOW-TOs#debugging-cc-memory-usage))
161
+ * (Optional) Specific simulators (sometimes the bug exists in the simulator and not cocotb)
162
+
163
+ Fixing a bug follows the procedure:
164
+
165
+ 1. Locate buggy behavior, make a Github issue
166
+ * Maintainers may be able to offer more information, confirm it as a bug, or confirm it as expected behavior
167
+ 2. Make a Minimum Reproducible Failing Example (MRFE, pronounced like Murphy, like the law :)
168
+ * Confirms the bug
169
+ * Add to [regressions](#running-tests-locally)
170
+ 3. Open a new draft pull request with the MRFE test
171
+ * It should cause CI to fail
172
+ 4. Determine scope of the bug, and add that detail to the pull request
173
+ * Which simulators/interfaces are affected?
174
+ * Which Python versions?
175
+ * Which operating systems?
176
+ 5. Determine the cause of the bug, and add that detail to the pull request
177
+ * May require Python or C debugging, or the builtin cocotb debugging utilities
178
+ 6. Make a fix, and push it up on the PR branch
179
+ * It should cause the CI to pass
180
+ * The fix should not break other existing functionality
181
+
182
+ Details on how to debug cocotb can be found on the [Wiki](https://github.com/cocotb/cocotb/wiki/Debugging-HOW-TOs).
183
+
184
+
185
+ ### Deprecations and Removals
186
+
187
+ Cocotb's treatment of deprecations and removal follows guidelines laid out [here](https://symfony.com/doc/current/setup/upgrade_major.html#make-your-code-deprecation-free).
188
+ Deprecations serve the following purposes:
189
+
190
+ * Remove legacy code that has been deemed out of scope
191
+ * Remove support for a simulator, OS, or Python version that is past end-of-life
192
+ * Remove potentially dangerous, broken, and misunderstood interfaces (usually accompanied with a superior alternative)
193
+
194
+ Deprecations can be incorporated at any time.
195
+ They are implemented in Python by [issuing a `DeprecationWarning`](https://docs.python.org/3/library/warnings.html#warnings.warn)
196
+ or using the [`@deprecated`](cocotb/_deprecation.py) decorator.
197
+ In C++ code, deprecations are implemented by [issuing a LOG_WARN](https://docs.cocotb.org/en/stable/generated/file/gpi__logging_8h.html?highlight=LOG_WARN#c.LOG_WARN) with `DEPRECATED` in the message.
198
+
199
+ Removals only occur on major version bumps.
200
+ One can create removal pull requests at any time, on the condition they will not be accepted until the next release is known to be a major version release.
201
+
202
+
203
+ ### Breaking Changes
204
+
205
+ Breaking changes are changes to the interface or behavior of a user-facing entity.
206
+ They are necessary when a user-facing interfaces are broken in a way that cannot be changed without changing the behavior of user's code.
207
+ In these situations it is ideal to be able to implement a switch between new better behavior and the old broken behavior.
208
+ On major version bumps, this switch will be deprecated and the new behavior will become the default.
209
+
210
+ In cases where behavioral switches are not easy to implement, breaking changes will attempt to be broadcasted to user by [issuing a `DeprecationWarning`](https://docs.python.org/3/library/warnings.html#warnings.warn) when the to-be-changed behavior is invoked.
211
+ Before major releases, pending breaking changes will be incorporated.
212
+
213
+ One can create pull requests with breaking changes at any time, on the condition they will not be accepted until the next release is known to be a major version release.
214
+
215
+
216
+ ## Setting Up a Development Environment
217
+
218
+ Assuming you have used cocotb prior to reading this guide, you will already have the cocotb [installation prerequisites](https://docs.cocotb.org/en/latest/install.html) and standard development tools (editor, shell, git, etc.) installed.
219
+
220
+ First, you should [fork and clone](https://guides.github.com/activities/forking/) the cocotb repo to your machine.
221
+ This will allow you to make changes to the cocotb source code, create pull requests, and run regressions and build documentation locally.
222
+
223
+ Additionally, you will need [doxygen](https://www.doxygen.nl/index.html), for building documentation;
224
+ [nox](https://pypi.org/project/nox/), for building documentation and running regression tests;
225
+ and [pre-commit](https://pre-commit.com/), to check your changes before committing them.
226
+
227
+ We recommend if you are using a Linux distribution to use your system package manager to install doxygen.
228
+ Likewise, doxygen can be installed using the homebrew package manager on Mac OS.
229
+ Windows contributors should download a binary distribution installer from the main website.
230
+
231
+ `nox` and `pre-commit` are Python projects and can be installed with `pip`:
232
+
233
+ ```command
234
+ pip install nox pre-commit
235
+ ```
236
+
237
+ To enable pre-commit run the following command at the root of the cloned project to install the git hooks.
238
+ The first run of pre-commit will build an environment for you, so it may take a while.
239
+ Following runs should be much quicker.
240
+
241
+ ```command
242
+ pre-commit install
243
+ ```
244
+
245
+ When committing, pre-commit's hook will run, checking your changes for formatting, code smells, etc.
246
+ You will see the lists of checks printed and whether they passed, were skipped, or failed.
247
+ If any of the checks fail, it is recommended to fix them before opening a pull request,
248
+ otherwise the pull request checks will fail as well.
249
+
250
+ Now you are ready to contribute!
251
+
252
+
253
+ ## Running Tests Locally
254
+
255
+ First, [set up your development environment](#setting-up-a-development-environment).
256
+
257
+ Our tests are managed by `nox`, which runs both `pytest` tests and our system of makefiles.
258
+ The regression does not end on the first failure, but continues until all tests in the `/tests` and `/examples` directories have been run.
259
+
260
+ To run the tests locally with `nox`, issue the following command.
261
+
262
+ ```command
263
+ nox -s dev_test
264
+ ```
265
+
266
+ At the end of the regression, if there were any test failures, the tests that failed will be printed.
267
+ If the tests succeed you will see the message `Session tests was successful` printed in green.
268
+
269
+ By default the `dev_test` nox session runs all simulator-agnostic tests, as well as all tests which require a simulator and can be run against Icarus Verilog.
270
+ Icarus Verilog must be installed.
271
+
272
+ The simulator and the toplevel language can be changed by setting the environment variables [`SIM`](https://docs.cocotb.org/en/latest/building.html#var-SIM) and [`TOPLEVEL_LANG`](https://docs.cocotb.org/en/latest/building.html#var-TOPLEVEL_LANG).
273
+ Alternatively, the simulator-specific nox sessions can be used, as described below.
274
+
275
+ ### Selecting a Language and Simulator for Regression
276
+
277
+ cocotb can be used with multiple simulators, and can run tests against all of them.
278
+ Nox provides a session for each valid simulator/language/GPI interface combination, from which one or multiple sessions can be selected.
279
+
280
+ The following examples are good starting points;
281
+ refer to the [nox command-line usage documentation](https://nox.thea.codes/en/stable/usage.html) for more information.
282
+
283
+ ```command
284
+ # List all available sessions.
285
+ nox -l
286
+
287
+ # Run all simulator-agnostic tests.
288
+ nox -s dev_test_nosim
289
+
290
+ # Run the simulator-specific tests against Xcelium, using a VHDL toplevel and
291
+ # the VHPI interface.
292
+ nox -s "dev_test_sim(sim='xcelium', toplevel_lang='vhdl', gpi_interface='vhpi')"
293
+
294
+ # Run all simulator-specific tests against Icarus Verilog and GHDL.
295
+ # Both simulators must be installed locally.
296
+ nox -k "dev_test_sim and (icarus or ghdl)"
297
+ ```
298
+
299
+ ### Running Individual Tests Locally
300
+
301
+ Each test under `/tests/test_cases/*/` and `/examples/*/tests/` can be run individually.
302
+ This is particularly useful if you want to run a particular test that fails the regression.
303
+
304
+ First you must install cocotb from source by navigating to the project root directory and issuing the following command:
305
+
306
+ ```command
307
+ python -m pip install .
308
+ ```
309
+
310
+ On Windows, you must instead install cocotb from source like so:
311
+
312
+ ```command
313
+ python -m pip install --global-option build_ext --global-option --compiler=mingw32 .
314
+ ```
315
+
316
+ Once that has been done, you can navigate to the directory containing the test you wish to run.
317
+ Then you may issue an [appropriate](https://docs.cocotb.org/en/latest/building.html#makefile-based-test-scripts) `make` command.
318
+ For example, if you want to test with Icarus using Verilog sources:
319
+
320
+ ```command
321
+ make SIM=icarus TOPLEVEL_LANG=verilog
322
+ ```
323
+
324
+
325
+ ## Building Documentation Locally
326
+
327
+ First, [set up your development environment](#setting-up-a-development-environment).
328
+
329
+ Documentation is built locally using `nox`.
330
+ The last message in the output will contain a URL to the documentation you just built.
331
+ Simply copy and paste the link into your browser to view it.
332
+ The documentation will be built in the same location on your hard drive on every run, so you only have to refresh the page to see new changes.
333
+
334
+ To build the documentation locally on Linux or Mac, issue the following command:
335
+
336
+ ```command
337
+ nox -e docs
338
+ ```
339
+
340
+ Building the documentation is not currently supported on Windows.
341
+
342
+
343
+ ## Architecture and Scope of Cocotb
344
+
345
+ Cocotb has seen adoption in a wide variety of scenarios with sometimes conflicting requirements.
346
+ To foster experimentation and to decentralize the development process the architecture of cocotb is highly modular.
347
+ A solid core forms the foundation upon which extensions can provide higher-level functionality.
348
+
349
+ The core of cocotb are
350
+ - the infrastructure to write testbenches with coroutines, threads, etc.,
351
+ - the abstraction and interaction with simulators through interfaces like VPI, GPI, etc.,
352
+ - tooling to run tests, and
353
+ - core primitives to interact with the simulation: triggers, data access classes, etc.
354
+
355
+ As a general rule, functionality beyond this core set should go into extensions.
356
+ However, none of these rules are set in stone.
357
+ They can and should be challenged at times to ensure the project stays relevant to the majority of its users.
358
+
359
+
360
+ ## Maintainer Pre-approval
361
+
362
+ After making changes to cocotb, changes must be approved by at least one maintainer before being included.
363
+ Out-of-scope and breaking changes ***will not be accepted***.
364
+ Also a maintainer could object to a change due to implementation approach or code quality reasons.
365
+ To potentially save you frustration and time, it is a good idea to get maintainer pre-approval on the task before starting it.
366
+
367
+ The best way to get maintainer pre-approval is to make a [Github issue](https://github.com/cocotb/cocotb/issues).
368
+ These issues can be a place for maintainers, as well as other users, to voice opinions on a proposed change before the task is worked.
369
+ You may also propose changes on the [Gitter channel](https://gitter.im/cocotb/Lobby) or by directly contacting a [maintainer](#maintainer).
370
+
371
+
372
+ ## How to Get Changes Merged
373
+
374
+ Have you fixed a bug in cocotb, or want to add new functionality to it?
375
+ Cocotb follows the typical [GitHub flow](https://guides.github.com/introduction/flow/) and makes use of pull requests and reviews.
376
+ Follow the steps below to get your changes merged, i.e. integrated into the main cocotb codebase.
377
+
378
+ 1. Create an issue ticket on [cocotb's GitHub issue tracker](https://github.com/cocotb/cocotb/issues) describing the problem.
379
+ Issues are also a good place to discuss design options with others before writing code.
380
+ 2. [Fork](https://help.github.com/articles/fork-a-repo/) the [cocotb GitHub repository](https://github.com/cocotb/cocotb) into your personal namespace.
381
+ 3. Create a new branch off the `master` branch for your set of changes.
382
+ Use one branch per "topic," i.e. per set of changes which belong together.
383
+ 4. Create one or multiple commits to address the issue.
384
+ Make sure to read and follow the [Patch Requirements](#patch-requirements) when preparing your commits.
385
+ 5. Create new [pull request (PR)](https://github.com/cocotb/cocotb/pulls).
386
+ 6. When you submit (or update) the pull request, a suite of regression tests will run.
387
+ If any of them turns "red," i.e. reports a failure, you most likely need to fix your code before it can be merged.
388
+ 7. The pull request needs to be reviewed by at least one maintainer.
389
+ We aim to give feedback to all pull requests within a week, but as so often, life can get in the way.
390
+ If you receive no feedback from a maintainer within that time, please contact them directly (e.g. on [Gitter](https://gitter.im/cocotb) or email).
391
+ You can find a [list of all maintainers](#maintainers) below.
392
+ If a maintainer asks you to explain or modify code, try to do so.
393
+ 8. Once your code has at least one positive review from a maintainer and no maintainer strongly objects it your code is ready to be merged into the `master` branch.
394
+
395
+
396
+ ## Patch Requirements
397
+
398
+ All changes which should go into the main codebase of cocotb must follow this set of requirements.
399
+
400
+ - The code must be within the [scope of cocotb](#architecture-and-scope-of-cocotb).
401
+ - All code must be licensed under the [Revised BSD License](https://github.com/cocotb/cocotb/blob/master/LICENSE).
402
+ By contributing to this project you signal your agreement with these license terms.
403
+ - All code must follow the established coding standards:
404
+ - For Python code, follow the [PEP 8](https://www.python.org/dev/peps/pep-0008/) style guide.
405
+ - For C++ code, follow the [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html) but with 4 space indentation.
406
+ You can run the following command to automatically format the modified file to match the standard:
407
+ ```command
408
+ clang-format -i <file>
409
+ ```
410
+ - All code must pass existing tests.
411
+ New functionality must be accompanied by tests, and bug fixes should add tests to increase the test coverage and prevent regressions.
412
+ - If code changes or enhances documented behavior the documentation should be updated.
413
+ - If a change is user-visible, a newsfragment should be added to `docs/source/newsfragments`.
414
+ - All pull requests must be accepted by at least one maintainer, with no maintainer strongly objecting.
415
+ Reviews must be performed by a person other than the primary author of the code.
416
+ - All commits should follow established best practices when creating a commit message:
417
+ - The first line of the commit message is the short summary of what the code change does.
418
+ Keep this line below 50 characters.
419
+ - Then have one blank line.
420
+ - Now comes the long description of the commit.
421
+ Use this text to discuss things which are not obvious from the code, especially *why* changes were made.
422
+ Include the GitHub issue number (if one exists) in the form "Fixes #nnn" ([read more about that](https://help.github.com/articles/closing-issues-using-keywords/)).
423
+ Keep each description line below 72 characters.
424
+ - Use the following header for new non-example files:
425
+ ```python
426
+ # Copyright cocotb contributors
427
+ # Licensed under the Revised BSD License, see LICENSE for details.
428
+ # SPDX-License-Identifier: BSD-3-Clause
429
+ ```
430
+ - Use the following header for new example files:
431
+ ```python
432
+ # This file is public domain, it can be freely copied without restrictions.
433
+ # SPDX-License-Identifier: CC0-1.0
434
+ ```
435
+
436
+ ## Managing of Issues and Pull Requests
437
+
438
+ The cocotb project makes use of GitHub labels attached to issues and pull requests to structure the development process.
439
+ Each issue and pull request can have multiple labels assigned.
440
+
441
+ The `type` labels define the type of issue or PR:
442
+ - `type:bug`: a bug in existing functionality
443
+ - `type:feature`: new functionality
444
+ - `type:question`: a support question
445
+ - `type:cleanup`: cleanup or refactoring on code, documentation, or other areas
446
+ - `type:deprecation`: API that should warn and eventually be removed
447
+
448
+ The `status` labels give a quick impression of the current status of the issue or PR:
449
+ - `status:worksforme`: the issue it not reproducible, or intended behavior (i.e. not a bug)
450
+ - `status:blocked`: further progress is blocked by a dependency, e.g. other code which must be commited first.
451
+ - `status:needs-info`: feedback from someone is required. The issue/PR text gives more details.
452
+ - `status:duplicate`: the same issue is already being handled in another issue/PR.
453
+ - `status:close?`: issues which can probably be closed, but need a second pair of eyes
454
+ - `status:needs-proprietary-testing`: Help needed testing on a proprietary tool
455
+ - `status:out-of-scope`: An issue or PR that was closed because the feature or bug was deemed to be out of scope
456
+
457
+ For the use in pull requests the following additional status labels are defined:
458
+ - `status:needs-review`: this PR needs at least one review
459
+ - `status:changes-requested`: changes are requested to the code
460
+ - `status:ready-for-merge`: this PR is ready (according to the [Patch Requirements](#patch-requirements)) to be merged
461
+ - `status:needs-rebase`: needs a git rebase
462
+ - `status:needs-newsfragment`: Needs a towncrier newsfragment for the changelog
463
+
464
+ The `category` labels help maintainers to filter issues which are relevant to their area of expertise:
465
+ - `category:OS:MacOS`: Mac OS/OS X specific issues
466
+ - `category:OS:Linux`: Linux specific issues
467
+ - `category:OS:Windows`: Microsoft Windows-specific issues
468
+ - `category:simulators`: simulator support, including VPI/GPI/etc.
469
+ - `category:simulators:activehdl`: Aldec Active-HDL
470
+ - `category:simulators:cvc`: Tachyon CVC
471
+ - `category:simulators:ghdl`: GHDL
472
+ - `category:simulators:icarus`: Icarus Verilog (iverilog)
473
+ - `category:simulators:ius`: Cadence Incisive (IUS)
474
+ - `category:simulators:modelsim`: Mentor Modelsim
475
+ - `category:simulators:questa`: Mentor Questa
476
+ - `category:simulators:riviera`: Aldec Riviera-PRO
477
+ - `category:simulators:vcs`: Synopsys VCS
478
+ - `category:simulators:verilator`: Verilator
479
+ - `category:simulators:xcelium`: Cadence Xcelium
480
+ - `category:codebase:gpi`: relating to the GPI or one of the implementation
481
+ - `category:codebase:pygpi`: relating to the Python wrapper around the GPI (embed library and simulator module)
482
+ - `category:codebase:scheduler`: relating to the coroutine scheduler, triggers, or coroutine objects
483
+ - `category:codebase:test-runner`: relating to code for automating test runs (regression manager)
484
+ - `category:codebase:handle`: relating to handles or handle types (BinaryValue)
485
+ - `category:codebase:project-automation`: relating to included project automation (makefiles)
486
+ - `category:codebase:testbenching`: relating to testbenching components (Drivers, Monitors, etc.)
487
+ - `category:building`: relating to build C/C++ libraries and extension modules
488
+ - `category:packaging`: issues related to (PyPi) packaging, etc.
489
+ - `category:docs`: documentation issues and fixes
490
+ - `category:extensions`: cocotb extensions
491
+ - `category:performance`: performance topics
492
+ - `category:tests-ci`: continuous integration and unit tests
493
+
494
+ To help new contributors find a good issue to work on one more label is used (following [GitHub standard practices](#https://help.github.com/articles/helping-new-contributors-find-your-project-with-labels/)):
495
+ - `good first issue`: this issue is a good starting point for new contributors.
496
+ The issue should give an actionable description of what to do to complete this task, along with contact information of a mentor for this task.
497
+
498
+ cocotb explicitly uses no priority labels, as experience indicates that they provide little value.
499
+
500
+ Issues and pull requests which are invalid, or where feedback is lacking for four weeks, should be closed.
501
+
502
+ ## Cocotb Releases
503
+
504
+ cocotb aims to keep the `master` branch always in a releasable state.
505
+ At least four times a year an official release should be created.
506
+ It is the job of the maintainers to find a suitable time for a release, to communicate it to the community, and to coordinate it.
507
+
508
+ ## Maintainers
509
+
510
+ Cocotb uses a shared maintainer model.
511
+ Most maintainers are experts in part of the cocotb codebase, and are primarily responsible for reviews in this area.
512
+
513
+ - Kaleb Barrett (@ktbarrett)
514
+ - Tomasz Hemperek (@themperek)
515
+ - Marlon James (@marlonjames)
516
+ - Colin Marquardt (@cmarqu)
517
+ - Philipp Wagner (@imphil)
518
+ - Eric Wieser (@eric-wieser)
519
+
520
+ Founders
521
+
522
+ - Chris Higgs (@chiggs)
523
+ - Stuart Hodgson (@stuarthodgson)
524
+
525
+ ### Getting in Contact with a Maintainer
526
+
527
+ All of the maintainers are active on the [Gitter channel](https://github.com/cocotb/cocotb).
528
+ They prefer inquiries go through direct messages on Gitter,
529
+ or by mentioning them in the main [cocotb Gitter channel](https://gitter.im/cocotb/Lobby) using `@{maintainer name}`.
530
+ Maintainers are unpaid volunteers, so it might take a while for a maintainer to get back to you.
531
+
532
+
533
+ ## Code of Conduct
534
+
535
+ The cocotb development community aims to be welcoming to everyone.
536
+ The [FOSSi Foundation Code of Conduct](https://www.fossi-foundation.org/code-of-conduct) applies.
537
+ Please contact any of the maintainers if you feel uncomfortable in the cocotb development community.
testbed/cocotb__cocotb/tests/benchmark.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 sys
6
+ from pathlib import Path
7
+
8
+ from cocotb.runner import get_runner
9
+
10
+
11
+ def build_and_run_matrix_multiplier(benchmark, sim):
12
+ hdl_toplevel_lang = "verilog"
13
+ build_args = []
14
+ test_args = []
15
+
16
+ if sim == "nvc":
17
+ build_args = ["--std=08"]
18
+ hdl_toplevel_lang = "vhdl"
19
+
20
+ verilog_sources = []
21
+ vhdl_sources = []
22
+
23
+ proj_path = (
24
+ Path(__file__).resolve().parent.parent / "examples" / "matrix_multiplier"
25
+ )
26
+
27
+ sys.path.append(str(proj_path / "tests"))
28
+
29
+ if hdl_toplevel_lang == "verilog":
30
+ verilog_sources = [proj_path / "hdl" / "matrix_multiplier.sv"]
31
+ else:
32
+ vhdl_sources = [
33
+ proj_path / "hdl" / "matrix_multiplier_pkg.vhd",
34
+ proj_path / "hdl" / "matrix_multiplier.vhd",
35
+ ]
36
+
37
+ runner = get_runner(sim)
38
+
39
+ runner.build(
40
+ hdl_toplevel="matrix_multiplier",
41
+ verilog_sources=verilog_sources,
42
+ vhdl_sources=vhdl_sources,
43
+ build_args=build_args,
44
+ )
45
+
46
+ @benchmark
47
+ def run_test():
48
+ runner.test(
49
+ hdl_toplevel="matrix_multiplier",
50
+ hdl_toplevel_lang=hdl_toplevel_lang,
51
+ test_module="test_matrix_multiplier",
52
+ test_args=test_args,
53
+ seed=123456789,
54
+ )
55
+
56
+
57
+ def test_matrix_multiplier_icarus(benchmark):
58
+ build_and_run_matrix_multiplier(benchmark, "icarus")
59
+
60
+
61
+ def test_matrix_multiplier_nvc(benchmark):
62
+ build_and_run_matrix_multiplier(benchmark, "nvc")
testbed/cocotb__cocotb/tests/sxs.ps1 ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright cocotb contributors
2
+ # Licensed under the Revised BSD License, see LICENSE for details.
3
+ # SPDX-License-Identifier: BSD-3-Clause
4
+
5
+ # Run this script with:
6
+ # powershell -executionpolicy bypass -File tests\sxs.ps1
7
+
8
+ $j = Start-Job -ScriptBlock { SxsTrace Trace -logfile:SxsTrace.etl }
9
+ Start-Sleep -s 5
10
+ python -c "import cocotb.simulator"
11
+ Start-Sleep -s 5
12
+ $j | Stop-Job
13
+ SxsTrace Stoptrace
14
+ SxsTrace Parse -logfile:SxsTrace.etl -outfile:SxsTrace.txt
15
+ Get-Content SxsTrace.txt
testbed/cocotb__cocotb/tests/test_cases/issue_253/issue_253.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # A set of regression tests for open issues
2
+
3
+ import cocotb
4
+ from cocotb.triggers import Timer
5
+
6
+
7
+ async def toggle_clock(dut):
8
+ dut.clk.value = 0
9
+ await Timer(10, "ns")
10
+ assert dut.clk.value.integer == 0, "Clock not set to 0 as expected"
11
+ dut.clk.value = 1
12
+ await Timer(10, "ns")
13
+ assert dut.clk.value.integer == 1, "Clock not set to 1 as expected"
14
+
15
+
16
+ @cocotb.test()
17
+ async def issue_253_empty(dut):
18
+ await toggle_clock(dut)
19
+
20
+
21
+ @cocotb.test()
22
+ async def issue_253_none(dut):
23
+ await toggle_clock(dut)
24
+
25
+
26
+ @cocotb.test()
27
+ async def issue_253_notset(dut):
28
+ await toggle_clock(dut)
testbed/cocotb__cocotb/tests/test_cases/issue_330/Makefile ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ###############################################################################
2
+ # Copyright (c) 2013 Potential Ventures Ltd
3
+ # Copyright (c) 2013 SolarFlare Communications Inc
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ # * Redistributions of source code must retain the above copyright
9
+ # notice, this list of conditions and the following disclaimer.
10
+ # * Redistributions in binary form must reproduce the above copyright
11
+ # notice, this list of conditions and the following disclaimer in the
12
+ # documentation and/or other materials provided with the distribution.
13
+ # * Neither the name of Potential Ventures Ltd,
14
+ # SolarFlare Communications Inc nor the
15
+ # names of its contributors may be used to endorse or promote products
16
+ # derived from this software without specific prior written permission.
17
+ #
18
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ # DISCLAIMED. IN NO EVENT SHALL POTENTIAL VENTURES LTD BE LIABLE FOR ANY
22
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ ###############################################################################
29
+
30
+
31
+ include ../../designs/sample_module/Makefile
32
+
33
+ MODULE = issue_330
testbed/cocotb__cocotb/tests/test_cases/issue_330/issue_330.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # A set of regression tests for open issues
2
+
3
+ import logging
4
+
5
+ import cocotb
6
+ from cocotb._sim_versions import RivieraVersion
7
+
8
+ SIM_NAME = cocotb.SIM_NAME.lower()
9
+
10
+
11
+ # GHDL unable to access record signals (gh-2591)
12
+ # Icarus doesn't support structs (gh-2592)
13
+ # Verilator doesn't support structs (gh-1275)
14
+ # Riviera-PRO 2022.10 and newer does not discover inout_if correctly over VPI (gh-3587)
15
+ @cocotb.test(
16
+ expect_error=AttributeError
17
+ if SIM_NAME.startswith(("icarus", "ghdl", "verilator"))
18
+ or (
19
+ SIM_NAME.startswith("riviera")
20
+ and RivieraVersion(cocotb.SIM_VERSION) >= RivieraVersion("2022.10")
21
+ and cocotb.LANGUAGE == "verilog"
22
+ )
23
+ else ()
24
+ )
25
+ async def issue_330_direct(dut):
26
+ """
27
+ Access a structure
28
+ """
29
+
30
+ tlog = logging.getLogger("cocotb.test")
31
+
32
+ structure = dut.inout_if
33
+
34
+ tlog.info(
35
+ f"Value of inout_if => a_in = {structure.a_in.value} ; b_out = {structure.b_out.value}"
36
+ )
37
+
38
+
39
+ # GHDL unable to access record signals (gh-2591)
40
+ # Icarus doesn't support structs (gh-2592)
41
+ # Verilator doesn't support structs (gh-1275)
42
+ @cocotb.test(
43
+ expect_error=AttributeError
44
+ if SIM_NAME.startswith(("icarus", "ghdl"))
45
+ else AssertionError
46
+ if SIM_NAME.startswith("verilator")
47
+ else ()
48
+ )
49
+ async def issue_330_iteration(dut):
50
+ """
51
+ Access a structure via issue_330_iteration
52
+ """
53
+
54
+ tlog = logging.getLogger("cocotb.test")
55
+
56
+ structure = dut.inout_if
57
+
58
+ count = 0
59
+ for member in structure:
60
+ tlog.info("Found %s" % member._path)
61
+ count += 1
62
+
63
+ # Riviera-PRO 2022.10 and newer does not discover inout_if correctly over VPI (gh-3587)
64
+ rv_2022_10_plus = RivieraVersion(cocotb.SIM_VERSION) >= RivieraVersion("2022.10")
65
+ if (
66
+ SIM_NAME.startswith("riviera")
67
+ and rv_2022_10_plus
68
+ and cocotb.LANGUAGE == "verilog"
69
+ ):
70
+ assert count == 0
71
+ else:
72
+ assert count == 2, "There should have been two members of the structure"
testbed/cocotb__cocotb/tests/test_cases/issue_588/Makefile ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ###############################################################################
2
+ # Copyright (c) 2018 Potential Ventures Ltd
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
+ # names of its contributors may be used to endorse or promote products
14
+ # derived from this software without specific prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ # DISCLAIMED. IN NO EVENT SHALL POTENTIAL VENTURES LTD BE LIABLE FOR ANY
20
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ ###############################################################################
27
+
28
+
29
+ include ../../designs/sample_module/Makefile
30
+
31
+ MODULE = issue_588
testbed/cocotb__cocotb/tests/test_cases/issue_588/issue_588.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Test case for issue 588- yielding both coroutines and triggers in a list.
2
+ # This is a very simple test; it just makes sure we can yield a list of both.
3
+
4
+ import cocotb
5
+ from cocotb import triggers, utils
6
+
7
+
8
+ async def sample_coroutine(dut):
9
+ """Very simple coroutine that waits 5 ns."""
10
+ await triggers.Timer(5, "ns")
11
+ dut._log.info("Sample coroutine yielded.")
12
+
13
+
14
+ @cocotb.test()
15
+ async def issue_588_coroutine_list(dut):
16
+ """Yield a list of triggers and coroutines."""
17
+
18
+ # Record simulation time.
19
+ current_time = utils.get_sim_time("ns")
20
+
21
+ # Yield a list, containing a RisingEdge trigger and a coroutine.
22
+ coro = cocotb.start_soon(sample_coroutine(dut))
23
+ await triggers.First(coro, triggers.Timer(100, "ns"))
24
+ coro.kill()
25
+
26
+ # Make sure that only 5 ns passed, because the sample coroutine
27
+ # terminated first.
28
+ new_time = utils.get_sim_time("ns")
29
+ assert int(new_time - current_time) == 5, "Did not yield coroutine in list."
testbed/cocotb__cocotb/tests/test_cases/issue_768_a/Makefile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ include ../../designs/sample_module/Makefile
2
+
3
+ MODULE = issue_768
testbed/cocotb__cocotb/tests/test_cases/issue_768_b/Makefile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ include ../../designs/sample_module/Makefile
2
+
3
+ MODULE = issue_768
testbed/cocotb__cocotb/tests/test_cases/issue_768_b/issue_768.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Failing case.
3
+
4
+ Note that the bug only occurred if the test in question runs first - so
5
+ no more tests can be added to this file.
6
+ """
7
+
8
+ import cocotb
9
+ from cocotb.triggers import ReadOnly, Timer
10
+ from cocotb.types import LogicArray, Range
11
+
12
+ # this line is different between the two files
13
+ value = LogicArray(0, Range(7, "downto", 0))
14
+
15
+
16
+ @cocotb.test()
17
+ async def do_test(dut):
18
+ dut.stream_in_data.setimmediatevalue(value)
19
+ await Timer(1, "step")
20
+ assert dut.stream_in_data.value == 0
21
+ await ReadOnly()
testbed/cocotb__cocotb/tests/test_cases/issue_857/Makefile ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ###############################################################################
2
+ # Copyright (c) 2015 Potential Ventures Ltd
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
+ # names of its contributors may be used to endorse or promote products
14
+ # derived from this software without specific prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ # DISCLAIMED. IN NO EVENT SHALL POTENTIAL VENTURES LTD BE LIABLE FOR ANY
20
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ ###############################################################################
27
+
28
+
29
+ include ../../designs/sample_module/Makefile
30
+
31
+ MODULE = issue_857
testbed/cocotb__cocotb/tests/test_cases/issue_892/Makefile ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ###############################################################################
2
+ # Copyright (c) 2013 Potential Ventures Ltd
3
+ # Copyright (c) 2013 SolarFlare Communications Inc
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ # * Redistributions of source code must retain the above copyright
9
+ # notice, this list of conditions and the following disclaimer.
10
+ # * Redistributions in binary form must reproduce the above copyright
11
+ # notice, this list of conditions and the following disclaimer in the
12
+ # documentation and/or other materials provided with the distribution.
13
+ # * Neither the name of Potential Ventures Ltd,
14
+ # SolarFlare Communications Inc nor the
15
+ # names of its contributors may be used to endorse or promote products
16
+ # derived from this software without specific prior written permission.
17
+ #
18
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ # DISCLAIMED. IN NO EVENT SHALL POTENTIAL VENTURES LTD BE LIABLE FOR ANY
22
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ ###############################################################################
29
+
30
+
31
+ include ../../designs/sample_module/Makefile
32
+
33
+ MODULE = issue_892
testbed/cocotb__cocotb/tests/test_cases/test_external/Makefile ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ###############################################################################
2
+ # Copyright (c) 2013 Potential Ventures Ltd
3
+ # Copyright (c) 2013 SolarFlare Communications Inc
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ # * Redistributions of source code must retain the above copyright
9
+ # notice, this list of conditions and the following disclaimer.
10
+ # * Redistributions in binary form must reproduce the above copyright
11
+ # notice, this list of conditions and the following disclaimer in the
12
+ # documentation and/or other materials provided with the distribution.
13
+ # * Neither the name of Potential Ventures Ltd,
14
+ # SolarFlare Communications Inc nor the
15
+ # names of its contributors may be used to endorse or promote products
16
+ # derived from this software without specific prior written permission.
17
+ #
18
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ # DISCLAIMED. IN NO EVENT SHALL POTENTIAL VENTURES LTD BE LIABLE FOR ANY
22
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ ###############################################################################
29
+
30
+
31
+ include ../../designs/sample_module/Makefile
32
+
33
+ MODULE = test_external
testbed/cocotb__cocotb/tests/test_cases/test_iteration_vhdl/test_iteration.py ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) 2015, 2018 Potential Ventures Ltd
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 Potential Ventures Ltd
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
+ import logging
27
+ import os
28
+
29
+ import cocotb
30
+ from cocotb._sim_versions import QuestaVersion
31
+ from cocotb.triggers import Combine, Timer
32
+
33
+
34
+ def total_object_count():
35
+ """Return the total object count based on simulator."""
36
+ SIM_NAME = cocotb.SIM_NAME.lower()
37
+ SIM_VERSION = cocotb.SIM_VERSION.lower()
38
+
39
+ # Questa with VHPI
40
+ # TODO: Why do we get massively different numbers for Questa/VHPI than for Questa/FLI or VPI?
41
+ if SIM_NAME.startswith("modelsim") and os.environ["VHDL_GPI_INTERFACE"] == "vhpi":
42
+ return 68127
43
+
44
+ # Questa 2023.1 onwards (FLI) do not discover the following objects, which
45
+ # are instantiated four times:
46
+ # - inst_generic_sp_ram.clk (<class 'cocotb.handle.ModifiableObject'>)
47
+ # - inst_generic_sp_ram.rst (<class 'cocotb.handle.ModifiableObject'>)
48
+ # - inst_generic_sp_ram.wen (<class 'cocotb.handle.ModifiableObject'>)
49
+ # - inst_generic_sp_ram.en (<class 'cocotb.handle.ModifiableObject'>)
50
+ if (
51
+ SIM_NAME.startswith("modelsim")
52
+ and QuestaVersion(SIM_VERSION) >= QuestaVersion("2023.1")
53
+ and os.environ["VHDL_GPI_INTERFACE"] == "fli"
54
+ ):
55
+ return 35153 - 4 * 4
56
+
57
+ if SIM_NAME.startswith(
58
+ (
59
+ "ncsim",
60
+ "xmsim",
61
+ "modelsim",
62
+ "riviera",
63
+ )
64
+ ):
65
+ return 35153
66
+
67
+ # Active-HDL
68
+ if SIM_NAME.startswith("aldec"):
69
+ if SIM_VERSION.startswith("11.1"):
70
+ # Active-HDL 11.1 only finds 'inbranch_tdata_low' inside the gen_acs for generate block
71
+ return 27359
72
+ if SIM_VERSION.startswith("10.01"):
73
+ # Active-HDL 10.1 doesn't find any signals declared inside the gen_acs for generate block
74
+ return 26911
75
+
76
+ return 0
77
+
78
+
79
+ @cocotb.test(skip=(total_object_count() == 0))
80
+ async def recursive_discovery(dut):
81
+ """Recursively discover every single object in the design."""
82
+
83
+ pass_total = total_object_count()
84
+
85
+ tlog = logging.getLogger("cocotb.test")
86
+ await Timer(100)
87
+
88
+ def dump_all_the_things(parent):
89
+ if not isinstance(
90
+ parent,
91
+ (
92
+ cocotb.handle.HierarchyObjectBase,
93
+ cocotb.handle.NonHierarchyIndexableObjectBase,
94
+ ),
95
+ ):
96
+ return 0
97
+ count = 0
98
+ for thing in parent:
99
+ count += 1
100
+ tlog.info("Found %s (%s)", thing._path, type(thing))
101
+ count += dump_all_the_things(thing)
102
+ return count
103
+
104
+ total = dump_all_the_things(dut)
105
+ tlog.info("Found a total of %d things", total)
106
+ assert total == pass_total
107
+
108
+
109
+ # GHDL unable to access signals in generate loops (gh-2594)
110
+ @cocotb.test(
111
+ expect_error=IndexError if cocotb.SIM_NAME.lower().startswith("ghdl") else ()
112
+ )
113
+ async def discovery_all(dut):
114
+ """Discover everything on top-level."""
115
+ dut._log.info("Iterating over top-level to discover objects")
116
+ for thing in dut:
117
+ thing._log.info("Found something: %s", thing._path)
118
+
119
+ dut._log.info("length of dut.inst_acs is %d", len(dut.gen_acs))
120
+ item = dut.gen_acs[3]
121
+ item._log.info("this is item")
122
+
123
+
124
+ @cocotb.test()
125
+ async def dual_iteration(dut):
126
+ """Test iteration over top-level in two forked coroutines."""
127
+
128
+ async def iteration_loop():
129
+ for thing in dut:
130
+ thing._log.info("Found something: %s", thing._path)
131
+ await Timer(1)
132
+
133
+ loop_one = cocotb.start_soon(iteration_loop())
134
+ loop_two = cocotb.start_soon(iteration_loop())
135
+
136
+ await Combine(loop_one, loop_two)
137
+
138
+
139
+ # GHDL unable to access record types (gh-2591)
140
+ @cocotb.test(
141
+ expect_fail=cocotb.SIM_NAME.lower().startswith("aldec"),
142
+ expect_error=AttributeError if cocotb.SIM_NAME.lower().startswith("ghdl") else (),
143
+ )
144
+ async def test_n_dimension_array(dut):
145
+ """Test iteration over multi-dimensional array."""
146
+ tlog = logging.getLogger("cocotb.test")
147
+ inner_count = 0
148
+ outer_count = 0
149
+ config = dut.inst_ram_ctrl.config
150
+ # This signal is a 2 x 7 vhpiEnumVecVal
151
+ for thing in config:
152
+ for sub_thing in thing:
153
+ tlog.info("Found %s", sub_thing._name)
154
+ inner_count += 1
155
+ outer_count += 1
156
+
157
+ assert outer_count == 2, outer_count
158
+ assert inner_count == 14, inner_count
testbed/cocotb__cocotb/tests/test_cases/test_long_log_msg/.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ errlog
testbed/cocotb__cocotb/tests/test_cases/test_long_log_msg/Makefile ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright cocotb contributors
2
+ # Licensed under the Revised BSD License, see LICENSE for details.
3
+ # SPDX-License-Identifier: BSD-3-Clause
4
+
5
+ ifeq ($(SIM),ghdl)
6
+
7
+ all:
8
+ @echo Skipping test because GHDL does not support identifiers longer than 1023 characters.
9
+ @echo See also https://github.com/ghdl/ghdl/issues/1930
10
+
11
+ else
12
+
13
+ PROJ_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
14
+
15
+ TOPLEVEL_LANG ?= verilog
16
+
17
+ ifeq ($(TOPLEVEL_LANG),verilog)
18
+ VERILOG_SOURCES := $(PROJ_DIR)/test.sv
19
+ else ifeq ($(TOPLEVEL_LANG),vhdl)
20
+ VHDL_SOURCES := $(PROJ_DIR)/test.vhd
21
+ endif
22
+
23
+ ifneq ($(filter $(SIM),ius xcelium),)
24
+ COMPILE_ARGS += -v93
25
+ endif
26
+
27
+ TOPLEVEL := test
28
+
29
+ export MODULE := test_long_log_msg
30
+ export COCOTB_LOG_LEVEL := DEBUG
31
+
32
+ .PHONY: override_for_this_test
33
+ override_for_this_test:
34
+ $(MAKE) all 2>errlog
35
+ ! grep &>/dev/null "Log message construction failed" errlog
36
+
37
+ include $(shell cocotb-config --makefiles)/Makefile.sim
38
+
39
+ endif
testbed/cocotb__cocotb/tests/test_cases/test_long_log_msg/test.vhd ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -- Copyright cocotb contributors
2
+ -- Licensed under the Revised BSD License, see LICENSE for details.
3
+ -- SPDX-License-Identifier: BSD-3-Clause
4
+
5
+ entity test is
6
+ port (
7
+ KPFIVTM1LHY0OFUNXF0XZO1RV535NNU4A8QWR12BLQXJ98PMM1P552QC0T089PUJPB4POUJZLBS19S8XNMPGJV2QK3AJUW98X7RU56ZV4IMFIPDJI81E5B9HNW94Q9APLMMK3VPHS1VB1QVPQDG7VOTLY2NT3F4080OUXSC68H0JZF7KQ0O6GGN3DARXC03CSZL7TE6B7R47366SB54T5Q4MOR5BT3L5S0S3NM8MALXPHZKCUA6AR5U391GGDYG5LB7JGKAHSIREODSNGW7FAYNRTTXFFCRL4U3ZQA6DH1RKCFKGDG9WMF81IX5YSAINQSP14F2FJV0GYEM3R4LUFFSWOZKK5MGKS25RLROJFEQDC8L2XY07728MM7V516ZXH1YFS0AL1GPLH03N5EL0RQVY61EVEQEJCYDT0ZBBN1ZLC5BDQU83NF8N953MU6A99SDNPCTSOD2W9WY69ZL64JHURFHA5DT7KQC7T4KASR5CAG85ONU3F2XWYA97JHDN9V9SBS39MYMYERJ338O6JQYCHX7SH8FB2VL2PI7DOQWB3NXTA8CQM7YKT34L6U3O42WWMI7NHKUIBO4U9MBP176000FU39WET32RG4PHLYYGWFMKPYPCUFE46RFSQDELLXU31ZZH0OJCGEFUDR2USDUYZ3XPBQ6RC0XARPG2Z1GHCESILHJOF7503PHKWUKDVM2V18WB16CB7AAQ8C4C6E7FXUB3E89Q0ZJSKQFYNZPSKYKGXURV3V5C0SHU9QQ2GFUTP38ORCSWN0QYIX9H0SKJEXPC5U1D3QN9PRT0QPOVM7H5EGQ4E449YTSHUMJW1TT2S6EVIPPIR9ZMFCOWPYXRSNJEQ3OCKGDUW2ZX2AS7N5GBUY7NOAR2P7BK5YPOA6APVAH12V86V2YQZ2M56HLNAD785GI4GMFSCI5P3LNFM0CLSBUEJXCVT695N5D3GC8T0HKAN0BZDV1ZMI0WZ3QUVABNYFOJHXXBUW5OK5MQ46NMK3W0FMCKWVPP6265 : in integer;
8
+ o : out integer);
9
+ end entity test;
10
+
11
+ architecture rtl of test is
12
+ begin
13
+ o <= KPFIVTM1LHY0OFUNXF0XZO1RV535NNU4A8QWR12BLQXJ98PMM1P552QC0T089PUJPB4POUJZLBS19S8XNMPGJV2QK3AJUW98X7RU56ZV4IMFIPDJI81E5B9HNW94Q9APLMMK3VPHS1VB1QVPQDG7VOTLY2NT3F4080OUXSC68H0JZF7KQ0O6GGN3DARXC03CSZL7TE6B7R47366SB54T5Q4MOR5BT3L5S0S3NM8MALXPHZKCUA6AR5U391GGDYG5LB7JGKAHSIREODSNGW7FAYNRTTXFFCRL4U3ZQA6DH1RKCFKGDG9WMF81IX5YSAINQSP14F2FJV0GYEM3R4LUFFSWOZKK5MGKS25RLROJFEQDC8L2XY07728MM7V516ZXH1YFS0AL1GPLH03N5EL0RQVY61EVEQEJCYDT0ZBBN1ZLC5BDQU83NF8N953MU6A99SDNPCTSOD2W9WY69ZL64JHURFHA5DT7KQC7T4KASR5CAG85ONU3F2XWYA97JHDN9V9SBS39MYMYERJ338O6JQYCHX7SH8FB2VL2PI7DOQWB3NXTA8CQM7YKT34L6U3O42WWMI7NHKUIBO4U9MBP176000FU39WET32RG4PHLYYGWFMKPYPCUFE46RFSQDELLXU31ZZH0OJCGEFUDR2USDUYZ3XPBQ6RC0XARPG2Z1GHCESILHJOF7503PHKWUKDVM2V18WB16CB7AAQ8C4C6E7FXUB3E89Q0ZJSKQFYNZPSKYKGXURV3V5C0SHU9QQ2GFUTP38ORCSWN0QYIX9H0SKJEXPC5U1D3QN9PRT0QPOVM7H5EGQ4E449YTSHUMJW1TT2S6EVIPPIR9ZMFCOWPYXRSNJEQ3OCKGDUW2ZX2AS7N5GBUY7NOAR2P7BK5YPOA6APVAH12V86V2YQZ2M56HLNAD785GI4GMFSCI5P3LNFM0CLSBUEJXCVT695N5D3GC8T0HKAN0BZDV1ZMI0WZ3QUVABNYFOJHXXBUW5OK5MQ46NMK3W0FMCKWVPP6265;
14
+ end architecture rtl;
testbed/cocotb__cocotb/tests/test_cases/test_long_log_msg/test_long_log_msg.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
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 cocotb
6
+
7
+
8
+ @cocotb.test()
9
+ async def test_access_long_name(dut):
10
+ dut.KPFIVTM1LHY0OFUNXF0XZO1RV535NNU4A8QWR12BLQXJ98PMM1P552QC0T089PUJPB4POUJZLBS19S8XNMPGJV2QK3AJUW98X7RU56ZV4IMFIPDJI81E5B9HNW94Q9APLMMK3VPHS1VB1QVPQDG7VOTLY2NT3F4080OUXSC68H0JZF7KQ0O6GGN3DARXC03CSZL7TE6B7R47366SB54T5Q4MOR5BT3L5S0S3NM8MALXPHZKCUA6AR5U391GGDYG5LB7JGKAHSIREODSNGW7FAYNRTTXFFCRL4U3ZQA6DH1RKCFKGDG9WMF81IX5YSAINQSP14F2FJV0GYEM3R4LUFFSWOZKK5MGKS25RLROJFEQDC8L2XY07728MM7V516ZXH1YFS0AL1GPLH03N5EL0RQVY61EVEQEJCYDT0ZBBN1ZLC5BDQU83NF8N953MU6A99SDNPCTSOD2W9WY69ZL64JHURFHA5DT7KQC7T4KASR5CAG85ONU3F2XWYA97JHDN9V9SBS39MYMYERJ338O6JQYCHX7SH8FB2VL2PI7DOQWB3NXTA8CQM7YKT34L6U3O42WWMI7NHKUIBO4U9MBP176000FU39WET32RG4PHLYYGWFMKPYPCUFE46RFSQDELLXU31ZZH0OJCGEFUDR2USDUYZ3XPBQ6RC0XARPG2Z1GHCESILHJOF7503PHKWUKDVM2V18WB16CB7AAQ8C4C6E7FXUB3E89Q0ZJSKQFYNZPSKYKGXURV3V5C0SHU9QQ2GFUTP38ORCSWN0QYIX9H0SKJEXPC5U1D3QN9PRT0QPOVM7H5EGQ4E449YTSHUMJW1TT2S6EVIPPIR9ZMFCOWPYXRSNJEQ3OCKGDUW2ZX2AS7N5GBUY7NOAR2P7BK5YPOA6APVAH12V86V2YQZ2M56HLNAD785GI4GMFSCI5P3LNFM0CLSBUEJXCVT695N5D3GC8T0HKAN0BZDV1ZMI0WZ3QUVABNYFOJHXXBUW5OK5MQ46NMK3W0FMCKWVPP6265
testbed/cocotb__cocotb/tests/test_cases/test_module_var_empty/Makefile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright cocotb contributors
2
+ # Licensed under the Revised BSD License, see LICENSE for details.
3
+ # SPDX-License-Identifier: BSD-3-Clause
4
+
5
+ # test MODULE is empty
6
+ # should cause regression initialization failure so no results.xml is written
7
+
8
+ MODULE := " "
9
+
10
+ .PHONY: override_for_this_test
11
+ override_for_this_test:
12
+ -$(MAKE) all
13
+ @test ! -f $(COCOTB_RESULTS_FILE)
14
+
15
+ include ../../designs/sample_module/Makefile
testbed/cocotb__cocotb/tests/test_cases/test_module_var_messy/Makefile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright cocotb contributors
2
+ # Licensed under the Revised BSD License, see LICENSE for details.
3
+ # SPDX-License-Identifier: BSD-3-Clause
4
+
5
+ # test MODULE contains leading and trailing separators
6
+ # should cause regression initialization failure so no results.xml is written
7
+
8
+ MODULE=" , test_nothing ,"
9
+
10
+ .PHONY: override_for_this_test
11
+ override_for_this_test:
12
+ -$(MAKE) all
13
+ @test ! -f $(COCOTB_RESULTS_FILE)
14
+
15
+ include ../../designs/sample_module/Makefile
testbed/cocotb__cocotb/tests/test_cases/test_module_var_messy/test_nothing.py ADDED
@@ -0,0 +1 @@
 
 
1
+ """ This test module is purposefully empty """
testbed/cocotb__cocotb/tests/test_cases/test_module_without_tests/Makefile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright cocotb contributors
2
+ # Licensed under the Revised BSD License, see LICENSE for details.
3
+ # SPDX-License-Identifier: BSD-3-Clause
4
+
5
+ # test MODULE is set
6
+ # should cause regression initialization failure so no results.xml is written
7
+
8
+ MODULE=test_nothing
9
+
10
+ .PHONY: override_for_this_test
11
+ override_for_this_test:
12
+ -$(MAKE) all
13
+ @test ! -f $(COCOTB_RESULTS_FILE)
14
+
15
+ include ../../designs/sample_module/Makefile
testbed/cocotb__cocotb/tests/test_cases/test_multi_dimension_array/test_cocotb_array.py ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cocotb
2
+ from cocotb.triggers import Timer
3
+
4
+ SIM_NAME = cocotb.SIM_NAME.lower()
5
+
6
+
7
+ @cocotb.test()
8
+ async def test_in_vect_packed(dut):
9
+ test_value = 0x5
10
+ dut.in_vect_packed.value = test_value
11
+ await Timer(1, "ns")
12
+ assert dut.out_vect_packed.value == test_value
13
+
14
+
15
+ # Verilator combines 1-dimensional unpacked arrays into a single vector (gh-3611)
16
+ @cocotb.test(expect_error=TypeError if SIM_NAME.startswith("verilator") else ())
17
+ async def test_in_vect_unpacked(dut):
18
+ test_value = [0x1, 0x0, 0x1]
19
+ dut.in_vect_unpacked.value = test_value
20
+ await Timer(1, "ns")
21
+ assert dut.out_vect_unpacked.value == test_value
22
+
23
+
24
+ @cocotb.test()
25
+ async def test_in_arr(dut):
26
+ test_value = 0x5
27
+ dut.in_arr.value = test_value
28
+ await Timer(1, "ns")
29
+ assert dut.out_arr.value == test_value
30
+
31
+
32
+ @cocotb.test()
33
+ async def test_in_2d_vect_packed_packed(dut):
34
+ test_value = (0x5 << 6) | (0x5 << 3) | 0x5
35
+ dut.in_2d_vect_packed_packed.value = test_value
36
+ await Timer(1, "ns")
37
+ assert dut.out_2d_vect_packed_packed.value == test_value
38
+
39
+
40
+ @cocotb.test()
41
+ async def test_in_2d_vect_packed_unpacked(dut):
42
+ test_value = [0x5, 0x5, 0x5]
43
+ dut.in_2d_vect_packed_unpacked.value = test_value
44
+ await Timer(1, "ns")
45
+ assert dut.out_2d_vect_packed_unpacked.value == test_value
46
+
47
+
48
+ # Verilator doesn't support multi-dimensional unpacked arrays (gh-3611)
49
+ @cocotb.test(expect_error=AttributeError if SIM_NAME.startswith("verilator") else ())
50
+ async def test_in_2d_vect_unpacked_unpacked(dut):
51
+ test_value = 3 * [[0x1, 0x0, 0x1]]
52
+ dut.in_2d_vect_unpacked_unpacked.value = test_value
53
+ await Timer(1, "ns")
54
+ assert dut.out_2d_vect_unpacked_unpacked.value == test_value
55
+
56
+
57
+ @cocotb.test()
58
+ async def test_in_arr_packed(dut):
59
+ test_value = 365
60
+ dut.in_arr_packed.value = test_value
61
+ await Timer(1, "ns")
62
+ assert dut.out_arr_packed.value == test_value
63
+
64
+
65
+ @cocotb.test()
66
+ async def test_in_arr_unpacked(dut):
67
+ test_value = [0x5, 0x5, 0x5]
68
+ dut.in_arr_unpacked.value = test_value
69
+ await Timer(1, "ns")
70
+ assert dut.out_arr_unpacked.value == test_value
71
+
72
+
73
+ @cocotb.test()
74
+ async def test_in_2d_arr(dut):
75
+ test_value = 365
76
+ dut.in_2d_arr.value = test_value
77
+ await Timer(1, "ns")
78
+ assert dut.out_2d_arr.value == test_value
79
+
80
+
81
+ @cocotb.test()
82
+ async def test_in_vect_packed_packed_packed(dut):
83
+ test_value = 95869805
84
+ dut.in_vect_packed_packed_packed.value = test_value
85
+ await Timer(1, "ns")
86
+ assert dut.out_vect_packed_packed_packed.value == test_value
87
+
88
+
89
+ # Questa is unable to access elements of a logic array if the last dimension is unpacked (gh-2605)
90
+ # Verilator doesn't support multi-dimensional unpacked arrays (gh-3611)
91
+ @cocotb.test(
92
+ expect_error=IndexError
93
+ if cocotb.LANGUAGE == "verilog" and SIM_NAME.startswith("modelsim")
94
+ else AttributeError
95
+ if SIM_NAME.startswith("verilator")
96
+ else ()
97
+ )
98
+ async def test_in_vect_packed_packed_unpacked(dut):
99
+ test_value = [365, 365, 365]
100
+ dut.in_vect_packed_packed_unpacked.value = test_value
101
+ await Timer(1, "ns")
102
+ assert dut.out_vect_packed_packed_unpacked.value == test_value
103
+
104
+
105
+ # Verilator doesn't support multi-dimensional unpacked arrays (gh-3611)
106
+ @cocotb.test(expect_error=AttributeError if SIM_NAME.startswith("verilator") else ())
107
+ async def test_in_vect_packed_unpacked_unpacked(dut):
108
+ test_value = 3 * [3 * [5]]
109
+ dut.in_vect_packed_unpacked_unpacked.value = test_value
110
+ await Timer(1, "ns")
111
+ assert dut.out_vect_packed_unpacked_unpacked.value == test_value
112
+
113
+
114
+ # Verilator doesn't support multi-dimensional unpacked arrays (gh-3611)
115
+ @cocotb.test(expect_error=AttributeError if SIM_NAME.startswith("verilator") else ())
116
+ async def test_in_vect_unpacked_unpacked_unpacked(dut):
117
+ test_value = 3 * [3 * [[1, 0, 1]]]
118
+ dut.in_vect_unpacked_unpacked_unpacked.value = test_value
119
+ await Timer(1, "ns")
120
+ assert dut.out_vect_unpacked_unpacked_unpacked.value == test_value
121
+
122
+
123
+ @cocotb.test()
124
+ async def test_in_arr_packed_packed(dut):
125
+ test_value = (365 << 18) | (365 << 9) | (365)
126
+ dut.in_arr_packed_packed.value = test_value
127
+ await Timer(1, "ns")
128
+ assert dut.out_arr_packed_packed.value == test_value
129
+
130
+
131
+ # Questa is unable to access elements of a logic array if the last dimension is unpacked (gh-2605)
132
+ # Verilator doesn't support multi-dimensional unpacked arrays (gh-3611)
133
+ @cocotb.test(
134
+ expect_error=IndexError
135
+ if cocotb.LANGUAGE == "verilog" and SIM_NAME.startswith("modelsim")
136
+ else AttributeError
137
+ if SIM_NAME.startswith("verilator")
138
+ else ()
139
+ )
140
+ async def test_in_arr_packed_unpacked(dut):
141
+ test_value = [365, 365, 365]
142
+ dut.in_arr_packed_unpacked.value = test_value
143
+ await Timer(1, "ns")
144
+ assert dut.out_arr_packed_unpacked.value == test_value
145
+
146
+
147
+ # Verilator doesn't support multi-dimensional unpacked arrays (gh-3611)
148
+ @cocotb.test(expect_error=AttributeError if SIM_NAME.startswith("verilator") else ())
149
+ async def test_in_arr_unpacked_unpacked(dut):
150
+ test_value = 3 * [3 * [5]]
151
+ dut.in_arr_unpacked_unpacked.value = test_value
152
+ await Timer(1, "ns")
153
+ assert dut.out_arr_unpacked_unpacked.value == test_value
154
+
155
+
156
+ @cocotb.test()
157
+ async def test_in_2d_arr_packed(dut):
158
+ test_value = (365 << 18) | (365 << 9) | (365)
159
+ dut.in_2d_arr_packed.value = test_value
160
+ await Timer(1, "ns")
161
+ assert dut.out_2d_arr_packed.value == test_value
162
+
163
+
164
+ # Questa is unable to access elements of a logic array if the last dimension is unpacked (gh-2605)
165
+ # Verilator doesn't support multi-dimensional unpacked arrays (gh-3611)
166
+ @cocotb.test(
167
+ expect_error=IndexError
168
+ if cocotb.LANGUAGE == "verilog" and SIM_NAME.startswith("modelsim")
169
+ else AttributeError
170
+ if SIM_NAME.startswith("verilator")
171
+ else ()
172
+ )
173
+ async def test_in_2d_arr_unpacked(dut):
174
+ test_value = [365, 365, 365]
175
+ dut.in_2d_arr_unpacked.value = test_value
176
+ await Timer(1, "ns")
177
+ assert dut.out_2d_arr_unpacked.value == test_value
178
+
179
+
180
+ @cocotb.test()
181
+ async def test_in_3d_arr(dut):
182
+ test_value = (365 << 18) | (365 << 9) | (365)
183
+ dut.in_3d_arr.value = test_value
184
+ await Timer(1, "ns")
185
+ assert dut.out_3d_arr.value == test_value
testbed/cocotb__cocotb/tests/test_cases/test_multi_level_module_path/Makefile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright cocotb contributors
2
+ # Licensed under the Revised BSD License, see LICENSE for details.
3
+ # SPDX-License-Identifier: BSD-3-Clause
4
+
5
+ # test MODULE contains a multi-level Python module path, separated by period
6
+
7
+ MODULE = test_package.test_module_path
8
+
9
+ export PYTHONPATH := .
10
+
11
+ include ../../designs/sample_module/Makefile
testbed/cocotb__cocotb/tests/test_cases/test_multi_level_module_path/__init__.py ADDED
File without changes
testbed/cocotb__cocotb/tests/test_cases/test_multi_level_module_path/test_package/__init__.py ADDED
File without changes
testbed/cocotb__cocotb/tests/test_cases/test_multi_level_module_path/test_package/test_module_path.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright cocotb contributors
2
+ # Licensed under the Revised BSD License, see LICENSE for details.
3
+ # SPDX-License-Identifier: BSD-3-Clause
4
+
5
+ """Test for multi-level module path in MODULE"""
6
+
7
+ import cocotb
8
+
9
+
10
+ @cocotb.test()
11
+ async def test_pass(_):
12
+ pass
testbed/cocotb__cocotb/tests/test_cases/test_package/Makefile ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright cocotb contributors
2
+ # Licensed under the Revised BSD License, see LICENSE for details.
3
+ # SPDX-License-Identifier: BSD-3-Clause
4
+
5
+ ifeq ($(SIM),)
6
+ USING_ICARUS := 1
7
+ endif
8
+
9
+ ifeq ($(shell echo $(SIM) | tr A-Z a-z),icarus)
10
+ USING_ICARUS := 1
11
+ endif
12
+
13
+ ifneq ($(USING_ICARUS),)
14
+ ICARUS_MIN := 12.0
15
+ ICARUS_VERSION := $(shell iverilog -V 2>/dev/null | head -n1 | cut -d ' ' -f 4)
16
+ MIN_VERSION := $(shell printf "%s\n%s\n" "$(ICARUS_MIN)" "$(ICARUS_VERSION)" | sort -g | head -1)
17
+ ifneq ($(MIN_VERSION),$(ICARUS_MIN))
18
+ SKIP := 1
19
+ $(info "Skipping test_defaultless_parameter since icarus < v12.0 doesn't support vpiInstance iteration")
20
+ endif
21
+ endif
22
+
23
+ TOPLEVEL_LANG ?= verilog
24
+ ifneq ($(TOPLEVEL_LANG),verilog)
25
+ SKIP := 1
26
+ $(info "Skipping . . . Verilog only")
27
+ endif
28
+
29
+ ifeq ($(SKIP),)
30
+
31
+ VERILOG_SOURCES = cocotb_package_pkg.sv \
32
+ cocotb_package.sv
33
+ TOPLEVEL := cocotb_package
34
+ MODULE = test_package
35
+
36
+ include $(shell cocotb-config --makefiles)/Makefile.sim
37
+
38
+ else
39
+
40
+ all:
41
+ @echo "Skipping test_package"
42
+
43
+ clean::
44
+ # nothing to clean, just define target in this branch
45
+
46
+ endif
testbed/cocotb__cocotb/tests/test_cases/test_package/cocotb_package.sv ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright cocotb contributors
2
+ // Licensed under the Revised BSD License, see LICENSE for details.
3
+ // SPDX-License-Identifier: BSD-3-Clause
4
+
5
+ module cocotb_package;
6
+ // Necessary for Xcelium and Riviera in order for compiled packages to be visible
7
+ import cocotb_package_pkg_1::*;
8
+ import cocotb_package_pkg_2::*;
9
+
10
+ parameter int seven_int = 7;
11
+ endmodule
testbed/cocotb__cocotb/tests/test_cases/test_package/test_package.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ A set of tests that demonstrate package access
7
+ """
8
+
9
+ import logging
10
+
11
+ import cocotb
12
+ from cocotb.result import TestSuccess
13
+
14
+
15
+ @cocotb.test()
16
+ async def test_params(dut):
17
+ """Test package parameter access"""
18
+ tlog = logging.getLogger("cocotb.test")
19
+
20
+ tlog.info("Checking Parameters:")
21
+ assert dut.seven_int.value == 7
22
+ pkg1 = cocotb.packages.cocotb_package_pkg_1
23
+ assert pkg1.five_int.value == 5
24
+ assert pkg1.eight_logic.value == 8
25
+ pkg2 = cocotb.packages.cocotb_package_pkg_2
26
+ assert pkg2.eleven_int.value == 11
27
+
28
+
29
+ @cocotb.test()
30
+ async def test_stringification(dut):
31
+ """Test package stringification"""
32
+ tlog = logging.getLogger("cocotb.test")
33
+
34
+ tlog.info("Checking Strings:")
35
+ pkg1 = cocotb.packages.cocotb_package_pkg_1
36
+ assert str(pkg1).startswith("HierarchyObject(cocotb_package_pkg_1")
37
+ assert str(pkg1.five_int) == "LogicObject(cocotb_package_pkg_1::five_int)"
38
+ assert str(pkg1.eight_logic) == "LogicObject(cocotb_package_pkg_1::eight_logic)"
39
+ pkg2 = cocotb.packages.cocotb_package_pkg_2
40
+ assert str(pkg2).startswith("HierarchyObject(cocotb_package_pkg_2")
41
+ assert str(pkg2.eleven_int) == "LogicObject(cocotb_package_pkg_2::eleven_int)"
42
+
43
+
44
+ @cocotb.test()
45
+ async def test_dollar_unit(dut):
46
+ """Test $unit scope"""
47
+ tlog = logging.getLogger("cocotb.test")
48
+
49
+ if cocotb.SIM_NAME.lower().startswith("riviera"):
50
+ tlog.info("Riviera does not support $unit access via vpiInstance")
51
+ raise TestSuccess
52
+
53
+ tlog.info("Checking $unit:")
54
+ # Is $unit even a package? Xcelium says yes and 37.10 detail 5 would also suggest yes
55
+ pkgs = vars(cocotb.packages).keys()
56
+ f = filter(lambda x: "unit" in x, pkgs)
57
+ unit = list(f)[0]
58
+ tlog.info(f"Found $unit as {unit}")
59
+ unit_pkg = getattr(cocotb.packages, unit)
60
+ assert unit_pkg.unit_four_int.value == 4
testbed/cocotb__cocotb/tests/test_cases/test_packed_union/Makefile ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright cocotb contributors
2
+ # Licensed under the Revised BSD License, see LICENSE for details.
3
+ # SPDX-License-Identifier: BSD-3-Clause
4
+
5
+ TOPLEVEL_LANG ?= verilog
6
+
7
+ ifneq ($(TOPLEVEL_LANG),verilog)
8
+
9
+ all:
10
+ @echo "Skipping test due to TOPLEVEL_LANG=$(TOPLEVEL_LANG) not being verilog"
11
+ clean::
12
+
13
+ else
14
+
15
+ VERILOG_SOURCES = test_packed_union.sv
16
+ TOPLEVEL = test_packed_union
17
+ MODULE = test_packed_union
18
+
19
+ include $(shell cocotb-config --makefiles)/Makefile.sim
20
+
21
+ endif
testbed/cocotb__cocotb/tests/test_cases/test_packed_union/test_packed_union.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 cocotb
6
+ from cocotb._sim_versions import RivieraVersion
7
+
8
+
9
+ # Riviera-PRO 2022.10 (VPI) and newer does not discover dut.t correctly (gh-3587)
10
+ @cocotb.test(
11
+ expect_error=Exception
12
+ if cocotb.SIM_NAME.lower().startswith(("verilator", "icarus", "ghdl"))
13
+ or (
14
+ cocotb.SIM_NAME.lower().startswith("riviera")
15
+ and RivieraVersion(cocotb.SIM_VERSION) >= RivieraVersion("2022.10")
16
+ and cocotb.LANGUAGE == "verilog"
17
+ )
18
+ else ()
19
+ )
20
+ async def test_packed_union(dut):
21
+ dut.t.a.value = 0
testbed/cocotb__cocotb/tests/test_cases/test_packed_union/test_packed_union.sv ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Copyright cocotb contributors
3
+ * Licensed under the Revised BSD License, see LICENSE for details.
4
+ * SPDX-License-Identifier: BSD-3-Clause
5
+ */
6
+
7
+ module test_packed_union
8
+ (input union packed {
9
+ logic [3:0] a;
10
+ logic [1:0][1:0] b;
11
+ } t);
12
+ endmodule : test_packed_union
testbed/cocotb__cocotb/tests/test_cases/test_plusargs/plusargs.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ plusarg testing
30
+ """
31
+
32
+ import cocotb
33
+
34
+
35
+ @cocotb.test()
36
+ async def plusargs_test(dut):
37
+ """Demonstrate plusarg access from Python test"""
38
+
39
+ for name in cocotb.plusargs:
40
+ print("COCOTB:", name, cocotb.plusargs[name])
41
+
42
+ assert "test1" in cocotb.plusargs
43
+ assert cocotb.plusargs["foo"] == "bar"
44
+ assert cocotb.plusargs["lol"] == "wow=4"
testbed/cocotb__cocotb/tests/test_cases/test_seed/Makefile ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright cocotb contributors
2
+ # Licensed under the Revised BSD License, see LICENSE for details.
3
+ # SPDX-License-Identifier: BSD-3-Clause
4
+
5
+ run:
6
+ $(RM) number
7
+ $(MAKE) sim MODULE=test_other,test_seed RANDOM_SEED=1234
8
+ $(MAKE) sim MODULE=test_seed TESTCASE=test_reproducibility RANDOM_SEED=1234
9
+
10
+ include ../../designs/sample_module/Makefile
testbed/cocotb__cocotb/tests/test_cases/test_seed/test_other.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright cocotb contributors
2
+ # Licensed under the Revised BSD License, see LICENSE for details.
3
+ # SPDX-License-Identifier: BSD-3-Clause
4
+ import cocotb
5
+
6
+
7
+ @cocotb.test()
8
+ async def test_pass(_):
9
+ # exists solely so there is another test in another module
10
+ # before the other module is run
11
+ pass
testbed/cocotb__cocotb/tests/test_cases/test_seed/test_seed.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright cocotb contributors
2
+ # Licensed under the Revised BSD License, see LICENSE for details.
3
+ # SPDX-License-Identifier: BSD-3-Clause
4
+ import random
5
+
6
+ import cocotb
7
+
8
+
9
+ @cocotb.test()
10
+ async def test_first(_):
11
+ # move generator to test that it doesn't affect the next test
12
+ for _ in range(100):
13
+ random.getrandbits(64)
14
+
15
+
16
+ @cocotb.test()
17
+ async def test_reproducibility(_):
18
+ try:
19
+ with open("number") as file:
20
+ a = int(file.read())
21
+ assert a == random.getrandbits(32)
22
+ except FileNotFoundError:
23
+ with open("number", "w") as file:
24
+ number = random.getrandbits(32)
25
+ file.write(str(number))
testbed/cocotb__cocotb/tests/test_cases/test_select_testcase/Makefile ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright cocotb contributors
2
+ # Licensed under the Revised BSD License, see LICENSE for details.
3
+ # SPDX-License-Identifier: BSD-3-Clause
4
+
5
+ # select only y_tests from all MODULEs
6
+
7
+ include ../../designs/sample_module/Makefile
8
+
9
+ MODULE := x_tests,y_tests,y_tests_again
10
+ TESTCASE := y_test
testbed/cocotb__cocotb/tests/test_cases/test_select_testcase/x_tests.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ import cocotb
2
+
3
+
4
+ @cocotb.test()
5
+ async def x_test(dut):
6
+ assert False
testbed/cocotb__cocotb/tests/test_cases/test_select_testcase/y_tests.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ import cocotb
2
+
3
+
4
+ @cocotb.test()
5
+ async def y_test(dut):
6
+ pass
testbed/cocotb__cocotb/tests/test_cases/test_select_testcase/y_tests_again.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ import cocotb
2
+
3
+
4
+ @cocotb.test()
5
+ async def y_test(dut):
6
+ pass
testbed/cocotb__cocotb/tests/test_cases/test_select_testcase_error/Makefile ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright cocotb contributors
2
+ # Licensed under the Revised BSD License, see LICENSE for details.
3
+ # SPDX-License-Identifier: BSD-3-Clause
4
+
5
+ # This module exists, but...
6
+ MODULE := x_tests
7
+ # ...this test does not exist
8
+ TESTCASE := y_test
9
+
10
+ # TESTCASE filtering out all tests results in a warning
11
+
12
+ include ../../designs/sample_module/Makefile
testbed/cocotb__cocotb/tests/test_cases/test_select_testcase_error/x_tests.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ import cocotb
2
+
3
+
4
+ @cocotb.test()
5
+ async def x_test(dut):
6
+ dut._log.info("x_test")
testbed/cocotb__cocotb/tests/test_cases/test_skipped/Makefile ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright cocotb contributors
2
+ # Licensed under the Revised BSD License, see LICENSE for details.
3
+ # SPDX-License-Identifier: BSD-3-Clause
4
+
5
+ include ../../designs/sample_module/Makefile
6
+
7
+ SKIPPED_TEST_FILE = ran_skipped_test~
8
+
9
+ clean::
10
+ $(RM) -r ${SKIPPED_TEST_FILE}
11
+
12
+ # Override the default target. We need to run clean (to remove the cached test file)
13
+ # and then test to make sure it is recreated.
14
+ .DEFAULT_GOAL := override
15
+ .PHONY: override
16
+ override: clean all
17
+ @test -f $(SKIPPED_TEST_FILE) || (echo "ERROR: skip=True test was not ran!" >&2 && exit 1)
18
+
19
+ # Set TESTCASE; run test_skipped even though skip=True is set.
20
+ TESTCASE = test_skipped
21
+
22
+ MODULE = test_skipped
testbed/cocotb__cocotb/tests/test_cases/test_skipped/test_skipped.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 pathlib
6
+
7
+ import cocotb
8
+
9
+ skipped_file_name = "ran_skipped_test~"
10
+
11
+
12
+ @cocotb.test(skip=True)
13
+ async def test_skipped(dut):
14
+ """Touch a file so we can check that this test has run."""
15
+ pathlib.Path(skipped_file_name).touch()
testbed/cocotb__cocotb/tests/test_cases/test_sv_interface/Makefile ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright cocotb contributors
2
+ # Licensed under the Revised BSD License, see LICENSE for details.
3
+ # SPDX-License-Identifier: BSD-3-Clause
4
+
5
+ TOPLEVEL_LANG ?= verilog
6
+ VERILOG_SOURCES = $(shell pwd)/top.sv
7
+ MODULE = test_sv_if
8
+ TOPLEVEL = top
9
+
10
+ # Simulator behavior:
11
+ # Icarus Verilog sees SV interfaces as vpiModule but doesn't discover signals inside them
12
+ # Verilator sees SV interfaces as vpiModule and discovers signals inside them
13
+ # Commercial simulators all see SV interfaces as vpiInterface and discover signals inside them
14
+
15
+
16
+ ifneq ($(TOPLEVEL_LANG),verilog)
17
+ all:
18
+ @echo "Skipping test due to TOPLEVEL_LANG=$(TOPLEVEL_LANG) not being verilog"
19
+ clean::
20
+ else
21
+ ifeq ($(filter questa xcelium ius vcs riviera activehdl verilator,$(shell echo $(SIM) | tr A-Z a-z)),)
22
+ all::
23
+ @echo "Skipping simulator $(SIM) because it might not support SV interfaces"
24
+ clean::
25
+ else
26
+ include $(shell cocotb-config --makefiles)/Makefile.sim
27
+ endif
28
+ endif
testbed/cocotb__cocotb/tests/test_cases/test_sv_interface/test_sv_if.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 cocotb
6
+
7
+
8
+ @cocotb.test()
9
+ async def test_sv_if(dut):
10
+ """Test that signals in an interface are discovered and iterable"""
11
+
12
+ dut.sv_if_i._discover_all()
13
+ assert hasattr(dut.sv_if_i, "a")
14
+ assert hasattr(dut.sv_if_i, "b")
15
+ assert hasattr(dut.sv_if_i, "c")
testbed/cocotb__cocotb/tests/test_cases/test_sv_interface/top.sv ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright cocotb contributors
2
+ // Licensed under the Revised BSD License, see LICENSE for details.
3
+ // SPDX-License-Identifier: BSD-3-Clause
4
+
5
+ `timescale 1us/1us
6
+
7
+ interface sv_if();
8
+ logic a;
9
+ reg b;
10
+ wire c;
11
+ endinterface
12
+
13
+ module top ();
14
+
15
+ sv_if sv_if_i();
16
+
17
+ endmodule