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