Dynamic Coverpoints in Coverage Systemverilog

9.1k views Asked by At
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?

2

There are 2 answers

7
dave_59 On BEST ANSWER

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

0
Karan Shah On

Answer of this question was given by @dave_59. But I'll just post the updated code with his logic.

Dynamic Coverpoints are not possible. So here is the another solution for the same purpose, with fixed coverpoints.

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

covergroup x (int nsid, input conf cfg) with function sample(int slba);
option.per_instance = 1;
  a : coverpoint slba
  {
    bins range[3] = {[32'h0000_0000 : cfg.num_ns[nsid].ns_size]};
  }
endgroup

class c;
  pac p;
  conf cfg;
  x cg[];

  function new(input conf ca);     
    p = new();
    cfg = ca;
    cg = new[cfg.num_ns_supported];
    foreach(cfg.num_ns[i])
      cg[i] = new(i, cfg);
  endfunction

  function void sample(input pac p1);
    p = p1;
    cg[p.nsid-1].sample(p.slba);
  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