Difficulty: Medium · Puzzle 5 of 6 · Topic: Scoreboard Puzzles: Mismatch or Ordering Bug?
Random tests fail with 'expected queue not empty' in about 2% seeds. DUT has variable response latency and can legally return after stimulus stops.
task run_phase(uvm_phase phase);
forever begin
compare_once();
end
endtask
function void check_phase(uvm_phase phase);
if (exp_q.size() != 0 || got_q.size() != 0)
\`uvm_error("SB", "leftover transactions");
endfunctionA scoreboard needs explicit drain policy when response latency is elastic.
1) Log queue sizes near end-of-test and observe they are shrinking but not yet zero.
2) Confirm no drain window exists between stimulus completion and final check.
3) Implement phase_ready_to_end wait/drain with bounded timeout and progress checks.
4) Keep objection until queues settle or timeout indicates real hang.
5) Track residual ids in timeout message for actionable debug.Answer: Bug: scoreboard checks leftovers immediately without allowing legal late responses to drain. Fix: add bounded end-of-test draining before final emptiness assertion.
Checked by running the code in Verilator 5; the printed output supports the answer above. Plain-SV model of elastic latency: an immediate check sees 3 leftovers, a progress-based drain sees none, and a truly lost response still times out.
Removing the check hides escapes; the right fix is controlled drain, not silence.
What timeout heuristic would you use so drain does not mask real deadlocks? Model answer: Bound it by the spec's maximum response latency times a margin, measured from the last progress event: restart the timer whenever the queue size changes, so a slow-but-moving drain continues while a stuck one fails after one latency window with the residual ids in the message.
First I check whether the leftover entries are late legal responses or truly lost ones, by looking at when the check runs relative to the last traffic. The root cause is that the scoreboard checks for leftovers immediately, without letting legal late responses drain. I confirm it by delaying the check and seeing the leftovers disappear. The fix is a bounded end-of-test drain before the final emptiness check, not removing the check.