我有一个UVM项目。我在test_base中有以下代码:
class test_base extends uvm_test;
//factory registration
`uvm_component_utils(test_base)
//internal decleration
girobo2_env grb_env_i;
//configuration objects:
grb2_env_config m_env_cfg;
axi_agent_config m_axi_agent_cfg;
.........
//build_phase
//Create axi_agent agent configuration object
m_axi_agent_cfg = axi_agent_config::type_id::create("m_axi_agent_cfg");
if(!uvm_config_db #(virtual axi_interface)::get(this, "", "axi_vif", m_axi_agent_cfg.axi_vif)
`uvm_error("RESOURCE_ERROR", "axi_interface virtual interface not found")
m_env_cfg.m_axi_agent_cfg = m_axi_agent_cfg;
// Call function to configure the axi agent
configure_axi_agent(m_axi_agent_cfg);
//--------------------------------------------------------------------
// configure_my_agent
//--------------------------------------------------------------------
// Convenience function to configure the agent
// This can be overloaded by extensions to this base class
virtual function void configure_axi_agent (axi_agent_config cfg);
cfg.is_active = UVM_PASSIVE;
endfunction: configure_my_agent
endclass: test_base
是否可以选择定义configure_my_agent
函数的输入类型(例如c ++中的模板)。
答案 0 :(得分:1)
您可以将configure_my_agent
的输入类型设置为通用uvm_object
。然后,您可以传递任何uvm_object
并适当地投射它。
virtual function void configure_my_agent (uvm_object base_cfg);
if (base_cfg.get_type_name == "grb2_env_config") begin
axi_agent_config cfg;
$cast(cfg, base_cfg);
cfg.is_active = UVM_PASSIVE;
end
else if (base_cfg.get_type_name == "grb2_env_config") begin
grb2_env_config cfg;
$cast(cfg, base_cfg);
cfg.is_active = UVM_PASSIVE;
end
else if ...... // All other config type names
endfunction: configure_my_agent
注意:强>
就个人而言,我不喜欢这种方法。 is_active
的类型为UVM_ACTIVE_PASSIVE_ENUM
,应在构建阶段为每个代理的基本测试直接设置。然后在代理的build_phase中,查找此变量并确定您的代理是主动还是被动。请注意,要使其正常工作,您应该在代理的`uvm_component_utils中注册is_active
变量(UVM组件在其build_phase期间自动查找已注册的类变量)。
答案 1 :(得分:0)
UVM工厂提供了一种机制,用于指定类型覆盖,也可用于检查类型。
静态方法axi_agent_config::type_id::get_type()
返回表示axi_agent_config
类型的代理单例对象的句柄。您可以调用虚拟uvm_object
方法get_object_type()
,该方法返回代理单例对象的句柄,该对象表示传递给cfg
的实际对象的类型。所以你可以写
if (axi_agent_config::type_id::get_type() == cfg.get_object_type() )
// then you have a matching base class object
else if (axi_extended_agent_cdg::type_id::get_type() == cfg.get_object_type() )
// then you have a matching extended object