Setting and pulling config object for a child component

Lets say I have a component CompA, and object CompA_cfg.

Later I extend both of these:
CompA ->CompB
CompA_cfg->CompB_cfg

Both compA and compB peform a ‘get’ configuration pull in their build_phases.

Assume I want to instantiate my new ‘CompB’ and it’s new config object in the env.

Is it possible to satisfy those configuration pulls by doing a SINGLE configuration set in the environment?

CompB my_comp;

task build_phase();
  uvm_config_db #( CompB_cfg )::set( this, my_comp, "cfg", cfg.compb_cfg_obj ); <----
endtask

This satisfies the child component, but the parent (compA) can no longer find it’s configuration in the database.
If I want it to work, I also have to add this to build_phase:

uvm_config_db #( CompA_cfg )::set( this, my_comp, "cfg", cfg.compb_cfg_obj );

In reply to bmorris:

You can have a single set() by doing

uvm_config_db #( CompA_cfg )::set( this, my_comp, "cfg", cfg.compb_cfg_obj ); <----

You can have a single get() in your CompA base clase, but CompB will need $cast the object to CompB_cfg variable.

Also, you should not be constructing both CompA_cfg and CompB_cfg objects. Use the factory to override the cfg object creation.

BTW, I’ve said many times before, I wish people would stop using “child” to refer to an extended class.

In reply to dave_59:

"You can have a single get() in your CompA base clase, but CompB will need $cast the object to CompB_cfg variable. "

Got it. Thanks.

"Also, you should not be constructing both CompA_cfg and CompB_cfg objects. Use the factory to override the cfg object creation. "

I don’t currently construct both, just CompB_cfg. I see what you mean though. I could, in my env config have CompA_cfg instead. Then, in my test do an override, build env, then cast cfg.comp_cfg to compB_cfg. Then I can configure the additional properties of the extension.

I implemented the factory and casting technique, and finally got that working. That having been said…

I have a test base class I use that looks like:

virtual class test_BASE #(type ENV_TYPE=int, CFG_TYPE=int) extends uvm_test ;

  ENV_TYPE env;   <------
  CFG_TYPE cfg;   <------

  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction

  function void build_phase(uvm_phase phase);
    // ...
  endfunction

  //...

endclass

This is my only class I don’t modify using the factory; it uses parameters. I did this because I can’t “create” the ‘cfc’ and ‘env’ objects if they are types uvm_component, and uvm_object.
Furthermore, I’d have to do an ‘instance’ override with a static path name in a test_BASE extension.

Thoughts?