Advanced UVM: Modeling Transactions
Advanced UVM: Modeling Transactions
Modeling Transactions
Tom Fitzpatrick
Strategic Verification Architect
Separating Stimulus from the Testbench
A key to reusability is to separate Behavior from Structure
Transactions (a.k.a. Sequence Items) are the main communication vehicle
across the boundary
Behavior
Structure
Testbench VIP
DUT
Virtual method
do_copy()
do_compare()
convert2string()
do_print()
do_record()
endfunction
do_pack()
do_unpack()
endclass: bus_item
5 Unrestricted | © Siemens | Verification Academy: Advanced UVM | March 2021
Designing a Sequence Item: Methods
class bus_item extends uvm_sequence_item; do_copy()
`uvm_object_utils(bus_item)
endfunction: do_copy
endclass: bus_item
6 Unrestricted | © Siemens | Verification Academy: Advanced UVM | March 2021
Designing a Sequence Item: Methods
class bus_item extends uvm_sequence_item; do_copy()
`uvm_object_utils(bus_item)
endfunction: do_copy
endclass: bus_item
7 Unrestricted | © Siemens | Verification Academy: Advanced UVM | March 2021
Designing a Sequence Item: Methods
class bus_item extends uvm_sequence_item; do_copy()
`uvm_object_utils(bus_item)
endclass: bus_item
8 Unrestricted | © Siemens | Verification Academy: Advanced UVM | March 2021
Designing a Sequence Item: Methods
class bus_item extends uvm_sequence_item; do_copy()
`uvm_object_utils(bus_item)
endfunction: do_compare
endclass: bus_item
10 Unrestricted | © Siemens | Verification Academy: Advanced UVM | March 2021
Designing a Sequence Item: Methods
class bus_item extends uvm_sequence_item; do_copy()
`uvm_object_utils(bus_item) do_compare()
function bit do_compare(uvm_object rhs,
uvm_comparer comparer);
bus_item rhs_;
endfunction: do_compare
endclass: bus_item
11 Unrestricted | © Siemens | Verification Academy: Advanced UVM | March 2021
Designing a Sequence Item: Methods
class bus_item extends uvm_sequence_item; do_copy()
`uvm_object_utils(bus_item) do_compare()
function bit do_compare(uvm_object rhs,
uvm_comparer comparer);
bus_item rhs_;
endclass: bus_item
12 Unrestricted | © Siemens | Verification Academy: Advanced UVM | March 2021
Designing a Sequence Item: Methods
class bus_item extends uvm_sequence_item; do_copy()
`uvm_object_utils(bus_item) do_compare()
function string convert2string(); convert2string()
string s;
s = super.convert2string();
endfunction: convert2string
endclass: bus_item
13 Unrestricted | © Siemens | Verification Academy: Advanced UVM | March 2021
Designing a Sequence Item: Methods
class bus_item extends uvm_sequence_item; do_copy()
`uvm_object_utils(bus_item) do_compare()
function string convert2string(); convert2string()
string s;
s = super.convert2string();
$sformat(s,
"%s\n %s\n delay \t%0d\n addr \t%0h\n op_code \t%s\n slave_name \t%s\n",
s, this.get_name(), delay, addr, op_code.name(), slave_name);
Returns enum
value as a string
endfunction: convert2string
endclass: bus_item
14 Unrestricted | © Siemens | Verification Academy: Advanced UVM | March 2021
Designing a Sequence Item: Methods
class bus_item extends uvm_sequence_item; do_copy()
`uvm_object_utils(bus_item) do_compare()
function string convert2string(); convert2string()
string s;
endfunction: convert2string
endclass: bus_item
15 Unrestricted | © Siemens | Verification Academy: Advanced UVM | March 2021
Designing a Sequence Item: Methods
class bus_item extends uvm_sequence_item; do_copy()
`uvm_object_utils(bus_item) do_compare()
function string convert2string(); convert2string()
string s;
s = super.convert2string();
$sformat(s,
"%s\n %s\n delay \t%0d\n addr \t%0h\n op_code \t%s\n slave_name \t%s\n",
s, this.get_name(), delay, addr, op_code.name(), slave_name);
foreach(data[i]) begin
$sformat(s, "%s data[%0d] \t%0h\n", s, i, data[i]);
end
$sformat(s, "%s response \t%0b\n", s, response);
return s;
USAGE:
endfunction: convert2string bus_item A;
`uvm_info(“Bus_Item A”,A.convert2string(), UVM_NONE)
endclass: bus_item
16 Unrestricted | © Siemens | Verification Academy: Advanced UVM | March 2021
Designing a Sequence Item: Methods
class bus_item extends uvm_sequence_item; Printer policy do_copy()
`uvm_object_utils(bus_item) class do_compare()
function void do_print(uvm_printer printer); convert2string()
printer.print_field(“delay”, delay, $bits(delay), do_print()
UVM_DEC);
printer.print_field(“addr”, addr, $bits(addr));
printer.print_string(“opcode”, opcode.name());
printer.print_string(“slave_name”, slave_name);
printer.print_array_header(“data”, data.size);
foreach(data[i]) begin
printer.print_field($sformatf(“data[%0d]”, i), data[i], $bits(data[i]));
end
printer.print_array_footer();
printer.print_field(“response”, response, 1); USAGE:
endfunction: do_print bus_item A;
A.print();
endclass: bus_item
17 Unrestricted | © Siemens | Verification Academy: Advanced UVM | March 2021
Designing a Sequence Item: convert2string vs do_print
class bus_item extends uvm_sequence_item; do_copy()
`uvm_object_utils(bus_item) do_compare()
convert2string: convert2string()
# UVM_INFO tb.sv(73) @ 0: uvm_test_top [Bus_Item A] do_print()
# A
# delay 10
# addr abcd
# op_code ADD do_print:
# slave_name SLAVE1 # ----------------------------------------
# data[0] deadbeef # Name Type Size Value
# data[1] a0b1c2d3 # ----------------------------------------
# response 1 # A bus_item - @473
# delay integral 32 'd10
# addr integral 32 'habcd
# opcode string 3 ADD
# slave_name string 6 SLAVE1
# data array 2 -
# data[0] integral 32 'hdeadbeef
# data[1] integral 32 'ha0b1c2d3
# response integral 1 'h1
# ----------------------------------------
endclass: bus_item
18 Unrestricted | © Siemens | Verification Academy: Advanced UVM | March 2021
Designing a Sequence Item: Methods
class bus_item extends uvm_sequence_item; do_copy()
`uvm_object_utils(bus_item) do_compare()
function void do_record(uvm_recorder recorder); convert2string()
super.do_record(recorder); do_print()
do_record()
Record inherited
data members
endfunction: do_record
endclass: bus_item
19 Unrestricted | © Siemens | Verification Academy: Advanced UVM | March 2021
Designing a Sequence Item: Methods
class bus_item extends uvm_sequence_item; do_copy()
`uvm_object_utils(bus_item) do_compare()
function void do_record(uvm_recorder recorder); convert2string()
super.do_record(recorder); do_print()
`uvm_record_field("delay", delay) do_record()
`uvm_record_field("addr", addr)
`uvm_record_field("op_code", op_code.name())
`uvm_record_field("slave_name", slave_name)
Simulator-specific implementation
Questa uses $add_attribute
endfunction: do_record
endclass: bus_item
20 Unrestricted | © Siemens | Verification Academy: Advanced UVM | March 2021
Designing a Sequence Item: Methods
class bus_item extends uvm_sequence_item; do_copy()
`uvm_object_utils(bus_item) do_compare()
function void do_record(uvm_recorder recorder); convert2string()
super.do_record(recorder); do_print()
`uvm_record_field("delay", delay) do_record()
`uvm_record_field("addr", addr)
`uvm_record_field("op_code", op_code.name())
`uvm_record_field("slave_name", slave_name)
USAGE:
uvm_config_db#(int)::set(this,”*”,”recording_detail”, UVM_FULL);
endclass: bus_item
21 Unrestricted | © Siemens | Verification Academy: Advanced UVM | March 2021
Designing a Sequence Item: Methods
class bus_item extends uvm_sequence_item; do_copy()
`uvm_object_utils(bus_item) do_compare()
function void do_pack(uvm_packer packer); convert2string()
super.do_pack(packer); do_print()
… do_record()
endfunction: do_pack do_pack()
do_unpack()
function void do_unpack(uvm_packer packer);
super.do_unpack(packer);
…
endfunction: do_unpack
See the
Online UVM Cookbook
for details
endclass: bus_item
22 Unrestricted | © Siemens | Verification Academy: Advanced UVM | March 2021
Sequence Item Composition
bus_item my_bus_item
extends uvm_sequence_item; extends bus_item;
rand int delay; bit status;
rand logic[31:0] addr; logic[31:0] result;
rand op_code_enum op_code;
rand logic[31:0] data[];
bus_item_pair
extends uvm_sequence_item;
rand bus_item a;
rand bus_item b;
Tom Fitzpatrick
Strategic Verification Architect