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

问题描述

我定义了以下结构:

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

在另一个结构中,我实例化了该结构的列表:

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

    keep list_size >= 4;
};

我想做的是约束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;  
};

有什么办法可以实现?

谢谢

解决方法

我建议创建一个助手列表并将其限制为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;

不确定是否可行,但我希望最后一个约束是双向的。

,

一种方法是先生成仅包含变体的列表,然后在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;
   };

};


'>

使用此代码后,您的列表将具有您想要的所有变体,以及由“ 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 

请注意,前10个元素(0-9)包含变体,其余列表元素是随机结构。