I have a test_base, and several test extensions. In the extensions, I would like to change some agents from active->passive. However I’m not sure how to do this in the correct order… see the following code comments:
class test_UDP_LL extends test_base;
virtual function void build_phase(uvm_phase phase);
// cfg.init(...); // I cannot do this because cfg hasnt been created yet.
super.build_phase(phase); // execute test base
// cfg.init(...); // I cannot do this because... it's too late. The test base already built the environment.
endfunction
//...
endclass
What is the standard approach here? Create local variables in the test_base, and set those before super.build, or perhaps create the env cfg object in the test_base new?
I do nor know why you want to run the init task of your configuration. One objective of a test is to customize yurr verification environment, i.e. setting your agents UVM_ACTIVE or UVM_PASSIVE.
What I normally do is the following:
//-----------------------------------------------------------------------------
class example_top_test1 extends example_top_base_test;
//-----------------------------------------------------------------------------
function void example_top_test1::build_phase(uvm_phase phase);
// Include your settings
uvm_config_db#(int)::set(this, “env.apb_env_i.agent”, “is_active”, UVM_ACTIVE);
uvm_config_db#(int)::set(this, “env.spi_env_i.agent”, “is_active”, UVM_ACTIVE);
// NEED to set configurations before calling super.build_phase() which creates the
// verification hierarchy.
super.build_phase(phase);
endfunction : build_phase
In the corresponding agents I’m calling uvm_config_db-get.
This works fine.
Hope this helps.
Since it’s your code, you can define a hook method:
class test_UDP_LL extends test_base;
virtual function void build_phase(uvm_phase phase);
// cfg.init(...); // I cannot do this because cfg hasnt been created yet.
pre_build();
super.build_phase(phase); // execute test base
// cfg.init(...); // I cannot do this because... it's too late. The test base already built the environment.
endfunction
virtual function void pre_build();
// empty ...
// ... or pure virtual if class is abstract
endfunction
//...
endclass
Another thing I like to do is to call randomize() on config stuff even when you know the exact values you want. This way you can always add constraints in sub-classes and use factory overrides to switch them.
class your_config;
function void init():
randomize() with {
soft some_agent_cfg.is_active == UVM_ACTIVE;
}
endfunction
endclass
class your_passive_config extends your_config;
constraint agent_passive {
some_agent_cfg.is_active == UVM_PASSIVE;
}
endclass
your_config::set_type_override(your_passive_config::get_type());