Functional Coverage Notes, Bins Caluclation, Bins Types
Functional Coverage Notes, Bins Caluclation, Bins Types
3) When the bug rate starts dropping,the beginning has come to an end.
Functional Coverage:
1) Used to measure the quality of design and Verification.
2) Functional coverage deals with covering design functionality.
1) Define covergroup
2) Coverage points
3) Bins
4) Cross coverage
COVERGROUP:
Covergroup is a user defined construct. That encapsulates coverage model specification.
A covergroup can be defined in a program,class,module,interface.
Covergroup encapsulates the specification of
Syntax :
1) Basic covergroup syntax:
endgroup
…………………
2) Covergroup syntax with clocking event:
a : coverpoint addr;
A covergroup can have one or more coverage points that can be labled.
Each coverpoint associated with single or multiple bins that can be explicitly defined.
Syntax:
endgroup
Coverpoint label is optional.if we are not specified any label.simulator provides its own
label.(Which make no sense).
BINS
Bins is something to collect coverage information.
The goal of functional coverage analysis is to achieve sufficient coverage on all the defined
bins to ensure thorough verification of the design.
If a certain bin is never hit, it indicates that the corresponding condition or value has not
been exercised in the testbench, and more test cases might be needed to cover that
particular scenario.
Implicit bins:
While defining coverpoint,if you do not specify any bins system verilog will automatically
create bins.
For any coverage pont, N is 2^M where M is the number of bits required to represent the
variable.
Ex:
class coverage;
bit[2:0] addr;
covergroup cg;
endgroup
function new();
cg=new();
endfunction
endclass
…………………………………..
Explicit bins:
covergroup cg;
coverpoint addr{
b[1]=4
b[2]=5
c[1]=6
c[2]=7,8
d[1] = 9
d[2]=10;
d[3]=empty
bins other = default; // add everything else that’s not covered by bins above
//Default Bins: A coverpoint can also have a default bin that captures
all values not covered by other explicit bins.
Endgroup
CROSS COVERAGE
1) Cross coverage is specified between two or more coverpoints variable.
2) Cross coverage is allowed only between coverpoints defined within the same
covergroup.
3) Expression cannot be used directly in a cross
4) Cross coverage is a combination of coverpoints and variables also.
5) When variable is used without a defined coverpoint for the variable,a
coverpoint is explicitly covered.
Example 1:
covergroup cg;
c1 : coverpont offset {bins a[]={[0:3]};} //4 bins for 4 values (0,1,2,3) of offset
c2 : coverpoint addr { bins b[]= {[0:3]};} //4 bins of 4 values (0,1,2,3) of addr
endgroup
Assume that addr==0 has been covered and offset==0 also has been
covered but if addr==0 && offset==0 never happened together
(not necessarily at the same clock) then the cross of addr[0] and offset[0]
will be empty.
Example 2)
C2 : coverpoint addr
{
bins a= {[0:7]}; //Explicit bins : a covers addr values 0 to 7
endgroup
Note: the default auto_bin_max of 64 does not apply to cross. So cross will create as many
bins as required. So we need to filter those bins.
1) Cross using ignore_bins
2) Cross using with clause
3) Cross of transition
TRANSITION COVERAGE
Transition coverage is a powerful tool for capturing and analyzing state changes in
sequential circuits, and it helps ensure that the design is thoroughly tested for all
possible transitions.
Example:
C1 : coverpoint addr
{
bins a = (8'h00 => 8'hff); // addr is 00 at this posedge clk and it should be ff at the
next posedge clk
C2 : coverpoint data;
{
bins b =(1'b1 => 1'b0); // data is 1 followed by 0 at successive sample points
}
C1C2 : cross C1,C2; // This means that the following condition is met that the cross
will be covered
addr=00 && data=1 at this posedge clk
and at the next posedge clk
addr=ff && data=0
endgroup
……………………………………………….
Example 2
}
--------------------------
Example 3
C1 : coverpoint addr
{
bins a[] = (1,2 => 3,4); // This is equal to 4 transitions(1=>3,1=>4,2=>3,2=>4)
WILDCARD BINS
Wildcard is a keyword associated with bins.
Wildcard characters are x and z or ? each of which evaluate to 0 and 1.
Value of few bits from vector do not effect functionaity.
Ex: We can use this types of bins for priority encoder.
Example:
wildcart bins c=(2'b0x => 2'b1x); // only 1 bin c is used for the transition
}
endgroup
IGNORE BINS
All values or transitions associated with ignore_bins are excluded from coverage
Example:
ILLEGAL BINS
All values or transitions associated with illegal_bins are excluded from coverage
and will give a run time error if encountered.
Example:
}
Endgroup
WITH CLAUSE
Allows creation of bins if condition specified with clause method.
Example:
module tb;
bit [3:0]a;
initial begin
cg cov=new();
repeat(10) begin
a=$random;
cov.sample();
$display("a=%0d",a);
#1;
end
end
endmodule
COVERGROUP COVERAGE
# =============================================================
# | Covergroup | Hits | Goal / | Status |
# | | | At Least | |
# =============================================================
# | TYPE /tb/cg | 25.000% | 100.000% | Uncovered |
# =============================================================
# | INSTANCE <UNNAMED1> | 25.000% | 100.000% | Uncovered |
# |--------------------------|---------|----------|-----------|
# | COVERPOINT <UNNAMED1>::a | 25.000% | 100.000% | Uncovered |
# |--------------------------|---------|----------|-----------|
# | bin used_a[0] | 0 | 1 | Zero |
# | bin used_a[2] | 1 | 1 | Covered |
# | bin used_a[4] | 1 | 1 | Covered |
# | bin used_a[6] | 0 | 1 | Zero |
# | bin used_a[8] | 0 | 1 | Zero |
# | bin used_a[10] | 0 | 1 | Zero |
# | bin used_a[12] | 0 | 1 | Zero |
# | bin used_a[14] | 0 | 1 | Zero |
# =============================================================
https://www.edaplayground.com/x/SJ_G
Example :
module tb;
bit [3:0]a;
covergroup cg;
option.per_instance=1;
coverpoint a{
bins used_a[]={[1:10]} with (item%2==0); // 2,4,6,8,10
}
endgroup
initial begin
cg cov=new();
repeat(10) begin
a=$random;
cov.sample();
$display("a=%0d",a);
#1;
end
end
endmodule
COVERGROUP COVERAGE
# =============================================================
# | Covergroup | Hits | Goal / | Status |
# | | | At Least | |
# =============================================================
# | TYPE /tb/cg | 40.000% | 100.000% | Uncovered |
# =============================================================
# | INSTANCE <UNNAMED1> | 40.000% | 100.000% | Uncovered |
# |--------------------------|---------|----------|-----------|
# | COVERPOINT <UNNAMED1>::a | 40.000% | 100.000% | Uncovered |
# |--------------------------|---------|----------|-----------|
# | bin used_a[4] | 1 | 1 | Covered |
# | bin used_a[6] | 0 | 1 | Zero |
# | bin used_a[8] | 0 | 1 | Zero |
# | bin used_a[10] | 0 | 1 | Zero |
# =============================================================
DEFAULT BINS
suppose variable is 4 bits and bins b0 defined 0 to 12. So, 13
to 15 value will be cover under default bins.
Example:
module tb;
bit [3:0]a;
covergroup cg;
option.per_instance=1;
coverpoint a{
bins used_a[]={[0:3]};
bins used_a1[]={[6:12]};
bins unused_a=default;
}
endgroup
initial begin
cg cov=new();
repeat(10) begin
a=$random;
cov.sample();
$display("a=%0d",a);
#1;
end
end
endmodule
COVERGROUP COVERAGE
# =============================================================
# | Covergroup | Hits | Goal / | Status |
# | | | At Least | |
# =============================================================
# | TYPE /tb/cg | 36.363% | 100.000% | Uncovered |
# =============================================================
# | INSTANCE <UNNAMED1> | 36.363% | 100.000% | Uncovered |
# |--------------------------|---------|----------|-----------|
# | COVERPOINT <UNNAMED1>::a | 36.363% | 100.000% | Uncovered |
# |--------------------------|---------|----------|-----------|
# | bin used_a[0] | 0 | 1 | Zero |
# | bin used_a[1] | 2 | 1 | Covered |
# | bin used_a[2] | 1 | 1 | Covered |
# | bin used_a[3] | 1 | 1 | Covered |
# | bin used_a1[6] | 0 | 1 | Zero |
# | bin used_a1[7] | 0 | 1 | Zero |
# | bin used_a1[8] | 0 | 1 | Zero |
# | bin used_a1[9] | 1 | 1 | Covered |
# | bin used_a1[10] | 0 | 1 | Zero |
# | bin used_a1[11] | 0 | 1 | Zero |
# | bin used_a1[12] | 0 | 1 | Zero |
# | default bin unused_a | 5 | - | Occurred |
# =============================================================
https://www.edaplayground.com/x/s7Lg
Sample()
Get_coverage
Get_instance_coverage()
Set_instance_name(string)
Start()
Stop()
Example:
bit a,b;
covergroup cg;
C1 : coverpoint a;
C2 : coverpoint b;
endgroup
cg cov = new();
Option.<option_name> = <expression>
Option.comment
Option.weight
Option.auto_bin_max
a[0]= 3,4
a[1]=5,6
a[2]= 7,3,4,5
bit [2:0] a;
covergroup cg;
option.per_instance=1;
coverpoint a{
bins a[3] = {[3:$],3,4,5};
}
endgroup
initial
begin
cg cov=new();
repeat(10)
begin
a=$random;
cov.sample();
$display("a=%0d",a);
#1;
end
end
endmodule
COVERGROUP COVERAGE
# ============================================================
# | Covergroup | Hits | Goal / | Status |
# | | | At Least | |
# ============================================================
# | TYPE /tb/cg | 100.000% | 100.000% | Covered |
# ============================================================
# | INSTANCE <UNNAMED1> | 100.000% | 100.000% | Covered |
# |--------------------------|----------|----------|---------|
# | COVERPOINT <UNNAMED1>::a | 100.000% | 100.000% | Covered |
# |--------------------------|----------|----------|---------|
# | bin a[0] | 2 | 1 | Covered |
# | bin a[1] | 4 | 1 | Covered |
# | bin a[2] | 6 | 1 | Covered |
# ============================================================
https://www.edaplayground.com/x/npaw
covergroup cg;
option.per_instance=1;
coverpoint a{
bins a={0,[3:7]};
}
endgroup
initial
begin
cg cov=new();
repeat(10)
begin
a=$random;
cov.sample();
$display("a=%0d",a);
#1;
end
end
endmodule
COVERGROUP COVERAGE
# ============================================================
# | Covergroup | Hits | Goal / | Status |
# | | | At Least | |
# ============================================================
# | TYPE /tb/cg | 100.000% | 100.000% | Covered |
# ============================================================
# | INSTANCE <UNNAMED1> | 100.000% | 100.000% | Covered |
# |--------------------------|----------|----------|---------|
# | COVERPOINT <UNNAMED1>::a | 100.000% | 100.000% | Covered |
# |--------------------------|----------|----------|---------|
# | bin a | 6 | 1 | Covered |
# ============================================================
https://www.edaplayground.com/x/M_cG
module tb;
bit a;
covergroup cg;
option.per_instance=1;
coverpoint a{
bins b0={0,1};
}
endgroup
initial begin
cg cov=new();
repeat(1) begin
a=$random;
cov.sample();
$display("a=%0d",a);
#1;
end
end
endmodule
COVERGROUP COVERAGE
# ============================================================
# | Covergroup | Hits | Goal / | Status |
# | | | At Least | |
# ============================================================
# | TYPE /tb/cg | 100.000% | 100.000% | Covered |
# ============================================================
# | INSTANCE <UNNAMED1> | 100.000% | 100.000% | Covered |
# |--------------------------|----------|----------|---------|
# | COVERPOINT <UNNAMED1>::a | 100.000% | 100.000% | Covered |
# |--------------------------|----------|----------|---------|
# | bin b0 | 1 | 1 | Covered |
# ============================================================
#
https://www.edaplayground.com/x/Sqme
initial begin
cg cov=new();
repeat(5) begin
temp=$random();
cov.sample();
$display("var1=%s",var1.name);
#1;
end
end
endmodule
COVERGROUP COVERAGE
# ===============================================================
# | Covergroup | Hits | Goal / | Status |
# | | | At Least | |
# ===============================================================
# | TYPE /tb/cg | 100.000% | 100.000% | Covered |
# ===============================================================
# | INSTANCE <UNNAMED1> | 100.000% | 100.000% | Covered |
# |-----------------------------|----------|----------|---------|
# | COVERPOINT <UNNAMED1>::var1 | 100.000% | 100.000% | Covered |
# |-----------------------------|----------|----------|---------|
# | bin b0 | 1 | 1 | Covered |
# | bin b1 | 3 | 1 | Covered |
https://www.edaplayground.com/x/GZzK
covergroup cg;
option.per_instance=1;
coverpoint a{
bins a[]={[3:$],3,4,5};
}
endgroup
initial begin
cg cov=new();
repeat(10) begin
a=$random;
cov.sample();
$display("a=%0d",a);
#1;
end
end
endmodule
COVERGROUP COVERAGE
# =============================================================
# | Covergroup | Hits | Goal / | Status |
# | | | At Least | |
# =============================================================
# | TYPE /tb/cg | 60.000% | 100.000% | Uncovered |
# =============================================================
# | INSTANCE <UNNAMED1> | 60.000% | 100.000% | Uncovered |
# |--------------------------|---------|----------|-----------|
# | COVERPOINT <UNNAMED1>::a | 60.000% | 100.000% | Uncovered |
# |--------------------------|---------|----------|-----------|
# | bin a[3] | 1 | 1 | Covered |
# | bin a[4] | 1 | 1 | Covered |
# | bin a[5] | 4 | 1 | Covered |
# | bin a[6] | 0 | 1 | Zero |
# | bin a[7] | 0 | 1 | Zero |
# =============================================================
Total bins 3 to 7 is 5
Total hit =3
%coverage =60%
https://www.edaplayground.com/x/ETxD
Example 6)
module tb;
reg [7:0] a; /// 00 01 10 11 -> 0 1 2 3
reg clk = 0;
integer i = 0;
initial begin
#100;
$finish();
end
covergroup c;
option.per_instance=1;
coverpoint a; // implicit bin (4 bins)
endgroup
initial begin
c ci = new();
for(i = 0; i < 10; i++) begin
@(posedge clk);
a = $urandom();
$info("Value of a : %0d", a);
ci.sample();
end
end
endmodule
COVERGROUP COVERAGE
# =============================================================
# | Covergroup | Hits | Goal / | Status |
# | | | At Least | |
# =============================================================
# | TYPE /tb/c | 12.500% | 100.000% | Uncovered |
# =============================================================
# | INSTANCE <UNNAMED1> | 12.500% | 100.000% | Uncovered |
# |--------------------------|---------|----------|-----------|
# | COVERPOINT <UNNAMED1>::a | 12.500% | 100.000% | Uncovered |
# |--------------------------|---------|----------|-----------|
# | bin auto[0:3] | 1 | 1 | Covered |
# | bin auto[4:7] | 0 | 1 | Zero |
# | bin auto[8:11] | 1 | 1 | Covered |
# | bin auto[12:15] | 0 | 1 | Zero |
# | bin auto[16:19] | 0 | 1 | Zero |
# | bin auto[20:23] | 0 | 1 | Zero |
# | bin auto[24:27] | 0 | 1 | Zero |
# | bin auto[28:31] | 0 | 1 | Zero |
# | bin auto[32:35] | 0 | 1 | Zero |
# | bin auto[36:39] | 0 | 1 | Zero |
# | bin auto[40:43] | 0 | 1 | Zero |
# | bin auto[44:47] | 0 | 1 | Zero |
# | bin auto[48:51] | 0 | 1 | Zero |
# | bin auto[52:55] | 0 | 1 | Zero |
# | bin auto[56:59] | 0 | 1 | Zero |
# | bin auto[60:63] | 0 | 1 | Zero |
# | bin auto[64:67] | 1 | 1 | Covered |
# | bin auto[68:71] | 0 | 1 | Zero |
# | bin auto[72:75] | 0 | 1 | Zero |
# | bin auto[76:79] | 2 | 1 | Covered |
# | bin auto[80:83] | 0 | 1 | Zero |
# | bin auto[84:87] | 1 | 1 | Covered |
# | bin auto[88:91] | 0 | 1 | Zero |
# | bin auto[92:95] | 0 | 1 | Zero |
# | bin auto[96:99] | 0 | 1 | Zero |
# | bin auto[100:103] | 0 | 1 | Zero |
# | bin auto[104:107] | 0 | 1 | Zero |
# | bin auto[108:111] | 0 | 1 | Zero |
# | bin auto[112:115] | 1 | 1 | Covered |
# | bin auto[116:119] | 0 | 1 | Zero |
# | bin auto[120:123] | 0 | 1 | Zero |
# | bin auto[124:127] | 0 | 1 | Zero |
# | bin auto[128:131] | 0 | 1 | Zero |
# | bin auto[132:135] | 0 | 1 | Zero |
# | bin auto[136:139] | 0 | 1 | Zero |
# | bin auto[140:143] | 0 | 1 | Zero |
# | bin auto[144:147] | 0 | 1 | Zero |
# | bin auto[148:151] | 0 | 1 | Zero |
# | bin auto[152:155] | 0 | 1 | Zero |
# | bin auto[156:159] | 0 | 1 | Zero |
# | bin auto[160:163] | 0 | 1 | Zero |
# | bin auto[164:167] | 0 | 1 | Zero |
# | bin auto[168:171] | 2 | 1 | Covered |
# | bin auto[172:175] | 0 | 1 | Zero |
# | bin auto[176:179] | 0 | 1 | Zero |
# | bin auto[180:183] | 0 | 1 | Zero |
# | bin auto[184:187] | 0 | 1 | Zero |
# | bin auto[188:191] | 0 | 1 | Zero |
# | bin auto[192:195] | 0 | 1 | Zero |
# | bin auto[196:199] | 0 | 1 | Zero |
# | bin auto[200:203] | 0 | 1 | Zero |
# | bin auto[204:207] | 0 | 1 | Zero |
# | bin auto[208:211] | 0 | 1 | Zero |
# | bin auto[212:215] | 0 | 1 | Zero |
# | bin auto[216:219] | 0 | 1 | Zero |
# | bin auto[220:223] | 0 | 1 | Zero |
# | bin auto[224:227] | 0 | 1 | Zero |
# | bin auto[228:231] | 1 | 1 | Covered |
# | bin auto[232:235] | 0 | 1 | Zero |
# | bin auto[236:239] | 0 | 1 | Zero |
# | bin auto[240:243] | 0 | 1 | Zero |
# | bin auto[244:247] | 0 | 1 | Zero |
# | bin auto[248:251] | 0 | 1 | Zero |
# | bin auto[252:255] | 0 | 1 | Zero |
# =============================================================
https://www.edaplayground.com/x/hTtW
module tb;
bit [1:0]a,b;
covergroup cg;
coverpoint a{
bins b0={0};
bins b1={2};
}
coverpoint b{
bins b0={1};
}
endgroup
initial begin
cg cov=new();
repeat(5) begin
a=$random;
b=$random;
cov.sample();
$display("a=%0d, b=%0d",a,b);
#1;
end
end
endmodule
COVERGROUP COVERAGE
# ================================================
# | Covergroup | Hits | Goal / | Status |
# | | | At Least | |
# ================================================
# | TYPE /tb/cg | 75.000% | 100.000% | Uncovered |
# ================================================
https://www.edaplayground.com/x/RpJK