i had declared a dynamic array like below:
rand int data ;
And was doing the functional coverage for that dynamic array
c4 : coverpoint data;
but faced an error like below can anyone help me how to do functional coverage for dynamic arrays
– Compiling package testbench_sv_unit
** Error: (vlog-2146) Illegal unpacked type expression for coverpoint expression of Coverpoint ‘c4’.
– Compiling module test
** Error: (vlog-2146) Illegal unpacked type expression for coverpoint expression of Coverpoint ‘c4’.

In reply to Mahantha Deeksha S B:

There are two problems with your issue.

Arrays cannot be used for covepoints, only integral values can be captured as bin values. You could create an array of covergroups, one for each element of the array. But the other problem is a dynamic array can change its size during runtime. What exactly is your functional coverage trying to capture? I.e. what samples will it take to get 100% coverage?

In reply to dave_59:

ooh ok i was trying to explore as i was learning SV
the coverage i was tryn to do was :

class packet;
  event cov_ev;
  rand bit [31:0] addr;
  rand int data [];
  rand enum  {idle,busy,write,read,resp} mode;
  rand bit [3:0] xfer_id;
  constraint c1 {unique{addr};addr[3:0] == 0;unique{xfer_id};};
  constraint c2 {!(addr inside {[32'hf000:32'h1_0000]}); addr dist {['h0000:'h8000]:/ 2,['h1000_00:'hffff_fff0] :/ 2};}//constraints doubt i wanted to get it cleared
  constraint c3 {unique{mode};soft (mode == busy || mode == read) -> (data.size() == 0);soft data.size() <= 300;}
  //constraint c4 {soft data.size() > 0;soft data.size() < 128;}
  constraint c5 {foreach(data[i]) data[i] inside {'h00,'hAA,'hBB,'hCC,'hDD,'h44,'d88,'hFF,'h11,'h22};}
  function void display();
                 $display("The properties values  are addr %0h data %0p enum %0s xfer_id %0d", addr, data, mode,xfer_id);
  function void event_gen();
    $display("the event cov_ev has been generated");
                 covergroup fun_cvrg@(cov_ev);
    option.per_instance = 1;
    c1 : coverpoint addr {
      bins min = {['h0000_0000 :'h0000_EFFFF] };
      bins mid = {['h1_0004 :'h1000_FFFF] };
      bins max = {['hF000_0000 :'hFFFF_FFF0] };
      bins def = default;
    c2 : coverpoint xfer_id{bins id = {[0:7]};
                           bins def = default;}
    c3 : coverpoint mode{ignore_bins b1 = {idle};
                         bins def = default;}
    c4 : coverpoint data;//shows error for this coverage
    c1Xc2 : cross c1,c2{bins inte = binsof(c1.min) intersect{xfer_id};
                        bins be = binsof(c1.min)||binsof(c2);
                        bins ve = binsof(c1.min)&&binsof(c2);
    c2Xc3 : cross c2,c3{bins inter = binsof( intersect{mode};
                        bins be = binsof(||binsof(c3);
                        bins ve = binsof(;}
  function new();
    fun_cvrg = new;
    data = new[10];
module test;
  int i, k;
  initial begin
    packet covg;
    covg = new();
    for(i = 0;i < 60;i = i + 1) begin
      k = covg.randomize();//randomising
    $display("coverage = %0.2f %%",covg.fun_cvrg.get_inst_coverage());

and was stuck at 87% coverage without data, dave sir.

In reply to Mahantha Deeksha S B:

If you try different seeds, or increase the number of iterations, you will get to 100%.

I understand that you are just experimenting, but functional coverage needs to be traced back to a set of testing requirements. You cannot just ask for “data” to be covered. You need a testing goal in mind that represents what getting 100$ coverage on a coverpoint means. Your constraint on each data element restricts it to 10 different values.

A couple of other things about your code:

You initialize data to have 10 elements, but that gets ignored during randomization when you constrain the size to be in the range 1-127.

The unique constraints have no effect with there is just a single integral value–it needs an array or multiple values to be compared with to be made unique.

A bin with a default value does not get included in the coverage calculation.