Q:
class cg ;
int skew_val_vl[20];
covergroup skew_val_cg (int skew_val_vl);
coverpoint skew_val_vl {
bins skew_range_1 ={[124:0]};
bins skew_range_2 ={[325:125]};
bins skew_range_3 ={[526:326]};
bins skew_range_oor ={[1100:929]};
}
endgroup: skew_val_cg
function new(string name, uvm_component parent =null);
super.new(name, parent);
foreach(skew_val_vl[i])
skew_val_cg skew_cg[i]=new(skew_val_vl[i]); //getting error for this line
endfunction// new
endclass
A:
上面写法会报error ,因为
A covergroup declaration within a class is an embedded covergroup declaration. An embedded
covergroup declaration declares an anonymous covergroup type and an instance variable of the
anonymous type. The covergroup_identifier defines the name of the instance variable. In the above
example, a variable skew_val_cg (of the anonymous coverage group) is implicitly declared.
推荐用法:(covergroup写在class外面)
covergroup skew_val_cg ( ref int skew_val_vl); //一定要加ref
coverpoint skew_val_vl {
bins skew_range_1 ={[124:0]};
bins skew_range_2 ={[325:125]};
bins skew_range_3 ={[526:326]};
bins skew_range_oor ={[1100:929]};
bins d = default;
}
endgroup: skew_val_cg
default bins所cover的值是coverpoint变量所没有在其它bins中出现过的值,default bins 不会被用于计算covergroup覆盖率值
class cg;
glb_cfg cfg;
int skew_val_vl[20];
skew_val_cg sv_cg[20];
function new(string name, uvm_component parent =null);
super.new(name, parent);
foreach(sv_cg[ii])
sv_cg[ii]=new(skew_val_vl[ii]);
endfunction// new
function sample_sig();
foreach(sv_cg[ii]) begin
skew_val_vl[ii] = cfg.skew_val_vl[ii]; //先更新变量的值,再sample
sv_cg[ii].sample();
end
endfunction
endclass
另外一种用法:override sample function
covergroup test_grp with function sample(bt_trans tr);
option.per_instance = 1;
aa:coverpoint(tr.aa){
bins aa = {1};
}
endgroup
class sub extends uvm_subscriber;
test_grp test_grp1;
function new(string name = "sub",uvm_component parent);
super.new(name,parent);
test_grp1 = new();
endfunction
...
task aa_cov(bt_trans tr);
if(vif.a_re ==1)begin
test_grp1.sample(tr);
end
endtask
endclass
通过给sample 函数传参数来实现
再来一个例子,传interface
covergroup fifo_depth(int fifo_d) with function sample(bit wcs,bit waddr);
option.per_instance = 1;
aa:coverpoint(waddr)iff(wcs ==1){
bins udb[] = {[0:fifo_d-1]};
}
endgroup
class sub extends uvm_subscriber;
fifo_depth test_grp1;
function new(string name = "sub",uvm_component parent);
super.new(name,parent);
test_grp1 = new(10);
endfunction
...
task aa_cov(bt_trans tr);
if(vif.a_re ==1)begin
test_grp1.sample(vif.wr_en,vif.waddr);
end
endtask
endclass