Skip to main content

Using UVM Configuration Classes

· loading · loading · ·
Education UVM Verification UVM Verification SystemVerilog Configuration Classes Randomization
Education UVM Verification
Axolot Logic
Author
Axolot Logic
Digital Design Engineer
Table of Contents
UVM Series - This article is part of a series.
Part 22: This Article

📦 Using UVM Configuration Classes
#

🔍 Introduction
#

In UVM testbenches, configuration objects are essential for dynamically controlling component parameters. These objects enable flexible communication of settings like timeouts, delays, and data widths between different levels of the testbench hierarchy. They are typically derived from uvm_object or, for cases where randomization is needed, from uvm_sequence_item.


🤖 Why Use Configuration Classes?
#

Component Parameter Management You can set parameters like timeouts, delays, and data widths for a component (e.g., an agent) using a configuration object, allowing for highly flexible testbench designs.

Randomization Support Using a uvm_sequence_item-based configuration class enables easy randomization of parameters, helping you explore different verification scenarios.

Factory and Type Override UVM’s factory mechanism allows dynamic replacement and reusability of configuration classes.


📦 Adder Config Example
#

  class adder_config extends uvm_object;
    int delay_min = 1;
    int delay_max = 10;

    `uvm_object_utils(adder_config)

    function new(string name = "adder_config");
      super.new(name);
    endfunction
  endclass

🏗️ How to Write a UVM Configuration Class
#

📦 Simple Example
#

class agent_config extends uvm_sequence_item;
  rand int timeout_cycles;      // Randomizable timeout
  rand bit enable_scoreboard;   // Enable or disable scoreboard
  
  `uvm_object_utils(agent_config)
  
  function new(string name = "agent_config");
    super.new(name);
  endfunction
endclass

This class is used to hold the operational parameters of an agent.


⚡ Sharing the Configuration
#

You can distribute this configuration object using uvm_config_db:

// Inside the test or environment class:
agent_config ag_cfg;
ag_cfg = agent_config::type_id::create("ag_cfg");
ag_cfg.randomize() with { timeout_cycles > 0; };
uvm_config_db#(agent_config)::set(this, "env.agent", "cfg", ag_cfg);

In the agent:

// Inside the build_phase() of the agent:
if (!uvm_config_db#(agent_config)::get(this, "", "cfg", cfg)) begin
  `uvm_error("CFG", "agent_config not found!")
end

🧩 Randomization Usage
#

Randomized configuration classes can generate varied parameter values to broaden test coverage:

ag_cfg.randomize() with {
  timeout_cycles inside {[50:200]};
  enable_scoreboard == 1;
};

🛠️ Using with the UVM Factory
#

Factory support allows you to override configuration classes dynamically:

agent_config::type_id::set_type_override(custom_agent_config::get_type());

🎯 Summary
#

AdvantageDescription
Parameter ManagementControls component parameters at runtime
Randomization SupportEnables parameter randomization for varied testing
Factory SupportAllows dynamic type switching and reuse

This approach greatly enhances testbench flexibility and maintainability! 🚀


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

Related

UVM Agent Usage and Adder Example
· loading · loading
Education UVM Verification UVM Verification SystemVerilog Uvm_agent Testbench Structure
Education UVM Verification
UVM Base Classes
· loading · loading
Education UVM Verification UVM Verification SystemVerilog Class Hierarchy
Education UVM Verification
UVM Driver Usage and Adder Example
· loading · loading
Education UVM Verification UVM Verification SystemVerilog Uvm_driver Stimulus Driving
Education UVM Verification
UVM Environment Usage and adder_env Example
· loading · loading
Education UVM Verification UVM Verification SystemVerilog Uvm_env Testbench Structure
Education UVM Verification
UVM Monitor Usage and Adder Example
· loading · loading
Education UVM Verification UVM Verification SystemVerilog Uvm_monitor Coverage
Education UVM Verification
UVM Object Class
· loading · loading
Education UVM Verification UVM Verification SystemVerilog Uvm_object
Education UVM Verification