UVM打印hello word

本文介绍了如何在Synopsys VCS环境中使用UVM(Universal Verification Methodology)创建一个简单的hello_world测试组件,包括类定义、初始化、运行阶段和Makefile配置。重点展示了从TB文件启动测试并观察测试日志的过程。
部署运行你感兴趣的模型镜像

DUT文件hello_world.sv打印

class hello_world extends uvm_test;//定义
  `uvm_component_utils(hello_world);//将类注册到工厂factory,才能用uvm框架

  function new (string name, uvm_component parent);//规定用new()函数分配空间
    super.new(name, parent);
  endfunction

  virtual task run_phase(uvm_phase phase);
   //phase.raise_objection(this); 
   `uvm_info("TEST", "****************************", UVM_MEDIUM);
   `uvm_info("TEST", "* my first uvm hello_world *", UVM_MEDIUM);
   `uvm_info("TEST", "****************************", UVM_MEDIUM);
   //phase.drop_objection(this); 
  endtask

endclass:hello_world

TB文件test.sv

program automatic test;
  import uvm_pkg::*;//进入所有uvm的feature,如factory,config机制
  `include "../hello_world.sv"

  initial begin
    $timeformat(-9, 1, "ns", 10);
    run_test();//启动uvm_root的架构,激活component的phase函数,从test开始执行。从+UVM_TESTNAME获取一个测试激励,并创建测试组件uvm_test_top
  end
endprogram

run_test()的整个启动及执行流程参考张强的《UVM 实战》白皮书第55页,大致为run_test----启动验证平台—根据UVM_TESTNAME产生实例依次执行build_phase,形成为完整的UVM树,再按照顺序执行UVM树,各结点的connect_phase、main_phase等,最后所有phase执行完,仿真结束。
UVM的Makefile文件

UVM_VERBOSITY =	UVM_MEDIUM
DEFINE=

##TB filelist
TB_FILES   = ../test.sv

#compile option
VCS =	vcs -full64\
       	+v2k\
       	-sverilog\
        -sim_res=1ps\
	-l compile.log\
	-debug_acc+all -debug_region+cell+encrypt\
       	-fsdb\
	+vcd+vcdpluson\
        -lca -cm line+fsm+cond+path+branch+tgl\
	+vpi \
	+define+UVM_OBJECT_MUST_HAVE_CONSTRUCTOR \
	+incdir+$(UVM_HOME)/src \
    $(UVM_HOME)/src/uvm.sv \
	$(UVM_HOME)/src/dpi/uvm_dpi.cc -CFLAGS -DVCS
##simv option
SIMV = 	./simv +UVM_VERBOSITY=$(UVM_VERBOSITY) -l vcs.log\
	-sml +ntb_random_seed=$(SEED)\
	-lca -cm line+fsm+cond+path+branch+tgl

##for testbench compile command 
comp:
	$(VCS) $(TB_FILES)
##for simv command
run:
	$(SIMV) +UVM_TESTNAME=hello_world

##clean compile and simv generate files
clean:
	rm -rf AN.DB DVEfiles csrc *.simv *.simv.daidir simv* ucli.key 64
	rm -rf *.log* *.vpd *.fsdb *.vdb novas* *verdi*
	rm -rf vc_hdrs.h  via.rc
	

make comp编译之后会报错,原因是环境构建有问题
在这里插入图片描述
配置UVM_HOME环境变量

export UVM_HOME=/usr/synopsys/vcs/O-2018.09-SP2/etc/uvm-1.1
echo $UVM_HOME

enter键之后显示结果
/usr/synopsys/vcs/O-2018.09-SP2/etc/uvm-1.1
重新编译,make run之后结束,打开vcs.log文件结果如下
vcs.log文件

UVM_INFO @ 0.0ns: reporter [RNTST] Running test hello_world...
UVM_INFO ../hello_world.sv(10) @ 0.0ns: uvm_test_top [TEST] ****************************
UVM_INFO ../hello_world.sv(11) @ 0.0ns: uvm_test_top [TEST] * my first uvm hello_world *
UVM_INFO ../hello_world.sv(12) @ 0.0ns: uvm_test_top [TEST] ****************************
****************************

您可能感兴趣的与本文相关的镜像

Llama Factory

Llama Factory

模型微调
LLama-Factory

LLaMA Factory 是一个简单易用且高效的大型语言模型(Large Language Model)训练与微调平台。通过 LLaMA Factory,可以在无需编写任何代码的前提下,在本地完成上百种预训练模型的微调

<think>好的,我现在需要解决用户在UVM框架中如何正确使用打印功能获取完整名称的问题。用户之前已经得到过关于两种方法的回答,现在进一步询问相关使用方法和解决方案。首先,我需要回顾之前的对话,确保不重复信息,同时补充更多细节或可能遗漏的部分。用户提到他们想查找关于UVM打印功能的使用方法,特别是获取完整名称(fullname)。根据之前的回答,已经介绍了get_full_name()和print()方法,但用户可能需要更深入的信息,比如如何在不同场景下应用这些方法,或者遇到问题时如何调试。首先,我需要确认是否覆盖了所有可能的打印方式。除了直接调用get_full_name()和使用print()方法,UVM还提供了uvm_printer类,允许自定义打印格式。这一点可能在之前的回答中简要提到过,但需要更详细的说明,比如如何重写do_print方法来自定义输出。另外,用户可能关心层次结构的生成机制,尤其是uvm_component和uvm_object的区别。需要进一步解释为什么uvm_object默认没有层次路径,以及如何通过设置父对象来建立层次关系。这里可能需要示例代码,比如调用set_parent()方法,并展示如何影响get_full_name()的输出。还需要考虑打印信息的控制,比如使用不同的report宏(uvm_info,uvm_warning等)来输出不同级别的信息,并如何设置verbosity来控制打印信息的可见性。例如,在调试时提高verbosity级别,而在正常运行时降低,以避免日志过多。另一个方面是使用uvm_top打印整个UVM环境的层次结构。这可能对用户有帮助,特别是当需要全局查看组件结构时。需要给出具体的代码示例,说明如何调用uvm_top.print_topology(),并解释输出结果的结构。此外,用户可能遇到名称冲突或覆盖的问题,尤其是在使用factory机制时。需要说明如何确保重载组件时的名称一致性,可能涉及type_id::create的使用和名称传递的正确方法。这部分可能需要引用UVM的工厂模式文档,确保信息的准确性。还要考虑自定义打印机的情况,比如用户希望以特定格式输出对象信息。这里需要介绍uvm_printer的子类化,例如创建自定义的printer类,并覆盖相关方法,如print_header、print_footer等,以满足特定的格式需求。在总结部分,需要强调不同方法的应用场景:get_full_name()适合快速获取路径,print()适合详细对象信息,自定义打印机适合特定格式需求,而uvm_top.print_topology()适合整体结构查看。同时,提醒用户注意uvm_component和uvm_object在层次结构上的根本区别,避免混淆。最后,生成的相关问题需要围绕这些扩展点,例如如何控制打印详细度、自定义打印机、解决名称冲突等,帮助用户深入探索可能遇到的后续问题。</think>### UVM打印功能深度解析 在UVM框架中获取完整名称的打印功能可通过以下方法实现,结合层次结构管理和自定义打印技术: #### 一、核心打印方法 1. **`get_full_name()`直接调用** ```systemverilog // 组件内直接打印 uvm_report_info("DEBUG", $sformatf("Component path: %s", get_full_name()), UVM_LOW); ``` 输出示例:`uvm_test_top.env.master_agent.monitor`[^3] 2. **对象层次绑定** ```systemverilog class packet extends uvm_object; `uvm_object_utils(packet) function void set_parent(uvm_component parent); super.set_parent(parent); endfunction endclass // 建立层次关系 packet pkt = packet::type_id::create("pkt"); pkt.set_parent(env.master_agent); uvm_report_info("OBJ_PATH", pkt.get_full_name()); ``` 输出示例:`uvm_test_top.env.master_agent.pkt` #### 二、增强打印控制 1. **动态详细度控制** ```systemverilog // 设置组件打印详细度 env.set_report_verbosity_level_hier(UVM_FULL); monitor.set_report_id_verbosity("TRANSACTION", UVM_DEBUG); ``` 2. **全局拓扑打印** ```systemverilog initial begin #100ns; uvm_top.print_topology(); // 打印整个UVM层次树 end ``` 输出结构: ``` uvm_test_top (my_test) env (my_env) agent (my_agent) sequencer (uvm_sequencer) driver (my_driver) ``` #### 三、高级打印定制 1. **自定义打印机实现** ```systemverilog class json_printer extends uvm_printer; virtual function string print_header(); return "{\n"; endfunction virtual function string print_footer(); return "\n}"; endfunction virtual function string print_field (string name, uvm_bitstream_t value, int size, radix_enum radix=UVM_NORADIX); return $sformatf(" \"%s\": %0d,\n", name, value); endfunction endclass // 使用示例 json_printer jp = new(); my_object.print(jp); ``` 输出示例: ``` { "m_value": 42, } ``` 2. **递归打印算法** 对于复杂对象结构,可使用递归遍历: $$ \text{print\_object}(obj) = \begin{cases} \text{print\_fields}(obj) & \text{if leaf node} \\ \bigcup_{child} \text{print\_object}(child) & \text{otherwise} \end{cases} $$ #### 四、调试技巧 1. **名称冲突检测** ```systemverilog // 检查重复实例名 function void check_duplicate_names(); uvm_root top = uvm_root::get(); uvm_component all[$]; top.get_children(all); foreach(all[i]) begin foreach(all[j]) begin if (i != j && all[i].get_name() == all[j].get_name()) `uvm_error("DUPNAME", $sformatf("Duplicate name %s found", all[i].get_name())) end end endfunction ``` 2. **工厂覆盖追踪** ```systemverilog // 打印所有工厂注册类型 uvm_factory f = uvm_factory::get(); f.print(); ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值