Hi,
I am new to UVM and was trying the set_inst_override_by_type method. the first grandchild object is created using the factory create method, so, I it should be supporting these two overrides as far as I know. When I’m using “set_type_override_by_type” then the code is working as it should and printing “I’m the new grandchild” when e.c1.gc1.display() is called in the report_phase of test class. But when I use set_inst_override_by_type to just override e.c1.gc1, the override is not happening and display function of the grandchild is being called instead of the overriding display function of the newgrandchild class. The same can be seen in the topology that I’m printing in the same reporting phase. I’ve attached my full code which I was trying on EDA playground. Please help me out with this.
import uvm_pkg::*;
`include "uvm_macros.svh"
class grandchild extends uvm_component;
`uvm_component_utils(grandchild)
function new(string name, uvm_component parent);
super.new(name,parent);
`uvm_info("new", "constructor_gc",0)
endfunction
function void build_phase(uvm_phase phase);
`uvm_info("build", "phase_gc",0)
endfunction
function void connect_phase(uvm_phase phase);
`uvm_info("connect", "phase_gc",0)
endfunction
task run_phase(uvm_phase phase);
`uvm_info("run", "phase_gc",0)
endtask
function void report_phase(uvm_phase phase);
`uvm_info("report", "phase_gc",0)
endfunction
virtual function void display();
`uvm_info("DISP","I'm grandchild",0);
endfunction
endclass
class newgrandchild extends grandchild;
`uvm_component_utils(newgrandchild)
function new(string name, uvm_component parent);
super.new(name,parent);
`uvm_info("new", "constructor_ngc",0)
endfunction
function void build_phase(uvm_phase phase);
`uvm_info("build", "phase_ngc",0)
endfunction
function void connect_phase(uvm_phase phase);
`uvm_info("connect", "phase_ngc",0)
endfunction
task run_phase(uvm_phase phase);
`uvm_info("run", "phase_ngc",0)
endtask
function void report_phase(uvm_phase phase);
`uvm_info("report", "phase_ngc",0)
endfunction
virtual function void display();
`uvm_info("DISP","I'm the new grandchild",0);
endfunction
endclass
class child extends uvm_component;
`uvm_component_utils(child)
grandchild gc1,gc2;
function new(string name, uvm_component parent);
super.new(name,parent);
`uvm_info("new", "constructor_c",0)
endfunction
function void build_phase(uvm_phase phase);
`uvm_info("build", "phase_c",0)
gc1 = grandchild::type_id::create("gc1",this);
`uvm_info("build", "created gc1",0)
gc2 = new("gc2",this);
`uvm_info("build", "created gc2",0)
endfunction
function void connect_phase(uvm_phase phase);
`uvm_info("connect", "phase_c",0)
endfunction
task run_phase(uvm_phase phase);
`uvm_info("run", "phase_c",0)
endtask
function void report_phase(uvm_phase phase);
`uvm_info("report", "phase_c",0)
endfunction
endclass
class env extends uvm_env;
`uvm_component_utils(env)
child c1,c2;
function new(string name, uvm_component parent);
super.new(name,parent);
`uvm_info("new", "constructor_e",0)
endfunction
function void build_phase(uvm_phase phase);
`uvm_info("build", "phase_e",0);
set_type_override_by_type(grandchild::get_type(),newgrandchild::get_type()); // --> All instances getting overridden. Working fine.
//set_inst_override_by_type("*.e.c1.gc1",grandchild::get_type(),newgrandchild::get_type()); // --> No instance getting overridden. Not working.
c1 = child::type_id::create("c1",this);
c2 = new("c2",this);
endfunction
function void connect_phase(uvm_phase phase);
`uvm_info("connect", "phase_e",0)
endfunction
task run_phase(uvm_phase phase);
`uvm_info("run", "phase_e",0)
endtask
function void report_phase(uvm_phase phase);
`uvm_info("report", "phase_e",0)
endfunction
endclass : env
class test extends uvm_test;
`uvm_component_utils(test);
function new(string name, uvm_component parent);
super.new(name,parent);
`uvm_info("new", "constructor_t",0)
endfunction
env e;
function void build_phase(uvm_phase phase);
`uvm_info("build", "phase_t",0)
e = new("e",this);
endfunction
function void report_phase(uvm_phase phase);
`uvm_info("report", "phase_t",0)
uvm_top.print();
e.c1.gc1.display();
endfunction // report_phase
endclass
module top;
env e2,e3;
initial begin
e2 = env::type_id::create("e2",null);
e3 = new("e3",e2);
run_test("test");
end
endmodule