Part 7 · Environment & Tests · Intermediate

+UVM_TESTNAME: Factory-Based Test Selection at Runtime

How run_test() with no argument uses +UVM_TESTNAME to instantiate the correct uvm_test class through the UVM factory.

run_test() and factory selection

Calling run_test() without a string argument tells UVM to read +UVM_TESTNAME=<class_name> and construct that test type via the factory registry.

diagram
[TEST][UVM] selection flow

simv +UVM_TESTNAME=burst_traffic_test
        │
        ▼
run_test()  (no arg)
        │
        ▼
uvm_factory::create_component_by_name("burst_traffic_test", ...)
        │
        ▼
uvm_test_top = burst_traffic_test instance
systemverilog
// tb/top.sv — thin bridge, no hardcoded test name
initial begin
  uvm_config_db#(virtual axi_if)::set(null, "*", "vif", axi_vif);
  run_test();  // honors +UVM_TESTNAME from command line
end
bash
# Regression selects scenario at runtime
./simv +UVM_TESTNAME=smoke_sanity_test
./simv +UVM_TESTNAME=protocol_illegal_len_test +ntb_random_seed=9001

Key takeaways

  • One simv binary can run the entire test library via +UVM_TESTNAME.

  • Factory registration (`uvm_component_utils) must include every runnable test.

  • Top module should call run_test() — not run_test("hardcoded_name").

Common pitfalls

  • Typo in test class name — factory error at runtime, not compile time.

  • Forgetting to include new test files in the tests package.

  • Mixing run_test("foo") in some builds and CLI selection in others.


Test registration and list hygiene

Test selection only works when every runnable test is compiled, registered, and named consistently.

Registration checklist

systemverilog
class smoke_sanity_test extends base_test;
  `uvm_component_utils(smoke_sanity_test)
  // ...
endclass

// tests_pkg must include the file:
`include "smoke/smoke_sanity_test.sv"
  • Class name must match +UVM_TESTNAME exactly (case-sensitive).

  • Use testlists (smoke.list, nightly.list) that reference class names.

  • Keep a generated manifest in CI to catch missing registrations.

Explicit vs CLI selection

diagram
[TEST] when to pass run_test("name")

debug single test in IDE:
  run_test("repro_bug_441_test")  // OK for local debug

production / CI default:
  run_test()  // always prefer +UVM_TESTNAME
bash
# testlist-driven loop
for t in $(cat nightly.list); do
  ./simv +UVM_TESTNAME=$t +ntb_random_seed=$RANDOM || exit 1
done

Common pitfalls

  • Renaming test classes without updating testlists and dashboards.

  • Runnable tests left out of package includes — silent omission from regressions.

  • Using display names in scripts instead of exact SystemVerilog class names.