Coverage for enum

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 :


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

In reply to rag123:

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


  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