Sequence Configuration
Configure reusable UVM sequences without hard-coding scenario parameters, while keeping stimulus intent separate from protocol implementation.
Learning objectives
- Explain why reusable sequences need configurable behavior.
- Distinguish sequence parameters, sequence fields, and environment configuration.
- Configure sequence behavior using direct assignments and configuration objects.
- Use
uvm_config_dbappropriately when configuration must cross component boundaries. - Understand default values, test-specific overrides, and configuration precedence.
- Validate that the sequence actually received and used its intended configuration.
Step 1: Understand the problem
Reusable sequences become valuable when the same stimulus pattern can be used in many tests. However, reuse becomes difficult if the sequence contains hard-coded values.
Consider a sequence that always writes the same address and data:
task body();
bus_item req;
req = bus_item::type_id::create("req");
start_item(req);
req.write = 1'b1;
req.addr = 'h20;
req.data = 'h55;
finish_item(req);
endtask
This works, but the sequence is tightly coupled to one scenario. A different test may need:
address = 0x24
data = 0xAA
We could create another sequence, but that duplicates behavior rather than reusing it.
Step 2: Identify what should be configurable
Not every sequence property should become configurable. Configuration should represent a meaningful variation in the scenario.
For a bus write sequence, reasonable configuration might include:
- number of transactions
- address range
- data pattern
- read/write ratio
- delay between transactions
- whether errors should be injected
By contrast, low-level protocol mechanics such as the exact handshake behavior normally belong in the sequence item and driver rather than becoming arbitrary test configuration.
| Information | Typical owner |
|---|---|
| Scenario parameters | Test / high-level sequence |
| Sequence behavior controls | Sequence configuration |
| Protocol transaction fields | Sequence item |
| Pin-level protocol timing | Driver |
| Agent mode and interface setup | Agent/environment configuration |
Step 3: Configure a sequence directly
The simplest approach is to expose configuration as fields in the sequence
and assign them before calling start().
class bus_write_seq extends uvm_sequence #(bus_item);
`uvm_object_utils(bus_write_seq)
rand bit [31:0] addr;
rand bit [31:0] data;
function new(string name = "bus_write_seq");
super.new(name);
endfunction
task body();
bus_item req;
req = bus_item::type_id::create("req");
start_item(req);
req.write = 1'b1;
req.addr = addr;
req.data = data;
finish_item(req);
endtask
endclass
The test or parent sequence can now configure the sequence instance:
bus_write_seq write_seq;
write_seq = bus_write_seq::type_id::create("write_seq");
write_seq.addr = 'h20;
write_seq.data = 'h55;
write_seq.start(bus_seqr);
This is often the best solution for a small number of explicit scenario parameters.
Step 4: Use a configuration object for related settings
As a sequence grows, passing many independent fields can become difficult to maintain. A configuration object groups related controls into one reusable object.
class bus_seq_cfg extends uvm_object;
`uvm_object_utils(bus_seq_cfg)
bit [31:0] base_addr = 'h1000;
bit [31:0] data = 'h55;
int unsigned count = 4;
int unsigned delay_cycles = 0;
function new(string name = "bus_seq_cfg");
super.new(name);
endfunction
endclass
The sequence can then contain a reference to this configuration:
class register_write_seq extends uvm_sequence #(bus_item);
`uvm_object_utils(register_write_seq)
bus_seq_cfg cfg;
function new(string name = "register_write_seq");
super.new(name);
endfunction
task body();
bus_item req;
if (cfg == null)
`uvm_fatal("NO_CFG", "register_write_seq has no configuration")
repeat (cfg.count) begin
req = bus_item::type_id::create("req");
start_item(req);
req.write = 1'b1;
req.addr = cfg.base_addr;
req.data = cfg.data;
finish_item(req);
repeat (cfg.delay_cycles)
#1ns;
end
endtask
endclass
Now the configuration represents a coherent set of sequence behavior instead of a collection of unrelated variables.
Step 5: Decide where configuration should come from
There are several ways to configure a sequence. The correct choice depends on who owns the information.
| Approach | Best use |
|---|---|
| Direct field assignment | A parent/test explicitly controls one sequence instance. |
| Constructor/default values | A sensible default behavior should always exist. |
| Configuration object | Several related sequence controls must travel together. |
uvm_config_db |
Configuration needs to be distributed through the UVM hierarchy. |
Do not use uvm_config_db simply because it is available. A direct
assignment can be easier to understand when configuration is local to one
sequence instance.
Step 6: Understand uvm_config_db for sequence configuration
A sequence is a uvm_object, not a uvm_component.
This distinction matters when using the configuration database.
A common pattern is for the sequence to use its starting context to access configuration:
class traffic_seq extends uvm_sequence #(bus_item);
`uvm_object_utils(traffic_seq)
bus_seq_cfg cfg;
task body();
if (!uvm_config_db#(bus_seq_cfg)::get(
m_sequencer,
"",
"bus_seq_cfg",
cfg
))
begin
`uvm_fatal("CFG", "bus_seq_cfg was not found")
end
// Generate traffic using cfg...
endtask
endclass
The exact configuration path and context must match how the configuration was placed into the database. This is why configuration database debugging is largely about understanding scope and context.
uvm_config_db is hierarchical configuration infrastructure.
It is not a replacement for ordinary object-oriented parameter passing.
Step 7: Configure from the test
A common architecture is for the test to establish the default configuration, while the sequence consumes it.
class my_test extends uvm_test;
`uvm_component_utils(my_test)
bus_seq_cfg cfg;
function void build_phase(uvm_phase phase);
super.build_phase(phase);
cfg = bus_seq_cfg::type_id::create("cfg");
cfg.base_addr = 'h2000;
cfg.data = 'hA5;
cfg.count = 8;
uvm_config_db#(bus_seq_cfg)::set(
this,
"*",
"bus_seq_cfg",
cfg
);
endfunction
endclass
The sequence can then retrieve the configuration when it executes.
This provides a useful separation:
test
|
| establishes configuration
v
uvm_config_db
|
| sequence retrieves configuration
v
sequence
|
| generates transactions
v
sequencer
|
v
driver Step 8: Defaults versus test-specific overrides
Reusable environments usually need sensible defaults. Individual tests should then override only the values that matter to their scenario.
For example:
Default:
base_addr = 0x1000
data = 0x00
count = 4
Stress test:
count = 1000
Pattern test:
data = 0xAA
Address test:
base_addr = 0x8000
This is preferable to creating a separate sequence class for every possible combination.
Step 9: Configuration and randomization are different
Configuration determines how the sequence should behave. Randomization explores values within the allowed behavior space.
Configuration
|
+--> transaction count = 100
|
+--> address range = 0x1000-0x1FFF
|
v
Randomization
|
+--> address = 0x13A0
+--> data = 0x7C
|
v
Sequence item
|
v
Driver
Configuration can therefore constrain the operating region while randomization selects individual values within that region.
A good verification environment does not confuse "make this test configurable" with "randomize everything."
Step 10: Validate that configuration was actually applied
A configuration value existing in the database does not prove that the sequence consumed it correctly.
Add an observable checkpoint:
`uvm_info("SEQ_CFG",
$sformatf(
"Starting traffic: base_addr=0x%08h data=0x%08h count=%0d",
cfg.base_addr,
cfg.data,
cfg.count
),
UVM_MEDIUM
)
Then verify the generated transactions through the monitor.
For example, if the configuration specifies:
base_addr = 0x2000
data = 0xA5
count = 3
the monitor should provide evidence consistent with three expected writes.
| Checkpoint | Evidence |
|---|---|
| Configuration retrieved | Sequence report shows expected values. |
| Sequence generated transactions | Driver receives expected items. |
| Protocol activity occurred | Monitor observes expected transactions. |
| DUT behavior is correct | Scoreboard/assertion provides checking evidence. |
Step 11: Common sequence configuration mistakes
uvm_config_db for everything.
Global configuration mechanisms can obscure ownership. Use direct object
references when local configuration is sufficient.
uvm_fatal.
Step 12: A practical design pattern
A strong intermediate-level sequence architecture can follow this pattern:
+------------------+
| uvm_test |
+--------+---------+
|
| configure
v
+------------------+
| sequence config |
+--------+---------+
|
| consumed by
v
+------------------+
| high-level seq |
+--------+---------+
|
| starts
v
+------------------+
| protocol seq |
+--------+---------+
|
v
sequence item
|
v
sequencer
|
v
driver
|
v
DUT
The benefit is that each layer has a clear responsibility. The test chooses the scenario, configuration describes how the reusable stimulus should behave, sequences generate transactions, and the driver handles interface mechanics.
Try it yourself
Build a configurable memory-write sequence.
- Create a
bus_seq_cfgobject. - Add
base_addr,data, andcountfields. - Create a reusable sequence that consumes this configuration.
- Give the configuration sensible default values.
- Create one test that overrides only
count. - Create another test that overrides only
data. - Report the final configuration before generating traffic.
- Use monitor output to confirm that the generated transactions match the configuration.
Challenge: Add a configurable address range and randomize each generated address while keeping all addresses aligned.
Verification checkpoint
Before moving to the next lesson, make sure you can explain:
- Why should reusable sequences avoid hard-coded scenario values?
- When is direct sequence field assignment preferable to
uvm_config_db? - Why might several related settings be grouped into a configuration object?
- What is the difference between configuration and randomization?
- How can you prove that a sequence actually consumed the intended configuration?
- When should a new sequence class be created instead of adding another configuration field?
Key takeaways
- Sequence configuration makes reusable stimulus adaptable to different verification scenarios.
- Keep scenario-specific values configurable instead of hard-coding them inside reusable sequence algorithms.
- Direct field assignment is often the clearest solution for local sequence configuration.
- Configuration objects are useful when several related sequence controls must be managed together.
-
Use
uvm_config_dbwhen hierarchical configuration distribution is actually needed, not simply because it is available. - Configuration defines the operating behavior; randomization explores values within that behavior.
- Always validate configuration with observable evidence such as reports, monitored transactions, assertions, or scoreboard results.
- Create a new sequence when the stimulus algorithm changes; configure an existing sequence when only its parameters change.