0% found this document useful (0 votes)
16 views

6.Functional coverage

Uploaded by

Kartikey Bhatt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

6.Functional coverage

Uploaded by

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

Raghavendra B S, PG student

21 August 2024 06:30

► What is Functional coverage in SV?


• Functional coverage describes the extent upto which the design functionalities exercised/covered/Progressed by the test cases(either random/directed) in
Testbench usually in constrained random verification(CRV). Debugging the design is made with ease upon analyzing the coverage details of some selected
variables. The quality of coverage is decided by the specifications included in the covergroup.
• All the coverage details are merged and dumped into a file and later reviewed for coverage analysis.
• Configure? : one can enable/ disable the covergroup, setting the coverage goal. Multiple coverage files from different tests are merges together for
analyzing later collectively.

Note: Coverage tools gather the information during simulation and post process them and generate the coverage report through which loop holes are identified so
modifying or creating new tests to fill those holes untill the desire coverage goal is met.

► Types of Coverage:
• Code Coverage(automatically generated): This tells the percentage of RTL Bug Rate: An Indirect way of measuring coverage is by looking at the bug
implementations hit by testcases, which include line coverage, path rate.
coverage, Toggle coverage, FSM coverage and Dead code analysis.

Example: (Incomplete D-Flipflop*)


module dff(input logic clk,d,rst, output logic q);

always @(posedge clk or negedge rst) begin


q<=d; //if rst=1'bz then also tool generate 100% code
coverage but functionally it is wrong
end

• Functional Coverage: It checks the quantitative functional metrics(checking


the system behaviour properly for specific data combination or checking
some operation happens in sequence).

Consequences:
1. Have I exercised all the protocol request types and combinations(Burst
read/write)?
2. Did I accessed different memory alignments(Byte aligned, word aligned,
dword aligned)?
3. Did we verify sequence of transactions(write follows read)?
4. Did we verify queue full and empty conditions?

Note: If some block of code is missing in the design code coverage cant
catch this but functional coverage do.

Assertion Coverage: assertion coverage specifies how much assertions


will be triggered by tests, cover property observes sequences of signals,
while a covergroup samples data values and transactions during the
simulation.

How the code coverage is 100% but functional coverage is low? How can you approach the situation that Functional coverage is 100%
This may be due to but code coverage is low?
○ check the bins specified align with the design requirements. This may be due to
○ check if code coverage exclusions are valied. ○ Modify the stimulus.
○ Identify whether the covergroup for some feature is not specified.
What is covergroup?

6.Functional coverage Page 1


What is covergroup?
• It is used to encapsulate coverage specifications. The cover group can be What covergroup encapsulates?
instantiated using new() operator like class. 1. A set of coverage points and cross coverage between them.
The components of covergroup include 2. An event that defines when the covergroup is sampled.
1. A set of coverage points(variables) and cross coverage between coverage points. 3. other options to configure coverage object.
2. A clocking event which synchronizes the coverage points.
3. Coverage options and optional formal arguments. What is cross coverage?
Note: Covergroup can be defined within module, package, class, interface and It is used to track the occurrence and interaction between multiple
program blocks. coverpoints in combination.

Syntax:
covergroup cg [(tf_port_list)] [coverage_event];
{coverage_specs_or_option;}
endgroup [:covergroup_identifier]

Coverpoint:
○ A coverpoint is a variable/expression/Transitions that is expected to be analysed for coverage when the covergroup is sampled. Each coverpoint has
a set of bins which either hits/misses upon sampling the covergroup based on values taken by coverpoint.
○ The coverpoints are normally associated with the design.

Explain Coverpoint Bins in covergroup?


○ A bin specifies a quantitative metric of coverage for coverpoint(defining a range or a value that the coverpoint must take).
○ bins can be specified explicitly or tool generates them automatically based on variable type(Example if the variable is 2-bit, 4 automatic bins are
created.)
bins may be =>single value, range of values, Illegal values, default value (very powerfull feature in verification).

Example-1(covergroup within a class): Example-2(covergroup within a Testbench):


In the below example, the coverage analysis is done for variables mode and key which take 16 Instantiating the covergroup inside a testbench is different from that done
and 4 values respectively and is placed inside a covergroup cg which is not triggered by any inside a class.
event.
• bins are said to be hit/covered if that variable reaches that corresponding values(bin module tb();
featureB is hit when mode takes either 1,2 or 3). bit [1:0]mode;
• bin common can have separate bins (6,7…15) bit [2:0]cfg;
• bin reserve is a bin which hits when none of the bins are hitted. bit clk;
• covergroup key has inherently 4 automatic bins.
• covergroup can be instantiated within the class by its name only*. always #20 clk=~clk;
• Upon creating the class instance covergroup within that by default will be activated, It
can be later enabled/disabled as necessity. covergroup cg@(posedge clk); //cg sampled at posedge clk
coverpoint mode;
endgroup
// declaring the covergroup within a class // calling covergroup inside testbench
cg c1=new(); //creating instance and object of covergroup
class myTrans; module tb();
rand bit [3:0]mode; myTrans m1=new(); initial begin
rand bit [1:0]key;
initial begin
repeat(4) begin
function display(); m1.cg.sample(); //implicitly specifying for
@(negedge clk) {mode,cfg}=$random; //driving random stimulus to the
$display("%0t, %0h, %0h", $time, mode, sampling covergroup
coverage variables
key); end $display("At %0t, mode= %0h, cfg=%0h", $time, mode, cfg);
endfunction end
endmodule

covergroup cg; Note: #500 $display("coverage is %0.2f", c1.get_inst_coverage()); //To


c1: coverpoint mode{ Other ways of specifying coverpoint display percentage of coverage
bins featureA={0}; //bin hits if mode= 0 bins and their meaning. $finish();
bins featureB={[1:3]}; /bin hits if mode=1,2 or 3. end
bins common[ ]={[6:$]}; //creating a separate bin covergroup cg;
for values 6,7… upto 15 c3: coverpoint mode{ endmodule
ignore_bins ig1={4}; //value 4 is excluded for bins f_a[ ]={[2:3],[4:7]}; //create a
coverage calculation separate bin for each range.
illegal_bins ig2={5}; //value 5 is illegal leads to bins f_b[3]={[1:7],2,3,4}; //split the total
simulation failure 10 values into 3 bins which hits if
bins reserve=default; {1,2,3},{4,5,6},{7,2,3,4} respectively
}
c2: coverpoint key; //coverpoint without bins bins f_c={0=>1}; //bin hits if mode changes
from 0 to 1
endgroup
bins f_d={2=>3,4}; //bin hits if mode
changes from 2 to 3or4.
bins f_d={1=>2=>3};//bin hits if mode
changes from 1 to 2 to 3
function new(); }
cg=new(); //instantiating covergroup by its name. endgroup
endfunction

endclass

Example-3

6.Functional coverage Page 2


How to enable/disable coverage conditionally? Exercise:

What is Cross coverage?

6.Functional coverage Page 3


What is Cross coverage?

Exercise:

System verilog Packages:


It is a mechanism for sharing parameters, data, function, tasks, types, property to other interfaces, programs, or modules that can b e declared within a package.
1. The package can be made accessible within the interface, programs, modules, and other packages using an import keyword follow ed by scope resolution
operator :: and what has to import to get the controlled access.
2. Items in the package cannot have hierarchical references.

Syntax: Example-2:
package <package_name>; package pkg; import pkg::transaction;
... class transaction; module package_example;
endpackage int data = 5; initial begin
transaction tr = new();
function void display(); tr.display();
// To import package
$display("data = %0d", data); //pkg_funct(); // Not accessible
import <package_name> :: *; // All package items are endfunction end
imported endclass endmodule
import <package_name> :: <method_name>; // Only
<method_name> is imported function pkg_funct();
$display("Inside pkg_funct");
Example-1: endfunction
endpackage
package pkg; import pkg::*;
class transaction; module package_example;
int data = 5; initial begin
transaction tr = new();
function void display(); tr.display(); Example-3:
$display("data = %0d", data); pkg_funct(); package pkg_A; import pkg_A::*;
endfunction end int data = 5; import pkg_B::*;
endclass endmodule function pkg_funct();
$display("pkg_A: Inside pkg_funct, data = %0d", data); module package_example;
function pkg_funct(); endfunction initial begin
$display("Inside pkg_funct"); endpackage pkg_A::pkg_funct();
endfunction pkg_B::pkg_funct();
endpackage package pkg_B; end
int data = 10; endmodule
function pkg_funct();
$display("pkg_B: Inside pkg_funct, data = %0d", data);
endfunction
endpackage

6.Functional coverage Page 4

You might also like