Run_phase until expected coverage

Hello!

Optimally I want to make a run_phase loop until meet to expected coverage (for example 100%) cross over classes.
So far my code does not work. What should I make it?
Here is my code example.


class apb_test extends uvm_test;

        `uvm_component_utils(apb_test)
.......// bla bla bla
        extern function new(string name="apb_test", uvm_component parent);
        extern virtual function void build_phase(uvm_phase phase);
        extern virtual function void end_of_elaboration();
        extern task run_phase(uvm_phase phase);
endclass

task apb_test::run_phase(uvm_phase phase);
                apb_seq seq;
                apb_subscriber  sub;
                seq = apb_seq::type_id::create("seq");
                phase.raise_objection(this, "Starting apb_seq main phase");

                repeat (40) begin // I want to change this to while() using coverage
                        //$display("%t Starting sequence apb_seq run_phase",$time);
                        seq.start(env.apb_agnt.seqr);
                end
// For testing to get coverage value from subscriber class.
                `uvm_info(get_type_name(), $sformatf("Coverage is: %0.2f%%", sub.cov), UVM_MEDIUM)

                #100ns;
                phase.drop_objection(this, "Finishing apb_seq in main phase");
                phase.phase_done.set_drain_time(this, 50);
        endtask

The Error Msg was

Error-[NOA] Null object access
apb_test.sv, 63 (`uvm_info(get_type_name(), $sformatf(“Coverage is: %0.2f%%”, sub.cov), UVM_MEDIUM))
The object at dereference depth 0 is being used before it was
constructed/allocated.
Please make sure that the object is allocated before using it.

In reply to uvmbee:

Where do you create or assign a handle to ‘apb_subscriber sub’? Since there is no creation or assignment shown, it is a null pointer.

In reply to cgales:

Thanks cgales.
The class “apb_subscriber” was defined in a different file. Anyhow I resolved this as below.



class apb_test extends uvm_test;
.... bla bla bla ....
     real cov;
..... bla bla blar ....
endclass

task apb_test::run_phase(uvm_phase phase);
                apb_seq seq;
                //apb_subscriber        sub;
                seq = apb_seq::type_id::create("seq");

                phase.raise_objection(this, "Starting apb_seq main phase");
                //repeat (40) begin
                while (cov < 100.0) begin
                        seq.start(env.apb_agnt.seqr);
                        cov = env.apb_sub.cover_bus.get_coverage();
                end
                #100ns;
                phase.drop_objection(this, "Finishing apb_seq in main phase");
                phase.phase_done.set_drain_time(this, 50);
        endtask