Chap 9 Functional Coverage PDF
Chap 9 Functional Coverage PDF
•Functional coverage is
•Functional coverage is not
•Functional coverage strategies
Strategies when code coverage or functional coverage is lacking
•Collecting coverage with covergroups
Basics of collecting coverage with covergroups
•Coverage options
Options that drive collection coverage or make the reports easier
to read
•Bin manipulation
For example: naming and excluding
•Transition coverage
Track events over time
•Cross coverage
Collects coverage on the intersection of coverage points
•Monitoring coverage during simulation
Testbench can be steered into areas not covered, required for
coverage driven verification
Chapter 9 Copyright 2011 G. Tumbush, C. Spear v1.1 1
Functional Coverage is:
•A measure of which design features have been exercised.
•You’ve already performed functional coverage manually
Functional
Coverage Tests
Tests
Test Plan
Good coverage:
High
Is design
Start of Project
Low
complete?
Low High
Code Coverage
Chapter 9 Copyright 2011 G. Tumbush, C. Spear v1.1 7
9.4 Simple Functional Coverage
program automatic test(busifc.TB ifc);
Example
class Transaction;
rand bit [31:0] data;
rand bit [ 2:0] dst;
endclass
Transaction tr;
covergroup CovPort;
coverpoint tr.dst;
endgroup
initial begin
CovPort ck;
ck = new();
Declare covergroup ck
repeat (32) begin
Instantiate ck
@ifc.cb;
tr = new();
`SV_RAND_CHECK(tr.randomize);
ifc.cb.port <= tr.dst;
ifc.cb.data <= tr.data;
ck.sample();
end end endprogram Gather coverage
Chapter 9 Copyright 2011 G. Tumbush, C. Spear v1.1 8
Questa Coverage Results
VSIM>coverage report -verbose
# COVERGROUP COVERAGE:
# ---------------------------------------------------------------
# Covergroup Metric Goal/Status
# At Least
# ---------------------------------------------------------------
# TYPE /top/test/CovPort 100.0% 100 Covered
# Coverpoint CovPort::#coverpoint__0# 100.0% 100 Covered
# covered/total bins: 8 8
# bin auto[0] 5 1 Covered
# bin auto[1] 7 1 Covered
# bin auto[2] 3 1 Covered
# bin auto[3] 4 1 Covered
# bin auto[4] 2 1 Covered
# bin auto[5] 4 1 Covered
# bin auto[6] 3 1 Covered
# bin auto[7] 4 1 Covered
event trans_ready;
covergroup CovPort @(trans_ready);
coverpoint ifc.cb.port;
endgroup
Assume the opcodes are valid on the positive edge of signal clk.
class Transaction;
rand opcode_e opcode;
rand byte operand1;
rand byte operand2;
endclass
Transaction tr;
Assume the opcodes are valid on the positive edge of signal clk.
•Name
option.name = "CovPort";
•auto_bin_max
•weight
# Covergroup Metric
Goal/ Status
# At Least
# ------------------------------------------------------------
# TYPE /top/test/CovPort 100.0% 100 Covered
# Coverpoint CovPort::#coverpoint__0# 100.0% 100 Covered
# covered/total bins: 2 2
# bin auto[0:3] 19 1 Covered
# bin auto[4:7] 13 1 Covered
Chapter 9 Copyright 2011 G. Tumbush, C. Spear v1.1 17
9.7.4 Sampling Expressions
•Expressions in coverpoints are allowed
•But check the report for the correct # of bins.
class Packet;
rand bit [2:0] hdr_len;
rand bit [3:0] payload_len;
rand bit [3:0] kind;
endclass
Packet p;
covergroup CovLen;
len16: coverpoint (p.hdr_len + p.payload_len);
len32: coverpoint (p.hdr_len + p.payload_len + 5'b0);
endgroup
class Transaction;
rand opcode_e opcode;
rand byte operand1;
rand byte operand2;
endclass
Transaction tr;
Chapter 9 Copyright 2011 G. Tumbush, C. Spear v1.1 21
Exercise 2
typedef enum {ADD, SUB, MULT, DIV} opcode_e;
class Transaction;
rand opcode_e opcode;
rand byte operand1;
rand byte operand2;
endclass
Transaction tr;
covergroup CovCode @ifc.cb;
operand1_cp: coverpoint tr.operand1{
bins max_neg = {-128};
bins zero = {0};
bins max_pos = {127};
bins misc = default;
}
endgroup
or
covergroup CovPort;
coverpoint tr.port{
ignore_bins hi = {6,7};
illegal_bins no_hi = {6,7};
}
endgroup
Chapter 9 Copyright 2011 G. Tumbush, C. Spear v1.1 28
Exercise 3
Expand the last exercise to cover the following test plan
requirements:
1. “The opcode shall take on the values ADD or SUB” (hint: this
is 1 coverage bin).
2. “The opcode shall take on the values ADD followed by SUB”
(hint: this is a second coverage bin).
3. “Opcode must not equal DIV” (hint: report an error using
illegal_bins).
Label the coverpoint opcode_cp.
typedef enum {ADD, SUB, MULT, DIV} opcode_e;
class Transaction;
rand opcode_e opcode;
rand byte operand1;
rand byte operand2;
endclass
Transaction tr;
Chapter 9 Copyright 2011 G. Tumbush, C. Spear v1.1 29
Exercise 3
typedef enum {ADD, SUB, MULT, DIV} opcode_e;
class Transaction;
rand opcode_e opcode;
rand byte operand1;
rand byte operand2;
endclass
Transaction tr;
covergroup CovPort;
cross tr.direction, tr.port;
endgroup
covergroup CovPort;
direction: coverpoint tr.direction;
port: coverpoint tr.port;
cross direction, port;
endgroup
Chapter 9 Copyright 2011 G. Tumbush, C. Spear v1.1 31
9.8.2 Labeling Cross Coverage Bins
To reduce the # of bins, create custom bins
covergroup CovPort;
direction: coverpoint tr.direction;
port: coverpoint tr.port{
bins zero ={0};
bins middle = {[1:6]};
bins maximum = {7};
}
cross direction, port;
endgroup
class Transaction;
rand opcode_e opcode;
rand byte operand1;
rand byte operand2;
endclass
Transaction tr;
class Transaction;
rand opcode_e opcode;
rand byte operand1;
rand byte operand2;
endclass
Transaction tr;
covergroup CovCode @ifc.cb;
operand1_cp: coverpoint tr.operand1{
bins max_neg = {-128};
bins zero = {0};
bins max_pos = {127};
bins misc = default;
}
endgroup
option.weight = 5;
}
initial begin
CovPort cp;
cp = new(5);
end
initial begin
CovPort cpa, cpb;
tr = new();
cpa = new(tr.port_a, 6);
cpb = new(tr.port_b, 2);
end
vsim –cvg63
Chapter 9 Copyright 2011 G. Tumbush, C. Spear v1.1 44
Exercise 5
Assuming that your covergroup is called CovCode and the
instantiation name of the covergroup is ck expand the last exercise
to:
1) Display the coverage of coverpoint operand1_cp referenced
by the instantiation name
2) Display the coverage of coverpoint opcode_cp referenced by
the covergroup name
typedef enum {ADD, SUB, MULT, DIV} opcode_t;
class Transaction;
rand opcode_t opcode;
rand byte operand1;
rand byte operand2;
endclass
Transaction tr;
Chapter 9 Copyright 2011 G. Tumbush, C. Spear v1.1 45
Exercise 5
Assuming that your covergroup is called CovCode and the
instantiation name of the covergroup is ck expand the last exercise
to:
1) Display the coverage of coverpoint operand1_cp referenced
by the instantiation name
2) Display the coverage of coverpoint opcode_cp referenced by
the covergroup name
class Transaction;
rand opcode_t opcode;
rand byte operand1;
rand byte operand2;
endclass
Transaction tr;