techmore.in

Verilog Coverage

Coverage in Verilog is a critical aspect of verification that ensures your design is thoroughly tested and all possible scenarios are evaluated. It helps identify which parts of the design have been exercised during simulation and which parts need more testing. Coverage can be categorized into different types, each focusing on different aspects of the design.

Types of Coverage

  1. Code Coverage: Measures how much of the design's code has been exercised.
  2. Functional Coverage: Measures whether specific functionalities or behaviors have been tested.
  3. Assertion Coverage: Measures whether assertions have been triggered.

Code Coverage

Code coverage evaluates which parts of the Verilog code (e.g., lines, branches) are executed during simulation.

Types of Code Coverage:

  • Line Coverage: Checks if each line of code has been executed.
  • Branch Coverage: Checks if all possible branches of conditional statements (if, case) have been taken.
  • Expression Coverage: Checks if all possible values of expressions have been evaluated.

Example:

For a simple state machine, code coverage would ensure that all states and transitions are tested.

verilog
module simple_fsm( input clk, input rst, input in, output reg out ); typedef enum reg [1:0] { S0 = 2'b00, S1 = 2'b01, S2 = 2'b10 } state_t; state_t state, next_state; always @(posedge clk or posedge rst) begin if (rst) state <= S0; else state <= next_state; end always @(*) begin case (state) S0: next_state = in ? S1 : S0; S1: next_state = in ? S2 : S0; S2: next_state = in ? S0 : S1; default: next_state = S0; endcase end always @(*) begin out = (state == S2); end endmodule

Functional Coverage

Functional coverage checks if specific functionalities, scenarios, or conditions have been tested. It is defined using coverage points and bins.

Syntax:

verilog
covergroup <group_name>; coverpoint <signal_or_expression> { bins <bin_name> = <expression>; // Additional bin definitions } // Additional coverpoints endgroup

Example:

For the state machine, functional coverage might involve checking if each state and transition has occurred.

verilog
module test; reg clk, rst, in; wire out; // Instantiate the FSM simple_fsm fsm ( .clk(clk), .rst(rst), .in(in), .out(out) ); // Coverage group definition covergroup fsm_covergroup; coverpoint fsm.state { bins S0 = {2'b00}; bins S1 = {2'b01}; bins S2 = {2'b10}; } coverpoint fsm.next_state; endgroup fsm_covergroup fsm_cov; initial begin clk = 0; rst = 1; in = 0; #10 rst = 0; #10 in = 1; #10 in = 0; #10 in = 1; end always #5 clk = ~clk; endmodule

Assertion Coverage

Assertion coverage measures whether assertions (used to check properties or conditions) have been triggered during simulation. This helps verify that the assertions are meaningful and that the design behaves as expected.

Example:

verilog
module test; reg clk, rst, in; wire out; // Instantiate the FSM simple_fsm fsm ( .clk(clk), .rst(rst), .in(in), .out(out) ); // Assertions property p_check_state; @(posedge clk) (fsm.state == 2'b00) |-> (fsm.out == 1'b0); endproperty assert property (p_check_state); initial begin clk = 0; rst = 1; in = 0; #10 rst = 0; #10 in = 1; #10 in = 0; #10 in = 1; end always #5 clk = ~clk; endmodule

Coverage Tools

Various EDA (Electronic Design Automation) tools support coverage analysis, including:

  • Synopsys VCS
  • Cadence Xcelium
  • Mentor Graphics Questa

These tools provide comprehensive coverage metrics and reports, helping you identify untested code and ensure thorough verification.

Summary

Coverage in Verilog helps ensure your design is thoroughly tested by measuring how much of the code, functionalities, and assertions have been exercised during simulation. By using code coverage, functional coverage, and assertion coverage, you can identify gaps in testing and improve the reliability of your design.