Efficient Testbench
- 格式:ppt
- 大小:986.50 KB
- 文档页数:34


In the Universal Verification Methodology (UVM), a transaction denotes a structured data entity utilized for representing an individual unit of activity within a design or testbench. Such transactions are instrumental in modeling the interaction between distinctponents of the design, including the dynamic interplay between the Design Under Test (DUT) and the testbench environment. Within the framework of UVM, transactions are typically concretized as classes, with each class embodying a specific category of transaction. For instance, a transaction class may be delineated to signify a memory read or write operation, a bus transaction, or a data packet transmission between twoponents. Subsequently, transactions may encapsulate fields and methods to embody diverse properties and behaviors inherent to the transaction, epassing attributes such as address, data, control signals, and timing information.在通用核查方法(UVM)中,交易是指用于代表设计或试验台内单个活动单位的结构化数据实体。
Writing Efficient Testbenches原文作者:Mujtaba Hamid翻译:phixcoco@(浙江大学飘渺水云间论坛)[请阅读文档最后的说明]摘要:本应用笔记是专门为没有测试编写经验并对HDL验证流程陌生的逻辑设计者而编写的。
编写测试代码是验证HDL设计的主要手段。
本应用笔记为创建或构建有效的测试设计提供了准则。
同时给出了一个为任何设计开发自检测测试的算法。
涉及的所有设计文件可以从以下的站点获得:PC: ftp:///pub/applications/xapp/xapp199.zipUNIX: ftp:///pub/applications/xapp/xapp199.tar.gz1简介由于设计的规模越来越大和越来越复杂,数字设计的验证已经成为一个日益困难和繁琐的任务。
验证工程师们运用多种验证工具和方法来应对挑战。
对于大的系统,如几百万门的设计,工程师们通常使用一系列完善的验证工具。
当然,对于一些小的设计,设计工程师常常发现能编写测试设计的hdl仿真器就可以做得很好。
测试设计已经成为一个验证高级语言HLL (High-Level Language)描述的设计的标准方法。
典型的,测试设计完成以下任务:·在测试中实例化设计模块Design Under Test(DUT);·向要进行测试的模块(DUT)输入测试向量进行仿真;·仿真通过使用模块的测试向量来仿真测试设计;·仿真结果输出到终端或波形窗口以观察结果;·将实际结果和预期结果进行比较(可选步骤)。
一般测试使用工业标准的VHDL或Verilog硬件描述语言来编写。
测试中调用功能设计,然后仿真。
复杂的测试设计完成一些附加的功能――如它们包含逻辑模块来为设计产生适当的激励或者将实际结果与预期结果做比较。
后续的章节说明了一个优良的测试设计的结构,并提供了一个自检测测试的例子――用以自动化地比较实际结果和测试设计的预期结果。
testbench常⽤语法总结1.testbench总体代码结构`timescale 1ns/1ps //时间精度`define clk_perilod 20 //时钟周期可变module test_file_tb;//==================<端⼝>==================================================reg clk ; //时钟,50Mhzreg rst_n ; //复位,低电平有效reg [XX:0] in ; //wire [XX:0] out ; ////--------------------------------------------------------------------------//-- 模块例化//--------------------------------------------------------------------------my_design u_my_design(.clk (clk ),.rst_n (rst_n ),.in (in ),.out (out ));//----------------------------------------------------------------------//-- 时钟信号和复位信号//----------------------------------------------------------------------initial beginclk = 0;forever#(`Clock/2) clk = ~clk;endinitial beginrst_n = 0; #(`Clock*20+1);rst_n = 1;end//----------------------------------------------------------------------//-- 设计输⼊信号//----------------------------------------------------------------------initial beginin = 0;#(`Clock*20+2); //初始化完成$stop;endendmodule在这⾥插⼊代码⽚2.时钟激励的编写`timescale 1ns/1ps //时间精度`define Clock 20 //时钟周期//========================================================================== //== ⽅法⼀,50%占空⽐//========================================================================== initial beginclk = 0;forever#(`Clock/2) clk = ~clk;end//========================================================================== //== ⽅法⼆,50%占空⽐//========================================================================== initial beginclk = 0;always#(`Clock/2) clk = ~clk;end//========================================================================== //== ⽅法三,产⽣固定输⼊的时钟脉冲//========================================================================== initial beginclk = 0;repeat(6)#(`Clock/2) clk = ~clk;end//========================================================================== //== ⽅法四,⾮50%占空⽐//========================================================================== initial beginclk = 0;forever begin#((`Clock/2)-2) clk = 0;#((`Clock/2)+2) clk = 1;endend3.复位信号`timescale 1ns/1ps //时间精度`define Clock 20 //时钟周期//========================================================================== //== ⽅法⼀,异步复位//========================================================================== initial beginrst_n = 0; #(`Clock*20+1);rst_n = 1;end//========================================================================== //== ⽅法⼆,同步复位//========================================================================== initial beginrst_n = 0; #(`Clock*20);rst_n = 1;end4.task使⽤//========================================================================== //== 输⼊信号任务封装//========================================================================== task i_data;input [7:0] dut_data;begin@(posedge data_en); send_data=0;@(posedge data_en); send_data=dut_data[0];@(posedge data_en); send_data=dut_data[1];@(posedge data_en); send_data=dut_data[2];@(posedge data_en); send_data=dut_data[3];@(posedge data_en); send_data=dut_data[4];@(posedge data_en); send_data=dut_data[5];@(posedge data_en); send_data=dut_data[6];@(posedge data_en); send_data=dut_data[7];@(posedge data_en); send_data=1;#100;endendtask//调⽤⽅法:i_data(8'hXX);//========================================================================== //== 多输⼊信号任务封装//========================================================================== task more_input;input [ 7:0] a;input [ 7:0] b;input [31:0] times;output [ 8:0] c;beginrepeat(times) @(posedge clk) //等待 times 个时钟上升沿c=a+b;endendtask//调⽤⽅法:more_input(x,y,t,z); //按声明顺序5.repeat ,wait函数//==========================================//== repeat重复执⾏//==========================================initial beginstart = 1;repeat(5) @(posedge clk) //等待5个时钟上升沿start = 0;endinitial beginrepeat(10)begin...//执⾏10次endend//===========================================//== wait为电平触发//==========================================initial beginstart = 1;wait(en); //等待en==1start = 0;end6.随机数产⽣$random //产⽣随机数$random % n //产⽣范围 {-n,n} 的随机数{$random} % n //产⽣范围 { 0,n} 的随机数7.⽂本输⼊输出reg [a:0] data_mem [0:b]; //定义位宽为(a+1)深度为(b+1)的存储器$readmemb/$readmemh("<读⼊⽂件名>",<存储器名>);$readmemb/$readmemh("<读⼊⽂件名>",<存储器名>,<起始地址>);$readmemb/$readmemh("<读⼊⽂件名>",<存储器名>,<起始地址>,<结束地址>);$readmemb/*------------------------------------------------------------------------*\读取⼆进制数据,读取⽂件内容只能包含:空⽩位置,注释⾏,⼆进制数数据中不能包含位宽说明和格式说明,每个数字必须是⼆进制数字。