Part 7 · Environment & Tests · Intermediate

uvm_cmdline_processor in Tests: One Parser, Typed Outputs

Using uvm_cmdline_processor from base_test to read built-in and custom plusargs and publish results into cfg objects.

Centralized parsing in base_test

Use uvm_cmdline_processor::get_inst() as a singleton parser in base_test. Child tests inherit resolved cfg — they should not re-parse the command line.

diagram
[TEST][UVM] parser placement

base_test::build_phase
  cfg = env_cfg::type_id::create("cfg")
  apply_defaults()
  configure_from_plusargs()   <-- single clp entry point
  config_db::set(...)
  create env
systemverilog
function void configure_from_plusargs();
  uvm_cmdline_processor clp = uvm_cmdline_processor::get_inst();
  string vals[$];

  // +SEQ_COUNT=500
  if (clp.get_arg_values("+SEQ_COUNT=", vals) > 0)
    cfg.seq_count = vals[0].atoi();

  // boolean flag: +ERR_INJECT
  if (clp.get_arg_matches("+ERR_INJECT", vals) > 0)
    cfg.inject_errors = 1'b1;

  // built-in verbosity is handled by UVM; log for replay
  if (clp.get_arg_values("+UVM_VERBOSITY=", vals) > 0)
    `uvm_info("CLI", $sformatf("verbosity=%s", vals[0]), UVM_LOW)
endfunction

Key takeaways

  • One configure_from_plusargs() method beats scattered $value$plusargs.

  • get_arg_values for +NAME=value; get_arg_matches for boolean flags.

  • Always convert string values before assigning to integral cfg fields.

Common pitfalls

  • Calling clp parsing in env or agent instead of test layer.

  • Assuming atoi succeeds on empty or malformed strings.

  • Re-parsing plusargs in child tests with conflicting defaults.


Built-in plusargs tests rely on

Regression scripts should standardize built-in UVM plusargs before adding custom project flags.

Common built-ins

  • +UVM_TESTNAME=<class> — factory test selection.

  • +UVM_VERBOSITY=<level> — global message filter.

  • +UVM_TIMEOUT=<time>,<overridable> — global watchdog.

  • +UVM_MAX_QUIT_COUNT=<n> — stop after n UVM_ERROR.

  • +uvm_set_config_int=<path>,<field>,<value> — config_db injection from CLI.

bash
simv +UVM_TESTNAME=stress_backpressure_test \
     +UVM_VERBOSITY=UVM_MEDIUM \
     +UVM_MAX_QUIT_COUNT=10 \
     +UVM_TIMEOUT=5000000,YES \
     +ntb_random_seed=4242

Logging resolved CLI

systemverilog
function void log_resolved_cfg();
  `uvm_info("CFG_RESOLVED",
    $sformatf("seq_count=%0d inject=%0b seed=%0d",
      cfg.seq_count, cfg.inject_errors, $get_initial_random_seed()),
    UVM_LOW)
endfunction
diagram
[TEST][UVM] replay bundle

persist in failure logs:
  +UVM_TESTNAME
  simulator seed option
  custom knobs (+SEQ_COUNT, +MODE, ...)
  build/git identifier

Common pitfalls

  • Relying on custom flags when a built-in UVM plusarg already exists.

  • Not logging resolved values — failures become non-replayable.

  • Parsing +uvm_set_config_* manually when UVM handles injection.