# FUNCTIONAL COVERAGE FOR DYNAMIC ARRAY

**URL:** <https://verificationacademy.com/forums/t/functional-coverage-for-dynamic-array/41444>\
**Category:** Coverage\
**Tags:** functional-coverage-systemverilog, Coverage\
**Created:** [March 31, 2023, 1:34pm UTC](https://verificationacademy.com/forums/t/functional-coverage-for-dynamic-array/41444 "2023-03-31T13:34:55Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Mahantha\_Deeksha\_S\_B](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/mahantha_deeksha_s_b/32/1072_2.png) [@Mahantha\_Deeksha\_S\_B](https://verificationacademy.com/forums/u/Mahantha_Deeksha_S_B)\
**Post date:** [March 31, 2023, 6:13pm UTC](https://verificationacademy.com/forums/t/functional-coverage-for-dynamic-array/41444/3 "2023-03-31T18:13:02Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/functional-coverage-for-dynamic-array/41444/2):_

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

```verilog
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);
  endfunction
  //-----------------------------------------------
  function void event_gen();
    ->cov_ev;
    $display("the event cov_ev has been generated");
  endfunction
  //-----------------------------------------------
                 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(c2.id) intersect{mode};
                        bins be = binsof(c2.id)||binsof(c3);
                        bins ve = binsof(c2.id)&&binsof(c3);}
  endgroup
  //-----------------------------------------------
  function new();
    fun_cvrg = new;
    data = new[10];
  endfunction
  //-----------------------------------------------
endclass
//-------------------------------------------------
module test;
  int i, k;
  initial begin
    packet covg;
    covg = new();
    for(i = 0;i < 60;i = i + 1) begin
       covg.event_gen();
      k = covg.randomize();//randomising
       covg.fun_cvrg.sample();
       covg.display();
    end
    $display("coverage = %0.2f %%",covg.fun_cvrg.get_inst_coverage());
  end
endmodule

```

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

---

_[View the full topic](https://verificationacademy.com/forums/t/functional-coverage-for-dynamic-array/41444)._
