| |
Factory Overrides
从construction这个观点来说,UVM factory允许一个UVM 类被另一个继承类替换。此工具可用于更改或更新组件行为或扩展配置对象。必须在构造目标对象之前指定factory重载,因此在构建过程开始时这样做很方便。
Sub-Component Configuration Objects
每个集合组件(如agent或env)都应具有定义其结构和行为的配置对象。这些配置对象应该在test build method里被创建,并根据测试用例的要求进行配置。如果子组件的配置要么复杂,要么可能会发生变化,那么值得添加一个虚函数调用来处理配置,因为这可能会在从基本测试类扩展来的测试用例中过载。
//
// Class Description:
//
//
class spi_test_base extends uvm_test;
// UVM Factory Registration Macro
//
`uvm_component_utils(spi_test_base)
//------------------------------------------
// Data Members
//------------------------------------------
//------------------------------------------
// Component Members
//------------------------------------------
// The environment class
spi_env m_env;
// Configuration objects
spi_env_config m_env_cfg;
apb_agent_config m_apb_cfg;
spi_agent_config m_spi_cfg;
//------------------------------------------
// Methods
//------------------------------------------
// Standard UVM Methods:
extern function new(string name = "spi_test_base", uvm_component parent = null);
extern function void build_phase( uvm_phase phase );
extern virtual function void configure_env(spi_env_config cfg);
extern virtual function void configure_apb_agent(apb_agent_config cfg);
endclass: spi_test_base
function spi_test_base::new(string name = "spi_test_base", uvm_component parent = null);
super.new(name, parent);
endfunction
// Build the env, create the env configuration
// including any sub configurations and assigning virtual interfaces
function void spi_test_base::build_phase( uvm_phase phase );
// Create env configuration object
m_env_cfg = spi_env_config::type_id::create("m_env_cfg");
// Call function to configure the env
m_apb_cfg = apb_agent_config::type_id::create("m_apb_cfg");
// Call function to configure the apb_agent
configure_apb_agent(m_apb_cfg);
// More to follow
endfunction: build_phase
//
// Convenience function to configure the env
//
// This can be overloaded by extensions to this base class
function void spi_test_base::configure_env(spi_env_config cfg);
cfg.has_functional_coverage = 1;
cfg.has_reg_scoreboard = 0;
cfg.has_spi_scoreboard = 1;
endfunction: configure_env
//
// Convenience function to configure the apb agent
//
// This can be overloaded by extensions to this base class
function void spi_test_base::configure_apb_agent(apb_agent_config cfg);
cfg.active = UVM_ACTIVE;
cfg.has_functional_coverage = 0;
cfg.has_scoreboard = 0;
endfunction: configure_apb_agent