In uvm cookbook part:VirtInterfaceFunctionCallChain, it says that one of the disadvantage of assign_vi:
It is not reusable - If the test environment hierarchy changes, these functions must be updated
In the testcase, there is a assign_vi() like function assign_if:
class test_case extends uvm_test;
test_env env;
virtual interface test_if vif;
...
function void build_phase (uvm_phase phase);
this.vif = vif_pkg::vif;
env = test_env::type_id::create("env", this);
endfunction : build_phase
function void connect_phase (uvm_phase phase);
env.assign_if(vif);
endfunction : connect_phase
...
endclass : test_case
If the hierarchy changed, use agent level instead of env:
class test_case extends uvm_test;
test_agent agent;
virtual test_if vif;
...
function void build_phase (uvm_phase phase);
this.vif = vif_pkg::vif;
agent = test_agent::type_id::create("agent", this);
endfunction : build_phase
function void connect_phase (uvm_phase phase);
agent.assign_if(vif);
endfunction : connect_phase
...
endclass : test_case
Use config_db may not change the connect_phase() method:
class test_case extends uvm_test;
test_env env;
virtual test_if vif;
...
function void build_phase (uvm_phase phase);
this.vif = vif_pkg::vif;
env = test_env::type_id::create("env", this);
endfunction : build_phase
function void connect_phase (uvm_phase phase);
uvm_config_db #(virtual test_if)::set(this, "*", "test_if", vif);
endfunction : connect_phase
...
endclass : test_case
and the changed one:
class test_case extends uvm_test;
test_agent agent;
virtual test_if vif;
...
function void build_phase (uvm_phase phase);
this.vif = vif_pkg::vif;
agent = test_agent::type_id::create("agent", this);
endfunction : build_phase
function void connect_phase (uvm_phase phase);
uvm_config_db #(virtual test_if)::set(this, "*", "test_if", vif);
endfunction : connect_phase
...
endclass : test_case
In uvm cookbook part:UVM/Performance Guidelines, it says “Use specific strings with the uvm_config_db set() and get() calls”, so
uvm_config_db #(virtual test_if)::set(this, "*", "test_if", vif);
is not recommended. The connect_phase() code must be change also if use a specific string when hierarchy changes.
So I wonder why don’t we make directly assignments to set virtual interface handle or configuration object?
Thanks a lot!