End-of-Test Scoreboard Draining
Finish a UVM test only after in-flight verification work has been processed, while distinguishing normal draining from missing or late responses.
Learning objectives
- Explain why a test can end before a scoreboard has processed all expected transactions.
- Distinguish end-of-test draining from timeout detection.
- Understand how UVM objections keep phases alive while verification work is still in progress.
- Design a scoreboard with explicit outstanding-state and drain behavior.
- Choose a practical strategy for waiting for expected responses before allowing a test to finish.
- Detect unresolved transactions at the end of the drain period.
- Avoid arbitrary delays that make regressions slow or nondeterministic.
Why end-of-test draining matters
A test can finish generating stimulus before the DUT has finished processing that stimulus.
For example:
100 ns Test sends request ID=10
110 ns Test sends request ID=11
120 ns Test sequence completes
120 ns Test drops its objection
...
150 ns DUT produces response ID=10
180 ns DUT produces response ID=11
If the test ends at 120 ns, the scoreboard never gets the opportunity to check the two responses.
This creates one of the most dangerous verification failures: a test can appear to pass simply because it ended before the checker observed the failure.
Step 1: Understand the difference between timeout and drain
Lesson 28 introduced timeout detection. These two mechanisms solve different problems.
| Mechanism | Question it answers | Typical trigger |
|---|---|---|
| Timeout detection | Did this transaction take too long? | A transaction exceeds its deadline. |
| End-of-test draining | Has all expected work completed before the test ends? | Stimulus generation has finished, but transactions may still be in flight. |
Consider a request with a 100-cycle response limit.
Request accepted at cycle 100
Test stimulus ends at cycle 110
Response arrives at cycle 130
The test should not necessarily end at cycle 110. It should drain the outstanding work.
If the response does not arrive by cycle 200, timeout detection should report the missing response.
Draining and timeout detection therefore work together:
Stimulus complete
|
v
Are transactions still outstanding?
|
yes/no
|
v
Allow DUT/checkers to drain
|
v
All complete? ---- yes ----> finish
|
no
|
v
Deadline expires?
|
yes/no
|
v
Timeout / unresolved work Step 2: Understand UVM objections
UVM objections provide a mechanism for components and tests to indicate that a phase should remain active.
A common pattern is:
task run_phase(uvm_phase phase);
phase.raise_objection(this);
// Generate stimulus and perform test work.
phase.drop_objection(this);
endtask
The important concept is not the syntax itself. The objection tells the phase that this component still has work associated with the phase.
A test should not drop its objection merely because the sequence has finished generating requests if responses are still required for verification.
Step 3: Why the scoreboard should not blindly control test completion
It may be tempting to make the scoreboard responsible for deciding when the entire simulation ends.
For example:
// Avoid making the scoreboard the owner of the whole test lifecycle.
if (expected_count == received_count)
$finish;
This creates architectural problems:
- The scoreboard now controls simulation termination.
- Other verification components may still have work to perform.
- Multiple tests may require different completion policies.
- End-of-test behavior becomes tightly coupled to one checker.
A better architecture is for the test or virtual sequence to own the overall test lifecycle while the scoreboard exposes enough state or synchronization information to determine whether verification work has drained.
Test / virtual sequence
|
| controls test lifecycle
v
DUT activity
|
+------------------+
| |
v v
actual monitor predictor
| |
v v
scoreboard
|
v
outstanding = 0
|
v
drain complete Step 4: Track outstanding work explicitly
The scoreboard needs a clear definition of what “drained” means.
For an out-of-order scoreboard, this may be as simple as:
typedef int unsigned id_t;
packet expected_by_id[id_t];
function bit is_drained();
return expected_by_id.size() == 0;
endfunction
If the environment has multiple streams, the definition may include several outstanding collections:
function bit is_drained();
return (expected_a.size() == 0) &&
(expected_b.size() == 0) &&
(pending_completions.size() == 0);
endfunction
The important point is that the condition should represent all verification work that must complete, not merely the number of transactions generated by the test.
Step 5: Use an explicit drain wait
One practical approach is for the test to wait until the scoreboard reports that all expected work has completed.
A simple conceptual interface might look like:
while (!scoreboard.is_drained()) begin
#1ns;
end
This demonstrates the idea, but arbitrary polling is not ideal for a reusable verification environment. A synchronization mechanism is usually clearer.
For example, the scoreboard can maintain an event that is triggered when the outstanding count reaches zero:
event drain_done;
After processing a response:
if (expected_by_id.size() == 0)
-> drain_done;
The test can then wait for the drain event rather than repeatedly polling.
task wait_for_drain();
if (scoreboard.is_drained())
return;
@scoreboard.drain_done;
endtask
This is a useful synchronization concept, although a production environment may use a more complete synchronization abstraction depending on how multiple producers and reset behavior are handled.
Step 6: Put a limit on the drain period
A dangerous implementation is:
wait_until_scoreboard_is_empty();
What happens if the DUT never produces the missing response?
The test can wait forever.
Therefore, draining needs a bounded completion policy.
Stimulus complete
|
v
Begin drain
|
+---- all expected work complete ----> finish
|
+---- drain deadline expires ------> report unresolved work
The drain deadline is not necessarily the same thing as each transaction's normal protocol timeout.
A robust environment normally has both:
- Per-transaction timeout: detects an individual transaction that exceeded its allowed latency.
- Drain limit: prevents the test from waiting indefinitely for the environment to become empty.
Ideally, the per-transaction timeout should identify the missing response before the overall drain limit expires. The drain limit acts as a safety boundary around test completion.
Step 7: Avoid arbitrary “sleep and hope” delays
A common anti-pattern is:
// Stimulus is done.
#1000ns;
// Assume all responses have arrived.
This approach has two major problems.
Problem 1: The delay may be too short
A slower DUT or a heavily backpressured scenario may require more time.
Problem 2: The delay may be unnecessarily long
A fast test may finish much earlier, but the fixed delay still consumes simulation time.
Prefer a condition-based completion mechanism:
stimulus_complete
+
scoreboard_drained
+
other required end conditions
|
v
test may complete
The completion condition should describe actual verification state rather than an arbitrary amount of simulated time.
Step 8: Drain more than just the scoreboard
A scoreboard may become empty while other components still have pending work.
For example:
- a monitor may have an incomplete transaction,
- a predictor may have buffered input,
- an analysis FIFO may contain transactions not yet processed,
- a coverage component may still need to sample a completed transaction, or
- a protocol agent may still be handling final response activity.
Therefore, “scoreboard empty” should not automatically mean “entire environment finished.”
A mature test can define completion from several conditions:
stimulus_complete
AND
scoreboard_drained
AND
predictor_drained
AND
required_protocol_activity_complete
|
v
test complete
This becomes particularly important in environments with analysis FIFOs because transactions may have been published but not yet consumed by downstream components.
Step 9: Handle end-of-test failures explicitly
Suppose the drain period ends and the scoreboard still contains expectations:
Expected:
ID=10
ID=11
Actual:
ID=10
End of drain:
ID=11 still outstanding
The environment should report the unresolved transaction with useful context.
if (!scoreboard.is_drained()) begin
`uvm_error("SB_DRAIN",
$sformatf(
"End-of-test drain expired with %0d outstanding transactions",
scoreboard.outstanding_count()))
end
For an out-of-order scoreboard, the diagnostic should ideally identify the remaining IDs:
Outstanding IDs: 11, 14, 18
This connects directly to the diagnostics work in Lesson 30.
Step 10: Reset and drain state
Reset can invalidate outstanding transactions during a test, so the drain policy must understand reset semantics.
For example:
Request ID=21 accepted
Request ID=22 accepted
Reset asserted
Reset cancels both requests
Test continues with new traffic
The scoreboard should not wait forever for IDs 21 and 22 if the protocol defines reset as cancellation.
Therefore:
reset
|
+-- flush expected transactions
+-- clear timeout state
+-- clear pending actuals according to policy
+-- establish a new verification epoch
The exact behavior is protocol-specific, but it must be explicit. Otherwise, reset-related stale state can make the test appear to hang during its final drain.
Step 11: A practical test-level pattern
A simplified test can coordinate stimulus and draining like this:
task run_phase(uvm_phase phase);
phase.raise_objection(this);
// Generate the scenario.
scenario_seq.start(env.vseqr);
// No more stimulus will be generated.
`uvm_info("TEST", "Stimulus complete; beginning drain", UVM_MEDIUM)
// Wait for all required verification work.
wait_for_environment_drain();
`uvm_info("TEST", "Verification drain complete", UVM_MEDIUM)
phase.drop_objection(this);
endtask
The key architectural separation is:
- The test owns the phase objection and overall completion policy.
- The sequence generates stimulus.
- The monitor observes actual protocol activity.
- The predictor produces expected transactions.
- The scoreboard tracks outstanding expectations and determines whether its checking work is drained.
This prevents the scoreboard from becoming the owner of the entire simulation lifecycle.
Common mistakes
- Dropping the test objection immediately after the sequence finishes: the DUT may still have responses in flight.
- Using a fixed
#delayas the drain mechanism: the delay can be either insufficient or unnecessarily long. - Waiting forever for an empty scoreboard: a missing response can turn the test into a hung simulation.
- Treating an outstanding transaction as automatically failed: it may still be within its legal latency window.
- Using the scoreboard as the global simulation terminator: other components may still have work.
- Ignoring analysis FIFO contents: the scoreboard may appear empty while transactions are still buffered upstream.
- Forgetting reset semantics: cancelled transactions can remain outstanding and prevent the environment from draining.
- Reporting only a count: “3 transactions outstanding” is less useful than identifying their IDs, streams, and acceptance times.
- Assuming all environments have the same drain rule: a simple in-order protocol and a multi-agent asynchronous system may require very different completion policies.
Debugging strategy: why did the test not finish?
When a test hangs or reaches the end of its drain period with outstanding work, trace the completion path rather than immediately increasing the delay.
- Confirm stimulus completion. Did the sequence actually finish?
- Check the test objection. Is the expected component still holding the phase open?
- Inspect outstanding expectations. Which IDs or streams remain?
- Check timeout state. Should one or more transactions already have timed out?
- Inspect monitor output. Did the response occur on the interface?
- Inspect analysis FIFOs. Is the transaction waiting to be consumed?
- Check predictor output. Was an expected transaction created?
- Check reset behavior. Was outstanding work cancelled but not removed?
- Check the drain deadline. Is the completion policy itself too aggressive?
A useful mental model is:
Why is the test still waiting?
|
+-- Stimulus not complete?
|
+-- Expected transaction still outstanding?
|
+-- Response not produced?
|
+-- Response not monitored?
|
+-- Response buffered in TLM?
|
+-- Predictor/checker state incorrect?
|
+-- Reset state not cleared?
|
+-- Drain policy incorrect?
Exercise 1: Find the premature termination
A test performs:
100 ns Request ID=1 sent
110 ns Request ID=2 sent
120 ns Sequence completes
120 ns Test drops objection
160 ns Response ID=1
180 ns Response ID=2
Explain why the scoreboard may never see the responses. Modify the test architecture so that the phase remains active until the expected verification work has drained.
Exercise 2: Replace a fixed drain delay
Start with:
scenario_seq.start(env.vseqr);
#1000ns;
phase.drop_objection(this);
Replace the fixed delay with a condition-based drain mechanism.
Your implementation should:
- wait for the expected transactions to complete,
- stop waiting when the environment is drained, and
- report a failure if the drain deadline expires first.
Exercise 3: Drain with a missing response
Create three expected responses:
ID=10
ID=11
ID=12
Allow responses for ID=10 and ID=12 to arrive, but never generate ID=11.
Verify that:
- the scoreboard does not declare itself drained prematurely,
- the missing transaction can be identified,
- the transaction timeout can report the missing response if its deadline expires, and
- the overall drain mechanism eventually allows the test to terminate with a meaningful failure.
Advanced challenge: multi-stream end-of-test coordination
Build an environment with:
- an in-order command stream,
- an out-of-order response stream,
- a predictor,
- analysis FIFOs, and
- a shared scoreboard.
The test should complete only when:
stimulus complete
AND
command stream drained
AND
response expectations drained
AND
required predictor/FIFO work drained
Then inject a missing response and verify that the environment does not hang forever. Instead, the timeout and drain mechanisms should identify the unresolved transaction and end the test with a useful failure.
Success criterion: you can explain which component owns each part of completion, why the test remains alive while work is outstanding, and exactly what happens when the drain deadline expires.
Knowledge check
- Why can a test sequence finishing not mean that verification is complete?
- What is the difference between a per-transaction timeout and an end-of-test drain limit?
- Why is a fixed
#delaygenerally weaker than a condition-based drain? - Why should the scoreboard normally not call
$finish? - Why can a scoreboard be empty while the environment still has work to process?
- What should happen to outstanding transactions when reset legally cancels them?
- Why should a drain mechanism have a bounded completion policy?
Answers
- The DUT may still have requests in flight and responses may still need to be observed and checked.
- A transaction timeout determines whether one transaction exceeded its allowed latency; a drain limit prevents the overall test from waiting indefinitely for unfinished work.
- A fixed delay may be too short for a slow scenario or unnecessarily long for a fast one.
- The test owns the overall lifecycle; other components may still have work that must complete.
- Transactions may still be buffered in monitors, predictors, analysis FIFOs, or other checking paths.
- The checker should clear or otherwise reclassify those transactions according to the protocol's reset semantics.
- Without a bound, a missing response can leave the test waiting forever.
Key takeaways
- Stimulus completion is not verification completion.
- Use UVM phase objections to keep the relevant phase alive while the test still has verification work to complete.
- Let the test own the overall lifecycle while the scoreboard exposes meaningful checking/drain state.
- Prefer condition-based draining over arbitrary fixed simulation delays.
- Per-transaction timeouts detect individual latency violations; drain limits prevent indefinite end-of-test waiting.
- Draining may need to include predictors, analysis FIFOs, monitors, and multiple scoreboard streams—not just one expected-transaction table.
- Reset must explicitly define how outstanding work is cancelled or preserved.
- When draining fails, report the actual unresolved transactions rather than only saying that the test timed out.
Where this lesson fits
The checking architecture now has a complete path from prediction to controlled completion:
Lesson 21 Scoreboard patterns
↓
Lesson 22 Reference models
↓
Lesson 23 Predictors
↓
Lesson 24 In-order scoreboards
↓
Lesson 25 Out-of-order scoreboards
↓
Lesson 26 Multi-stream scoreboards
↓
Lesson 27 Error handling
↓
Lesson 28 Timeout detection
↓
Lesson 29 End-of-test draining
↓
Lesson 30 Debug-friendly diagnostics
Lesson 28 answers “Did this transaction take too long?”
Lesson 29 answers “Has the environment finished processing the work required by this test?”
Lesson 30 will build on both by answering a practical regression question: “When something fails, how do we make the failure fast to understand?”