cocotb value cocotb—基础语法对照篇

cocotb---基础语法对照篇

python 复制代码
import cocotb
from cocotb.triggers import Timer
from adder_model import adder_model
from cocotb.clock import Clock
from cocotb.triggers import RisingEdge
import random

@cocotb.test()
async def adder_basic_test(dut):

    """Test for 5 + 10"""
    cocotb.fork(Clock(dut.clk, 10, units='ns').start())
    A = 5
    B = 10

    #dut.A <= A
    #dut.B <= B  # 和下边两行等价
    dut.A.value =A
    dut.B.value =B
    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
    assert dut.X.value == adder_model(A, B), "Adder result is incorrect: {} != 15".format(dut.X.value)


@cocotb.test()
async def adder_randomised_test(dut):
    """Test for adding 2 random numbers multiple times"""
    cocotb.fork(Clock(dut.clk, 5, units='ns').start())
    for i in range(10):

        A = random.randint(0, 15)
        B = random.randint(0, 15)

        #dut.A <= A
        #dut.B <= B
        dut.A.value = A
        dut.B.value = B

        await RisingEdge(dut.clk)
        await RisingEdge(dut.clk)

        assert dut.X.value == adder_model(A, B), "Randomised test failed with: {A} + {B} = {X}".format(
            A=dut.A.value, B=dut.B.value, X=dut.X.value)
复制代码
#adder_model.py
def adder_model(a: int, b: int) -> int:
    """ model of adder """
    return a + b
Makefile 复制代码
# Makefile
TOPLEVEL_LANG= verilog
PWD=$(shell pwd)

VERILOG_SOURCES=./adder.v

TOPLEVEL=adder
MODULE= test_adder

SIM=icarus

include $(shell cocotb-config --makefiles)/Makefile.sim

多文件tb, 多文件dut

复制代码
# makefile template

VERILOG_SOURCES = $(PWD)/submodule.sv $(PWD)/my_design.sv
# TOPLEVEL is the name of the toplevel module in your Verilog or VHDL file:
TOPLEVEL=my_design
# MODULE is the name of the Python test file:
MODULE=test_my_design

include $(shell cocotb-config --makefiles)/Makefile.sim
相关推荐
千宇宙航4 小时前
闲庭信步使用SV搭建图像测试平台:第三十二课——系列结篇语
fpga开发
千宇宙航10 小时前
闲庭信步使用SV搭建图像测试平台:第三十一课——基于神经网络的手写数字识别
图像处理·人工智能·深度学习·神经网络·计算机视觉·fpga开发
小眼睛FPGA1 天前
【RK3568+PG2L50H开发板实验例程】FPGA部分/紫光同创 IP core 的使用及添加
科技·嵌入式硬件·ai·fpga开发·gpu算力
forgeda1 天前
如何将FPGA设计验证效率提升1000倍以上(2)
fpga开发·前沿技术·在线调试·硬件断点·时钟断点·事件断点
9527华安2 天前
FPGA实现40G网卡NIC,基于PCIE4C+40G/50G Ethernet subsystem架构,提供工程源码和技术支持
fpga开发·架构·网卡·ethernet·nic·40g·pcie4c
search72 天前
写Verilog 的环境:逻辑综合、逻辑仿真
fpga开发
search72 天前
Verilog 语法介绍 1-1结构
fpga开发
小眼睛FPGA2 天前
【RK3568+PG2L50H开发板实验例程】Linux部分/FPGA dma_memcpy_demo 读写案例
linux·运维·科技·ai·fpga开发·gpu算力
幸运学者2 天前
xilinx axi datamover IP使用demo
fpga开发
搬砖的小码农_Sky2 天前
XILINX Zynq-7000系列FPGA的架构
fpga开发·架构