0
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?

Karan Shah
  • 1,912
  • 1
  • 29
  • 42

2 Answers2

2

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

dave_59
  • 39,096
  • 3
  • 24
  • 63
  • 1
    ok so if dynamic coverpoints are not possible, then is there any other way to solve the problem thorugh normal/fixed coverpoints, as I have this kind of scenario in my coverage? – Karan Shah Jun 05 '15 at 18:22
  • You are going to have to explain how you expect coverage to be computed, i.e. how do you expect to achieve 100% coverage if you change the bin structure at each sample?. The way coverage is supposed to work is you set up a set of bins at the beginning of simulation, and each sample hits one bin. If at the end of simulation all bins have been hit, you get 100% coverage of that coverpoint. Try explaining what you want to do with a smaller example, showing which bins would be hit with each sample, and show enough samples that would explain how to get 100% coverage. – dave_59 Jun 06 '15 at 00:39
  • Here I will try to explain you the requirements. (1) I want to cover 3 ranges of ns_size field for all num_ns structure. (2) Now in this case, number of num_ns strucutre is dynamic & passed as an argument in new method. So I can't use different coverpoints for the same purpose, as I won't know, how many coverpoints will be required...... Since there is nothing like dynamic coverpoints in systemverilog, then for this purpose, how can I meet the requirement? – Karan Shah Jun 06 '15 at 04:55
  • Now for sampling of the coverpoints, here is a few example. (1) p.nsid = 1 and p.slba = 550, then range[2] of coverpoint related to num_ns[0] structure should get hit, as num_ns[0].ns_size = 1000, so 550 will be in range[2] (Medium Range). (2) p.nsid = 2 and p.slba = 550, then range[1] of coverpoint related to num_ns[1] structure should get hit, as num_ns[1].ns_size = 2000. So 550 will be in range[1] (Low Range). (3) Similarly, for any p.slba, appropriate range of num_ns[p.nsid - 1].ns_size should get hit. ...... – Karan Shah Jun 06 '15 at 04:55
  • 1
    OK, I think what you need to do is create an array of covergroup instances, one for each element of num_ns. Then you chose the covergroup element to sample using p.nsid as the index. The key point is once your classes are constructed and the size of num_ns is defined, you construct all the bins for your covergroup. It is a little harder to construct an array of covergroups because you must declare the covergroup outside the class and pass your coverpoint values in as sample arguments. – dave_59 Jun 06 '15 at 05:59
  • And the reason they way you want to do it does not make sense is because you are assuming that your testbench is working and all nsid's will be used. If you never call sample(), you want 0% coverage, but since you never created the bins, it won't bring down your total coverage. – dave_59 Jun 06 '15 at 06:02
  • Thanks a lot. Your logic served my purpose. I will post the updated code as an answer here, so that someone else can use it. :) – Karan Shah Jun 06 '15 at 09:41
2

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
Karan Shah
  • 1,912
  • 1
  • 29
  • 42