cocotb is a coroutine-based cosimulation library that enables writing Verilog and VHDL testbenches in Python. It provides a robust framework for verifying hardware designs by interacting directly with commercial and open-source HDL simulators. The current version is 2.0.1, with major releases typically aligning with significant architectural changes, moving towards more Pythonic async/await patterns.
pip install cocotbVerified import paths — ran on the pinned version, not inferred.
This Python code defines a basic `cocotb` test for a D flip-flop (DFF) with clock and data inputs (`clk`, `i`) and a data output (`q`). To run this, you need a corresponding Verilog/VHDL DFF design file (e.g., `dff.v` or `dff.vhdl`) and a `Makefile` to integrate with an HDL simulator (like Icarus Verilog or GHDL). The `Makefile` typically specifies `TOPLEVEL`, `TOPLEVEL_LANG`, and `SIM` variables, and orchestrates the simulation. For simpler execution, `pytest-cocotb` can also be used.
Update test functions to `async def` and use `@cocotb.test()`. For parameterized tests, import `TestFactory` from `cocotb.regression`. Review cocotb 2.0 migration guides for full details.
Install a compatible HDL simulator for your target HDL (Verilog or VHDL) and ensure its executable is in your system's PATH environment variable.
Carefully review the `cocotb` documentation on `Makefile` setup. Ensure `TOPLEVEL` matches your HDL top module, `TOPLEVEL_LANG` is correct, `SIM` points to an installed simulator, and `PYTHONPATH` includes the directory containing your Python test files.
Ensure all calls to `cocotb` triggers or other `async` functions are preceded by the `await` keyword. If using an older `cocotb` version, ensure `yield` is used for `@cocotb.coroutine` functions.
Run `pip install cocotb` in your active Python environment. If using a `Makefile`, ensure `PYTHONPATH` is correctly set to include the directory containing your Python test file(s).
Ensure your test functions are decorated with `@cocotb.test()`. Verify the `Makefile`'s `MODULE` variable points to the correct Python module (e.g., `MODULE=test_my_design`) and `PYTHONPATH` includes the directory containing `test_my_design.py`.
Install the required HDL simulator (e.g., Icarus Verilog for Verilog, GHDL for VHDL). Ensure its executable is added to your system's PATH environment variable.
Change your import statement from `from cocotb.test import TestFactory` to `from cocotb.regression import TestFactory`.
No dependency data recorded yet.