RTL Studio Open IDE

3.7 · SYSTEMVERILOG CLASS

functional coverage (manual bins, Verilator)

Implement manual functional coverage with explicit bin comparisons in a Verilator-safe testbench.

Watch on YouTube

What you practice

functional coverage (manual bins, Verilator) (3.7). Implement manual functional coverage with explicit bin comparisons in a Verilator-safe testbench. It is in Constraint Random Verification — Part 3 · Advanced SV & Mini-UVM of the SystemVerilog Masterclass. Timing, concurrency, constrained-random verification, assertions, and a pure-SV Mini-UVM environment.

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

You will learn how to implement functional coverage manually using explicit bin comparisons in a Verilator-compatible testbench, since full SystemVerilog covergroups are not supported in this flow.

Learning objectives

  • Understand why manual bin coverage is needed when covergroups are unavailable.
  • Implement a record_coverage task with two upper-bound comparisons to define three bins.
  • Drive stimulus to ensure coverage of low, mid, and high value ranges.
  • Interpret simulation logs to verify bin coverage.

Theory

Functional coverage measures how well test stimulus exercises design behavior. In simulators that support SystemVerilog covergroups, coverage is automatic. However, Verilator does not simulate covergroups in this flow, so coverage must be implemented manually using conditional logic.

Bin RangeDescriptionUpper Bound
low0 ≤ val < 6464
mid64 ≤ val < 192192
high192 ≤ val ≤ 255—

The record_coverage task uses two if/else if comparisons with upper bounds to classify the sampled value. Flags (hit_low, hit_mid, hit_high) track which bins were visited. After stimulus, the testbench checks all flags to confirm full coverage.

Practice

Open RtlStudio and select this chapter. Files appear automatically in Explore.

  1. Open student/tb/tb.sv in the editor.
  2. Locate the record_coverage task.
  3. Replace the two __TODO__ placeholders with the correct upper-bound constants (64 and 192) to define the low and mid bins.
  4. Run Simulation and check the Log panel for INFO messages.
  5. Confirm all three bins are hit and the test ends with INFO: PASS.

Summary

You practiced manual functional coverage by defining explicit bins for data_out using Verilator-compatible constructs and sampling logic. You implemented record_coverage(data_out) with three bins—low, mid, and high—using two upper-bound comparisons to categorize values. You drove data_in to ensure data_out visited each bin, validating coverage collection without relying on covergroup. This approach provides a practical, simulator-independent way to track functional coverage in Verilator-based flows.

Run it in the Verilog IDE

  1. Open the lesson in the IDE. The SystemVerilog for this topic is already in the editor.
  2. Lint with Slang before you simulate. It covers both Verilog and SystemVerilog in this IDE.
  3. Run Verilator and inspect the VCD. Interfaces, classes, and assertions count only if the simulator agrees.
  4. 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 functional coverage (manual bins, Verilator). Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.