Test Architecture
Build a UVM test that configures the environment, selects a scenario, starts stimulus, and controls when verification is complete.
Learning objectives
- Explain the responsibility of a UVM test.
- Build a test that extends
uvm_testand creates an environment. - Configure an environment and its agents from the test layer.
- Start a sequence on an agent's sequencer.
- Use objections to keep the test running while meaningful stimulus is executing.
- Separate test-specific scenario decisions from reusable environment architecture.
- Trace a complete simulation from
run_test()to sequence, DUT activity, checking, and reporting.
Step 1: What is a UVM test?
The test is the top-level UVM component that selects how a verification environment should be configured and what scenario should run.
The environment from the previous lesson provides reusable infrastructure. The test decides how to use that infrastructure for a particular verification goal.
Test
|
+-- creates/configures Environment
|
+-- selects Sequence
|
+-- starts stimulus
|
+-- controls test completion
A test should answer questions such as:
- Which environment configuration should be used?
- Which agents should be active or passive?
- Which sequence should run?
- What scenario is this test intended to verify?
Step 2: See the complete UVM hierarchy
A small UVM testbench might have this hierarchy:
uvm_test_top
└── env
├── agent
│ ├── sequencer
│ ├── driver
│ └── monitor
├── scoreboard
└── coverage
The test is at the top of the UVM component hierarchy. It owns the environment, while the environment owns its verification components.
This ownership relationship matters:
Test
|
+---- Environment
|
+---- Agent
| +---- Sequencer
| +---- Driver
| +---- Monitor
|
+---- Scoreboard
|
+---- Coverage Step 3: Create a basic test
A UVM test normally extends uvm_test.
It creates the environment in build_phase().
class basic_test extends uvm_test;
`uvm_component_utils(basic_test)
bus_env env;
function new(string name = "basic_test",
uvm_component parent = null);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
env = bus_env::type_id::create(
"env", this);
endfunction
endclass
The test now owns an instance of the reusable environment. It does not create the environment's driver, monitor, scoreboard, or coverage components directly.
Step 4: Configure the environment
Tests are a natural place to provide test-specific configuration. For example, the test can configure an agent with its virtual interface and active/passive mode.
function void build_phase(uvm_phase phase);
bus_agent_cfg cfg;
super.build_phase(phase);
env = bus_env::type_id::create(
"env", this);
cfg = bus_agent_cfg::type_id::create(
"cfg");
cfg.vif = bus_vif;
cfg.is_active = UVM_ACTIVE;
uvm_config_db#(bus_agent_cfg)::set(
this,
"env.agent",
"cfg",
cfg
);
endfunction
The test can therefore change configuration without changing the environment's source code.
Same environment
|
+---- Smoke test
| active agent
|
+---- Monitor-only test
| passive agent
|
+---- Regression test
selected configuration
This is one of the foundations of UVM reuse.
Step 5: Select a sequence
The test also decides what stimulus scenario should execute. The actual transaction generation belongs in a sequence.
class smoke_test extends uvm_test;
`uvm_component_utils(smoke_test)
bus_env env;
function new(string name = "smoke_test",
uvm_component parent = null);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
env = bus_env::type_id::create(
"env", this);
endfunction
task run_phase(uvm_phase phase);
bus_sequence seq;
phase.raise_objection(this);
seq = bus_sequence::type_id::create(
"seq");
seq.start(env.agent.sequencer);
phase.drop_objection(this);
endtask
endclass
Notice the division of responsibility:
| Layer | Responsibility |
|---|---|
| Test | Selects and starts the scenario |
| Sequence | Generates sequence items |
| Sequencer | Manages sequence items for the driver |
| Driver | Converts transactions into protocol activity |
| Monitor | Observes and reconstructs transactions |
| Scoreboard | Checks correctness |
Step 6: Understand the test's run phase
The test's run_phase() is commonly used to launch scenario activity.
Because sequence execution takes simulation time, run_phase() is a task.
task run_phase(uvm_phase phase);
phase.raise_objection(this);
seq.start(env.agent.sequencer);
phase.drop_objection(this);
endtask
Conceptually:
Raise objection
|
v
Start sequence
|
v
Generate transactions
|
v
Driver sends traffic
|
v
DUT processes traffic
|
v
Monitor observes
|
v
Scoreboard checks
|
v
Sequence completes
|
v
Drop objection
The objection indicates that the test still has work that must be completed as part of the run-phase activity.
Step 7: Understand why objections matter
A testbench contains many components running concurrently. A test should not assume that simulation completion can be represented simply by "wait 1000 ns."
Instead, the test can keep its run-phase activity active while its scenario is executing.
phase.raise_objection(this);
seq.start(env.agent.sequencer);
// The scenario has completed.
phase.drop_objection(this);
This creates a meaningful relationship between the scenario and phase completion. When the test has completed its required work, it releases its objection.
Step 8: Do not put protocol behavior in the test
The test should select a scenario, not implement the bus protocol.
Prefer:
test
|
+--> sequence
|
+--> transaction
|
v
driver
|
v
bus_if
|
v
DUT
Avoid writing protocol-level signal manipulation directly in the test:
// Poor architecture
task run_phase(uvm_phase phase);
vif.valid = 1;
vif.write = 1;
vif.addr = 8'h10;
vif.data = 8'hAA;
@(posedge vif.clk);
vif.valid = 0;
endtask
This bypasses the reusable sequence, sequencer, and driver architecture. It also makes the test tightly coupled to the interface implementation.
Instead, the test should start a sequence containing the desired transaction. The driver handles the protocol details.
Step 9: Create different tests from the same environment
Once the environment is reusable, multiple tests can use it without duplicating the environment implementation.
bus_env
^
+---------+---------+
| | |
| | |
smoke_test reset_test random_test
| | |
v v v
sequence sequence sequence
For example:
- Smoke test: a few simple transactions.
- Reset test: verify behavior around reset.
- Directed test: target a known requirement or corner case.
- Random test: generate many legal transaction combinations.
The environment remains essentially the same. The test and sequence determine the scenario.
Step 10: Start the test from the HDL top
The SystemVerilog top-level module typically creates the interface, connects the DUT,
configures the virtual interface, and calls run_test().
module tb_top;
logic clk;
bus_if bus_vif(clk);
dut u_dut (
.clk (clk),
.reset (bus_vif.reset),
.valid (bus_vif.valid),
.ready (bus_vif.ready),
.write (bus_vif.write),
.addr (bus_vif.addr),
.data (bus_vif.data)
);
initial begin
uvm_config_db#(virtual bus_if)::set(
null,
"uvm_test_top.env.agent.*",
"vif",
bus_vif
);
run_test();
end
endmodule
A specific test can be selected by the simulator, command line, or another supported test-selection mechanism:
run_test("smoke_test");
The important flow is:
HDL top
|
v
run_test()
|
v
UVM test
|
v
Environment
|
v
Agent
|
v
Sequence
|
v
Driver
|
v
DUT Step 11: Understand factory-based test selection
UVM tests are normally registered with the factory:
`uvm_component_utils(smoke_test)
This allows the test to participate in UVM's standard factory-based construction and test-selection mechanisms.
The test class is therefore a reusable scenario definition rather than a special simulation-only block.
run_test() starts the UVM test.
The test builds/configures the environment and starts the scenario.
Step 12: Keep checking inside the environment
The test should not normally compare every DUT result itself. Checking belongs in reusable verification components such as scoreboards and reference models.
TEST
|
+---- starts sequence
|
v
ENVIRONMENT
|
+---- AGENT ----> DUT
| |
| v
| MONITOR
| |
| +-------> SCOREBOARD
| |
| +-------> COVERAGE
|
+---- REFERENCE MODEL
This allows the same checking infrastructure to be reused by many tests.
A test can therefore focus on the question: "What scenario should I execute?" rather than: "How do I manually check every signal?"
Step 13: A complete small test
Put the main concepts together:
class smoke_test extends uvm_test;
`uvm_component_utils(smoke_test)
bus_env env;
function new(string name = "smoke_test",
uvm_component parent = null);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
bus_agent_cfg cfg;
super.build_phase(phase);
env = bus_env::type_id::create(
"env", this);
cfg = bus_agent_cfg::type_id::create(
"cfg");
cfg.vif = bus_vif;
cfg.is_active = UVM_ACTIVE;
uvm_config_db#(bus_agent_cfg)::set(
this,
"env.agent",
"cfg",
cfg
);
endfunction
task run_phase(uvm_phase phase);
bus_sequence seq;
phase.raise_objection(this);
seq = bus_sequence::type_id::create(
"seq");
seq.start(env.agent.sequencer);
phase.drop_objection(this);
endtask
endclass
The test now has a clear lifecycle:
- Create the environment.
- Configure the environment.
- Enter the run phase.
- Raise an objection.
- Create and start a sequence.
- Allow the sequence to generate stimulus through the agent.
- Let monitors, scoreboards, and coverage operate concurrently.
- Drop the objection when the test's scenario is complete.
Step 14: Debug test architecture
If a test runs but no useful verification occurs, trace the control flow from the top.
run_test()
|
v
Test created?
|
v
build_phase()
|
+--> Environment created?
|
+--> Configuration available?
|
v
run_phase()
|
+--> Objection raised?
|
+--> Sequence created?
|
+--> Sequence started?
|
v
Sequencer
|
v
Driver
|
v
DUT
|
v
Monitor
|
+----> Scoreboard
|
+----> Coverage
|
v
Objection dropped
This gives you a practical debugging order:
- Verify the intended test was actually selected.
- Verify the environment was constructed.
- Verify configuration reached the environment and agent.
- Verify the active agent contains a sequencer and driver.
- Verify the sequence started on the correct sequencer.
- Verify the driver received sequence items.
- Verify the DUT received protocol activity.
- Verify the monitor observed transactions.
- Verify the scoreboard and coverage received observations.
- Verify the test eventually drops its objection.
Step 15: Common test architecture mistakes
| Mistake | Problem | Better approach |
|---|---|---|
| Creating drivers directly in the test | Breaks agent encapsulation | Let the environment/agent own protocol components |
| Driving interface signals from the test | Bypasses the reusable driver | Start sequences and let the driver implement the protocol |
| Putting scoreboard logic in the test | Duplicates checking across tests | Keep checking in reusable verification components |
| Hard-coding one scenario into the environment | Makes the environment difficult to reuse | Put scenario selection in tests and sequences |
| Raising an objection without dropping it | Can prevent phase completion | Pair every test-owned objection with a clear completion point |
| Using arbitrary delays as completion control | Can be fragile and hide real synchronization problems | Tie completion to meaningful scenario activity |
| Starting a sequence on the wrong sequencer | Stimulus may never reach the intended driver | Verify the sequence-to-sequencer path |
Try it yourself
Create a smoke_test for the bus_env from Lesson 53.
- Extend
uvm_test. - Create the environment in
build_phase(). - Configure the bus agent as active.
- Write or reuse a short directed sequence.
- Raise an objection at the beginning of
run_phase(). - Start the sequence on
env.agent.sequencer. - Drop the objection after the sequence completes.
- Confirm that the driver receives transactions.
- Confirm that the monitor publishes observations.
- Confirm that the scoreboard reports its result.
bus_env but a different sequence.
Do not modify the environment. Your two tests should represent different scenarios
while sharing the same verification infrastructure.
Key takeaways
- The UVM test is the top-level scenario and configuration layer.
- The test creates the environment; the environment creates its verification components.
- Tests can configure agents without changing reusable environment code.
- Sequences define stimulus scenarios; tests select and start those sequences.
- Drivers implement protocol behavior, so tests should not directly manipulate DUT interface signals.
- Scoreboards and coverage belong in reusable verification infrastructure rather than individual test logic.
- Objections coordinate meaningful test activity with run-phase completion.
- Multiple tests can reuse the same environment while exercising different scenarios.
Core mental model
Think of the test as the director of the verification environment. It does not perform every job itself. It selects the configuration and tells the reusable verification infrastructure what scenario to execute.
TEST
+----------------+
| Configure |
| Select scenario|
| Start sequence |
+-------+--------+
|
v
ENVIRONMENT
+----------------+
| Agents |
| Scoreboard |
| Reference model|
| Coverage |
+-------+--------+
|
v
DUT
The clean separation is:
- Test: Which scenario?
- Sequence: Which transactions?
- Agent: How does the protocol work?
- Environment: How do the verification components connect?
- Scoreboard: Is the behavior correct?
- Coverage: What behavior was exercised?
The test chooses the scenario; the environment provides the infrastructure.
What comes next?
In the next lesson, you will connect the pieces of the environment explicitly. Connecting the Environment will bring together agents, monitors, scoreboards, reference models, and analysis connections into one complete UVM verification data flow.