Coverage (Subscriber)

Hi,

I’m getting about 98% coverage when I write my coverage in monitor. However, I’m getting only about 2% coverage for the same signal when I create a separate class for coverage as a subscriber. Could someone please spot the issue. Below are the coverage and monitor class.

class uart_coverage extends uvm_subscriber#(uart_transaction);
  `uvm_component_utils(uart_coverage)
  
  uart_transaction t1;
  
  covergroup uart_cg;
  data_cp:   coverpoint t1.out_data;
  endgroup
  
  function new(string name="", uvm_component parent);
    super.new(name, parent);
    uart_cg=new;
  endfunction

  function void write(T t);
    t1= uart_transaction::type_id::create("t1");
    uart_cg.sample();
  endfunction
endclass

Monitor:


class uart_monitor_after extends uvm_monitor;
  `uvm_component_utils(uart_monitor_after)   
   uvm_analysis_port #(uart_transaction) mon_ap_after;
  
  virtual uart_if vif;
  uart_transaction u_tx_cg;

  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
	mon_ap_after=new(.name ("mon_ap_after"),.parent(this));   
	if (!uvm_config_db #(virtual uart_if)::get(null, "uvm_test_top", "uart_if", vif))
		`uvm_error("Monitor_before","Interface not found")
 endfunction: build phase
 
 task run_phase(uvm_phase phase);
	uart_transaction u_tx_after;
	begin
		forever 
          begin
          u_tx_after = uart_transaction::type_id::create("u_tx_after", this);
		
          @(posedge vif.frame_end);
		begin
		  u_tx_after.out_data = vif.rx_out;
                  mon_ap_after.write(u_tx_after);
                end 	
	  end
        end
 endtask: run_phase
endclass

In reply to Rana_Meet:
I have spotted one thing in monitor class.
In monitor run_phase , you should not directly placed transaction write method.
First clone the transaction , then place into write method.
Write method is non blocking methong , the previouls transaction may get overridden by new transcation so its better to use clone then place data into write method

In reply to kddholak:

I tried that, still not getting it right.

In reply to Rana_Meet:

In your uart_coverage class, you don’t use the uart_transaction t that you write. You need to create your covergroup with a reference to a uart_transaction and then use the uart_transaction that you write.

Refer to the LRM for an example