Override in UVM Using Factory With Example
Override in UVM Using Factory With Example
I am a Verification Engineer at Cadence Design System. I started the Verification blog to store
solutions to small (and big) problems I've faced in my day to day work. I want to share them
with the community in the hope that they may be useful to someone else.
One of the main advantage of UVM is Creating each components using factory enables them to
be overridden in different tests or environments without changing underlying code base.
uvm_factory provides four different methods to override particular instance or all instances of
particular class.
set_inst_override_by_type
set_inst_override_by_name
set_type_override_by_type
set_type_override_by_name
set_inst_override_by_type
-------------------------------------------------------
// set_inst_override_by_type
`include "uvm.svh"
import uvm_pkg::*;
//--------------------uvm_component------------------------------
class A extends uvm_agent;
`uvm_component_utils(A)
function hello();
`uvm_info(get_full_name, $sformatf("HELLO from override class 'A_ovr'"), UVM_LOW);
endfunction : hello
endclass : A_ovr
//--------------------uvm_object------------------------------
class B extends uvm_object;
`uvm_object_utils(B)
function hello();
`uvm_info(get_full_name, $sformatf("HELLO from override class 'B_ovr'"), UVM_LOW);
endfunction : hello
endclass : B_ovr
function hello();
`uvm_info(get_full_name, $sformatf("HELLO from override class 'B_override'"), UVM_LOW);
endfunction : hello
endclass : B_override
//--------------------env class--------------------
class environment extends uvm_env;
`uvm_component_utils(environment)
A a1;
B b1, b2;
//-------------------test class--------------------------
class test extends uvm_test;
`uvm_component_utils(test)
environment env;
module top();
initial begin
run_test("test");
end
endmodule : top
view raw set_instance_override_by_type.sv hosted with by GitHub
-------------------------------------------------------
-------------------------------------------------------
//Output:
// UVM_INFO @ 0: reporter [RNTST] Running test test...
// UVM_INFO top.sv(118) @ 0: uvm_test_top [uvm_test_top] TEST set_inst_override_by_type
//
// #### Factory Configuration (*)
// Instance Overrides:
// Requested Type Override Path Override Type
// -------------- ------------------- -------------
// A uvm_test_top.env.a1 A_ovr
// B path1.b1 B_ovr
// B path2.b2 B_override
//
// No type overrides are registered with this factory
//
// All types registered with the factory: 45 total
// (types without type names will not be printed)
// Type Name
// ---------
// A
// A_ovr
// B
// B_override
// B_ovr
// environment
// test
// (*) Types with no associated type name will be printed as <unknown>
// ####
//
// UVM_INFO top.sv(15) @ 0: uvm_test_top.env.a1 [uvm_test_top.env.a1] A new
// UVM_INFO top.sv(28) @ 0: uvm_test_top.env.a1 [uvm_test_top.env.a1] A_ovr new
// UVM_INFO top.sv(42) @ 0: reporter [B_ovr] B new
// UVM_INFO top.sv(55) @ 0: reporter [B_ovr] B_ovr new
// UVM_INFO top.sv(42) @ 0: reporter [B_override] B new
// UVM_INFO top.sv(55) @ 0: reporter [B_override] B_ovr new
// UVM_INFO top.sv(68) @ 0: reporter [B_override] B_override new
// UVM_INFO top.sv(32) @ 0: uvm_test_top.env.a1 [uvm_test_top.env.a1] HELLO from
override class 'A_ovr'
// UVM_INFO top.sv(59) @ 0: reporter [b1] HELLO from override class 'B_ovr'
// UVM_INFO top.sv(72) @ 0: reporter [b2] HELLO from override class 'B_override'
view raw set_instance_override_by_type_op.sv hosted with by GitHub
-------------------------------------------------------
set_inst_override_by_name
-------------------------------------------------------
// set_inst_override_by_name
`include "uvm.svh"
import uvm_pkg::*;
//--------------------uvm_component------------------------------
class A extends uvm_agent;
`uvm_component_utils(A)
function hello();
`uvm_info(get_full_name, $sformatf("HELLO from override class 'A_ovr'"), UVM_LOW);
endfunction : hello
endclass : A_ovr
//--------------------uvm_object------------------------------
class B extends uvm_object;
`uvm_object_utils(B)
function hello();
`uvm_info(get_full_name, $sformatf("HELLO from override class 'B_ovr'"), UVM_LOW);
endfunction : hello
endclass : B_ovr
function hello();
`uvm_info(get_full_name, $sformatf("HELLO from override class 'B_override'"), UVM_LOW);
endfunction : hello
endclass : B_override
//--------------------env class--------------------
class environment extends uvm_env;
`uvm_component_utils(environment)
A a1;
B b1, b2;
//-------------------test class--------------------------
class test extends uvm_test;
`uvm_component_utils(test)
environment env;
module top();
initial begin
run_test("test");
end
endmodule : top
view raw set_instance_override_by_name.sv hosted with by GitHub
-------------------------------------------------------
-------------------------------------------------------
//Output:
// UVM_INFO @ 0: reporter [RNTST] Running test test...
// UVM_INFO top.sv(118) @ 0: uvm_test_top [uvm_test_top] TEST
set_inst_override_by_name
//
// #### Factory Configuration (*)
// Instance Overrides:
// Requested Type Override Path Override Type
// -------------- ------------------- -------------
// A uvm_test_top.env.a1 A_ovr
// B path1.b1 B_ovr
// B path2.b2 B_override
//
// No type overrides are registered with this factory
//
// All types registered with the factory: 45 total
// (types without type names will not be printed)
// Type Name
// ---------
// A
// A_ovr
// B
// B_override
// B_ovr
// environment
// test
// (*) Types with no associated type name will be printed as <unknown>
// ####
//
// UVM_INFO top.sv(15) @ 0: uvm_test_top.env.a1 [uvm_test_top.env.a1] A new
// UVM_INFO top.sv(28) @ 0: uvm_test_top.env.a1 [uvm_test_top.env.a1] A_ovr new
// UVM_INFO top.sv(42) @ 0: reporter [B_ovr] B new
// UVM_INFO top.sv(55) @ 0: reporter [B_ovr] B_ovr new
// UVM_INFO top.sv(42) @ 0: reporter [B_override] B new
// UVM_INFO top.sv(55) @ 0: reporter [B_override] B_ovr new
// UVM_INFO top.sv(68) @ 0: reporter [B_override] B_override new
// UVM_INFO top.sv(32) @ 0: uvm_test_top.env.a1 [uvm_test_top.env.a1] HELLO from
override class 'A_ovr'
// UVM_INFO top.sv(59) @ 0: reporter [b1] HELLO from override class 'B_ovr'
// UVM_INFO top.sv(72) @ 0: reporter [b2] HELLO from override class 'B_override'
view raw set_instance_override_by_name_op.sv hosted with by GitHub
-------------------------------------------------------
set_type_override_by_type
-------------------------------------------------------
// set_type_override_by_type
`include "uvm.svh"
import uvm_pkg::*;
//--------------------uvm_component------------------------------
class A extends uvm_agent;
`uvm_component_utils(A)
//--------------------uvm_object------------------------------
class B extends uvm_object;
`uvm_object_utils(B)
//--------------------env class--------------------
class environment extends uvm_env;
`uvm_component_utils(environment)
A a1;
B b1, b2;
module top();
initial begin
run_test("test");
end
endmodule : top
view raw set_type_override_by_type.sv hosted with by GitHub
-------------------------------------------------------
-------------------------------------------------------
//Output:
UVM_INFO @ 0: reporter [RNTST] Running test test...
UVM_INFO testbench.sv(109) @ 0: uvm_test_top [uvm_test_top] TEST
set_inst_override_by_name
#### Factory Configuration (*)
Type Overrides:
Type Name
---------
A
A_ovr
B
B_override
B_ovr
environment
snps_uvm_reg_bank_group
snps_uvm_reg_map
test
(*) Types with no associated type name will be printed as <unknown>
####
-------------------------------------------------------
set_type_override_by_name
-------------------------------------------------------
// set_type_override_by_name
`include "uvm.svh"
import uvm_pkg::*;
//--------------------uvm_component------------------------------
class A extends uvm_agent;
`uvm_component_utils(A)
//--------------------uvm_object------------------------------
class B extends uvm_object;
`uvm_object_utils(B)
//--------------------env class--------------------
class environment extends uvm_env;
`uvm_component_utils(environment)
A a1;
B b1, b2;
B_ovr b3;
//-------------------test class--------------------------
class test extends uvm_test;
`uvm_component_utils(test)
environment env;
-------------------------------------------------------
-------------------------------------------------------
//Output:
UVM_INFO @ 0: reporter [RNTST] Running test test...
UVM_INFO testbench.sv(117) @ 0: uvm_test_top [uvm_test_top] TEST
set_inst_override_by_name
Type Overrides:
Type Name
---------
A
A_ovr
B
B_override
B_ovr
environment
snps_uvm_reg_bank_group
snps_uvm_reg_map
test
(*) Types with no associated type name will be printed as <unknown>
####
-------------------------------------------------------
-------------------------------------------------------
// set_inst_override_* hase high priority than set_type_override_*
`include "uvm.svh"
import uvm_pkg::*;
//--------------------uvm_component------------------------------
class A extends uvm_agent;
`uvm_component_utils(A)
//--------------------uvm_object------------------------------
class B extends uvm_object;
`uvm_object_utils(B)
//--------------------env class--------------------
class environment extends uvm_env;
`uvm_component_utils(environment)
A a1, a2, a3;
B b1, b2, b3;
a1 = A::type_id::create("a1", this);
a2 = A::type_id::create("a2", this);
a3 = A::type_id::create("a3", this);
b1 = B::type_id::create("b1", , "path1");
b2 = B::type_id::create("b2", , "path2");
b3 = B::type_id::create("b3", , "path3");
//-------------------test class--------------------------
class test extends uvm_test;
`uvm_component_utils(test)
environment env;
module top();
initial begin
run_test("test");
end
endmodule : top
view raw override_precedence.sv hosted with by GitHub
-------------------------------------------------------
-------------------------------------------------------
//Output:
UVM_INFO @ 0: reporter [RNTST] Running test test...
UVM_INFO testbench.sv(122) @ 0: uvm_test_top [uvm_test_top] TEST
set_inst_override_by_name
Instance Overrides:
Type Overrides:
Type Name
---------
A
A_override
A_ovr
B
B_override
B_ovr
environment
snps_uvm_reg_bank_group
snps_uvm_reg_map
test
(*) Types with no associated type name will be printed as <unknown>
####
-------------------------------------------------------
//--------------------uvm_object------------------------------
class B extends uvm_object;
`uvm_object_utils(B)
//--------------------env class--------------------
class environment extends uvm_env;
`uvm_component_utils(environment)
A a1, a2, a3;
B b1, b2, b3;
//-------------------test class--------------------------
class test extends uvm_test;
`uvm_component_utils(test)
environment env;
module top();
initial begin
run_test("test");
end
endmodule : top
view raw override_by_cmd_line.sv hosted with by GitHub
-------------------------------------------------------
Instance Overrides:
Type Overrides:
Type Name
---------
A
A_override
A_ovr
B
B_override
B_ovr
environment
snps_uvm_reg_bank_group
snps_uvm_reg_map
test
(*) Types with no associated type name will be printed as <unknown>
####