Functional Coverage
Functional Coverage
OVERAGE
Functional Coverage
Introduction to Coverage
Types of Coverage
1. Code Coverage
2. Functional Coverage
Code Coverage
Code coverage deals with covering design code metrics. It measures how many lines
of code have been exercised with respect to blocks, expressions, FSMs, and signal
toggling.
• Block Coverage: Checks how many lines of code have been covered.
• Expression Coverage: Ensures all combinations of inputs have been driven to
cover expressions completely.
• FSM Coverage: Verifies all state transitions are covered.
• Toggle Coverage: Ensures all bits in variables have changed their states.
Note:
• Code coverage does not indicate whether the code behavior is correct; it only
identifies uncovered lines, expressions, state transitions, dead code, etc.
• Verification engineers aim to achieve 100% code coverage.
• Industry tools are available to show covered and missing code in code
coverage.
Functional Coverage
Note:
covergroup <coverage_model_name>;
...
endgroup
A covergroup can have an optional list of arguments, which must also be specified in
the new operator.
covergroup cg (list_of_arguments);
...
endcovergroup
Coverpoint in Functional Coverage
A coverpoint is an integral expression or variable that must be covered when
sampling the covergroup. A covergroup can have one or more coverpoints, which
can be labeled. Each coverpoint is associated with single or multiple bins that can be
explicitly defined.
Syntax
covergroup <covergroup_name>;
<coverpoint_label>: coverpoint <coverpoint_name>;
<coverpoint_label>: coverpoint <coverpoint_name>;
...
endgroup
Example
Bins create a set of values for a particular range or all possible values for the specified
coverpoint variable.
Syntax
covergroup <covergroup_name>;
<coverpoint_label>: coverpoint <coverpoint_name> {bins <bin_name> =
{<values>} };
...
endgroup
Without Explicit Bins Declaration
module func_coverage;
logic [3:0] addr;
logic [2:0] data;
logic en;
covergroup c_group;
cp1: coverpoint addr;
cp2: coverpoint data;
cp3: coverpoint en;
endgroup
c_group cg = new();
...
endmodule
variables bins
en cp3.auto[0], cp1.auto[1]
covergroup c_group;
cp1: coverpoint addr {bins b1 = {1, 10, 12};
bins b2[] = {[2:9], 11};
bins b3[4] = {0:8};
}
cp2: coverpoint data {bins b1 = {4,$};
bins b2[] = {2, 3, 6};
}
cp3: coverpoint en {bins b1 = {1}; }
endgroup
c_group cg = new();
...
...
endmodule
variables bins Description
addr bins b1 = {1, 10, 12}; Constructs single bin for 1, 10, 12 value.
b3[2] = 3~4,
b3[3] = 5~7,
b2[0] = 2,
b2[1] = 3,
b2[2] = 6,
Example:
module func_coverage;
logic [3:0] data;
covergroup c_group;
cp1: coverpoint data {bins b1 = (2 => 5);
bins b2 = (2 => 10);
bins b3 = (3 => 8);
}
endgroup
c_group cg = new();
...
...
endmodule
Sequence of transitions
The sequence of transitions can be specified as <value1> => <value2> => <value3>
=> <value4>
Example:
module func_coverage;
logic [3:0] data;
covergroup c_group;
cp1: coverpoint data {bins b1 = (2 => 5 => 6);
bins b2 = (2 => 10 => 12);
bins b3 = (3 => 8 => 9 => 10);
}
endgroup
c_group cg = new();
...
...
endmodule
Set of transitions
The set of transitions can be specified as <transition_set1> => <transition_set2>
Example:
module func_coverage;
logic [3:0] data;
covergroup c_group;
cp1: coverpoint data {bins b1[] = (2,3 => 4,5);
}
endgroup
c_group cg = new();
...
...
endmodule
Consecutive repetition
The range of repetition can be specified as <transition_value> [*<repeat_value>]
Example:
module func_coverage;
logic [3:0] data;
covergroup c_group;
cp1: coverpoint data {bins b1[] = (4[*3]);
}
endgroup
c_group cg = new();
...
...
endmodule
Example:
module func_coverage;
logic [3:0] data;
covergroup c_group;
cp1: coverpoint data {bins b1[] = (4[*2:4]);
}
endgroup
c_group cg = new();
...
...
endmodule
Goto repetition
Example:
module func_coverage;
logic [3:0] data;
covergroup c_group;
cp1: coverpoint data {bins b1 = (2=>5[->3]=>7);
}
endgroup
c_group cg = new();
...
...
endmodule
Example:
module func_coverage;
logic [3:0] data;
covergroup c_group;
cp1: coverpoint data {bins b1 = (2=>5[=3]=>7);
}
endgroup
c_group cg = new();
...
...
endmodule
Ignore bins
The ignore bins are used to specify a set of values or transitions that can be excluded
from coverage.
Example:
module func_coverage;
logic [3:0] addr;
covergroup c_group;
cp1: coverpoint addr {ignore_bins b1 = {1, 10, 12};
ignore_bins b2 = {2=>3=>9};
}
endgroup
c_group cg = new();
...
...
endmodule
illegal_bins
The illegal bins are used to specify a set of values or transitions that can be marked
as illegal.
Example:
module func_coverage;
logic [3:0] addr;
covergroup c_group;
cp1: coverpoint addr {illegal_bins b1 = {1, 10, 12};
illegal_bins b2 = {2=>3=>9};
}
endgroup
c_group cg = new();
...
...
endmodule
Cross Coverage
Cross coverage allows creating a cross product (i.e., Cartesian product) between two
or more variables or coverage points within the same covergroup. In simple terms,
cross coverage is a set of cross-products of variables or coverage points.
Syntax
Example
Coverage Constructs
iff Construct
The iff construct allows excluding the coverpoint from coverage if an expression
evaluates to false.
Example
module func_coverage;
logic [3:0] addr;
covergroup c_group;
cp1: coverpoint addr iff (!reset_n); // coverpoint addr is covered when
reset_n is low.
endgroup
c_group cg = new();
...
endmodule
binsof and intersect Constructs in Functional Coverage
binsof Construct
The binsof construct yields bins of its expression, which can be a single variable or an
explicitly defined coverage point.
Syntax
binsof (<expression>)
Example
bit [7:0] var1, var2;
covergroup c_group @(posedge clk);
cp1: coverpoint var1 {
bins x1 = { [0:99] };
bins x2 = { [100:199] };
bins x3 = { [200:255] };
}
cp2: coverpoint var2 {
bins y1 = { [0:74] };
bins y2 = { [75:149] };
bins y3 = { [150:255] };
}
cp1_X_cp2: cross cp1, cp2 {
bins xy1 = binsof(cp1.x1);
bins xy2 = binsof(cp2.y2);
bins xy3 = binsof(cp1.x1) && binsof(cp2.y2);
bins xy4 = binsof(cp1.x1) || binsof(cp2.y2);
}
endgroup
<x1, y2>
• Cross Bin xy4: Results in 5 cross-products:
<x1, y1>, <x1, y2>, <x1, y3>, <x2, y2>, <x3, y2>
intersect Construct
The intersect construct is used with the binsof construct to include or exclude a set of
values of bins that intersect a desired set of values.
Syntax
Syntax Description
binsof(cp) intersect {r} The bins of coverpoint cp whose values intersect the range r.
!binsof(cp) intersect {r} The bins of coverpoint cp whose values do not intersect the range r.
Example
<x2, y1>, <x2, y2>, <x2, y3>, <x3, y1>, <x3, y2>, <x3, y3>
<x2, y1>, <x2, y2>, <x2, y3>, <x3, y1>, <x3, y2>, <x3, y3>
c_group cg = new();
initial begin
cg.start();
cg.set_inst_name("my_cg");
forever begin
cg.sample();
#5;
end
end
initial begin
$monitor("At time = %0t: addr = %0d, data = %0d", $time, addr, data);
repeat(5) begin
addr = $random;
data = $random;
#5;
end
cg.stop();
$display("Coverage = %f", cg.get_coverage());
$finish;
end
endmodule
Output:
At time = 0: addr = 36, data = 129
At time = 5: addr = 9, data = 99
At time = 10: addr = 13, data = 141
At time = 15: addr = 101, data = 18
At time = 20: addr = 1, data = 13
Coverage = 5.777995
System Descriptions
tasks/functions
$set_coverage_db_name Sets coverage information throughout the simulation
in a specified file name.
$get_coverage Returns 0 to 100 range real numbers as an overall
coverage of all coverage groups.
$load_coverage_db Loads cumulative coverage information of all coverage
groups from the given file name.
c_group cg = new();
initial begin
$set_coverage_db_name("my_cg");
forever begin
cg.sample();
#5;
end
end
initial begin
$monitor("At time = %0t: addr = %0d, data = %0d", $time, addr, data);
repeat(5) begin
addr = $random;
data = $random;
#5;
end
$display("Coverage = %f", $get_coverage());
$finish;
end
endmodule
Output:
At time = 0: addr = 36, data = 129
At time = 5: addr = 9, data = 99
At time = 10: addr = 13, data = 141
At time = 15: addr = 101, data = 18
At time = 20: addr = 1, data = 13
Coverage = 5.777995
Coverage options in Functional Coverage
The coverage options control the behavior of covergroup, coverpoint, and cross.
There are two types of options which are
Syntax:
option.<option_name> = <expression>;
Where,
module func_coverage;
bit [7:0] addr, data;
covergroup c_group;
option.per_instance = 1;
option.comment = "This is the comment";
c_group cg = new();
initial begin
forever begin
cg.sample();
#5;
end
end
initial begin
$monitor("At time = %0t: addr = %0d, data = %0d", $time, addr, data);
repeat(5) begin
addr = $random;
data = $random;
#5;
end
$display("Coverage = %f", cg.get_coverage());
$finish;
end
endmodule
Output:
At time = 0: addr = 36, data = 129
At time = 5: addr = 9, data = 99
At time = 10: addr = 13, data = 141
At time = 15: addr = 101, data = 18
At time = 20: addr = 1, data = 13
Coverage = 7.389323
Type B: Specific to the covergroup type as a whole
It specified a particular feature or property of the covergroup type as a whole. They
are analogous to static data members of classes.
Syntax:
type_option.<option_name> = <expression>;
Where,
[Default value =
0]
Example for specific to the covergroup type as a whole
module func_coverage;
bit [7:0] addr, data;
covergroup c_group;
option.per_instance = 1;
type_option.comment = "This is the comment";
type_option.strobe = 1;
c_group cg = new();
initial begin
forever begin
cg.sample();
#5;
end
end
initial begin
$monitor("At time = %0t: addr = %0d, data = %0d", $time, addr, data);
repeat(5) begin
addr = $random;
data = $random;
#5;
end
$display("Coverage = %f", cg.get_coverage());
$finish;
end
endmodule
Output:
At time = 0: addr = 36, data = 129
At time = 5: addr = 9, data = 99
At time = 10: addr = 13, data = 141
At time = 15: addr = 101, data = 18
At time = 20: addr = 1, data = 13
Coverage = 6.286621