🎯 UVM Sequence Usage and Adder Example#
🚀 Introduction#
The uvm_sequence
is one of the core classes used for stimulus (test data) generation in UVM verification environments. It works alongside the sequencer and driver components to create and send transactions.
A UVM testbench is typically built around the sequence, sequencer, and driver triangle. This structure enables modular, reusable, and flexible test scenario development.
🗂️ What is uvm_sequence?#
The uvm_sequence
generates transactions derived from uvm_sequence_item
and sends them to the sequencer, which in turn passes them to the driver.
This structure simplifies the organization of test scenarios, data flows, and stimulus generation.
Key Features#
✅ Generates stimulus by randomizing uvm_sequence_item
objects
✅ Defines the main test flow in the body()
method
✅ Offers user customization through the pre_body()
and post_body()
methods
✅ Integrates seamlessly with the sequencer and driver
📝 Adder Sequence Example#
Below is a simple adder_base_seq example that generates random adder_packet
items to test an adder design.
class adder_sequence extends uvm_sequence #(adder_transaction);
int num_transactions = 20;
`uvm_object_utils(adder_sequence)
function new(string name = "adder_sequence");
super.new(name);
endfunction
virtual task body();
adder_transaction tr;
repeat(num_transactions) begin
tr = adder_transaction::type_id::create("tr");
`uvm_do(tr);
end
endtask
/*
task pre_body();
`uvm_info(get_type_name(), "Pre Body", UVM_MEDIUM) // Print info message
endtask : pre_body
task post_body();
`uvm_info(get_type_name(), "Post Body", UVM_MEDIUM) // Print info message
endtask : post_body
*/
endclass
🔍 Explanations#
- body(): The main working part of the sequence. It generates 20 random
adder_packet
items and sends them to the sequencer-driver structure.
🔹 uvm_do
is a convenient macro in UVM that creates a sequence item or sequence, randomizes it, and sends it to a sequencer.
✅ Its responsibilities:
- Calls
create()
to instantiate the object. - Calls
randomize()
to apply randomization. - Calls
start_item()
andfinish_item()
to send the item to the sequencer.
This allows you to create, randomize, and send the item to the driver all in one line! 🚀
💡 Summary#
🔹 uvm_sequence
is the backbone of UVM’s stimulus generation mechanism.
🔹 It makes test scenarios modular and reusable.
🔹 The adder example demonstrates how to model a simple addition test environment using adder_packet
sequence items.
🔹 The pre_body()
and post_body()
methods give users additional customization and logging opportunities.