Uvm_config_db set and get method

In reply to Boogeyman:

Your problem is mixing up parent/child relationships with inheritance. You also have terrible choices for class names. Better to just be A (for object) and B (for object_child).

my_test creates an B instance ob_ch that is completely separate from the A instance ob created by base_test. The A handle stored in ob is what gets stored the uvm_config_db, not B handle in ob_ch. You only need one class instance.

There are a couple of approaches you could take.

Normally one uses a factory override to have base_test create an B instance instead of a A instance.

function void my_test::build_phase(uvm_phase phase);
   set_type_override_by_type(A::get_type(), B::get_type()) ;
   super.build_phase(phase);
endfunction : build_phase
function void base_test::build_phase(uvm_phase phase);
 
  ob = A::type_id::create("ob");
  ob.randomize with {rand_en == 0;};
  uvm_config_db#(object)::set(null,"*","obj",ob);

endfunction

Now there is only one object created, and one call to randomize, and only one object set into the uvm_config_db. But you have a problem with the with {rand_en == 0;} constraint in that it conflicts with the constraint added by the B class. That might not be a real problem if this example is contrived. But you can work around that by not having the my_test::build_phase call super.build().

function void my_test::build_phase(uvm_phase phase);
 
  ob = B::type_id::create("ob"); // ob is declared in base_test
  if(!ob.randomize()) `uvm_error()
  uvm_config_db#(object)::set(null,"*","obj",ob);

endfunction