Sequence Reuse Patterns
Design sequence libraries that maximize reuse, minimize duplication, and keep verification intent separate from protocol mechanics.
Learning objectives
- Explain what makes a UVM sequence genuinely reusable.
- Recognize common patterns for composing and extending sequences.
- Separate reusable stimulus behavior from test-specific scenario intent.
- Choose between sequence reuse, configuration, inheritance, and composition.
- Use base sequences to centralize common behavior without creating rigid hierarchies.
- Build a small sequence library that can support multiple tests.
- Validate that reused sequences produce the intended transactions.
Step 1: Understand what sequence reuse really means
Sequence reuse is more than calling the same class from multiple tests. A reusable sequence has a stable purpose, a clear interface, and behavior that can be adapted without copying its implementation.
Consider three tests:
smoke_test
-> write register
-> read register
stress_test
-> write many registers
-> read many registers
error_test
-> write register
-> inject an error
-> read register
All three tests may need the same basic read and write operations. Those operations should normally be implemented once and reused.
Step 2: Build a sequence library
A practical sequence library often contains several levels of abstraction.
Sequence Library
|
+---------------+---------------+
| | |
v v v
bus_write_seq bus_read_seq reset_seq
| |
+-------+-------+
|
v
register_access_seq
|
v
block_config_seq
The lower-level sequences perform reusable protocol operations. Higher-level sequences combine those operations into meaningful scenarios.
This creates a useful relationship:
low-level sequence
=
"How do I perform this operation?"
high-level sequence
=
"What operation should this scenario perform?" Step 3: Pattern 1 — Reuse by composition
Composition means building a new sequence by starting existing sequences. This is often the safest and most flexible reuse pattern.
Suppose we already have:
bus_write_seq
bus_read_seq
We can create a register access sequence that composes them:
class register_test_seq extends uvm_sequence #(bus_item);
`uvm_object_utils(register_test_seq)
function new(string name = "register_test_seq");
super.new(name);
endfunction
task body();
bus_write_seq write_seq;
bus_read_seq read_seq;
write_seq = bus_write_seq::type_id::create("write_seq");
write_seq.addr = 'h20;
write_seq.data = 'h55;
write_seq.start(m_sequencer);
read_seq = bus_read_seq::type_id::create("read_seq");
read_seq.addr = 'h20;
read_seq.start(m_sequencer);
endtask
endclass
The new sequence does not duplicate bus transaction generation. It reuses existing protocol sequences.
bus_write_seq or bus_read_seq can benefit
every higher-level sequence that uses them.
Step 4: Pattern 2 — Reuse through configuration
Lesson 4 introduced sequence configuration. Configuration is often preferable when the algorithm remains the same but the data changes.
class burst_write_seq extends uvm_sequence #(bus_item);
`uvm_object_utils(burst_write_seq)
rand bit [31:0] start_addr;
rand int unsigned count;
function new(string name = "burst_write_seq");
super.new(name);
endfunction
task body();
bus_item req;
repeat (count) begin
req = bus_item::type_id::create("req");
start_item(req);
req.write = 1'b1;
req.addr = start_addr;
req.data = $urandom;
finish_item(req);
start_addr += 4;
end
endtask
endclass
The same sequence can now support many scenarios:
count = 4
count = 16
count = 100
start_addr = 0x1000
start_addr = 0x8000
No new sequence class is required merely because the parameters changed.
Step 5: Pattern 3 — Base sequence for common behavior
Sometimes several sequences share common setup or utility behavior. A base sequence can centralize that behavior.
class base_bus_seq extends uvm_sequence #(bus_item);
`uvm_object_utils(base_bus_seq)
function new(string name = "base_bus_seq");
super.new(name);
endfunction
task wait_cycles(int unsigned cycles);
repeat (cycles)
#1ns;
endtask
endclass
Specialized sequences can derive from the base:
class burst_read_seq extends base_bus_seq;
`uvm_object_utils(burst_read_seq)
function new(string name = "burst_read_seq");
super.new(name);
endfunction
task body();
// Burst-read implementation
wait_cycles(2);
endtask
endclass
Inheritance can be useful when the child sequences share a genuine conceptual relationship and common implementation.
Step 6: Pattern 4 — Constrained specialization
Another useful reuse technique is to keep a generic sequence and specialize its constraints for a particular scenario.
class random_access_seq extends uvm_sequence #(bus_item);
`uvm_object_utils(random_access_seq)
rand bit [31:0] addr;
rand bit [31:0] data;
constraint aligned_c {
addr[1:0] == 2'b00;
}
constraint valid_range_c {
addr inside {[32'h1000:32'h1FFF]};
}
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
A test can further control the randomized sequence:
random_access_seq seq;
seq = random_access_seq::type_id::create("seq");
assert(seq.randomize() with {
addr inside {[32'h1800:32'h18FF]};
data == 'hAA;
});
seq.start(bus_seqr);
This combines reusable constraints with scenario-specific intent.
Step 7: Pattern 5 — Separate scenario sequences from primitive sequences
A scalable sequence library distinguishes between primitive operations and scenario operations.
| Sequence type | Example | Purpose |
|---|---|---|
| Primitive | bus_write_seq |
Perform one reusable protocol operation. |
| Primitive | bus_read_seq |
Perform one reusable read operation. |
| Compound | register_access_seq |
Combine several primitive operations. |
| Scenario | configure_block_seq |
Represent a meaningful verification scenario. |
This separation prevents scenario-specific code from leaking into every primitive sequence.
Step 8: Know when to create a new sequence
One of the most important design decisions is determining whether to extend an existing sequence or create a new one.
Use the following decision process:
Does the stimulus algorithm stay the same?
|
+----+----+
| |
YES NO
| |
v v
Configure Create a new
existing sequence or
sequence compose sequences
For example:
- Different address → configuration.
- Different data pattern → configuration.
- Different transaction count → configuration.
- Same operation plus additional operations → composition.
- Fundamentally different stimulus algorithm → new sequence.
Step 9: Reuse through factory-compatible creation
Reusable sequence libraries should generally use UVM factory creation when appropriate:
seq = bus_write_seq::type_id::create("seq");
rather than hard-coding construction everywhere:
seq = new("seq");
Factory-compatible creation preserves the ability to replace the sequence implementation later using UVM factory mechanisms.
For example, a test may initially use:
bus_write_seq
while a specialized test can later substitute an extended implementation without modifying the calling code.
Step 10: Do not confuse reuse with virtual sequencing
A reusable sequence does not automatically need a virtual sequencer.
At this stage, focus on reusing sequences within a stimulus path:
test
|
v
scenario sequence
|
+----> write sequence
|
+----> read sequence
|
v
bus sequencer
|
v
driver
Later, when a scenario must coordinate multiple independent sequencers, the architecture changes:
virtual sequence
/ \
v v
bus sequencer irq sequencer
| |
v v
bus driver irq driver
That is the subject of the upcoming virtual-sequence lessons. Reuse should be mastered first because virtual sequences depend heavily on well-designed lower-level sequences.
Step 11: Build a reusable sequence library incrementally
A practical development strategy is to build the library in layers.
- Create one primitive sequence and prove that it generates a correct transaction.
- Add configuration so the primitive can support multiple scenarios.
- Create a second primitive sequence for another fundamental operation.
- Compose the primitives into a meaningful compound sequence.
- Reuse the compound sequence from multiple tests.
- Add specialization only when the verification requirement actually differs.
This prevents the sequence library from becoming an abstraction exercise with no demonstrated verification value.
Step 12: Validate reuse with multiple scenarios
A sequence is not truly reusable until it has been exercised in more than one meaningful context.
For example, use the same bus_write_seq in:
Test A:
address = 0x20
data = 0x55
Test B:
address = 0x24
data = 0xAA
Test C:
address = 0x80
data = 0xFF
Then verify through the monitor that the sequence generated the expected transactions in all three cases.
The important evidence is not that the sequence ran without a UVM error. The evidence is that the reusable abstraction generated the correct protocol behavior for each scenario.
Step 13: Common sequence reuse mistakes
Step 14: A production-style sequence architecture
A mature sequence library might look like this:
Test
|
v
scenario_sequence
|
+--------+--------+
| | |
v v v
config_seq traffic_seq error_seq
| | |
+--------+--------+
|
v
primitive sequences
/ | \
v v v
write_seq read_seq reset_seq
| | |
+---------+----------+
|
v
sequence item
|
v
sequencer
|
v
driver
|
v
DUT
This architecture provides multiple reuse points without forcing every layer to understand every other layer.
Try it yourself
Build a small reusable sequence library for a memory-mapped peripheral.
- Create
bus_write_seq. - Create
bus_read_seq. - Add configurable address and data fields.
- Create
register_access_seqthat writes and then reads the same address. - Create
configure_block_seqthat composes multiple register accesses. - Use the same primitive sequences from at least two different scenarios.
- Verify the generated transactions using the monitor.
Challenge:
Add a reusable burst_write_seq. Then create two scenarios that
use the same burst sequence but configure different address ranges and
transaction counts.
Design challenge: Decide which of your sequences should use configuration, which should use composition, and which—if any—actually need inheritance. Be prepared to justify each choice.
Verification checkpoint
Before moving to virtual sequences, make sure you can explain:
- What makes a sequence genuinely reusable?
- When should you configure an existing sequence instead of creating a new one?
- When is composition better than inheritance?
- Why should primitive protocol sequences remain separate from scenario sequences?
- Why is a giant configurable sequence usually a poor abstraction?
- Why should reused sequences be validated independently before being composed into larger scenarios?
- Why does good sequence reuse make later virtual-sequence development easier?
Key takeaways
- Sequence reuse is about sharing stable stimulus behavior without copying implementation.
- Configuration is the preferred mechanism when the algorithm remains the same but parameters change.
- Composition is a powerful way to create higher-level sequences from verified lower-level operations.
- Inheritance is useful for genuine shared sequence behavior, but should not become the default reuse mechanism.
- A good sequence library separates primitive protocol operations from compound and scenario-level sequences.
- Avoid both duplicated sequences and overly generic sequences with excessive configuration flags.
- Factory-compatible sequence creation keeps the library extensible and supports later factory-based customization.
- Reusable sequences should be independently validated because defects in a shared sequence can affect many tests.
- Strong sequence reuse provides the foundation for the virtual-sequence and multi-agent coordination techniques introduced in the next lessons.