Part 7 · Environment & Tests · Intermediate
Config Object Factory: Typed Policy with Override Flexibility
Using factory-created configuration objects so policy can be specialized by test without changing env construction logic.
Why factory for cfg classes
Factory-created cfg objects let tests swap policy models while keeping env creation stable.
[TEST][UVM][ENV] cfg factory model
base cfg type:
env_cfg
scenario-specific cfg:
perf_env_cfg extends env_cfg
low_power_env_cfg extends env_cfg
test chooses cfg subtype via factory or direct createclass env_cfg extends uvm_object;
`uvm_object_utils(env_cfg)
rand int unsigned num_agents;
rand bit enable_cov;
string mode;
endclass
class perf_env_cfg extends env_cfg;
`uvm_object_utils(perf_env_cfg)
rand int unsigned max_outstanding;
endclassKey takeaways
Cfg classes are first-class API, not throwaway containers.
Factory allows controlled specialization by scenario family.
Typed cfg fields improve debug and refactoring safety.
Common pitfalls
Using untyped associative arrays instead of cfg objects.
Deep cfg inheritance without clear ownership.
Factory overrides that are not logged in test startup.
Cfg factory workflow
Tie cfg creation to test intent and preserve visibility through startup logs.
Creation and cast pattern
function env_cfg make_cfg();
env_cfg c;
c = env_cfg::type_id::create("cfg");
if (!$cast(c, c))
`uvm_fatal("CFG_CAST", "cfg create cast failed")
return c;
endfunctionvirtual function void configure_scenario_cfg(ref env_cfg c);
perf_env_cfg pc;
if ($cast(pc, c)) begin
pc.max_outstanding = 64;
pc.mode = "PERF";
end
endfunctionReview checklist
Every cfg subclass documents additional required fields.
Scenario code checks cast success before subtype assignments.
Factory print appears in logs for reproducibility.
Cfg object includes print/convert2string support.
[UVM] cfg subtype debugging
symptom: field assignment silently ignored
cause: base handle not cast to expected subtype
fix: explicit $cast with fatal on failureCommon pitfalls
Relying on subtype-specific fields without cast guards.
Mixing direct new() and factory create() unpredictably.
No regression coverage for each cfg subtype path.