Search code examples
code-coveragesystem-verilog

writing coverage group within a class in a system verilog file returns error


I am writing a covergroup in my .sv file within a class that I am using for randomizing some inputs.I keep getting error :

An embedded coverage group not instantiated in the 'new' method

Then i am calling the run_coverage function in my initial block. I am not sure about it.

covergroup cg_for_arrays(ref logic [7:0]array, input int min, int max);
  coverpoint cp_array
      {
        bins s = {min,max};
      }
endgroup

function void run_coverage();
cg_for_arrays = new(array1,1,255);
cg_for_arrays.sample();
endfunction         

Solution

  • The error message is very clear. You are only allowed to construct a covergroup defined inside a class inside the constructor of that class. See section 19.4 Using covergroup in classes in the SystemVerilog IEEE 1800-2012 LRM.