# How to use "set\_type\_override\_by\_type" method?

**URL:** <https://verificationacademy.com/forums/t/how-to-use-set-type-override-by-type-method/32135>\
**Category:** UVM\
**Tags:** UVM, RUN\_TEST\_NOCOMP\_FACTORY\_SET\_TYPE\_OVERRIDE\_BY\_TYPE\
**Created:** [August 10, 2016, 7:32am UTC](https://verificationacademy.com/forums/t/how-to-use-set-type-override-by-type-method/32135 "2016-08-10T07:32:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mahesh\_6](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/ecd19e/32.png) [@Mahesh\_6](https://verificationacademy.com/forums/u/Mahesh_6)\
**Post date:** [August 10, 2016, 7:32am UTC](https://verificationacademy.com/forums/t/how-to-use-set-type-override-by-type-method/32135/1 "2016-08-10T07:32:10Z")

</div>

This is one of the example took from;

> **[Set\_type\_override\_by\_type](https://verificationacademy.com/forums/ovm/settypeoverridebytype)**
>
> Hi, Could someone please provide me some sample code for set\_type\_override\_by\_type(). I tried using it but it didnt produce the desired effect. Perhaps I am doing something wrong. My intention is to add a constraint to an already existing class. I...

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

---

<div class="post-metadata">

**Author:** ![mayurkubavat](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/a9a28c/32.png) [@mayurkubavat](https://verificationacademy.com/forums/u/mayurkubavat)\
**Post date:** [August 10, 2016, 8:20am UTC](https://verificationacademy.com/forums/t/how-to-use-set-type-override-by-type-method/32135/2 "2016-08-10T08:20:07Z")

</div>

_In reply to [Mahesh K](https://verificationacademy.com/forums/t/how-to-use-set-type-override-by-type-method/32135):_

Hi,

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

e.g,

```verilog

initial begin
run_test("testcase");
end

```

Or from command line,

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

```
