Generic coverage groups can be written by passing their traits as arguments to the coverage constructor. This allows creating a reusable coverage group which can be used in multiple places.
For example, To cover a array of specified index range.
covergroup cg(refint array, int low, int high ) @(clk);
coverpoint// sample variable passed by reference
{
bins s = { [low : high] };
}
endgroup
int A, B;
rgc1 = new( A, 0, 50 );// cover A in range 0 to 50
rgc2 = new( B, 120, 600 );// cover B in range 120 to 600
The example above defines a coverage group, gc, in which the signal to be sampled as well as the extent of the coverage bins are specified as arguments. Later, two instances of the coverage group are created; each instance samples a different signal and covers a different range of values.