CoverPoint declaration for Dynamic Array

Hello All,
I would like to know if there is way to declare coverpoint to dynamic array , Its evident from below mentioned link as of how to declare coverpoint to static array, but I would like to know the same for dynamic array.

https://verificationacademy.com/forums/coverage/coverpoint-array-or-queue

Best Regards,
Ganesh

In reply to ganesh_b:

It depends. Do you know the size of the dynamic array at the time the covergroup needs to be constructed? If yes, then you can make a dynamic array of covergroups and construct it to be the same time. If you do not know, then you need to explain more clearly what you are trying to cover, i.e. what it takes to get 100% coverage.

In reply to dave_59:

Hi Dave, I have a question related to this particular concept.

Suppose my sequence_item (my_sqi) has a variable:

rand bit my_variable; //NOTE: This is a dynamic array whose size i am aware of alll the time
// As it is based on a paramter called “P_NUM”

Now suppose I want to make a functional coverage of this particular variable. So based on the link above and system verilog - Dynamic Coverpoints in Coverage Systemverilog - Stack Overflow

covergroup my_cg with function sample(bit cp_s);
coverpoint cp_s;
endgroup

my_cg m_my_cg1;
m_my_cg1 = new[P_NUM];
foreach (m_my_sqi.my_variable[i]) m_my_cg1[i] = new();
foreach (m_my_sqi.my_variable[i]) m_my_cg1[i].sample(m_my_sqi.my_variable[i]);

Well this is what i have come upto, but this doesn’t work.
Any advices from your end, what am i doing wrong here.

In reply to npadhi:

You need to explain what “doesn’t work” means. Are you getting different coverage result from what you expect? How is it different?

One thing that may missing is you need
option.per_instance = 1;
inside the
covergroup
. Otherwise the coverage for all the instances gets merged together by default.

In reply to dave_59:

So, Currently the simulation has compilation error since i have added this portion of the code.
It is not happy about This particular line
“my_cg m_my_cg1;” and states it as “Syntactically this identifier appears to begin a datatype but it does not refer to a visible datatype in the current scope.”

Thus please let me explain the code structure:

class my_fcov extends uvm_subscriber #(my_sqi);

covergroup my_cg with function sample(bit cp_s);
coverpoint cp_s;
endgroup

my_cg m_my_cg1;

extern function new(string name, uvm_component parent);
extern virtual function void write(my_sqi t);

endclass

function my_fcov::new(string name, uvm_component parent);
m_my_cg1 = new[P_NUM];
foreach (m_my_sqi.my_variable[i]) m_my_cg1[i] = new();

endfunction: new

function void my_fcov::write(my_sqi t);

foreach (m_my_sqi.my_variable[i]) m_my_cg1[i].sample(m_my_sqi.my_variable[i]);

endfunction:write

As the part of coverage i haven’t been able to see anything as it has a compilation error itself.

In reply to npadhi:

See Creating new instances of a covergroup using an array. | Verification Academy