Part 7 · Environment & Tests · Intermediate

Randomized Config from Test: Controlled Variation, Stable Triage

Generating constrained-random config objects in tests while preserving legality, reproducibility, and actionable debug.

Randomization strategy

Randomize cfg at test level to explore mode space, then push one coherent policy object into the env.

diagram
[TEST][UVM][ENV] random cfg flow

cfg = create()
cfg.apply_defaults()
if !cfg.randomize() with scenario constraints -> fatal
emit cfg summary
set cfg to env*
create env

seed + cfg summary must reproduce behavior
systemverilog
virtual function void build_phase(uvm_phase phase);
  super.build_phase(phase);
  cfg = env_cfg::type_id::create("cfg");
  cfg.apply_defaults();
  if (!cfg.randomize() with {
      num_agents inside {[1:4]};
      timeout_ns inside {[100_000:2_000_000]};
      !(enable_low_power && enable_max_perf);
    }) begin
    `uvm_fatal("CFG_RAND", "env_cfg randomize failed")
  end
  log_cfg(cfg);
  uvm_config_db#(env_cfg)::set(this, "env*", "cfg", cfg);
  env = my_env::type_id::create("env", this);
endfunction

Key takeaways

  • Randomize cfg once, then treat it as immutable test policy.

  • Constrain for legal architecture combinations.

  • Always log solved cfg fields with the seed.

Common pitfalls

  • Randomizing cfg in multiple components independently.

  • Leaving legality checks only to late runtime assertions.

  • No compact cfg summary in failure logs.


Legality and reproducibility

Separate constraint solving, legality validation, and scenario tagging to make random cfg runs debuggable.

Two-step quality gate

systemverilog
function bit is_legal_cfg(env_cfg c);
  if (c.num_agents == 0) return 0;
  if (c.enable_cov && !c.enable_scoreboard) return 0;
  if (c.max_outstanding > 64 && c.mode == "LOW_POWER") return 0;
  return 1;
endfunction

function void finalize_cfg(env_cfg c);
  if (!is_legal_cfg(c))
    `uvm_fatal("CFG_LEGAL", "illegal cfg combination")
endfunction
  • Do not rely on constraints alone for cross-field policy checks.

  • Tag cfg with scenario labels for dashboard grouping.

  • Promote high-value randomized cfgs into directed regression tests.

Debug packet format

diagram
[TEST] cfg debug packet

seed=12345
test=stress_backpressure_mix_test
cfg:
  num_agents=3
  timeout_ns=900000
  mode=PERF
  max_outstanding=48
  enable_cov=1
  enable_scoreboard=1
diagram
[UVM] triage rule

first reproduce with same:
  - test class
  - seed
  - cfg packet
then mutate one cfg dimension at a time

Common pitfalls

  • Changing constraints and expecting old seeds to behave identically.

  • Huge cfg dumps with no prioritized key fields.

  • Combining random cfg and random sequence chaos in first triage pass.