Tutorials
Learn More
Instance Override in UVM factory
Unlike type override does override all instances of the type, instance override does override only specified positions in the uvm component hierarchy.
Methods of instance override in UVM factory
- set_inst_override_by_type
- set_inst_override_by_name
Syntax for set_inst_override_by_type
function void set_inst_override_by_type (uvm_object_wrapper original_type,
uvm_object_wrapper override_type,
string full_inst_path)
Syntax for set_inst_override_by_name
function void set_inst_override_by_name (string original_type_name,
string override_type_name,
string full_inst_path)
Example with set_inst_override_by_type
class component_A extends uvm_component;
`uvm_component_utils(component_A)
function new(string name = "component_A", uvm_component parent = null);
super.new(name, parent);
endfunction
virtual function display();
`uvm_info(get_type_name(), $sformatf("inside component_A"), UVM_LOW);
endfunction
endclass
class component_B extends component_A;
`uvm_component_utils(component_B)
function new(string name = "component_B", uvm_component parent = null);
super.new(name, parent);
endfunction
function display();
`uvm_info(get_type_name(), "inside component_B", UVM_LOW);
endfunction
endclass
class my_test extends uvm_test;
`uvm_component_utils(my_test)
component_A comp_A;
function new(string name = "my_test", uvm_component parent = null);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
uvm_factory factory = uvm_factory::get();
super.build_phase(phase);
set_inst_override_by_type("*", component_A::get_type(), component_B::get_type());
comp_A = component_A::type_id::create("comp_A", this);
factory.print();
endfunction
function void end_of_elaboration_phase(uvm_phase phase);
super.end_of_elaboration_phase(phase);
uvm_top.print_topology();
endfunction
task run_phase(uvm_phase phase);
super.run_phase(phase);
comp_A.display();
endtask
endclass
module tb_top;
initial begin
run_test("my_test");
end
endmodule
Output:
#### Factory Configuration (*)
Instance Overrides:
Requested Type Override Path Override Type
-------------- -------------- -------------
component_A uvm_test_top.* component_B
No type overrides are registered with this factory
All types registered with the factory: 55 total
Type Name
---------
component_A
component_B
my_test
snps_uvm_reg_bank_group
snps_uvm_reg_map
(*) Types with no associated type name will be printed as <unknown>
####
UVM_INFO /apps/vcsmx/vcs/Q-2020.03-SP1-1//etc/uvm-1.2/src/base/uvm_root.svh(675) @ 0: reporter [UVMTOP] UVM testbench topology:
--------------------------------------
Name Type Size Value
--------------------------------------
uvm_test_top my_test - @336
comp_A component_B - @349
--------------------------------------
UVM_INFO testbench.sv(26) @ 0: uvm_test_top.comp_A [component_B] inside component_B
Example with set_inst_override_by_name
class component_A extends uvm_component;
`uvm_component_utils(component_A)
function new(string name = "component_A", uvm_component parent = null);
super.new(name, parent);
endfunction
virtual function display();
`uvm_info(get_type_name(), $sformatf("inside component_A"), UVM_LOW);
endfunction
endclass
class component_B extends component_A;
`uvm_component_utils(component_B)
function new(string name = "component_B", uvm_component parent = null);
super.new(name, parent);
endfunction
function display();
`uvm_info(get_type_name(), "inside component_B", UVM_LOW);
endfunction
endclass
class my_test extends uvm_test;
`uvm_component_utils(my_test)
component_A comp_A;
function new(string name = "my_test", uvm_component parent = null);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
uvm_factory factory = uvm_factory::get();
super.build_phase(phase);
factory.set_inst_override_by_name("component_A", "component_B", "*");
comp_A = component_A::type_id::create("comp_A", this);
factory.print();
endfunction
function void end_of_elaboration_phase(uvm_phase phase);
super.end_of_elaboration_phase(phase);
uvm_top.print_topology();
endfunction
task run_phase(uvm_phase phase);
super.run_phase(phase);
comp_A.display();
endtask
endclass
module tb_top;
initial begin
run_test("my_test");
end
endmodule
Output:
#### Factory Configuration (*)
Instance Overrides:
Requested Type Override Path Override Type
-------------- ------------- -------------
component_A * component_B
No type overrides are registered with this factory
All types registered with the factory: 53 total
Type Name
---------
component_A
component_B
my_test
(*) Types with no associated type name will be printed as <unknown>
####
UVM_INFO /xcelium20.09/tools//methodology/UVM/CDNS-1.2/sv/src/base/uvm_root.svh(605) @ 0: reporter [UVMTOP] UVM testbench topology:
--------------------------------------
Name Type Size Value
--------------------------------------
uvm_test_top my_test - @1807
comp_A component_B - @1883
--------------------------------------
UVM_INFO testbench.sv(26) @ 0: uvm_test_top.comp_A [component_B] inside component_B
There are also similar two methods used that behave similarly as mentioned above.
- set_type_override
- set_inst_override
set_type_override and set_inst_override Methods
Syntax for set_type_override
<original_type>::type_id::set_type_override(<substitute_type>::get_type(),
replace);
Syntax for set_inst_override
<original_type>::type_id::set_inst_override(<substitute_type>::get_type(),
<path_string>);
Example with set_type_override
class component_A extends uvm_component;
`uvm_component_utils(component_A)
function new(string name = "component_A", uvm_component parent = null);
super.new(name, parent);
endfunction
virtual function display();
`uvm_info(get_type_name(), $sformatf("inside component_A"), UVM_LOW);
endfunction
endclass
class component_B extends component_A;
`uvm_component_utils(component_B)
function new(string name = "component_B", uvm_component parent = null);
super.new(name, parent);
endfunction
function display();
`uvm_info(get_type_name(), "inside component_B", UVM_LOW);
endfunction
endclass
class my_test extends uvm_test;
`uvm_component_utils(my_test)
component_A comp_A;
function new(string name = "my_test", uvm_component parent = null);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
uvm_factory factory = uvm_factory::get();
super.build_phase(phase);
component_A::type_id::set_type_override(component_B::get_type());
comp_A = component_A::type_id::create("comp_A", this);
factory.print();
endfunction
function void end_of_elaboration_phase(uvm_phase phase);
super.end_of_elaboration_phase(phase);
uvm_top.print_topology();
endfunction
task run_phase(uvm_phase phase);
super.run_phase(phase);
comp_A.display();
endtask
endclass
module tb_top;
initial begin
run_test("my_test");
end
endmodule
Output:
#### Factory Configuration (*)
No instance overrides are registered with this factory
Type Overrides:
Requested Type Override Type
-------------- -------------
component_A component_B
All types registered with the factory: 53 total
Type Name
---------
component_A
component_B
my_test
(*) Types with no associated type name will be printed as <unknown>
####
UVM_INFO /xcelium20.09/tools//methodology/UVM/CDNS-1.2/sv/src/base/uvm_root.svh(605) @ 0: reporter [UVMTOP] UVM testbench topology:
--------------------------------------
Name Type Size Value
--------------------------------------
uvm_test_top my_test - @1807
comp_A component_B - @1876
--------------------------------------
UVM_INFO testbench.sv(26) @ 0: uvm_test_top.comp_A [component_B] inside component_B
Example with set_inst_override
class component_A extends uvm_component;
`uvm_component_utils(component_A)
function new(string name = "component_A", uvm_component parent = null);
super.new(name, parent);
endfunction
virtual function display();
`uvm_info(get_type_name(), $sformatf("inside component_A"), UVM_LOW);
endfunction
endclass
class component_B extends component_A;
`uvm_component_utils(component_B)
function new(string name = "component_B", uvm_component parent = null);
super.new(name, parent);
endfunction
function display();
`uvm_info(get_type_name(), "inside component_B", UVM_LOW);
endfunction
endclass
class my_test extends uvm_test;
`uvm_component_utils(my_test)
component_A comp_A;
function new(string name = "my_test", uvm_component parent = null);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
uvm_factory factory = uvm_factory::get();
super.build_phase(phase);
component_A::type_id::set_inst_override(component_B::get_type(), "*");
comp_A = component_A::type_id::create("comp_A", this);
factory.print();
endfunction
function void end_of_elaboration_phase(uvm_phase phase);
super.end_of_elaboration_phase(phase);
uvm_top.print_topology();
endfunction
task run_phase(uvm_phase phase);
super.run_phase(phase);
comp_A.display();
endtask
endclass
module tb_top;
initial begin
run_test("my_test");
end
endmodule
Output:
#### Factory Configuration (*)
Instance Overrides:
Requested Type Override Path Override Type
-------------- ------------- -------------
component_A * component_B
No type overrides are registered with this factory
All types registered with the factory: 53 total
Type Name
---------
component_A
component_B
my_test
(*) Types with no associated type name will be printed as <unknown>
####
UVM_INFO /xcelium20.09/tools//methodology/UVM/CDNS-1.2/sv/src/base/uvm_root.svh(605) @ 0: reporter [UVMTOP] UVM testbench topology:
--------------------------------------
Name Type Size Value
--------------------------------------
uvm_test_top my_test - @1807
comp_A component_B - @1881
--------------------------------------
UVM_INFO testbench.sv(26) @ 0: uvm_test_top.comp_A [component_B] inside component_B
UVM Tutorials