The UVM configuration database accessed by the class uvm_config_db is a great way to pass different objects between multiple testbench components. Read more on Using config database for a quick review. There are two primary functions used to put and retrieve items from the database which are set() and get() respectively.
staticfunctionvoidset(uvm_component cntxt,string inst_name,string field_name,
T value);staticfunctionbitget(uvm_component cntxt,string inst_name,string field_name,inout T value);
The best way to understand how the combination of cntxt, inst_name and field_name works is by enabling the commandline debug switch for UVM that dumps information on all the set() and get() calls within a simulation.
Let's create a small test class with a simple empty environment, and try to pass configuration data from the test to the environment. In this case, we set the cntxt to null and the inst_name to uvm_test_top to indicate that all components in the test can access the item. To make things simple, we'll put a string item tagged as Friend1.
class base_env extendsuvm_env;
string name;virtualfunctionvoid build_phase (uvm_phase phase);super.build_name ();// Retrieve the string set from the test in the envif(uvm_config_db #(string)::get(null,"uvm_test_top","Friend1", name))`uvm_info("ENV", $sformatf ("Found %s", name),UVM_MEDIUM)endfunctionendclassclass base_test extendsuvm_test;
base_env m_env;virtualfunctionvoid build_phase (uvm_phase phase);
// Set this string in the test