How to pass a variable from test to sequence?

A bit of context, I’m an intern getting to grips with UVM, and this is my first post on this forum, so apologies if my question is poorly asked.

I’ve been given a sequence that has hard coded variables, and my aim is to set these variables to the values calculated in the test’s connect phase. I know that the test creates an instance of the sequence in the run phase, but as the sequence isn’t a child of the test, we can’t simply “look up” to the parent test’s values. So far I’ve tried a few options:

  • I tried introducing parameters to the sequence code. Then in the test when I instantiate the sequence, I passed through the value that overrides the default value of the sequence parameter. This works if I hard code the overriding value, however in my case the value to introduce comes from a variable, so I get the “Class specialization parameter must be constant” error, which makes sense.
  • I then tried doing a factory override of the sequence class, where I change the default value of the parameter to the value I want (I found some information on it here UsingFactoryOverrides | Verification Academy). However this also doesn’t work, as the parameter value has to be the same in each case, which doesn’t work for my case where the value can vary.
  • I then looked at using the config_db to “set” the value in the test, and “get” the value in the sequence (I found some information on it here pass a parameter from uvm_test to uvm_sequence_item | Verification Academy). This looked like the answer, but I was advised against it as I would be cluttering the database.
  • As a shot in the dark, I tried creating a package that contains the variable I need, and thought I could import the package in both the test and sequence, get the test to alter the package value and get the sequence to read the package value. So in a way it acts as a global variable. This didn’t work.

So my question is, how do I go about this? Config_db seems like the way forward, but are there any alternatives? I’ve tried a lot of options and searched the forums before resorting to posting a question, so please don’t belittle a poor beginner. ;)


In reply to rickitura1:

Using the config_db is the recommended method. If your configuration contains a lot of randomized variables, then creating a configuration class and passing it down the hierarchy using the config_db is easier than setting/getting a lot of individual variables.

In reply to rickitura1:


If you do not want to use config db and want to make life little more complex, make use of sequencer!

  • Sequence started on a sequencer can access sequencer’s variables e.g. in sequence
    this.a = p_sequencer.a;

So, next step is to pass test variables to the sequencer, which you can do using
env.seqr.a = this.a;
from test.

  • Also try doing this in sequence, this.a = my_pkg::a;

Thanks for your responses! I gave it another go and managed to get the package method to work. I’ve created a structure in the package containing the variables I want to be “global”, and I can get the test and sequence to edit and read these values respectively.

Cheers for your help!