Functional Coverage
Functional Coverage
cg_inst.sample();
end
endprogram
In the above example, we are sampleing the cover point "y". The cover point is named
"cover_point_y" . In the Coverage report you will see this name. A cover group "cg" is defined
and its instance "cg_inst" is created. The value of "y" is sampled when cg_inst.sample()
method is called. Total possible values for Y are 0,1,2,3,4,5,6,7. The variable "y" is assigned
only values 3,5,6. The coverage engine should report that only 3 values are covered and there
are 8 possible values.
Commands To Simulate And Get The Coverage Report:
VCS
Compilation command:
vcs -sverilog -ntb_opts dtm filename.sv
Simulation Command:
./simv
Command to generate Coverage report: Coverage report in html format will be in the
./urgReport directory
urg -dir simv.vdb
VARIABLE : cover_point_y
Expected : 8
Covered : 3
Percent: 37.50.
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
In the preceding example, cover point varible "cp_varib" is covered only if the value reset is
low.
GENERIC COVERAGE GROUPS
Generic coverage groups can be written by passing their traits as arguments to the coverage
constructor. This allows creating a reusable coverage group which can be used in multiple
places.
For example, To cover a array of specified index range.
The example above defines a coverage group, gc, in which the signal to be sampled as well as
the extent of the coverage bins are specified as arguments. Later, two instances of the
coverage group are created; each instance samples a different signal and covers a different
range of values.
COVERAGE BINS
A coverage-point bin associates a name and a count with a set of values or a sequence of
value transitions. If the bin designates a set of values, the count is incremented every time
the coverage point matches one of the values in the set. If the bin designates a sequence of
value transitions, the count is incremented every time the coverage point matches the entire
sequence of value transitions.
Bins can be created implicitly or explicitly.
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.
Bin[0] for
Bin[1] for
Bin[2] for
Bin[3] for
0 and
2 and
4 and
6 and
1
3
5
7
Varible Y is assigned values 3,5 and 6. Values 3,5 and 6 belongs to bins bin[1],bin[2] and bin[3]
respectively. Bin[0] is not covered.
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
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
In the above example, bins are created explicitly. The bins are named a,b,c and d.
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
In the above example, bin a is array of 8 bins and each bin associates to one number between
0 to 7.
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:
Single Value Transition
Sequence Of Transitions
Set Of Transitions
Consecutive Repetitions
Range Of Repetition
Goto Repetition
Non Consecutive Repetition
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
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
cg cg_inst = new();
initial
foreach(values[i])
begin
y = values[i];
cg_inst.sample();
end
endprogram
In the above example, 2 bins re created for covering the transition of point "y" from 3 to 4 to
5 and other for 3 to 5 to 6. The variable y is given the values and only the transition 3 to 5 to
6 is occurring.
Coverage report:
-------------------VARIABLE : cover_point_y
Expected : 2
Covered : 1
Percent: 50.00
Uncovered bins
-----------------tran_345
Covered bins
----------------tran_356
Set Of Transitions
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
cg cg_inst = new();
initial
foreach(values[i])
begin
y = values[i];
cg_inst.sample();
end
endprogram
In the above example, bin trans creates 4 bin for covering 3=>5,4=>5,3=>6 and 4=>6.
Coverage report:
-------------------VARIABLE : cover_point_y
Expected : 4
Covered : 1
Percent: 25.00
Uncovered bins
-----------------tran_34_to_56:3->6
tran_34_to_56:4->5
tran_34_to_56:4->6
Covered bins
---------------tran_34_to_56:3->5
Consecutive Repetitions
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
cg cg_inst = new();
initial
foreach(values[i])
begin
y = values[i];
cg_inst.sample();
end
endprogram
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
cg cg_inst = new();
initial
foreach(values[i])
begin
y = values[i];
cg_inst.sample();
end
endprogram
In the above example, only the sequence 3=>3=>3=>3 is generated. Other expected sequences
3=>3=>3 and 3=>3=>3=>3=>3 are not generated.
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
cg cg_inst = new();
initial
foreach(values[i])
begin
y = values[i];
cg_inst.sample();
end
endprogram
Coverage report:
-------------------VARIABLE : cover_point_y
Expected : 1
Covered : 1
Percent: 100.00
is same as
...=>3...=>3
A nonconsecutive repetition followed by an additional value is represented as follows:
1 => 3 [=2] => 5
is the same as
1...=>3...=>3...=>5
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
cg cg_inst = new();
initial
foreach(values[i])
begin
y = values[i];
cg_inst.sample();
end
endprogram
Coverage report:
-------------------VARIABLE : cover_point_y
Expected : 1
Covered : 1
Percent: 100.00
WILDCARD BINS
The count of bin g12_16 is incremented when the sampled variable is between 12 and 16:
Covered bin
--------------g12_15
Number of times g12_15 hit : 4
The count of transition bin T0_3 is incremented for the following transitions (as if by
(0,1=>2,3)):
program main;
reg [0:1] y;
reg [0:1] values[$]= '{ 2'b00,2'b01,2'b10,2'b11};
covergroup cg;
cover_point_y : coverpoint y {
wildcard bins trans = (2'b0X => 2'b1X );
}
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 : 1
Covered : 1
Percent: 100.00
Covered bin
--------------trans
Number of times trans hit : 1 (01 => 10)
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
cg cg_inst = new();
initial
foreach(values[i])
begin
y = values[i];
cg_inst.sample();
end
endprogram
In the above program, total possible values for y are 0 to 7. Ignore_bins specified to Ignored
values between 1 to 5. So the Expected values are 0,6 and 7. Out of these expected values,
only 6 and 7 are generated.
Coverage report:
-------------------VARIABLE : cover_point_y
Expected : 3
Covered : 2
Percent: 66.66
Uncovered bins
-----------------auto[0]
Excluded/Illegal bins
------------------------ig
auto[1]
auto[2]
auto[3]
auto[4]
auto[5]
Covered bins
---------------auto[6]
auto[7]
ILLEGAL 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 {
illegal_bins ib = {7};
}
endgroup
cg cg_inst = new();
initial
foreach(values[i])
begin
y = values[i];
cg_inst.sample();
end
endprogram
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
In the above program, y has can have 4 values 0,1,2 and 3 and similarly z can have 4 values
0,1,2 and 3. The cross product of the y and z will be 16 values (00),(01),(02),(03),(10),
(11)........(y,z)......(3,2)(3,3) .
Only combinations (11) and (32) are generated.
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] }; }
Weight
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
Description :
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
Description :
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
Description :
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
Description :
Number of missing (not covered) cross product bins that shall be saved to the coverage
Per_instance
Syntax :per_instance=Boolean
default value: 0
Description :
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
Description :
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
COVERAGE METHODS
The following coverage methods are provided for the covergroup. These methods can be
invoked procedurally at any time.
void sample():
Description : Triggers sampling of the covergroup
real get_coverage()
real get_coverage(ref int, ref int)
Description : Calculates type coverage number (0...100)
The get_coverage() method returns the cumulative (or type) coverage, which considers the
contribution of all instances of a particular coverage item. and it is a static method that is
available on both types (via the :: operator) and instances (using the "." operator).
The get_coverage() method both accept an optional set of arguments, a pair of int values
passed by reference. When the optional arguments are specified, the get_coverage() method
assign to the first argument the value of the covered bins, and to the second argument the
number of bins for the given coverage item. These two values correspond to the numerator
and the denominator used for calculating the particular coverage number (i.e., the return
value before scaling by 100).
real get_inst_coverage()
real get_inst_coverage(ref int, ref int)
Description : Calculates the coverage number (0...100)
get_inst_coverage() method returns the coverage of the specific instance on which it is
SYSTEM TASKS
SystemVerilog provides the following system tasks and functions to help manage coverage
data collection.
$set_coverage_db_name ( name ) :
Sets the filename of the coverage database into which coverage information is saved at the
end of a simulation run.
$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 groups can reference data sets where as cover property references a temporal
expression.
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.