简体   繁体   English

Specman:如何将列表约束为变量的所有迭代,但不仅如此?

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

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, ie to combine both constraints :我想要做的是约束 my_list 至少具有 var_a 和 var_b 的所有可能迭代,但不仅如此,即结合两个约束:

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

I suggest to create a helper list and constrain it to be a sublist of my_list:我建议创建一个 helper 列表并将其限制为 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.不确定这是否有效,但我希望最后一个约束是双向的。

One approach is to first generate list which contains only variations, and then append desired number of other elements, in post_generate.一种方法是首先生成仅包含变体的列表,然后在 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".在此代码之后,您的列表将包含您想要的所有变体,以及由“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.请注意,前 10 个元素 (0-9) 包含变体,其余列表元素是随机结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM