Build a UVM environment part 1: interface, transaction and driver, tested on VCS. The Art of Verification

Build a UVM Environment, Part 1: Design, Interface, Transaction and Driver (Tested)

In short: part 1 of 4 builds the three lowest layers of a UVM environment for a small design: the interface (the pins), the transaction (one unit of work) and the driver skeleton (the block that will turn work into pin activity). Every piece runs on Synopsys VCS, with 7 checks and four planted bugs. Parts 2 to 4 add the sequencer, monitor, scoreboard, environment and test on top of this same file.

In UVM testbench architecture we looked at what each testbench part is for. This series builds one, from the first line to a running regression, for one small design.

The order matters. You cannot drive pins you have not described, and you cannot check results you have not defined. So we start at the bottom.

Four columns for the four parts of the series. Part 1, highlighted: tav_pipe, tav_pipe_if, tav_pipe_item and the driver build phase. Part 2: driver run phase, sequencer, sequences. Part 3: monitor, agent, scoreboard, env. Part 4: test, config_db wiring, regression
One design, one bench that grows over four parts.

Start here: the simplest example

The transaction on its own. We randomize it three times and print it with sprint(), which works because of the field macros.

// tav_env1_simple.sv : the pipe transaction on its own, randomized and printed (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::*;

// One unit of work for the pipe: what to send, and (later) what came back
class tav_pipe_item extends uvm_sequence_item;
  rand bit [1:0]  cf;          // control field: 00 pass, 01 swap, 10 add/sub
  rand bit [15:0] data_in1;
  rand bit [15:0] data_in2;
       bit [15:0] data_out1;   // filled in later by the monitor, never randomized
       bit [15:0] data_out2;
  rand int        delay;       // idle cycles before this item

  constraint c_legal_cf { cf != 2'b11; }
  constraint c_delay    { delay inside {[0:5]}; }

  `uvm_object_utils_begin(tav_pipe_item)
    `uvm_field_int(cf,        UVM_ALL_ON)
    `uvm_field_int(data_in1,  UVM_ALL_ON)
    `uvm_field_int(data_in2,  UVM_ALL_ON)
    `uvm_field_int(data_out1, UVM_ALL_ON)
    `uvm_field_int(data_out2, UVM_ALL_ON)
    `uvm_field_int(delay,     UVM_ALL_ON | UVM_DEC)
  `uvm_object_utils_end

  function new(string name = "tav_pipe_item");
    super.new(name);
  endfunction
endclass

module tav_top;
  initial begin
    tav_pipe_item it = tav_pipe_item::type_id::create("it");
    repeat (3) begin
      if (!it.randomize()) `uvm_error("TAV_ITEM", "randomize failed")
      `uvm_info("TAV_ITEM", {"\n", it.sprint()}, UVM_LOW)
    end
  end
endmodule

Here is what VCS printed:

UVM_INFO testbench.sv(41) @ 0: reporter [TAV_ITEM] 
----------------------------------------
Name         Type           Size  Value 
----------------------------------------
it           tav_pipe_item  -     @336  
  cf         integral       2     'h1   
  data_in1   integral       16    'h8aa3
  data_in2   integral       16    'h88f 
  data_out1  integral       16    'h0   
  data_out2  integral       16    'h0   
  delay      integral       32    'd0   
----------------------------------------

UVM_INFO testbench.sv(41) @ 0: reporter [TAV_ITEM] 
----------------------------------------
Name         Type           Size  Value 
----------------------------------------
it           tav_pipe_item  -     @336  
  cf         integral       2     'h0   
  data_in1   integral       16    'h47d6
  data_in2   integral       16    'h2797
  data_out1  integral       16    'h0   
  data_out2  integral       16    'h0   
  delay      integral       32    'd5   
----------------------------------------

UVM_INFO testbench.sv(41) @ 0: reporter [TAV_ITEM] 
----------------------------------------
Name         Type           Size  Value 
----------------------------------------
it           tav_pipe_item  -     @336  
  cf         integral       2     'h2   
  data_in1   integral       16    'h6c01
  data_in2   integral       16    'h9ede
  data_out1  integral       16    'h0   
  data_out2  integral       16    'h0   
  delay      integral       32    'd2   
----------------------------------------
  • The constraints held: cf came out 1, 0 and 2, never 3, and delay stayed inside 0 to 5.
  • The outputs stayed 0: data_out1 and data_out2 are not rand, because they come from the design, not the test.
  • The table is free: the field macros give you sprint(), copy() and compare() without writing them.

What you will learn

  • How to turn a design’s port list into an interface with a clocking block and modports.
  • What goes into a transaction, what stays out of rand, and why the field macros matter.
  • How a child transaction changes the stimulus through the factory, and the one-character dist mistake that breaks it.
  • How the driver gets its interface from uvm_config_db, and what happens when it does not.

Step 1: the design under test

The design is tav_pipe: two 16-bit channels, a 2-bit control field, an enable and an active-low reset. Results appear one clock after the inputs are sampled.

cfOperationo_data1o_data2
00passi_data1i_data2
01swapi_data2i_data1
10add / subtracti_data1 + i_data2i_data1 - i_data2
11illegal00

Write this table before any testbench code. It becomes the reference model inside the scoreboard in part 3.

Analogy: building a testbench is like setting up a small factory. First you describe the loading dock (the interface), then the order form (the transaction), then the worker who reads one order and runs the machine (the driver). The inspector and the manager come later.

Step 2: the interface

An interface bundles the design’s signals so the testbench passes one handle instead of eight wires. Two additions make it safer:

  • A clocking block (drv_cb) drives outputs 1 ns after the clock and samples inputs just before it (#1step), so the driver and the design never race.
  • Modports give each user a direction: DRV drives through the clocking block, MON only reads. A monitor using MON cannot drive a pin by mistake.

For why the testbench needs a virtual interface at all, and how it travels, see UVM virtual interface.

Step 3: the transaction

The transaction, or sequence item, is one unit of work. For the pipe it holds the control field, both inputs, both outputs (filled in later by the monitor) and an idle delay.

  • rand on inputs only: the outputs come from the design, so randomizing them would give the checker nonsense to compare.
  • Constraints keep it legal: cf != 2'b11 and delay in 0 to 5. For switching them off on purpose, see rand_mode and constraint_mode.
  • Field macros: without them print, copy and compare do nothing useful, and the scoreboard cannot compare items.
  • A stress child: tav_pipe_stress_item extends the item and pushes both inputs toward 16'hFFFF. The factory can swap it in without touching the sequence (UVM factory).

Step 4: the driver skeleton

The driver will take one item at a time and wiggle the pins. In part 1 it only does its setup: in build_phase it fetches the interface from uvm_config_db, and stops with a clear UVM_FATAL if it is missing.

The drive loop (get_next_item, drive, item_done) arrives in part 2 with the sequencer. Until then, the test drives three items straight through drv_cb to prove the interface and the design work.

The bench: all four layers, 7 checks

Run it yourself: the files are on GitHub, with the expected output. Parts 2 to 4 will be added to the same folder.

// tav_env1_uvm.sv : UVM environment part 1 - design, interface, transaction, driver skeleton, 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_pipe              the design: 2 x 16-bit channels, cf 00 pass, 01 swap, 10 add/sub, 11 zero, 1 cycle latency
//   tav_pipe_if           the interface, with a driver clocking block and DRV / MON modports
//   tav_pipe_item         the transaction; tav_pipe_stress_item pushes data toward 16'hFFFF
//   tav_pipe_driver       the driver skeleton: gets the interface from uvm_config_db (drive logic comes in part 2)
//   tav_env1_test         7 self-checks
//
// Run options:
//   (none)   all 7 checks pass, 0 errors
//   +BUG=1   the legal-cf constraint is switched off, so illegal cf = 11 appears        (check 2 fails)
//   +BUG=2   the design does not swap on cf = 01                                       (check 7 fails)
//   +BUG=3   the test never puts the interface in uvm_config_db                         (driver stops with UVM_FATAL)
//   +BUG=4   the stress item uses := instead of :/ for the range, so 16'hFFFF is rare  (check 6 fails)

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

// ---------------------------------------------------------------- the design
module tav_pipe (input  logic        clk, rst_n,
                 input  logic [1:0]  i_cf,
                 input  logic        i_en,
                 input  logic [15:0] i_data1, i_data2,
                 output logic [15:0] o_data1, o_data2);
  int tav_bug;
  initial void'($value$plusargs("BUG=%d", tav_bug));
  always @(posedge clk) begin
    if (!rst_n) begin
      o_data1 <= '0; o_data2 <= '0;
    end
    else if (i_en) begin
      case (i_cf)
        2'b00:   begin o_data1 <= i_data1;           o_data2 <= i_data2;           end  // pass
        2'b01:   if (tav_bug == 2)                                                     // BUG=2: no swap
                 begin o_data1 <= i_data1;           o_data2 <= i_data2;           end
                 else
                 begin o_data1 <= i_data2;           o_data2 <= i_data1;           end  // swap
        2'b10:   begin o_data1 <= i_data1 + i_data2; o_data2 <= i_data1 - i_data2; end  // add / sub
        default: begin o_data1 <= '0;                o_data2 <= '0;                end
      endcase
    end
  end
endmodule

// ---------------------------------------------------------------- the interface
interface tav_pipe_if (input logic clk, input logic rst_n);
  logic [1:0]  cf;
  logic        enable;
  logic [15:0] data_in1, data_in2;
  logic [15:0] data_out1, data_out2;

  clocking drv_cb @(posedge clk);          // the driver drives and samples here, race free
    default input #1step output #1;
    output cf, enable, data_in1, data_in2;
    input  data_out1, data_out2;
  endclocking

  modport DRV (clocking drv_cb, input clk, rst_n);
  modport MON (input clk, rst_n, cf, enable, data_in1, data_in2, data_out1, data_out2);
endinterface

// ---------------------------------------------------------------- the transaction
class tav_pipe_item extends uvm_sequence_item;
  rand bit [1:0]  cf;
  rand bit [15:0] data_in1;
  rand bit [15:0] data_in2;
       bit [15:0] data_out1;   // from the design, never randomized
       bit [15:0] data_out2;
  rand int        delay;

  constraint c_legal_cf { cf != 2'b11; }
  constraint c_delay    { delay inside {[0:5]}; }

  `uvm_object_utils_begin(tav_pipe_item)
    `uvm_field_int(cf,        UVM_ALL_ON)
    `uvm_field_int(data_in1,  UVM_ALL_ON)
    `uvm_field_int(data_in2,  UVM_ALL_ON)
    `uvm_field_int(data_out1, UVM_ALL_ON)
    `uvm_field_int(data_out2, UVM_ALL_ON)
    `uvm_field_int(delay,     UVM_ALL_ON | UVM_DEC)
  `uvm_object_utils_end

  function new(string name = "tav_pipe_item");
    super.new(name);
  endfunction

  function void pre_randomize();
    int tav_bug;
    void'($value$plusargs("BUG=%d", tav_bug));
    if (tav_bug == 1) c_legal_cf.constraint_mode(0);        // BUG=1: illegal cf allowed
  endfunction
endclass

// A child item for stress: data_in1 and data_in2 are 16'hFFFF about 3 times in 4
class tav_pipe_stress_item extends tav_pipe_item;
  `uvm_object_utils(tav_pipe_stress_item)
  // :/ shares the weight 1 across the whole range, so FFFF gets 3 parts in 4
  constraint c_corner_ok  { data_in1 dist { 16'hFFFF := 3, [0:16'hFFFE] :/ 1 };
                            data_in2 dist { 16'hFFFF := 3, [0:16'hFFFE] :/ 1 }; }
  // := gives EVERY value in the range weight 1, so FFFF gets 3 parts in 65538
  constraint c_corner_bad { data_in1 dist { 16'hFFFF := 3, [0:16'hFFFE] := 1 };
                            data_in2 dist { 16'hFFFF := 3, [0:16'hFFFE] := 1 }; }
  function new(string name = "tav_pipe_stress_item");
    super.new(name);
  endfunction
  function void pre_randomize();
    int tav_bug;
    super.pre_randomize();
    void'($value$plusargs("BUG=%d", tav_bug));
    c_corner_ok.constraint_mode(tav_bug != 4);               // BUG=4: the := version is used
    c_corner_bad.constraint_mode(tav_bug == 4);
  endfunction
endclass

// ---------------------------------------------------------------- the driver skeleton
class tav_pipe_driver extends uvm_driver #(tav_pipe_item);
  `uvm_component_utils(tav_pipe_driver)
  virtual tav_pipe_if.DRV 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_pipe_if.DRV)::get(this, "", "vif", vif))
      `uvm_fatal("TAV_NOVIF", {"no virtual interface set for ", get_full_name(), ".vif"})
  endfunction
  // run_phase (get_next_item, drive the pins, item_done) is written in part 2
endclass

// ---------------------------------------------------------------- the test
class tav_env1_test extends uvm_test;
  `uvm_component_utils(tav_env1_test)
  tav_pipe_driver drv;
  int tav_pass, tav_fail;
  string tav_dut_res;
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction

  function void build_phase(uvm_phase phase);
    virtual tav_pipe_if.DRV v;
    int tav_bug;
    void'($value$plusargs("BUG=%d", tav_bug));
    if (!uvm_config_db#(virtual tav_pipe_if.DRV)::get(null, "tav_top", "vif", v))
      `uvm_fatal("TAV_NOVIF", "tav_top did not publish the interface")
    if (tav_bug != 3)                                         // BUG=3: never passed down
      uvm_config_db#(virtual tav_pipe_if.DRV)::set(this, "drv", "vif", v);
    drv = tav_pipe_driver::type_id::create("drv", this);
  endfunction

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

  // part 1 has no sequencer yet, so the test drives one item straight through the DRV clocking block
  task tav_send(bit [1:0] cf, bit [15:0] d1, bit [15:0] d2, output bit [15:0] o1, output bit [15:0] o2);
    @(drv.vif.drv_cb);
    drv.vif.drv_cb.cf <= cf;  drv.vif.drv_cb.data_in1 <= d1;  drv.vif.drv_cb.data_in2 <= d2;
    drv.vif.drv_cb.enable <= 1;
    @(drv.vif.drv_cb);
    drv.vif.drv_cb.enable <= 0;                               // the design samples the item on this edge
    @(drv.vif.drv_cb);
    o1 = drv.vif.drv_cb.data_out1;  o2 = drv.vif.drv_cb.data_out2;
  endtask

  task run_phase(uvm_phase phase);
    bit [15:0] a1, a2, b1, b2, c1, c2;
    phase.raise_objection(this);
    @(drv.vif.drv_cb); drv.vif.drv_cb.enable <= 0;
    wait (drv.vif.rst_n === 1'b1);
    tav_send(2'b00, 16'h1234, 16'habcd, a1, a2);              // pass
    tav_send(2'b01, 16'h1234, 16'habcd, b1, b2);              // swap
    tav_send(2'b10, 16'h1234, 16'h0001, c1, c2);              // add / sub
    tav_dut_res = $sformatf("%h %h / %h %h / %h %h", a1, a2, b1, b2, c1, c2);
    phase.drop_objection(this);
  endtask

  function void report_phase(uvm_phase phase);
    tav_pipe_item it, cp;
    tav_pipe_item st;
    int rfail, cf3, dbad, outs, ffff;
    bit eq_same, eq_changed;
    string got_vif, got_ffff;
    // 2, 3, 5: 50 random plain items
    it = tav_pipe_item::type_id::create("it");
    repeat (50) begin
      if (!it.randomize()) rfail++;
      if (it.cf == 2'b11) cf3++;
      if (!(it.delay inside {[0:5]})) dbad++;
      if (it.data_out1 != 0 || it.data_out2 != 0) outs++;
    end
    // 4: field macros give copy and compare
    cp = tav_pipe_item::type_id::create("cp");
    cp.copy(it);
    eq_same    = cp.compare(it);
    cp.data_in1 = ~it.data_in1;
    eq_changed = cp.compare(it);
    // 6: the factory swaps in the stress item; count 16'hFFFF on data_in1
    tav_pipe_item::type_id::set_type_override(tav_pipe_stress_item::get_type());
    st = tav_pipe_item::type_id::create("st");
    repeat (50) begin
      void'(st.randomize());
      if (st.data_in1 == 16'hffff) ffff++;
    end
    `uvm_info("TAV_ENV1", $sformatf("stress item: data_in1 was 16'hFFFF in %0d of 50", ffff), UVM_LOW)

    got_vif  = "no";  if (drv.vif != null) got_vif  = "yes";   // no ?: between literals of different length
    got_ffff = "no";  if (ffff >= 25)      got_ffff = "yes";
    tav_check("1 driver got its interface from uvm_config_db", got_vif, "yes");
    tav_check("2 50 random items: randomize failures / cf = 11", $sformatf("%0d / %0d", rfail, cf3), "0 / 0");
    tav_check("3 delay outside 0..5", $sformatf("%0d", dbad), "0");
    tav_check("4 copy compares equal / after a change", $sformatf("%0d / %0d", eq_same, eq_changed), "1 / 0");
    tav_check("5 items with a non-zero output field", $sformatf("%0d", outs), "0");
    tav_check("6 factory type / 16'hFFFF in at least 25 of 50", $sformatf("%s / %s", st.get_type_name(), got_ffff),
              "tav_pipe_stress_item / yes");
    tav_check("7 design through the interface: pass / swap / add-sub", tav_dut_res, "1234 abcd / abcd 1234 / 1235 1233");
    `uvm_info("TAV_ENV1", $sformatf("Checks: %0d pass, %0d fail", tav_pass, tav_fail), UVM_NONE)
  endfunction
endclass

// ---------------------------------------------------------------- top
module tav_top;
  logic clk = 0, rst_n = 0;
  always #5 clk = ~clk;
  initial #22 rst_n = 1;

  tav_pipe_if pif (.clk(clk), .rst_n(rst_n));
  tav_pipe    dut (.clk(clk), .rst_n(rst_n), .i_cf(pif.cf), .i_en(pif.enable),
                   .i_data1(pif.data_in1), .i_data2(pif.data_in2),
                   .o_data1(pif.data_out1), .o_data2(pif.data_out2));
  initial begin
    uvm_config_db#(virtual tav_pipe_if.DRV)::set(null, "tav_top", "vif", pif.DRV);
    run_test("tav_env1_test");
  end
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 with no option, then with each of +BUG=1 to +BUG=4.

What VCS returned

#CheckResult
1Driver got its interface from uvm_config_dbyes
250 random items: randomize failures / cf = 110 / 0
3delay outside 0 to 50
4copy compares equal / after one field changes1 / 0
5Items with a non-zero output field0
6Factory type / 16'hFFFF in at least 25 of 50tav_pipe_stress_item / yes (39 of 50)
7Design through the interface: pass / swap / add-sub1234 abcd / abcd 1234 / 1235 1233

Result: 7 pass, 0 fail. The two MISCMP lines are expected: check 4 changes a field on purpose, and UVM’s comparer reports exactly which field differs.

UVM_INFO @ 0: reporter [RNTST] Running test tav_env1_test...
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_objection.svh(1276) @ 105: 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_comparer.svh(351) @ 105: reporter [MISCMP] Miscompare for cp.data_in1: lhs = 'h9201 : rhs = 'h6dfe
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_comparer.svh(382) @ 105: reporter [MISCMP] 1 Miscompare(s) for object it@415 vs. cp@419
UVM_INFO testbench.sv(218) @ 105: uvm_test_top [TAV_ENV1] stress item: data_in1 was 16'hFFFF in 39 of 50
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 1 driver got its interface from uvm_config_db: yes
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 2 50 random items: randomize failures / cf = 11: 0 / 0
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 3 delay outside 0..5: 0
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 4 copy compares equal / after a change: 1 / 0
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 5 items with a non-zero output field: 0
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 6 factory type / 16'hFFFF in at least 25 of 50: tav_pipe_stress_item / yes
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 7 design through the interface: pass / swap / add-sub: 1234 abcd / abcd 1234 / 1235 1233
UVM_INFO testbench.sv(230) @ 105: uvm_test_top [TAV_ENV1] 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) @ 105: reporter [UVM/REPORT/SERVER] 
--- UVM Report Summary ---

** Report counts by severity
UVM_INFO :   14
UVM_WARNING :    0
UVM_ERROR :    0
UVM_FATAL :    0
** Report counts by id
[MISCMP]     2
[RNTST]     1
[TAV_ENV1]     9
[TEST_DONE]     1
[UVM/RELNOTES]     1
Timing diagram of the three items from check 7. cf is 00, then 01, then 10, with enable sampled high at 35, 65 and 95 ns. The outputs change one clock later: 1234 and abcd at 45 ns for pass, abcd and 1234 at 75 ns for swap, 1235 and 1233 at 105 ns for add and subtract. A red row shows +BUG=2, where data_out1 stays 1234 at 75 ns, with a box explaining the failure
Check 7, edge by edge, and what +BUG=2 changes.

The planted bugs, and why each one failed

+BUG=1: the legal-cf constraint is switched off

UVM_INFO @ 0: reporter [RNTST] Running test tav_env1_test...
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_objection.svh(1276) @ 105: 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_comparer.svh(351) @ 105: reporter [MISCMP] Miscompare for cp.data_in1: lhs = 'h9201 : rhs = 'h6dfe
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_comparer.svh(382) @ 105: reporter [MISCMP] 1 Miscompare(s) for object it@415 vs. cp@419
UVM_INFO testbench.sv(218) @ 105: uvm_test_top [TAV_ENV1] stress item: data_in1 was 16'hFFFF in 39 of 50
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 1 driver got its interface from uvm_config_db: yes
UVM_ERROR testbench.sv(164) @ 105: uvm_test_top [TAV_ENV1] FAIL 2 50 random items: randomize failures / cf = 11: got 0 / 11, expected 0 / 0
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 3 delay outside 0..5: 0
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 4 copy compares equal / after a change: 1 / 0
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 5 items with a non-zero output field: 0
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 6 factory type / 16'hFFFF in at least 25 of 50: tav_pipe_stress_item / yes
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 7 design through the interface: pass / swap / add-sub: 1234 abcd / abcd 1234 / 1235 1233
UVM_INFO testbench.sv(230) @ 105: uvm_test_top [TAV_ENV1] Checks: 6 pass, 1 fail
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_report_server.svh(904) @ 105: reporter [UVM/REPORT/SERVER] 
--- UVM Report Summary ---

** Report counts by severity
UVM_INFO :   13
UVM_WARNING :    0
UVM_ERROR :    1
UVM_FATAL :    0
** Report counts by id
[MISCMP]     2
[RNTST]     1
[TAV_ENV1]     9
[TEST_DONE]     1
[UVM/RELNOTES]     1
  • Why it failed: with c_legal_cf off, the solver may pick any of the four cf values. 11 of 50 items came out as cf = 11, which the design treats as illegal.
  • What it means: a constraint is the only thing standing between your random stimulus and illegal traffic. Check its count, not just that randomize() returned 1.

+BUG=2: the design does not swap

UVM_INFO @ 0: reporter [RNTST] Running test tav_env1_test...
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_objection.svh(1276) @ 105: 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_comparer.svh(351) @ 105: reporter [MISCMP] Miscompare for cp.data_in1: lhs = 'h9201 : rhs = 'h6dfe
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_comparer.svh(382) @ 105: reporter [MISCMP] 1 Miscompare(s) for object it@415 vs. cp@419
UVM_INFO testbench.sv(218) @ 105: uvm_test_top [TAV_ENV1] stress item: data_in1 was 16'hFFFF in 39 of 50
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 1 driver got its interface from uvm_config_db: yes
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 2 50 random items: randomize failures / cf = 11: 0 / 0
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 3 delay outside 0..5: 0
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 4 copy compares equal / after a change: 1 / 0
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 5 items with a non-zero output field: 0
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 6 factory type / 16'hFFFF in at least 25 of 50: tav_pipe_stress_item / yes
UVM_ERROR testbench.sv(164) @ 105: uvm_test_top [TAV_ENV1] FAIL 7 design through the interface: pass / swap / add-sub: got 1234 abcd / 1234 abcd / 1235 1233, expected 1234 abcd / abcd 1234 / 1235 1233
UVM_INFO testbench.sv(230) @ 105: uvm_test_top [TAV_ENV1] Checks: 6 pass, 1 fail
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_report_server.svh(904) @ 105: reporter [UVM/REPORT/SERVER] 
--- UVM Report Summary ---

** Report counts by severity
UVM_INFO :   13
UVM_WARNING :    0
UVM_ERROR :    1
UVM_FATAL :    0
** Report counts by id
[MISCMP]     2
[RNTST]     1
[TAV_ENV1]     9
[TEST_DONE]     1
[UVM/RELNOTES]     1
  • Why it failed: at 65 ns the design sampled cf = 01 with 1234 / abcd, but produced 1234 / abcd again. The diagram above shows the red row.
  • What it means: this is a real design bug, and the interface plus a directed item was enough to expose it. In part 3 the scoreboard will catch it on every random item.

+BUG=3: the interface never reaches the driver

Flow of uvm_config_db calls: tav_top sets the interface, the test gets it, the test sets it for drv, and the driver gets it in build_phase. +BUG=3 skips the test's set, so the driver finds nothing and stops at 0 ns with UVM_FATAL TAV_NOVIF
Four config_db calls; +BUG=3 removes the third.
UVM_INFO @ 0: reporter [RNTST] Running test tav_env1_test...
UVM_FATAL testbench.sv(131) @ 0: uvm_test_top.drv [TAV_NOVIF] no virtual interface set for uvm_test_top.drv.vif
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_report_server.svh(904) @ 0: reporter [UVM/REPORT/SERVER] 
--- UVM Report Summary ---

** Report counts by severity
UVM_INFO :    2
UVM_WARNING :    0
UVM_ERROR :    0
UVM_FATAL :    1
** Report counts by id
[RNTST]     1
[TAV_NOVIF]     1
[UVM/RELNOTES]     1
  • Why it failed: the driver asked for "vif" at its own path, uvm_test_top.drv, and nobody had set it there.
  • Why the fatal matters: the run stopped at 0 ns with a message naming the exact path. Without that check, the driver would hit a null handle much later, with a far less useful error.

+BUG=4: := instead of :/ in the stress item

Bar chart of how often data_in1 was 16'hFFFF in 50 stress items: 39 of 50 with :/ 1 on the range, and 0 of 50 with := 1, which the previous version of this post used. A box explains that := gives every value in the range weight 1
One character, 39 hits versus 0.
UVM_INFO @ 0: reporter [RNTST] Running test tav_env1_test...
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_objection.svh(1276) @ 105: 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_comparer.svh(351) @ 105: reporter [MISCMP] Miscompare for cp.data_in1: lhs = 'h9201 : rhs = 'h6dfe
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_comparer.svh(382) @ 105: reporter [MISCMP] 1 Miscompare(s) for object it@415 vs. cp@419
UVM_INFO testbench.sv(218) @ 105: uvm_test_top [TAV_ENV1] stress item: data_in1 was 16'hFFFF in 0 of 50
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 1 driver got its interface from uvm_config_db: yes
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 2 50 random items: randomize failures / cf = 11: 0 / 0
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 3 delay outside 0..5: 0
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 4 copy compares equal / after a change: 1 / 0
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 5 items with a non-zero output field: 0
UVM_ERROR testbench.sv(164) @ 105: uvm_test_top [TAV_ENV1] FAIL 6 factory type / 16'hFFFF in at least 25 of 50: got tav_pipe_stress_item / no, expected tav_pipe_stress_item / yes
UVM_INFO testbench.sv(160) @ 105: uvm_test_top [TAV_ENV1] PASS 7 design through the interface: pass / swap / add-sub: 1234 abcd / abcd 1234 / 1235 1233
UVM_INFO testbench.sv(230) @ 105: uvm_test_top [TAV_ENV1] Checks: 6 pass, 1 fail
UVM_INFO /apps/vcsmx/vcs/X-2025.06-SP1//etc/uvm-1.2/src/base/uvm_report_server.svh(904) @ 105: reporter [UVM/REPORT/SERVER] 
--- UVM Report Summary ---

** Report counts by severity
UVM_INFO :   13
UVM_WARNING :    0
UVM_ERROR :    1
UVM_FATAL :    0
** Report counts by id
[MISCMP]     2
[RNTST]     1
[TAV_ENV1]     9
[TEST_DONE]     1
[UVM/RELNOTES]     1
  • Why it failed: [0:16'hFFFE] := 1 gives each of the 65,535 values weight 1, so 16'hFFFF (weight 3) almost never wins. It came up 0 times in 50.
  • The fix: :/ 1 shares the weight 1 across the whole range, so 16'hFFFF gets 3 parts in 4. It came up 39 times in 50.
  • A correction: the previous version of this post used := here, with a comment saying it pushed toward 16'hFFFF. It did the opposite.

The lesson: each layer can be wrong on its own, so test each one before you stack the next. A constraint, a dist weight or a missing config_db call is much easier to find now than inside a full environment.

Common mistakes at this stage

MistakeWhat you seeFix
Making output fields randThe checker compares against random valuesKeep outputs non-rand; the monitor fills them
Forgetting the field macrosprint, copy, compare do nothing usefulAdd `uvm_field_* for every field
:= on a range in a distThe corner value almost never appears (+BUG=4)Use :/ for a range
No fatal on the config_db getA null handle error far from the cause`uvm_fatal with the path (+BUG=3)
Driving without a clocking blockRaces between the driver and the designDrive through drv_cb
A monitor using the driver’s modportThe monitor can drive a pin by mistakeGive the monitor MON

How AI helps you master this

  • From spec to interface: paste a port list and ask for an interface with a clocking block and modports, then check every direction yourself.
  • Review a transaction: paste your item and ask which fields should not be rand and which constraints are missing.
  • Check a dist: paste a dist and ask for the expected share of each value, then measure it like check 6.

Warning: a convincing AI answer is not the same as a correct engineering result. The := bug above sat in a published post with a confident comment next to it, so measure it.

Interview questions on these layers

  • Why use a clocking block in the interface? It sets when the testbench drives and samples relative to the clock, which removes races with the design.
  • Why are modports useful? They give each user a direction, so a monitor cannot drive a pin.
  • Which transaction fields should be rand? The stimulus fields. Values produced by the design are filled in by the monitor.
  • What is the difference between := and :/ in a dist? := gives each value in a range the weight; :/ shares the weight across the range.
  • How does the driver get the interface? From uvm_config_db in build_phase, with a fatal if it is missing.

More practice: UVM interview questions.

Practice challenge

  1. Run the simple example and confirm cf never comes out as 3.
  2. Run the bench with +BUG=4, then change the weight to :/ 3. What share of 16'hFFFF do you expect?
  3. Add a cf = 11 item to run_phase. What does the design return?
  4. Bonus: give the stress item a constraint that makes cf always 10, and check it the way check 2 does.

FAQ

What are the steps to build a UVM environment? Describe the design, write the interface, build the transaction, then the driver and sequencer (part 2), the monitor, agent, scoreboard and environment (part 3), and finally the test (part 4).

Why put a clocking block in the interface? It fixes when signals are driven and sampled relative to the clock, so the testbench and the design do not race.

Should transaction output fields be randomized? No. They come from the design and are filled in by the monitor.

What does `uvm_field_int do? It registers a field so print, copy and compare include it.

Why does my driver stop with “no virtual interface set”? Nothing set "vif" for its path in uvm_config_db. Check the path in the set call, as in +BUG=3.

References

  • IEEE 1800-2023, SystemVerilog standard: interfaces, clocking blocks, modports, constraints and dist.
  • IEEE 1800.2-2020, UVM standard, and the Accellera UVM 1.2 Class Reference: uvm_sequence_item, field macros, uvm_config_db.

Keep learning

2 Comments

  1. good work Hardik, and The Art of Verification team.
    you have narrate UVM. very well and its sound like beginner can pick up easy.

Comments are closed.