7.5.8 Two coverpoints for the FIFO

EasyImplementVerilator coverage build · local serverReview the topic

Write a covergroup that records how full the FIFO was and which operations were requested.

Hardware context: Coverage closure and mutation analysis for a FIFO regression. Record FIFO occupancy and requested operations in a covergroup and read its instance coverage.

A green regression only means something if the stimulus reached the situations the plan lists. For the depth-4 FIFO, the first two questions are: did the test see the FIFO empty, partly full and full, and did it request each kind of operation?

Write the covergroup fifo_cov. Its sample method takes the occupancy before the edge and the two enables. Give it two coverpoints: level, with three bins (empty for 0, middle for 1 to 3, full for 4), and op, with four bins for the enable pair (idle, read only, write only, both).

Each case creates one instance, samples it, and reads its coverage with get_inst_coverage(). With no cross, the covergroup’s coverage is the average of its two coverpoints.

Signals in the timeline

SignalWidthRole
samples8input of each check
Full specification
What you write
covergroup fifo_cov with function sample(int used, bit write_en, bit read_en);
  // level: 3 bins; op: 4 bins
endgroup
CoverpointBins
level (used)empty = {0}, middle = {[1:3]}, full = {4}
op ({write_en, read_en})idle = 0, read = 1, write = 2, both = 3

The result is get_inst_coverage() times 100, rounded: 6250 means 62.50%. Sampling every level and every operation gives 10000.

Examples

Example 1

One sample
Input
samples (used, write_en read_en): (0, 00)
Output
coverage_percent_x100 = 2917

One level of three (33.33%) and one operation of four (25%): the average is 29.17%.

Example 2

Every level, writes only
Input
samples (used, write_en read_en): (0, 10) (2, 10) (4, 10)
Output
coverage_percent_x100 = 6250

level is 100% and op 25%: 62.50%.

Example 3

Everything reached
Input
samples (used, write_en read_en): (0, 00) (1, 01) (3, 10) (4, 11)
Output
coverage_percent_x100 = 10000

All three levels and all four operations: 100%.

Constraints and contract

  • used is 0 to 4 in every sample.
  • Keep the covergroup name and the sample arguments.
  • Use exactly these two coverpoints, with no cross.

Hints

Hint 1

with function sample(...) lets the testbench pass the values in, instead of the covergroup reading signals itself.

Hint 2

A coverpoint can be any expression; the concatenation {write_en, read_en} gives the four operations as the values 0 to 3.

Hint 3

Check the arithmetic on example 2: three of three levels and one of four operations average to 62.50%.

What this judge verifies: Your covergroup is sampled with 18 sets of values, from one sample to all seven bins, and its instance coverage is compared. Passing shows its bins match the plan.

18 checks on Verilator coverage build · local server. Run the examples first, then check the full regression. The suite is local and inspectable. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 9 steps and the final capstone
Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

One sample

Input
samples (used, write_en read_en): (0, 00)
Expected output
coverage_percent_x100 = 2917

One level of three (33.33%) and one operation of four (25%): the average is 29.17%.

Run samples executes all 3 example checks. Check all tests runs 18 checks.

Verilator coverage build · local server