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
相关推荐
Terasic友晶科技7 小时前
第26篇 基于ARM A9处理器用C语言实现中断<二>
c语言·fpga开发·中断·de1-soc开发板
Zoolybo16 小时前
FPGA|安装USB Blaster驱动
fpga开发
我爱C编程2 天前
【硬件测试】基于FPGA的QPSK+帧同步系统开发与硬件片内测试,包含高斯信道,误码统计,可设置SNR
fpga开发·qpsk·帧同步·硬件片内测试·高斯信道
Zoolybo2 天前
FPGA|使用quartus II通过AS下载POF固件
fpga开发
水饺编程3 天前
简易CPU设计入门:控制总线的剩余信号(四)
linux·嵌入式硬件·fpga开发·硬件工程
mcupro3 天前
从AD的原理图自动提取引脚网络的小工具
fpga开发
cckkppll4 天前
FPGA 使用 CLOCK_DEDICATED_ROUTE 约束
fpga开发
萨文 摩尔杰4 天前
ZYNQ-IP-AXI-GPIO
fpga开发·zynq
博览鸿蒙6 天前
国内优秀的FPGA设计公司主要分布在哪些城市?
fpga开发
csdn_gddf1023843986 天前
Verilog边沿检测
fpga开发