Functional Coverage
To capture coverage, SystemVerilog provides constructs such as covergroup, coverpoint, and bins. The covergroup is a user-defined type that encapsulates the specification of coverage collection. The coverpoint is a point of interest for coverage measurement. Bins are containers for collecting coverage data.
While Code Coverage can be collected automatically by most of the modern simulators, Functional Coverage needs to be manually coded using SystemVerilog constructs. An efficient verification environment usually includes both Code and Functional Coverage to ensure the design has been thoroughly verified.
Let's see an example of how to define a covergroup in SystemVerilog:
covergroup cg_example @(posedge clk);
cp_a: coverpoint a {
bins low = {0};
bins high = {1};
}
cp_b: coverpoint b {
bins range[] = {[0:15]};
}
endgroup
cg_example my_cg; // instance of the covergroup
initial begin
my_cg = new();
end
In this example, a covergroup named cg_example
is defined with two coverpoints cp_a
and cp_b
for signals a
and b
. The covergroup is sampled at every positive edge of the clk
. Then, an instance of this covergroup is created in the initial
block. The actual signals for a
and b
will be sampled and the coverage data will be collected as per the bins defined.
Functional coverage in SystemVerilog is a way to quantify the progress of the verification process. It's about ensuring that the functionality of the design has been adequately exercised. It is user-defined and helps to ensure that all aspects of the specification are verified. This includes any corner cases, boundary conditions, or cross-conditions that must be verified.
SystemVerilog provides three important constructs for defining functional coverage: covergroup
, coverpoint
, and bins
.
Covergroup
A covergroup is a user-defined type that encapsulates the specification of the coverage to be collected. It's a container for one or more coverage points (coverpoints). Each covergroup has its own instance, and multiple instances of the same covergroup can be created to track coverage from different points in the design. The syntax for a covergroup is:
covergroup covergroupName @(triggering event);
// coverpoints and crosses
endgroup
Here's an example of a basic covergroup definition:
covergroup cg_example @(posedge clk);
cp_a: coverpoint a;
endgroup
cg_example my_cg; // Creating an instance of the covergroup
initial begin
my_cg = new();
end
In this example, cg_example
is a covergroup that samples a coverpoint cp_a
at every positive edge of the clock.
Coverpoint
A coverpoint is a point of interest for coverage measurement. It specifies a signal or an expression to be observed for coverage collection. Each coverpoint can have one or more bins associated with it, which define the values or ranges of values of the coverpoint that should be observed. The syntax for a coverpoint is:
coverpoint expression {
// bins
}
Here's an example of a coverpoint definition:
covergroup cg_example @(posedge clk);
cp_a: coverpoint a {
bins low = {0};
bins high = {1};
}
endgroup
In this example, cp_a
is a coverpoint that specifies two bins, low
and high
, which represent the values 0 and 1 of the signal a
.
Bins
Bins are the containers for collecting the coverage data. They define a set of values or a range of values that are of interest for a coverpoint. Each bin is given a unique name within its coverpoint. The syntax for a bin is:
bins name = set_of_values;
Here's an example of a bin definition:
covergroup cg_example @(posedge clk);
cp_a: coverpoint a {
bins low = {0};
bins high = {1};
}
endgroup
In this example, two bins low
and high
are defined for the coverpoint cp_a
. The low
bin is for the value 0 of a
, and the high
bin is for the value 1 of a
.
These constructs together allow you to define very specific and detailed coverage metrics for your design. This way, you can ensure that all the important parts of your design have been exercised by your verification environment.
Have a Question?
Feel free to ask your question in the comments below.
Please Login to ask a question.
Login Now