Coverpoint for an array or queue

How should I write a coverpoint for an array/queue such that each element is evaluated separately.
e.g if temp_q = {1,0,4,8};

The coverpoint should cover all values 0,1,4,8

You will have to iterate over all the elements. You can either do it with one covergroup

covergroup cg with function sample(int cp);
coverpoint cp;
endgroup;
cg cvg=new();

foreach(temp_q[i]) cvg.sample(temp_q[i]);


or an array of covergroups.

event samplecg;
covergroup cg(ref int cp) @samplecg
coverpoint cp;
endgroup;
cg cvg[N];
foreach(temp_q[i]) cvg[i] = new(temp_q[i]);


In reply to dave_59:

This helps. My scenario is much more complex as the transaction item, has queues of dynamic arrays where all individual elements needed to be covered.

In reply to vinayv:

Just remember that by default, bins for a covergroup are collected per type, not per instance.

In reply to dave_59:

You will have to iterate over all the elements. You can either do it with one covergroup

covergroup cg with function sample(int cp);
coverpoint cp;
endgroup;
cg cvg=new();
foreach(temp_q[i]) cvg.sample(temp_q[i]);

or an array of covergroups.

event samplecg;
covergroup cg(ref int cp) @samplecg
coverpoint cp;
endgroup;
cg cvg[N];
foreach(temp_q[i]) cvg[i] = new(temp_q[i]);

module array_cp();

class test;

rand bit [2:0]a[5];

endclass

covergroup cg with function sample(bit [2:0] cp);
coverpoint cp;
endgroup

test t;
cg cg_inst;

initial begin

t=new();
cg_inst=new();

repeat(10) begin
void’(t.randomize());
$display(“--------------------------------------------”);
foreach (t.a[i]) begin
$display(“a[%d]=%d”,i,t.a[i]);
cg_inst.sample(t.a[i]);
end
end

end

endmodule

Hi Dave,
In the above program it is creating only 8 bins totally, but i thought that it will create a total of 85=40 bins(because there are 5 elements in an array). My doubt is that, if we declare an array name as a coverpoint then it is showing an error as:
‘An expression with an unpacked array datatype is not allowed.’
And what should we do if I want it to create a total of 8
5=40 bins, i.e; 8-bins for each element of the array? Could you please give me an idea of it.

Thanks in advance.
Naveen.

In reply to dave_59:

Hello Dave,

This was really helpful. Can we also define cross coverage between multiple arrays either by iterating within one covergroup or array of covergroups ?

Regards
Navdeep

In reply to dave_59:

You will have to iterate over all the elements. You can either do it with one covergroup

covergroup cg with function sample(int cp);
coverpoint cp;
endgroup;
cg cvg=new();
foreach(temp_q[i]) cvg.sample(temp_q[i]);

or an array of covergroups.

event samplecg;
covergroup cg(ref int cp) @samplecg
coverpoint cp;
endgroup;
cg cvg[N];
foreach(temp_q[i]) cvg[i] = new(temp_q[i]);

Hi Dave. Is there a way to cover a queue of register address? I have a queue of 370 specific 17 bit addresses. I follow the similar approach mentioned above

covergroup

covergroup cg with function sample(bit [16:0] addr);
coverpoint addr;
endgroup;
cg cvg=new();

foreach(temp_q[i]) cvg.sample(temp_q[i]);

and loop thru the whole addr queue to sample and I received 40 auto bins. But the autobins does not match the address in the queue. I get utobins of range of address instead.

In reply to cnhoang:

Is there a way to cover a queue of register address? I have a queue of 370 specific 17 bit addresses.

Something like this?


covergroup register_address_queue_cg() with function sample (int array_index);
    register_address_cp :   coverpoint register_address_queue[array_index] {
                                bins address1  = {`ADDRESS1_VALUE};
                                bins address2  = {`ADDRESS2_VALUE};
                                /* fill in the rest */
                                bins address16 = {`ADDRESS16_VALUE};
                                bins address17 = {`ADDRESS17_VALUE};
                                bins unexpected_address[] = default;
                        }
endgroup : register_address_queue_cg

register_address_queue_cg = new();
foreach(register_address_queue[i]) register_address_queue_cg.sample(i);

In reply to dave_59:
What if I have other coverpoints as well in the covergroup apart from the queue coverpoint?
Do I need to get to create a seperate covergroup for this? The other coverpoints are not of queue type.

Thanks In advance.

In reply to Noob_max:

In reply to dave_59:
What if I have other coverpoints as well in the covergroup apart from the queue coverpoint?
Do I need to get to create a seperate covergroup for this? The other coverpoints are not of queue type.
Thanks In advance.

Yes, need a separate covergroup.