100% found this document useful (1 vote)
414 views54 pages

Functional Coverage

The document discusses functional coverage in SystemVerilog, including covergroups, coverage points, bins, and sampling. A covergroup defines a set of coverage points that can be sampled at different events. Coverage points specify values or expressions to monitor. Bins partition coverage points into groups to track coverage. Sampling triggers updates to bin counts based on coverage point values. Explicit bins allow specifying exact value groups, while default bins catch unmatched values. Transition bins track legal value changes over time.

Uploaded by

maheshasic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
414 views54 pages

Functional Coverage

The document discusses functional coverage in SystemVerilog, including covergroups, coverage points, bins, and sampling. A covergroup defines a set of coverage points that can be sampled at different events. Coverage points specify values or expressions to monitor. Bins partition coverage points into groups to track coverage. Sampling triggers updates to bin counts based on coverage point values. Explicit bins allow specifying exact value groups, while default bins catch unmatched values. Transition bins track legal value changes over time.

Uploaded by

maheshasic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 54

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.

1. Any event expression -edge, variable


covergroup cg @(posedge clk);
...
...
...
endgroup

The above example defines a covergroup named "cg". This


covergroup will be automatically sampled each time there is a
posedge on "clk" signal.

covergroup cg;
...
...
...
endgroup
cg cg_inst = new;
initial // or task or function or always block
begin
...
...

cg_inst.sample();
...
...
end

Sampling can also be done by calling explicitly calling .sample() method in


procedural code. This is used when coverage sampling is required based
on some calculations rather than events.

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

In the above example, we are sampleing the cover


point "y". 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.

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

A coverage point can be an integral variable or an integral


Expression. SystemVerilog allows specifying the cover points in
various ways.
1)Using XMR

Cover_xmr : coverpoint top.DUT.Submodule.bus_address;


2)Part select

Cover_part: coverpoint bus_address[31:2];


3)Expression

Cocver_exp: coverpoint (a*b);


4)Function return value

Cover_fun: coverpoint funcation_call();


5)Ref variable

covergroup (ref int r_v) cg;


cover_ref: coverpoint r_v;
endgroup

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.


covergroup cg(ref int array, int low, int high ) @(clk);
coverpoint// sample variable passed by reference
{
bins s = { [low : high] };
}
endgroup
int A, B;
rgc1 = new( A, 0, 50 );// cover A in range 0 to 50
rgc2 = new( B, 120, 600 );// cover B in range 120 to 600

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.

A coverage-point bin associates a name and a count


with
1.a set of values or
2. 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 0 and 1


Bin[1] for 2 and 3
Bin[2] for 4 and 5
Bin[3] for 6 and 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]

typedef enum { A,B,C,D } alpha;


program main;
alpha y;
alpha values[$]= '{A,B,C};
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

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

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:

Single Value Transition


Sequence Of Transitions
Set Of Transitions
Consecutive Repetitions
Range Of Repetition
Goto Repetition
Non Consecutive Repetition

Single Value Transition


Single value transition is specified as:
value1 => value2
program main;
bit [0:3] y;
bit [0:2] values[$]= '{3,5,6};
covergroup cg;
cover_point_y : coverpoint y {
bins tran_34 = (3=>4);
bins tran_56 = (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 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

An example of a range of repetition is:


3 [* 3:5]
is the same as
3=>3=>3, 3=>3=>3=>3, 3=>3=>3=>3=>3

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

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
Coverage report:
-------------------VARIABLE : cover_point_y
Expected : 1
Covered : 1
Percent: 100.00

Non Consecutive Repetition

The nonconsecutive 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 nonconsecutive
repetition may occur after any number of sample points so long as the repetition
value does not occur again.
For example:
3 [= 2]
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

Coverage report:
-------------------VARIABLE : cover_point_y
Expected : 1
Covered : 1
Percent: 100.00

WILDCARD BINS

By default, a value or transition bin definition can specify 4-state values.


When a bin definition includes an X or Z, it indicates that the bin count should only be incremented
when the sampled value has an X or Z in the same bit positions.
The wildcard bins definition causes all X, Z, or ? to be treated as wildcards for 0 or 1 (similar to the
==? operator).
For example:
wildcard bins g12_16 = { 4'b11?? };
The count of bin g12_16 is incremented when the sampled variable is between 12 and 16:
1100 1101 1110 1111

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

Expected values are 0,6 and 7. Out of these expected


Coverage report:
-------------------VARIABLE : cover_point_y
Expected : 3
Covered : 2
Percent: 66.66
Uncovered bins
-----------------auto[0]
Excluded/Illegal bins
------------------------auto[1]
auto[2]
auto[3]
auto[4]
auto[5]

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

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.
Cross coverage report: cover points are not shown.
Covered bins
----------------cover_point_y cover_point_z
auto[3] auto[2]
auto[1] auto[1]

ser-Defined Cross Bins

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

Options control the behavior of the covergroup, coverpoint, and cross.


There are two types of options:
those that are specific to an instance of a covergroup and
those that specify an option for the covergroup type as a whole.
Weight
Syntax : weight= number
default value: 1
Description :
If set at the covergroup syntactic level, it specifies the weight of this covergroup instance for computing the overall
instance coverage of the simulation. If set at the coverpoint (or cross) syntactic level, it specifies the weight of a
coverpoint (or cross) for computing the instance coverage of the enclosing covergroup. The specified weight shall
be a non-negative integral value.

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

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 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

A design or a separate module


Packages
Interfaces
Program block
Cover properties are not allowed in class.

Comparison Of Cover Property And Cover Group.

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.

You might also like