I have a requirement which need to override a uvm_object in uvm based test-bench.
`include "uvm_macros.svh"
import uvm_pkg::*;
class config_0 extends uvm_object;
int number_of_axi = 0;
`uvm_object_utils(config_0)
function new(string name = "config_0");
super.new(name);
//`uvm_info("cfg","config-0 created",UVM_LOW)
endfunction
endclass
class config_1 extends config_0;
int number_of_axi = 1;
`uvm_object_utils(config_1)
function new(string name = "config_1");
super.new(name);
//`uvm_info("cfg","config-1 created",UVM_LOW)
endfunction
endclass
class config_2 extends config_0;
int number_of_axi = 2;
`uvm_object_utils(config_2)
function new(string name = "config_2");
super.new(name);
//`uvm_info("cfg","config-2 created",UVM_LOW)
endfunction
endclass
class agent extends uvm_agent;
config_0 cfg;
`uvm_component_utils(agent)
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction : new
function void build_phase(uvm_phase phase);
super.build_phase(phase);
cfg = config_0::type_id::create("cfg",this);
`uvm_info("cfg_value_print_in_agt",$sformatf("cfg.number_of_axi = %0d",cfg.number_of_axi),UVM_LOW)
endfunction
endclass
class mem_model_env extends uvm_env;
config_0 cfg;
agent agt;
`uvm_component_utils(mem_model_env)
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction : new
function void build_phase(uvm_phase phase);
super.build_phase(phase);
cfg = config_0::type_id::create("cfg");
agt = agent::type_id::create("cfg",this);
if(!uvm_config_db #(config_0)::get(this, "*", "cfg_i", cfg))
`uvm_error("ERROR","not geting cfg")
`uvm_info("cfg_value_print",$sformatf("cfg.number_of_axi = %0d",cfg.number_of_axi),UVM_LOW)
endfunction : build_phase
endclass : mem_model_env
class top_env extends uvm_env;
config_0 cfg0;
config_1 cfg1;
config_2 cfg2;
mem_model_env env[3];
uvm_factory factory;
`uvm_component_utils(top_env)
function new(string name = "top_env", uvm_component parent);
super.new(name,parent);
factory = uvm_factory::get();
set_inst_override_by_type("env[0].cfg",config_0::get_type(),config_1::get_type());
set_inst_override_by_type("env[1].cfg",config_0::get_type(),config_1::get_type());
set_inst_override_by_type("env[2].cfg",config_0::get_type(),config_2::get_type());
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
factory = uvm_factory::get();
cfg1 = config_1::type_id::create("cfg1");
cfg2 = config_2::type_id::create("cfg2");
uvm_config_db #(config_1)::set(this, "*.env[0]*", "cfg_i", cfg1);
uvm_config_db #(config_1)::set(this, "*.env[1]*", "cfg_i", cfg1);
uvm_config_db #(config_2)::set(this, "*.env[2]*", "cfg_i", cfg2);
factory.print();
foreach(env[i]) begin
env[i] = mem_model_env::type_id::create($sformatf("env[%0d]",i),this);
end
endfunction: build_phase
endclass
class base_test extends uvm_test;
top_env env;
`uvm_component_utils(base_test)
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
env = top_env::type_id::create("env",this);
endfunction
endclass
module test;
initial begin
run_test("base_test");
end
endmodule
When I follow above code I get 0 value in `uvm_info(“cfg_value_print”,$sformatf(“cfg.number_of_axi = %0d”,cfg.number_of_axi),UVM_LOW) (at mem_model_env build_phase). I want to get value from top_env which I set using config_db. If any one know to to do that please provide a solution for that.
Thanks.