Skip to main content

SystemVerilog: Covergroups and Coverage

· loading · loading · ·
Course Verification SystemVerilog SystemVerilog Covergroup Coverage Verification
Course Verification SystemVerilog
Axolot Logic
Author
Axolot Logic
Digital Design Engineer
Table of Contents
SystemVerilog Design Series - This article is part of a series.
Part 30: This Article

🧩 SystemVerilog: Covergroups and Coverage
#

This section explores covergroups and coverage modeling in SystemVerilog—essential for ensuring thorough verification. We’ll discuss structural vs. functional coverage, coverpoints, bins, crosses, integrating covergroups into classes, and how to print and analyze coverage results.


1️⃣ Structural vs. Functional Coverage
#

Structural Coverage

  • Measures coverage of HDL constructs (e.g., statements, branches).
  • Typically reported by simulators automatically.

Functional Coverage

  • Measures how thoroughly the design has been exercised from a functional perspective.
  • Implemented using covergroups and coverpoints.

2️⃣ Data-Oriented vs. Control-Oriented Functional Coverage
#

Functional coverage can be:

  • Data-Oriented: Focuses on different data values (e.g., all valid opcodes).
  • Control-Oriented: Focuses on design states, conditions, and transitions (e.g., protocol states).

3️⃣ What Is a Covergroup?
#

A covergroup is a SystemVerilog construct used to define functional coverage. It contains one or more coverpoints that specify what to measure.

Example:

covergroup cg @(posedge clk);
  coverpoint opcode;
endgroup

4️⃣ Coverpoints and Bins
#

A coverpoint specifies a variable or expression to be covered. By default, SystemVerilog automatically creates bins for each possible value (depending on the type).

  • Implicit Bins: Automatically created bins for each possible value.
  • Explicit Bins: User-defined bins for ranges or specific values.

Example:

covergroup cg @(posedge clk);
  coverpoint opcode {
    bins ALU = {4'h0, 4'h1};
    bins BRANCH = {4'h2, 4'h3};
  }
endgroup

5️⃣ Cover Crosses
#

A cross combines two or more coverpoints to measure all possible value combinations.

Example:

covergroup cg @(posedge clk);
  coverpoint opcode;
  coverpoint state;
  cross opcode, state;
endgroup
  • Implicit Cross Bins: Automatically created for all combinations.
  • Illegal and Ignore Bins: Used to mark invalid or uninteresting combinations.

Example:

cross opcode, state {
  illegal_bins invalid = binsof(opcode) intersect {4'hF};
}

6️⃣ Using Covergroups in Classes
#

Covergroups can be declared inside classes and constructed at runtime. This is essential for object-oriented testbench architectures.

Example:

class Transaction;
  rand bit [3:0] opcode;
  covergroup cg @(posedge clk);
    coverpoint opcode;
  endgroup

  function new();
    cg = new();
  endfunction
endclass

In this example, the covergroup is tied to each transaction, allowing per-instance coverage collection.


7️⃣ Printing and Analyzing Coverage
#

✅ After running the simulation, you can print and analyze the collected coverage using simulator commands or SystemVerilog functions.

Printing Coverage in the Simulator Console:

initial begin
  $display("Coverage = %0.2f%%", $get_coverage());
end

This prints the overall coverage percentage to the simulator console.

Detailed Coverage Report:

  • Most simulators provide coverage analysis tools (e.g., HTML reports) that detail covergroups, coverpoints, bins, and cross coverage.
  • These reports help identify untested cases and improve testbench quality.

Interpreting Coverage:

  • 100% coverage means all defined bins and cross bins have been hit.
  • Less than 100% indicates scenarios that haven’t been exercised—review the testbench and design to improve coverage.

📖 Conclusion
#

Covergroups and coverage modeling are essential for verifying that a design has been thoroughly exercised. Understanding coverpoints, bins, crosses, printing, and analysis helps build robust testbenches that catch corner cases and ensure compliance.


SystemVerilog Design Series - This article is part of a series.
Part 30: This Article

Related

Advanced OOP in SystemVerilog: Aggregation, Inheritance, and More
· loading · loading
Course Verification SystemVerilog SystemVerilog OOP Object-Oriented Programming Verification Classes
Course Verification SystemVerilog
Advanced OOP in SystemVerilog: Constructors, Handles, and Static Members
· loading · loading
Course Verification SystemVerilog SystemVerilog OOP Object-Oriented Programming Verification Classes
Course Verification SystemVerilog
Mailboxes in SystemVerilog
· loading · loading
Course Verification SystemVerilog SystemVerilog IPC Mailboxes Verification Synchronization
Course Verification SystemVerilog
Named Events in SystemVerilog
· loading · loading
Course Verification SystemVerilog SystemVerilog IPC Named Events Verification Synchronization
Course Verification SystemVerilog
Object-Oriented Programming in SystemVerilog
· loading · loading
Course Verification SystemVerilog SystemVerilog OOP Object-Oriented Programming Verification Classes
Course Verification SystemVerilog
Polymorphism and Virtuality in SystemVerilog
· loading · loading
Course Verification SystemVerilog SystemVerilog OOP Object-Oriented Programming Verification Virtuality
Course Verification SystemVerilog