Skip to main content...
S3 · Verification Engineering (SV + UVM)
30 min

Day 97: SystemVerilog for verification: classes and OOP basics

SystemVerilog adds full object-orientation for testbenches. Classes, inheritance, and polymorphism are the vocabulary UVM is built on.

SystemVerilog for verification: OOP

Testbenches need abstraction that synthesizable RTL lacks. SystemVerilog adds a full object-oriented layer: classes (with data + methods), inheritance (extends), polymorphism (virtual methods), and dynamic objects on the heap. A transaction becomes a class; a driver, monitor, and scoreboard become classes. This OOP layer is non-synthesizable — it exists purely to build reusable, scalable verification.

A transaction class and a base component
class uart_txn;
    rand bit [7:0] data;      // randomizable field
    rand bit       parity_err;
    constraint c_par { parity_err dist { 0 := 95, 1 := 5 }; } // mostly good
    function void print();
        $display("uart_txn data=%h perr=%b", data, parity_err);
    endfunction
endclass

class base_driver;
    virtual function void run();  endfunction   // overridden by children
endclass

class uart_driver extends base_driver;
    virtual function void run();  /* drive the DUT */  endfunction
endclass

Why OOP for testbenches

A transaction as a *class* can be randomized, copied, printed, and passed between components generically. Inheritance lets a base testbench be specialized per DUT without rewriting it. This reuse is the entire reason UVM (a class library) exists — and why DV engineers write more class code than RTL.

Key terms

Class
A SystemVerilog object type bundling data and methods; the unit of testbench abstraction.
Inheritance (extends)
Deriving a specialized class from a base, reusing and overriding its behavior.
Virtual method / polymorphism
A method a subclass can override, called through a base handle at run time.
Transaction
A class representing one unit of stimulus/observation (e.g. a bus transfer).

Before moving on, you should be able to

Why does SystemVerilog add classes and inheritance, which have no synthesizable meaning?

We use cookies

We use cookies to enhance your browsing experience, serve personalized content, and analyze our traffic. By clicking "Accept All", you consent to our use of cookies. Learn more

    Day 97: SystemVerilog for verification: classes and OOP basics | RBTechIconX