Configuration Objects
Learn how to package testbench settings into reusable configuration objects and use them to control UVM components without hard-coding behavior.
Learning objectives
By the end of this lesson, you will be able to:
- Explain what a UVM configuration object is.
- Identify settings that belong in a configuration object.
- Create a configuration class using SystemVerilog.
- Use a configuration object to control reusable component behavior.
- Distinguish configuration data from transaction data.
- Explain why configuration objects improve testbench reuse.
- Prepare a configuration object for distribution through
uvm_config_db.
Before you start
In the previous lessons, you learned how the UVM Factory allows a test to customize which implementation gets created.
Now we need to solve a different problem:
For example, one test might want:
data_width = 32
active = 1
delay = 0
while another test might want:
data_width = 64
active = 1
delay = 5
We could create separate variables for all of these settings and pass them individually through the testbench. As the environment grows, that becomes difficult to maintain.
A configuration object gives us a better way to group related settings into one reusable object.
Test
↓
Configuration Object
↓
Agent / Driver / Monitor
↓
Behavior controlled by configuration Step 1: What is a configuration object?
A configuration object is a SystemVerilog class that stores settings used to control the behavior of one or more UVM components.
For example:
class bus_config extends uvm_object;
int data_width;
bit active;
int delay;
endclass
Instead of spreading these settings across many variables, we keep related configuration information together.
The configuration object does not normally perform the protocol operation itself. It describes how a component should operate.
Step 2: Configuration data vs transaction data
Beginners often confuse configuration objects with sequence items. They solve different problems.
| Configuration | Transaction |
|---|---|
| Controls how the testbench behaves | Represents activity sent to or observed from the DUT |
| Usually changes less frequently | Usually changes from transaction to transaction |
| Example: data width | Example: address |
| Example: active/passive mode | Example: read/write operation |
| Example: timing or delay settings | Example: payload data |
A useful rule is:
Configuration
↓
"How should my testbench behave?"
Transaction
↓
"What operation should my testbench perform?"
Step 3: Identify configuration settings
Before creating a configuration class, ask:
Common examples include:
- Whether an agent is active or passive.
- Data or address width.
- Protocol timing settings.
- Number of transactions to generate.
- Optional feature enable/disable controls.
- Protocol mode selection.
- Timeout values.
- Environment-specific behavior switches.
The exact settings depend on the design being verified.
Step 4: Build a configuration class
Let's create a configuration object for a simple bus agent.
class bus_config extends uvm_object;
bit active;
int data_width;
int timeout_cycles;
`uvm_object_utils(bus_config)
function new(string name = "bus_config");
super.new(name);
active = 1;
data_width = 32;
timeout_cycles = 100;
endfunction
endclass
There are several important parts here.
-
bus_configextendsuvm_object. - The class contains configuration fields.
- The class is registered with the UVM factory.
- The constructor provides sensible default values.
Step 5: Why use defaults?
Suppose a configuration object contains:
bit active;
int data_width;
int timeout_cycles;
Leaving these values undefined can make debugging unnecessarily difficult.
Instead, establish known defaults:
active = 1;
data_width = 32;
timeout_cycles = 100;
Now the configuration has a predictable starting state.
Step 6: Create and customize the configuration
A test can create a configuration object and change its settings.
bus_config cfg;
cfg = bus_config::type_id::create("cfg");
cfg.active = 1;
cfg.data_width = 64;
cfg.timeout_cycles = 200;
Notice that the configuration object itself does not need to know which component will eventually use it.
It simply contains the settings.
Configuration object
↓
+-------------------+
| active = 1 |
| data_width = 64 |
| timeout = 200 |
+-------------------+
Later, the configuration can be delivered to the appropriate component.
Step 7: Let the component use the configuration
Imagine a bus agent that needs to know whether it should be active.
class bus_agent extends uvm_agent;
bus_config cfg;
`uvm_component_utils(bus_agent)
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
endclass
The agent now has a place to store its configuration.
It can use settings such as:
cfg.active
cfg.data_width
cfg.timeout_cycles
The important architecture is:
Test
↓
creates/configures bus_config
↓
configuration delivered to agent
↓
agent reads configuration
↓
agent builds the appropriate components
↓
components behave according to configuration Step 8: Active and passive behavior
A particularly useful configuration setting is whether an agent should be active or passive.
An active agent typically participates in driving stimulus. A passive agent can observe activity without driving the interface.
A configuration object can describe this choice:
cfg.active = 1;
or:
cfg.active = 0;
The same reusable agent can therefore support different testbench modes without creating separate agent classes.
Step 9: Configuration belongs to the environment architecture
A common mistake is to put configuration decisions directly inside drivers and monitors.
For example, avoid scattering hard-coded values like:
if (DATA_WIDTH == 32)
...
else
...
throughout the environment.
Instead, centralize the setting:
cfg.data_width
Then components consume the configuration rather than owning independent copies of the same setting.
bus_config
/ | \
/ | \
↓ ↓ ↓
driver monitor agent
Step 10: Configuration objects and the factory
Notice something important about our configuration class:
class bus_config extends uvm_object;
Because it is a UVM object, it can also participate in the UVM Factory.
bus_config cfg;
cfg = bus_config::type_id::create("cfg");
This follows the same factory concept you learned in Lessons 17 and 18.
Configuration type
↓
Factory registration
↓
type_id::create()
↓
Configuration object
This is useful when a test needs a specialized configuration object without modifying the reusable environment.
Step 11: Keep configuration simple
A configuration object should primarily describe configuration. Avoid turning it into a second environment or a collection of unrelated helper functions.
Good:
class bus_config extends uvm_object;
bit active;
int data_width;
int timeout_cycles;
bit enable_error_injection;
endclass
Less desirable:
class bus_config extends uvm_object;
bit active;
task drive_packet();
...
endtask
function void calculate_score();
...
endfunction
endclass
The second example mixes configuration data with behavior that belongs elsewhere in the verification architecture.
Step 12: How configuration reaches a component
So far, we have created a configuration object and shown that a component can store it.
But how does the configuration object actually travel from the test to the agent?
UVM provides a standard mechanism for this:
uvm_config_db
The configuration database allows configuration information to be placed into a shared UVM configuration mechanism and retrieved by components.
uvm_config_db,
including how to set and get configuration values and objects.
For this lesson, remember the architecture rather than memorizing the API:
Test
↓
Create configuration object
↓
Customize configuration
↓
Deliver configuration
↓
Component retrieves configuration
↓
Component uses configuration Step 13: A complete configuration example
Here is a compact example that brings the main ideas together.
class bus_config extends uvm_object;
bit active;
int data_width;
int timeout_cycles;
`uvm_object_utils_begin(bus_config)
`uvm_field_int(active, UVM_DEFAULT)
`uvm_field_int(data_width, UVM_DEFAULT)
`uvm_field_int(timeout_cycles, UVM_DEFAULT)
`uvm_object_utils_end
function new(string name = "bus_config");
super.new(name);
active = 1;
data_width = 32;
timeout_cycles = 100;
endfunction
endclass
class bus_agent extends uvm_agent;
bus_config cfg;
`uvm_component_utils(bus_agent)
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
endclass
The configuration object contains the settings. The agent contains the behavior.
bus_config
↓
settings
bus_agent
↓
behavior
Keeping these responsibilities separate is an important UVM architecture principle.
Step 14: Common mistakes
Mistake 1: Hard-coding configuration inside components
If the driver contains dozens of hard-coded settings, every new test may require source-code changes.
Move test-controlled settings into configuration data.
Mistake 2: Confusing configuration with stimulus
A bus address such as 8'h40 for one transaction is
normally stimulus.
A setting such as data_width = 32 describes how the
environment operates.
Mistake 3: Creating too many configuration classes
Do not create a separate class for every single setting. Group related configuration data according to the architecture of the environment.
Mistake 4: Giving configuration objects no defaults
Predictable defaults make environments easier to use and debug.
Mistake 5: Putting component behavior inside configuration
Configuration should describe behavior, not implement the behavior. Keep protocol operations inside the appropriate UVM components.
Quick check
Question 1
What is the primary purpose of a configuration object?
Show answer
To group settings that control how reusable UVM components and environments behave.
Question 2
Which is more likely to belong in a configuration object?
A. The address of the next transaction
B. Whether the agent is active
C. The payload of one transaction
Show answer
B. Whether an agent is active is a configuration setting that controls the environment's behavior.
Question 3
Why should a configuration object have useful default values?
Show answer
Defaults provide predictable behavior and make the environment easier to use and debug.
Question 4
Should a configuration object normally contain the task that drives a packet onto the DUT interface?
Show answer
No. The configuration object should contain settings. Protocol behavior belongs in components such as drivers, monitors, and sequences.
Try it yourself
Create a configuration object for a simple FIFO verification environment.
Include at least these settings:
active— whether the agent drives the FIFO.data_width— width of FIFO data.depth— expected FIFO depth.timeout_cycles— maximum wait time.
Then:
- Extend
uvm_object. - Register the configuration class with UVM.
- Add a constructor.
- Give every field a useful default value.
- Create the configuration using
type_id::create(). - Change at least two settings.
- Print the configuration with
sprint().
Professional tip
Design configuration around reuse.
When you find yourself editing a driver, monitor, or agent just to change a test-specific setting, ask whether that setting belongs in a configuration object instead.
Key takeaways
- A configuration object groups settings that control UVM component behavior.
- Configuration data describes how the testbench should behave; transaction data describes what operation should occur.
- Good configuration objects provide sensible defaults.
- Configuration keeps reusable components from becoming dependent on hard-coded test settings.
- Configuration objects can themselves be created through the UVM Factory.
- Configuration objects should contain settings rather than component behavior.
-
uvm_config_dbprovides a standard mechanism for delivering configuration information through the UVM hierarchy.
What's next?
You now know how to design a configuration object and why it is useful for reusable UVM environments.
But we still have one important question:
In the next lesson, we will answer that question by learning the
uvm_config_db.