uvm_component Fundamentals
Learn how UVM builds a hierarchical testbench from reusable components, how parent-child relationships work, and how components are created and identified.
Learning objectives
- Explain what
uvm_componentrepresents in a UVM testbench. - Distinguish a
uvm_componentfrom auvm_object. - Understand the UVM component hierarchy and parent-child relationships.
- Create a custom component using the correct constructor pattern.
- Register a component with the UVM factory.
- Create components using
type_id::create(). - Use
get_name()andget_full_name()to inspect hierarchy. - Understand why UVM components use phases instead of a simple
initialblock.
Step 1: What is uvm_component?
In the previous lesson, you learned that uvm_object is the
foundation for many data-oriented UVM classes.
uvm_component serves a different purpose.
It is the foundation for the structural elements of a UVM testbench.
A component represents something that exists as part of the testbench, has a position in the UVM hierarchy, and participates in the UVM simulation lifecycle.
Common UVM components include:
- Tests
- Environments
- Agents
- Drivers
- Monitors
- Scoreboards
- Subscribers
- Sequencers
uvm_object usually represents data.
uvm_component usually represents structure and behavior
inside the testbench.
Step 2: uvm_object vs uvm_component
This distinction is fundamental to understanding UVM.
| uvm_object | uvm_component |
|---|---|
| Primarily represents data | Primarily represents testbench structure |
| Does not belong to the component hierarchy | Belongs to the UVM component hierarchy |
| Does not have a parent component | Normally has a parent component |
| Examples: transactions and configuration objects | Examples: drivers, monitors, agents, environments |
| Created with an object-style constructor | Created with a name and parent |
uvm_object family.
A driver is part of the testbench structure and belongs to the
uvm_component family.
Step 3: Understand the UVM hierarchy
UVM components form a tree. Each component can contain child components.
A simplified testbench hierarchy might look like this:
uvm_test_top
|
+-- env
|
+-- agent
|
+-- sequencer
|
+-- driver
|
+-- monitor
|
+-- scoreboard
The hierarchy is not just for organization. UVM uses it to manage component construction, configuration, phases, reporting, and other framework services.
The most important concept at this stage is:
parent
|
+-- child
|
+-- child
When you create a component, you normally specify its parent. That establishes where the component belongs in the UVM hierarchy.
Step 4: Create a simple component
Let's create a very small component called my_component.
class my_component extends uvm_component;
function new(string name = "my_component",
uvm_component parent = null);
super.new(name, parent);
endfunction
endclass
Compare this constructor with the uvm_object constructor
from the previous lesson.
// uvm_object
function new(string name = "packet");
super.new(name);
endfunction
// uvm_component
function new(string name = "my_component",
uvm_component parent = null);
super.new(name, parent);
endfunction
The important difference is the additional
parent argument.
Step 5: Register the component with the factory
Just like uvm_object classes, UVM components can be registered
with the factory.
The component registration macro is:
`uvm_component_utils(my_component)
The complete class becomes:
class my_component extends uvm_component;
`uvm_component_utils(my_component)
function new(string name = "my_component",
uvm_component parent = null);
super.new(name, parent);
endfunction
endclass
Notice the difference from Lesson 13:
// Object
`uvm_object_utils(packet)
// Component
`uvm_component_utils(my_component)
The macro matches the type of UVM class being registered.
Step 6: Create a parent and child component
Now let's create two components and connect them through the hierarchy.
class child_component extends uvm_component;
`uvm_component_utils(child_component)
function new(string name = "child_component",
uvm_component parent = null);
super.new(name, parent);
endfunction
endclass
class parent_component extends uvm_component;
child_component child;
`uvm_component_utils(parent_component)
function new(string name = "parent_component",
uvm_component parent = null);
super.new(name, parent);
endfunction
endclass
The class definitions alone do not establish a hierarchy. A child must actually be created with the parent component.
The normal UVM pattern is to create child components in
build_phase().
Step 7: Create components in build_phase()
UVM components are normally constructed during the UVM build phase. For now, focus only on the creation pattern.
function void build_phase(uvm_phase phase);
super.build_phase(phase);
child = child_component::type_id::create("child", this);
endfunction
The important line is:
child = child_component::type_id::create("child", this);
The two important arguments are:
"child"— the name of the new component.this— the current component, which becomes the parent.
If this is parent_component, the resulting hierarchy is:
parent_component
|
+-- child
type_id::create("name", this).
The this argument establishes the parent-child relationship.
Step 8: Understand component names
Every UVM component has a local name and a hierarchical full name.
Suppose we have:
uvm_test_top
|
+-- env
|
+-- agent
|
+-- driver
The driver has the local name:
driver
But its full hierarchical name is:
uvm_test_top.env.agent.driver
You can inspect these names with:
$display("Name = %s", driver.get_name());
$display("Full name = %s", driver.get_full_name());
This becomes extremely useful when debugging large UVM environments. Instead of seeing an anonymous object, a report can identify exactly where the component lives.
uvm_test_top.env.agent.driver,
that path tells you exactly which component produced the message.
Step 9: A small working example
Let's combine the concepts into a small component hierarchy.
class child_component extends uvm_component;
`uvm_component_utils(child_component)
function new(string name = "child_component",
uvm_component parent = null);
super.new(name, parent);
endfunction
endclass
class parent_component extends uvm_component;
child_component child;
`uvm_component_utils(parent_component)
function new(string name = "parent_component",
uvm_component parent = null);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
child = child_component::type_id::create("child", this);
endfunction
function void end_of_elaboration_phase(uvm_phase phase);
super.end_of_elaboration_phase(phase);
`uvm_info("HIERARCHY",
$sformatf("Child full name: %s",
child.get_full_name()),
UVM_LOW)
endfunction
endclass
If this component is itself placed below the standard UVM test, you would see a hierarchical name similar to:
uvm_test_top.parent.child
The exact path depends on where the component is instantiated.
Step 10: Why does UVM use phases?
A normal SystemVerilog class can perform work from an
initial block or a task.
UVM components are different because the framework needs to coordinate
an entire hierarchy of components.
UVM therefore provides standardized phases such as:
build_phase()
connect_phase()
end_of_elaboration_phase()
start_of_simulation_phase()
run_phase()
check_phase()
report_phase()
final_phase()
Each component can implement the phases it needs. The UVM framework calls those phases across the component hierarchy.
You do not need to memorize the complete phase system yet. That is the subject of Lessons 21–26.
Step 11: The component creation pattern
You will see this pattern hundreds of times in real UVM environments.
class my_component extends uvm_component;
`uvm_component_utils(my_component)
function new(string name = "my_component",
uvm_component parent = null);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
// Create child components here
child = child_component::type_id::create("child", this);
endfunction
endclass
Learn to recognize the four major pieces:
extends uvm_component— makes the class a UVM component.`uvm_component_utils— registers the type with the factory.new(name, parent)— gives the component its name and parent.type_id::create("child", this)— creates a child through the factory.
Step 12: What belongs in a component?
A component normally represents a persistent part of the verification environment.
For example:
class my_monitor extends uvm_component;
// Monitor behavior
endclass
class my_driver extends uvm_component;
// Driver behavior
endclass
class my_scoreboard extends uvm_component;
// Checking behavior
endclass
These components may contain state, communicate with other components, participate in phases, and run simulation behavior.
By contrast, a packet is usually data:
class packet extends uvm_object;
// Transaction data
endclass
uvm_component.
Data is usually a uvm_object.
Try it yourself
Build a small two-level UVM component hierarchy.
- Create a class called
my_envthat extendsuvm_component. - Register it with
`uvm_component_utils. - Add the correct
new(name, parent)constructor. - Create a child component called
my_agent. - Create the agent with
my_agent::type_id::create("agent", this). - Use
get_name()to print the agent's local name. - Use
get_full_name()to print its hierarchical name.
scoreboard.
Predict its full hierarchical name before running the simulation.
Quick check
Question 1: What is the main purpose of uvm_component?
Question 2: Why does a component constructor have a parent argument?
Question 3: What does this mean in this statement?
agent = my_agent::type_id::create("agent", this);
this refers to the current component.
It becomes the parent of the newly created agent.
Question 4: What is the difference between get_name() and get_full_name()?
get_name() returns the component's local name.
get_full_name() returns its complete hierarchical path.
Question 5: Should a transaction normally extend uvm_component?
uvm_object family.
Key takeaways
-
uvm_componentis the foundation for structural elements of a UVM testbench. - Components form a hierarchical tree of parent and child components.
-
A component constructor normally receives a
nameandparent. -
`uvm_component_utilsregisters a component with the UVM factory. -
Child components are commonly created with
type_id::create("name", this). -
get_name()returns a local component name. -
get_full_name()returns the component's hierarchical path. - Components participate in the UVM phase mechanism.
-
Data-oriented classes generally extend
uvm_object, while testbench structure generally extendsuvm_component.
What's next?
UVM components often contain many data fields, and manually writing code to print, copy, compare, and manipulate those fields can become repetitive.
In the next lesson, we introduce UVM field automation macros and learn how UVM can automatically operate on registered object fields.