How can I configure two agents with Active and Passive?

Hi,
I have two agents in one environment.
Considering agt1(active) and agt2(passive),

I have two agent config files and using uvm_config_db both the config is set in the testbase class and I’m retrieving back using get method in agt1 and agt2.
Can you please provide me the proper way to configure it.
Thanks

//Config file for agt1
class agent1_config extends uvm_object;
  `uvm_object_utils(agent1_config)
  
  uvm_active_passive_enum is_active = UVM_ACTIVE;
  
  function new(string name="");
    super.new(name);
  endfunction
  
endclass 

//Config file for agt2
class agent2_config extends uvm_object;
  `uvm_object_utils(agent2_config)
 uvm_active_passive_enum is_active = UVM_PASSIVE;

 function new(string name="");
    super.new(name);
  endfunction
  
endclass 

Hi,
You can refer to this code :


`include "uvm_macros.svh"
import uvm_pkg::*;

module my_testbench;
  bit clk;
  initial begin
    run_test("base_test");
  end
  
  initial begin
    repeat(5) begin
      #5 clk = ~clk;
    end
  end
  
endmodule

//Config file for agt1
class agent1_config extends uvm_object;
  `uvm_object_utils(agent1_config)
 
  uvm_active_passive_enum is_active = UVM_ACTIVE;
 
  function new(string name="");
    super.new(name);
  endfunction
 
endclass 
 
//Config file for agt2
class agent2_config extends uvm_object;
  `uvm_object_utils(agent2_config)
 uvm_active_passive_enum is_active = UVM_PASSIVE;
 
 function new(string name="");
    super.new(name);
  endfunction
 
endclass 

class agt1 extends uvm_agent;
  `uvm_component_utils(agt1)
  
  
  agent1_config agt1_cfg;
  agent2_config agt2_cfg;
  uvm_driver drv;
  uvm_monitor mon;
  uvm_sequencer seqr;
  
  function new(string name, uvm_component parent = null);
    super.new(name, parent);
    
  endfunction
  
  virtual function void build_phase(uvm_phase phase);
    super.build_phase(phase);  
    
    if(!uvm_config_db#(agent1_config)::get(this,"","agt1_cfg", agt1_cfg))
      `uvm_fatal(get_type_name(),"Cannot retrive agt1_cfg");
    
   
    if(agt1_cfg.is_active == UVM_ACTIVE) begin     

//Create object for UVM driver and Seqeuencer here 
      `uvm_info(get_type_name(),"is active, created seqr and driver", UVM_LOW)
    end
//Create object for UVM Monitor here
  endfunction
  
endclass


class agt2 extends uvm_agent;
  `uvm_component_utils(agt2)
  
  agent1_config agt1_cfg;
  agent2_config agt2_cfg; 
  uvm_driver drv;
  uvm_monitor mon;
  uvm_sequencer seqr;
  
  function new(string name, uvm_component parent = null);
    super.new(name, parent);    
  endfunction
  
  virtual function void build_phase(uvm_phase phase);
    super.build_phase(phase);     
    if(!uvm_config_db#(agent2_config)::get(this,"","agt2_cfg", agt2_cfg))
      `uvm_fatal(get_type_name(),"Cannot retrive agt2_cfg");
    
    if(agt2_cfg.is_active == UVM_ACTIVE) begin
//Create object for UVM driver and Seqeuencer here 
      `uvm_info(get_type_name(),"is active, created seqr and driver", UVM_LOW)
    end 
//Create object for UVM Monitor here
  endfunction
  
endclass


class base_test extends uvm_test;
  `uvm_component_utils(base_test)

  agent1_config agt1_cfg;
  agent2_config agt2_cfg; 
  
  function new(string name, uvm_component parent = null);
    super.new(name, parent);
    
  endfunction
  
  virtual function void build_phase(uvm_phase phase);
    super.build_phase(phase); 
    
    agt1_cfg = agent1_config::type_id::create("agt1_cfg");
    agt2_cfg = agent2_config::type_id::create("agt2_cfg");
    agt1_cfg.is_active = UVM_ACTIVE;
    agt2_cfg.is_active = UVM_PASSIVE;
    
    uvm_config_db#(agent1_config)::set(this,"my_env.agent1","agt1_cfg", agt1_cfg);
    uvm_config_db#(agent2_config)::set(this,"my_env.agent2","agt2_cfg", agt2_cfg);
    
  endfunction
  
   virtual task run_phase(uvm_phase phase);
     `uvm_info("MSG1", " message ", UVM_LOW)
  endtask
 
endclass

class my_env extends uvm_env;
  `uvm_component_utils(my_env)
  
  agt1 agent1;
  agt2 agent2;
  
  agent1_config agt1_cfg;
  agent2_config agt2_cfg; 
  
  function new(string name, uvm_component parent = null);
    super.new(name, parent);
    
  endfunction
  
  virtual function void build_phase(uvm_phase phase);
    super.build_phase(phase); 
    agent1 = agt1::type_id::create("agent1", this);
    agent2 = agt2::type_id::create("agent2", this);
  endfunction
  
   virtual task run_phase(uvm_phase phase);
     `uvm_info("MSG1", " message ", UVM_LOW)
  endtask

endclass

In reply to nirajsp47:

Hi nirajsp47, in agent1_config and agent2_config you have declared and assigned with UVM_ACTIVE and UVM_PASSIVE respectively(uvm_active_passive_enum is_active = UVM_ACTIVE / UVM_PASSIVE).

In base_test I am able to see equating the UVM_ACTIVE / UVM_PASSIVE again,
agt1_cfg.is_active = UVM_ACTIVE;
agt2_cfg.is_active = UVM_PASSIVE;

So may I know what is the reason of assigning two times?

In reply to Yeptho:

The config classes are setting a default value. The test is explicitly assigning the value. This is a common style as the test writer may not know the default value, or just wants to be very clear.

In reply to chrisspear:

I believe and summarized my understanding that the default value which was set in the config class will work without any hindrance even though we don’t explicitly assigning the value from the test base.