Dynamic Coverpoints in Coverage Systemverilog

Karan Shah picture Karan Shah · Jun 4, 2015 · Viewed 7.8k times · Source
class conf;
  typedef struct packed
  {
    int ns_size;
    int limit;
  } ns;

  int num_ns_supported;
  ns num_ns[];

  function new(input int s=5);     
    num_ns_supported = s;
    num_ns = new[s];
    foreach(num_ns[i])
    begin
      num_ns[i].ns_size = (1000 * (i+1));         
    end
  endfunction
endclass

class pac;
  int nsid=1;
  int slba;
endclass

class c;
  pac p;
  conf cfg;

  covergroup x;
    option.per_instance = 1;
    a : coverpoint p.slba
    {
      bins range[3] = {[32'h0000_0000 : cfg.num_ns[p.nsid-1].ns_size]};
    }
  endgroup

  function new(input conf ca);     
    p = new();
    cfg = ca;
    x = new();
  endfunction

  function void sample(input pac p1);
    p = p1;
    x.sample();
  endfunction
endclass

program p1;
  conf cfg = new(6);
  pac p = new();
  c co = new(cfg);

  initial
  begin
    p.nsid = 1;
    p.slba = 550;
    co.sample(p);
    p.nsid = 2;
    co.sample(p);
  end  
endprogram

In this code, I need to cover slba with ranges associated to the respected num_ns structure.

But in this code, ranges will be divided according to num_ns[0] only.

So how can I reuse same coverpoint to generate dynamic ranges depending upon the variable value on the sampling time?

Answer

dave_59 picture dave_59 · Jun 4, 2015

What you are asking for cannot be done, nor does it make any sense. See https://verificationacademy.com/forums/coverage/how-get-values-different-bins-coverpoint