Uvm Factory
Uvm Factory
• INTRODUCTION
• REGISTRATION
• CREATE
• OVERRIDE
INTRODUCTION
• In System Verilog we create instances of class object via
new () method.
• UVM introduces Factory concept which essentially
involves collecting all the members of testbench
environment under a single library kind of structure
(Registration).
• Here on all the object creation is done with respect to
Factory using Create() method instead of new().
• By using Factory registration and create ,user can
substitute one component over another without having
to change any code(overrides)
• UVM factory is a mechanism to improve flexibility and
scalability of the testbench by allowing the user to
substitute an existing class object by any of its inherited
child class objects.
• For this purpose, the factory needs to know all the types
of classes created within the testbench by a process
called as registration. There are UVM macros that allow
classes to be registered with the factory, and methods
that allow certain types and instances of class objects to
be overridden by its derived types.
REGISTRATION
• Factory Registration is done by adding below in the class declarations
OVERRIDE BY TYPE:
1. uvm_component::set_type_override_by_type(original_type, override_type)
<comp_h>::type_id::set_type_override( <comp_new_h>::get_type() );
2. uvm_factory.set_type_override_by_type(original_type, override_type)
set_type_override_by_type(<comp_h>::get_type(),
<comp_new_h>::get_type() );
3. uvm_component_registry#(T,Tname)::set_type_override(override_type)
factory.set_type_override_by_type( <comp_h>::get_type(),
<comp_new_h>::get_type() );
OVERRIDE
• OVERRIDE BY INSTANCE:
1. uvm_component_registry#(T,Tname)::set_inst_override(override
_type, inst_path, parent)
<comp_h>::type_id::set_inst_override( <comp_new_h>::get_type(),
“comp_path", this );
2. uvm_component::set_inst_override_by_type(relative_inst_path,
original_type, override_type)
set_inst_override_by_type( “comp_path", <comp_h>::get_type(),
<comp_new_h>::get_type() );
3. uvm_factory.set_inst_override_by_type(original_type,
override_type, full_inst_path)
factory.set_inst_override_by_type( <comp_h>::get_type(),
<comp_new_h>::get_type(), “comp_path" );
class base_test extends uvm_test;
`uvm_component_utils(base_test)
super.new(name, parent);
endfunction
base_env m_env;
super.build_phase(phase);
set_type_override_by_type(base_agent::get_type(), child_agent::get_type());
// factory.set_type_override_by_name("base_agent", "child_agent");
factory.print();
endfunction
endclass
class base_test extends uvm_test;
`uvm_component_utils(base_test)
super.new(name, parent);
endfunction
base_env m_env;
super.build_phase(phase);
// Set factory to override all instances under m_env of type 'base_agent' by 'child_agent'
// Or set factory to override all instances under 'm_env' called 'base_agent' by 'child_agent' by name
factory.print();
endfunction
endclass
class feature_test extends base_test;
`uvm_component_utils (feature_test)
function new (string name, uvm_component parent = null);
super.new (name, parent);
endfunction