通用的covergroup(带参数的covergroup)
构建通用化的covergroup需要使用参数,在创建cg实例时,将需要的特征通过参数传递进入,从而创建符合特殊要求的cg。
这样就可以在例化时选择要采样的变量。这样可以使用同一个coverpoint语句对多个变量采样,只需要将covergroup例化多份。
covergroup cg_ref (ref bit [1:0] ref_test) ;
ref_cp : coverpoint ref_test {
bins ref_bins = {0,2};
}
endgroup
calss A;
rand bit [1:0] a1;
rand bit [1:0] a2;
rand bit [1:0] a3
endclass
module test;
bit [1:0] mode;
A a_inst = new();
cg_ref cg_inst_1 = new(mode);
cg_ref cg_inst_2 = new(a_inst.a1);
cg_ref cg_inst_3 = new(a_inst.a2);
initial begin
repeat(5) begin
mode = $random;
a_inst.randomize();
cg_inst_1.sample();
cg_inst_2.sample();
cg_inst_3.sample();
end
end
endmodule
几点限制:
- 作为参数的变量的格式需要和参数是一致的。
- 定义covergroup的时候传递的变量参数需要带上ref关键字,否则无法正确采样
- 多个covergroup的实例的覆盖率会总结在一起,如果需要分开打印,需要在covergroup中加上option.per_instrance= 1。
也可以将一个类实例作为参数传递进去
calss A;
rand bit [1:0] a1;
rand bit [1:0] a2;
rand bit [1:0] a3
endclass
covergroup cg_ref (ref A inst) ;
ref_cp : coverpoint inst.a1 {
bins ref_bins = {0,2};
}
endgroup
module test;
bit [1:0] mode;
A a_inst = new();
cg_ref cg_inst_1 = new(a_inst);
initial begin
repeat(5) begin
a_inst.randomize();
cg_inst_1.sample();
end
end
endmodule
这样最后会对实例a_inst中的a1变量进行采样。
此外上述的cg中的容器是一样的,每个cg实例最后能cover到的值范围是一致的,如果想改变cover的范围,就像下面一样做:
covergroup cg(ref int array, int low, int high ) @(clk);
coverpoint// sample variable passed by reference
{
bins s = { [low : high] };
}
endgroup
int A, B;
cg rgc1 = new( A, 0, 50 );// cover A in range 0 to 50
cg rgc2 = new( B, 120, 600 );// cover B in range 120 to 600
这里可以看出如果想传递coverpoint变量就得使用ref关键字,如果只是传递参数就不需要。
关于coverpoint中队列bins
不指定尺寸的队列型bins会为bins描述的值的个数创建对应个数的bins,每个bins监视一个值。
指定尺寸的队列型bins会产生指定个数的bins,会将描述的值均分到各个bins中
bit [2:0] data
covergroup cg_data;
cp_data : coverpoint data {
bins data_bins_1[ ] = {[$:4]};
//会自动产生5个bins,每个bins包含一个数值,对应0,1,2,3,4
bins data_bins_2[2] = {[2:4],[5:7]};
// 限制了该队列只有两个容器,数值从2,3,4,5,6,7均分,第一个包含2,3,4,第二个包含5,6,7
bins data_bins_3[3] = {[0:2], [4:7]};
//该队列左边表达式有7个值,但要分到三个容器里,一般会把剩下的值放到最后的容器里
//最终三个容器对应值为{0,1}, {2,4}, {5,6,7}
bins data_bins_4[] = {[0:7]};
bins data_bins_5 = {[0:7]};
//上面两的结果是不同的,第一个会为0~7共8个值产生8个容器,每个容器对应不同的值,
//这与自创建容器得到的结果一致
//而第二个只会有一个容器,其值是一个范围[0:7],data落在这个范围则该容器被击中
bins data_bins_6[] = ( 3,4 => 5,7 );
//创建了四个transition bins,分别覆盖(3=>5),(3=>7), (4=>5),(4=>7)
}
endgroup
coverpoint的变量是枚举类型
coverpoint的变量需要时整数型的,自然也能对枚举类型的变量进行采样
typedef enum { A,B,C,D } alpha;
program main;
alpha y;
alpha values[$]= '{A,B,C};
covergroup cg;
cover_point_y : coverpoint y;
endgroup
cg cg_inst = new();
initial
foreach(values[i])
begin
y = values[i];
cg_inst.sample();
end
endprogram
Coverage report:
---------------------
VARIABLE : cover_point_y
Expected : 4
Covered : 3
Percent: 75.00
Uncovered bins
--------------------
auto_D
Covered bins
--------------------
auto_C
auto_B
auto_A
default bins
default bins所cover的值是coverpoint变量所没有在其它bins中出现过的值,比如下面例子中的default bins的cover值是y除[0:4]以外的值,default bins 不会被用于计算covergroup覆盖率值
program main;
bit [0:3] y;
bit [0:2] values[$]= '{3,5,6};
covergroup cg;
cover_point_y : coverpoint y {
bins a[2] = {[0:4]};
bins d = default;
}
endgroup
cg cg_inst = new();
initial
foreach(values[i])
begin
y = values[i];
cg_inst.sample();
end
endprogram
http://www.testbench.in/CO_09_TRANSITION_BINS.html
不同仿真器的覆盖率报告生成命令:
http://www.testbench.in/CO_04_COVER_POINTS.html