How to configure an agent from active to passive, or vice-versa?

I’m trying to create an agent that can be configured as active and as passive. I need it to be active in block level verification, but I need it to be passive in system level verification.

All I know is that I have this code in my agent’s build_phase:

if(is_active == UVM_ACTIVE) begin
  driver = apb_slave_driver#(data_width, addr_width)::type_id::create("driver", this);
  sequencer = apb_slave_sequencer#(data_width, addr_width)::type_id::create("sequencer", this);

But I don’t know how to control or set the is_active.

I think I found the solution for this.

I put this in the build_phase of my test class:

set_config_int("env.a_agent", "is_active", UVM_PASSIVE);

However, can I put this in the sequence class?
I tried to place it inside the function new of the base sequence class but it didn’t work.
It compiles but it didn’t work. I wonder maybe the agent’s path is wrong. I used the same path.

use uvm_config_db to change the type from UVM_ACTIVE to UVM_PASSIVE.

is_type is of type uvm_active_passive_enum

You should encapsulate the UVM_ACTIVE/UVM_PASSIVE within your agent’s configuration object. You do have an agent configuration object, right?

This configuration object should be created by the testbench or the test and passed to the agent using the uvm_config_db. You shouldn’t use the set_config_int as it is deprecated and doesn’t match the uvm_active_passive_enum type.

Also, this configuration has to be done in a component during the build phase since the UVM_ACTIVE/UVM_PASSIVE will determine if the agent builds the sequencer/driver. You can’t do any testbench configuration in a sequence since it is an object that is created after the testbench is built.

In reply to cgales:

Alright. Thanks! =)

To which component’s build_phase should I use the uvm_config_db? In the test class?

In reply to Reuben:

I prefer to create the agent configuration objects and assign the virtual interface handles in the testbench. This allows me to control each configuration based on the specific testbench requirements. I pass the configuration objects to uvm_test_top which allows the test to modify the configuration as required and in turn pass the configuration to the agent as appropriate.