Functional Coverage
Functional Coverage
Code Coverage
Functional Coverage
Covergroup
The covergroup is just like user defined type construct that
encapsulates and specifies coverage. Each covergroup specification
can include the following components:
A clocking event that synchronizes the sampling of coverage points
1. A set of coverage points
2.Cross coverage between coverage points
3.Optional formal arguments
4.Coverage options
It can be defined in a package, module, program,interface or class.
Once defined multiple instances can be created using new
covergroup cg;
-- -endgroup
cg cg_inst = new; // cg_inst is instance of covergroup cg using new operator
SAMPLE
Coverage should be triggered to sample the
coverage values. Sampling can be done using
1. Any event expression -edge, variable
2. End-point of a sequence
3. Event can be omitted
4. Calling sample() method.
covergroup cg;
...
...
...
endgroup
cg cg_inst = new;
initial // or task or function or always block
begin
...
...
cg_inst.sample();
...
...
end
COVER POINTS
A covergroup can contain one or more
coverage points.
A coverage point can be an integral variable
or an integral expression.
A coverage point creates a hierarchical scope,
and can be optionally labeled. If the label is
specified then it designates the name of the
coverage point.
program main;
bit [0:2] y;
bit [0:2] values[$]= '{3,5,6};
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
Report:
VARIABLE : cover_point_y
Expected : 8
Covered : 3
Percent : 37.50.
NCSIM
ncverilog -sv -access +rwc -coverage
functional filename.sv
iccr iccr.cmd
iccr.cmd
load_test *
report_detail -instance -both -d *
Coverpoint Expression
Coverage Filter
The expression within the iff construct specifies an optional
condition that disables coverage for that cover point. If the guard
expression evaluates to false at a sampling point, the coverage
point is ignored.
For example:
covergroup cg;
coverpoint cp_varib iff(!reset); // filter condition
endgroup
Implicit Bins
While define cover point, if you do not specify any bins, then Implicit bins
are created. The number of bins creating can be controlled by
auto_bin_max parameter.
program main;
bit [0:2] y;
bit [0:2] values[$]= '{3,5,6};
covergroup cg;
cover_point_y : coverpoint y
{ option.auto_bin_max = 4 ; }
endgroup
cg cg_inst = new();
initial
foreach(values[i])
begin
y = values[i];
cg_inst.sample();
end
endprogram
In the above example, the auto_bin_max is declared as 4. So, the total possible values
are divided in 4 parts and each part correspoits to one bin.
The total possible values for variable "y" are 8. They are divided in to 4 groups.
Coverage report:
-------------------VARIABLE : cover_point_y
Expected : 4
Covered : 3
Percent: 75.00
Uncovered bins
-----------------auto[0:1]
Covered bins
-----------------auto[2:3]
auto[4:5]
auto[6:7]
In The above example, the variable "y" is enum data type and it can have 4
enum members A,B,C and D. Variable Y is assigned only 3 Enum members
A,B and C.
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
Explicit bin creation is recommended method. Not all values are interesting or relevant
in a cover point, so when the user knows the exact values he is going to cover, he can
use explicit bins. You can also name the bins.
program main;
bit [0:2] y;
bit [0:2] values[$]= '{3,5,6};
covergroup cg;
cover_point_y : coverpoint y {
bins a = {0,1};
bins b = {2,3};
bins c = {4,5};
bins d = {6,7};
}
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
-------------------a
Covered bins
-------------------b
c
d
Array Of Bins
To create a separate bin for each value (an array of bins) the square brackets, [],
must follow the bin name.
program main;
bit [0:2] y;
bit [0:2] values[$]= '{3,5,6};
covergroup cg;
cover_point_y : coverpoint y {
bins a[] = {[0:7]};
}
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 : 8
Covered : 3
Percent: 37.50
Uncovered bins
------------------a_0
a_1
a_2
a_4
a_7
Covered bins
------------------a_3
a_5
a_6
To create a fixed number of bins for a set of values, a number can be specified
inside the square brackets.
program main;
bit [0:3] y;
bit [0:2] values[$]= '{3,5,6};
covergroup cg;
cover_point_y : coverpoint y {
bins a[4] = {[0:7]};
}
endgroup
cg cg_inst = new();
initial
foreach(values[i])
begin
y = values[i];
cg_inst.sample();
end
endprogram
In the above example, variable y is 4 bit width vector. Total possible values for this
vector are 16.
But in the cover point bins, we have giving the interested range as 0 to 7. So the
coverage report is calculated over the range 0 to 7 only. In this example, we have
shown the number bins to be fixed to size 4.
Coverage report:
-------------------VARIABLE : cover_point_y
Expected : 4
Covered : 3
Percent: 75.00
Uncovered bins
------------------a[0:1]
Covered bins
-----------------a[2:3]
a[4:5]
a[6:7]
Default Bin
The default specification defines a bin that is associated with none of the defined value bins. The
default bin catches the values of the coverage point that do not lie within any of the defined bins.
However, the coverage calculation for a coverage point shall not take into account the coverage
captured by the default bin.
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
In the above example, we have specified only 2 bins to cover values from 0 to 4.
Rest of values are covered in default bin ~Sd~T which is not using in calculating the
coverage percentage.
Coverage report:
-------------------VARIABLE : cover_point_y
Expected : 2
Covered : 1
Percent: 50.00
Uncovered bins
-----------------a[0:1]
Covered bins
---------------a[2:4]
Default bin
----------------d
TRANSITION BINS
Transitional functional point bin is used to examine the
legal transitions of a value. SystemVerilog allows to
specifies one or more sets of ordered value transitions
of the coverage point.
Type of Transitions:
In the above example, 2 bins are created for covering the transition
of point "y" from 3 to 4 and other for 5 to 6. The variable y is given
the values and only the transition 5 to 6 is occurring.
Coverage report:
-------------------VARIABLE : cover_point_y
Expected : 2
Covered : 1
Percent: 50.00
Uncovered bins
-----------------tran_34
Covered bins
---------------tran_56
Sequence Of Transitions
A sequence of transitions is represented as:
value1 => value3 => value4 => value5
In this case, value1 is followed by value3,
followed by value4 and followed by value5. A
sequence can be
of any arbitrary length
program main;
bit [0:3] y;
bit [0:2] values[$]= '{3,5,6};
covergroup cg;
cover_point_y : coverpoint y {
bins tran_345 = (3=>4>=5);
bins tran_356 = (3=>5=>6);
}
endgroup
Coverage report:
-------------------VARIABLE : cover_point_y
Expected : 2
Covered : 1
Percent: 50.00
Uncovered bins
-----------------tran_345
Covered bins
----------------tran_356
Set Of Transitions
A set of transitions can be specified as:
range_list1 => range_list2
program main;
bit [0:3] y;
bit [0:2] values[$]= '{3,5,6};
covergroup cg;
cover_point_y : coverpoint y {
bins trans[] = (3,4=>5,6);
}
endgroup
Consecutive Repetitions
Consecutive repetitions of transitions are specified using
trans_item [* repeat_range ]
Here, trans_item is repeated for repeat_range times. For example,
3 [* 5]
is the same as
3=>3=>3=>3=>3
program main;
bit [0:3] y;
bit [0:2] values[$]= '{3,3,3,4,4};
covergroup cg;
cover_point_y : coverpoint y {
bins trans_3 = (3[*5]);
bins trans_4 = (4[*2]);
}
endgroup
Coverage report:
-------------------VARIABLE : cover_point_y
Expected : 2
Covered : 1
Percent: 50.00
Uncovered bins
-----------------trans_3
Covered bins
---------------trans_4
Range Of Repetition
program main;
bit [0:3] y;
bit [0:2] values[$]= '{4,5,3,3,3,3,6,7};
covergroup cg;
cover_point_y : coverpoint y {
bins trans_3[] = (3[*3:5]);
}
endgroup
Coverage report:
-------------------VARIABLE : cover_point_y
Expected : 3
Covered : 1
Percent: 33.33
Uncovered bins
-----------------tran_3:3[*3]
tran_3:3[*5]
Covered bins
---------------tran_3:3[*4]
Goto Repetition
The goto repetition is specified using: trans_item [-> repeat_range]. The
required number of occurrences of a particular value is specified by the
repeat_range. Any number of sample points can occur before the first
occurrence of the specified value and any number of sample points can occur
between each occurrence of the specified value. The transition following the
goto repetition must immediately follow the last occurrence of the
repetition.
For example:
3 [-> 3]
is the same as
...=>3...=>3...=>3
where the dots (...) represent any transition that does not contain the value
3.
A goto repetition followed by an additional value is represented as follows:
1 => 3 [ -> 3] => 5
is the same as
1...=>3...=>3...=>3 =>5
program main;
bit [0:3] y;
bit [0:2] values[$]= '{1,6,3,6,3,6,3,5};
covergroup cg;
cover_point_y : coverpoint y {
bins trans_3 = (1=>3[->3]=>5);
}
endgroup
Coverage report:
-------------------VARIABLE : cover_point_y
Expected : 1
Covered : 1
Percent: 100.00
program main;
bit [0:3] y;
bit [0:2] values[$]= '{1,6,3,6,3,6,5};
covergroup cg;
cover_point_y : coverpoint y {
bins trans_3 = (1=>3[=2]=>5);
}
endgroup
Coverage report:
-------------------VARIABLE : cover_point_y
Expected : 1
Covered : 1
Percent: 100.00
WILDCARD BINS
program main;
reg [0:3] y;
reg [0:3] values[$]= '{ 4'b1100,4'b1101,4'b1110,4'b1111};
covergroup cg;
cover_point_y : coverpoint y {
wildcard bins g12_15 = { 4'b11?? } ;
}
endgroup
Coverage report:
-------------------VARIABLE : cover_point_y
Expected : 1
Covered : 1
Percent: 100.00
Covered bin
--------------g12_15
Number of times g12_15 hit : 4
IGNORE BINS
A set of values or transitions associated with a
coverage-point can be explicitly excluded from
coverage by specifying them as ignore_bins.
program main;
bit [0:2] y;
bit [0:2] values[$]= '{1,6,3,7,3,4,3,5};
covergroup cg;
cover_point_y : coverpoint y {
ignore_bins ig = {1,2,3,4,5};
}
endgroup
Covered bins
---------------auto[6]
auto[7]
ILLEGAL BINS
A set of values or transitions associated with a coverage-point can be
marked as illegal by specifying them as illegal_bins. All values or
transitions associated with illegal bins are excluded from coverage. If an
illegal value or transition occurs, a runtime error is issued.
program main;
bit [0:2] y;
bit [0:2] values[$]= '{1,6,3,7,3,4,3,5};
covergroup cg;
cover_point_y : coverpoint y {
illegal_bins ib = {7};
}
endgroup
Result:
-----------** ERROR **
Illegal state bin ib of coverpoint cover_point_y in
covergroup cg got hit with value 0x7
CROSS COVERAGE
Cross allows keeping track of information which is received simultaneous on more than one
cover point. Cross coverage is specified using the cross construct.
program main;
bit [0:1] y;
bit [0:1] y_values[$]= '{1,3};
bit [0:1] z;
bit [0:1] z_values[$]= '{1,2};
covergroup cg;
cover_point_y : coverpoint y ;
cover_point_z : coverpoint z ;
cross_yz : cross cover_point_y,cover_point_z ;
endgroup
cg cg_inst = new();
initial
foreach(y_values[i])
begin
y = y_values[i];
z = z_values[i];
cg_inst.sample();
end
endprogram
User-defined bins for cross coverage are defined using bin select expressions.
Consider the following example code:
int i,j;
covergroup ct;
coverpoint i { bins i[] = { [0:1] }; }
coverpoint j { bins j[] = { [0:1] }; }
x1: cross i,j;
x2: cross i,j {
bins i_zero = binsof(i) intersect { 0 };
}
endgroup
Cross x1 has the following bins:
<i[0],j[0]>
<i[1],j[0]>
<i[0],j[1]>
<i[1],j[1]>
Cross x2 has the following bins:
i_zero
<i[1],j[0]>
<i[1],j[1]>
COVERAGE OPTIONS
Goal
Syntax :goal=number
default value: 100
Description :
Specifies the target goal for a covergroup instance or for a coverpoint or a cross of an instance.
Name
Syntax :name=string
default value:unique name
Description :
Specifies a name for the covergroup instance. If unspecified, a unique name for each instance is automatically
generated by the tool.
Comment
Syntax :comment=string
default value: ""
Description :
A comment that appears with a covergroup instance or with a coverpoint or cross of the covergroup instance. The comment is saved in the coverage
database and included in the coverage report.
At_least
Syntax :at_least=number
default value: 1
Minimum number of hits for each bin. A bin with a hit count that is less than number is not considered covered.
Detect_overlap
Syntax :detect_overlap=Boolean
default value: 0
When true, a warning is issued if there is an overlap between the range list (or transition list) of two bins of a coverpoint.
Auto_bin_max
Syntax :auto_bin_max=number
default value: 64
Maximum number of automatically created bins when no bins are explicitly defined for a coverpoint.
Cross_num_print_missing
Syntax :cross_num_print_missing=number
default value: 0
Number of missing (not covered) cross product bins that shall be saved to the coverage database and printed in the coverage report.
Per_instance
Syntax :per_instance=Boolean
default value: 0
Each instance contributes to the overall coverage information for the covergroup type. When true, coverage information for this covergroup instance
shall be saved in the coverage database and included in the coverage report. When false, implementations are not required to save instance-specific
information.
Get_inst_coverage
Syntax :get_inst_coverage=Boolean
default value: 0
Only applies when the merge_instances type option is set . Enables the tracking of per instance coverage with the get_inst_coverage built-in method.
When false, the value returned by get_inst_coverage shall equal the value returned by get_coverage
following Table summarizes the syntactical level (covergroup, coverpoint, or cross) in which type options can be specified.
SYSTEM TASKS
$load_coverage_db ( name ) :
Load from the given filename the cumulative coverage information
for all coverage group types.
$get_coverage ( ) :
Returns as a real number in the range 0 to 100 the overall coverage
of all coverage group types. This number is computed as described
above.
COVER PROPERTY
Cover statement can be used to monitor sequences and other behavioral aspects of the design. The tools
can gather information about the evaluation and report the results at the end of simulation. When the
property for the cover statement is successful, the pass statements can specify a coverage function, such
as monitoring all paths for a sequence. The pass statement shall not include any concurrent assert,
assume or cover statement. A cover property creates a single cover point.
Coverage results are divided into two: coverage for properties, coverage for sequences.
For sequence coverage, the statement appears as:
Cover property ( sequence_expr ) statement_or_null
Cover Property Results
The results of coverage statement for a property shall contain:
Number of times attempted
Number of times succeeded
Number of times failed
Number of times succeeded because of vacuity
In addition, statement_or_null is executed every time a property succeeds.
(S) Coverage property can be declared in
Cover groups can reference data sets where as cover property references a temporal expression.
Cover group can be triggered using .sample method ()
Cover property dont have this option.
Cover group has multiple bins options.
Cover property has only one bin.
Cover group cannot handle complex temporal relationships.
Cover properties can cover complex temporal expressions.
Cover group automatically handles the crosses.
Cover properties cannot do crosses.
Cover group has lot of filtering options.
Cover property has no specific filtering constructs but it can be filtered.
Cover properties cannot be used in classes.
Cover groups can be used in classes. So, cover groups can reference the variables in class.
Cover groups are most useful at a higher level of abstractions where as cover property makes sense
to use when we want to work at low level signals.
We can mix cover group and cover property to gain the OO and temporal advantages. Using
properties for temporal expressions and trigger the cover group.