Uvm_config_db set from module, get from testcase?

In reply to jwatt_f:

A quick addition to the answer above .


uvm_config_db#(data_type)::set(null, "uvm_test_top", "DATA_NAME", data_handle); 

This will work in 99% of the cases where either ::

(1) String Argument is provided to run_test in top_tb and No run-time argument of +UVM_TESTNAME=user_test

(2) Run-time argument of +UVM_TESTNAME=user_test is provided

However if the component / test ( where the config_db::get is being fetched ) is explicitly created before call to run_test


   initial  begin
     
     //  No  "uvm_test_top"  as  2nd  argument  !!

     uvm_config_db#(data_type)::set(null, "user_comp_h" , "DATA_NAME", data_handle);

     user_comp_h =  user_comp :: type_id :: create("user_comp_h" , null); 
    
     //  Could  even  set  after  creating  user_comp  as  Phasing  would  start  after  call  to  run_test()
    //  uvm_config_db#(data_type)::set(null, "user_comp_h", "DATA_NAME", data_handle);

     run_test() ;

   end

  //   Assume  run - time  argument  of  +UVM_TESTNAME=user_test  is  provided


Now if the config::get is required in user_comp ::


  //  In  user_comp's  build_phase() ::
  
  if (!uvm_config_db#(data_type)::get(this, "", "DATA_NAME", data_handle))
  `uvm_error(get_full_name(), "Unable to get DATA_NAME");