Jump to content
Sign in to follow this  
meenu

randomization control

Recommended Posts

This is to know whether there is an easier method to do this.

There is a packet

class A

{

rand int a;

rand int b;

rand int c;

rand int d;

rand int e;

rand int f;

constraint a_c{b==0->a==0;}

.

.

.

.

.

}

I have a task which randomizes A and does some operation on its members

task operate_on_A();

A obj_a;

assert(obj_a.randomize() with a==10;b==3;c==9;} // few values would be fixed, few random

endtask

From a test, i would like to call this task

d,e and f get random values as of now.

i would like to control from the test whether d,e,f would get random values or fixed values passed from the test when calling the task. If am passing fixed values, it should get the fixed values, else it should be randomized.

How can this be done in a generic manner and what is the best possible way in uvm ?

Share this post


Link to post
Share on other sites

You do that using the factory. You always randomize in the task with minimum constraints and that becomes the default behavior.

If you need fixed values, you create a class extension that either set them and turn rand_mode() off or constrains them to constant values. The test then overrides the factory for the original class with this new class using origtype::type_id::set_inst_override(newtyp::get_type(), "path.to.where.object.is.created", this) and voila! because of polymorphism, the task will randomize the object (which is now an instance of the extended type) to the desired fixed values.

The actual code required to illustrate the solution can be somewhat complex, so I suggest you look into some examples that are included in UVM. Just look for "factory" and "set_inst_override".

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×