# Coverage for enum

**URL:** <https://verificationacademy.com/forums/t/coverage-for-enum/39055>\
**Category:** UVM\
**Tags:** UVM, Coverage\
**Created:** [May 8, 2021, 4:54am UTC](https://verificationacademy.com/forums/t/coverage-for-enum/39055 "2021-05-08T04:54:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rag123](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/eada6e/32.png) [@rag123](https://verificationacademy.com/forums/u/rag123)\
**Post date:** [May 8, 2021, 4:54am UTC](https://verificationacademy.com/forums/t/coverage-for-enum/39055/1 "2021-05-08T04:54:36Z")

</div>

Hi,

I am trying to write a coverage for enum which is dynamic array and i am not able to completely write it. Here is my code. Can anyone help me?

typedef enum bit[1:0] {IDLE, BUSY, NONSEQ, SEQ} transfer\_t;

In transaction class  
rand transfer\_t trans\_type;

Coverage class :

```verilog

covergroup transfer with function sample (transfer_t ty);
   TRANS: coverpoint ty; 
   endgroup
// comp_b has a imp port where we need to implement the put method.
class comp_b extends uvm_component;
  `uvm_component_utils (comp_b)
  transfer txy;
  uvm_blocking_put_imp #(transaction,comp_b) trans_in;
  
  function new (string name = "comp_b", uvm_component parent);
    super.new(name,parent);
     txy = new();
  endfunction
  
   function void build_phase(uvm_phase phase);
     trans_in = new("trans_in",this);
  endfunction
  
  task put (transaction tx);
    
    #100;
    `uvm_info(get_type_name(),$sformatf(" Recived trans On comp_b "),UVM_LOW)
    `uvm_info(get_type_name(),$sformatf(" trans, \n %s",tx.sprint()),UVM_LOW)
    txy.sample(transfer_t'(tx.trans_type));
  endtask  

```

Link to code : [Enum coverage - EDA Playground](https://edaplayground.com/x/ht9S)

---

<div class="post-metadata">

**Author:** ![cgales](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/ccd318/32.png) [@cgales](https://verificationacademy.com/forums/u/cgales)\
**Post date:** [May 8, 2021, 1:53pm UTC](https://verificationacademy.com/forums/t/coverage-for-enum/39055/2 "2021-05-08T13:53:35Z")

</div>

_In reply to [rag123](https://verificationacademy.com/forums/t/coverage-for-enum/39055):_

Your transaction has an array of transfer\_t elements. I’m guessing that you want to sample each one?

```verilog

  task put (transaction tx);
    `uvm_info(get_type_name(),$sformatf(" Recived trans On comp_b "),UVM_LOW)
    `uvm_info(get_type_name(),$sformatf(" trans, \n %s",tx.sprint()),UVM_LOW)
    foreach (tx.trans_type[i])
      txy.sample(tx.trans_type[i]);
  endtask  

```
