Tutorials

Learn More

The covergroup provides a set of system tasks and functions in coverage as follows.

System tasks/functions

Descriptions

$set_coverage_db_name

Sets coverage information throughout the simulation in a specified file name.

$get_coverage

Returns 0 to 100 range real numbers as an overall coverage of all coverage groups.

$load_coverage_db

Loads cumulative coverage information of all coverage groups from the given file name.

System tasks and functions coverage 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
    $set_coverage_db_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
    $display("Coverage = %f", $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