Constraint Random Verification With Python and Cocotb
Constraint Random Verification With Python and Cocotb
Philipp Wagner
Agenda
Verification is software
With cocotb, you write verification like software.
In Python.
module fifo #(
parameter Width = 8,
parameter Depth = 32
) (
input logic clk,
input logic rst,
@cocotb.test()
async def test_fifo_manual(dut):
# clock with 1 ns period
cocotb.start_soon(Clock(dut.clk, 1, units='ns').start())
# reset (2 cycles)
dut.din.value = 0
dut.wr_en.value = 0
dut.rd_en.value = 0
dut.rst.value = 1
await ClockCycles(dut.clk, 2)
dut.rst.value = 0
if dut.empty.value.integer != 0:
await FallingEdge(dut.empty)
dut.rd_en.value = 1
await RisingEdge(dut.clk)
dut.rd_en.value = 0
expected_output = 100
› “Hardcoded” test
› Great for bringup (“designer tests”)
› Great for understanding the test
› Great to ensure that bugs stay fixed
› Benefits
› Write exhaustive test benches more efficiently.
› Finds corner cases you haven’t thought about.
class Bus;
rand bit[15:0] addr;
rand bit[31:0] data;
constraint word_align {addr[1:0] == 2'b0;}
endclass
Example: FIFO
https://pyvsc.readthedocs.io
› Constraints are Python functions and solved using a pure-Python SAT solver
› No covergroups, trees of coverpoints
› Inspired by SystemVerilog, but extended with own ideas
› Permissively licensed (BSD license)
› cocotbcoverageview
https://github.com/JoseIuri/cocoTBCoverageView
https://docs.python.org/3/library/random.html
https://docs.cocotb.org/en/stable/building.html#envvar-RANDOM_SEED
You will be emailed a link to a recording of today’s webinar and you will be able to download
these slides. For upcoming webinars please visit www.aldec.com/events
Traininghttps://www.aldec.com/training TySOM™
High Performance Embedded Development
Spec-TRACER™
Support https://www.aldec.com/support Requirements Lifecycle Management
DO-254/CTS™
FPGA Level In-Target Testing
Blog https://www.aldec.com/company/blog
HES™
SoC/ASIC Prototyping
RTAX/RTSX
Prototyping Microchip™ Rad-Tolerant Devices