Tutorials

Learn More

The covergroup provides a set of coverage methods as follows.

Methos (functions)

Description

Can be called on

void sample

Triggers covergroup sampling

covergroup

void start

Starts collecting coverage information

covergroup, coverpoint, cross

void stop

Stops collecting coverage information

covergroup, coverpoint, cross

void set_inst_name

Sets instance name to the given string

covergroup

real get_coverage

Returns cumulative or type coverage of all instances of coverage item.

covergroup, coverpoint, cross

real get_inst_coverage

Returns specific instance coverage on which it is called.

covergroup, coverpoint, cross

Coverage Methods Example

module func_coverage;
  bit [7:0] addr, data;
  covergroup c_group;
    cp1: coverpoint addr;
    cp2: coverpoint data;
    cp1_X_cp2: cross cp1, cp2;
  endgroup : c_group

  c_group cg = new();
  
  initial begin
    cg.start();
    cg.set_inst_name("my_cg");
    
    forever begin
      cg.sample();
      #5;
    end
  end
  
  initial begin
    $monitor("At time = %0t: addr = %0d, data = %0d", $time, addr, data);
    repeat(5) begin
      addr = $random;
      data = $random;
      #5;
    end
    cg.stop();
    $display("Coverage = %f", cg.get_coverage());
    $finish;
  end
  
endmodule

Output:

At time = 0: addr = 36, data = 129
At time = 5: addr = 9, data = 99
At time = 10: addr = 13, data = 141
At time = 15: addr = 101, data = 18
At time = 20: addr = 1, data = 13
Coverage = 5.777995