Module 2: UVM Foundations | Beginner UVM

uvm_object Fundamentals

Learn how UVM represents reusable data objects, registers them with the factory, and creates them using the standard UVM object pattern.

Learning objectives

  • Explain what uvm_object represents in UVM.
  • Distinguish a uvm_object from a uvm_component.
  • Create a custom UVM object by extending uvm_object.
  • Register an object with the UVM factory.
  • Create an object using type_id::create().
  • Use object names and type information to debug a UVM testbench.
  • Print an object with print() and sprint().

Step 1: What is uvm_object?

uvm_object is one of the most important base classes in UVM. It provides common behavior for data-oriented objects that are created, copied, printed, compared, recorded, or managed by the UVM factory.

In simple terms, think of a uvm_object as a reusable piece of verification data or configuration.

Beginner rule: If the thing you are creating represents data, a transaction, a sequence item, or configuration information, it will often be based on uvm_object.

A simplified UVM inheritance path looks like this:

uvm_object
|
+-- uvm_transaction
        |
        +-- uvm_sequence_item

Later, you will use uvm_sequence_item to represent protocol transactions. For now, focus on the base class: uvm_object.

Step 2: uvm_object vs uvm_component

One of the most important distinctions for a UVM beginner is the difference between an object and a component.

uvm_object uvm_component
Primarily represents data or reusable objects Represents structural parts of the testbench
Does not participate in the UVM component hierarchy Belongs to the UVM component hierarchy
Examples: transactions, configuration objects Examples: drivers, monitors, scoreboards
Created using an object-style constructor or factory Created with a parent component

You will study uvm_component in the next lesson. Keeping these two concepts separate will make the rest of UVM much easier to understand.

Common mistake: Do not assume every UVM class should extend uvm_component. A transaction is data, so it normally belongs in the uvm_object family instead.

Step 3: Create your first uvm_object

Let's create a simple packet object. We will deliberately extend uvm_object rather than uvm_sequence_item. Sequence items are introduced later when we start building stimulus.

class packet extends uvm_object;


bit [7:0] addr;
bit       write;
bit [7:0] data;

function new(string name = "packet");
super.new(name);
endfunction

endclass

There are three important ideas in this example.

  1. packet is a normal SystemVerilog class.
  2. It extends uvm_object, so it inherits UVM object functionality.
  3. The constructor calls super.new(name) so the base UVM object receives its name.
Connection to SystemVerilog: You already learned classes, inheritance, and constructors in the earlier SystemVerilog lessons. UVM builds on those same language features.

Step 4: Register the object with the factory

UVM uses a factory to make verification components and objects easier to replace and customize. Before an object can be created through the factory, its type needs to be registered with the factory.

The basic registration macro is:

`uvm_object_utils(packet)

Our complete class now becomes:

class packet extends uvm_object;


bit [7:0] addr;
bit       write;
bit [7:0] data;

`uvm_object_utils(packet)

function new(string name = "packet");
super.new(name);
endfunction

endclass

The macro connects the class to the UVM factory and also provides useful type information to UVM.

Do not memorize the macro yet. For now, remember the pattern: extends uvm_object + uvm_object_utils() makes a class available to standard UVM factory mechanisms.

Field automation macros such as uvm_field_int are intentionally not covered here. They are the focus of Lesson 15.

Step 5: Create the object directly

Because packet is a SystemVerilog class, you can create it directly with new().

packet pkt;


initial begin
pkt = new("pkt");

pkt.addr  = 8'h20;
pkt.write = 1'b1;
pkt.data  = 8'hA5;
end

This is normal SystemVerilog object construction. It does not use the UVM factory.

Direct construction is useful, but UVM provides another important pattern: factory-based creation.

Step 6: Create the object through the factory

Because we registered packet with the factory, we can create it using its generated type_id.

packet pkt;


initial begin
pkt = packet::type_id::create("pkt");

pkt.addr  = 8'h20;
pkt.write = 1'b1;
pkt.data  = 8'hA5;
end

The important line is:

pkt = packet::type_id::create("pkt");

Instead of directly calling new(), the code asks the UVM factory to create an object of the registered type.

Why does this matter? Factory creation allows a testbench to replace a type later without changing every place where that object is created. The factory becomes especially powerful when you learn factory overrides in Lessons 17 and 18.

For now, think of the difference this way:

// Direct SystemVerilog construction


pkt = new("pkt");

// UVM factory construction
pkt = packet::type_id::create("pkt");

Step 7: Understand object names and type names

UVM objects have names that can help you understand what is happening during simulation.

packet pkt;


initial begin
pkt = packet::type_id::create("pkt");

$display("Object name = %s", pkt.get_name());
$display("Type name   = %s", pkt.get_type_name());
end

You should see information similar to:

Object name = pkt


Type name   = packet

The distinction is useful when debugging:

  • get_name() tells you the name assigned to this particular object.
  • get_type_name() tells you the registered UVM type name.

Imagine a testbench containing several packet objects: req, rsp, and reset_pkt. Object names help you identify which instance you are looking at.

Step 8: Inspect an object with print() and sprint()

Debugging becomes much easier when you can inspect the contents of an object. UVM provides printing support through print() and sprint().

For example:

packet pkt;


initial begin
pkt = packet::type_id::create("pkt");

pkt.addr  = 8'h20;
pkt.write = 1'b1;
pkt.data  = 8'hA5;

pkt.print();
end

print() sends a formatted representation of the object to the simulator output.

sprint() returns the formatted representation as a string.

string text;


text = pkt.sprint();

$display("%s", text);
Debugging tip: When a transaction does not contain the values you expected, printing the object is often one of the fastest ways to find the problem.

In this lesson we are keeping the object simple. Later, UVM field automation will make printing and other object operations much more powerful.

Step 9: Put everything together

Here is the complete example:

class packet extends uvm_object;


bit [7:0] addr;
bit       write;
bit [7:0] data;

`uvm_object_utils(packet)

function new(string name = "packet");
super.new(name);
endfunction

endclass

module example;

packet pkt;

initial begin


// Create through the UVM factory
pkt = packet::type_id::create("pkt");

// Assign some test data
pkt.addr  = 8'h20;
pkt.write = 1'b1;
pkt.data  = 8'hA5;

// Show basic object information
$display("Object name = %s", pkt.get_name());
$display("Type name   = %s", pkt.get_type_name());

// Print the object
pkt.print();


end

endmodule

Trace the example in this order:

  1. The class extends uvm_object.
  2. The class is registered with uvm_object_utils.
  3. The factory creates the object with type_id::create().
  4. The test assigns values to the object.
  5. The test queries the object's name and type.
  6. The object is printed for debugging.

Step 10: What should you remember?

You do not need to understand every UVM macro at this point. The important mental model is:

SystemVerilog class
    |
    v


extends uvm_object
|
v
register with factory
|
v
type_id::create()
|
v
reusable UVM object

This pattern will appear repeatedly throughout the rest of UVM. Once you understand it here, later classes such as sequence items and configuration objects will be much easier to understand.

Try it yourself

Create a new UVM object called packet with three fields: addr, write, and data.

  1. Extend uvm_object.
  2. Add a constructor that calls super.new(name).
  3. Register the class with uvm_object_utils.
  4. Create the object using packet::type_id::create("pkt").
  5. Assign values to the three fields.
  6. Display get_name() and get_type_name().
  7. Call print() or sprint().
Challenge: Create two packet objects with different names, such as req and rsp. Print both and verify that their object names are different while their type name remains packet.

Quick check

Question 1: Which base class is intended for data-oriented UVM objects?

Answer: uvm_object.

Question 2: Which macro registers an object class with the UVM factory?

Answer: `uvm_object_utils(class_name).

Question 3: What is the difference between new() and type_id::create()?

Answer: new() directly constructs the SystemVerilog object, while type_id::create() requests object creation through the UVM factory.

Question 4: Is a driver normally derived directly from uvm_object?

Answer: No. A driver is a UVM component and is derived from uvm_component. We will study that in the next lesson.

Key takeaways

  • uvm_object is the foundation for many data-oriented UVM classes.
  • uvm_component is different: components form the structural hierarchy of the UVM testbench.
  • A custom UVM object normally extends uvm_object.
  • `uvm_object_utils registers the class with the UVM factory.
  • type_id::create() creates an object through the factory.
  • get_name() and get_type_name() are useful when debugging.
  • print() and sprint() help inspect object contents.
  • Sequence items are part of the uvm_object family, but their detailed use belongs to later lessons.

What's next?

An object represents data, but a UVM testbench also needs structural elements that build hierarchies, connect to other components, and participate in UVM phases.

In the next lesson, we move from data objects to those structural elements: uvm_component.