What is a UVM sequence ?

UVM sequences are made up of several data items which can be put together in different ways to create interesting scenarios. They are executed by an assigned sequencer which then sends data items to the driver. Hence, sequences make up the core stimuli of any verification plan.

sequences on a sequencer

Class Hierarchy

uml_uvm_sequence_class_hier

Steps to create a UVM sequence

1. Create a user-defined class inherited from uvm_sequence, register with factory and call new

// my_sequence is user-given name for this class that has been derived from "uvm_sequence"
class my_sequence extends uvm_sequence;
	
	// [Recommended] Makes this sequence reusable. Note that we are calling 
	// `uvm_object_utils instead of `uvm_component_utils because sequence is a uvm_transaction object
	`uvm_object_utils (my_sequence)
	
	// This is standard code for all components
    function new (string name = "my_sequence");
    	super.new (name);
    endfunction	
endclass
2. Declare the default sequencer to execute this sequence

	// [Optional] my_sequencer is a pre-defined custom sequencer before this sequence definition
	`uvm_declare_p_sequencer (my_sequencer)
3. Define the body method

	// [Recommended] Make this task "virtual" so that child classes can override this task definition
	virtual task body ();
		// Stimulus for this sequence comes here
	endtask

UVM Sequence Example


	class my_sequence extends uvm_sequence;
		`uvm_object_utils (my_sequence)
		
		function new (string name = "my_sequence");
			super.new (name);
		endfunction
		
		// Called before the body() task
		task pre_body ();
			...
		endtask
		
		task body ();
			my_data pkt;
			`uvm_do (pkt);
		endtask
		
		// Called after the body() task
		task post_body();
			...
		endtask
	endclass

Note the following from the example shown above.

  • my_sequence is inherited from uvm_sequence
  • It is registered with the factory using `uvm_object_utils because it is a transaction item
  • The main stimulus is written within the body() task, while pre_body() and post_body() are useful callbacks to be used if required
  • A data packet is created and sent for execution using `uvm_do macro

pre_body and post_body methods are not invoked in a `uvm_do macro call.

The `uvm_do macro will allocate an object of type my_data to pkt, randomize it and send it to the default sequencer associated to execute this sequence. Use of this macro simply reduces the code required to achieve the objectives mentioned before.

Learn how to create and use a sequence