Search code examples
code-coveragesystem-verilogverificationquestasim

How to load coverage_db?


I'm trying to write a functional coverage for my design. I wrote needed covergroups, but now I faced with difficulties to transport my coverage between test runs. Here a few code examples:

`include "uvm_macros.svh"
package t;
    import uvm_pkg::*;

    class test extends uvm_test;
        `uvm_component_utils(test)
        byte unsigned data;
        covergroup cg;
            dat: coverpoint data;
        endgroup

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

        task run_phase(uvm_phase phase);
            phase.raise_objection(this);
            repeat(5) begin
                #5data = $urandom();
                #10 cg.sample();
            end
            phase.phase_done.set_drain_time(this, 50ns);
            phase.drop_objection(this);
        endtask
    endclass: test
endpackage

module top();
    import uvm_pkg::*;
    import t::*;
    initial begin
        $load_coverage_db("coverage_report.db");
        $set_coverage_db_name("coverage_report.db");
        run_test();
    end
endmodule

If I try to run test above, I get this error:

** Error: (vsim-6844) Covergroup '/t/test/cg' has no instance created in simulation, ignoring it

Clearly, the problem is that cg created after test start, while config_db loading when it's not created yet. So I placed $load_coverage_db in run_phase like this:

`include "uvm_macros.svh"
package t;
    import uvm_pkg::*;

    class test extends uvm_test;
        `uvm_component_utils(test)
        byte unsigned data;
        covergroup cg;
            dat: coverpoint data;
        endgroup

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

        task run_phase(uvm_phase phase);
            $load_coverage_db("coverage_report.db");
            phase.raise_objection(this);
            repeat(5) begin
                #5data = $urandom();
                #10 cg.sample();
            end
            phase.phase_done.set_drain_time(this, 50ns);
            phase.drop_objection(this);
        endtask
    endclass: test
endpackage

module top();
    import uvm_pkg::*;
    import t::*;
    initial begin
        $set_coverage_db_name("coverage_report.db");
        run_test();
    end
endmodule

Now, I'm getting this type of warning:

** Warning: (vsim-6841) Covergroup instance '/t::test::cg ' exists in simulation but not found in database

What I need to do, to get my old coverage in test?


Solution

  • After I already wrote a python script that creates and updates my own sqlite database after each run of tests from the coverage exported to a text file,I finally found out that there is a vcover merge command in questa sim that merges the coverage of all tests.
    As far as I understand, this is the generally accepted practice: to keep the coverage of each of the tests and merge them together, rather than loading the total coverage into each of the new tests. But there is still a problem that vcover has very poor help and there is practically no mention of it in the documentation.