Jump to content

how to randomize local variable for every new transaction with uvm_do_with


aputcha

Recommended Posts

class txn;

rand int size;

rand int length;

rand bit [31:0] addr;

end class

class my_seq extends base_seq

rand bit [31:0] total_bytes; <----------------- this is a local variable

virtual task body()

for (int i=1; i< sequence_length; i++) begin

`uvm_do_with(req, {

size inside {0, 1, 2};

length inside {[0:15]};

total_bytes == ((1<<size) * (length+1)); <----------------- gives constraint inconsistancy failure

})

end // for loop

endtask: body

endclass: my_seq

Link to comment
Share on other sites

Here is my suggestion:

class txn;
rand int size; 
rand int length;
rand bit [31:0] addr;
end class

class my_seq extends base_seq

rand bit [31:0] total_bytes;

virtual task body()
for (int i=1; i< sequence_length; i++) begin

 `uvm_create(req)

 void'(req.randomize() with {
  size inside {0, 1, 2};
  length inside {[0:15]};

 `uvm_send (req)

 void'(this.randomize() with { (total_bytes == ((1<<req.size) * (req.length+1));}

 end // for loop
endtask: body
endclass: my_seq
Edited by rafael.shirakawa
Link to comment
Share on other sites

I think, you can use req.size and req.length.

class txn;

rand int size;

rand int length;

rand bit [31:0] addr;

end class

class my_seq extends base_seq

rand bit [31:0] total_bytes;

virtual task body()

for (int i=1; i< sequence_length; i++) begin

`uvm_do_with(req, {req.size inside {0, 1, 2};

req.length inside {[0:15]};

total_bytes == ((1<<req.size) * (req.length+1)); })

end // for loop

endtask: body

endclass: my_seq

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...