0% found this document useful (0 votes)
18 views

Uvm Factory

The document explains the UVM Factory concept in System Verilog, which allows for flexible and scalable testbench design by enabling the substitution of class objects through registration and creation methods. It details the registration process for components and objects, the syntax for creating instances using the factory, and methods for overriding types and instances. Additionally, it provides code examples demonstrating how to implement these concepts in a test environment.

Uploaded by

rajforever2k1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Uvm Factory

The document explains the UVM Factory concept in System Verilog, which allows for flexible and scalable testbench design by enabling the substitution of class objects through registration and creation methods. It details the registration process for components and objects, the syntax for creating instances using the factory, and methods for overriding types and instances. Additionally, it provides code examples demonstrating how to implement these concepts in a test environment.

Uploaded by

rajforever2k1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

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

Class my_component extends uvm_component;


`uvm_component_utils (my_component)
function new (string name = “my_component”,
uvm_component parent);

Class my_object extends uvm_object;


`uvm_object_utils (my_object)
function new (string name = “my_object”);
CREATE
• Objects or Components are created using the below
syntax instead of new().
• Object has only 1 argument
• Obj_h = object :: type_id :: create
(“obj_h”);
• Component has 2 argument as specified in new
• Cmp_h = component :: type_id ::
create (“cmp_h” , this);
OVERRIDE

Getting Factory Single ton:


uvm_factory factory = uvm_coreservice_t::get().get_factory();

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)

function new(string name, uvm_component parent);

super.new(name, parent);

endfunction

base_env m_env;

virtual function void build_phase(uvm_phase phase);

// Get handle to the singleton factory instance

uvm_factory factory = uvm_factory::get();

super.build_phase(phase);

// Set factory to override 'base_agent' by 'child_agent' by type

set_type_override_by_type(base_agent::get_type(), child_agent::get_type());

// Or set factory to override 'base_agent' by 'child_agent' by name

// factory.set_type_override_by_name("base_agent", "child_agent");

// Print factory configuration

factory.print();

// Now create environment

m_env = base_env::type_id::create("m_env", this);

endfunction

endclass
class base_test extends uvm_test;

`uvm_component_utils(base_test)

function new(string name, uvm_component parent);

super.new(name, parent);

endfunction

base_env m_env;

virtual function void build_phase(uvm_phase phase);

// Get handle to the singleton factory instance

uvm_factory factory = uvm_factory::get();

super.build_phase(phase);

// Set factory to override all instances under m_env of type 'base_agent' by 'child_agent'

set_inst_override_by_type("m_env.*", base_agent::get_type(), child_agent::get_type());

// Or set factory to override all instances under 'm_env' called 'base_agent' by 'child_agent' by name

// factory.set_inst_override_by_name("base_agent", "child_agent", {get_full_name(), ".m_env.*"});

// Print factory configuration

factory.print();

// Now create environment

m_env = base_env::type_id::create("m_env", this);

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

virtual function void build_phase (uvm_phase phase);


super.build_phase (phase);
`ifdef PKT_OVERRIDE
// Substitute all eth_packets with eth_v2_packet
set_type_override_by_type (eth_packet::get_type(), eth_v2_packet::get_type());
`endif
// These are the three different styles to override something
`ifdef DRV_STYLE1
// Substitute all instances of base_driver with driver2
set_type_override_by_type (base_driver::get_type(), spi_driver::get_type());
`elsif DRV_STYLE2
// Substitute only eth_driver in agnt2 with spi_driver - by calling the
component to be replaced method
eth_driver::type_id::set_inst_override (spi_driver::get_type(),
"m_top_env.m_agnt2.m_drv0", this);
`elsif DRV_STYLE3
// Substitute base_driver only in agnt0 - by calling the factory method
factory.set_inst_override_by_type (base_driver::get_type(),
eth_driver::get_type(), {get_full_name(), ".m_top_env.m_agnt0.*"});
`endif
// Trying to override a sequence
`ifdef SEQ_TYPE
// Substitute seq1 with seq2
set_type_override_by_type (seq1::get_type(), seq3::get_type());
`elsif SEQ_INST
// Substitute seq1 with seq2 only for agnt1
set_inst_override_by_type ("m_top_env.m_agnt1.m_seqr0.*", seq1::get_type(),
seq2::get_type());
`else
`endif
factory.print();
endfunction
// Enter test code for feature here
endclass

You might also like