Override instance

Hello,
I am new with UVM environment so please can anyone tell me why the override instance functionality is their in UVM. what it is the need of it ?
Can anyone explain me with a simple example that how one instance is exactly overridden ?

In reply to Huzefa Halolwala:
I have design one simple testbench in which there are two driver classes

  1. driver (drv)
  2. driver2 (drv2)
    and I want to override the instance with driver2 (drv2), But it is showing me the result as drv not the replaced one drv2. This is what i have written in my testcase

 
driver::type_id::set_inst_override(driver2::get_type(),"top.t_env.ag2.drv2");


In reply to Huzefa Halolwala:

The override command needs 3 arguments:
function void set_inst_override( string relative_inst_path,
string original_type_name,
string override_type_name)

In reply to chr_sue:

But in the output it is showing me that the factory has granted the request for overriding.

Instance Overrides:

Requested Type Override Path Override Type


driver top.t_env.ag2.drv2 driver2

In reply to chr_sue:

Here is my code:


------------------ Agent ------------------
class agent extends uvm_agent;
     `uvm_component_utils(agent)
      protected uvm_active_passive_enum is_active = UVM_ACTIVE;
	monitor mon;
        driver drv;
     // driver_2 drv2;
      //monitor_2 mon2;  
     function new(string name, uvm_component parent);
         super.new(name, parent);
     endfunction

     function void build();
         uvm_report_info(get_full_name(),"Build", UVM_LOW);
         mon = monitor::type_id::create("mon",this);   
         drv = driver::type_id::create("drv",this);     
        // ag2 = agent::type_id::create("ag2",this);     
        // mon2 = monitor_2::type_id::create("mon2",this);   
        // drv2 = driver_2::type_id::create("drv2",this);     
     endfunction
endclass

--------------------------- Agent 2 derived from Agent-------------
class agent2 extends agent;
     `uvm_component_utils(agent2)
      protected uvm_active_passive_enum is_active = UVM_ACTIVE;
      monitor2 mon2;
      driver2 drv2;
 
     function new(string name, uvm_component parent);
         super.new(name, parent);
     endfunction

     function void build();
         uvm_report_info(get_full_name(),"Build", UVM_LOW);
         mon2 = monitor2::type_id::create("mon2",this);   
         drv2= driver2::type_id::create("drv2",this);     
     
     endfunction
endclass

---------------- env --------------------
class env extends uvm_env;

    `uvm_component_utils(env)
     agent ag1;
     agent2 ag2;
      
    function new(string name, uvm_component parent);
        super.new(name, parent);
    endfunction

    function void build();
        uvm_report_info(get_full_name(),"Build", UVM_LOW);
        ag1 = agent::type_id::create("ag1",this);   
        ag2 = agent2::type_id::create("ag2",this);   
    endfunction
endclass

---------------- testcase------------------

class test2 extends uvm_test;

   `uvm_component_utils(test2)
    env t_env;
 
    function new (string name="test2", uvm_component parent=null);
        super.new (name, parent);
        driver::type_id::set_inst_override(driver2::get_type(),"top.t_env.ag2.drv2");
        	factory.print();
	
	t_env = new("t_env",this);
    endfunction : new
endclass


Output :
Instance Overrides:

Requested Type Override Path Override Type


driver top.t_env.ag2.drv2 driver2


Name Type Size Value

uvm_test_top test2 - @455
t_env env - @463
ag1 agent - @471
drv driver - @495
rsp_port uvm_analysis_port - @512
seq_item_port uvm_seq_item_pull_port - @503
mon monitor - @487
ag2 agent2 - @479
drv2 driver2 - @533
rsp_port uvm_analysis_port - @550
seq_item_port uvm_seq_item_pull_port - @541
mon2 monitor2 - @525

In reply to Huzefa Halolwala:

Your second argument is wrong. You have to indicate the instance which has to be overwritten and this is drv and not drv2:
driver::type_id::set_inst_override(driver2::get_type(),“top.t_env.ag2.drv”);

For an example see
https://verificationacademy.com/cookbook/cookbook-code-examples#UVM_Examples:#UVM_Examples:#UVM_Examples:
Overriding