SystemVerilog interface, modport and clocking block
Understand how interfaces bundle signals, modports define viewpoints, and clocking blocks prevent testbench sampling and driving races.
Interface: shared connectivity
An interface bundles related signals and can contain tasks, functions, assertions and clocking blocks. It reduces repetitive port wiring between the DUT and testbench.
interface bus_if(input logic clk);
logic valid, ready;
logic [7:0] data;
endinterface
Instantiate the interface once and pass it to modules instead of connecting every signal independently.
Modport: a viewpoint
A modport declares which interface members a particular user may read, drive or import. Directions are relative to the component using the modport.
modport dut (input valid, data, output ready);
modport tb (output valid, data, input ready);
Modports improve checking and document roles, but they do not create signals or timing behavior.
Clocking block: timing discipline
A clocking block defines when the testbench samples inputs and drives outputs relative to a clock event.
clocking cb @(posedge clk);
default input #1step output #0;
output valid, data;
input ready;
endclocking
The monitor reads cb.ready, and the driver writes cb.valid and cb.data. Sampling before the active edge and driving in a defined region avoids races with DUT sequential logic. Select skews that match the verification methodology; do not copy values without understanding their event-region meaning.
Class-based components normally receive a virtual interface handle through configuration. Check that the handle is non-null before use, and keep driver and monitor access aligned with their intended modports or clocking blocks.