Create a coverpoint to sample non default value

I want to create a coverpoint to check if non default values exist.

For example

class reg_test;
  bit [31:0] a;
  bit [31:0] b;

  function void new(string new="");
    super.new(name);
    a = 'h4;
    b = 'h10;
  endfunction

  covergroup reg_non_default;
    A_non_default: coverpoint a { bins non_default_a }
    B_non_default: coverpoint b { bins non_default_b }
  endgroup

endclass

If the value of a is not 4, then A_non_default is 100%, and the same for b if its value is not 10.

The real usage is to collect the reg value in uvm_reg, where I could call get_reset() to know its default value.

Is there a sufficient way to do this?

Thanks.

I can think of two ways to handle this.

A coverpoint can be an expression, not just a variable.

covergroup reg_non_default;
    A_non_default: coverpoint a!='h4 { bins non_default_a = {1}; }
    B_non_default: coverpoint b !='h10 { bins non_default_b = {1}; }
  endgroup

You can add an ignore_bin that overlaps other bins.

  covergroup reg_non_default;
    A_non_default: coverpoint a { 
      bins non_default_a = {[0:$]};
      ignore_bins ig = {'h4};
    }
    B_non_default: coverpoint b {
      bins non_default_b = {[0:$]};
      ignore_bins ig = {'h10};
    }
  endgroup

In either case, I would use a localparam for the default value instead of a literal. That way the value only needs to be changed in one place.

1 Like

Thanks for the example.

I finally write like

covergroup reg_non_default (string cg_name) with function sample (int value, int default_value);
  non_default: coverpoint (value != default_value) { bins occurred = {1}; }
  option.name = cg_name;
  option.per_instance = 1;
endgroup

and new the covergroup with name

reg_non_default reg_non_default_cg[string];

reg_non_default_cg["A_non_default"] = new("A_non_default");
reg_non_default_cg["B_non_default"] = new("B_non_default");

reg_non_default_cg["A_non_default"].sample(a.value(), a.get_reset());
reg_non_default_cg["B_non_default"].sample(b.value(), b.get_reset());

It works fine with my case.

Thanks.