UVM Sequence Libraries

A powerful mechanism to group related sequences and automatically select them for execution strategies like Random, Round-Robin, or User-Defined.

Why Use a Sequence Library?

Instead of manually starting sequences in your test (seq1.start(sqr) followed by seq2.start(sqr)), you can bundle them into a Library. The uvm_sequence_library class can then handle the selection logic for you.

Defining a Library

Simply extend uvm_sequence_library and register other sequences to it.

class my_seq_lib extends uvm_sequence_library #(my_transaction);
    `uvm_object_utils(my_seq_lib)
    `uvm_sequence_library_utils(my_seq_lib) // Helper macro
    function new(string name="my_seq_lib");
        super.new(name);
        init_sequence_library();
    endfunction
    // Register sequences that belong to this library
    virtual function void init_sequence_library();
        add_typewide_sequence(seq_read::get_type());
        add_typewide_sequence(seq_write::get_type());
        add_typewide_sequence(seq_reset::get_type());
    endfunction
endclass

Using the Library in a Test

In your test, you set the sequencer's default_sequence to be your library. You can also configure Selection Mode and Count.

class my_test extends uvm_test;
    // ...
    function void build_phase(uvm_phase phase);
        super.build_phase(phase);
        // 1. Set the default sequence to run the library
        uvm_config_db#(uvm_object_wrapper)::set(this, "env.agent.sqr.run_phase", 
                                               "default_sequence", my_seq_lib::get_type());
        // 2. Configure the Library (Optional)
        // Run 10 sequences from the library
        uvm_config_db#(int)::set(this, "env.agent.sqr.run_phase", "count", 10);
        // Pick randomly (UVM_SEQ_LIB_RAND) or Cyclic (UVM_SEQ_LIB_ITEM)
        uvm_config_db#(uvm_sequence_lib_mode)::set(this, "env.agent.sqr.run_phase", 
                                                  "selection_mode", UVM_SEQ_LIB_RANDC);
    endfunction
endclass
Is this used often?
Honestly, many verification engineers prefer writing explicit Virtual Sequences instead of Sequence Libraries because Virtual Sequences give you precise control (e.g., "Do Reset, then 5 Reads, then 2 Writes"). Sequence Libraries are great for "stress testing" where the order doesn't matter as much as volume.