Search code examples
system-veriloguvmtest-coverage

How to print coverage report in uvm?


I am trying to work on functional coverage for the first time so I created a mem_cov.sv file where I created a coverage class extending it from uvm_subscriber class and implemented the write function to sample the coverage. I am trying to print it in the report_phase but its not getting printed, I am not sure if I am missing something to print it.

 This is the link of the code
 https://www.edaplayground.com/x/3R8m

Providing samples from the code, this is my coverage class extended from uvm_subscriber class

         class mem_cov extends uvm_subscriber#(mem_seq_item);
        `uvm_component_utils(mem_cov)

         real cov;
         mem_seq_item tx; 
         covergroup cg;
         READ_EN:coverpoint tx.rd_en {bins bin_0_1[] ={0,1};}
         endgroup
         extern function new(string name="mem_cov",uvm_component parent);
         extern function void write( mem_seq_item t);
         extern function void extract_phase(uvm_phase phase);
         extern function void report_phase(uvm_phase phase);   
         endclass

         function mem_cov::new(string name,uvm_component parent);
         super.new(name,parent);
         cg=new();
         endfunction


         function void mem_cov::write(mem_seq_item t);
         tx=t;
         cg.sample();
         endfunction

         function void mem_cov::extract_phase(uvm_phase phase);    
         cov=cg.get_coverage();
         endfunction

         function void mem_cov::report_phase(uvm_phase phase);
         `uvm_info(get_full_name(),$sformatf("Coverage is 
         %d",cov),UVM_HIGH);
         endfunction

In my env class I have connected the monitor analysis port to the analysis export port of the subscriber, here is snippet from env class :

         function void build_phase(uvm_phase phase);
         super.build_phase(phase);
         mem_cv=  mem_cov::type_id::create("mem_cv",this);
         endfunction : build_phase


         function void connect_phase(uvm_phase phase);
       mem_agnt.monitor.item_collected_port.connect(mem_cv.analysis_export);
          endfunction : connect_phase

Solution

  • Your problem is nothing to do with coverage. It is to do with verbosity. You are printing your coverage with verbosity UVM_HIGH. The verbosity on your simulation is set to UVM_MEDIUM (which I think is the default). So, you message won't get printed. If you lower the verbosity to UVM_MEDIUM, it gets printed:

    function void mem_cov::report_phase(uvm_phase phase);
        `uvm_info(get_full_name(),$sformatf("Coverage is %d",cov),UVM_MEDIUM)
    endfunction
    

    The verbosity level of a message is the level at which the verbosity must be set in order for the message to be printed. So, a message with level UVM_HIGH will only get printed if the verbosity is UVM_HIGH or higher. In other words, if you want a message to be printed, set the verbosity to a lower level.


    BTW: you don't need a semicolon after a macro.