Home

Awesome

cocotb-test

Build Status PyPI version

cocotb-test provides standard python unit testing capabilities for cocotb

Usage:

conda install -c conda-forge iverilog==10.3
pip install cocotb-test

 or development version

pip install -v https://github.com/themperek/cocotb-test/archive/master.zip

 or

git clone https://github.com/themperek/cocotb-test.git
pip install -v -e cocotb-test
from cocotb_test.simulator import run
def test_dff():
    run(
        verilog_sources=["dff.sv"], # sources
        toplevel="dff",            # top level HDL
        module="dff_cocotb"        # name of cocotb test module
    )
SIM=icarus pytest -o log_cli=True test_dff.py
cocotb-clean -r

Arguments for simulator.run:

Environmental variables:

pytest arguments

Tips and tricks:

pytest --collect-only
pytest -k test_dff_verilog_param[3]
@pytest.mark.parametrize("width", [{"WIDTH_IN": "8"}, {"WIDTH_IN": "16"}])
def test_dff_verilog_testcase(width):
    run(
        ...
        parameters=width,
        sim_build="sim_build/" + "_".join(("{}={}".format(*i) for i in width.items())),
    )
pytest -n NUMCPUS

Running (some) tests and examples from cocotb

For cocotb tests/examples install cocotb in editable mode

git clone https://github.com/potentialventures/cocotb.git
pip install -e cocotb
SIM=icarus pytest -o log_cli=True --junitxml=test-results.xml --cocotbxml=test-cocotb.xml tests

Related resources