Array of Covergroups

In a testbench sometimes there is a need to take multiple instances of a covergroup as per protocol requirement.

In that case Array of Covergroup is needed.


By default the coverage information of all covergroup instances shall be grouped together and simulator shall create overall coverage of all the instances combined . So, user will not be able to see separate coverage information of each instance of covergroup.
There are some cases when user want to view separate coverage for all the instances. 

Example :

 In a testbench there can be more than one agents.  All of them belong to different transaction, different generator, different driver etc. In that case, if user may not want to view overall coverage of all the agents, instead individual agent coverage is required.

So, You can use SystemVerilog’s  single-word  Per instance Coverage option.

Here is the simple example how one can declare Array of Covergroup and how can use it.

Code :
covergroup configuration(string name_ ,ref int data);     type_option.comment = “Covergroup for data no in data”; = name_;                          // gives different name to each instance
       option.per_instance = 1;                 //  to see separate coverage for each instance    no_in_data : coverpoint data[31:24]
        bins rng_0 = {[0:127]} ;
        bins rng_1 = {[128:255]} ;
       }endgroup : configurationclass coverage_class;    int data[25];

    configuration cfg[25];                  // declaration of array of coverage

   function new(string name=”coverage class”, uvm_component parent= null);
      cfg = new($sformatf(“cg_%d”,i),data);      // instantiate array of covergroup
    endfunction : new

task give_data();

for(int i=0; i<25; i++)


= i*i;

    endtask : give_data

endclass : coverage_class


Explanation :
  • when declaring array of covergroup, covergroup  should be outside of coverage classs.
Referring some online forum and LRM(IEEE std 1800-2009 Section 19.4), One cannot declare an array of an embedded covergroup inside class because the covergroup declared inside a class is an anonymous type and the covergroup name becomes the instance variable.

  • One need to use ref argument to access variable declared inside coverage class.
Referring LRM (IEEE std 1800-2009 Section 19.3 ) a ref argument allows a different variable to be sampled by each instance of covergroup. Input arguments will not track the value of their arguments,they will use the value passed to the new operator. So, it is necessary to use ref argument for covergroup.
  •  In this code, I have demonstrated how one can use option.per_instance coverage option. But user’s application and requirement may be different.

Let’s discuss important Coverage Options :

These are the options that can be used in a instance of covergroup.

1)  option.per_instance :  To keep track of coverage for each instance and to get separate coverage of each instance. option.per_instance = 1 is necessary. 

2) : To give unique name to each of the instance, so that you can identify each instance differently. 

3) type_option.comment : To add a comment into coverage report to make it easier to analyse . In multiple instances you can give each a separate comment.
Detailed information on different type of coverage options is given in Chris Spear Book – System verilog for Verification in section 9.10. 
For more information on array of covergroup one can refer LRM (IEEE std 1800-2009) from section 19 .3, 19.4 and 19.7.
I hope it will be helpful !!
Mansi Kelawala 

One response

  1. I’m not sure if this is still active. But thanks for the information it was useful!
    I have a question regarding the sample code and I was hoping you could clarify.
    When you do the sampling wouldn’t you need to specify the index of the cg?

    Thanks again


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: