Setting using uvm_config_db

I am trying to set values in my test class to different env instances using uvm_config_db.
But the output is coming as 0 for both instances.
The code is quoted below. What changes do I have to make to get expected output ?

Obsreved output is,
**# UVM_INFO @ 0: reporter [RNTST] Running test test…

UVM_INFO .\db_problem.sv(23) @ 0: uvm_test_top.ENV1 [ENV1] VALUE = 0

UVM_INFO .\db_problem.sv(23) @ 0: uvm_test_top.ENV2 [ENV2] VALUE = 0**

Expected output is,
**# UVM_INFO @ 0: reporter [RNTST] Running test test…

UVM_INFO .\db_problem.sv(23) @ 0: uvm_test_top.ENV1 [ENV1] VALUE = 10

UVM_INFO .\db_problem.sv(23) @ 0: uvm_test_top.ENV2 [ENV2] VALUE = 20**

`include "uvm_macros.svh"
import uvm_pkg::*;

class env extends uvm_env;

    `uvm_component_utils(env)
    
    function new(string name, uvm_component parent);
        super.new(name, parent);    
    endfunction //new()

    int value;

    virtual function void build_phase(uvm_phase phase);
        super.build_phase(phase);

        uvm_config_db#(int) :: get(this,"","value",value);

        `uvm_info(get_name(), $sformatf("VALUE = %d", value), UVM_NONE)
    endfunction
endclass //env

class test extends uvm_test;

    `uvm_component_utils(test)
    
    function new(string name, uvm_component parent);
        super.new(name, parent);    
    endfunction //new()

    env E1,E2;

    virtual function void build_phase(uvm_phase phase);
        super.build_phase(phase);

        E1 = env::type_id::create("ENV1",this);
        E2 = env::type_id::create("ENV2",this);

        //Setting value = 10 for env1 E1 
        uvm_config_db#(int) :: set(this,".E1","value",10);
        
        //Setting value = 20 for env2 E2
        uvm_config_db#(int) :: set(this,".E2","value",20);
    endfunction

endclass //agent2 extends uvm_agent

module tb;
    initial begin
        run_test("test");
    end
endmodule

In reply to bachan21:

Several comments:

  • You should always check the return value of the get() call.
  • Your component names passed in create() are what is used during the get() call. They should match the names in the set() call.
  • You should always set() prior to create().
  • Don’t use a ‘.’ in the set() call hierarchy.

`include "uvm_macros.svh"
import uvm_pkg::*;
 
class env extends uvm_env;
 
    `uvm_component_utils(env)
 
    function new(string name, uvm_component parent);
        super.new(name, parent);    
    endfunction //new()
 
    int value;
 
    virtual function void build_phase(uvm_phase phase);
        super.build_phase(phase);
 
      if (!uvm_config_db#(int) :: get(this,"","value",value))
        `uvm_fatal("ERRGET", "Can't get a valid value");
 
      `uvm_info(get_name(), $sformatf("VALUE = %d", value), UVM_NONE)
    endfunction
endclass //env
 
class test extends uvm_test;
 
    `uvm_component_utils(test)
 
    function new(string name, uvm_component parent);
        super.new(name, parent);    
    endfunction //new()
 
    env E1,E2;
 
    virtual function void build_phase(uvm_phase phase);
        super.build_phase(phase);

        //Setting value = 10 for env1 E1 
        uvm_config_db#(int)::set(this,"E1","value",10);
 
        //Setting value = 20 for env2 E2
        uvm_config_db#(int)::set(this,"E2","value",20);
 
        E1 = env::type_id::create("E1",this);
        E2 = env::type_id::create("E2",this);
     endfunction
 
endclass //agent2 extends uvm_agent
 
module tb;
    initial begin
        run_test("test");
    end
endmodule

In reply to cgales:

Thanks cgales
The code is working as per the intention.