UVM callbacks vs factory, tested on VCS. The Art of Verification

UVM Callbacks vs Factory: When to Use Each (Tested)

In short: callbacks and the factory both change what a testbench does without editing the original code, but in different ways. A callback plugs a small piece of code into a fixed hook inside a component that stays as it is, and you can add or remove it during the run. A factory override swaps the whole class for a child class, and it must be set before the component is created.

Both answer the same question: how do I change one test without breaking every other test? They take different routes, and picking the wrong one usually means rework.

In this lesson we make the same change both ways, flipping bit 0 of an address, and then test seven differences between them on Synopsys VCS.

Start here: the simplest example

Three drivers each drive address 10. One is left alone, one gets a callback that flips bit 0, and one is swapped by the factory for a child driver that flips bit 0.

// tav_cbf_simple.sv : the same change done twice, once with a callback and once with the factory (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;

// The callback base class: the hook the driver offers
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 function void pre_drive(tav_drv drv, ref bit [7:0] addr);
  endfunction
endclass

// The driver: calls every registered callback, then "drives" the address
class tav_drv extends uvm_component;
  `uvm_component_utils(tav_drv)
  `uvm_register_cb(tav_drv, tav_drv_cb)
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction
  virtual function void drive(bit [7:0] addr);
    `uvm_do_callbacks(tav_drv, tav_drv_cb, pre_drive(this, addr))
    `uvm_info("TAV_DRV", $sformatf("drove addr=%h", addr), UVM_LOW)
  endfunction
  task run_phase(uvm_phase phase);
    #10 drive(8'h10);
  endtask
endclass

// Way 1: a callback that flips bit 0 (the driver class stays the same)
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 function void pre_drive(tav_drv drv, ref bit [7:0] addr);
    addr[0] = ~addr[0];
  endfunction
endclass

// Way 2: a child driver that flips bit 0 (swapped in by the factory)
class tav_err_drv extends tav_drv;
  `uvm_component_utils(tav_err_drv)
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction
  virtual function void drive(bit [7:0] addr);
    addr[0] = ~addr[0];
    super.drive(addr);
  endfunction
endclass

class tav_cbf_test extends uvm_test;
  `uvm_component_utils(tav_cbf_test)
  tav_drv drv_plain, drv_cb, drv_fac;
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction

  function void build_phase(uvm_phase phase);
    tav_flip_cb flip = tav_flip_cb::type_id::create("flip");
    tav_drv::type_id::set_inst_override(tav_err_drv::get_type(), "drv_fac", this); // before create
    drv_plain = tav_drv::type_id::create("drv_plain", this);
    drv_cb    = tav_drv::type_id::create("drv_cb", this);
    drv_fac   = tav_drv::type_id::create("drv_fac", this);
    uvm_callbacks#(tav_drv, tav_drv_cb)::add(drv_cb, flip);                  // only drv_cb
  endfunction

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

  function void report_phase(uvm_phase phase);
    `uvm_info("TAV_CBF", $sformatf("classes: drv_plain=%s drv_cb=%s drv_fac=%s",
              drv_plain.get_type_name(), drv_cb.get_type_name(), drv_fac.get_type_name()), UVM_LOW)
  endfunction
endclass

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

Here is what VCS printed:

UVM_INFO @ 0: reporter [RNTST] Running test tav_cbf_test...
UVM_INFO testbench.sv(31) @ 10: uvm_test_top.drv_cb [TAV_DRV] drove addr=11
UVM_INFO testbench.sv(31) @ 10: uvm_test_top.drv_fac [TAV_DRV] drove addr=11
UVM_INFO testbench.sv(31) @ 10: uvm_test_top.drv_plain [TAV_DRV] drove addr=10
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_objection.svh(1276) @ 20: reporter [TEST_DONE] 'run' phase is ready to proceed to the 'extract' phase
UVM_INFO testbench.sv(83) @ 20: uvm_test_top [TAV_CBF] classes: drv_plain=tav_drv drv_cb=tav_drv drv_fac=tav_err_drv
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_report_server.svh(904) @ 20: reporter [UVM/REPORT/SERVER] 
--- UVM Report Summary ---

** Report counts by severity
UVM_INFO :    7
UVM_WARNING :    0
UVM_ERROR :    0
UVM_FATAL :    0
** Report counts by id
[RNTST]     1
[TAV_CBF]     1
[TAV_DRV]     3
[TEST_DONE]     1
[UVM/RELNOTES]     1
  • Same result: drv_cb and drv_fac both drove 11, while drv_plain drove 10.
  • Different method: the last line shows drv_cb is still a tav_drv, while drv_fac became a tav_err_drv.

That one line is the whole difference. A callback adds code to an object that keeps its class, and the factory changes which class gets built.

What you will learn

  • How a callback hook and a factory override each make the same change.
  • The seven steps of a callback, from hook to end, and a quick guide to choosing.
  • Why a callback can be switched on and off during the run, and a factory override cannot.
  • How to limit each one to a single instance.
  • The timing mistake that makes a factory override do nothing, with no warning.

Cheat sheet: callback vs factory

AspectCallbackFactory override
What it changesAdds code at a hook inside a componentReplaces the whole class with a child class
Original classStays as writtenSwapped before the component is created
When it takes effectAt the hook, any time during the runOnly when create() runs
On / offuvm_callbacks::add / delete, even mid-runset_type_override / set_inst_override, before build
NeedsThe component to offer a hook (`uvm_register_cb, `uvm_do_callbacks)The component to be built with type_id::create()
Best forSmall changes: error injection, an extra check, coverageLarge changes: a different driver, an extended transaction

Analogy: picture an office coffee machine. A callback is a sticky note on the machine saying “add one extra shot”, which you can put on or peel off any time. A factory override is ordering a different machine before the office opens.

When to use a callback, and when the factory

Use a callback when

  • The change is small: corrupt one field, add a check, sample coverage.
  • The component is locked (encrypted or third-party VIP) but offers hooks.
  • The change must switch on and off during the test (check 5).
  • Several small changes must stack on the same component.

Use the factory when

  • The change replaces most of a component or many of its methods.
  • Each test needs its own version of a class, such as a special driver or an extended transaction.
  • The component offers no hook where you need the change.
  • The change can be decided once, before build, and holds for the whole run.

Rule of thumb: a small change at a known point is a callback, and a different class is the factory.

Callbacks from hook to end, step by step

A callback needs three things in the component and four things in the test. The diagram walks through all seven, using the code from this post’s bench.

Seven numbered steps. Component author, once: 1 define the hook class tav_drv_cb extends uvm_callback with a virtual pre_drive; 2 register it with uvm_register_cb in tav_drv; 3 call the hook with uvm_do_callbacks in drive_item. Each test: 4 write tav_flip_cb extending tav_drv_cb and override pre_drive to flip address bit 0; 5 create it and add it with uvm_callbacks add, an instance handle for one driver or null for all. UVM at run time: 6 the hook calls every added callback, drv_a drove 11 13 15 and stays tav_drv. Each test: 7 delete it when done, drv_b drove 20 23 24
Steps 1 to 3 build the hook once; steps 4 to 7 are what each test does.
  • Steps 1 to 3 are done once, by whoever writes the component. For VIP, the vendor has already done them.
  • Steps 4 and 5 are all a test needs to change behaviour.
  • Step 7 is optional, and can happen at any time during the run.
Timeline diagram with build, connect and run phases. Factory row: set_inst_override and create in build_phase make drv_c a tav_err_drv, which drives 31, 33 and 35; a red dashed box in connect_phase shows the planted bug where the override is set too late and drv_c stays tav_drv. Callback row: drv_b stays tav_drv; a callback added at 15 ns and deleted at 25 ns changes only the middle item, so drv_b drives 20, 23 and 24
When each one takes effect, from this post’s VCS runs.

Going further: one bench, 7 checks

  • tav_drv drives three items at 10, 20 and 30 ns and offers a pre_drive() hook.
  • tav_flip_cb flips address bit 0, and tav_count_cb counts items.
  • tav_err_drv is a child driver that flips bit 0, swapped in for env.drv_c by the factory.
  • Planted bug: +BUG=1 sets the factory override in connect_phase instead of build_phase.

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

// tav_cbf_uvm.sv : callbacks vs the factory, 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_item_err        a transaction and a child of it (for the run-time override check)
//   tav_drv_cb                    the callback hook the driver offers
//   tav_flip_cb, tav_count_cb     a callback that flips address bit 0, and one that counts items
//   tav_drv, tav_err_drv          the driver, and a child that flips bit 0 (swapped in by the factory)
//   tav_env, tav_cbf_test         three drivers and the test: 7 self-checks
//
// Run options:
//   (none)   all 7 checks pass, 0 errors
//   +BUG=1   the factory override is set in connect_phase, after drv_c was built (checks 3 and 4 fail)

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

typedef class tav_drv;

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

class tav_item_err extends tav_item;
  `uvm_object_utils(tav_item_err)
  function new(string name = "tav_item_err");
    super.new(name);
  endfunction
endclass

// 1. The 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 function void pre_drive(tav_drv drv, tav_item it);
  endfunction
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 function void pre_drive(tav_drv drv, tav_item it);
    it.addr[0] = ~it.addr[0];
  endfunction
endclass

class tav_count_cb extends tav_drv_cb;
  `uvm_object_utils(tav_count_cb)
  int tav_count;
  function new(string name = "tav_count_cb");
    super.new(name);
  endfunction
  virtual function void pre_drive(tav_drv drv, tav_item it);
    tav_count++;
  endfunction
endclass

// 2. The driver: 3 items, at 10, 20 and 30 ns
class tav_drv extends uvm_component;
  `uvm_component_utils(tav_drv)
  `uvm_register_cb(tav_drv, tav_drv_cb)
  bit [7:0] tav_base;
  bit [7:0] tav_sent[$];
  string    tav_item_type;
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction

  task run_phase(uvm_phase phase);
    for (int i = 0; i < 3; i++) begin
      tav_item it = tav_item::type_id::create("it");
      tav_item_type = it.get_type_name();
      #10 it.addr = tav_base + 2*i;
      drive_item(it);
    end
  endtask

  virtual function void drive_item(tav_item it);
    `uvm_do_callbacks(tav_drv, tav_drv_cb, pre_drive(this, it))
    tav_sent.push_back(it.addr);
    `uvm_info("TAV_DRV", $sformatf("drove addr=%h", it.addr), UVM_LOW)
  endfunction
endclass

// 3. The factory way: a child driver that flips bit 0
class tav_err_drv extends tav_drv;
  `uvm_component_utils(tav_err_drv)
  `uvm_set_super_type(tav_err_drv, tav_drv)   // lets callbacks registered on tav_drv reach this child
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction
  virtual function void drive_item(tav_item it);
    it.addr[0] = ~it.addr[0];
    super.drive_item(it);
  endfunction
endclass

class tav_env extends uvm_env;
  `uvm_component_utils(tav_env)
  tav_drv drv_a, drv_b, drv_c;
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction
  function void build_phase(uvm_phase phase);
    drv_a = tav_drv::type_id::create("drv_a", this);  drv_a.tav_base = 8'h10;
    drv_b = tav_drv::type_id::create("drv_b", this);  drv_b.tav_base = 8'h20;
    drv_c = tav_drv::type_id::create("drv_c", this);  drv_c.tav_base = 8'h30;
  endfunction
endclass

// 4. The test
class tav_cbf_test extends uvm_test;
  `uvm_component_utils(tav_cbf_test)
  tav_env      env;
  tav_flip_cb  flip_a, flip_b;
  tav_count_cb cnt;
  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);
    void'($value$plusargs("BUG=%d", tav_bug));
    if (tav_bug != 1)
      tav_drv::type_id::set_inst_override(tav_err_drv::get_type(), "env.drv_c", this);
    env    = tav_env::type_id::create("env", this);
    flip_a = tav_flip_cb::type_id::create("flip_a");
    flip_b = tav_flip_cb::type_id::create("flip_b");
    cnt    = tav_count_cb::type_id::create("cnt");
    uvm_callbacks#(tav_drv, tav_drv_cb)::add(null, cnt);     // type-wide: every tav_drv
  endfunction

  function void connect_phase(uvm_phase phase);
    if (tav_bug == 1)   // BUG=1: too late, env.drv_c already exists
      tav_drv::type_id::set_inst_override(tav_err_drv::get_type(), "env.drv_c", this);
    uvm_callbacks#(tav_drv, tav_drv_cb)::add(env.drv_a, flip_a);  // one instance only
  endfunction

  task run_phase(uvm_phase phase);
    phase.raise_objection(this);
    #15 uvm_callbacks#(tav_drv, tav_drv_cb)::add(env.drv_b, flip_b);     // on at 15 ns
    #10 uvm_callbacks#(tav_drv, tav_drv_cb)::delete(env.drv_b, flip_b);  // off at 25 ns
    #10 tav_item::type_id::set_type_override(tav_item_err::get_type());  // run-time override at 35 ns
    #5  phase.drop_objection(this);
  endtask

  function string tav_q2s(bit [7:0] q[$]);
    string s = "";
    foreach (q[i]) begin
      if (i > 0) s = {s, " "};      // no ?: between literals of different length (it pads)
      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_CBF", $sformatf("PASS %s: %s", what, got), UVM_LOW)
    end
    else begin
      tav_fail++;
      `uvm_error("TAV_CBF", $sformatf("FAIL %s: got %s, expected %s", what, got, exp))
    end
  endfunction

  function void report_phase(uvm_phase phase);
    tav_item late = tav_item::type_id::create("late");
    tav_check("1 callback on drv_a only: drv_a sent", tav_q2s(env.drv_a.tav_sent), "11 13 15");
    tav_check("2 drv_a class after the callback", env.drv_a.get_type_name(), "tav_drv");
    tav_check("3 drv_c class after the factory override", env.drv_c.get_type_name(), "tav_err_drv");
    tav_check("4 factory override: drv_c sent", tav_q2s(env.drv_c.tav_sent), "31 33 35");
    tav_check("5 callback on at 15 ns, off at 25 ns: drv_b sent", tav_q2s(env.drv_b.tav_sent), "20 23 24");
    tav_check("6 type-wide counter (3 drivers, child included)", $sformatf("%0d", cnt.tav_count), "9");
    tav_check("7 run-time override: drv_a item / item created after",
              $sformatf("%s / %s", env.drv_a.tav_item_type, late.get_type_name()), "tav_item / tav_item_err");
    `uvm_info("TAV_CBF", $sformatf("Checks: %0d pass, %0d fail", tav_pass, tav_fail), UVM_LOW)
  endfunction
endclass

module tav_top;
  initial run_test("tav_cbf_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
1Callback on drv_a only: drv_a sent11 13 15
2drv_a class after the callbacktav_drv
3drv_c class after the factory overridetav_err_drv
4Factory override: drv_c sent31 33 35
5Callback on at 15 ns, off at 25 ns: drv_b sent20 23 24
6Type-wide counter (3 drivers, child included)9
7Override set at 35 ns: drv_a‘s item / an item created aftertav_item / tav_item_err

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

UVM_INFO @ 0: reporter [RNTST] Running test tav_cbf_test...
UVM_INFO testbench.sv(93) @ 10: uvm_test_top.env.drv_a [TAV_DRV] drove addr=11
UVM_INFO testbench.sv(93) @ 10: uvm_test_top.env.drv_b [TAV_DRV] drove addr=20
UVM_INFO testbench.sv(93) @ 10: uvm_test_top.env.drv_c [TAV_DRV] drove addr=31
UVM_INFO testbench.sv(93) @ 20: uvm_test_top.env.drv_a [TAV_DRV] drove addr=13
UVM_INFO testbench.sv(93) @ 20: uvm_test_top.env.drv_b [TAV_DRV] drove addr=23
UVM_INFO testbench.sv(93) @ 20: uvm_test_top.env.drv_c [TAV_DRV] drove addr=33
UVM_INFO testbench.sv(93) @ 30: uvm_test_top.env.drv_a [TAV_DRV] drove addr=15
UVM_INFO testbench.sv(93) @ 30: uvm_test_top.env.drv_b [TAV_DRV] drove addr=24
UVM_INFO testbench.sv(93) @ 30: uvm_test_top.env.drv_c [TAV_DRV] drove addr=35
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 testbench.sv(173) @ 40: uvm_test_top [TAV_CBF] PASS 1 callback on drv_a only: drv_a sent: 11 13 15
UVM_INFO testbench.sv(173) @ 40: uvm_test_top [TAV_CBF] PASS 2 drv_a class after the callback: tav_drv
UVM_INFO testbench.sv(173) @ 40: uvm_test_top [TAV_CBF] PASS 3 drv_c class after the factory override: tav_err_drv
UVM_INFO testbench.sv(173) @ 40: uvm_test_top [TAV_CBF] PASS 4 factory override: drv_c sent: 31 33 35
UVM_INFO testbench.sv(173) @ 40: uvm_test_top [TAV_CBF] PASS 5 callback on at 15 ns, off at 25 ns: drv_b sent: 20 23 24
UVM_INFO testbench.sv(173) @ 40: uvm_test_top [TAV_CBF] PASS 6 type-wide counter (3 drivers, child included): 9
UVM_INFO testbench.sv(173) @ 40: uvm_test_top [TAV_CBF] PASS 7 run-time override: drv_a item / item created after: tav_item / tav_item_err
UVM_INFO testbench.sv(191) @ 40: uvm_test_top [TAV_CBF] 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_CBF]     8
[TAV_DRV]     9
[TEST_DONE]     1
[UVM/RELNOTES]     1
  • Checks 1 and 5: callbacks can target one instance, and can come and go mid-run. Only drv_b‘s 20 ns item became 23.
  • Check 6: a callback added with null reached all three drivers, including drv_c, which the factory had replaced with a child class.
  • Check 7: a factory override set during the run changed only objects created after it. Everything already built kept its class.

For check 6, the child driver declares `uvm_set_super_type(tav_err_drv, tav_drv), so callbacks registered on tav_drv also apply to it. I kept it in and did not test the bench without it.

The planted bug: the override came too late

With +BUG=1, the test sets the same instance override in connect_phase. By then env.drv_c had already been built as a plain tav_drv.

UVM_INFO @ 0: reporter [RNTST] Running test tav_cbf_test...
UVM_INFO testbench.sv(93) @ 10: uvm_test_top.env.drv_a [TAV_DRV] drove addr=11
UVM_INFO testbench.sv(93) @ 10: uvm_test_top.env.drv_b [TAV_DRV] drove addr=20
UVM_INFO testbench.sv(93) @ 10: uvm_test_top.env.drv_c [TAV_DRV] drove addr=30
UVM_INFO testbench.sv(93) @ 20: uvm_test_top.env.drv_a [TAV_DRV] drove addr=13
UVM_INFO testbench.sv(93) @ 20: uvm_test_top.env.drv_b [TAV_DRV] drove addr=23
UVM_INFO testbench.sv(93) @ 20: uvm_test_top.env.drv_c [TAV_DRV] drove addr=32
UVM_INFO testbench.sv(93) @ 30: uvm_test_top.env.drv_a [TAV_DRV] drove addr=15
UVM_INFO testbench.sv(93) @ 30: uvm_test_top.env.drv_b [TAV_DRV] drove addr=24
UVM_INFO testbench.sv(93) @ 30: uvm_test_top.env.drv_c [TAV_DRV] drove addr=34
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 testbench.sv(173) @ 40: uvm_test_top [TAV_CBF] PASS 1 callback on drv_a only: drv_a sent: 11 13 15
UVM_INFO testbench.sv(173) @ 40: uvm_test_top [TAV_CBF] PASS 2 drv_a class after the callback: tav_drv
UVM_ERROR testbench.sv(177) @ 40: uvm_test_top [TAV_CBF] FAIL 3 drv_c class after the factory override: got tav_drv, expected tav_err_drv
UVM_ERROR testbench.sv(177) @ 40: uvm_test_top [TAV_CBF] FAIL 4 factory override: drv_c sent: got 30 32 34, expected 31 33 35
UVM_INFO testbench.sv(173) @ 40: uvm_test_top [TAV_CBF] PASS 5 callback on at 15 ns, off at 25 ns: drv_b sent: 20 23 24
UVM_INFO testbench.sv(173) @ 40: uvm_test_top [TAV_CBF] PASS 6 type-wide counter (3 drivers, child included): 9
UVM_INFO testbench.sv(173) @ 40: uvm_test_top [TAV_CBF] PASS 7 run-time override: drv_a item / item created after: tav_item / tav_item_err
UVM_INFO testbench.sv(191) @ 40: uvm_test_top [TAV_CBF] 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_CBF]     8
[TAV_DRV]     9
[TEST_DONE]     1
[UVM/RELNOTES]     1

drv_c drove 30 32 34, and checks 3 and 4 failed. There is no warning anywhere in the log: UVM accepted the override and had nothing left to apply it to.

The lesson: set factory overrides in the test’s build_phase, before the components they target are created. If a run-time change is what you need, that is a job for a callback.

Common mistakes to avoid

MistakeWhat you seeFix
Setting a factory override after buildNothing changes, no warning (+BUG=1)Set it in the test’s build_phase
Building a component with new()The factory override is ignoredUse type_id::create()
Forgetting `uvm_register_cb in the componentAdding the callback reports an errorRegister the callback type in the component
Adding a callback with null when you meant one instanceEvery driver changesPass the instance handle
Writing a full new driver for a one-line changeA large class to maintainUse a callback if a hook exists

How AI helps you master this

  • Pick the method: describe the change you need and ask whether a callback or an override fits, and why.
  • Check timing: paste your test’s phases and ask where each override is set relative to create().
  • Find hooks: paste a VIP driver and ask which callback hooks it offers.

Warning: a convincing AI answer is not the same as a correct engineering result. The late override above compiles, runs and prints no warning, so check the class in a log.

Interview questions on callbacks vs factory

  • When do you use a callback instead of the factory? For a small change at a fixed hook, especially in VIP you cannot edit, or one that switches on and off during the test.
  • When is the factory better? When the change replaces most of a component, or several tests need different versions of a class.
  • Can a factory override change a component that already exists? No. It only affects objects created after it is set.
  • How do you limit each to one instance? Pass the instance to uvm_callbacks::add, or use set_inst_override with its path.
  • What does a component need to support callbacks? `uvm_register_cb and a `uvm_do_callbacks call at the hook point.

More practice: UVM interview questions.

Practice challenge

  1. Run the simple example and confirm which driver changed class.
  2. Run the full bench with +BUG=1 and find drv_c‘s addresses.
  3. Move the delete in the test from 25 ns to 35 ns. What does check 5 report?
  4. Bonus: remove `uvm_set_super_type from tav_err_drv and see what check 6 reports on your simulator.

FAQ

What is the difference between a UVM callback and a factory override? A callback adds code at a hook inside a component that keeps its class. A factory override replaces the class itself when the component is created.

Can I add a callback during the run? Yes. In this bench a callback added at 15 ns and deleted at 25 ns changed only the item driven at 20 ns.

Why is my factory override not working? The two common causes are setting it after the component is built, and building the component with new() instead of type_id::create().

Do callbacks work on a factory-replaced child class? In this bench, yes: the child declared `uvm_set_super_type, and the type-wide callback counted all 9 items.

Which is better for error injection? Usually a callback, because the change is small and you can turn it on only when needed.

References

  • IEEE 1800.2-2020, Universal Verification Methodology (UVM) standard: callbacks and the factory.
  • Accellera UVM 1.2 Class Reference: uvm_callback, uvm_callbacks, uvm_factory and the `uvm_register_cb / `uvm_set_super_type macros.

Keep learning