Q178FreeDesign Verification
Detect missing type-priority coverage
Interview prompt
Question
Given packets containing type, size, and priority fields, track the type-by-priority cross without built-in covergroups. Report whether every expected pair has been observed and return the first missing pair.
Candidate starting point
Implementation scaffold
class CoverageGapDetector;
typedef struct packed {
int type_id;
int size;
int prio;
} packet_t;
local bit hit[];
local int num_types;
local int num_prios;
local int domain_size;
function new(int num_types, int num_prios);
longint signed total = longint'(num_types) * longint'(num_prios);
if (num_types <= 0 || num_prios <= 0 || total > 32'sh7fff_ffff)
$fatal(1, "positive coverage dimensions must fit the dense array index range");
this.num_types = num_types;
this.num_prios = num_prios;
domain_size = int'(total);
hit = new[domain_size];
endfunction
function void sample(packet_t p);
int index;
// Implement here: sample.
endfunction
function bit all_combinations_hit();
int hit_count = hit.sum() with (int'(item));
// Implement here: all_combinations_hit.
endfunction
function void first_missing(output int miss_type,
output int miss_prio);
// Implement here: first_missing.
endfunction
endclassReviewed example
Trace one case
Input
type_count=2, priority_count=2; sample (0,0),(0,1),(1,0)Expected output
all_combinations_hit=0; first_missing=(1,1)Three unique pairs set three cells in the dense 2x2 domain, leaving the row-major final pair unobserved.
What to cover
Requirements
- Validate both lower and upper bounds of the sampled type and priority values.
- Count repeated observations of the same pair only once.
- Implement all_combinations_hit and first_missing queries.
- Use dense storage proportional to the declared domain. Constructor dimensions must be positive and their product must fit the signed 32-bit dynamic-array size/index range; reject other dimensions before allocation.
- Do not use a SystemVerilog covergroup.
