Difficulty: Medium · Puzzle 5 of 6 · Topic: Covergroup and Coverpoint Puzzles
Compute legal coverage and classify each sampled value as legal, ignored, or illegal. Options: none set (all defaults: at_least = 1, weight = 1, auto_bin_max = 64).
covergroup cg with function sample(bit [3:0] req_len);
cp_len: coverpoint req_len {
bins short = {[1:4]};
bins long = {[5:8]};
ignore_bins keepalive = {0};
illegal_bins too_big = {[9:15]};
}
endgroup
initial begin
cg c = new();
c.sample(0);
c.sample(3);
c.sample(6);
c.sample(10);
c.sample(2);
c.sample(15);
endOnly short and long are legal scored bins in the denominator.
1) Legal bins are short and long -> denominator 2.
2) Hits: short hit by 3 and 2, long hit by 6.
3) Value 0 is ignored (keepalive), values 10 and 15 are illegal.
4) Legal coverage is 2/2 = 100% with two illegal hits logged.Answer: Legal coverage is 100% (short and long both hit). Sample classification: ignored={0}, illegal={10,15}, legal={3,6,2}.
Checked by running a model of the rule in a Python model. A model of the LRM rule: ignored and illegal values never reach the legal bins, which both end up hit.
Ignore and illegal activity can be present even when legal coverage is 100%, so closure does not imply protocol correctness.
Would you keep too_big as illegal_bins or move it to assertions for better debug diagnostics? Model answer: Do both. An assertion in the monitor is always active, gives a timed message and works without coverage enabled; illegal_bins is a backstop that flags the same event in the coverage database. Do not rely on illegal_bins alone as the protocol check.
I would classify each sample first: 0 is ignored, 10 and 15 are illegal, and 3, 6 and 2 are legal. Both legal bins, short and long, are hit, so legal coverage is 100 percent. Ignored values leave the calculation and illegal values only raise errors. The trap is reading 100 percent as protocol correctness, because two illegal hits happened, so I would check the illegal count too.