Specman : how to constraint a list to be all iterations of a variable but not only?

295 Views Asked by At

I've defined the following struct :

struct my_struct {
    var_a : bit;
    var_b : bit;
}; 

In another struct, I've instantiated a list of this struct :

struct another_struct {
    my_list   : list of my_struct;
    list_size : uint;

    keep list_size >= 4;
};

What I want to do is to constraint my_list to have at least all the possible iterations of both var_a and var_b but not only, i.e. to combine both constraints :

extend another_struct {
    keep my_list.is_all_iterations(.var_a, .var_b);
    keep my_list.size() ==  list_size;  
};

Is there any way to achieve that ?

Thanks

2

There are 2 best solutions below

1
On

One approach is to first generate list which contains only variations, and then append desired number of other elements, in post_generate.

<'

struct mys_s {
   a: int [0..3];
   b: int [10, 11];
};

extend sys {
   mys_l: list of mys_s;
   keep mys_l.is_all_iterations(.a,.b);

   !rand_struct: mys_s;

   upper_limit: uint;
   keep upper_limit == 20;

   old_size: uint;
   keep old_size in [read_only(mys_l.size())];

   new_size: uint;
   keep new_size >= read_only(old_size);
   keep new_size < upper_limit;

   post_generate() is {
      for i from 1 to new_size-old_size {
         gen rand_struct;
         mys_l.add(rand_struct);
      };
   };


   run() is also {
      print mys_l;
   };

};


'>

Afer this code, your list will have all variations you wanted, but also arbitrary number of other structures, defined by the "upper_limit".

Output for random seed:

Starting the test ...
Running the test ...
  mys_l = 
item   type        a           b           
---------------------------------------------------------------------------
0.     mys_s       0           10          
1.     mys_s       0           11          
2.     mys_s       1           10          
3.     mys_s       1           11          
4.     mys_s       2           10          
5.     mys_s       2           11          
6.     mys_s       3           10          
7.     mys_s       3           11          
8.     mys_s       3           11          
9.     mys_s       3           10          
10.    mys_s       1           11          
11.    mys_s       1           11          
12.    mys_s       3           10          
13.    mys_s       2           11          
14.    mys_s       0           10          
15.    mys_s       2           11          
16.    mys_s       2           11          
17.    mys_s       2           11 

Note that the first 10 elements (0-9) contain variations, and remaining list elements are random sturctures.

0
On

I suggest to create a helper list and constrain it to be a sublist of my_list:

list_all_i: list of my_struct;
keep list_all_i.is_all_iterations(.var_a, .var_b);
keep list_all_i in my_list;

Not sure if that works, but I expect the last constraint to be bi-directional.