can the ovm_do will do randomization of objects inside the class for which we did ovm_do

5 posts / 0 new
Last post
ranjith.palavarapu
Offline
Academy Total Access User
Joined: 03/11/2010
Posts: 3
can the ovm_do will do randomization of objects inside the class for which we did ovm_do

i have a cfg class and two sequences as shown below

class cfg extends ovm_object;
....
rand int len;
function new();
len = 32 // default assignment
endfunction:new

....
endclass

class seq1 extends ovm_sequence;
...
cfg cfg_obj;
rand int var1;
function new();
super.new
cfg_obj = new();
endfunction:new

task body
....
cfg_obj.randomize with {len == 1;};
...
endtask
endclass

class seq2 extends ovm_sequence;
...
seq1 seq1_obj;
.....

task body();
`ovm_do_with(seq1_obj,{cfg_obj.len =0; var1 = 32'h43})
endtask

endclass

I wanted to know is the len assignment (with ovm_do_with in seq2) proper?
even when i remove the .randomize of seq1, its giving a constraint solver error for len of cfg_obj saying the default value of cfg_obj is different than the value currently assigned so constraint solver failed.

can anyone help me how the ovm_do works for sequences in which there are objects of other classes.

dave_59
Offline
Verification Forum Moderator
Joined: 03/10/2010
Posts: 976
Re: can the ovm_do will do randomization of objects inside the class for which we did ovm_do

I can explain why your code doesn't work, but there could be many different solutions depending on what you ultimately want to do.

The problem is that you are applying a constraint to something that is considered a non-random variable. Although you have declared len as a rand variable, you did not declare cfg_obg as rand. SystemVerilog requires that the member class variable also be declared as rand when randomizing the enclosing object. So so the call to randomize inside seq2::body cannot modify the value of len to meet the with constraint.

But just adding the rand modifier will not solve your problem. After you randomize seq1_obj, the seq1:body calls randomize on cfg_obg, which replaces the value of len that you just randomize.

If you always will be setting len to a specific value, you might consider using set/get_congig_object and overriding the value as needed.

__________________

Dave Rich
Mentor Graphics
http://go.mentor.com/drich

sharan_basappa
Offline
Academy Forum User
Joined: 04/01/2008
Posts: 161
Re: can the ovm_do will do randomization of objects inside the class for which we did ovm_do

I would do the following:

- declare rand cfg_len in seq1
- change cfg_obj.randomize with {len == cfg_len;};
- change `ovm_do_with(seq1_obj,{cfg_len =0; var1 = 32'h43})

ranjith.palavarapu
Offline
Academy Total Access User
Joined: 03/11/2010
Posts: 3
Re: can the ovm_do will do randomization of objects inside the class for which we did ovm_do

Hi Dave,

Thanks for the reply

so incase if i want to use set_config_object, will it be fine to use something like
set_config_obj("*","CFG_STRING",seq1.cfg_obj,0); is it legal and advisable?

or is it advisable to have a local object in seq2 and do the set cfg with that

set_cfg_obj("*","CFG_STRING","local_cfg_obj of seq2",0)

and use get_cfg for getting the configuration with the string.

ranjith.palavarapu
Offline
Academy Total Access User
Joined: 03/11/2010
Posts: 3
Re: can the ovm_do will do randomization of objects inside the class for which we did ovm_do

Thanks Sharan,

your suggestion seems simpler and easy to implement....