使用Makefile、VCS、Verdi做个简单的TestBench 目录:1.简介2.需求3.加法器模块4.测试模块5.测试脚本6.编译项目7.测试结果1.简介Synopsys的VCS和Verdi是做IC使用的很好的开发工具。但新手往往是无法下手,入门比较困难。在此,我根据自己的学习经历,写个最简单的使用教程。教程中会用到Makefile、VCS、Verdi,写个简单的8位加法器的TB例子。所有代码都使用verilog编写,带简单的结果验证功能。 此教程没有使用到UVM,以后有时间我在单独写个UVM的简单例子。 2.需求我是在VMware下开发测试的,用到的软件列表如下:VMware®Workstation12Pro,12.5.7build-5813279CentOS-6.10-x86_64-bin-DVD1.isoscl_v2016.12_common.spfscl_v2016.12_linux64.spfSynopsysInstaller_v3.5.runuvm-1.1d.tar.gzVCS_vL-2016-SP2-12verdi_vL-2016.06-SP2-12 Win7下的许可证破解软件是:scl_keygen.rar 3.加法器模块8位加法器adder8.v代码如下:输入a_i和b_i都是8位的,输出c_o是9位的。只是用做示例,不需要太纠结合理性了。 moduleadder8(inputclk,input[7:0]a_i,input[7:0]b_i,outputreg[8:0]c_o);always@(posedgeclk)beginc_o=a_i+b_i;endendmodule4.测试模块测试模块tb_adder8.v,代码如下://TB_SEED是随机种子`ifndefTB_SEED`defineTB_SEED0`endifmoduletb_adder8(); wire[8:0]result; reg[7:0]input_0; reg[7:0]input_1; regclk; //clk2是主clk的延迟,用于验证结果 wire#5clk2; assign clk2=clk;initialbegin $fsdbDumpfile(adder8.fsdb); $fsdbDumpvars(); $display(TB_SEEDis%d,`TB_SEED); clk=0; input_0=8'd0; input_1=8'd0; #10000 $display(AlltestPASS!); $finish;end//主时钟50MHzalwaysbegin #10clk=~clk;end//产生随机输入always@(negedgeclk)begin input_0=$random()%256; input_1=$random()%256;end//获取验证输出always@(posedgeclk2)begin if((input_0+input_1)!=result)begin $display(Testfailedfor%x+%x=%x,input_0,input_1,result); $finish; endelsebegin $display(%x+%x=%x,input_0,input_1,result); endend//连接加法器模块adder8dut( .clk(clk), .a_i(input_0), .b_i(input_1), .c_o(result));endmodule5.测试脚本整个编译过程采用Makefile控制,Makefile文件内容如下:Makefile里面的空格排版都是TAB键,否则会出错,修改的时候请注意一下这个细节。 其中file.f文件的内容如下: VCS=vcs-sverilog-timescale=1ns/1ns+vpi-lbuild.log-debug_access+allSIMV=./simv-lsimv.logifndefTB_SEEDTB_SEED=1024endifall:compruncomp:$(VCS)+define+TB_SEED=$(TB_SEED)+incdir+.\adder8.v\tb_adder8.vrun:$(SIMV)+fsdbfile+top.fsdbdbg:verdi-ffile.f-ssftop.fsdb&clean:rm-rfcorecsrcsimv*vc_hdrs.hucli.keyurg**.log*.fsdbnovas.*verdiLogtb_adder8.vadder8.v6.编译项目编译前,请先清除项目: 然后,编译项目: 然后,查看波形: makecleanmakemakedbg 编译日志文件为:build.log,如果有错误可查看该文件: Command:vcs-sverilog-timescale=1ns/1ns+vpi-lbuild.log-debug_access+all+define+TB_SEED=1024\+incdir+.adder8.vtb_adder8.v ChronologicVCS(TM) VersionL-2016.06-SP2-12_Full64--TueNov2018:57:092018 Copyright(c)1991-2016bySynopsysInc. ALLRIGHTSRESERVEDThisprogramisproprietaryandconfidentialinformationofSynopsysInc.andmaybeusedanddisclosedonlyasauthorizedinalicenseagreementcontrollingsuchuseanddisclosure.Parsingdesignfile'adder8.v'Parsingdesignfile'tb_adder8.v'TopLevelModules: tb_adder8TimeScaleis1ns/1nsStartingvcsinlinepass...1uniquemodulestogeneraterecompilingmoduletb_adder8make[1]:Enteringdirectory`/home/toor/ajob/adder8/csrc'rm-f_csrc*.sopre_vcsobj_*.soshare_vcsobj_*.soif[-x../simv];thenchmod-x../simv;fig++ -o../simv -Wl,-rpath-link=./-Wl,-rpath='$ORIGIN'/simv.daidir/-Wl,-rpath=./simv.daidir/\-Wl,-rpath='$ORIGIN'/simv.daidir//scsim.db.dir -rdynamic objs/amcQw_d.o _19474_archive_1.so\SIM_l.o rmapats_mop.ormapats.ormar.ormar_llvm_0_1.ormar_llvm_0_0.o \/usr/synopsys/vcs_L-2016.06-SP2-12/linux64/lib/libzerosoft_rt_stubs.so/usr/synopsys/vcs_L-2016.06-SP2-12/linux64/lib/libvirsim.so\/usr/synopsys/vcs_L-2016.06-SP2-12/linux64/lib/liberrorinf.so/usr/synopsys/vcs_L-2016.06-SP2-12/linux64/lib/libsnpsmalloc.so\/usr/synopsys/vcs_L-2016.06-SP2-12/linux64/lib/libvfs.so /usr/synopsys/vcs_L-2016.06-SP2-12/linux64/lib/libvcsnew.so\/usr/synopsys/vcs_L-2016.06-SP2-12/linux64/lib/libsimprofile.so/usr/synopsys/vcs_L-2016.06-SP2-12/linux64/lib/libuclinative.so\-Wl,-whole-archive/usr/synopsys/vcs_L-2016.06-SP2-12/linux64/lib/libvcsucli.so-Wl,-no-whole-archive\_vcs_pli_stub_.o /usr/synopsys/vcs_L-2016.06-SP2-12/linux64/lib/vcs_save_restore_new.o\/usr/synopsys/verdi3_L-2016.06-SP2-12/share/PLI/VCS/LINUX64/pli.a-ldl -lc-lm-lpthread\-ldl../simvuptodatemake[1]:Leavingdirectory`/home/toor/ajob/adder8/csrc'CPUtime:.294secondstocompile+.427secondstoelab+.276secondstolink 仿真日志文件为:simv.log,仿真结果在该文件内: Command:/home/toor/ajob/adder8/./simv-lsimv.log+fsdbfile+top.fsdbChronologicVCSsimulatorcopyright1991-2016ContainsSynopsysproprietaryinformation.CompilerversionL-2016.06-SP2-12_Full64;RuntimeversionL-2016.06-SP2-12_Full64;Nov2018:572018*Verdi3*Loadinglibsscore_vcs201606.so*Verdi3*:FSDB_GATEisset.*Verdi3*:FSDB_RTLisset.*Verdi3*:EnableParallelDumping.FSDBDumperforVCS,ReleaseVerdi3_L-2016.06-SP2-12,Linuxx86_64/64bit,12/11/2017(C)1996-2017bySynopsys,Inc.*Verdi3*:CreateFSDBfile'top.fsdb'*Verdi3*:Begintraversingthescopes,layer(0).*Verdi3*:Endoftraversing.TB_SEEDis 102424+81=0a509+63=06c0d+8d=09a65+12=07701+0d=00e76+3d=0b3ed+8c=179f9+c6=1bfc5+aa=16f.........51+04=05580+f9=17906+ca=0d0AlltestPASS!$finishcalledfromfiletb_adder8.v,line26.$finishatsimulationtime 10000 VCS Simulation ReportTime:10000nsCPUTime: 0.550seconds; Datastructuresize: 0.0MbTueNov2018:57:1120187.测试结果 最终Verdi的效果如下: 这样一个简单的采用Makefile、VCS、Verdi的TestBench就诞生了。