TODO section 21, round 2 of coverage_gaps C1, closing it. A covergroup
was a flat token scan into verbatim text; now ItemKind::Covergroup with
CoverItemKind::{Coverpoint, Cross, Option, Directive, Empty}, BinDecl
(wildcard, kind, array, spec: Values / Transitions / Default /
DefaultSequence / Select, with, iff) and SelectExpr for binsof ...
intersect ... && !binsof - behind the same Rewind fallback as
constraints (v0.27.0's scan re-run character for character on any
failure), no keywords reserved. The bin '(' ambiguity is settled by
position, the LRM's own rule, which replaced a lookahead scan and took
the fallback count to zero. Two guards in shared expression machinery -
an index cannot begin with *, -> or =; a bin's own with (...) filter is
not an array-method iterator argument - both attacked across the corpus
and the opentitan tree. Canonical layout, verify.rs untouched, thirteen
attack pairs. Every sampled expression binds to the class's properties;
cg_inst.cp resolves cross-file; FACTS_FORMAT 11 -> 12. The gap fuzzer
was built in from day one and its classification is asserted, not
claimed.
Opentitan: 544/544 structured, 87/87 DV covergroup files idempotent
with comment streams byte-identical, sweep and per-file diagnostics
identical. Corpus +1139 references, 1135 answered.
docs/features/covergroup-bodies/README.md.
Co-Authored-By: Claude Fable 5 <[email protected]>
617 lines
12 KiB
Plaintext
617 lines
12 KiB
Plaintext
# Covergroup bodies (IEEE 1800 §19) — the canonical layout the
|
|
# covergroup-bodies round introduced. See
|
|
# docs/features/covergroup-bodies/README.md.
|
|
#
|
|
# A covergroup is a block and is laid out like one: the whole header on the
|
|
# header line, one cover item per line at one further indent, and `endgroup`
|
|
# back at the header's column with whatever label the source wrote. A
|
|
# coverpoint or cross body is laid out like a constraint set, one bin per
|
|
# line. A covergroup the grammar does not recognise rewinds to the
|
|
# byte-for-byte verbatim capture covergroups had before this round.
|
|
|
|
# a covergroup is a block: the header on one line, one cover item per line,
|
|
# `endgroup` back at the header's column
|
|
class cov;
|
|
covergroup cg;
|
|
coverpoint addr;
|
|
endgroup
|
|
endclass
|
|
----
|
|
class cov;
|
|
covergroup cg;
|
|
coverpoint addr;
|
|
endgroup
|
|
endclass
|
|
====
|
|
# the whole header on one line: formals, the sample function, the end label
|
|
class cov;
|
|
covergroup cg (bit [3:0] a, int n) with function sample (bit [31:0] addr, bit rw);
|
|
cp_addr : coverpoint addr {
|
|
bins lo = { [0:9] };
|
|
bins hi = {[10:$]};
|
|
}
|
|
endgroup : cg
|
|
endclass
|
|
----
|
|
class cov;
|
|
covergroup cg(bit [3:0] a, int n) with function sample(bit [31:0] addr, bit rw);
|
|
cp_addr: coverpoint addr {
|
|
bins lo = {[0:9]};
|
|
bins hi = {[10:$]};
|
|
}
|
|
endgroup : cg
|
|
endclass
|
|
====
|
|
# a clocking event header, and the option assignments a covergroup body may hold
|
|
module m;
|
|
covergroup cg @(posedge clk);
|
|
option.per_instance = 1;
|
|
option.name = "cg";
|
|
type_option.weight = 5;
|
|
coverpoint x;
|
|
endgroup
|
|
endmodule
|
|
----
|
|
module m;
|
|
covergroup cg @(posedge clk);
|
|
option.per_instance = 1;
|
|
option.name = "cg";
|
|
type_option.weight = 5;
|
|
coverpoint x;
|
|
endgroup
|
|
endmodule
|
|
====
|
|
# every bin shape: wildcard, the three keywords, defaults, transitions with
|
|
# their three repetitions, a `with` filter and a per-bin `iff`
|
|
class c;
|
|
covergroup cg;
|
|
cp : coverpoint a iff (en) {
|
|
wildcard bins w[4] = {4'b1??1};
|
|
ignore_bins ig = {2, 3};
|
|
illegal_bins bad = default;
|
|
bins seq = default sequence;
|
|
bins t = (0 => 1, 2 => 3), (4 => 5);
|
|
bins r = (1'b0[*1:10] => 1'b1[->2] => 1'b0[=1]);
|
|
bins e[] = cp_x with (item % 2 == 0);
|
|
bins v = {[0:$]} with ($countones(item) != 1);
|
|
bins g = {1} iff (en);
|
|
}
|
|
endgroup : cg
|
|
endclass
|
|
----
|
|
class c;
|
|
covergroup cg;
|
|
cp: coverpoint a iff (en) {
|
|
wildcard bins w[4] = {4'b1??1};
|
|
ignore_bins ig = {2, 3};
|
|
illegal_bins bad = default;
|
|
bins seq = default sequence;
|
|
bins t = (0 => 1, 2 => 3), (4 => 5);
|
|
bins r = (1'b0[*1:10] => 1'b1[->2] => 1'b0[=1]);
|
|
bins e[] = cp_x with (item % 2 == 0);
|
|
bins v = {[0:$]} with ($countones(item) != 1);
|
|
bins g = {1} iff (en);
|
|
}
|
|
endgroup : cg
|
|
endclass
|
|
====
|
|
# a cross body: `binsof ... intersect`, the boolean operators, a nested paren
|
|
class c;
|
|
covergroup cg;
|
|
cr : cross cp_a, cp_b {
|
|
bins sel = binsof(cp_a.x) intersect {0, [1:2]} && !binsof(cp_b);
|
|
bins two = (binsof(cp_a) || binsof(cp_b)) && binsof(cp_c) intersect {1};
|
|
option.weight = 0;
|
|
}
|
|
endgroup : cg
|
|
endclass
|
|
----
|
|
class c;
|
|
covergroup cg;
|
|
cr: cross cp_a, cp_b {
|
|
bins sel = binsof(cp_a.x) intersect {0, [1:2]} && !binsof(cp_b);
|
|
bins two = (binsof(cp_a) || binsof(cp_b)) && binsof(cp_c) intersect {1};
|
|
option.weight = 0;
|
|
}
|
|
endgroup : cg
|
|
endclass
|
|
====
|
|
# an empty body prints `{}`, a null item and a stray `;` after `endgroup` are
|
|
# both reproduced
|
|
class c;
|
|
covergroup cg;
|
|
cp: coverpoint a {
|
|
}
|
|
cr: cross a, b;
|
|
;
|
|
endgroup;
|
|
endclass
|
|
----
|
|
class c;
|
|
covergroup cg;
|
|
cp: coverpoint a {}
|
|
cr: cross a, b;
|
|
;
|
|
endgroup;
|
|
endclass
|
|
====
|
|
# every header and bin comment slot prints back where it was written
|
|
class c;
|
|
covergroup /*a*/ cg /*b*/ (int n) /*c*/ with /*d*/ function /*e*/ sample /*f*/ (int x) /*g*/ ;
|
|
cp /*h*/ : /*i*/ coverpoint /*j*/ x /*k*/ iff /*l*/ ( /*m*/ en /*n*/ ) /*o*/ {
|
|
wildcard /*p*/ bins /*q*/ v /*r*/ [ /*s*/ 4 /*t*/ ] /*u*/ = /*v*/ {1} /*w*/ with /*x*/ ( /*y*/ item /*z*/ ) /*A*/ iff /*B*/ ( /*C*/ en /*D*/ ) /*E*/ ;
|
|
}
|
|
endgroup : cg /*F*/ ;
|
|
endclass
|
|
----
|
|
class c;
|
|
covergroup /*a*/ cg /*b*/ (int n) /*c*/ with /*d*/ function /*e*/ sample /*f*/ (int x) /*g*/;
|
|
cp /*h*/: /*i*/ coverpoint /*j*/ x /*k*/ iff /*l*/ (
|
|
/*m*/
|
|
en /*n*/
|
|
) /*o*/ {
|
|
wildcard /*p*/ bins /*q*/ v /*r*/ [ /*s*/ 4 /*t*/ ] /*u*/ = /*v*/ {1} /*w*/ with /*x*/ (
|
|
/*y*/
|
|
item /*z*/
|
|
) /*A*/ iff /*B*/ (
|
|
/*C*/
|
|
en /*D*/
|
|
) /*E*/;
|
|
}
|
|
endgroup : cg /*F*/;
|
|
endclass
|
|
====
|
|
# leading, trailing and dangling comments in a covergroup body
|
|
class c;
|
|
covergroup cg;
|
|
// a leading comment
|
|
cp: coverpoint a { // trailing
|
|
// inside
|
|
bins v = {1}; // after
|
|
// dangling
|
|
}
|
|
|
|
cr: cross a, b;
|
|
// last
|
|
endgroup
|
|
endclass
|
|
----
|
|
class c;
|
|
covergroup cg;
|
|
// a leading comment
|
|
cp: coverpoint a {
|
|
// trailing
|
|
// inside
|
|
bins v = {1}; // after
|
|
// dangling
|
|
}
|
|
|
|
cr: cross a, b;
|
|
// last
|
|
endgroup
|
|
endclass
|
|
====
|
|
# both arms of an `ifdef stand as ordinary cover items
|
|
class c;
|
|
covergroup cg;
|
|
`ifdef FOO
|
|
cp: coverpoint a;
|
|
`else
|
|
cp: coverpoint b;
|
|
`endif
|
|
endgroup
|
|
endclass
|
|
----
|
|
class c;
|
|
covergroup cg;
|
|
`ifdef FOO
|
|
cp: coverpoint a;
|
|
`else
|
|
cp: coverpoint b;
|
|
`endif
|
|
endgroup
|
|
endclass
|
|
====
|
|
# a long sample-function list breaks like a port list; a long value list breaks
|
|
# like every other braced list
|
|
class c;
|
|
covergroup cg_with_a_really_long_name_here with function sample (bit [31:0] address_value, bit read_write_flag, int unsigned index);
|
|
cp: coverpoint address_value {
|
|
bins many = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22};
|
|
}
|
|
endgroup
|
|
endclass
|
|
----
|
|
class c;
|
|
covergroup cg_with_a_really_long_name_here with function sample(
|
|
bit [31:0] address_value,
|
|
bit read_write_flag,
|
|
int unsigned index
|
|
);
|
|
cp: coverpoint address_value {
|
|
bins many = {
|
|
0,
|
|
1,
|
|
2,
|
|
3,
|
|
4,
|
|
5,
|
|
6,
|
|
7,
|
|
8,
|
|
9,
|
|
10,
|
|
11,
|
|
12,
|
|
13,
|
|
14,
|
|
15,
|
|
16,
|
|
17,
|
|
18,
|
|
19,
|
|
20,
|
|
21,
|
|
22
|
|
};
|
|
}
|
|
endgroup
|
|
endclass
|
|
====
|
|
# a macro supplying a coverpoint's whole bin body rewinds to the byte-for-byte
|
|
# verbatim capture covergroups had before this round
|
|
class c;
|
|
covergroup cg;
|
|
cp: coverpoint a `GPR_BIN_TYPES
|
|
endgroup : cg
|
|
endclass
|
|
----
|
|
class c;
|
|
covergroup cg;
|
|
cp: coverpoint a `GPR_BIN_TYPES
|
|
endgroup : cg
|
|
endclass
|
|
====
|
|
# a macro standing where a cover item belongs is passed through, the way one
|
|
# standing where an item or a statement belongs is
|
|
class c;
|
|
covergroup cg;
|
|
`MY_CP(a, b)
|
|
cp: coverpoint a;
|
|
endgroup
|
|
endclass
|
|
----
|
|
class c;
|
|
covergroup cg;
|
|
`MY_CP(a, b)
|
|
cp: coverpoint a;
|
|
endgroup
|
|
endclass
|
|
====
|
|
# a covergroup at package scope
|
|
package p;
|
|
covergroup cg;
|
|
coverpoint x;
|
|
endgroup
|
|
endpackage
|
|
----
|
|
package p;
|
|
covergroup cg;
|
|
coverpoint x;
|
|
endgroup
|
|
endpackage
|
|
====
|
|
# the member qualifiers a covergroup may carry
|
|
class c;
|
|
local covergroup cg;
|
|
coverpoint x;
|
|
endgroup
|
|
static covergroup cg2;
|
|
coverpoint y;
|
|
endgroup
|
|
endclass
|
|
----
|
|
class c;
|
|
local covergroup cg;
|
|
coverpoint x;
|
|
endgroup
|
|
static covergroup cg2;
|
|
coverpoint y;
|
|
endgroup
|
|
endclass
|
|
====
|
|
# every name goes through `name_doc`: an escaped identifier keeps its
|
|
# terminating space
|
|
class c;
|
|
covergroup \cg-1 ;
|
|
\cp-1 : coverpoint \a-1 {
|
|
bins \b-1 = {1};
|
|
}
|
|
endgroup : \cg-1
|
|
endclass
|
|
----
|
|
class c;
|
|
covergroup \cg-1 ;
|
|
\cp-1 : coverpoint \a-1 {
|
|
bins \b-1 = {1};
|
|
}
|
|
endgroup : \cg-1
|
|
endclass
|
|
====
|
|
# a covergroup with no items at all
|
|
class c;
|
|
covergroup cg;
|
|
endgroup
|
|
endclass
|
|
----
|
|
class c;
|
|
covergroup cg;
|
|
endgroup
|
|
endclass
|
|
====
|
|
# a blank line between two cover items is kept
|
|
class c;
|
|
covergroup cg;
|
|
cp1: coverpoint a;
|
|
|
|
cp2: coverpoint b;
|
|
endgroup
|
|
endclass
|
|
----
|
|
class c;
|
|
covergroup cg;
|
|
cp1: coverpoint a;
|
|
|
|
cp2: coverpoint b;
|
|
endgroup
|
|
endclass
|
|
====
|
|
# the unsized `[]` array spelling, on both a value and a default bin
|
|
class c;
|
|
covergroup cg with function sample(bit a);
|
|
cp: coverpoint a {
|
|
bins v[] = {[0:$]};
|
|
bins w[] = default;
|
|
}
|
|
endgroup
|
|
endclass
|
|
----
|
|
class c;
|
|
covergroup cg with function sample(bit a);
|
|
cp: coverpoint a {
|
|
bins v[] = {[0:$]};
|
|
bins w[] = default;
|
|
}
|
|
endgroup
|
|
endclass
|
|
====
|
|
# a bare `@ev` event keeps its lack of parentheses; an `or` list keeps its
|
|
# spelling
|
|
module m;
|
|
covergroup cg @ev;
|
|
coverpoint x;
|
|
endgroup
|
|
covergroup cg2 @(a or b);
|
|
coverpoint y;
|
|
endgroup
|
|
endmodule
|
|
----
|
|
module m;
|
|
covergroup cg @ev;
|
|
coverpoint x;
|
|
endgroup
|
|
covergroup cg2 @(a or b);
|
|
coverpoint y;
|
|
endgroup
|
|
endmodule
|
|
====
|
|
# a concatenation as the sampled expression, and an `iff` guard on it
|
|
class c;
|
|
covergroup cg;
|
|
cp: coverpoint {a, b, (c != d)} iff (!rst) {
|
|
bins z = {0};
|
|
}
|
|
endgroup
|
|
endclass
|
|
----
|
|
class c;
|
|
covergroup cg;
|
|
cp: coverpoint {a, b, (c != d)} iff (!rst) {
|
|
bins z = {0};
|
|
}
|
|
endgroup
|
|
endclass
|
|
====
|
|
# a `{` written on its own line cuddles onto the header
|
|
class c;
|
|
covergroup cg;
|
|
cp: coverpoint a
|
|
{
|
|
bins v = {1};
|
|
}
|
|
endgroup
|
|
endclass
|
|
----
|
|
class c;
|
|
covergroup cg;
|
|
cp: coverpoint a {
|
|
bins v = {1};
|
|
}
|
|
endgroup
|
|
endclass
|
|
====
|
|
# a covergroup whose `endgroup` label is missing keeps none
|
|
class c;
|
|
covergroup cg;
|
|
cp: coverpoint a;
|
|
endgroup
|
|
endclass
|
|
----
|
|
class c;
|
|
covergroup cg;
|
|
cp: coverpoint a;
|
|
endgroup
|
|
endclass
|
|
====
|
|
# `option` and `type_option` inside a coverpoint body, beside its bins
|
|
class c;
|
|
covergroup cg;
|
|
cp: coverpoint a {
|
|
option.weight = 3;
|
|
type_option.merge_instances = 1;
|
|
bins v = {1};
|
|
}
|
|
endgroup
|
|
endclass
|
|
----
|
|
class c;
|
|
covergroup cg;
|
|
cp: coverpoint a {
|
|
option.weight = 3;
|
|
type_option.merge_instances = 1;
|
|
bins v = {1};
|
|
}
|
|
endgroup
|
|
endclass
|
|
====
|
|
# an unlabelled coverpoint and an unlabelled cross
|
|
class c;
|
|
covergroup cg;
|
|
coverpoint a;
|
|
cross a, b;
|
|
endgroup
|
|
endclass
|
|
----
|
|
class c;
|
|
covergroup cg;
|
|
coverpoint a;
|
|
cross a, b;
|
|
endgroup
|
|
endclass
|
|
====
|
|
# a transition bin whose ranges carry value ranges of their own
|
|
class c;
|
|
covergroup cg;
|
|
cp: coverpoint a {
|
|
bins any2any[] = ([None:Bidir] => [None:Bidir]);
|
|
bins two = (Read, Write => RStart);
|
|
}
|
|
endgroup
|
|
endclass
|
|
----
|
|
class c;
|
|
covergroup cg;
|
|
cp: coverpoint a {
|
|
bins any2any[] = ([None:Bidir] => [None:Bidir]);
|
|
bins two = (Read, Write => RStart);
|
|
}
|
|
endgroup
|
|
endclass
|
|
====
|
|
# a scope-qualified name in a bin value and in a `with` filter
|
|
class c;
|
|
covergroup cg;
|
|
cp: coverpoint a {
|
|
bins on = {lc_ctrl_pkg::On};
|
|
bins bad = {[0:$]} with (!(item inside {lc_ctrl_pkg::Off, lc_ctrl_pkg::On}));
|
|
}
|
|
endgroup
|
|
endclass
|
|
----
|
|
class c;
|
|
covergroup cg;
|
|
cp: coverpoint a {
|
|
bins on = {lc_ctrl_pkg::On};
|
|
bins bad = {[0:$]} with (!(item inside {lc_ctrl_pkg::Off, lc_ctrl_pkg::On}));
|
|
}
|
|
endgroup
|
|
endclass
|
|
====
|
|
# a covergroup nested in a class that also carries a constraint: both bodies
|
|
# are laid out, and neither reaches into the other
|
|
class item;
|
|
rand int addr;
|
|
constraint c_addr { addr < 64; }
|
|
covergroup cg_addr with function sample (int a);
|
|
cp: coverpoint a { bins lo = {[0:31]}; }
|
|
endgroup
|
|
endclass
|
|
----
|
|
class item;
|
|
rand int addr;
|
|
constraint c_addr {
|
|
addr < 64;
|
|
}
|
|
covergroup cg_addr with function sample(int a);
|
|
cp: coverpoint a {
|
|
bins lo = {[0:31]};
|
|
}
|
|
endgroup
|
|
endclass
|
|
====
|
|
# a comment written where the `;` of an item was not written belongs to the
|
|
# item that follows it
|
|
class c;
|
|
covergroup cg;
|
|
cp: coverpoint x {
|
|
}
|
|
// why
|
|
cr: cross a, b;
|
|
endgroup
|
|
endclass
|
|
----
|
|
class c;
|
|
covergroup cg;
|
|
cp: coverpoint x {}
|
|
// why
|
|
cr: cross a, b;
|
|
endgroup
|
|
endclass
|
|
====
|
|
# a coverpoint bin's `( ... )` is a transition list even with no arrow; a
|
|
# cross bin's is a parenthesized select expression
|
|
class c;
|
|
covergroup cg;
|
|
cp: coverpoint a {
|
|
bins zero_delay_5 = (1'b1[*5]);
|
|
bins stall_long = (1'b0[*5:10] => 1'b1);
|
|
}
|
|
cr: cross a, b {
|
|
bins any = (binsof(a) || binsof(b)) && !binsof(c);
|
|
}
|
|
endgroup
|
|
endclass
|
|
----
|
|
class c;
|
|
covergroup cg;
|
|
cp: coverpoint a {
|
|
bins zero_delay_5 = (1'b1[*5]);
|
|
bins stall_long = (1'b0[*5:10] => 1'b1);
|
|
}
|
|
cr: cross a, b {
|
|
bins any = (binsof(a) || binsof(b)) && !binsof(c);
|
|
}
|
|
endgroup
|
|
endclass
|
|
====
|
|
# a call may stand as a bin spec, and a concatenation may stand as a
|
|
# transition item
|
|
class c;
|
|
covergroup cg;
|
|
cp: coverpoint a {
|
|
bins single_exc[] = single_masks(num_hw_apps);
|
|
bins req_before_done = ({1'b1, pkg::False} => {1'b1, pkg::True});
|
|
}
|
|
endgroup
|
|
endclass
|
|
----
|
|
class c;
|
|
covergroup cg;
|
|
cp: coverpoint a {
|
|
bins single_exc[] = single_masks(num_hw_apps);
|
|
bins req_before_done = ({1'b1, pkg::False} => {1'b1, pkg::True});
|
|
}
|
|
endgroup
|
|
endclass
|
|
====
|