System Verilog Coverage
System Verilog Coverage
COVERAGE
ROHIT KHANNA
Coverage
Types of Coverage's:
o Code Coverage.
o Functional Coverage.
o Branch coverage
o Checks whether each branch of control statement (if,
case) has been covered.
o Example: choices in case statements.
o Condition coverage
o Has Boolean expression in each condition evaluated to both
true and false.
o Toggle coverage
o Checks that each bit of every signal has toggled from 0 to 1
and 1 to 0.
o Transition coverage
o Checks that all possible transitions in FSM has been covered.
o State coverage
o Checks that all states of FSM has been covered.
System Verilog Coverage
Functional Coverage
High
Low High
Code Coverage
System Verilog Coverage
Coverage Driven Verification
Coverage Met ?
YES
NO
Verification
Identify Coverage Holes
Complete
Add tests to target holes,
Enhance stimulus generator,
Enhance cover metrics if required
System Verilog Coverage
SV Functional Coverage Support
Syntax:
covergroup cg_name [(port_list)] [coverage_event];
//coverage_specs;
//coverage_options;
endgroup [ : cg_name]
Example:
covergroup cg;
……
endgroup
cg cg1=new;
System Verilog Coverage
Coverpoint
Syntax:
[label : ] coverpoint expression [iff (expression)]
[{
//bins specifications;
}] ;
Example:
covergroup cg;
coverpoint a iff(!reset);
endgroup
cg cg1;
initial cg1=new;
covergroup addr_cov (int low, int high, ref bit [16:0] address)
@ (posedge clk);
addr_range : coverpoint address {
bins addrbin= { [low: high] };
}
endgroup
class xyz;
bit [3:0] m_x;
int m_y;
bit m_z;
covergroup cov1 @ (m_z); //Embedded Covergroup
coverpoint m_x; //16 bins
coverpoint m_y; //2^32 bins
endgroup
function new(); cov1=new; endfunction
endclass
class c1;
bit [7:0] x;
covergroup cv (int arg) @ (posedge clk);
option.at_least=arg;
coverpoint x;
endgroup
function new(int p1); cv=new(p1); endfunction
endclass
initial c1 obj=new(4);
Sequence of Transitions
(value1=> value2 => value3=> value4)
Set of Transitions
(value1, value2 => value3, value4)
bit [4:1] a;
covergroup cg @ (posedge clk);
coverpoint a
{ bins sa [ ]= { ( 4=>5=>6 ), ( [7:9],10=>11,12) };
bins allother= default sequence;
}
endgroup
Sa will be associated with individual bins (4=>5=>6) ,
(7=>11), (7=>12), (8=>11), (8=12), (9=>11), (9=>12),
(10=>11), (10=>12)
System Verilog Coverage
Example2
Consecutive Repetition
bins sb={ 4 [*3] } ;
// (4=>4=>4)
bins sc [ ]={ 3 [*2:4] };
// (3=>3) , (3=>3=>3), (3=>3=>3=>3)
Non-Consecutive Repetition
bins sd [ ]={ 2 [->3] };
//2=>…. =>2 …. =>2
covergroup cg;
coverpoint num
{ wildcard bins even={3’b??0};
wildcard bins odd={3’b??1};
}
endgroup
covergroup cg;
coverpoint count1
{ wildcard bins n12_16={4’b11??};
//1100 || 1101 || 1110 || 1111
}
coverpoint count2
{ wildcard bins t =(2’b0x=>2’b1x);
//(0, 1=>2, 3)
}
endgroup
System Verilog Coverage
Excluding bins
covergroup cg;
coverpoint num {
options.auto_bin_max=4;
//<0:1> , <2:3>, <4:5>, <6:7>
ignore_bins bins hi={6, 7};
// bins 6 and 7 are ignored from coverage
}
endgroup
They will result in a run-time error even if they are also included
in another bin.
Examples:
o Was write enable 1 when address was 4’b1101.
o Have we provide all possible combination of inputs to a Full
Adder.
bit [3:0] a, b;
covergroup cg @ (posedge clk);
cross_cov: cross a , b;
endgroup
bit [3:0] a, b, c;
covergroup cg @ (posedge clk);
cov_add: coverpoint b+c;
cross_cov: cross a , cov_add;
endgroup
bit [31:0] a;
bit [3:0] b;
covergroup cg @ (posedge clk);
cova: coverpoint a {bins low [ ]={ [0:9] }; }
cross_cov: cross b, cova;
endgroup
Examples:
o binsof(X) intersect { Y } , denotes the bins of coverage point
X whose values intersect the range given
o ! binsof(X) intersect { Y }, denotes the bins of coverage point
X whose values do not intersect the range given by Y.
The bins selected can be combined with other selected bins using
the logical operators && and ||.
bit [7:0] a, b;
covergroup cg @ (posedge clk);
cova : coverpoint a
{
bins a1 = { [0:63] };
bins a2 = { [64:127] };
bins a3 = { [128:191] };
bins a4 = { [192:255] };
}
System Verilog Coverage
Binsof and intersect
covb : coverpoint b
{
bins b1 = { 0 };
bins b2 = { [1:84] };
bins b3 = { [85:169] };
bins b4 = { [170:255] };
}
covergroup cg;
cross a, b;
{
ignore_bins bins ig=binsof(a) intersect { 5, [1:3] };
}
endgroup
All cross products that satisfy the select expression are excluded
from coverage even if they are included in other cross-coverage
bins of the cross.
System Verilog Coverage
Illegal Cross products
Options placed in the cover group will apply to all cover points.
Options can also be put inside a single cover point for finer
control.
covergroup cg;
option.comment=“Cover group for data and address”;
coverpoint data;
coverpoint address;
endgroup
covergroup cg;
option.per_instance=1;
coverpoint data;
endgroup
option.at_least =10
covergroup cg;
a: coverpoint sig_a { bins a0= {0};
option.weight=0; //will not compute to
//coverage
}
b: coverpoint sig_b {bins b1= {1};
option.weight=1;
}
ab: cross a , b { option.weight=3; }
endgroup
covergroup packet_cg;
coverpoint dest_addr;
coverpoint packet_type;
endgroup
packet_cg pkt;
initial pkt=new;
always @ (pkt_received)
pkt.sample();
covergroup packet_cg;
coverpoint dest_addr;
coverpoint packet_type;
endgroup
packet_cg pkt;
initial pkt=new;
$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.
property ab;
@(posedge clk) a => b;
endproperty