Fix a per-port coverage report that prints the same number for every port.
Hardware context: A 3-port switch with one covergroup instance per port. Report each port's own coverage, not the type number.
This is a Fix problem: the code in the editor has one realistic defect. Find it and fix it.
A switch has three ports, each with its own instance of port_cg. A report function port_pct(cg) should give one port's coverage. Every port shows the same number, even when one port sent nothing.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
samples | 8 | input of each check |
Full specification
port_cg pc [3]; // one instance per port, fresh per case
// result = 1 * port_pct(pc[0]) + 2 * port_pct(pc[1]) + 3 * port_pct(pc[2])
The weights 1, 2 and 3 only tell the ports apart in one number. The full check samples more lists than the examples show.
Examples
Example 1
One Packet on Port 0- Input
packets (port, len): (0, 1)
- Output
coverage_percent_x100 = 3333
Port 0 has 1 of 3 bins: 33.33% (3333). Ports 1 and 2 have 0: the result is 3333.
Example 2
Port 1 Only- Input
packets (port, len): (1, 3) (1, 9)
- Output
coverage_percent_x100 = 13334
Port 1 has 2 of 3 bins (6667), counted twice: 13334.
Example 3
Every Port- Input
packets (port, len): (0, 1) (1, 3) (2, 9)
- Output
coverage_percent_x100 = 19998
Each port has 1 of 3 bins: 3333 x (1 + 2 + 3) = 19998.
Constraints and Contract
- Keep the covergroup and the function header
int port_pct(port_cg cg). - Keep the bins.
Hints
Hint 1
Which method returns one instance's number, and which the number of the whole type?
Hint 2
Does option.per_instance change what either method returns?
Hint 3
With every port at a different number, the weighted sum must change when one port alone gets a new sample.
What the grader checks: Three instances are sampled per case with 18 lists of packets. The weighted sum of your per-port numbers is compared with the values IEEE 1800-2023 19.8 and 19.11 give. 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