How a UVM callback works, tested on VCS. The Art of Verification

How UVM Callbacks Work: Hooks, Order and exit_on (Tested)

In short: a UVM callback lets a test change what a component does at fixed points, without editing the component. The component declares an empty hook, registers it with `uvm_register_cb and calls it with `uvm_do_callbacks. A test then plugs in its own class with uvm_callbacks::add, per instance, in the order it chooses, and can switch it off mid-run.

Callbacks are the standard way to inject errors, add checks or collect coverage in a driver or monitor you cannot or should not edit, such as third-party VIP. If you are still deciding between a callback and a factory override, start with callbacks vs the factory.

This lesson opens up the mechanism. We build the four parts, then follow real data through four callbacks in a sequencer and driver loop, all on Synopsys VCS.

Start here: the simplest example

A driver sends three bytes. It offers one hook, pre_send(), and the test plugs in a callback that flips bit 0. The four parts are marked in the comments.

// tav_cbw_simple.sv : the smallest working UVM callback, all four parts (UVM 1.2)
// The Art of Verification | theartofverification.com
// Run on Synopsys VCS X-2025.06-SP1 with UVM 1.2 (EDA Playground), 2 Dec 2026.
// EDA Playground: Synopsys VCS, UVM 1.2, top module "tav_top".

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

typedef class tav_drv;

// Part 1: the callback class, with an empty hook
class tav_drv_cb extends uvm_callback;
  `uvm_object_utils(tav_drv_cb)
  function new(string name = "tav_drv_cb");
    super.new(name);
  endfunction
  virtual task pre_send(tav_drv drv, ref bit [7:0] data);   // does nothing by default
  endtask
endclass

class tav_drv extends uvm_component;
  `uvm_component_utils(tav_drv)
  `uvm_register_cb(tav_drv, tav_drv_cb)           // Part 2: allow this callback type here
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction

  task run_phase(uvm_phase phase);
    bit [7:0] list[3] = '{8'h3a, 8'h5c, 8'h70};
    foreach (list[i]) begin
      bit [7:0] data = list[i];
      #10;
      `uvm_do_callbacks(tav_drv, tav_drv_cb, pre_send(this, data))   // Part 3: the hook point
      `uvm_info("TAV_DRV", $sformatf("driving data=%h", data), UVM_LOW)
    end
  endtask
endclass

// Your callback: flips bit 0 on the way out
class tav_flip_cb extends tav_drv_cb;
  `uvm_object_utils(tav_flip_cb)
  function new(string name = "tav_flip_cb");
    super.new(name);
  endfunction
  virtual task pre_send(tav_drv drv, ref bit [7:0] data);
    data[0] = ~data[0];
    `uvm_info("TAV_FLIP", "flipped bit 0", UVM_LOW)
  endtask
endclass

class tav_cbw_test extends uvm_test;
  `uvm_component_utils(tav_cbw_test)
  tav_drv drv;
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction

  function void build_phase(uvm_phase phase);
    drv = tav_drv::type_id::create("drv", this);
  endfunction

  function void connect_phase(uvm_phase phase);
    tav_flip_cb flip = tav_flip_cb::type_id::create("flip");
    uvm_callbacks#(tav_drv, tav_drv_cb)::add(drv, flip);         // Part 4: attach it
  endfunction

  task run_phase(uvm_phase phase);
    phase.raise_objection(this);
    #40 phase.drop_objection(this);
  endtask
endclass

module tav_top;
  initial run_test("tav_cbw_test");
endmodule

Here is what VCS printed:

UVM_INFO @ 0: reporter [RNTST] Running test tav_cbw_test...
UVM_INFO testbench.sv(48) @ 10: reporter [TAV_FLIP] flipped bit 0
UVM_INFO testbench.sv(35) @ 10: uvm_test_top.drv [TAV_DRV] driving data=3b
UVM_INFO testbench.sv(48) @ 20: reporter [TAV_FLIP] flipped bit 0
UVM_INFO testbench.sv(35) @ 20: uvm_test_top.drv [TAV_DRV] driving data=5d
UVM_INFO testbench.sv(48) @ 30: reporter [TAV_FLIP] flipped bit 0
UVM_INFO testbench.sv(35) @ 30: uvm_test_top.drv [TAV_DRV] driving data=71
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_objection.svh(1276) @ 40: reporter [TEST_DONE] 'run' phase is ready to proceed to the 'extract' phase
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_report_server.svh(904) @ 40: reporter [UVM/REPORT/SERVER] 
--- UVM Report Summary ---

** Report counts by severity
UVM_INFO :    9
UVM_WARNING :    0
UVM_ERROR :    0
UVM_FATAL :    0
** Report counts by id
[RNTST]     1
[TAV_DRV]     3
[TAV_FLIP]     3
[TEST_DONE]     1
[UVM/RELNOTES]     1
  • Every byte changed: 3a 5c 70 went out as 3b 5d 71, and the driver code never mentions tav_flip_cb.
  • The callback ran first: each TAV_FLIP line comes just before its TAV_DRV line, because the hook sits before the print.
  • Look at the reporter: the TAV_FLIP lines say reporter, not a component path. A callback is a uvm_object, not a component, so its `uvm_info uses the global reporter.

What you will learn

  • The four parts of a callback, and which ones you write once and which ones every test writes.
  • What `uvm_do_callbacks does at the hook, step by step.
  • How order, UVM_PREPEND and callback_mode() change what reaches the bus.
  • How `uvm_do_callbacks_exit_on lets one callback make a decision for the whole chain.

Cheat sheet: the callback API

PieceWhere it goesWhat it does
class X_cb extends uvm_callbackNext to the componentDeclares the hooks as empty virtual methods
`uvm_register_cb(T, CB)Inside the component classAllows callbacks of type CB on T
`uvm_do_callbacks(T, CB, method(args))At the hook pointCalls method on every enabled callback, in order
`uvm_do_callbacks_exit_on(T, CB, method(args), val)In a function returning val‘s typeStops and returns val as soon as one callback returns it
uvm_callbacks#(T, CB)::add(obj, cb, ordering)In the testAttaches cb. null means every T; UVM_PREPEND puts it first.
uvm_callbacks#(T, CB)::delete(obj, cb)In the testRemoves it
cb.callback_mode(0 / 1)AnywhereSwitches it off or on, while it stays attached
uvm_callbacks#(T, CB)::display(obj)AnywherePrints the attached list with ON / OFF

Analogy: a delivery driver follows a fixed route, and the company will not rewrite it. Instead there is a note slot on the dashboard, checked before every stop. The slot is the hook, the notes are callbacks, and the dispatcher, your test, decides which notes go in and in what order.

The anatomy: three pieces of code, one list

Callbacks work because of virtual methods. The component calls pre_send() through a base-class handle, and each callback’s override runs instead of the empty default.

Diagram in three columns. Callback class: tav_drv_cb extends uvm_callback with virtual pre_send and do_drop, and four child callbacks tav_shift_cb, tav_flip_cb, tav_mark_cb and tav_drop_cb that override the hook. Component: tav_drv with uvm_register_cb, a uvm_do_callbacks_exit_on hook for do_drop and a uvm_do_callbacks hook for pre_send. Test: four add calls, two with UVM_PREPEND, and callback_mode(0) on flip at 25 ns. Below, the list UVM keeps for env.drv_a: drop, shift, flip OFF, mark
The component offers the hook, the test fills it, and UVM keeps the list.
  • Parts 1 to 3 are written once, by whoever writes the component. For VIP, the vendor has done this, and you look for the callback class in its documentation.
  • Part 4 is all a test does: write a child of the callback class and add it, usually in connect_phase or end_of_elaboration_phase, once the component exists (UVM phasing).

What happens at the hook, step by step

Here is the driver loop from the full bench, with the loop inside each callback macro opened up.

Flowchart. Left, the driver loop: get_next_item, then the decision tav_should_drop; if 1 the item is dropped, if 0 uvm_do_callbacks calls pre_send, the item is driven, then item_done and back to the next item. Right, inside uvm_do_callbacks: take the first enabled callback; if it is null, done; otherwise call cb.pre_send and move to the next enabled callback. OFF callbacks are skipped. A red box shows uvm_do_callbacks_exit_on, which returns 1 as soon as a callback's do_drop returns 1
The driver loop, and the callback loop each macro runs.
  1. The driver gets an item from the sequencer (sequencer and driver communication).
  2. It asks the callbacks whether to drop the item. `uvm_do_callbacks_exit_on stops at the first callback that answers 1.
  3. If the item is kept, `uvm_do_callbacks calls pre_send() on every enabled callback, in list order.
  4. The driver drives whatever the callbacks left in the item, then calls item_done().

Going further: one bench, 7 checks

  • Two sequencer and driver pairs: drv_a gets four callbacks, and drv_b gets none. Both receive 10 20 30 aa.
  • Two hooks: pre_send() changes the item, and do_drop() returns 1 to drop it.
  • Four callbacks: shift left, flip bit 0, set bit 7, and drop item aa.
  • Order: drop and shift are added with UVM_PREPEND, so the list is drop, shift, flip, mark. At 25 ns the test switches flip off.
  • Planted bug: +BUG=1 adds shift without UVM_PREPEND.

Run it yourself: both files are on GitHub, with the expected output.

// tav_cbw_uvm.sv : how a UVM callback works inside a real driver loop, 7 self-checks (UVM 1.2)
// The Art of Verification | theartofverification.com
// Run on Synopsys VCS X-2025.06-SP1 with UVM 1.2 (EDA Playground), 2 Dec 2026.
// EDA Playground: Synopsys VCS, UVM 1.2, top module "tav_top".
// Paste this whole file into testbench.sv and leave design.sv empty.
//
// What is in here:
//   tav_item, tav_seq            a byte of data, and a sequence that sends 10 20 30 aa
//   tav_drv_cb                   the callback class with two hooks: pre_send() and do_drop()
//   tav_shift_cb, tav_flip_cb,   three callbacks that change data (shift left, flip bit 0, set bit 7)
//   tav_mark_cb, tav_drop_cb     and one that asks the driver to drop item aa
//   tav_drv, tav_env, test       two sequencer/driver pairs (drv_a gets callbacks, drv_b none): 7 self-checks
//
// Callback order on drv_a: drop (prepend), shift (prepend), flip, mark.
// At 25 ns the test turns tav_flip_cb off with callback_mode(0).
//
// Run options:
//   (none)   all 7 checks pass, 0 errors
//   +BUG=1   tav_shift_cb is added without UVM_PREPEND, so it runs last (checks 2 and 3 fail)

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

typedef class tav_drv;

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

class tav_seq extends uvm_sequence #(tav_item);
  `uvm_object_utils(tav_seq)
  function new(string name = "tav_seq");
    super.new(name);
  endfunction
  task body();
    bit [7:0] list[4] = '{8'h10, 8'h20, 8'h30, 8'haa};
    foreach (list[i]) begin
      tav_item it = tav_item::type_id::create("it");
      start_item(it);
      it.data = list[i];
      finish_item(it);
    end
  endtask
endclass

// 1. The callback class: two empty hooks
class tav_drv_cb extends uvm_callback;
  `uvm_object_utils(tav_drv_cb)
  function new(string name = "tav_drv_cb");
    super.new(name);
  endfunction
  virtual task pre_send(tav_drv drv, tav_item it);        // change the item before it is driven
  endtask
  virtual function bit do_drop(tav_drv drv, tav_item it); // return 1 to drop the item
    return 0;
  endfunction
endclass

// 2. The driver: registers the callback type and calls both hooks
class tav_drv extends uvm_driver #(tav_item);
  `uvm_component_utils(tav_drv)
  `uvm_register_cb(tav_drv, tav_drv_cb)
  bit [7:0] tav_sent[$];
  string    tav_trace;      // which pre_send() ran, in order, for the first item
  int       tav_dropped;
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction

  // records the order the pre_send() hooks ran in, for the first item only
  function void tav_note(string n);
    if (tav_sent.size() != 0) return;
    if (tav_trace != "") tav_trace = {tav_trace, " "};
    tav_trace = {tav_trace, n};
  endfunction

  // `uvm_do_callbacks_exit_on returns from this function as soon as one callback returns 1
  function bit tav_should_drop(tav_item it);
    `uvm_do_callbacks_exit_on(tav_drv, tav_drv_cb, do_drop(this, it), 1)
  endfunction

  task run_phase(uvm_phase phase);
    forever begin
      seq_item_port.get_next_item(req);
      #10;
      if (tav_should_drop(req)) begin
        tav_dropped++;
        `uvm_info("TAV_DRV", $sformatf("dropped data=%h", req.data), UVM_LOW)
      end
      else begin
        `uvm_do_callbacks(tav_drv, tav_drv_cb, pre_send(this, req))
        tav_sent.push_back(req.data);
        `uvm_info("TAV_DRV", $sformatf("driving data=%h", req.data), UVM_LOW)
      end
      seq_item_port.item_done();
    end
  endtask
endclass

// 3. Four callbacks
class tav_shift_cb extends tav_drv_cb;
  `uvm_object_utils(tav_shift_cb)
  function new(string name = "tav_shift_cb");
    super.new(name);
  endfunction
  virtual task pre_send(tav_drv drv, tav_item it);
    it.data = it.data << 1;
    drv.tav_note("shift");
  endtask
endclass

class tav_flip_cb extends tav_drv_cb;
  `uvm_object_utils(tav_flip_cb)
  function new(string name = "tav_flip_cb");
    super.new(name);
  endfunction
  virtual task pre_send(tav_drv drv, tav_item it);
    it.data[0] = ~it.data[0];
    drv.tav_note("flip");
  endtask
endclass

class tav_mark_cb extends tav_drv_cb;
  `uvm_object_utils(tav_mark_cb)
  int tav_drop_calls;       // how many times do_drop() reached this callback
  function new(string name = "tav_mark_cb");
    super.new(name);
  endfunction
  virtual task pre_send(tav_drv drv, tav_item it);
    it.data[7] = 1'b1;
    drv.tav_note("mark");
  endtask
  virtual function bit do_drop(tav_drv drv, tav_item it);
    tav_drop_calls++;
    return 0;
  endfunction
endclass

class tav_drop_cb extends tav_drv_cb;
  `uvm_object_utils(tav_drop_cb)
  function new(string name = "tav_drop_cb");
    super.new(name);
  endfunction
  virtual function bit do_drop(tav_drv drv, tav_item it);
    return (it.data == 8'haa);
  endfunction
endclass

class tav_env extends uvm_env;
  `uvm_component_utils(tav_env)
  uvm_sequencer #(tav_item) sqr_a, sqr_b;
  tav_drv drv_a, drv_b;
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction
  function void build_phase(uvm_phase phase);
    sqr_a = uvm_sequencer#(tav_item)::type_id::create("sqr_a", this);
    sqr_b = uvm_sequencer#(tav_item)::type_id::create("sqr_b", this);
    drv_a = tav_drv::type_id::create("drv_a", this);
    drv_b = tav_drv::type_id::create("drv_b", this);
  endfunction
  function void connect_phase(uvm_phase phase);
    drv_a.seq_item_port.connect(sqr_a.seq_item_export);
    drv_b.seq_item_port.connect(sqr_b.seq_item_export);
  endfunction
endclass

// 4. The test: attaches the callbacks to drv_a only
class tav_cbw_test extends uvm_test;
  `uvm_component_utils(tav_cbw_test)
  tav_env      env;
  tav_shift_cb shift;
  tav_flip_cb  flip;
  tav_mark_cb  mark;
  tav_drop_cb  drop;
  int tav_bug;
  int tav_pass, tav_fail;
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction

  function void build_phase(uvm_phase phase);
    env = tav_env::type_id::create("env", this);
    void'($value$plusargs("BUG=%d", tav_bug));
  endfunction

  function void connect_phase(uvm_phase phase);
    shift = tav_shift_cb::type_id::create("shift");
    flip  = tav_flip_cb::type_id::create("flip");
    mark  = tav_mark_cb::type_id::create("mark");
    drop  = tav_drop_cb::type_id::create("drop");
    uvm_callbacks#(tav_drv, tav_drv_cb)::add(env.drv_a, flip);                 // appended
    uvm_callbacks#(tav_drv, tav_drv_cb)::add(env.drv_a, mark);                 // appended
    if (tav_bug == 1)
      uvm_callbacks#(tav_drv, tav_drv_cb)::add(env.drv_a, shift);              // BUG=1: appended, runs last
    else
      uvm_callbacks#(tav_drv, tav_drv_cb)::add(env.drv_a, shift, UVM_PREPEND); // runs first
    uvm_callbacks#(tav_drv, tav_drv_cb)::add(env.drv_a, drop, UVM_PREPEND);    // ahead of all of them
  endfunction

  task run_phase(uvm_phase phase);
    tav_seq seq_a = tav_seq::type_id::create("seq_a");
    tav_seq seq_b = tav_seq::type_id::create("seq_b");
    phase.raise_objection(this);
    fork
      seq_a.start(env.sqr_a);
      seq_b.start(env.sqr_b);
      #25 void'(flip.callback_mode(0));   // off, but still attached
    join
    phase.drop_objection(this);
  endtask

  function string tav_q2s(bit [7:0] q[$]);
    string s = "";
    foreach (q[i]) begin
      if (i > 0) s = {s, " "};
      s = {s, $sformatf("%h", q[i])};
    end
    return s;
  endfunction

  function void tav_check(string what, string got, string exp);
    if (got == exp) begin
      tav_pass++;
      `uvm_info("TAV_CBW", $sformatf("PASS %s: %s", what, got), UVM_LOW)
    end
    else begin
      tav_fail++;
      `uvm_error("TAV_CBW", $sformatf("FAIL %s: got %s, expected %s", what, got, exp))
    end
  endfunction

  function void report_phase(uvm_phase phase);
    uvm_callback_iter #(tav_drv, tav_drv_cb) iter = new(env.drv_a);
    tav_drv_cb cb;
    int n_on;
    cb = iter.first();
    while (cb != null) begin
      n_on++;
      cb = iter.next();
    end
    uvm_callbacks#(tav_drv, tav_drv_cb)::display(env.drv_a);

    tav_check("1 drv_b, no callbacks: sent", tav_q2s(env.drv_b.tav_sent), "10 20 30 aa");
    tav_check("2 pre_send order on drv_a, item 1", env.drv_a.tav_trace, "shift flip mark");
    tav_check("3 drv_a sent (flip off from 25 ns, aa dropped)", tav_q2s(env.drv_a.tav_sent), "a1 c1 e0");
    tav_check("4 flip after callback_mode(0)", $sformatf("%0d", flip.callback_mode()), "0");
    tav_check("5 drv_a / drv_b items dropped", $sformatf("%0d / %0d", env.drv_a.tav_dropped, env.drv_b.tav_dropped), "1 / 0");
    tav_check("6 exit_on: do_drop calls that reached tav_mark_cb", $sformatf("%0d", mark.tav_drop_calls), "3");
    tav_check("7 enabled callbacks on drv_a (4 attached)", $sformatf("%0d", n_on), "3");
    `uvm_info("TAV_CBW", $sformatf("Checks: %0d pass, %0d fail", tav_pass, tav_fail), UVM_LOW)
  endfunction
endclass

module tav_top;
  initial run_test("tav_cbw_test");
endmodule

How to run it

  1. Open EDA Playground and pick Synopsys VCS with UVM 1.2.
  2. Paste the file into testbench.sv, leave design.sv empty, and set the top module to tav_top.
  3. Run it once as is, then add +BUG=1 to the run options and run again.

What VCS returned

#CheckResult
1drv_b, no callbacks: sent10 20 30 aa
2pre_send() order on drv_a, item 1shift flip mark
3drv_a sent (flip off from 25 ns, aa dropped)a1 c1 e0
4flip.callback_mode() after switching it off0
5Items dropped: drv_a / drv_b1 / 0
6do_drop() calls that reached tav_mark_cb3
7Enabled callbacks on drv_a (4 attached)3

Result: 7 pass, 0 fail. Here is the log.

UVM_INFO @ 0: reporter [RNTST] Running test tav_cbw_test...
UVM_INFO testbench.sv(98) @ 10: uvm_test_top.env.drv_b [TAV_DRV] driving data=10
UVM_INFO testbench.sv(98) @ 10: uvm_test_top.env.drv_a [TAV_DRV] driving data=a1
UVM_INFO testbench.sv(98) @ 20: uvm_test_top.env.drv_a [TAV_DRV] driving data=c1
UVM_INFO testbench.sv(98) @ 20: uvm_test_top.env.drv_b [TAV_DRV] driving data=20
UVM_INFO testbench.sv(98) @ 30: uvm_test_top.env.drv_b [TAV_DRV] driving data=30
UVM_INFO testbench.sv(98) @ 30: uvm_test_top.env.drv_a [TAV_DRV] driving data=e0
UVM_INFO testbench.sv(93) @ 40: uvm_test_top.env.drv_a [TAV_DRV] dropped data=aa
UVM_INFO testbench.sv(98) @ 40: uvm_test_top.env.drv_b [TAV_DRV] driving data=aa
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_objection.svh(1276) @ 40: reporter [TEST_DONE] 'run' phase is ready to proceed to the 'extract' phase
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_callback.svh(428) @ 40: reporter [UVM/CB/DISPLAY] Registered callbacks for instance uvm_test_top.env.drv_a of tav_drv
---------------------------------------------------------------
drop    uvm_test_top.env.drv_a on   ON
shift   uvm_test_top.env.drv_a on   ON
flip    uvm_test_top.env.drv_a on   OFF
mark    uvm_test_top.env.drv_a on   ON

UVM_INFO testbench.sv(230) @ 40: uvm_test_top [TAV_CBW] PASS 1 drv_b, no callbacks: sent: 10 20 30 aa
UVM_INFO testbench.sv(230) @ 40: uvm_test_top [TAV_CBW] PASS 2 pre_send order on drv_a, item 1: shift flip mark
UVM_INFO testbench.sv(230) @ 40: uvm_test_top [TAV_CBW] PASS 3 drv_a sent (flip off from 25 ns, aa dropped): a1 c1 e0
UVM_INFO testbench.sv(230) @ 40: uvm_test_top [TAV_CBW] PASS 4 flip after callback_mode(0): 0
UVM_INFO testbench.sv(230) @ 40: uvm_test_top [TAV_CBW] PASS 5 drv_a / drv_b items dropped: 1 / 0
UVM_INFO testbench.sv(230) @ 40: uvm_test_top [TAV_CBW] PASS 6 exit_on: do_drop calls that reached tav_mark_cb: 3
UVM_INFO testbench.sv(230) @ 40: uvm_test_top [TAV_CBW] PASS 7 enabled callbacks on drv_a (4 attached): 3
UVM_INFO testbench.sv(256) @ 40: uvm_test_top [TAV_CBW] Checks: 7 pass, 0 fail
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_report_server.svh(904) @ 40: reporter [UVM/REPORT/SERVER] 
--- UVM Report Summary ---

** Report counts by severity
UVM_INFO :   20
UVM_WARNING :    0
UVM_ERROR :    0
UVM_FATAL :    0
** Report counts by id
[RNTST]     1
[TAV_CBW]     8
[TAV_DRV]     8
[TEST_DONE]     1
[UVM/CB/DISPLAY]     1
[UVM/RELNOTES]     1

Before the checks, UVM printed its own table for drv_a: the list in order, with flip marked OFF. That one call, uvm_callbacks#(T, CB)::display(), is the quickest way to see what a test really attached.

Following the data through the callbacks

Each item on drv_a, hook by hook. Every value here comes from the two VCS runs.

Data trace. Clean run, order drop, shift, flip, mark: item 10 becomes 20, 21, a1 and is driven as a1; item 20 becomes 40, 41, c1; item 30 becomes 60, flip is OFF, then e0; item aa gets 1 from do_drop and is dropped, the other callbacks are not called. Bug run, order drop, flip, mark, shift: item 10 becomes 11, 91, then 22 because bit 7 is shifted out, so drv_a drives 22 42 60
Same four callbacks; the order decides what reaches the bus.
  • Check 3: flip was off from 25 ns, so item 30 went from 60 straight to e0.
  • Check 6: for item aa, tav_drop_cb answered 1 first and the loop stopped, so tav_mark_cb saw do_drop() 3 times, not 4.
  • Check 7: the iterator skips OFF callbacks, so it counted 3 of the 4 attached.

The planted bug: the right callbacks in the wrong order

With +BUG=1, shift is added without UVM_PREPEND, so it lands at the end of the list instead of the front.

UVM_INFO @ 0: reporter [RNTST] Running test tav_cbw_test...
UVM_INFO testbench.sv(98) @ 10: uvm_test_top.env.drv_b [TAV_DRV] driving data=10
UVM_INFO testbench.sv(98) @ 10: uvm_test_top.env.drv_a [TAV_DRV] driving data=22
UVM_INFO testbench.sv(98) @ 20: uvm_test_top.env.drv_a [TAV_DRV] driving data=42
UVM_INFO testbench.sv(98) @ 20: uvm_test_top.env.drv_b [TAV_DRV] driving data=20
UVM_INFO testbench.sv(98) @ 30: uvm_test_top.env.drv_b [TAV_DRV] driving data=30
UVM_INFO testbench.sv(98) @ 30: uvm_test_top.env.drv_a [TAV_DRV] driving data=60
UVM_INFO testbench.sv(93) @ 40: uvm_test_top.env.drv_a [TAV_DRV] dropped data=aa
UVM_INFO testbench.sv(98) @ 40: uvm_test_top.env.drv_b [TAV_DRV] driving data=aa
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_objection.svh(1276) @ 40: reporter [TEST_DONE] 'run' phase is ready to proceed to the 'extract' phase
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_callback.svh(428) @ 40: reporter [UVM/CB/DISPLAY] Registered callbacks for instance uvm_test_top.env.drv_a of tav_drv
---------------------------------------------------------------
drop    uvm_test_top.env.drv_a on   ON
flip    uvm_test_top.env.drv_a on   OFF
mark    uvm_test_top.env.drv_a on   ON
shift   uvm_test_top.env.drv_a on   ON

UVM_INFO testbench.sv(230) @ 40: uvm_test_top [TAV_CBW] PASS 1 drv_b, no callbacks: sent: 10 20 30 aa
UVM_ERROR testbench.sv(234) @ 40: uvm_test_top [TAV_CBW] FAIL 2 pre_send order on drv_a, item 1: got flip mark shift, expected shift flip mark
UVM_ERROR testbench.sv(234) @ 40: uvm_test_top [TAV_CBW] FAIL 3 drv_a sent (flip off from 25 ns, aa dropped): got 22 42 60, expected a1 c1 e0
UVM_INFO testbench.sv(230) @ 40: uvm_test_top [TAV_CBW] PASS 4 flip after callback_mode(0): 0
UVM_INFO testbench.sv(230) @ 40: uvm_test_top [TAV_CBW] PASS 5 drv_a / drv_b items dropped: 1 / 0
UVM_INFO testbench.sv(230) @ 40: uvm_test_top [TAV_CBW] PASS 6 exit_on: do_drop calls that reached tav_mark_cb: 3
UVM_INFO testbench.sv(230) @ 40: uvm_test_top [TAV_CBW] PASS 7 enabled callbacks on drv_a (4 attached): 3
UVM_INFO testbench.sv(256) @ 40: uvm_test_top [TAV_CBW] Checks: 5 pass, 2 fail
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_report_server.svh(904) @ 40: reporter [UVM/REPORT/SERVER] 
--- UVM Report Summary ---

** Report counts by severity
UVM_INFO :   18
UVM_WARNING :    0
UVM_ERROR :    2
UVM_FATAL :    0
** Report counts by id
[RNTST]     1
[TAV_CBW]     8
[TAV_DRV]     8
[TEST_DONE]     1
[UVM/CB/DISPLAY]     1
[UVM/RELNOTES]     1

UVM’s table shows the new order: drop, flip, mark, shift. Checks 2 and 3 failed, and drv_a drove 22 42 60, because the shift now runs after bit 7 is set and pushes it out.

Nothing warned about it. Every callback ran and every line looked normal, only the bytes on the bus were different.

The lesson: when two callbacks touch the same field, their order is part of the test. Set it on purpose with UVM_APPEND or UVM_PREPEND, and check it with display().

Common mistakes to avoid

MistakeWhat you seeFix
Callbacks that change the same field in an unplanned orderWrong data, no warning (+BUG=1)Choose UVM_APPEND / UVM_PREPEND; check with display()
Calling add before the component existsThe handle is still null, which add reads as “every instance”Add in connect_phase or later
Passing null when you meant one instanceEvery driver of that type changesPass the instance handle (env.drv_a)
Using delete to pause a callbackIt has to be created and added again laterUse callback_mode(0) and callback_mode(1)
Using `uvm_do_callbacks_exit_on inside a taskIt does not fit: the macro returns a valueWrap it in a function, like tav_should_drop()
Expecting a component path in a callback’s messagesLines say reporterInclude drv.get_full_name() in the text

How AI helps you master this

  • Find the hooks: paste a VIP driver and ask where it calls `uvm_do_callbacks and with which methods.
  • Check order: paste your add calls and ask for the final list order, then compare it with display().
  • Trace data: describe your callbacks and an input value, and ask for the value after each one, as in the data-trace diagram.

Warning: a convincing AI answer is not the same as a correct engineering result. The order bug above produces a clean-looking log, so check the bytes.

Interview questions on UVM callbacks

  • What are the steps to add a callback? Define a callback class with virtual hooks, register it with `uvm_register_cb, call it with `uvm_do_callbacks, then extend it and add it from the test.
  • Why do callbacks need virtual methods? The component calls the hook through the base class, so only a virtual method runs the child’s override.
  • In what order do callbacks run? In list order: add appends by default, and UVM_PREPEND puts a callback first.
  • How do you turn a callback off without removing it? callback_mode(0); the iterator then skips it.
  • What does `uvm_do_callbacks_exit_on do? It stops at the first callback that returns the given value, and returns that value from the enclosing function.

More practice: UVM interview questions.

Practice challenge

  1. Run the simple example and confirm the three bytes that went out.
  2. Run the full bench with +BUG=1 and compare UVM’s callback table with the clean run.
  3. Switch flip back on at 35 ns with callback_mode(1). Which check changes?
  4. Bonus: in tav_flip_cb, try `uvm_info_context("TAV_FLIP", "flipped bit 0", UVM_LOW, drv). Whose name appears in the log now?

FAQ

How does a UVM callback work? The component calls an empty virtual hook through `uvm_do_callbacks. UVM loops over the callbacks attached to that instance and calls each one’s override, in order.

Where should I call uvm_callbacks::add? After the component is built, usually in the test’s connect_phase or end_of_elaboration_phase.

Can a callback be a task? Yes: pre_send() in this bench is a task, called with `uvm_do_callbacks. A hook used with `uvm_do_callbacks_exit_on must return a value, so it is a function.

How do I see which callbacks are attached? Call uvm_callbacks#(T, CB)::display(obj). It prints each callback with ON or OFF, in order.

Does a hook change anything when no callback is attached? No. In this bench drv_b ran the same driver code, hooks included, and drove 10 20 30 aa unchanged.

References

  • IEEE 1800.2-2020, Universal Verification Methodology (UVM) standard: callbacks.
  • Accellera UVM 1.2 Class Reference: uvm_callback, uvm_callbacks, uvm_callback_iter, and the `uvm_register_cb, `uvm_do_callbacks and `uvm_do_callbacks_exit_on macros.

Keep learning