Virtual Interface in UVM: Pass It with uvm_config_db, Tested on VCS
In short: A virtual interface in UVM is a handle that points to a real SystemVerilog interface instance. You put it into the config database with uvm_config_db#(virtual tav_apb_if)::set() in your top module, and the driver and monitor read it with get() in build_phase. After that, class code can drive and sample real DUT pins without a single hard-coded path.
A null virtual interface is one of the most common UVM errors. The set() is there, the get() is there, and the driver still gets a null handle. Most of the time, the cause is one wrong character in a path string.
In this lesson we build a small APB bench that I ran on Synopsys VCS, look at its waveform, and then cover every way to pass the handle.
What you will learn
- What a virtual interface is, and why UVM classes need one.
- How to set it in the top module and get it in
build_phase. - Five ways to deliver the handle, with pros and cons.
- How modports, clocking blocks, multiple instances and parameters change things.
- How to debug a null virtual interface in minutes.
Cheat sheet: virtual interface in 4 rules
| Rule | Where | Why |
|---|---|---|
| 1. Set the handle | Top module, before run_test() | The interface exists at time 0. Build starts after run_test(). |
| 2. Get the handle | build_phase of the user | Parents build first, so the entry is ready. |
| 3. Check the return bit | Every get() | Fail early with uvm_fatal and a clear message. |
| 4. Use the handle | run_phase and later | Pins only move once time starts. |
What is a virtual interface in UVM?
A virtual interface is a variable that holds a reference to an interface instance.
- Before assignment: it is
null, like an empty class handle. - After assignment: every signal and clocking block of the real interface is reachable through it.
- Type rule:
virtual tav_apb_ifcan only point to atav_apb_ifinstance.
“Virtual interfaces provide a mechanism for separating abstract models and test programs from the actual signals that make up the design.”
IEEE 1800-2017, section 25.9
That separation is the whole point. Your driver talks to vif.psel and does not care which instance in the top module that really is.
Why UVM classes need a virtual interface
A UVM testbench lives in two worlds that are built at different times.
| Class world | Static world | |
|---|---|---|
| What lives here | Test, env, agent, driver, monitor | Interface instance, DUT |
| When it is built | At run time, in build_phase | Once, at elaboration, before time 0 |
| How you reach it | Through handles | Through instance names |
A class cannot instance an interface or name a static instance directly. It can only hold a handle, and that handle is the virtual interface.
Analogy: a TV remote does not hold the wires inside the TV. It holds a link, and that is enough to change the channel. The driver is the remote, the interface is the TV, and the virtual interface is the link.
The working example: a small APB bench
I ran this exact code on Synopsys VCS X-2025.06 with UVM 1.2. All user names use the tav_ prefix.
Run it yourself: the one-file version is on GitHub. Paste it into EDA Playground, pick VCS and UVM 1.2, and set the top module to tb_top.
| File | What it does |
|---|---|
tav_apb_if.sv | APB pins, two clocking blocks, two modports |
tav_apb_slave.sv | The DUT: 16 registers, zero wait states |
tb_top.sv | Clock, reset, interface instance, and the set() call |
tav_apb_pkg.sv | Item, sequence, driver, monitor, scoreboard, agent, env, test |
The test: write three registers, read them back, and let the scoreboard check every read.
Step 1: the interface, with clocking blocks
drv_cbdrives outputs 1 ns after the clock edge.mon_cbonly samples, just before the edge.- Modports are optional. We use them later.
// tav_apb_if.sv
// The Art of Verification | theartofverification.com
// A small APB interface used to show how a virtual interface reaches the UVM classes.
interface tav_apb_if (input logic pclk);
logic presetn;
logic [7:0] paddr;
logic psel;
logic penable;
logic pwrite;
logic [31:0] pwdata;
logic [31:0] prdata;
logic pready;
// Driver side: outputs change 1ns after the clock edge, inputs are
// sampled just before the edge. This removes races between TB and DUT.
clocking drv_cb @(posedge pclk);
default input #1step output #1;
output psel, penable, pwrite, paddr, pwdata;
input pready, prdata;
endclocking
// Monitor side: only samples, never drives.
clocking mon_cb @(posedge pclk);
default input #1step;
input psel, penable, pwrite, paddr, pwdata, prdata, pready;
endclocking
// Modports describe who may do what. Useful when you want the compiler
// to stop a monitor from driving a pin by mistake.
modport drv_mp (clocking drv_cb, input presetn);
modport mon_mp (clocking mon_cb, input presetn);
endinterface
Step 2: the DUT
The DUT has plain ports, like most real RTL. The interface is a testbench idea, so the top module wires its signals to the DUT ports.
// tav_apb_slave.sv
// The Art of Verification | theartofverification.com
// A tiny APB slave with 16 x 32-bit registers and zero wait states.
// Plain ports, like most real RTL. The interface lives on the testbench side.
module tav_apb_slave (
input logic pclk,
input logic presetn,
input logic psel,
input logic penable,
input logic pwrite,
input logic [7:0] paddr,
input logic [31:0] pwdata,
output logic [31:0] prdata,
output logic pready
);
logic [31:0] tav_regs [16];
assign pready = 1'b1;
always_ff @(posedge pclk or negedge presetn) begin
if (!presetn) begin
foreach (tav_regs[i]) tav_regs[i] <= '0;
prdata <= '0;
end
else if (psel && !penable && !pwrite) begin
// Setup phase of a read: put data on prdata for the access phase
prdata <= tav_regs[paddr[5:2]];
end
else if (psel && penable && pwrite) begin
// Access phase of a write: store the data
tav_regs[paddr[5:2]] <= pwdata;
end
end
endmodule
Step 3: set the handle in the top module
One set() call, made before run_test(), hands the interface to the class world.
// tb_top.sv
// The Art of Verification | theartofverification.com
// Static world: clock, interface instance, DUT. Then hand the interface
// to the class world through uvm_config_db and start the test.
module tb_top;
import uvm_pkg::*;
`include "uvm_macros.svh"
import tav_apb_pkg::*;
logic pclk = 1'b0;
always #5 pclk = ~pclk; // 100 MHz
// The real (static) interface instance
tav_apb_if tav_apb_if_inst (pclk);
// DUT with plain ports, wired to the interface signals
tav_apb_slave dut (
.pclk (pclk),
.presetn (tav_apb_if_inst.presetn),
.psel (tav_apb_if_inst.psel),
.penable (tav_apb_if_inst.penable),
.pwrite (tav_apb_if_inst.pwrite),
.paddr (tav_apb_if_inst.paddr),
.pwdata (tav_apb_if_inst.pwdata),
.prdata (tav_apb_if_inst.prdata),
.pready (tav_apb_if_inst.pready)
);
// Reset
initial begin
tav_apb_if_inst.presetn = 1'b0;
repeat (2) @(posedge pclk);
tav_apb_if_inst.presetn = 1'b1;
end
initial begin
// One set reaches every component under env.agt (drv and mon)
uvm_config_db#(virtual tav_apb_if)::set(null, "uvm_test_top.env.agt.*",
"vif", tav_apb_if_inst);
run_test("tav_apb_test");
end
initial begin
$dumpfile("tav_vif.vcd");
$dumpvars(0, tb_top);
end
endmodule
Here is what each argument of that set() call means:
| Argument | Value in our set() | Value in get() | Tip |
|---|---|---|---|
| Type | virtual tav_apb_if | Same type | Must match exactly |
| cntxt | null | this | null means the path is absolute |
| inst_name | "uvm_test_top.env.agt.*" | "" | Wildcards allowed in set |
| field_name | "vif" | "vif" | Case sensitive string |
| value | tav_apb_if_inst | Your vif variable | The real instance |
Step 4: get the handle in the driver and monitor
- Where: in each component’s own
build_phase. - Always check the return bit of
get(). - On failure, stop with
uvm_fatal, so the error points at the cause, not at a null access 2,000 cycles later. - Drive and sample through
vif.drv_cbandvif.mon_cb, never raw signals.
// tav_apb_pkg.sv
// The Art of Verification | theartofverification.com
// UVM classes for the virtual interface demo.
package tav_apb_pkg;
import uvm_pkg::*;
`include "uvm_macros.svh"
// ---------------------------------------------------------------
// Transaction
// ---------------------------------------------------------------
class tav_apb_item extends uvm_sequence_item;
`uvm_object_utils(tav_apb_item)
bit [7:0] addr;
bit write;
bit [31:0] data;
function new(string name = "tav_apb_item");
super.new(name);
endfunction
function string convert2string();
return $sformatf("%s addr=0x%02h data=0x%08h",
write ? "WRITE" : "READ ", addr, data);
endfunction
endclass
// ---------------------------------------------------------------
// Sequence: write three registers, then read them back
// ---------------------------------------------------------------
class tav_apb_wr_rd_seq extends uvm_sequence #(tav_apb_item);
`uvm_object_utils(tav_apb_wr_rd_seq)
bit [31:0] tav_wdata [3] = '{32'hA5A5_0001, 32'h1234_5678, 32'hDEAD_BEEF};
function new(string name = "tav_apb_wr_rd_seq");
super.new(name);
endfunction
task body();
tav_apb_item tr;
foreach (tav_wdata[i]) begin
tr = tav_apb_item::type_id::create("tr");
start_item(tr);
tr.write = 1;
tr.addr = 8'(i * 4);
tr.data = tav_wdata[i];
finish_item(tr);
end
foreach (tav_wdata[i]) begin
tr = tav_apb_item::type_id::create("tr");
start_item(tr);
tr.write = 0;
tr.addr = 8'(i * 4);
finish_item(tr);
end
endtask
endclass
// ---------------------------------------------------------------
// Driver: gets the virtual interface, drives pins through drv_cb
// ---------------------------------------------------------------
class tav_apb_driver extends uvm_driver #(tav_apb_item);
`uvm_component_utils(tav_apb_driver)
virtual tav_apb_if vif;
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
if (!uvm_config_db#(virtual tav_apb_if)::get(this, "", "vif", vif))
`uvm_fatal("TAV_NOVIF", {"No virtual interface for ", get_full_name()})
`uvm_info("TAV_DRV", "Got the virtual interface", UVM_LOW)
endfunction
task run_phase(uvm_phase phase);
vif.drv_cb.psel <= 1'b0;
vif.drv_cb.penable <= 1'b0;
wait (vif.presetn === 1'b1);
forever begin
seq_item_port.get_next_item(req);
// Setup phase
@(vif.drv_cb);
vif.drv_cb.psel <= 1'b1;
vif.drv_cb.penable <= 1'b0;
vif.drv_cb.pwrite <= req.write;
vif.drv_cb.paddr <= req.addr;
vif.drv_cb.pwdata <= req.write ? req.data : '0;
// Access phase
@(vif.drv_cb);
vif.drv_cb.penable <= 1'b1;
// Wait for the slave to finish
do @(vif.drv_cb); while (vif.drv_cb.pready !== 1'b1);
if (!req.write) req.data = vif.drv_cb.prdata;
vif.drv_cb.psel <= 1'b0;
vif.drv_cb.penable <= 1'b0;
`uvm_info("TAV_DRV", {"Drove ", req.convert2string()}, UVM_MEDIUM)
seq_item_port.item_done();
end
endtask
endclass
// ---------------------------------------------------------------
// Monitor: gets the same virtual interface, only samples
// ---------------------------------------------------------------
class tav_apb_monitor extends uvm_monitor;
`uvm_component_utils(tav_apb_monitor)
virtual tav_apb_if vif;
uvm_analysis_port #(tav_apb_item) ap;
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
ap = new("ap", this);
if (!uvm_config_db#(virtual tav_apb_if)::get(this, "", "vif", vif))
`uvm_fatal("TAV_NOVIF", {"No virtual interface for ", get_full_name()})
`uvm_info("TAV_MON", "Got the virtual interface", UVM_LOW)
endfunction
task run_phase(uvm_phase phase);
tav_apb_item tr;
forever begin
@(vif.mon_cb);
if (vif.mon_cb.psel && vif.mon_cb.penable && vif.mon_cb.pready) begin
tr = tav_apb_item::type_id::create("tr");
tr.addr = vif.mon_cb.paddr;
tr.write = vif.mon_cb.pwrite;
tr.data = vif.mon_cb.pwrite ? vif.mon_cb.pwdata : vif.mon_cb.prdata;
`uvm_info("TAV_MON", {"Saw ", tr.convert2string()}, UVM_MEDIUM)
ap.write(tr);
end
end
endtask
endclass
// ---------------------------------------------------------------
// Scoreboard: keeps a model of the registers and checks every read
// ---------------------------------------------------------------
class tav_apb_scoreboard extends uvm_scoreboard;
`uvm_component_utils(tav_apb_scoreboard)
uvm_analysis_imp #(tav_apb_item, tav_apb_scoreboard) imp;
bit [31:0] tav_model [bit [7:0]];
int tav_pass, tav_fail;
function new(string name, uvm_component parent);
super.new(name, parent);
imp = new("imp", this);
endfunction
function void write(tav_apb_item tr);
if (tr.write) begin
tav_model[tr.addr] = tr.data;
end
else begin
bit [31:0] exp = tav_model.exists(tr.addr) ? tav_model[tr.addr] : '0;
if (tr.data == exp) begin
tav_pass++;
`uvm_info("TAV_SCB", $sformatf("PASS addr=0x%02h data=0x%08h", tr.addr, tr.data), UVM_LOW)
end
else begin
tav_fail++;
`uvm_error("TAV_SCB", $sformatf("FAIL addr=0x%02h exp=0x%08h got=0x%08h",
tr.addr, exp, tr.data))
end
end
endfunction
function void report_phase(uvm_phase phase);
`uvm_info("TAV_SCB", $sformatf("Reads checked: %0d pass, %0d fail", tav_pass, tav_fail), UVM_NONE)
endfunction
endclass
// ---------------------------------------------------------------
// Agent, env, test
// ---------------------------------------------------------------
class tav_apb_agent extends uvm_agent;
`uvm_component_utils(tav_apb_agent)
tav_apb_driver drv;
tav_apb_monitor mon;
uvm_sequencer #(tav_apb_item) sqr;
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
drv = tav_apb_driver::type_id::create("drv", this);
mon = tav_apb_monitor::type_id::create("mon", this);
sqr = uvm_sequencer#(tav_apb_item)::type_id::create("sqr", this);
endfunction
function void connect_phase(uvm_phase phase);
drv.seq_item_port.connect(sqr.seq_item_export);
endfunction
endclass
class tav_apb_env extends uvm_env;
`uvm_component_utils(tav_apb_env)
tav_apb_agent agt;
tav_apb_scoreboard scb;
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
agt = tav_apb_agent::type_id::create("agt", this);
scb = tav_apb_scoreboard::type_id::create("scb", this);
endfunction
function void connect_phase(uvm_phase phase);
agt.mon.ap.connect(scb.imp);
endfunction
endclass
class tav_apb_test extends uvm_test;
`uvm_component_utils(tav_apb_test)
tav_apb_env env;
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
env = tav_apb_env::type_id::create("env", this);
endfunction
task run_phase(uvm_phase phase);
tav_apb_wr_rd_seq seq = tav_apb_wr_rd_seq::type_id::create("seq");
phase.raise_objection(this);
seq.start(env.agt.sqr);
#20;
phase.drop_objection(this);
endtask
endclass
endpackage
What the run shows

What to notice:
- Each APB transfer takes two cycles: setup (
pselhigh), then access (penablehigh). - Both components report “Got the virtual interface” at time 0, during build, before any clock edge.
- All three reads return the written data: 3 pass, 0 fail, with zero errors.
Here is the log from my VCS run:
UVM_INFO @ 0: reporter [RNTST] Running test tav_apb_test...
UVM_INFO testbench.sv(115) @ 0: uvm_test_top.env.agt.drv [TAV_DRV] Got the virtual interface
UVM_INFO testbench.sv(169) @ 0: uvm_test_top.env.agt.mon [TAV_MON] Got the virtual interface
UVM_INFO testbench.sv(181) @ 35: uvm_test_top.env.agt.mon [TAV_MON] Saw WRITE addr=0x00 data=0xa5a50001
UVM_INFO testbench.sv(145) @ 35: uvm_test_top.env.agt.drv [TAV_DRV] Drove WRITE addr=0x00 data=0xa5a50001
UVM_INFO testbench.sv(181) @ 65: uvm_test_top.env.agt.mon [TAV_MON] Saw WRITE addr=0x04 data=0x12345678
UVM_INFO testbench.sv(145) @ 65: uvm_test_top.env.agt.drv [TAV_DRV] Drove WRITE addr=0x04 data=0x12345678
UVM_INFO testbench.sv(181) @ 95: uvm_test_top.env.agt.mon [TAV_MON] Saw WRITE addr=0x08 data=0xdeadbeef
UVM_INFO testbench.sv(145) @ 95: uvm_test_top.env.agt.drv [TAV_DRV] Drove WRITE addr=0x08 data=0xdeadbeef
UVM_INFO testbench.sv(181) @ 125: uvm_test_top.env.agt.mon [TAV_MON] Saw READ addr=0x00 data=0xa5a50001
UVM_INFO testbench.sv(211) @ 125: uvm_test_top.env.scb [TAV_SCB] PASS addr=0x00 data=0xa5a50001
UVM_INFO testbench.sv(145) @ 125: uvm_test_top.env.agt.drv [TAV_DRV] Drove READ addr=0x00 data=0xa5a50001
UVM_INFO testbench.sv(181) @ 155: uvm_test_top.env.agt.mon [TAV_MON] Saw READ addr=0x04 data=0x12345678
UVM_INFO testbench.sv(211) @ 155: uvm_test_top.env.scb [TAV_SCB] PASS addr=0x04 data=0x12345678
UVM_INFO testbench.sv(145) @ 155: uvm_test_top.env.agt.drv [TAV_DRV] Drove READ addr=0x04 data=0x12345678
UVM_INFO testbench.sv(181) @ 185: uvm_test_top.env.agt.mon [TAV_MON] Saw READ addr=0x08 data=0xdeadbeef
UVM_INFO testbench.sv(211) @ 185: uvm_test_top.env.scb [TAV_SCB] PASS addr=0x08 data=0xdeadbeef
UVM_INFO testbench.sv(145) @ 185: uvm_test_top.env.agt.drv [TAV_DRV] Drove READ addr=0x08 data=0xdeadbeef
UVM_INFO testbench.sv(222) @ 205: uvm_test_top.env.scb [TAV_SCB] Reads checked: 3 pass, 0 fail
--- UVM Report Summary ---
UVM_INFO : 21
UVM_WARNING : 0
UVM_ERROR : 0
UVM_FATAL : 0
How the handle travels: set once, get where you need it

uvm_test_top.env.agt.*. The agent itself does not, because .* only covers what sits under it.- Time 0:
tb_topcallsset(). UVM stores a scope pattern, a field name, a type and a value. - run_test(): UVM creates the test and runs
build_phasetop down. - build_phase: each component calls
get(). UVM builds its full name and checks it against the stored patterns. - Match: the handle is copied into
vif. No match:get()returns 0.
Every way to give a component its virtual interface
You will meet all five in existing testbenches. Here they are, from most common to the ones to avoid.
1. Direct get in the driver and monitor
- How:
tb_topsets with a wildcard path, and each driver and monitor gets the handle itself. This is our example. - When: small and medium benches, one or two agents, lessons and demos.
- Pros: very little code, and a missing handle is reported by the exact component that needs it.
- Cons: every component does its own string lookup, and
tb_topmust know names deep inside the env.
2. The agent gets it and hands it down
// tb_top: the set path now stops at the agent
uvm_config_db#(virtual tav_apb_if)::set(null, "uvm_test_top.env.agt", "vif", tav_apb_if_inst);
// tav_apb_agent
virtual tav_apb_if vif;
function void build_phase(uvm_phase phase);
super.build_phase(phase);
if (!uvm_config_db#(virtual tav_apb_if)::get(this, "", "vif", vif))
`uvm_fatal("TAV_NOVIF", "Agent has no virtual interface")
drv = tav_apb_driver::type_id::create("drv", this);
mon = tav_apb_monitor::type_id::create("mon", this);
endfunction
function void connect_phase(uvm_phase phase);
drv.vif = vif;
mon.vif = vif;
drv.seq_item_port.connect(sqr.seq_item_export);
endfunction
- How: the set path stops at the agent. The agent gets the handle once and assigns it to its children in
connect_phase. - When: you want the driver and monitor free of config lookups.
- Pros: one lookup per agent, and a shorter path in
tb_top. - Cons: the driver and monitor must drop their own
get()and must not touchvifbeforeconnect_phase.
3. A config object that carries the handle
class tav_apb_agent_cfg extends uvm_object;
`uvm_object_utils(tav_apb_agent_cfg)
virtual tav_apb_if vif;
uvm_active_passive_enum is_active = UVM_ACTIVE;
function new(string name = "tav_apb_agent_cfg");
super.new(name);
endfunction
endclass
// tb_top
uvm_config_db#(virtual tav_apb_if)::set(null, "uvm_test_top", "apb_vif", tav_apb_if_inst);
// tav_apb_test::build_phase
tav_apb_agent_cfg cfg;
super.build_phase(phase);
cfg = tav_apb_agent_cfg::type_id::create("cfg");
if (!uvm_config_db#(virtual tav_apb_if)::get(this, "", "apb_vif", cfg.vif))
`uvm_fatal("TAV_NOVIF", "Test has no APB virtual interface")
uvm_config_db#(tav_apb_agent_cfg)::set(this, "env.agt*", "cfg", cfg);
env = tav_apb_env::type_id::create("env", this);
- How: the test gets the handle, stores it in an agent config object with other settings, and sets that object for the agent.
- When: subsystem and SoC benches with many agents, or agents you reuse across projects.
- Pros: clean reuse, one place to change settings, and only the test knows how
tb_topis wired. - Cons: more code up front, which feels heavy for a small block bench.
4. Hierarchical reference (avoid)
- How:
vif = tb_top.tav_apb_if_inst;inside a class. Some tools accept it. - Why to avoid: the moment the agent moves to a different top module, every such line breaks.
5. A global handle in a package (avoid)
- How:
virtual tav_apb_if g_vif;in a package, assigned from the top. - Why to avoid: it breaks with two instances of the same agent, and nothing tells you who changed it.
| Method | Best for | Reuse | Recommendation |
|---|---|---|---|
| Direct get in driver and monitor | Block benches, lessons | Good | Start here |
| Agent gets and hands down | Thin drivers and monitors | Good | Fine choice |
| Config object | Subsystem and SoC benches | Best | Use on real projects |
| Hierarchical reference | Quick hacks | Poor | Avoid |
| Package global | Old code | Poor | Avoid |
Modports with a virtual interface
- What: a modport limits what a component can see, for example
virtual tav_apb_if.mon_mp vif;. - Catch: the config database matches the exact type. Set
virtual tav_apb_ifand getvirtual tav_apb_if.mon_mp, and the get fails. - Fix: set each modport view with its own type, as below.
// tb_top
uvm_config_db#(virtual tav_apb_if.drv_mp)::set(null, "uvm_test_top.env.agt.drv", "vif", tav_apb_if_inst.drv_mp);
uvm_config_db#(virtual tav_apb_if.mon_mp)::set(null, "uvm_test_top.env.agt.mon", "vif", tav_apb_if_inst.mon_mp);
// tav_apb_monitor
virtual tav_apb_if.mon_mp vif;
...
if (!uvm_config_db#(virtual tav_apb_if.mon_mp)::get(this, "", "vif", vif))
`uvm_fatal("TAV_NOVIF", "Monitor has no virtual interface")
- Pro: a monitor that tries to drive a pin fails at compile time, not in a review.
- Con: two set calls per agent and longer type names. Modports pay off most in shared agent code.
Clocking blocks through a virtual interface
- Drive:
vif.drv_cb.psel <= 1'b1;after@(vif.drv_cb); - Why: the clocking block drives a little after the edge and samples just before it.
- Without it: class code and DUT flops can act on the same edge, and the result depends on simulator scheduling.
- Rule: use
<=for clocking block outputs, and read inputs only after waiting on the clocking event.
Two agents, two interfaces
Give each agent instance its own handle by path, and keep the same field name. The driver code stays exactly the same for both.
tav_apb_if tav_apb_if_m0 (pclk);
tav_apb_if tav_apb_if_m1 (pclk);
initial begin
uvm_config_db#(virtual tav_apb_if)::set(null, "uvm_test_top.env.agt_m0.*", "vif", tav_apb_if_m0);
uvm_config_db#(virtual tav_apb_if)::set(null, "uvm_test_top.env.agt_m1.*", "vif", tav_apb_if_m1);
run_test();
end
Parameterized interfaces
virtual tav_bus_if #(.DW(32))andvirtual tav_bus_if #(.DW(64))are two different types.- Make one typedef and use it in both set and get, so they can never drift apart.
typedef virtual tav_bus_if #(.DW(64), .AW(40)) tav_bus_vif_t;
uvm_config_db#(tav_bus_vif_t)::set(null, "uvm_test_top.env.bus_agt.*", "vif", tav_bus_if_inst);
...
tav_bus_vif_t vif;
if (!uvm_config_db#(tav_bus_vif_t)::get(this, "", "vif", vif))
`uvm_fatal("TAV_NOVIF", "No bus virtual interface")
How to debug a missing virtual interface
| Tool | How to use it | What it shows |
|---|---|---|
+UVM_CONFIG_DB_TRACE | Add to the simulator command line | Every set and get with full paths |
uvm_top.print_topology() | Call in end_of_elaboration_phase | The real instance names to compare with your set path |
check_config_usage() | Call in report_phase | Sets that nobody read, usually a path or name mismatch |
print_config(1) | Call in the failing component | What that component can see in the database |
Why this matters: the 2024 Wilson Research Group study found that verification engineers spend more time on debug than on any other task, and only 14 percent of IC/ASIC projects reached first silicon success. A few minutes with a trace beats an afternoon of staring at code.
Common mistakes to avoid
| Mistake | What you see | Fix |
|---|---|---|
| Path does not match the instance name | get() returns 0 | Copy names from print_topology() |
Dot before the star: agt.* | The agent’s own get() fails | Use agt* if the agent also gets |
| Type mismatch (modport or parameters) | get() returns 0 | Use the identical type or a typedef |
Field name mismatch: "vif" vs "apb_vif" | get() returns 0 | Use one string constant |
No return check on get() | Null access crash at the first pin access | Wrap every get in if (!...) `uvm_fatal |
set() placed after run_test() | The set never runs before build | Put the set above run_test() |
Using vif in build_phase | Compile error if you wait on a clock | Build is a function. Wait for run_phase |
Package compiled after tb_top | VCS Error-[SV-LCM-PND] Package not defined | Order: interface, package, then tb_top |
EDA Playground tip: only design.sv and testbench.sv are compiled. Put the DUT in design.sv and the interface, package and tb_top in testbench.sv, in that order. I hit the package error myself while testing this lesson.
How AI helps you master this
Virtual interface bugs are mostly string and type matching problems, so AI assistants are good at spotting them.
- Find the mismatch: paste your
set(), the failingget()and theprint_topology()output. Ask “why does this get return 0?”. - Generate the interface: give it your DUT port list and ask for clocking blocks and modports. Then review every direction yourself.
- Quiz yourself: ask for five broken set and get pairs, and find each bug before reading the answer.
Warning: a convincing AI answer is not the same as a correct engineering result. AI tools can mix up agt.* and agt* or suggest hierarchical references. Always run the code and check the trace.
Interview questions on virtual interfaces
- Why can’t a UVM driver use the interface instance directly? Classes are created at run time and can only hold handles. Interface instances are static.
- Where do you set the virtual interface, and why there? In the top module before
run_test(), because the interface exists at time 0 and build starts afterrun_test(). - Your driver gets a null virtual interface. What do you check first? The path, the field name and the exact type, with
+UVM_CONFIG_DB_TRACE. - Why drive through a clocking block? It drives after the edge and samples before it, which removes races with the DUT.
More practice: verification interview questions.
Practice challenge
- Run the bench as it is and confirm 3 pass, 0 fail.
- Change the set path to
uvm_test_top.env.agent.*. Predict the error before you run it. - Add
+UVM_CONFIG_DB_TRACEand find the line that shows the mismatch. - Bonus: convert the monitor to
virtual tav_apb_if.mon_mpwith its own set, then try to drivepselfrom it. The compiler should stop you.
FAQ
What is a virtual interface in UVM? A virtual interface is a handle to a real SystemVerilog interface instance. It lets UVM classes, which are created at run time, drive and sample the static pins that connect to the DUT.
Why do we pass the virtual interface with uvm_config_db? The config database carries the handle from the top module down into the class hierarchy without hard-coded paths. The top module sets it once, and each component that needs it reads it in build_phase.
Where should I set the virtual interface? In the top module, in an initial block, before calling run_test(). Use context null with an absolute path such as uvm_test_top.env.agt.* so it reaches the right components.
Where should I get the virtual interface? In build_phase of the component that uses it, usually the driver and monitor, or in the test if you pass it through a config object. Always check the return bit and call uvm_fatal if it is 0.
Why is my virtual interface null in UVM? The get() did not match any set(). The usual causes are a wrong path, a different field name, a different type such as a modport or parameter mismatch, or a set placed after run_test().
What is the difference between agt.* and agt* in a set path? agt.* matches components below agt, such as agt.drv and agt.mon, but not agt itself. agt* matches agt and everything below it, and also any sibling whose name starts with agt.
Can I use a modport with a virtual interface in uvm_config_db? Yes. Declare the variable as virtual tav_apb_if.mon_mp, and set and get with that exact type, passing the modport of the instance in set().
Should I use a config object or a direct get? For a small block bench, a direct get is simple and clear. For subsystem and SoC benches with many agents, put the virtual interface in an agent config object so only the test needs to know how the top module is wired.
References
- IEEE 1800-2017, SystemVerilog standard: section 25.9, virtual interfaces; section 14, clocking blocks; section 25.5, modports.
- IEEE 1800.2, UVM class reference:
uvm_config_db,uvm_component::check_config_usage()anduvm_component::print_config(). - Accellera, Universal Verification Methodology (UVM) 1.2 class reference and user guide: the configuration database.
- Siemens EDA and Wilson Research Group, 2024 IC/ASIC Functional Verification Trend Report.
Keep learning
- Previous lesson: uvm_config_db vs uvm_resource_db, if set and get precedence still feels fuzzy.
- The idea behind the handle: why we need a virtual interface.
- The big picture: typical UVM testbench architecture.
- Next lesson: UVM TLM ports and exports.
- Full course: the UVM methodology learning path.
Part of the learning path UVM methodology

Hi Hardik
with the picturization one can get clear idea.. Very nice explanation
Thank you Sattya 🙂
Thank-you very much Hardik. It really helped.
Thank you Bhushan 🙂 Please share it with your friends or colleagues so it will help to more engineers 🙂
Hi,
I think that instead of:
1. passing the virtual interface to the config object
2. passing the config object to config_db
one could do it in a single step: pass the virtual interface using config_db
Isn’t it better this way?
Hi Zeev,
Yeah, I do agree with you that we can do with a single step as well but in that example or for reusability purposes we usually keep all the configurations in a separate class or file so whenever we need it we can reuse it anywhere in the UVM environment. I hope you got the point.
Thank you
I need to understand config db. Still not clear please share any video link