Toward a UVM-Ready Testbench
Section 6.1 defined the core components of a hardware testbench: stimulus generation, DUT instantiation, output monitoring, and checking. This article maps those four responsibilities into reusable SystemVerilog classes: drivers, monitors, and scoreboards. This component structure establishes the foundation of the industry-standard Universal Verification Methodology (UVM).
Component Responsibilities
The following table compares procedural Verilog testbench blocks with their class-based equivalents:
| Procedural Structure (Module 6) | Object-Oriented Architecture | Functional Responsibility |
|---|---|---|
| Stimulus generation blocks | Transaction generator | Creates randomized, constrained transaction objects. |
| DUT port driving | Driver class | Translates high-level transaction fields into pin-level signal toggles. |
| Output sampling logic | Monitor class | Observes interface pins passively and reconstructs transactions. |
| Self-checking tasks | Scoreboard class | Compares observed transactions against a reference model. |
The Driver Component
A driver converts abstract transactions into physical pin transitions.
It accesses hardware signals through a virtual interface (virtual interface_name):
class alu_driver;
virtual alu_if vif; // Virtual interface handle connects class to hardware nets
task automatic drive(alu_transaction txn);
vif.a <= txn.operand_a;
vif.b <= txn.operand_b;
vif.op <= txn.opcode;
@(posedge vif.clk);
endtask
endclass
A virtual interface acts as a reference pointer from the dynamic class environment to static module signals. Every verification class that drives or samples hardware nets requires a virtual interface handle.
The Monitor Component
The monitor observes interface pins passively without driving stimulus:
class alu_monitor;
virtual alu_if vif;
task automatic collect(output alu_transaction txn);
txn = new();
@(posedge vif.clk);
txn.operand_a = vif.a;
txn.operand_b = vif.b;
txn.opcode = vif.op;
txn.expected_result = vif.result; // Capture physical DUT response
endtask
endclass
The monitor samples bus activity on clock edges and packages observed data into transaction objects. It forwards these transactions to the scoreboard for validation.
The Scoreboard Component
The scoreboard evaluates circuit correctness against a golden behavioral reference model:
class alu_scoreboard;
int pass_count = 0, fail_count = 0;
function void check(alu_transaction txn);
bit [7:0] golden_result = compute_expected(txn.operand_a, txn.operand_b, txn.opcode);
if (txn.expected_result == golden_result) begin
pass_count++;
end else begin
fail_count++;
$display("FAIL: op=%b a=%h b=%h got=%h expected=%h",
txn.opcode, txn.operand_a, txn.operand_b,
txn.expected_result, golden_result);
end
endfunction
function bit [7:0] compute_expected(bit [7:0] a, b, bit [2:0] op);
case (op)
3'b000: compute_expected = a + b;
3'b001: compute_expected = a - b;
default: compute_expected = 8'h00;
endcase
endfunction
endclass
The scoreboard tracks cumulative pass and fail counts to report overall testbench status.
Assembling the Testbench
Connect the driver, monitor, scoreboard, and DUT inside the top-level testbench module:
module tb_alu_top;
alu_if vif();
alu dut (.a(vif.a), .b(vif.b), .op(vif.op), .result(vif.result), .clk(vif.clk));
initial begin
alu_driver drv = new();
alu_monitor mon = new();
alu_scoreboard sb = new();
alu_transaction stim_txn, observed_txn;
drv.vif = vif;
mon.vif = vif;
repeat (1000) begin
stim_txn = new();
if (!stim_txn.randomize()) $fatal(1, "Randomization error");
drv.drive(stim_txn);
mon.collect(observed_txn);
sb.check(observed_txn);
end
$display("Final Results: %0d passed, %0d failed", sb.pass_count, sb.fail_count);
$finish;
end
endmodule
This architecture executes one thousand randomized transactions systematically. Separating stimulus generation, physical driving, monitoring, and scoring ensures code reusability.
Practice Exercise
Explain why verification engineers should never implement scoreboard pass/fail checks inside a driver class.
Solution
A driver must only translate transaction fields into physical pin transitions. Combining output checking inside the driver violates the separation of concerns principle. Drivers are active masters, whereas monitors and scoreboards are passive observers. If you embed checking logic inside a driver, you cannot reuse that driver in multi-agent environments or passive verification taps. Decoupling components allows engineers to reuse identical drivers across different testbenches with specialized scoreboards.
Class-based verification separates testbench responsibilities into drivers, monitors, and scoreboards. Virtual interfaces bridge dynamic software objects to static hardware nets. This structured separation forms the direct architectural foundation of modern UVM testbenches. The next section introduces SystemVerilog Assertions (SVA) to monitor protocol rules continuously.