uvm_config_db机制支持在不同的测试平台组件之间共享配置和参数。用名为uvm_config_db的配置数据库启用该功能。任何测试台组件都可以使用变量,参数,对象句柄等填充配置数据库。
其他测试平台组件可以从配置数据库访问这些变量,参数,对象句柄,而无需真正知道其在层次结构中的位置。
例如,顶层测试平台模块可以通过uvm_config_db储存虚接口句柄。然后,任何uvm_driver或uvm_monitor组件都可以查询uvm_config_db获取此虚接口的句柄,并将其用于通过接口实际访问信号。
get()和set()是用于从uvm_config_db存储或检索信息的主要方法。任何验证组件都可以使用set()方法为config_db存储一些配置信息,还可以控制哪些其他组件对相同信息具有可见性。可以将其设置为具有全局可见性,或者仅对一个或多个特定测试平台组件可见。get()函数从数据库中检查与参数匹配的共享配置。
get()和set()方法的语法如下:
uvm_config_db#(<type>)::set(uvm_component context, string inst_name, string field_name,<type> value)
uvm_config_db#(<type>)::get(uvm_component context, string inst_name, string field_name, ref value)
context指定从中调用get / set的当前类或组件。inst_name是从中调用get / set的组件实例的名称。field_name是在config_db中设置/获取的对象或参数或变量的名称。<type>标识config_db中设置/获取的配置信息的类型。对于对象句柄,type是类名,而对于其他变量,type是数据类型名,代表了该变量的类型。
建议不要在UVM中这么做。通常,较高级别的组件使用句柄设置配置数据库,而较低级别的组件则使用get / set方法获取它们。
实例化DUT和接口的顶级testbench模块在uvm_config_db中例化虚接口。然后,测试类或UVM组件层次结构中的任何其他组件可以使用get()方法查询uvm_config_db,获得此虚接口的句柄并将其用于访问信号。
下面栈是了如何进行此操作。为APB总线master实例化了DUT和物理接口,然后,将虚接口句柄设置到uvm_config_db。
module test;
logic pclk;
logic [31:0] paddr;
//Instantiate an APB bus master DUT
apb_master apb_master(.pclk(pclk),*);
//Instantiate a physical interface for APB interface
apb_if apb_if(.pclk(pclk), *);
initial begin //Pass this physical interface to test class top //which will further pass it down to env->agent->drv/sqr/mon
uvm_config_db#(virtual apb_if)::set(null, "uvm_test_top", "vif",apb_if);
end
endmodule
下面是APB Env类,该类使用uvm_config_db中的get()方法检索在顶层测试模块中设置的虚接口。
class apb_env extends uvm_env;
`uvm_component_utils(apb_env);
//ENV class will have agent as its sub component
apb_agent agt;
//virtual interface for APB interface
virtual apb_if vif; //Build phase - Construct agent and get virtual interface handle fromtest and pass it down to agent
function void build_phase(uvm_phase phase);
agt = apb_agent::type_id::create("agt", this);
if (!uvm_config_db#(virtual apb_if)::get(this, "", "vif", vif))begin
`uvm_fatal("config_db_err", "No virtual interface specified forthis env instance")
end
uvm_config_db#(virtual apb_if)::set( this, "agt", "vif", vif);
endfunction: build_phase
endclass : apb_env
UVM具有phase机制,由一组构建阶段,运行阶段和检查阶段组成。在run()阶段进行实际的测试仿真,并且在此phase中,每个组件都可以在开始时提出raise_objection和drop_objection。一旦所有组件都drop_objection,则run_phase完成,然后所有组件的check_phase执行,然后测试结束。
这是正常仿真结束的方式,但是如果某些组件由于设计或测试平台中的错误而挂起,则仿真超时也可以终止run_phase。当run_phase启动时,并行超时计时器也会启动。如果在run_phase完成之前超时计时器达到指定的超时限制,则将发出一条错误消息,然后将执行run_phase之后的所有phase,最后测试结束。
正确答案将在下一期公布,或者到下面的文章获取答案