Skip to main content

Using the UVM Factory

· loading · loading · ·
Education UVM Verification UVM Verification SystemVerilog Factory Pattern
Education UVM Verification
Axolot Logic
Author
Axolot Logic
Digital Design Engineer
Table of Contents
UVM Series - This article is part of a series.
Part 10: This Article

🔍 Introduction
#

The UVM Factory is a powerful mechanism in the UVM testbench architecture that enables dynamic and flexible object and component creation. Thanks to the factory, you can decide at runtime which implementation of a base class will be instantiated. This dramatically increases the reusability and flexibility of your testbench.


🏭 What is UVM Factory?
#

UVM Factory is an implementation of the factory design pattern that allows:

  • Multiple derived classes for a single base class.
  • The factory determines which derived class to instantiate at runtime.
  • Different implementations can be loaded via configuration or in the test phase.

🔨 Registering with the Factory
#

To make a class available to the UVM Factory, you use the uvm_component_utils or uvm_object_utils macros:

class my_driver extends uvm_driver #(my_transaction);
  `uvm_component_utils(my_driver)
  // ...
endclass

This registers the my_driver class with the factory.


🔄 Using Factory Overrides
#

One of the biggest advantages of the UVM Factory is its override capability:

uvm_factory::get().set_type_override_by_type(base_type::get_type(), derived_type::get_type());

Or using name-based overrides:

uvm_factory::get().set_type_override_by_name("base_type", "derived_type");

This ensures that whenever the base type is requested, the derived type is instantiated instead.


📦 Example: Factory Override
#

Here’s an example of how to override a monitor class with a coverage-enabled version during a test:

initial begin
  uvm_factory::get().set_type_override_by_name("my_monitor", "my_coverage_monitor");
end

With this line, whenever "my_monitor" is requested, the "my_coverage_monitor" class will be created.


🎯 Why Use UVM Factory?
#

Flexibility: Change testbench behavior at runtime with different configurations.
Reusability: Try different derived classes using the same base type.
Maintainability: Swap implementations without changing testbench code.


🚀 Creating with the Factory
#

Components and objects are typically instantiated using the factory’s create() methods, which apply overrides automatically:

my_driver drv;
drv = my_driver::type_id::create("drv", this);

This call returns an instance of the correct class, including any registered overrides.


📌 Conclusion
#

The UVM Factory adds flexibility and configurability to your testbench environment. Use it to dynamically swap or extend components without rewriting code.


UVM Series - This article is part of a series.
Part 10: This Article

Related

UVM Phases: Testbench Lifecycle
· loading · loading
Education UVM Verification UVM Verification SystemVerilog Phase Management
Education UVM Verification
UVM Sequence Starting Methods
· loading · loading
Education UVM Verification UVM Verification SystemVerilog Sequence Starting Objection Usage
Education UVM Verification
Using uvm_subscriber in UVM Testbenches
· loading · loading
Education UVM Verification UVM Verification SystemVerilog Uvm_subscriber Coverage Collection
Education UVM Verification
Getting Started with UVM: Setup and Supported Simulators
· loading · loading
Education UVM Verification UVM Verification SystemVerilog Simulation
Education UVM Verification
Introduction to UVM
· loading · loading
Education UVM Verification UVM Verification SystemVerilog
Education UVM Verification
UVM Agent Usage and Adder Example
· loading · loading
Education UVM Verification UVM Verification SystemVerilog Uvm_agent Testbench Structure
Education UVM Verification