cocotb

CocoTB Simulation Directory

This directory contains simulation files for running Cocotb tests with GHDL, NVC, or Verilator backends.

Running Tests

Basic Usage

# Run a specific VHDL test with GHDL (Default) export SIM=ghdl python3 tests/units/test_edge_detector.py # Switch to NVC (VHDL) export SIM=nvc python3 tests/units/test_edge_detector.py # Switch to Verilator (Verilog/SystemVerilog) export SIM=verilator python3 tests/units/test_verilog_counter.py

Using the Simulation Engine

The recommended way to run simulations is through the unified run_simulation() API:

from engine.simulation import run_simulation run_simulation( top_level="wrapper_smi_sync", module="test_smi_sync", generics={"DATA_WIDTH": 32}, simulator="ghdl", # ghdl, nvc, or verilator waves=True, )

Unit Tests (Generated)

Templates for all VHDL units in src/units/ are available in sim/cocotb/tests/units/. These were generated using cocotb-testgen.

Test FileStatus (NVC)
tests/units/test_edge_detector.py✅ Verified Logic (GHDL/NVC)
tests/units/test_verilog_counter.py✅ Verilator Verification
tests/units/*.py✅ Smoke Tests

Available Test Scripts (Manual)

Test FileDescription
tests/test_uart_new.pyUART sniffer testbench
tests/test_system_top.pyFull system top-level tests
tests/test_verilog_counter.pyVerilator smoke test
tests/test_system_top_snd.pySystem top send path tests
tests/test_spi_rcv.pySPI receiver tests
tests/test_spi_injector.pySPI injector tests
tests/test_dds.pyDDS/phase accumulator tests
tests/test_engine_demo.pySimulation engine demo
tests/run_test_system_top.pyPytest runner for system top

Note: NVC is the recommended simulator for full behavioral testing due to GHDL VPI limitations with scalar ports.

Directory Structure

cocotb/ ├── engine/ # Simulation orchestrator │ ├── backends/ # GHDL, NVC, and Verilator backends │ ├── simulation.py # Main run_simulation() entry point │ └── ... ├── tests/ # Test files ├── tb/ # Testbench infrastructure (drivers, monitors, scoreboards) ├── packages/ # External cocotb extensions (cocotbext-uart, cocotbext-i2c) ├── waves/ # Generated waveforms └── logs/ # Test logs

Documentation


Back to main documentation