Jump to content

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 ?

Link to comment
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".

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...