How to terminate UVM Test

How to End a UVM Test: Objections, Drain Time and Timeouts

In short: a UVM run phase ends when no one holds an objection. The test raises one before its stimulus and drops it when the work is really done. A drain time gives the last items time to reach the scoreboard, and a global timeout ends a run that would otherwise hang. Get the raise, the drop and the drain right, and two whole classes of bug go away: tests that end at 0 ns, and tests that never end.

In plain SystemVerilog you call $finish yourself.

In UVM, the run phase decides on its own. It ends the moment nothing is holding it open.

That’s simple to say and easy to get wrong in three ways. Forget the raise, and the test ends before any stimulus runs. Forget the drop, and it never ends. Drop too early, and it ends while your last items are still inside the design, unchecked.

This lesson runs all of those on one small bench, on Synopsys VCS, so you can see each one in a real log.

By the end of this lesson, you’ll be able to:

  • Explain how UVM decides the run phase is over.
  • Use raise and drop correctly, and pick a drain time that covers your pipeline.
  • End a test on a condition, and set a global timeout for real hangs.
  • Spot a test that passes at 0 ns and a test that never ends, straight from the log.

The picture: a meeting that can’t end while a hand is up

Picture a meeting with one simple rule: it can’t end while anyone has a hand up.

You put your hand up when you have something to say. You lower it when you’re done. The chair doesn’t care what anyone is saying. The chair only watches hands. The moment the last hand goes down, the chair waits a few seconds, in case someone in the back has a final word, and then closes the meeting.

And the building closes at 10 pm, meeting or no meeting.

That’s the whole objection mechanism:

In the meetingIn UVMWhat it does
Raising your handphase.raise_objection(this)“Don’t end yet, I’m busy”
Lowering your handphase.drop_objection(this)“I’m done”
The chairThe run phaseEnds when no hands are up
The few seconds the chair waitsDrain timeLets the last words reach the room
The building closing at 10 pmGlobal timeoutEnds everything, finished or not
Nobody raised a handNo objectionMeeting closed before it began
Someone fell asleep with a hand upRaise with no dropNobody goes home until 10 pm

Keep this picture in mind. Every run below is one of these rows.

When does a UVM test end: no objection ends at 0 ns with 0 errors; raise and drop ends at 225 ns with 2 of 10 items unchecked; a 50 ns drain ends at 275 ns with all 10 checked; a missing drop hits the 2000 ns global timeout
Real times from the VCS runs below.

The raise and drop pattern

The pattern lives in the test’s run_phase. Raise, run the stimulus, drop.

task run_phase(uvm_phase phase);
  burst_seq seq = burst_seq::type_id::create("seq");
  phase.raise_objection(this, "burst");       // hand up
  seq.start(env.sqr);                          // the work
  phase.drop_objection(this, "burst sent");    // hand down
endtask

The text in quotes is optional. Add it anyway. UVM prints it in the objection trace, so a log tells you who is keeping the phase alive and why.

One thing this pattern hides: seq.start() returns when the last item has been driven, not when it has been checked. If your design has latency, the last few items are still inside it when the drop happens. The runs below show exactly how many.

Five endings, one bench

The bench is small on purpose: a 3-stage pipeline (data comes out 3 clocks after it goes in), a driver, a monitor on each side, and an in-order scoreboard. The sequence sends 10 items. Only the ending of the test changes between runs, chosen with +MODE=.

At the end of every run the test prints one line: when the run phase ended, how many items were sent, how many were checked, and how many went in but were never checked.

Real output, Synopsys VCS X-2025.06-SP1 with UVM 1.2:

RunRun phase endedSentCheckedNever checkedWhat the log says
no_raise0 ns000Nothing. No errors at all
raise_drop225 ns1082“2 item(s) went in but were never checked”
drain275 ns10100Clean
condition455 ns21201“1 item(s) went in but were never checked”
no_drop2000 nsn/an/an/aUVM_FATAL [PH_TIMEOUT] Explicit timeout of 2000 hit

no_raise is the scariest run. The test ended at 0 ns, sent nothing, checked nothing, and reported zero errors. In a regression that’s a green pass. Add a check that fails the test if nothing was sent.

raise_drop looks right and isn’t. The drop came at 225 ns, the moment the sequence finished, while 2 items were still inside the 3-stage pipeline. Only 8 of 10 were checked. The only reason we know is the scoreboard’s check_phase complaining about its non-empty queue. Without that check, this test passes.

UVM_INFO @ 225: reporter [TEST_DONE] 'run' phase is ready to proceed to the 'extract' phase
UVM_ERROR @ 225: uvm_test_top.env.sb [SB] 2 item(s) went in but were never checked
UVM_INFO @ 225: uvm_test_top [END] MODE=raise_drop run phase ended at 225: sent=10 checked=8 never checked=2

drain fixes it with one line. The same drop at 225 ns, then 50 ns of drain. The phase ended at 275 ns, and all 10 items were checked.

condition still lost one. The test dropped as soon as 20 items were checked, but traffic was still running: 21 were sent, and one was inside the pipeline. Ending on a condition doesn’t remove the need for a drain time.

no_drop hit the global timeout at exactly 2000 ns. Notice what’s missing: there’s no END line. A fatal skips report_phase, so anything you planned to print at the end of the test never appears. Print your counters before the timeout, from a watchdog, if you want them in a hung run’s log.

Back to the meeting: no_raise is a meeting where nobody raised a hand, so the chair closed it before anyone spoke. raise_drop is a speaker who lowered their hand the moment they stopped talking, while two people were still walking to the microphone. drain is the chair waiting a few seconds, and both of them got their turn. no_drop is someone asleep with a hand up, and everyone waited for the building to close.

Drain time: letting the tail settle

When the last objection drops, the phase would end on that same time step. A drain time makes UVM wait a little longer first, so the pipeline empties, the output monitor sees the last item and the scoreboard checks it.

In the meeting, this is the chair pausing after the last hand drops, because the last speaker’s words are still travelling across the room. Your pipeline is that room: data that has gone in but not yet come out.

task run_phase(uvm_phase phase);
  phase.phase_done.set_drain_time(this, 50ns);  // wait 50 ns after the last drop
  phase.raise_objection(this, "burst");
  seq.start(env.sqr);
  phase.drop_objection(this, "burst sent");    // the phase really ends 50 ns later
endtask

Pick a drain time that covers the longest path from input to checker. In this bench that’s 3 clocks of pipeline plus a clock for the monitor, so 50 ns at a 10 ns clock is plenty. Too short cuts off the tail. Too long only costs a little simulation time, so round up.

Older code sets this with uvm_test_done.set_drain_time(). That’s deprecated in UVM 1.2. Use the phase’s own objection, as above.

Ending on a condition, not a count

Many real tests should end when something happens, not after a fixed number of items. Keep the objection up until the condition is true, then drop it.

task run_phase(uvm_phase phase);
  phase.raise_objection(this, "until 20 checked");
  fork
    forever begin                     // keep traffic going
      burst_seq s = burst_seq::type_id::create("s");
      s.start(env.sqr);
    end
  join_none
  wait (env.sb.checked >= 20);        // the real end condition
  phase.drop_objection(this, "20 checked");
endtask

The traffic thread is still running when the drop happens. Items already inside the pipeline won’t be checked unless you add a drain time here too. The condition run below shows how many.

Think of a Q&A that ends after 20 questions are answered. When the 20th answer finishes, someone has already started asking the 21st. If the chair closes the meeting right then, that question is cut off. The pause still matters.

A global timeout for true hangs

Even with perfect objections, a design bug can leave a test waiting forever, for a response that never comes. A global timeout ends the run with a fatal so a regression doesn’t stall all night.

It’s the building closing at 10 pm. The guard doesn’t care why the meeting is still going. At 10, everyone leaves.

uvm_top.set_timeout(2us, 0);   // fail the run if it's still going after 2 us

You can also set it from the command line with +UVM_TIMEOUT. Without either one, UVM 1.2 waits 9200 seconds of simulated time. Set it a little above your longest clean run, per test.

For a test that hangs and you don’t know why, read Why Does My UVM Test Never End? It walks through five real hangs and a 5-minute triage.

Should monitors and drivers raise objections?

Usually not. Objections are counted across the whole testbench, so any component can hold the phase open. But the phase ends fine without monitors and drivers, and most benches leave them out.

Some teams have a monitor raise and drop around each transaction, so the test can’t end in the middle of a transfer:

// Works, but costs time on every transaction
task run_phase(uvm_phase phase);
  forever begin
    @(posedge vif.clk iff vif.valid);
    phase.raise_objection(this);
    collect_transaction();
    phase.drop_objection(this);
  end
endtask

That’s correct. It’s also slow on a big regression, because every raise and drop walks up the component tree. A drain time, or a scoreboard that raises in phase_ready_to_end() while it still has items queued, does the same job at a fraction of the cost.

In meeting terms: it’s like asking every attendee to raise a hand before each sentence and lower it after. It works, and nobody gets cut off. But the meeting runs slower, and the chair spends all day counting hands.

Whichever you choose, every raise needs a matching drop. A raise with no drop is the classic hang.

Common mistakes, with fixes

The test ends at 0 ns and nothing runs. No one raised an objection, so nothing held the phase open. Worse, the log shows zero errors, so it looks like a pass.

  • Fix A: raise in the test before seq.start().
  • Fix B: fail the test in check_phase if nothing was sent. Fix C: if the sequence raises for itself, make sure its starting phase is set. Raise/Drop objection Automatically covers that case.

The test never ends. Someone raised and never dropped.

  • Fix A: print who still holds an objection with phase.get_objection().display_objections(), or run with +UVM_OBJECTION_TRACE.
  • Fix B: set a global timeout so a hang costs minutes, not hours.

The last few items are never checked. The drop came when the sequence finished, but the design still had items in flight.

  • Fix A: add a drain time that covers the longest path from input to checker.
  • Fix B: make the scoreboard complain in check_phase if its queue isn’t empty. Without that check, this bug passes silently.

Using #1000 instead of an objection. A fixed delay breaks the day the timing changes. It either cuts the test short or wastes time.

  • Fix: tie the end of the test to real completion, with an objection and a condition.

Using the deprecated uvm_test_done. It still compiles in UVM 1.2 but is gone in IEEE 1800.2.

  • Fix: use phase.raise_objection(), phase.drop_objection() and phase.phase_done.set_drain_time().

How AI helps (and where it doesn’t)

Objection bugs are a good fit for an AI assistant, because the evidence is text: a log and a few lines of code.

  • Reading a trace. Paste a +UVM_OBJECTION_TRACE log and ask which raise has no matching drop. It’s fast at pairing them up.
  • Reviewing a test. Paste your run_phase and ask: “Where can this end before the scoreboard has checked everything?” It will usually spot a missing drain time.
  • Explaining the 9200 s wait. Ask why a test sat for hours before failing. It can explain the default timeout and how to set your own.

Where to be careful: AI can suggest raising objections in a monitor “to be safe”. That works, but it slows big regressions. And it can’t run your bench. The only proof that a drain time is long enough is a run where the scoreboard’s “never checked” count is zero.

Don’t paste confidential RTL or logs into public tools. Use what your company has approved. For the bigger picture, read AI in ASIC verification.

Interview questions

These come up a lot in UVM interviews. Try answering each one before reading the answer.

  1. What ends the run phase? The objection count reaching zero. If a drain time is set, UVM waits that long first, then ends the phase.
  2. How can a test pass at 0 ns with zero errors? No one raised an objection, so nothing held the phase open. In our run, sent=0 and checked=0, and the log looked clean.
  3. What is drain time, and how do you pick it? A short wait after the last drop, so items still in the design reach the scoreboard. Cover the longest path from input to checker. In our 3-stage pipeline, 50 ns took us from 8 checked to 10 of 10.
  4. What is UVM 1.2’s default timeout? 9200 seconds of simulated time. Set your own with uvm_top.set_timeout() or +UVM_TIMEOUT.
  5. Should you still use uvm_test_done? No. It’s deprecated in UVM 1.2 and gone in IEEE 1800.2. Use phase.raise_objection() and phase.drop_objection().

Practice challenge

Take the full code below and try this:

  1. Make the pipeline 6 stages deep instead of 3.
  2. Run +MODE=drain with the 50 ns drain time. How many items are never checked now?
  3. Find the smallest drain time that gets “never checked=0” again.

Then explain your number from the clock period and the pipeline depth. If you can, you’ll never guess a drain time again.

Frequently asked questions

How does a UVM test know when to end?

The run phase ends when no component holds an objection. The test raises one while it has work and drops it when it’s done. When the count reaches 0, UVM waits for the drain time, if one is set, and then ends the phase.

Why does my test finish at 0 ns with no activity?

No objection was raised, so nothing held the run phase open. Raise one in the test before starting your sequence.

Why does my test hang forever?

An objection was raised and never dropped, or the test is waiting for a condition that never comes true. Print who holds an objection, set a global timeout, and see the five real hangs in Why Does My UVM Test Never End.

What is drain time for?

It’s a short wait after the last objection drops, so items still inside the design reach the scoreboard. Without it, a design with latency loses its last few checks.

Should I use a #delay or objections to end a test?

Objections. A fixed delay breaks when timing changes. An objection ends the test when the work is really done.

Do drivers and monitors need objections?

Usually not. Raising and dropping around each transaction works, but it slows big regressions. A drain time or a scoreboard check usually does the job better. Every raise still needs a matching drop.

Full code

One file: the DUT, the bench and the test with five endings. On EDA Playground choose Synopsys VCS and UVM 1.2, set the top module to top, and run once per +MODE= option.

// objections_demo.sv : how a UVM test ends, five ways, one bench
// The Art of Verification | theartofverification.com
//
// Run options (one per run):
//   +MODE=no_raise    the test never raises an objection
//   +MODE=raise_drop  raise, run the sequence, drop (no drain time)
//   +MODE=drain       the same, plus a 50 ns drain time
//   +MODE=condition   endless traffic; the test ends when 20 items are checked
//   +MODE=no_drop     raise and never drop; a 2 us global timeout ends it
// Optional: add +UVM_OBJECTION_TRACE to see every raise and drop.
//
// Run on Synopsys VCS X-2025.06-SP1 with UVM 1.2 (EDA Playground), 23 Nov 2026.

`timescale 1ns/1ns
`include "uvm_macros.svh"
import uvm_pkg::*;

string MODE = "raise_drop";

// DUT: a 3-stage pipeline. Data comes out 3 clocks after it goes in.
interface pipe_if (input logic clk);
  logic       rst_n;
  logic       in_valid;
  logic [7:0] in_data;
  logic       out_valid;
  logic [7:0] out_data;
endinterface

module pipe_dut (pipe_if p);
  logic [2:0] v;
  logic [7:0] d0, d1, d2;
  always_ff @(posedge p.clk or negedge p.rst_n)
    if (!p.rst_n) v <= '0;
    else begin
      v  <= {v[1:0], p.in_valid};
      d0 <= p.in_data;
      d1 <= d0;
      d2 <= d1;
    end
  assign p.out_valid = v[2];
  assign p.out_data  = d2;
endmodule

class pipe_item extends uvm_sequence_item;
  rand bit [7:0] data;
  `uvm_object_utils(pipe_item)
  function new(string name = "pipe_item");
    super.new(name);
  endfunction
endclass

class burst_seq extends uvm_sequence #(pipe_item);
  `uvm_object_utils(burst_seq)
  int num_items = 10;
  function new(string name = "burst_seq");
    super.new(name);
  endfunction
  task body();
    repeat (num_items) `uvm_do(req)
  endtask
endclass

class pipe_driver extends uvm_driver #(pipe_item);
  `uvm_component_utils(pipe_driver)
  virtual pipe_if vif;
  int sent;
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction
  task run_phase(uvm_phase phase);
    vif.in_valid <= 1'b0;
    @(posedge vif.rst_n);
    forever begin
      seq_item_port.get_next_item(req);
      @(posedge vif.clk);
      vif.in_valid <= 1'b1;
      vif.in_data  <= req.data;
      @(posedge vif.clk);
      vif.in_valid <= 1'b0;
      sent++;
      seq_item_port.item_done();
    end
  endtask
endclass

class pipe_mon extends uvm_monitor;
  `uvm_component_utils(pipe_mon)
  virtual pipe_if vif;
  bit out_side;  // 0 = watch the input, 1 = watch the output
  uvm_analysis_port #(pipe_item) ap;
  function new(string name, uvm_component parent);
    super.new(name, parent);
    ap = new("ap", this);
  endfunction
  task run_phase(uvm_phase phase);
    forever begin
      @(posedge vif.clk);
      if (vif.rst_n && (out_side ? vif.out_valid : vif.in_valid)) begin
        pipe_item t = pipe_item::type_id::create("t");
        t.data = out_side ? vif.out_data : vif.in_data;
        ap.write(t);
      end
    end
  endtask
endclass

`uvm_analysis_imp_decl(_in)
`uvm_analysis_imp_decl(_out)

class pipe_sb extends uvm_scoreboard;
  `uvm_component_utils(pipe_sb)
  uvm_analysis_imp_in  #(pipe_item, pipe_sb) in_imp;
  uvm_analysis_imp_out #(pipe_item, pipe_sb) out_imp;
  bit [7:0] expected[$];
  int checked;
  function new(string name, uvm_component parent);
    super.new(name, parent);
    in_imp  = new("in_imp", this);
    out_imp = new("out_imp", this);
  endfunction
  function void write_in(pipe_item t);
    expected.push_back(t.data);
  endfunction
  function void write_out(pipe_item t);
    bit [7:0] exp;
    if (expected.size() == 0) begin
      `uvm_error("SB", $sformatf("got 'h%02h with nothing expected", t.data))
      return;
    end
    exp = expected.pop_front();
    if (t.data !== exp)
      `uvm_error("SB", $sformatf("got 'h%02h, expected 'h%02h", t.data, exp))
    checked++;
  endfunction
  function void check_phase(uvm_phase phase);
    if (expected.size() != 0)
      `uvm_error("SB", $sformatf("%0d item(s) went in but were never checked", expected.size()))
  endfunction
endclass

class pipe_env extends uvm_env;
  `uvm_component_utils(pipe_env)
  uvm_sequencer #(pipe_item) sqr;
  pipe_driver drv;
  pipe_mon    mon_in, mon_out;
  pipe_sb     sb;
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction
  function void build_phase(uvm_phase phase);
    virtual pipe_if vif;
    if (!uvm_config_db#(virtual pipe_if)::get(this, "", "vif", vif))
      `uvm_fatal("NOVIF", "pipe_if not set")
    sqr     = uvm_sequencer#(pipe_item)::type_id::create("sqr", this);
    drv     = pipe_driver::type_id::create("drv", this);
    mon_in  = pipe_mon::type_id::create("mon_in", this);
    mon_out = pipe_mon::type_id::create("mon_out", this);
    sb      = pipe_sb::type_id::create("sb", this);
    drv.vif = vif; mon_in.vif = vif; mon_out.vif = vif;
    mon_out.out_side = 1;
  endfunction
  function void connect_phase(uvm_phase phase);
    drv.seq_item_port.connect(sqr.seq_item_export);
    mon_in.ap.connect(sb.in_imp);
    mon_out.ap.connect(sb.out_imp);
  endfunction
endclass

// The test: one run_phase, five endings
class end_test extends uvm_test;
  `uvm_component_utils(end_test)
  pipe_env env;
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction
  function void build_phase(uvm_phase phase);
    env = pipe_env::type_id::create("env", this);
  endfunction

  task run_phase(uvm_phase phase);
    burst_seq seq = burst_seq::type_id::create("seq");
    case (MODE)
      "no_raise": begin
        seq.start(env.sqr);  // no objection: the phase does not wait for this
      end
      "raise_drop": begin
        phase.raise_objection(this, "burst");
        seq.start(env.sqr);
        phase.drop_objection(this, "burst sent");
      end
      "drain": begin
        phase.phase_done.set_drain_time(this, 50ns);
        phase.raise_objection(this, "burst");
        seq.start(env.sqr);
        phase.drop_objection(this, "burst sent");
      end
      "condition": begin
        phase.raise_objection(this, "until 20 checked");
        fork
          forever begin
            burst_seq s = burst_seq::type_id::create("s");
            s.start(env.sqr);
          end
        join_none
        wait (env.sb.checked >= 20);
        phase.drop_objection(this, "20 checked");
      end
      "no_drop": begin
        phase.raise_objection(this, "burst");
        seq.start(env.sqr);
        // the drop is missing
      end
      default: `uvm_fatal("MODE", {"unknown +MODE=", MODE})
    endcase
  endtask

  function void report_phase(uvm_phase phase);
    `uvm_info("END", $sformatf("MODE=%s run phase ended at %0t: sent=%0d checked=%0d never checked=%0d",
                               MODE, $time, env.drv.sent, env.sb.checked, env.sb.expected.size()), UVM_NONE)
  endfunction
endclass

module top;
  logic clk = 1'b0;
  pipe_if p (clk);
  pipe_dut u_dut (p);

  initial begin
    void'($value$plusargs("MODE=%s", MODE));
    `uvm_info("TOP", {"Running with MODE=", MODE}, UVM_NONE)
    p.rst_n = 1'b0;
    fork
      forever #5 clk = ~clk;
      #25 p.rst_n = 1'b1;
    join_none
    if (MODE == "no_drop") uvm_top.set_timeout(2us, 0);  // a global timeout for true hangs
    uvm_config_db#(virtual pipe_if)::set(null, "uvm_test_top.env", "vif", p);
    run_test("end_test");
  end
endmodule

References

Read next