At times we might need to accept values from the command line to make our testbench and testcases more flexible. UVM provides this support via the
uvm_cmdline_processor singleton class. Generation of the data structures which hold the command line arguments happen during construction of the class object. A global variable called
uvm_cmdline_proc is created at initialization time which can be used to access command line options. Let's see more on how this feature can be used.
class my_test extends uvm_test; ... uvm_cmdline_processor opts; string cmdline; virtual function void build_phase (uvm_phase phase); super.build_phase (phase); opts = uvm_cmdline_processor::get_inst (); endfunction virtual function void start_of_simulation_phase (uvm_phase phase); super.start_of_simulation_phase (phase); if (opts.get_arg_value ("+OPTION=", cmdline) begin // Pass to testbench, set as config db, or what its worth end endfunction endclass
Let's dig a bit more deeper and see how this is setup in the UVM class structure. A singleton class object of
uvm_cmdline_processor exists within
uvm_root and is used to collect and process all the commonly available command line options like uvm_set_verbosity, UVM_TIMEOUT, and UVM_MAX_QUIT_COUNT.
class uvm_root extends uvm_component; ... uvm_cmdline_processor clp; function new (); ... clp = uvm_cmdline_processor::get_inst(); endfunction endclassA new instance of
uvm_cmdline_processorwill be created via
uvm_rootbefore rest of the class hierarchy is done, and all subsequent calls to
get_inst()will return the handle of an already existing object within the UVM environment.
class uvm_cmdline_processor extends uvm_report_object; static local uvm_cmdline_processor m_inst; static function uvm_cmdline_processor get_inst (); if (m_inst == null) m_inst = new ("uvm_cmdline_proc"); return m_inst; endfunction ... endclass