Is it possible to set virtual interfaces with loop?

hi All,

I’m new to uvm. by using generate we can set array of interfaces in top module. but i have to set array of virtual interfaces in program block only. please help me on following error.

Error:
Illegal operand for constant expression
this error pointing out i in below line.
uvm_config_db#(virtual intf )::set(null, $sformatf(“uvm_test_top.env.agent[%0d]”,i), “vif”, top.vif[i]);

code:
include “program_file.sv”
module top();

intf vif5;

endmodule

program automatic program_file();
int i;
initial begin
for (i= 0; i < 5; i++ ) begin
uvm_config_db#(virtual intf )::set(null, $sformatf(“uvm_test_top.env.agent[%0d]”,i), “vif”, top.vif[i]);
end
end
endprogram

In reply to amsaveni.c:

Setting An interface array for hierarchical elements from top.. | Verification Academy

Additionally, you never want to use a program block. Put all of your testbench code into one module (top in this case).

Also, don’t target the agents for the virtual interface handles. Instead, target ‘uvm_test_top’ and have the test put the interface handles into the agent’s configuration object.