Jump to content

constraining repeated sequence


Recommended Posts

I have a question on how to make it possible to constrain the items in a sequence that send a randomized number of items?

That is I have a sequence that has a rand member telling how many items to send. The item itself has rand members like size of the item.

I would like from the test case decide how the size of the items is randomized. I have a solution that kind of work but I wonder if it is a good approach especially since I do get this problem

Can-t-randomize-members-of-class-derived-from-uvm_sequence.

My repeate_seq sequence has a global member no_items which sets how many items to send. It then has two protected members pkt_size and ph_num which is used to randomize the data in each item.

In the test case you can make a new sequence class which extends from repeat_seq and change the constrains of pkt_size and ph_num and then use that new sequence in the test case. This make it possible for the test case to change how the packet size is randomized for each item.

Is there a better approach for this? The biggest problem I have with this approach that the tools I have tried seems to enforce that all constrains needs to be valid when specifying in the randomize function that I only want to randomize certain variable.

Below you can see some sample code which I have not tried to compile so it might include some syntax errors.

class repeate_seq extends uvm_sequence #(my_item);
  rand int no_items;
  
  protected rand int pkt_size;
  protected rand bit [1:0] ph_num;

  constraint c_valid_pkt_size{ pkt_size inside {[1:10240]}; }
  constraint c_valid_ph_num{ ph_num <= 2; }

  virtual task body();
    repeat(no_items) begin
      `uvm_create(req)
      assert(this.randomize(ph_num, pkt_size));    
      assert(req.randomize(array) with {array.size == pkt_size;});
      req.ph_num = ph_num;
      `uvm_send(req)
    end
  endtask : body
  
endclass

class repeate_seq_tc_01 extends repeate_seq;
  constraint c_tc_01{
    ph_num == 0;
    pkt_size < 1000;
  }
endclass

class tc_01 extends uvm_test;
  virtual task run_phase(uvm_phase phase);    
    repeate_seq_tc_01 my_seq = new();
    my_seq.randomize() with { no_items == 50; }    
    my_seq.start(my_sequencer);
  endtask
endclass
Edited by ryz
Link to comment
Share on other sites

After getting some more information on how constrain solving is done in Can-t-randomize-members-of-class-derived-from-uvm_sequence it seems that my proposal might not bee that good.

Doing an randomisation on it self with only some parameters turned on might lead to unexpected constrains solver errors. Since constrains on all member variables is checked when doing the randomization. The question how should you do this then?

Link to comment
Share on other sites

You should look at calling std::randomize(pk_num,pkt_size) with {} on just the variables you want to randomize. The do not even need to be rand variables.

Another suggestion would be to put the variables and constraints you want to randomize separately into a separate class. This is what's know in OOP as the "separation of concerns" principle.

Link to comment
Share on other sites

It seems the problem wouldn't be there if the item constraints were defined in the item class, and not in the sequence class. Another solution could be to make a local copy of sequence members not to be re-randomized. In this case, the sequence body could simply make a local copy of no_items, and call randomize() without parameters in the repeat loop.

Erling

Link to comment
Share on other sites

It seems the problem wouldn't be there if the item constraints were defined in the item class, and not in the sequence class.Erling

The test case could create an derived class of the item class and do the constrain there and then do a type override on the sequence to make sure it uses the new item. I think this should be doable I am not to familiar with the type override. It seems to be a little complex to write thought.

Link to comment
Share on other sites

The test case could create an derived class of the item class and do the constrain there and then do a type override on the sequence to make sure it uses the new item. I think this should be doable I am not to familiar with the type override. It seems to be a little complex to write thought.

An easier way could be to write a trivial repeater sequence parameterized with the item, and it could repeat all kinds of items.

Erling

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