Jump to content

Constraining Sequencer from testcase

Recommended Posts

Hi ,


Sorry the heading should be Constraint Sequence from testcase


I am unable to change it , seen after posted


I am wondering to constrain my sequence from testcase, is there any good way of doing it ?

----------------------------Test Code----------------------------------------------\\
class card_test extends uvm_test;

task run_phase(uvm_phase phase);
    card_seq card_seq_i;
    repeat(3) begin
      card_seq_i = card_seq::type_id::create(.name("card_seq_i"), .contxt(get_full_name()));
      //assert(card_seq_i.randomize());// actual test case
      //assert(card_seq_i.randomize() with { card_seq_i.pkt_state == READY;}); // dedicated test
      `uvm_info("card_test", { "\n", card_seq_i.sprint() }, UVM_LOW)
      #10ns ;
   endtask: run_phase

The line 09 and 10 if chosen gives me error.


Thanks for help




Link to comment
Share on other sites

Hi Dave,


My apologizes for the same , below is the code snippet and errors:

class gift_boxed_jelly_beans_sequence extends uvm_sequence#(jelly_bean_transaction);
   rand int unsigned num_jelly_bean_flavors; // knob

   constraint num_jelly_bean_flavors_con { num_jelly_bean_flavors == 10; }

   function new(string name = "");
   endfunction: new

   task body();
      same_flavored_jelly_beans_sequence jb_seq;
      repeat (num_jelly_bean_flavors) begin
	 jb_seq = same_flavored_jelly_beans_sequence::type_id::create(.name("jb_seq"), .contxt(get_full_name()));
//	 `uvm_info("gift_boxed_jelly_beans_sequence", { "\n", jb_seq.sprint() },
//		   UVM_LOW)
   endtask: body

      `uvm_field_int(num_jelly_bean_flavors, UVM_ALL_ON)
endclass: gift_boxed_jelly_beans_sequence
class jelly_bean_test extends uvm_test;

task run_phase(uvm_phase phase);
      gift_boxed_jelly_beans_sequence jb_seq;

      jb_seq = gift_boxed_jelly_beans_sequence::type_id::create
	       (.name("jb_seq"), .contxt(get_full_name()));
      assert(jb_seq.randomize() with { jb_seq.num_jelly_bean_flavors == 1;});
      `uvm_info("jelly_bean_test", { "\n", jb_seq.sprint() }, UVM_LOW)
      #10ns ;
   endtask: run_phase
endclass: jelly_bean_test
UVM_INFO @ 0: reporter [RNTST] Running test jelly_bean_test...
      assert(jb_seq.randomize() with { jb_seq.num_jelly_bean_flavors == 1;});
ncsim: *W,SVRNDF (./jelly_bean_ex.sv,483|28): The randomize method call failed.
Observed simulation time : 0 FS + 33
ncsim: *W,RNDOCS: These constraints contribute to the set of conflicting constraints:

      assert(jb_seq.randomize() with { jb_seq.num_jelly_bean_flavors == 1;}); (./jelly_bean_ex.sv,483)
   constraint num_jelly_bean_flavors_con { num_jelly_bean_flavors == 10; } (./jelly_bean_ex.sv,182)
ncsim: *W,RNDOCS: These variables contribute to the set of conflicting constraints:

rand variables:
       num_jelly_bean_flavors [./jelly_bean_ex.sv, 180]

ncsim: *E,ASRTST (./jelly_bean_ex.sv,483): (time 0 FS) Assertion worklib.jelly_bean_pkg::jelly_bean_test::run_phase.__assert_6 has failed 
UVM_INFO jelly_bean_ex.sv(484) @ 0: uvm_test_top [jelly_bean_test] 

For the sake of reading I have placed only the sequence, test and error above . The full example is available at 




Hope this time i am able to provide my problem clearly




Link to comment
Share on other sites



the error message clearly indicates what is wrong:


  1. ncsim: *W,RNDOCS: These constraints contribute to the set of conflicting constraints:
  3. assert(jb_seq.randomize() with { jb_seq.num_jelly_bean_flavors == 1;}); (./jelly_bean_ex.sv,483)
  4. constraint num_jelly_bean_flavors_con { num_jelly_bean_flavors == 10; } (./jelly_bean_ex.sv,182)


num_jelly_bean_flavours cant be one and ten at the same time. 



Link to comment
Share on other sites



Thanks for replying, but can you tell how to resolve the error ????


I am basically overwriting a constraint from testcase.


I want it to have the value that is supplied from testcase.


So how does it creates conflict for two , test is obvious at high hierarchy so it can overwrite.


Please correct me if I am wrong .



Link to comment
Share on other sites

You can override constraints in a class hierarchy, but that's not what you're doing.



    class a;
        int i;
        constraint c { i == 10; }

  class b extends a;
      constraint c { i == 1 };

Note the constraints have the same name and are in a class hierarchy, so the class b constraint replaces the one in class a.


SV 2012 introduced soft constraints (constraints that will lose if in conflict with another strong constraint).




Link to comment
Share on other sites

Thanks Alan,


But I was wondering to override the constraints for testclass itself , for which I have now made many sequence_item and override one sequence_item  by other sequence_item in build phase of the test.


While the constraints are overrided in the sequences , for which i have to create many sequences with different constraints (I need).


Which I don't want. 


I wish I could do it like : 


testclass -> randomise any sequence -> with constraints supplied from here.


but it does not work

Link to comment
Share on other sites

One way to do it would be to make your base class constraint very wide, then narrow it down with extra constraints (thus avoiding a conflict). E.g.


 constraint c { i > 0 && i < 1000;}


You can then constrain to any value within 0 to 1000 without a conflict.


Alternatively you could use variables. There's nothing to stop you saying

rand int unsigned num_jelly_bean_flavors; // knob
constraint num_jelly_bean_flavors_con { num_jelly_bean_flavors == j; }

and then constraining j from outside the class.



Link to comment
Share on other sites

  • 2 weeks later...

If the sequence constraints are set up properly you could also disable the conflicting constraint on the sequence from the testcase.  This works best if the constraints are set up to only affect a single property because otherwise you need to recreate the constraints on the rest of the properties (your simple example demonstrates this).  For example, this would work:

jb_seq = gift_boxed_jelly_beans_sequence::type_id::create(.name("jb_seq"), .contxt(get_full_name()));

assert(jb_seq.randomize() with { jb_seq.num_jelly_bean_flavors == 1;});


Link to comment
Share on other sites

You may want to look at the new soft constraint feature of SV1800-2012. A soft constraint is automatically disabled when there is a conflicting constraint. However, then you lose a way of describing your intent. Did you intend to disable the constraint with a new one, or did you add a conflicting constraint by mistake and now you will no longer get an constraint failure.

Link to comment
Share on other sites

  • 2 weeks later...

hi Karandeep,


you can do one more thing.


you can use following approach,




seq.jelly_bean = 1.



In this case you need to overwrite the constraint, and not required to even extend the class


hope this will help you








code may not be executable

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.

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