Sequence Libraries
Build reusable stimulus libraries that can generate controlled, repeatable, and scalable verification scenarios.
Learning objectives
- Explain why sequence libraries are useful in reusable UVM environments.
- Distinguish a reusable sequence from a test-specific scenario.
- Build and configure a sequence library using
uvm_sequence_library. - Control how sequences are selected and executed by the library.
- Verify that the selected sequences generate the intended transactions.
Step 1: Understand the concept
As a UVM environment grows, the number of useful stimulus patterns grows with it. You may need a reset sequence, a single-transfer sequence, a burst sequence, an error sequence, a back-to-back traffic sequence, and many combinations of these behaviors. Putting all of those scenarios directly into tests quickly becomes difficult to maintain.
A sequence library provides a structured collection of related sequences. Instead of making every test know the implementation details of every stimulus sequence, the test can select or execute a library that represents a family of valid behaviors.
Why use a sequence library?
- Reuse: The same sequence collection can be used by many tests.
- Variation: Different sequences can exercise different legal behaviors.
- Maintainability: Protocol-specific stimulus stays in sequences instead of being duplicated across tests.
- Scalability: New stimulus patterns can be added without redesigning the environment.
- Regression control: A library can provide a known collection of stimulus suitable for smoke, random, or stress testing.
The key design principle is to keep protocol behavior in sequences and scenario intent in tests. For example, a test might decide to exercise heavy traffic, while the sequence library contains the actual legal traffic patterns.
Step 2: Understand uvm_sequence_library
UVM provides uvm_sequence_library specifically for creating a collection
of sequences. A library can contain multiple sequence types, and the library can select
sequences according to its configured execution mode.
A useful mental model is:
Test
|
v
Sequence Library
|
+-- single_transfer_seq
+-- burst_seq
+-- idle_then_transfer_seq
+-- error_injection_seq
|
v
Sequencer
|
v
Driver
|
v
DUT
The library is therefore a stimulus coordinator. It does not drive the DUT directly. Individual sequences still create and send sequence items through the sequencer.
A minimal sequence library
class bus_sequence_library extends uvm_sequence_library #(bus_item);
`uvm_object_utils(bus_sequence_library)
`uvm_sequence_library_utils(bus_sequence_library)
function new(string name = "bus_sequence_library");
super.new(name);
init_sequence_library();
endfunction
endclass
The important pieces are the parameterized transaction type and the sequence-library
registration macros. The call to init_sequence_library() initializes the
library's internal sequence information.
Step 3: Add reusable sequences
Suppose our bus environment already has two reusable sequences: one that performs a single transfer and another that performs a burst.
class single_transfer_seq extends uvm_sequence #(bus_item);
`uvm_object_utils(single_transfer_seq)
function new(string name = "single_transfer_seq");
super.new(name);
endfunction
task body();
bus_item req;
req = bus_item::type_id::create("req");
start_item(req);
assert(req.randomize() with {
burst_len == 1;
});
finish_item(req);
endtask
endclass
class burst_seq extends uvm_sequence #(bus_item);
`uvm_object_utils(burst_seq)
function new(string name = "burst_seq");
super.new(name);
endfunction
task body();
bus_item req;
req = bus_item::type_id::create("req");
start_item(req);
assert(req.randomize() with {
burst_len inside {[4:8]};
});
finish_item(req);
endtask
endclass
These sequences should be reusable independently of the test that invokes them. Notice that the sequence defines how to generate the transaction, while the test decides when and why to use it.
Registering the sequences
The sequence library can register the reusable sequences so they become members of the library.
class bus_sequence_library extends uvm_sequence_library #(bus_item);
`uvm_object_utils(bus_sequence_library)
`uvm_sequence_library_utils(bus_sequence_library)
function new(string name = "bus_sequence_library");
super.new(name);
add_typewide_sequence(single_transfer_seq::get_type());
add_typewide_sequence(burst_seq::get_type());
init_sequence_library();
endfunction
endclass
Once registered, the library knows which sequence types it may select. This gives the testbench a single reusable entry point for a family of related stimulus.
Step 4: Control library execution
A sequence library can be used in different ways depending on the verification goal. For example, a smoke test may want a small predictable set of sequences, while a stress test may want the library to generate more varied traffic.
bus_sequence_library lib_seq;
lib_seq = bus_sequence_library::type_id::create("lib_seq");
lib_seq.selection_mode =
UVM_SEQ_LIB_RANDC;
lib_seq.min_random_count = 5;
lib_seq.max_random_count = 10;
lib_seq.start(env.agent.sequencer);
Here the test creates the library, selects a library execution mode, specifies the desired number of sequence executions, and starts the library on the agent's sequencer.
The exact selection policy should be chosen deliberately. Random selection is useful for exploration, but a regression should still provide enough control to reproduce important failures.
Step 5: Use the library from a test
The test should remain responsible for the overall scenario. It can configure the sequence library and then start it on the appropriate sequencer.
class traffic_test extends base_test;
`uvm_component_utils(traffic_test)
function new(string name = "traffic_test",
uvm_component parent = null);
super.new(name, parent);
endfunction
task run_phase(uvm_phase phase);
bus_sequence_library lib_seq;
phase.raise_objection(this);
lib_seq = bus_sequence_library::type_id::create("lib_seq");
lib_seq.selection_mode = UVM_SEQ_LIB_RAND;
lib_seq.min_random_count = 10;
lib_seq.max_random_count = 20;
lib_seq.start(env.agent.sequencer);
phase.drop_objection(this);
endtask
endclass
The important architectural boundary is clear: the test chooses the traffic strategy, while the sequence library supplies reusable stimulus behavior.
Step 6: Validate what actually happened
Starting a sequence library successfully does not prove that the DUT was exercised correctly. Verification evidence should come from the monitor, scoreboard, assertions, and coverage model.
- Confirm that the library started on the intended sequencer.
- Use the monitor to verify that transactions reached the DUT interface.
- Check that the expected transaction types were observed.
- Use the scoreboard to detect incorrect DUT responses.
- Use coverage to determine whether the library exercised the intended behaviors.
- Record the seed and useful transaction information when debugging failures.
`uvm_info("SEQ_LIB",
$sformatf("Starting traffic library: %s", lib_seq.get_name()),
UVM_MEDIUM)
This report confirms that the library was started, but it is not a substitute for checking DUT behavior. A good verification environment distinguishes stimulus evidence from correctness evidence.
Common mistakes
- Putting test intent inside every sequence: this makes sequences difficult to reuse. Keep sequences focused on stimulus behavior.
- Using random selection without reproducibility: always preserve enough information to reproduce a failing run.
- Assuming sequence execution means DUT correctness: a sequence can execute perfectly while the DUT is completely wrong.
- Making the library too broad: unrelated protocol behaviors usually belong in separate libraries or higher-level virtual sequences.
- Skipping deterministic tests: sequence libraries are useful for variation, but directed sequences remain valuable for debugging and targeted requirements.
When should you use a sequence library?
| Verification need | Good approach |
|---|---|
| One precise protocol scenario | Directed sequence |
| Several related stimulus patterns | Sequence library |
| Coordinate multiple interfaces | Virtual sequence |
| Large randomized exploration | Sequence library with controlled random selection |
| Reproduce a known failure | Directed/replayable sequence with fixed seed or parameters |
Build it in small pieces
- Create one working transaction type and sequencer.
- Write two small sequences that represent different legal behaviors.
- Run each sequence independently and verify its transactions through the monitor.
- Create a sequence library containing both sequences.
- Run the library with a small execution count.
- Inspect the monitor output and confirm that both sequence behaviors can be observed.
- Add scoreboard checks and coverage before increasing the amount of random traffic.
Try it yourself
Build a sequence library for a simple bus or FIFO interface. Include at least three reusable sequences:
- A single-transfer sequence.
- A burst or multiple-transfer sequence.
- An idle or boundary-condition sequence.
Register the sequences in a uvm_sequence_library, run the library from a
test, and verify through the monitor which transaction patterns were generated.
Intermediate challenge
Add a fourth sequence that intentionally creates a legal corner case, then configure the library so that your regression can exercise the corner case without making every test depend on it.
Key takeaways
- A sequence library organizes related reusable stimulus sequences into a single UVM stimulus mechanism.
- Tests define verification intent; reusable sequences define protocol-level stimulus behavior.
uvm_sequence_librarycan provide controlled variation across a family of sequences.- Random sequence selection should always be paired with reproducibility and useful debug information.
- Sequence execution is stimulus evidence; monitor, scoreboard, assertions, and coverage provide verification evidence.