Moving from a Layered Testbench to UVM Concepts
Build a complete environment and connect its phases, configuration, callbacks, and component creation to the mechanisms that UVM standardizes.
Chargement…
Build a complete environment and connect its phases, configuration, callbacks, and component creation to the mechanisms that UVM standardizes.
UVM provides a SystemVerilog library for building reusable verification environments. Responsibilities remain those of the layered bench: drive, observe, predict, compare, and measure.
| Course SystemVerilog environment | Mechanism standardized by UVM |
|---|---|
| transaction and copy method | data object with common copy and representation operations |
| driver, monitor, scoreboard, environment, test | components in a named hierarchy |
build(), run(), wrap_up() | teaching subset of a richer phase mechanism |
| virtual interfaces passed to classes | configuration resource delivered to the appropriate component |
| callback calls | registered extension points that avoid deriving an entire driver |
| monitor publication to several consumers | transaction-level communication to scoreboard and coverage |
| selecting a derived class at construction | factory and type override |
UVM standardizes hierarchy, configuration, phases, creation, and communication. The plan, oracle, and protocol rules still need to be written. Sequences, sequencers, and objections require the selected version's exact API.
Construction, execution, and reporting are useful concepts, but not the complete UVM phase list. Reset consumes time and belongs in a timed phase rather than construction.
This is a layered SystemVerilog bench without UVM library calls. It includes the DUT, transactions, drivers and monitors, reference, scoreboard, coverage, timeout, and verdict.
The DUT accepts two bytes on in_valid && in_ready and updates their nine-bit sum with out_valid after that edge. It provides one ordered response per command without output backpressure.
// sum_if.sv
interface sum_if(input logic clk);
timeunit 1ns;
timeprecision 1ps;
logic rst_n = 1'b0;
logic in_valid = 1'b0;
logic in_ready;
logic [7:0] a = '0;
logic [7:0] b = '0;
logic out_valid;
logic [8:0] sum;
clocking drv_cb @(posedge clk);
default input #1step output #0;
output
// sum_dut.sv
module sum_dut(sum_if.dut bus);
timeunit 1ns;
timeprecision 1ps;
assign bus.in_ready = 1'b1;
always_ff @(posedge bus.clk or negedge bus.rst_n) begin
if (!bus.rst_n) begin
bus.out_valid <= 1'b0;
bus.sum <= '0;
end
else begin
bus.out_valid <= bus.in_valid && bus.in_ready;
if (bus.in_valid && bus.in_ready)
bus.sum <= {1'b0, bus.a} + {1'b0, bus.b};
Both testbench views use clocking blocks. Monitors sample just before each edge, so they see the previous edge's registered result at the next edge.
// sum_tb_pkg.sv - compile after sum_if.sv
package sum_tb_pkg;
timeunit 1ns;
timeprecision 1ps;
typedef virtual sum_if.drv sum_drv_vif_t;
typedef virtual sum_if.mon sum_mon_vif_t;
class sum_item;
randc logic [7:0] a;
rand logic [7:0] b;
rand int unsigned idle_cycles;
logic [8:0] sum;
constraint legal_idle { idle_cycles inside {[0:3]}; }
function sum_item copy();
sum_item result;
result
The generator randomizes its blueprint and sends a copy. The input monitor sends separate copies to reference and coverage: two consumers must not compete to remove the same transaction from one mailbox.
The reference independently adds accepted operands. The scoreboard compares ordered responses with separate counts. Coverage measures observed operands without deciding correctness.
// Continuation of sum_tb_pkg.sv, before endpackage
class sum_environment;
sum_drv_vif_t drv_vif;
sum_mon_vif_t mon_vif;
sum_config cfg;
mailbox #(sum_item) generated_mb;
mailbox #(sum_item) accepted_for_model_mb;
mailbox #(sum_item) accepted_for_coverage_mb;
mailbox #(sum_item) expected_mb;
mailbox #(sum_item) actual_mb;
sum_generator generator;
sum_driver driver;
sum_input_monitor input_monitor;
sum_output_monitor output_monitor;
sum_reference_model reference_model;
sum_scoreboard scoreboard;
sum_coverage coverage;
function new(sum_drv_vif_t drv_vif,
sum_mon_vif_t mon_vif,
sum_config cfg);
this
// tb_top.sv - compile last
program automatic sum_test_program(sum_if.drv drv_bus,
sum_if.mon mon_bus);
timeunit 1ns;
timeprecision 1ps;
import sum_tb_pkg::*;
initial begin
sum_test test;
test = new(drv_bus, mon_bus);
test.run();
$finish;
end
endprogram
module tb_top;
timeunit 1ns;
timeprecision 1ps;
logic clk = 1'b0;
always #5ns clk = ~clk;
The two package blocks together form sum_tb_pkg.sv. Compile sum_if.sv, that package, sum_dut.sv, then tb_top.sv with a simulator supporting classes, mailboxes, virtual interfaces, and covergroups.
build() creates and connects without consuming time. Reset is a separate task. run() waits for comparisons, including failures, then allows two drain cycles; the watchdog catches missing responses. wrap_up() checks counts and leftovers.
PASS validates this run's comparisons. Coverage may still require further scenarios.
| Executable element | Responsibility preserved during migration |
|---|---|
sum_item | copyable and randomizable transaction object |
sum_generator | scenario production; UVM then separates sequence and arbitration |
sum_driver | transaction-to-signal conversion through a virtual interface |
| monitors | passive observation and publication of accepted transactions |
sum_reference_model | prediction independent of the RTL |
sum_scoreboard | matching, comparison, leftovers, and verdict |
sum_coverage | separate measurement triggered after real observation |
sum_environment | construction, connection, execution, draining, and reporting |
sum_test | scenario, configuration, and extension selection |
Configuration supplies virtual interfaces, transaction counts, timeouts, and modes within the intended scope. Check required retrievals immediately: an incorrect name, type, or modport should produce a clear diagnostic.
Constructors are not virtual. A factory chooses concrete types at replaceable creation points:
driver_t driver;
driver = driver_t::type_id::create("driver", this);After registration and override, the environment can keep a base handle to a derived object. Virtual methods select its behavior. Objects created directly with new bypass factory substitution.
A callback may modify a transaction before transmission. After observed acceptance, publish stable transactions to reference and coverage, or give copies to subscribers that modify them. Do not predict from an object the DUT never received.
The test chooses configuration, constraints, overrides, and callbacks rather than copying shared components.
Start with a self-checking bench, stabilize interface timing, then separate components and draining. Centralize configuration and add useful extensions before adopting actual UVM classes and phases.
At each step, test the bench itself: replacing addition with subtraction should produce FAIL, removing a response TIMEOUT, and adding a response a count or leftover failure. A sophisticated bench that accepts an incorrect DUT is insufficient.
UVM helps when interfaces, teams, or integration levels multiply. For a small block, chapter 12's bench may remain easier to maintain.
📝 Test your knowledge - Chapter quiz