Coverage Systemverilog中的动态覆盖点

时间:2015-06-04 18:54:43

标签: system-verilog function-coverage questasim

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

在这段代码中,我需要用与受尊重的num_ns结构相关联的范围来覆盖slba。

但是在此代码中,范围将仅根据num_ns [0]进行划分。

那么我如何重复使用相同的覆盖点来根据采样时间的变量值生成动态范围?

2 个答案:

答案 0 :(得分:2)

你所要求的是无法做到的,也没有任何意义。见https://verificationacademy.com/forums/coverage/how-get-values-different-bins-coverpoint

答案 1 :(得分:2)

@ dave_59给出了这个问题的答案。但我只是用他的逻辑发布更新的代码。

无法使用动态封面。所以这是另一个用于相同目的的解决方案,具有固定的覆盖点。

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