C19.2 Override in the Subclass

HardFixVerilator coverage build · serverReview the topic

Fix a subclass covergroup that reads 0% because the base class keeps sampling its own covergroup of the same name.

Hardware context: A base monitor and a burst monitor that extends it. Make the subclass covergroup the one that observe() samples.

This is a Fix problem: the class in the editor has one realistic defect. Find it and fix it.

The base monitor mon covers lengths with automatic bins. The burst monitor burst_mon extends it and declares its own cov with the plan's four length classes. Tests sample through observe(), and the report reads m.cov on a burst_mon handle m.

Every burst test reports 0% for the burst monitor, however many bursts it sends.

Signals in the Timeline

SignalWidthRole
samples8input of each check
Full specification
Given (in the preamble)
// The base monitor (given): one covergroup, sampled by observe().
class mon;
  bit [3:0] len;
  covergroup cov;
    coverpoint len;
  endgroup
  function new();
    cov = new;
  endfunction
  virtual function void observe(bit [3:0] l);
    len = l;
    cov.sample();
  endfunction
endclass
Bin of burst_mon.covLengths
single1
short_2 to 4
long_5 to 8
max9 to 15

Each case builds a fresh burst_mon m, calls m.observe(len) for each length, and reads m.cov.get_inst_coverage() times 100, rounded. The full check samples more lists than the examples show.

Examples

Example 1

One Single Beat
Input
lengths: 1
Output
coverage_percent_x100 = 2500

single is hit: 1 of 4, 25.00%.

Example 2

Short and Long
Input
lengths: 3 6
Output
coverage_percent_x100 = 5000

3 is short_, 6 is long_: 2 of 4.

Example 3

Length 0
Input
lengths: 1 2 8 0
Output
coverage_percent_x100 = 7500

0 is in no bin. 1, 2 and 8 cover single, short_ and long_: 3 of 4.

Constraints and Contract

  • Keep the class name, the covergroup name cov and its bins.
  • Do not change the base class.

Hints

Hint 1

Inside mon::observe(), which cov does the name refer to?

Hint 2

A subclass covergroup of the same name hides the base one only for code that sees the subclass.

Hint 3

IEEE 1800-2023 covergroup extends would fix this at the source, but the coverage build rejects it (lesson C19).

What the grader checks: A fresh burst_mon per case is sampled through observe() with 18 lists of lengths. The subclass covergroup's instance coverage is compared with the value IEEE 1800-2023 clause 19 gives. Three lists are shown.

18 checks on Verilator coverage build · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 3 steps and the final capstone

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

One Single Beat

Input
lengths: 1
Expected output
coverage_percent_x100 = 2500

single is hit: 1 of 4, 25.00%.

Run samples executes all 3 public checks. Check all tests runs 18 checks on the server.

Verilator coverage build · server