I have a int variable which I get inside an block environment configuration object. This basically gets the number of agents to create.
if (!uvm_config_db#(int)::get(null, get_full_name(), "num_agt", num_agt))
begin
num_agt = `NUM_AGT;
`uvm_info($psprintf("%s_WARNING", get_type_name()), $psprintf("num_agt setting is not found in config_db! Setting default value of %0d\n", num_agt), UVM_HIGH);
end
From the top base test, I am trying to set this int variable before creating this environment configuration, so that based on the value set, within the environment configuration, I do some agent configuration creation. Within this top_env_cfg, I create the other block_env_cfg.
So only was trying to set the value of num_agts targeting specifically inside the each block_env_cfg with different values.
But somehow during the get, its missing or not sure if its missing searching for that complete string path for the value. Wondering if am I making any error in the get as well?
One of the main purposes of the test is to create and configure all of the configuration objects for your environment(s) and the sub-agent(s) of the environment(s). Every configuration variable of these objects should be set by the test, and the configuration objects passed to the environment(s) using the config_db().
I don’t understand why you would create a configuration object, then try to use the config_db() to get a variable inside the configuration object from the config_db(). Just use the test and set each variable appropriately.
In your example, why would you try and pass num_agents using the config_db() instead of just setting the variable in the environment(s) config object(s) directly?
Thanks for going over the post and responding back.
Have like a two way mechanism, i.e. top_env_cfg gets created in the top_test, it also creates the block_env_cfgs. So, when the block_env_cfg gets created, during the new process I check if there is any “num_agts” being set via the config_db else it uses a default value using `NUM_AGTS set in the defines.
After getting the default value of num_agts while it gets created, I also call a function which configures the num_agts, then the agent_cfgs and its default setup on the fly. Code excerpts as given below.
class block_env_configuration;
...
function new();
...
if (!uvm_config_db#(int)::get(null, get_full_name(), "num_agt", num_agt))
begin
num_agt = `NUM_AGT;
`uvm_info($psprintf("%s_WARNING", get_type_name()), $psprintf("num_agt setting is not found in config_db! Setting default value of %0d\n", num_agt), UVM_HIGH);
end
...
// calling agt setup
cfg_agts(num_agt);
endfunction: new
function cfg_agts(num_agt);
blk_agt_cfg = new[num_agt];
...
endfunction: cfg_agts
...
endclass: block_env_configuration
So that way, either the user can set the num_agts via config_db before the block_env_cfg is created or they can set the num_agts via the defines Or else, they can specifically call the cfg_agts function to set the num_agts and configure.
block_env_cfg.cfg_agts(2);
Say if the block_env is being used at multiple places [i.e. within multiple sub_envs], then I can set different values via the config_db to the particular block_env_cfg instead of calling the function cfg_agts. That’s the reason why I was trying to get the num_agts via config_db.
But your recommendation is to individually set the variables in the test and configure them right? Let me know which would be the best way. Thanks again !
As I stated, the best method is to set the configuration variables in the test. You are wasting resources in the config_db() by setting a value and then immediately reading it back at the same level of hierarchy. Just set the value in the configuration object directly.
Also, don’t use `defines to configure default values. The default values should be parameters in your test package.
I recommend defining a configuration_function() in the base test class that creates the top level environment configuration containing all the environment parameters, sub-environment configurations and agent configurations. It will put this single configuration object into the config_db() for the environment to retrieve during the build_phase.
By using a configuration_function, you allow your tests extended from the base_test to create their own configuration objects that vary based on the test.
class block_env_configuration extends uvm_object;
rand int unsigned num_agt;
agent_cfg blk_agt_cfg[];
constraint num_agt_c {num_agt inside {[1:MAX_AGENTS]};};
function new(string name="block_env_configuration");
super.new(name);
endfunction: new
function void post_randomize();
cfg_agents(num_agt);
endfunction
function cfg_agts(int unsigned num_agt_);
num_agt = num_agt_;
blk_agt_cfg = new[num_agt];
foreach(blk_agt_cfg[i]) begin
blk_agt_cfg[i] = agent_cfg::type_id::create($sformatf("blk_agt_cfg[%0d]", i));
end
endfunction: cfg_agts
endclass: block_env_configuration