What you practice
virtual interface (2.6). Connect verification classes to hardware instances using virtual interfaces. It is in Classes & OOP Basics — Part 2 · Verification & OOP of the SystemVerilog Masterclass. Software-side verification: dynamic data structures, classes, and the first UVM master keys.
The same IDE is the SystemVerilog simulator. Slang lints the file, Verilator runs it, and the waveform viewer sits next to the source.
What you will learn
Today you will learn how to connect software verification classes to hardware design instances using virtual interfaces in SystemVerilog.
Learning objectives
- Understand why virtual interfaces are needed to decouple testbench classes from physical interface instances.
- Declare and use a
virtual interfacehandle in a class. - Drive DUT signals through the virtual interface from a class method.
Theory
Virtual interfaces solve a key problem: classes cannot directly reference physical interface instances (which are elaborated at compile time), yet classes need to access interface signals for stimulus generation.
A *virtual interface* is a handle (pointer) to a physical interface instance. It is declared in a class as virtual dut_if vif; and assigned during class construction using the physical interface instance.
| Concept | Description |
|---|---|
interface | A hardware container grouping signals and timing (e.g., dut_if) |
virtual interface | A class-side handle to an interface instance; enables OOP-driven stimulus |
| Assignment | Done in class constructor: function new(virtual dut_if vif); this.vif = vif; endfunction |
This pattern is essential for reusable, scalable verification environments (e.g., UVM), where drivers, monitors, and scoreboards operate via virtual interfaces.
Practice
- Open this chapter in RtlStudio — all files appear automatically in Explore.
- In Explore, open
student/tb/tb.sv. - Locate the line where the
Driverclass is instantiated:driver = new(__TODO__). - Replace
__TODO__with the physical interface instance name to connect the virtual interface handle to the hardware. - Run Simulation from the left sidebar and read the Log panel.
- Verify the expected
INFO:messages appear and the simulation ends withINFO: PASS.
Summary
You practiced connecting a physical interface instance to a virtual interface handle inside a verification class. This allows software-based testbench components to interact with hardware design instances without hardwiring module-level connections. The key takeaway is that virtual interfaces decouple testbench classes from specific hardware instantiations, enabling flexible and reusable verification environments. You successfully passed the interface reference from top-level testbench to a Driver class, demonstrating standard OOP integration with hardware.
Run it in the Verilog IDE
- Open the lesson in the IDE. The SystemVerilog for this topic is already in the editor.
- Lint with Slang before you simulate. It covers both Verilog and SystemVerilog in this IDE.
- Run Verilator and inspect the VCD. Interfaces, classes, and assertions count only if the simulator agrees.
- Run Yosys when the lesson is synthesizable RTL, and keep testbench-only constructs out of that module.
The lesson is done when the simulation matches virtual interface. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.