How to use "set_type_override_by_type" method?

This is one of the example took from;
https://verificationacademy.com/forums/ovm/settypeoverridebytype

Here is code and please tell me how to remove this error to use factory override.

////////////////CODE_BEGINS////////////////////////////

module extend();

`include “uvm_macros.svh”
import uvm_pkg::*;

class my_packet extends uvm_object;

rand bit [31:0] a;
rand bit [3:0] b;
rand bit [7:0] c;

`uvm_object_utils_begin(my_packet)

uvm_field_int(a, UVM_ALL_ON) uvm_field_int(b, UVM_ALL_ON)
`uvm_field_int(c, UVM_ALL_ON)

`uvm_object_utils_end

function new (input string name = “my_packet”, uvm_component parent = null);
super.new(name);
endfunction: new

endclass: my_packet

///////////////////////////////////////////////////////

class my_packet_test extends my_packet;

constraint c1 {a == 5;}

`uvm_object_utils(my_packet_test)

function new (input string name = “my_packet_test”, uvm_component parent = null);
super.new(name, parent);
endfunction: new

endclass: my_packet_test

/////////////////////////////////////////////////////////

class testcase extends uvm_test;
`uvm_component_utils(testcase)

my_packet pkt;
bit flag;

function new (input string name = “testcase”, uvm_component parent = null);
super.new(name, parent);
endfunction: new

virtual function void build();
super.build();

factory.set_type_override_by_type(my_packet::get_type(), my_packet_test::get_type() );
pkt = my_packet::type_id::create(“pkt”, this);

endfunction: build

virtual task run();

flag = pkt.randomize();
if (flag == 0)
begin
$display(“COULD NOT RANDOMIZE: 1”);
end
pkt.print();

flag = pkt.randomize();
if (flag == 0)
begin
$display(“COULD NOT RANDOMIZE: 2”);
end
pkt.print();

endtask: run

endclass:testcase

////////////////////////////////////////////////////////////////////////

initial begin
run_test();
end

endmodule: extend

//////////////////////CODE_ENDS////////////////////////////////////////

Command used: irun -uvm extend.sv

Error received:
VM_FATAL @ 0: reporter [NOCOMP] No components instantiated. You must either instantiate at least one component before calling run_test or use run_test to do so. To run a test using run_test, use +UVM_TESTNAME or supply the test name in the argument to run_test(). Exiting simulation

In reply to Mahesh K:

Hi,

You need to pass testcase name either in run_test() method or from command line,

e.g,


initial begin
run_test("testcase");
end

Or from command line,

irun -uvm extend.sv +UVM_TESTNAME="testcase"