Debugging a Basic UVM Testbench
Learn a systematic method for finding where a UVM testbench stops behaving as expected.
Learning objectives
- Explain how to debug a UVM testbench by following a transaction through its components.
- Distinguish common problems in sequences, drivers, monitors, scoreboards, and connections.
- Use UVM reports and simple checks to identify the first point where behavior becomes incorrect.
- Build a small debugging strategy that can be reused on larger UVM environments.
Step 1: Understand the concept
Debugging a UVM testbench is not just looking at waveforms until something appears wrong. A better approach is to follow one transaction through the verification environment and determine where the expected behavior changes.
For a simple active agent, the transaction usually follows this path:
Each stage has a different responsibility:
- Sequence: creates the scenario and transaction values.
- Sequencer: supplies sequence items to the driver.
- Driver: converts a transaction into protocol-level signal activity.
- DUT: performs the actual design behavior.
- Monitor: observes completed protocol activity and reconstructs transactions.
- Scoreboard: compares observed behavior against the expected result.
The most important debugging rule is:
A scoreboard mismatch may be caused by an incorrect sequence, driver timing, monitor sampling, or DUT behavior. The scoreboard is often where the problem becomes visible, not where it originated.
Step 2: Study the debugging flow
Suppose a test sends a write transaction and the scoreboard reports the wrong data. Instead of immediately changing the scoreboard, trace the transaction backward and forward.
- Confirm that the sequence created the expected transaction.
- Confirm that the driver received the same transaction.
- Check that the driver placed the correct values on the interface.
- Check that the DUT responded at the expected protocol point.
- Check that the monitor sampled the correct cycle.
- Only then investigate the scoreboard comparison itself.
A few targeted UVM messages can make this process much easier:
task body();
packet req;
`uvm_info("SEQ",
$sformatf("Sending data=0x%0h", data),
UVM_MEDIUM)
start_item(req);
req.data = data;
req.valid = 1;
finish_item(req);
endtask
task run_phase(uvm_phase phase);
forever begin
seq_item_port.get_next_item(req);
`uvm_info("DRV",
$sformatf("Driving data=0x%0h", req.data),
UVM_MEDIUM)
vif.valid <= req.valid;
vif.data <= req.data;
@(posedge vif.clk);
seq_item_port.item_done();
end
endtask
If the sequence prints 0x55 but the driver prints 0xAA, the problem is before the DUT. If both print 0x55 but the monitor reports 0xAA, investigate interface timing and monitor sampling.
This gives you a useful debugging technique: place evidence at component boundaries.
Step 3: Recognize common UVM symptoms
Different symptoms often point toward different parts of the testbench.
| Symptom | Possible cause | First thing to check |
|---|---|---|
| No transactions are generated | Sequence was not started or has no items | Sequence start and sequence messages |
| Sequence runs but driver is silent | Sequencer/driver connection or handshake problem | seq_item_port connection and driver logs |
| Driver runs but DUT sees nothing | Virtual interface or driver timing problem | Interface signals in the waveform |
| Monitor sees unexpected values | Sampling at the wrong protocol event | Monitor event condition and clock edge |
| Scoreboard reports mismatches | Incorrect DUT, expected model, or observed transaction | Compare expected and actual transactions |
| Simulation never finishes | Outstanding objection or infinite activity | Phase objections and test completion |
Step 4: Debug the monitor carefully
Monitor bugs are especially dangerous because they can make a correct DUT appear incorrect. The monitor must sample a transaction at the protocol's actual completion point.
task collect_transfer();
packet observed;
@(posedge vif.clk iff vif.valid && vif.ready);
observed = packet::type_id::create("observed");
observed.data = vif.data;
observed.addr = vif.addr;
`uvm_info("MON",
$sformatf("Observed addr=0x%0h data=0x%0h",
observed.addr,
observed.data),
UVM_MEDIUM)
analysis_port.write(observed);
endtask
The important part is the event control:
@(posedge vif.clk iff vif.valid && vif.ready);
This means the monitor waits for a clock edge where the transfer is actually accepted. Sampling merely because valid is high may capture a transaction before the protocol considers it complete.
When debugging a monitor, compare three things in the waveform:
- The protocol handshake.
- The signal values on the sampling cycle.
- The transaction printed by the monitor.
If those three do not agree, the monitor is a strong candidate for the problem.
Step 5: Debug the scoreboard
A scoreboard should provide useful evidence when something fails. Avoid a message that only says "mismatch." Print enough information to understand what was expected and what was observed.
if (actual.data != expected.data) begin
`uvm_error("SCOREBOARD",
$sformatf(
"Data mismatch: expected=0x%0h actual=0x%0h",
expected.data,
actual.data))
end
else begin
`uvm_info("SCOREBOARD",
$sformatf("PASS: data=0x%0h", actual.data),
UVM_LOW)
end
A useful scoreboard message should answer at least three questions:
- What was expected?
- What was observed?
- Which transaction or address was involved?
For more complex environments, add transaction IDs, addresses, timestamps, or other context that helps you correlate the failure with the waveform.
Step 6: Use a disciplined debugging workflow
When a test fails, use the following order rather than making random changes:
- Reproduce: run the smallest test that demonstrates the failure.
- Locate: determine the first component where the behavior differs from expectations.
- Instrument: add a focused
uvm_info, assertion, or waveform marker. - Compare: compare the intended transaction with the observed transaction.
- Fix: change only the component responsible for the error.
- Regress: rerun the original test and at least one previously passing test.
Try it yourself
Imagine that your scoreboard reports:
UVM_ERROR: Data mismatch: expected=0x25 actual=0x52
Do not immediately change the scoreboard. Add or inspect messages at the sequence, driver, and monitor boundaries.
- Print the value generated by the sequence.
- Print the value received by the driver.
- Inspect the DUT interface on the transfer cycle.
- Print the value reconstructed by the monitor.
- Determine where
0x25first becomes0x52.
Challenge: If the sequence and driver both report 0x25, but the monitor reports 0x52, identify two possible monitor or protocol-timing problems before changing any code.
Quick self-check
- Can you explain the path from sequence item to scoreboard?
- Can you identify which component should be investigated when the driver receives no transaction?
- Can you explain why monitor timing matters?
- Can your scoreboard report both expected and actual values?
- Can you find the first incorrect value instead of simply reacting to the final error?
Key takeaways
- Debug UVM environments by tracing transactions through component boundaries.
- Find the first incorrect behavior rather than assuming the component that reports the error is responsible.
- Use targeted UVM messages, assertions, and waveforms as evidence.
- Monitor timing is critical because an incorrectly sampled transaction can make correct DUT behavior look wrong.
- Change one thing at a time and rerun a small, reproducible test.
- A strong scoreboard failure message should identify the expected value, actual value, and useful transaction context.