UVM - Reference Material
UVM - Reference Material
(UVM)
Presenting by
Chanda Prasanthi
Introduction
Why we need Methodology?
o Data Items
✔ It represents stimulus transaction that are input to the DUT.
✔ In a test, many data items are generated and sent in to the DUT.
✔ Examples: Network Packets, Instructions.
o Sequencer
✔ It is an advance stimulus generator that generates and returns data
items upon request from the driver.
✔ A sequencer has an ability to react to the current state of DUT and
generate more useful data items by changing randomization weights.
o Monitor
✔ It is a passive entity that samples DUT signals but does not drive them.
✔ They are useful in collecting coverage and checking performance.
✔ It can also be used to predict result based on sampled inputs and
verifying them against sampled outputs.
Universal Verification Components
o Agent
✔ They are used to encapsulate driver, sequencer and monitor.
✔ An UVC can contain more than one agent.
✔ Different agents can be used to target different protocols in an
SOC based example.
✔ Agents can be configured as active and passive.
✔ Active agents are one which emulates devices and drives DUT’s
ports.
✔ Passive agents only monitors DUT activity.
Universal Verification Components
o Environment
✔ It is top-level component of an UVC.
✔ It can contain one or more agents.
✔ It can also contain Score Boards that are used to perform
end-to-end transmission checks or perform checks against
reference models.
Test Bench Hierarchy
Test Bench Hierarchy
A1 A2
Sq S C S C
D M1 D M2
DUT
UVM Class Library
UVM Library
`include “uvm_pkg.sv”
//include for compiling if not available by default
import uvm_pkg :: *;
//importing definitions inside uvm_pkg
module hello_world;
initial
`uvm_info(“info1”, “Hello World”, UVM_LOW);
endmodule
UVM Library : Base Classes
uvm_void
uvm_object
Copy(), print() etc uvm_transaction
uvm_report_object uvm_sequence_item
uvm_component
all phases uvm_sequence
task body()
user component
uvm_test, uvm_env
etc
Features of Base Classes
⚫ uvm_object class is the base class for all UVM data and
hierarchical classes.
o Defines set of methods for common operations such as create,
copy, compare, print, etc.
Features of Base Classes
//Class constructor
function new (string name=“mem_transaction”);
super.new(name);
endfunction
Example2
module top;
import uvm_pkg:: *; //importing UVM Library
`include “uvm_macros.svh” //including UVM Macros
`include “mem_transaction.sv” //including user-defined class
initial begin
a1=mem_transaction :: type_id :: create(“a1”);
//creating object using factory create method, which supports
//overriding, using new will restrict overriding
…………………………………. //On Next slide
endmodule
Example2
assert(a1.randomize()) else
`uvm_fatal(“RFAIL”, “Randomization Failed”)
a2=mem_transaction :: type_id :: create(“a2”);
a2.copy(a1); //copy a1 to a2
$cast(a3, a1.clone()); //create new object of type a1
//and then copy to a3
if(!a3.compare(a2))
`uvm_error(“CFAIL”, “Comparison Failed”)
a1.print();
a2.print(default_line_printer);
a3.print(default_line_printer);
end
Result
Table Printer :
# -------------------------------------
# Name Type Size Value
# -------------------------------------
# a1 mem_transaction - @457
# data integral 8 'h50
# addr integral 4 'he
# dir direction 2 READ
#delay integral 4 'hb
# -------------------------------------
Result
Tree Printer :
# a2: (mem_transaction@458) {
# data: 'h50
# addr: 'he
# dir: READ
# delay: 'hb
#}
Line Printer :
# a1: (mem_transaction@459) { data: 'h50 addr: 'he dir: READ
delay: 'hb }
uvm_transaction
uvm_transaction
uvm_sequence_item
uvm_sequence
uvm_sequence methods
uvm_component
⚫ Only one instance of UVM Factory can exist during entire simulation
(singleton).
⚫ Non-Parameterized Objects:
class packet extends uvm_object;
`uvm_object_utils(packet)
endclass
⚫ Parameterized Objects:
class packet #(type T=int, int Width=32)extends uvm_object;
`uvm_object_param_utils(packet #(T, Width))
endclass
Registering with Factory
⚫ Non-Parameterized Components:
class comp extends uvm_component;
`uvm_component_utils(comp)
endclass
⚫ Parameterized Components:
class comp #(type T=int, int Width=32) extends
uvm_component;
`uvm_component_param_utils(comp #(T, Width))
endclass
UVM Field Macros
`uvm_field_array_int()
`uvm_field_array_object() Dynamic and Static Arrays
`uvm_field_array_string()
`uvm_field_queue_int()
`uvm_field_queue_object() Queues
`uvm_field_queue_string()
Flag Arguments
Flags Description
UVM_ALL_ON Set all operations on (default)
UVM_DEFAULT Use the default flag settings
UVM_NOCOPY Do not copy this field
UVM_NOCOMPARE Do not compare this field
UVM_NOPRINT Do not print this field
UVM_NODEFPRINT Do not print the field if it does not change
UVM_NOPACK Do not pack or unpack this field
UVM Phases
Why we require Phases
⚫ This leads to questions like what is the good time to start data
generation and transfer, assuming all UVC components have been
created and connected properly.
⚫ UVM Provides concept of Phases to solve this issue. Each phase has
a defined order of execution.
Phases in UVM
Start of Simulation
Run
Extract
build_phase()
connect_phase() extract_phase()
end_of_elaboration_phase() check_phase()
start_of_simulation_phase() report_phase()
run_phase() final_phase()
⚫ This phase can be used for displaying banners, test bench topology
or configuration messages.
Pre Reset
Reset
Post Reset
Pre Configure
Configure
Post Configure
Pre Main
Main
Post Reset
Pre Shutdown
Shutdown
Post Shutdown
Phase Synchronization
Component2
Component3
Reset Configure Main Shutdown
Post run Phases
⚫ A component that raises objection remains in same phase till all the
objections are dropped.
⚫ Usage:
o phase.raise_objection(this); //to raise objection in this object
o phase.drop_objection(this); //to drop objection in this object
Example
0 100
REPORTING MECHANISM
Messaging and Reporting
⚫ `__FILE__ and `__LINE__ are predefined macros to get file name and
line number.
Output:
myobject a;
initial begin
a=new(“a”);
a.set_report_verbosity_level (UVM_LOW); //set verbosity level
end
Output:
UVM_INFO @0 : [2] Verbosity LOW
UVM_INFO @0 : [3] Verbosity NONE
TLM Ports
TLM
Producer Consumer
packet p;
`uvm_component_utils(producer)
endclass
Example – Consumer (Put)
`uvm_component_utils(consumer)
endclass
Blocking GET port
Producer Consumer
`uvm_component_utils(producer)
endclass
Example – Consumer (Get)
`uvm_component_utils(consumer)
endclass
Connecting TLM Ports
⚫ uvm_non_blocking_get_port/uvm_non_blocking_put_port provides
set of methods that returns immediately even if target is not ready:
o try_put()
o try_get()
o try_peek()
TLM FIFO
⚫ They contain all TLM interface methods like put, get, peek etc.
endclass
Analysis port and export
Subscriber Subscriber
Consumer
Analysis port
Score Board
Analysis FIFO
⚫ UVM factory has the ability to substitute a child class with another
class of a derived type when it is constructed.
Test
Env
Test
Env
⚫ Example
uvm_config_db #(bit) :: set(this, “*.ag[1].*”, “is_active”, 1);
void’ ( uvm_config_db #(bit) :: get(this, “ ”,“is_active”, is_active));
Example - Env
monitor mon;
driver dvr;
sequencer sqr;
`uvm_component_utils(agent)
module top;
mem_inf i0 (clk); //Memory interface
mem_dut u0 (i0); // DUT instance
initial begin
uvm_config_db #(virtual mem_inf) :: set (null, “*", “mem_vif”, i0);
//registering virtual interface with all components(*) using mem_vif
//as the field name
run_test(); //calling uvm_top.run_test();
end
endmodule
Example – Virtual Interface (Driver)
Top
Test
Env
Agent
Top
Test
Env
Agent
endinterface
Test Bench - DUT
Top
Test
Env
Agent
endmodule
Test Bench – TOP
Top
Test
Env
Agent
module top;
import uvm_pkg :: *; //import UVM package
`include “uvm_macros.svh” //include UVM macros
`include “myfiles.sv” //include user defined file
bit clk;
adder_inf i0 (); //Adder interface
adder u0 (i0); // Adder instance
endmodule
Adder - Top
initial
begin
uvm_config_db #(virtual adder_inf) :: set (null, “*”, “add_vif”, i0);
//registering virtual interface to configuration database
run_test();
//calling uvm_top.run_test();
//Test name can be specified as an argument
end
always #5 clk<=~clk;
Adder - transaction
`uvm_object_utils_begin(transaction)
`uvm_field_int(a, UVM_DEFAULT)
`uvm_field_int(b, UVM_DEFAULT)
`uvm_field_int(c, UVM_DEFAULT)
`uvm_field_int(sum, UVM_DEFAULT)
`uvm_object_utils_end
……………….//On Next Slide
endclass
Adder - transaction
Top
Test
Env
Agent
endclass
Adder – sequence1
task body();
repeat(1000)
begin
pkt=transaction :: type_id :: create(“pkt”);
start_item(pkt);
void‘(pkt.randomize);
finish_item(pkt);
end
endtask
Adder – sequence2
endclass
Adder – sequence2
task body();
repeat(1000)
begin
pkt=transaction :: type_id :: create(“pkt”);
start_item(pkt);
pkt.randomize with {a<16; b<16;};
//inline constraints Randomization
finish_item(pkt);
end
endtask
Test Bench – Sequencer
Top
Test
Env
Agent
Sequencer Driver
uvm_sequence_item_pull_export uvm_sequence_item_pull_port
seq_item_export seq_item_port
mid_do()
Performs Pin Deliver to driver finish_item(item)
Level Activity
item_done()
Top
Test
Env
Agent
super.build_phase(phase);
endfunction
endclass
Test Bench – Monitor
Top
Test
Env
Agent
task predict_and_compare();
@(posedge vif.clk);
cg.sample;
sum=vif.a + vif.b + vif.c;
@(posedge vif.clk);
if(sum!=vif.sum)
`uvm_error(“Monitor”, “Result Mismatch”)
endtask
endclass
Test Bench – Agent
Top
Test
Env
Agent
monitor mon;
driver dvr;
sequencer sqr;
function new (string name, uvm_component parent);
super.new(name, parent);
endfunction
……………….//On Next Slide
Adder – agent
Top
Test
Env
Agent
Top
Test
Env
Agent
endclass
“myfiles.sv” and run test