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
相关推荐
FPGA小迷弟13 小时前
FPGA 应用技术能力的完整闭环(1-4)
fpga开发·dsp开发·fpga·sdr·无线电
Eloudy15 小时前
FPGA 开发与 IC 数字前端设计
fpga开发
tju新生代魔迷18 小时前
Verilog HDL 学习笔记(十八)| 附录C:关键字、系统任务和编译指令
fpga开发
free-elcmacom21 小时前
FPGA学习笔记<1>FPGA的开发流程
fpga开发·硬件工程·hdl
明德扬21 小时前
AD9653单通道波形怎么看?幅度、频率与基础测量入门
学习·fpga开发·fpga
ERROR:991 天前
GPT Images 2.5将手稿转时序图效果不佳
fpga开发
尤老师FPGA1 天前
声学相机介绍
fpga开发
科恒盛远1 天前
ZU902 FMC194 可编程宽带信号源实测
fpga开发·硬件工程·信号处理
大盛供应链·卢生1 天前
哪些国产芯片可以替代进口芯片,哪些替代不了
fpga开发·容器
ALINX技术博客2 天前
跨越 1819 公里,ALINX 携 AI 异构平台、电子后视镜及 HIL 仿真方案亮相深圳国际电子展
ai·fpga开发·汽车