Coverage of an uvm_object

Hi,
I’m trying to cover a uvm_object like:

class transaction extends uvm_object;
  int value;
endclass

class instruction extends uvm_onject;
  transaction txn[2];
  txn[0].value = 23;  

  covergroup txn_cg;
    coverpoint txn[0].value;

  endgroup

  function new();
    txn_cg t_cg = new
  endfunction
endclass

I’m getting compilation error in the new function where the txn_cg is created. Can you please let me know how can I create the covergroup in this hierarchy level itself? (ie, inside class instruction itself)

Thanks

In reply to Ramyas:

When you embed a covegroup declaration inside a class declaration, the covergroup name txn_cg becomes the name of the instance. (See 19.4 Using covergroup in classes in SV LRM)

You need write your constructor like this:

  function new();
    txn_cg = new;
  endfunction

This means you can only have one instance of an embedded covergroup per class object. If you need more, you have to define the covergroup outside the class.

Also in your constructor above, you were declaring t_cg inside the constructor. You would not be able to sample it outside the constructor.