Welcome ! This website will help YOU (recent graduates/professionals) learn verification languages like SystemVerilog and UVM. Register for free and access more content !
1 minute reading time (258 words)

how to pass a command line argument to UVM testbench ?

how to pass a command line argument to UVM testbench ?

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
endclass
A new instance of uvm_cmdline_processor will be created via get_inst() in uvm_root before 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
 
When an X on clock almost went unnoticed
$deposit - Put a value onto any net/register
 

Comments 1

son nguyen on Saturday, 18 August 2018 04:13

Hi, thanks for sharing!
Is there any difference bw this and $test$plusargs ?

Hi, thanks for sharing! Is there any difference bw this and $test$plusargs ?
Already Registered? Login Here
Guest
Sunday, 19 May 2019

You consent to our cookies if you continue to use our website. To know more about cookies, see our privacy policy. I accept cookies from this site.

Agree