covergroup CovPort;
options.auto_bin_max = 8; //所有的coverpoint auto_bin數量是8
coverpoint tr.port
{ option.auto_bin_max = 2} //特定的covepoint auto_bin數量2
endgroup
covergroup CovKind;
coverpoint tr.kind{
bins zero = {0}; //1個倉代表kind==0
bins lo = {[1:3] , 5}; //1個倉代表1:3和5
bins hi[] = {[8:$]}; //8個獨立的倉代表8:15
bins misc = default; //1個倉代表剩餘所有值
} //沒有分號
endgroup
注意coverpoint定義使用{ }而不是begin...end大括號結尾沒帶分號,和end一樣。
covergroup CoverPort;
coverpoint port iff
(!bus_if.reset); //滿足條件纔可以採樣
endgroup
initial begin
CovPort ck = new();
#1ns;
ck.stop(); //關掉,任何採樣都不起作用
bus_if.reset = 1;
#100ns bus_if.reset = 0;
ck.reset();
...
end
針對任何一個covergoup實例,都可以進行使能採樣。 不同的coverpoint可以設置if的條件。
covergroup CoverPort;
coverpoint port{
(bins t1 = (0 => 1),(0 => 2),(0 => 3));
}
endgroup
bit [2:0] port;
covergroup CoverPort;
coverpoint port{
wildcsrd bins even = {3'b??0};
wildcsrd bins odd= {3'b??1};
}
endgroup
bit [2:0] low_ports_0_5; //只使用數值0-5
covergroup CoverPort;
coverpoint low_ports_0_5{
ignore_bins hi = {[6:7]}; //忽略數值6-7
}
endgroup
bit [2:0] low_ports_0_5; //只是用數值0-5
covergroup CoverPort;
coverpoint low_ports_0_5{
illegal_bins hi {[6:7]}; //如果出現6-7便會報錯
}
endgroup
class Transaction;
rand bit [3:0] kind;
rand bit [2:0] port;
endclass
Transaction tr;
covergroup CovPort;
kind: coverpoint tr.kind;
kind: coverpoint tr.port;
cross kind, port;
endgroup
covergroup Covport;
port: coverpoint tr.port
{bins port[] = {[0:$]}; //0-8個bin
}
kind:coverpoint tr.kind { //kind11個bin
bins zero = {0};
bins lo = {[1:3]};
bins hi[] = {[8:$]};
bins misc = default;
}
cross kind, port{
ignore_bins hi = binsof(port) intersect{7}; 對於port來說爲7時和kind所有組合都排除
ignore_bins md = binsof(port) intersect{0} && binsof(port) intersect{9:11};
ignore_bins lo = binsof(kind.lo) ;
}
endgroup
class Transaction;
rand bit a,b;
endclass
covergroup CrossBinName;
a: coverpoint tr.a
{bins a0 = {0};
bins a1 = {1};
option.weight = 0;} //不計算覆蓋率
b: coverpoint t.b
{ bins b0 = {0};
bins b1 = {1};
option.weight = 0;} //不計算覆蓋率
ab: cross a,b
{ bins a0b0 = binsof(a.a0) && binsof(b.b0); //指定一個狀態
binsof(b.b0);
bins a1b0 = binsif(a.a1) && binsof(b.b0);
bina b1 = binsof(b.b1);}
endgroup