The cocotb blog
-
cocotb 2.1.0 released
This release focuses on improving user quality-of-life, improving documentation, and setting cocotb up for even more ambitious feature work. It is backwards compatible with the 2.0 release.
Check out the list below for the changes we are most proud of and think are the most impactful. If you want the full list, check out the release notes.
New Concurrency Primitives
gatherandselectcocotb.triggers.Firstandcocotb.triggers.Combinesupport awaiting multiple Triggers at the same time;Firstwaiting for any to finish, andCombinewaiting for all. However, they have some serious limitations, the most annoying being that they don’t support being passed Python native coroutines directly.To address the issues with these functions, new concurrency primitives were added.
selectandgatherwere introduced to replaceFirstandCombine, respectively. These new functions support being passed coroutines, or any awaitable object directly, and return more information to the user.For a full tutorial on these functions and the rest of cocotb’s concurrency system, check out the new docs!
async def drive(intf, transaction_queue): while True: await RisingEdge(intf.clk) intf.valid.value = 0 # idx is the index into the argument list # res is the result of the argument that finished idx, res = await select( transaction_queue.get(), # coroutine!!! RisingEdge(intf.rst), # Trigger ) if idx == 0: intf.data.value = res.data intf.valid.value = 1 else: # got reset, hold valid low until reset is done intf.valid.value = 0 await FallingEdge(intf.rst)TaskManagertrio introduced to the Python world structured concurrency with
Nurserys. The Python standard library asyncio followed withTaskGroup. Even SystemVerilog hasfork/join. Now cocotb hasTaskManagerto fill the same role. Ifgatherorselectare not expressive enough for your needs,TaskManagerwill likely work for you.async with TaskManager() as tm: @tm.fork async def drive_intf_a(intf): while True: ... # drive interface A @tm.fork async def drive_intf_b(intf): while True: ... # drive interface B # When the TaskManager block exits it implicitly waits for all Tasks to finish before continuing. print("Done!")cocotb Previews
Som improvements to cocotb can only be made by breaking something. Breaking changes are always considered very carefully, and when they occur cocotb gains a new major version. We, the maintainers, do try to prevent major versions from happening too often to make life a bit easier on our users. But the flip side of that coin is that multiple breaking changes can amass over time making it too painful for users to move to the new major version.
To solve this issue, cocotb has gained a new system: “Previews.” Enabling Previews allows cocotb maintainers and developers to make breaking changes without having to wait several years before getting the opportunity. And it allows users to opt-in to the new breaking behavior so they get feedback sooner about whether their codebase is ready for the next major version.
Previews are enabled by setting the
COCOTB_PREVIEWenvironment variable. You can set it to a comma separated list of features, allowing you to adapt to each change, one at a time; or you can simply set it to1to enable all changes.How you use this feature is up to you. Will you leave it off, checking it occasionally, allowing your codebase to take advantage of the backwards compatability guarantee of the cocotb 2.X major release cycle? Or will you leave it set to
1, taking advantage of the newest features and changes on every minor release, thus spreading out the major version upgrade work?Stackable Test Decorators
The
@cocotb.testdecorator has a number of arguments for specifying conditions on when to skip tests, mark them as expected to fail or raise an exception, and more. But this makes more complex uses difficult as all “skip” conditions have to be joined into a single ugly expression.To fix this, we added new “stackable” test decorators:
@cocotb.skipifand@cocotb.xfail, and also made@cocotb.parametrizestackable as well. Each cocotb test can take multiple decorators and every condition they specify is joined together before tests are discovered.@cocotb.skipif(cocotb.top.ENABLE_ETH_B.value == 0, reason="This tests ethernet B, so skip if the device is not configured with it.") @cocotb.xfail(today() == "Monday", reason="Mondays are the worst.") @cocotb.parametrize( packet_size=[1, 10, 200, 2000] ) @cocotb.parametrize( traffic_generator=["realistic", "stress"] ) async def test_switch(dut, packet_size: int, traffic_generator: str) -> None: ...Test Forcing Functions
If you’ve ever written a test where the decision the test has passed happens deep in some random Task, or if you’ve been unable to express the logic to skip a test in the test decorator, cocotb now has a set of test end forcing functions to help you.
Users can now call
pytest.skipandpytest.xfailin tests to immediately end the test with a forced SKIP or XFAIL result.@cocotb.parametrize( valid_fraction=[1.0, 0.6] ready_fraction=[1.0, 0.6], ) async def test_control_flow(dut, valid_fraction: float, ready_fraction: float) -> None: if dut.BUFFERED_OUTPUT.value and ready_fraction != 1.0: pytest.skip("If the device is configured with the buffered output, we will never see ready go low.") ...Similarly, the
cocotb.end_testfunction will end the test immediately as if the main test function had ended.@cocotb.test async def test_watchdog(dut): async def watch_watchdog(): await RisingEdge(dut.watchdog) # End the test from this Task instead of the main test coroutine. cocotb.end_test() # Run the watcher in the background. cocotb.start_soon(watch_watchdog()) ... # Stimulate a hang.Scheduler Rewrite
One of the major efforts of the release cycle should be invisible to the user. The coroutine scheduler that cocotb uses to run Tasks concurrently and react to Triggers firing has been rewritten. This rewrite was designed to improve performance, improve readbility and maintainability, and set cocotb up for scheduler-related enhancements in the coming versions.
Platform Support Changes
Technology progresses and we eventually must leave behind old platforms that have become difficult to maintain. 32-bit builds for Linux and Windows are no longer available. Support for Python 3.6, 3.7, and 3.8 have been removed. MacOS 13 support has also been removed.
On the other hand, cocotb gained support for Python 3.14, Ubuntu 26.04 and MacOS 26. Leaving old Python versions behind allows cocotb to use new Python features to ensure correctness and maintainability.
Read more -
Big news: cocotb 2.0 has landed!
cocotb 2.0 is the next major milestone for our Python-based verification framework, and we couldn’t be more thrilled to share it with you.
To be precise, cocotb 2.0.0 was released live at ORConf in September, followed by cocotb 2.0.1 this week. We held off on the big announcement until now to make sure everything was rock-solid. And guess what? It is. cocotb 2.0 is ready for prime time—whether you’re a long-time user or just getting started. Grab it today from PyPI and dive in!
What’s new in 2.0?
For this milestone, we put the spotlight on developer experience. Chip design and verification are tough enough. Your tools should make life easier, not harder.
We got told many times: with cocotb, writing testbenches feels intuitive and natural. And we couldn’t agree more – except for those corner cases, where it isn’t. For cocotb 2.0, we took a hard look at all the issue reports and hallway discussions we had where people got confused by behavior. In many cases, we could make cocotb just do the right thing. In some cases, “doing the right thing” required changes to the programming interface, and hence potentially changes to user testbenches. That’s why we call this release cocotb 2.0: even though many testbenches will run without any modification, some testbenches will require updates for cocotb 2.0. But we’re convinced: your testbenches will be easier to understand and extend as result!
Take a look at the step-by-step migration guide to guide you through the upgrade from cocotb 1.x to 2.0. The migration guide is also a great starting point to learn more about all the great new features that made it into cocotb 2.0!
Want the full scoop? Check out the release notes and be prepared to get overwhelmed!
A showcase in open source collaboration
None of this would have happened without our incredible users, developers, and maintainers. cocotb 2.0 is proof of what open-source collaboration can achieve. You’re amazing. Truly.
Enjoy cocotb 2.0!
If something doesn’t work as expected, reach out via our support channels. We’re happy to help and excited to see what you’ll build next!
Read more -
Introducing Copra – Type Stubs for Cocotb Testbenches
Ever find yourself digging through HDL code or waveforms just to recall the exact name of a DUT signal you need to drive in your cocotb test? “What was the name of that signal I needed to wiggle??” If you’ve been there, you’re not alone. In Python-based hardware testbenches using cocotb, the Device Under Test (DUT) is manipulated via attributes on a dut handle – but those attributes are dynamically discovered, meaning your IDE can’t auto-suggest them, and a typo in a signal name won’t be caught until runtime. This is where Copra comes in. Copra is a new subproject in the cocotb ecosystem that automatically generates Python typing stubs for your DUT, enabling rich IDE auto-completion and static type checking for cocotb testbenches. In this blog post, we’ll introduce the motivation behind Copra, how it works under the hood, how to integrate it into your workflow, and we’ll dive into detailed examples (including an adder, a matrix multiplier, and a multi-dimensional array DUT) to see Copra in action. We’ll also discuss how tools like VS Code’s Pylance and type checkers (mypy, etc.) benefit from these stubs and how to configure your environment to use them. Let’s get started!
Read more -
cocotb 2.0 is looking for beta-testers!
cocotb 2.0 is getting closer! We’re excited to announce the first beta release of cocotb 2.0 (2.0.0b1) is now available on PyPI. Install it with
Read morepip install cocotb==2.0.0b1to start testing today and let us know how it goes! -
cocotb 1.9 improves simulator support and prepares for the next major release
The cocotb project is proud to announce the immediate release of cocotb 1.9. Backwards-compatible to all prior 1.x versions of cocotb, this release brings a large amount of quality-of-life improvements to our users and prepares them for the upcoming major release of cocotb 2.0.
Read more -
A fresh CI setup for even more robust cocotb releases and happier developers
cocotb is a test framework, enabling users to test their Verilog or VHDL designs using Python-based testbenches. But at the same time, cocotb is also a piece of software that needs testing! As of today, this testing got even better: we are now running all tests against the exact release binaries we’re uploading to PyPi, including our tests against proprietary simulators such as Riviera-PRO, Questa, or Xcelium. At the same time, cocotb developers can be more productive, as the latency for pull request checks reduced from over an hour to around 15 minutes.
This extended testing is exciting news for our cocotb users, who can enjoy even more rock-solid cocotb releases. And it’s exciting news for the free and open source silicon community as a whole: cocotb has worked hard to earn a place in the heart of thousands of verification engineers by being reliable and yet fun to work with. With our new CI system, we continue to push the boundaries of what’s possible in open source EDA and addressing both the technical as well as the non-technical issues along the way.
Read more -
Announcing the cocotb unconference at ORConf
Today, we’re announcing the cocotb unconference as part of the ORConf Sunday Sessions in Munich, Germany on Sept 17, 2023.
The cocotb user community is growing rapidly. Every day, cocotb users write verification code, explore new use cases, and improve on existing ones. Is there something you have figured out when using cocotb? Is there something you’ve been wondering about, or something you’d like to have a discussion on? Are you not yet using cocotb but interested in in-depth discussions with the maintainers and other users? Then you’re fortunate: the cocotb project is hosting an unconference as part of the ORConf Sunday Sessions. Many cocotb maintainers will be there as well!
We won’t have a fixed agenda: instead, everyone is invited to bring their own discussions topics, which we’ll then discuss either in a large group, or in smaller breakout groups. The cocotb unconference will be an interactive event, tailored on the fly to the interests of its attendees.
When and where? Sunday, Sept 17, 2023 in Munich, Germany as part of ORConf. The exact location will be announced later.
Interested in joining? Please register now for ORConf, even if you’re only planning to attend the cocotb unconference. Registration is free, with optional professional tickets available. Please consider buying a professional ticket, the proceeds are funding the FOSSi Foundation and with it the cocotb project, e.g., to pay for our continuous integration setup.
ORConf is an excellent opportunity to present your company to a highly technical audience of hardware engineers, and some sponsorship opportunities are still available. Have a look at the ORConf sponsorship flyer if you’re interested and get in touch!
Read more -
Cocotb user survey 2023: the results are in
For the second time in its history, cocotb has asked its users for input: how they are using cocotb, what they enjoy about it, what pain points they experience, and much more. The results are now in, and paint an encouraging picture. Cocotb not only works, but is enjoyed by many users, and the development priorities of the core development team match the expectations of our users.
The survey also identified some (not overly surprising) areas for improvement; primarily, the availability of learning resources and verification IP.
Read on for a more detailed look into the survey results. We’ll not dive too deep into ways to address the pain points of our users – there are some ideas, and a number of limitations to the abilities of a volunteer-driven project. Please reach out if you would like to get involved or have an idea!
Read more -
cocotb 1.8 is out and makes your verification journey even more enjoyable
The cocotb project is proud to announce the immediate release of cocotb version 1.8.0. This release focuses on bug fixes and reliability improvements, with some notable additions as well.
Read more -
Celebrating 10 years of making verification fun again
Hardware verification can be as rewarding as a treasure hunt. Or as tedious as doing your tax returns. With cocotb, the Python-based verification framework, engineers can enjoy more of the treasure hunt experience. And today this experience is turning 10!
Read more -
Your input is needed: please take part in the cocotb user survey
Here’s an idea for you: grab a cup of your favourite beverage, and click on this link: cocotb user survey 2023.
Cocotb is free to download and use for anyone without registration. That’s why we need your help: how are you using cocotb? What are you enjoying? What do you think could improve? And of course the most basic question: how many cocotb users are there?
The survey should take no longer than 10 minutes to complete. Please reach out to Philipp at philipp@fossi-foundation.org if you have further comments or questions.
We will keep the survey open until June 4, 2023. Please distribute it to your colleagues and cocotb friends!
Click here to take the cocotb user survey 2023.
Read more -
From zero to testing in no time: cocotb 1.7 provides a super-smooth installation experience
The cocotb project is proud to announce the immediate release of cocotb version 1.7.0.
Users will find this release easier to install than any previous release, thanks to the availability of binary builds on the Python’s package repository, PyPi. Just run
pip install cocotbon any supported platform and cocotb is ready for operation within seconds, without the need to have a C/C++ compiler or the Python development libraries available.In addition to the usual set of bug fixes and reliability improvements, users of the Questa simulator will be happy to hear that the industry-standard VHPI interface is now supported with Questa 2022.3 and cocotb 1.7.
Read more -
Hello, and here's your homework.
If you’re reading these lines you undoubtedly know: cocotb has a new website, a new logo, and a brand-new blog!
Read more