Part 7 · Environment & Tests · Intermediate
Factory Overrides in Tests: Explicit, Local, Reviewable
Factory override strategy for tests so substitutions remain intentional, scoped, and debuggable across regressions.
Override intent and scope
Use factory overrides to switch behavior without rewriting env code, but keep overrides localized and discoverable .
[TEST][UVM] override scope ladder
global (discouraged for scenario tests)
set_type_override_by_type
instance (preferred)
set_inst_override_by_type("env.agt*.drv")
late dynamic override
avoid unless debugging special-case behaviorvirtual function void apply_factory_overrides();
my_driver::type_id::set_inst_override(
debug_driver::get_type(),
"uvm_test_top.env.agt_tx.drv"
);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
apply_factory_overrides();
endfunctionKey takeaways
Instance overrides preserve scenario isolation.
Apply overrides before component creation in build_phase.
Log active overrides every test run.
Common pitfalls
Silent global overrides leaking into unrelated tests.
Applying overrides after env creation.
No audit trail linking override to scenario intent.
Override hygiene and diagnostics
Treat factory behavior as part of test API; failures are often override-scope mistakes.
Override report snippet
function void report_overrides();
uvm_factory f = uvm_factory::get();
f.print(1);
endfunction[TEST] override sanity checklist
- expected class replaced?
- expected instance path matched?
- one scenario, one override purpose?
- regression seed reproduces replacement?Conflict management
Avoid setting same instance override in multiple helper methods.
Keep override definitions near scenario configuration.
Use dedicated debug tests for broad experimental overrides.
[UVM][TEST] conflict pattern
base_test applies override A
child_test applies override B on same target
result:
last-writer wins, intent becomes unclear
fix:
centralize in apply_factory_overrides() with explicit orderingCommon pitfalls
Interleaving override setup with randomization side effects.
Relying on class-name strings instead of type-safe handles.
No CI guard to detect accidental global override additions.