How to obtain cfg from lower hierarchy?

Hi,

I am new to UVM. Hopefully some of the experts here could help me with this,

I have the following code:



class my_env extends uvm_env;

cfg cfg1;
env env1;

virtual function void build_phase(uvm_phase phase);
cfg1 = cfg::type_id::create("cfg1",this);
env1 = cfg::type_id::create("env1",this);
uvm_config_db#(cfg)::set(this,"env1",c_cfg,this.cfg1);
endfunction

endclass


class my_test extends uvm_test;

my_env my_env1;
cfg cfg1;

virtual function void build_phase(uvm_phase phase);
my_env1 = my_env::type_id::create("my_env1",this);
cfg1 = cfg::type_id::create("cfg1",this);
endfunction

endclass


How do I make, my_env1.cfg1 to be visible and to be same as my_test.cfg1? (i.e whenever lower levels make changes to my_env1.cfg1, it will also be reflected on my_test.cfg1, or whenever the code within my_test writes to my_test.cfg1, it will also be reflected in my_env1.cfg1?

In reply to EE:

If you want to pass a configuration object from your env to the test you do not need the config_db, because there is a well-defined relationship between test and env.

In my_test you can simply write:

class my_test extends uvm_test;
 
my_env my_env1;
cfg cfg1;
 
virtual function void build_phase(uvm_phase phase);
  my_env1 = my_env::type_id::create("my_env1",this);
  cfg1 = my_env1.cfg1;
endfunction

In reply to EE:

Handle assignment will not work in build_phase() due to its top-down nature unless “cfg” is created in constructor of “env”. Or use above solution by chr_sue in connect_phase() of testcase.

You can also use configuration setting with these options,

virtual function void build_phase(uvm_phase phase);
  cfg1 = cfg::type_id::create("cfg1",this);
  uvm_config_db#(cfg)::set(null, "*", "c_cfg", this.cfg1); // Can get from any scope
  //Or
  uvm_config_db#(cfg)::set(uvm_root::get(), "*", "c_cfg", this.cfg1); // Can get from any scope
endfunction

In reply to MayurKubavat:

In reply to EE:
Handle assignment will not work in build_phase() due to its top-down nature unless “cfg” is created in constructor of “env”. Or use above solution by chr_sue in connect_phase() of testcase.

The assignmaent has been made after the construction of the env, i.e. the cfg object of the env is available.

In reply to MayurKubavat:

Hi MayurKubavat,

Your suggestion means that I should update the build_phase within my_env?
Then, does this mean, in my_test, I should use uvm_config_db get with the same label?

For example:



class my_env extends uvm_env;
 
cfg cfg1;
env env1;
 
virtual function void build_phase(uvm_phase phase);
cfg1 = cfg::type_id::create("cfg1",this);
env1 = cfg::type_id::create("env1",this);
uvm_config_db#(cfg)::set(uvm_root::get(), "*", "c_cfg", this.cfg1);
endfunction
 
endclass


class my_test extends uvm_test;
 
my_env my_env1;
cfg cfg1;
 
virtual function void build_phase(uvm_phase phase);
my_env1 = my_env::type_id::create("my_env1",this);
cfg1 = cfg::type_id::create("cfg1",this);
uvm_config_db#(cfg)::get(null, "*", "c_cfg", this.cfg1); 
endfunction
 
endclass


Your comments are greatly appreciated. Thanks!

In reply to EE:

If you do not say which configuration data you have in your config obejct there is no common answer. Configuration data influencing the generation of your testbenchave to be handled differently as configuration data with respect to sequences etc.

And there is another basic question: what is the reason you want to move-up configuration data from your env to your test. The objective of a test is to confiure your testbench, including your env in such a way you can verify a cerrtain functionality and not vice versa.