Академический Документы
Профессиональный Документы
Культура Документы
Using
UVM 1.0
VCS 2011.03
n Name
n Company
n Job Responsibilities
n EDA Experience
n Main Goal(s) and Expectations for this Course
2
Facilities
Restrooms Smoking
Meals Recycling
3
Course Materials
n Student Workbook
n Lab Book
n Reference Materials
n Course Evaluations
4
Workshop Goal
5
Target Audience
6
Workshop Prerequisites
7
Agenda: Day 1
DAY
1
1 OOP Inheritance Review
2 UVM Overview
3 Modeling Transactions
8
Agenda: Day 2
DAY
2
5 Component Configuration & Factory
6 TLM Communication
8 UVM Callback
9
Agenda: Day 3
DAY
3
9 Sequence Library/Virtual Sequencer
10 More on Phasing
12 Summary
10
What Is the Device Under Test?
A router:
16 x 16 crosspoint switch
valid_n [15:0]
router valido_n [15:0]
reset_n
clock
11
A Functional Perspective
inputs outputs
frame_n[0] port port
frameo_n[0]
valid_n[0] 0 0 valido_n[0]
din[0] dout[0]
1 1
2 2
3 3
4 4
partial view
12
The Router Description
13
Input Packet Structure
n frame_n:
l Falling edge indicates first bit of packet
l Rising edge indicates last bit of packet
n din:
l Header (destination address & padding bits) and payload
n valid_n:
l valid_n is low if payload bit is valid, high otherwise
clock
din[i] x A0 A1 A2 A3 d0 .... x dn-2 dn-1 x
valid_n[i] x x x x x
frame_n[i]
clock
dout[i] x x d0 d1 x x d2 d3 dn-3 x dn-2 dn-1 x
valido_n[i] x x
frameo_n[i]
15
Reset Signal
clock
reset_n
frame_n[i]
valid_n[i]
15 clock cycles
16
Icons Used in this Workshop
Definition of
Recommendation
Acronyms
17
18
Agenda: Day 1
DAY
1
1 OOP Inheritance Review
2 UVM Overview
3 Modeling Transactions
19
Unit Objectives
20
Object Oriented Programming: Classes
n Object-oriented programming
l Vera, e, C++, SystemVerilog
l Data and procedures together Properties need not
be passed as arguments
class Packet
"class"
da
function void display();
sa
...
data endfunction
crc
function int compute_crc();
...
endfunction
21
Object Oriented Programming: Inheritance
n Object-oriented programming
Packet
l New classes derived from original (base) class
l Inherits all contents of base class
class BadPacket extends Packet BadPacket
bad
function int compute_crc();
this.crc = super.compute_crc();
if (bad) crc = ~crc;
endfunction Can call overridden
behavior
22
Object Oriented Programming: Inheritance
Use Compatible
BadPacket bad_pkt = new();
$cast()
transmit(bad_pkt);
BadPacket
Compatible Derived class
23
OOP: Polymorphism
24
OOP: Polymorphism
Packet p = new();
BadPacket bp = new();
p.crc = p.compute_crc(); task transmit(Packet pkt);
bp.crc = bp.compute_crc(); pkt.crc = pkt.compute_crc();
transmit(p); ...
transmit(bp); endtask
25
OOP: Polymorphism
n If compute_crc() is virtual
p
class BadPacket extends Packet
da virtual
sa function int compute_crc();
data ...
crc endfunction
bad virtual
function int compute_crc();
...
endfunction
Packet p = new();
BadPacket bp = new();
p.crc = p.compute_crc(); task transmit(Packet pkt);
bp.crc = bp.compute_crc(); pkt.crc = pkt.compute_crc();
transmit(p); ...
transmit(bp); endtask
26
OOP: Polymorphism
27
Unit Objectives Review
28
Appendix
Parameterized Class
Typedef Class
External Definition
Static Property and Method
Singleton Classes
Proxy Classes
29
Parameterized Classes
n Written for a generic type
l Type parameter passed at instantiation, just like
parameterized modules
l Allows reuse of common code
class stack #(type T = int);
program automatic test;
local T items[$];
stack #(bit[31:0]) addr_stack;
function void push( T a );
stack #(packet) pkt_stack;
...
initial begin
function T pop( );
...
function int size(); ...
repeat(10) begin
endclass: stack
packet pkt = new();
if(!pkt.randomize())
$finish;
pkt.addr = addr_stack.pop();
pkt_stack.push(pkt);
end
end
endprogram: test
30
typedef
n Often need to use a class before declaration
l e.g. two classes need handle to each other
typedef class S2;
This is a compile error
class S1;
S2 inside_s1; if typedef is missing
...
endclass: S1
class S2;
S1 i_am_inside;
...
endclass: S2
n Or, to simplify parameterized class usage
class packet;
static int count = 0; Using a id field can
int id; help keep track of
function new(); transactions as they
id = count++; flow through test
endfunction
endclass
33
Static Method
class packet;
static int count = 0;
int id;
static function void print_count();
$display(“Created %0d packets”, count);
endfunction
…
endclass
34
Singleton Classes
class print;
static int err_count = 0, max_errors = 10;
if (expect != actual)
print::error(“Actual did not match expected”);
35
Simple Proxy Class
n Provides universal service routines like create()
class proxy_class#(type T=base);
typedef proxy_class#(T) this_type; // for coding convinience (not required)
static this_type me = get(); // construct a static object of this proxy
// type at beginning of simulation
static function this_type get();
if (me == null) me = new(); return me;
endfunction
static function T create();
create = new(); class myclass extends base;
endfunction typedef proxy_class#(myclass) proxy;
endclass endclassclass anotherclass extends base;
typedef proxy_class#(anotherclass) proxy;
endclass
class environment;
myclass m_obj; anotherclass a_obj;
function new();
m_obj = myclass::proxy::create();
a_obj = anotherclass::proxy::create();
endfunction
endclass
36
Proxy Classes & Factory (1/5)
n To create factory, two proxy class layers are needed:
l Virtual proxy base class (this slide)
l Proxy class (in a up coming slide)
l Act as molds in factory
n Virtual proxy wrapper class
l Base proxy class type to enable OOP polymorphism
l Declares abstracted interface methods for proxy services
u Creating objects
u Get type name
class factory;
static proxy_base registry[string];
static factory me = get();
static function factory get();
if (me == null) me = new(); return me;
endfunction
39
Creating Proxy Classes & Factory (4/5)
n Proxy class
l Implements the abstracted interface methods
l Registers itself in factory
l Create object using factory
class proxy_class#(type T=base, string Tname="none") extends proxy_base;
typedef proxy_class#(T, Tname) this_type; // for coding convinience (not
required)
static string type_name = Tname;
static this_type me = get();
static function this_type get();
factory f = factory::get(); if (me == null) me = new();
f.register(me); return me;
Use factory to create
endfunction
static function T create(string name); object
factory f = factory::get();
$cast(create, f.create_object_by_type(me, name));
endfunction
virtual function base create_object(string name);
T object_represented = new(name);
return object_represented;
endfunction
endclass 40
Creating Proxy Classes & Factory (5/5)
Why go through all these trouble?
n Test can use factory to override any object created
in environment without touching environment class
class modified extends myclass;
typedef proxy_class#(modified, "modified") proxy;
// other code not shown
endclass
program automatic test;
environment env;
initial begin
factory::override_type("myclass", "modified");
env = new();
// other code not shown
end
class environment; The override will cause a
myclass m_obj; anotherclass a_obj; modified class object to be
function new();
created instead of myclass
m_obj = myclass::proxy::create();
a_obj = anotherclass::proxy::create();
endfunction
endclass 41
42
Agenda: Day 1
DAY
1
1 OOP Inheritance Review
2 UVM Overview
3 Modeling Transactions
43
Unit Objectives
44
Origin of UVM
e eRM
uRM
SV OVM UVM
AVM
SC System System
C C
TLM 1.0 TLM 2.0
SV VMM VMM
1.0 1.2
OV RVM
45
Verification Goal
Pass
√
Tape out!
???
Debug Debug
Fail testbench RTL code
46
Coverage-Driven Verification
Productivity
gain
Coverage-Driven
Methodology
Goal Directed
Methodology
% Testcases
Self-checking
random environment
development time
Time
47
Phases of Verification
Goal
% Coverage
Difficult to reach
Corner-case
Verification
Time
Build verification
environment
48
Run More Tests, Write Less Code
49
The Testbench Environment/Architecture
Testcase
Testcase
Testcase Collection of testcases
Testcase
Creates
random Coverage
Test
transactions
Sequencer Sequencer
Self Check
Process Reacts to
transactions Bus Bus transactions
Driver Monitor Monitor
Driver
Interface
DUT RTL
50
UVM Encourages Encapsulation for Reuse
n Structure should be architected for reuse
Test instantiates
the environment Top Level Harness
and modifies the
environment on a Test
testcase by
testcase basis
Environment
Agents, coverage Master Agent Slave Agent
and scoreboard Coverage
should be
encapsulated in Sequencer Scoreboard Sequencer
an environment
Sequencer, driver
and monitor Bus Bus
associated with an Driver Monitor Monitor
Driver
interface should be
encapsulated as
an agent for that
interface DUT
51
UVM Structure is Scalable
n Agents are the building blocks across test/projects
Top Level Harness
Test
Environment
Scoreboard Slave Agent
Slave Agent
Slave Agent
Master Agent Passive Slave Agent
Coverage Sequencer
A Sequencer
g Sequencer
Sequencer e Scoreboard Sequencer
n
t Bus
Bus Driver
MonitorDriver
BusMonitor Driver
Bus Bus Bus
Monitor Driver
Driver Monitor Monitor Monitor
DUTB
DUTB
DUTB
DUTA DUTB
52
Structural Support in UVM
n Structural & Behavioral
l uvm_component Top Level Harness
u uvm_test Test
u uvm_env Environment
u uvm_agent
Master Agent Slave Agent
Coverage
u uvm_sequencer Sequencer Sequencer
u uvm_driver Scoreboard
u uvm_monitor
Driver Bus Bus Driver
u uvm_scoreboard Monitor Monitor
n Communication
l uvm_*_port DUT
l uvm_*_socket
n Data
l uvm_sequence_item
53
Component Phasing
n The run phase task executes concurrently with the
scheduled run time phase tasks
Build Time
Cleanup
54
Hello World Example
55
Compile and Simulate
More verbose
`uvm_info(“NORMAL”, “Normal message”, UVM_MEDIUM);
`uvm_info(“TRACE”, “Tracing execution”, UVM_HIGH);
`uvm_info(“FULL”, “Debugging operation”, UVM_FULL);
`uvm_info(“DEBUG”, “Verbose message”, UVM_DEBUG);
n Parent-child relationships
l Set up at component creation
l Establishes component phasing execution order
l Establishes component search path for component
configuration and factory replacement
l Logical hierarchy – Not OOP or composition hierarchy
n Phase execution order build
connect
l Each component follows end_of_elaboration
the same sequence of start_of_simulation
phase execution run*
extract
n Search path allow tests to: check
report
l Search and configure components final
l Search and replace components in environment
59
Key Component Concepts: Logical Hierarchy
class test_base extends uvm_test; simv
environment env;
`uvm_component_utils(test_base) uvm_top
function new(string name, uvm_component parent); run_test()
function void build_phase(uvm_phase phase);
super.build_phase(phase);
env = environment::type_id::create(“env”, this); uvm_test_top
endfunction Establish parent- “uvm_test_top”
class environment extends uvm_env; child
endclass
component comp; relationship at
env
`uvm_component_utils(environment) creation
function new(string name, uvm_component parent); “env”
function void build_phase(uvm_phase phase);
super.build_phase(phase);
comp
comp = component::type_id::create("comp", this);
endfunction “comp”
Set
endclass
class component extends uvm_component;
Parent
`uvm_component_utils(component)
function new(string name, uvm_component parent);
super.new(name, parent); Parent
endfunction
virtual task component_task(…);
handle
endclass
60
Key Component Concepts: Phase
n Agent class
l Encapsulates sequencer, driver and monitor on a
per interface basis
class router_agent extends uvm_agent;
n Environment class
l Encapsulates all components of testbench
l Connect components via TLM ports
class router_env extends uvm_env;
n Test class
l Encapsulates environment objects
l Sets test-level configuration/modification
class test_base extends uvm_test;
64
Simple Example of Key UVM Elements
n Test
l uvm_test
n Environment Test
l uvm_env Environment
n Agent Agent
l uvm_agent Sequencer
n Sequencer default_sequence
Sequence
l uvm_sequencer
Sequence_item
n Data class
l uvm_sequence Driver
l uvm_sequence_item
n Driver (BFM)
l uvm_driver
n Communication (TLM)
For simplicity, monitor and other components are left off
65
Key UVM Testbench Elements: TLM
packet
class packet extends uvm_sequence_item;
rand bit[3:0] sa, da;
rand bit[7:0] payload[$];
constraint valid {payload.size inside {[2:100]};}
`uvm_object_utils_begin(packet)
`uvm_field_int(sa, UVM_ALL_ON)
Macro creates support methods:
`uvm_field_int(da, UVM_ALL_ON) copy(), print() etc.
`uvm_field_queue_int(payload, UVM_ALL_ON)
`uvm_object_utils_end
function new(string name = “packet”);
super.new(name);
endfunction
endclass
67
Key UVM Element: Sequence Class
n Stimulus transactions are created inside a UVM
sequence extended from uvm_sequence class
Sequence must be typed for a specific sequence
item class
class packet_sequence extends uvm_sequence #(packet);
`uvm_object_utils(packet_sequence) Registers
function new(string name = "packet_sequence"); sequence
super.new(name);
endfunction Sequence code packet_sequence
task body(); resides in body()
if (starting_phase != null) packet
starting_phase.raise_objection(this);
repeat(10) begin Randomize built-in transaction
`uvm_do(req);
end object. Parent sequencer will output
if (starting_phase != null) transaction.
starting_phase.drop_objection(this);
endtask
endclass Use raise/drop objection
to stay in phase until
done 68
Key UVM Element: Sequencer Class
packet_sequencer
Must be typed for
default_sequence
a sequence item
class
Driver
69
Key UVM Element: Driver Class
n Driver should extend from uvm_driver class
l uvm_driver class has built-in sequence item handle
(req) and TLM port to communicate with the sequencer
Must be typed for
a sequence item
class driver extends uvm_driver #(packet);
`uvm_component_utils(driver) class
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
task run_phase(uvm_phase phase);
forever begin Agent
seq_item_port.get_next_item(req);
`uvm_info(“DRVR”, req.sprint(), UVM_MEDIUM); packet_sequencer
seq_item_port.item_done();
end default_sequence
endtask Driver should implement
endclass
run phase to handle
sequences from all Run driver
Time task phases
70
Key UVM Element: Agent Class
71
Key UVM Element: Environment Class
n Encapsulate agent in environment class
l Only agent for now. (Scoreboard and others in later units)
l Configure the agent sequencer’s default_sequence
class router_env extends uvm_env;
Extend from uvm_env
router_agent agent;
// utils macro and constructor not shown
In build phase,
function void build_phase(uvm_phase phase); create agent
super.build_phase(phase); object
agent = router_agent::type_id::create("agent", this);
uvm_config_db #(uvm_object_wrapper)::set(this, "*.seqr.main_phase",
"default_sequence", packet_sequence::get_type());
router_env
endfunction Set agent’s sequencer router_agent
endclass packet_sequencer
to execute a default
default_sequence
sequence packet_sequence
packet
driver
72
Key UVM Element: Test Class
n Develop Tests In Two Steps
l Create default test (unconstrained)
u test_base extending from test_base
the uvm_test base class router_env
Base test router_agent packet_sequencer
extends from default_sequence
packet_sequence
uvm_test
packet
class test_base extends uvm_test;
router_env env; driver
`uvm_component_utils(test_base)
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
env = router_env::type_id::create(“env”, this);
endfunction
In build phase, create the environment
endclass
object
l Then, develop targeted tests extending from test_base
u Will be covered in each of the subsequent units
73
Test Program
Simulate with:
simv +UVM_TESTNAME=test_base
74
Key UVM Testbench Elements: UVM Report
75
Embed Report Messages
n Create messages with macros:
`uvm_fatal(string ID, string MSG);
`uvm_error(string ID, string MSG);
`uvm_warning(string ID, string MSG);
`uvm_info(string ID, string MSG, verbosity);
Example:
function void build_phase(uvm_phase phase);
super.build_phase(phase);
`uvm_info("Trace", $sformatf("%m"), UVM_HIGH)
if (!cfg.randomize()) begin
`uvm_fatal("CFG_ERROR", "Failed in Configuration randomization");
end
endfunction
n typedef enum {
Default Verbosity is UVM_MEDIUM UVM_NONE = 0,
n UVM_LOW = 100,
Set with run-time switch UVM_MEDIUM = 200,
UVM_HIGH = 300,
simv +verbosity=UVM_HIGH UVM_FULL = 400,
UVM_DEBUG = 500
Can be: } uvm_verbosity;
LOW, MEDIUM, HIGH, FULL, DEBUG,
UVM_LOW, UVM_MEDIUM, UVM_HIGH, UVM_FULL, UVM_DEBUG
n Set verbosity for a component or hierarchy:
drv.set_report_verbosity_level(verbosity);
env.set_report_verbosity_level_hier(verbosity);
n Exception:
`uvm_fatal, `uvm_error, and `uvm_warning
messages can not be filtered out via run-time switch
77
Default Simulation Handling
Severity Default Action
UVM_FATAL UVM_DISPLAY | UVM_EXIT
UVM_ERROR UVM_DISPLAY | UVM_COUNT
UVM_WARNING UVM_DISPLAY
UVM_INFO UVM_DISPLAY
Action Description
UVM_NO_ACTION Do nothing
78
Modify Report Message Action in Test
79
Command Line Control of Report Messages
n Control verbosity of components at specific phases or times
l id argument can be _ALL_ for all IDs or a specific id
u Wildcard for id argument not supported
+uvm_set_verbosity=<comp>,<id>,<verbosity>,<phase>
+uvm_set_verbosity=<comp>,<id>,<verbosity>,time,<time>
+uvm_set_verbosity=uvm_test_top.env.agent1.*,_ALL_,UVM_FULL,time,800
n Control report message action (like set_report_*_action)
l Can be UVM_NO_ACTION or a | separated list of the other actions
+uvm_set_action=<comp>,<id>,<severity>,<action>
+uvm_set_action=uvm_test_top.env.*,_ALL_,UVM_ERROR,UVM_NO_ACTION
n Control severity (like set_report_*_severity_override)
+uvm_set_severity=<comp>,<id>,<current severity>,<new severity>
+uvm_set_severity=uvm_test_top.*,BAD_CRC,UVM_ERROR,UVM_WARNING
80
Misc: Command Line Processor
n User can query run-time arguments
class test_base extends uvm_test; // simplified code
uvm_cmdline_processor clp = uvm_cmdline_processor::get_inst();
function void build_phase(uvm_phase phase);
super.build_phase(phase); // simplified code
if (clp.get_arg_value("+packet_item_count=", value))
uvm_config_db#(int)::set(this, "*.seqr.*", "item_count",
value.atoi());
endfunction
function void start_of_simulation_phase(uvm_phase phase);
string tool, ver, args[$], m;
tool = clp.get_tool_name();
ver = clp.get_tool_version();
`uvm_info("TOOL_INFO",
$sformatf("Tool: %s, Version : %s", tool, ver), UVM_LOW);
clp.get_args(args);
foreach (args[i])
$sformat(m, {m, args[i], " "});
`uvm_info("ARGS", $sformatf("Sim cmd is:\n%s", m), UVM_LOW);
endfunction
endclass
81
Misc: Objection Run-Time Argument
n User can debug raising/dropping of objections with
+UVM_OBJECTION_TRACE
Simulate with:
simv +UVM_TESTNAME=test_base +UVM_OBJECTION_TRACE
UVM_INFO @ 0.0ns: main [OBJTN_TRC] Object uvm_test_top.env.agent.seqr.packet_sequence raised 1 objection(s): count=1
total=1
UVM_INFO @ 0.0ns: main [OBJTN_TRC] Object uvm_test_top.env.agent.seqr added 1 objection(s) to its total (raised from source
object ): count=0 total=1
UVM_INFO @ 0.0ns: main [OBJTN_TRC] Object uvm_test_top.env.agent added 1 objection(s) to its total (raised from source
object ): count=0 total=1
UVM_INFO @ 0.0ns: main [OBJTN_TRC] Object uvm_test_top.env added 1 objection(s) to its total (raised from source object ):
count=0 total=1
UVM_INFO @ 0.0ns: main [OBJTN_TRC] Object uvm_test_top added 1 objection(s) to its total (raised from source object
uvm_test_top.env.agent.seqr.packet_sequence): count=0 total=1
UVM_INFO @ 0.0ns: main [OBJTN_TRC] Object uvm_top added 1 objection(s) to its total (raised from source object
uvm_test_top.env.agent.seqr.packet_sequence): count=0 total=1
…
UVM_INFO @ 0.0ns: main [OBJTN_TRC] Object uvm_test_top.env.agent.seqr.packet_sequence dropped 1 objection(s): count=0
total=0
UVM_INFO @ 0.0ns: main [OBJTN_TRC] Object uvm_test_top.env.agent.seqr.packet_sequence all_dropped 1 objection(s):
count=0 total=0
UVM_INFO @ 0.0ns: main [OBJTN_TRC] Object uvm_test_top.env.agent.seqr subtracted 1 objection(s) from its total (dropped
from source object ): count=0 total=0
…
UVM_INFO @ 0.0ns: main [OBJTN_TRC] Object uvm_top subtracted 1 objection(s) from its total (dropped from source object
uvm_test_top.env.agent.seqr.packet_sequence): count=0 total=0
UVM_INFO @ 0.0ns: main [OBJTN_TRC] Object uvm_top subtracted 1 objection(s) from its total (all_dropped from source object
uvm_test_top.env.agent.seqr.packet_sequence): count=0 total=0 82
Unit Objectives Review
83
Lab 1 Introduction
Implement transaction, components, and test
Implement
Transaction
Class
30 min
Implement
Sequence
Class
Implement
Component
Classes
Implement
Test
Compile
and
Simulate
84
Appendix
85
VCS Support for UVM
86
Compiling UVM with VCS 2011.03
When using the VPI-based backdoor access mechanism included in the UVM
library, the "+acc" and "+vpi" command-line options must also be used.
87
DVE UVM Macro Debugging
88
DVE UVM Transaction Level Debugging
Dumps UVM sequence items to VPD Dumps UVM log messages to VPD
89
UVM Template Generator (Coming Soon)
90
Store UVM Report Messages in File
91
Store Report Message in File
Example:
UVM_FILE log, err_log;
log = $fopen("log", "w");
err_log = $fopen("err.log", "w");
set_report_default_file(log);
set_report_severity_file(UVM_FATAL, err_log);
set_report_severity_action(UVM_FATAL, UVM_EXIT, UVM_LOG, UVM_DISPLAY);
set_report_id_file("Trace", UVM_LOG | UVM_DISPLAY)
93
Calling UVM Messaging From Modules (1/2)
95
96
Agenda: Day 1
DAY
1
1 OOP Inheritance Review
2 UVM Overview
3 Modeling Transactions
97
Unit Objectives
98
Transaction Flow
Accumulated
Stimulus here
created Freed
here Tests here
Created
Master Monitor here Monitor Slave
Freed DUT
here
99
Modeling Transactions
n Derive from uvm_sequence_item base class
l Built-in support for stimulus creation, printing, comparing, etc.
n Properties should be public by default
l Must be visible to constraints in other classes
n Properties should be rand by default
l Can be turned off with rand_mode
103
Transactions: Should-Obey Constraints
Illegal solution
Space
Valid solution
space
Test constraints
Derived
Test constraints
105
Transaction Class Methods
n How to manipulate transactions?
l Print, copy, compare, record, pack
l UVM has standard methods for these actions
n Use macros to create commonly needed methods
`uvm_object_utils_begin(cname)
`uvm_field_*(ARG, FLAG)
`uvm_object_utils_end
class packet extends uvm_sequence_item;
rand bit [47:0] sa, da;
rand bit [ 7:0] payload[$];
packet next;
`uvm_object_utils_begin(packet)
`uvm_field_int(sa, UVM_ALL_ON | UVM_NOCOPY)
`uvm_field_int(da, UVM_ALL_ON)
`uvm_field_queue_int(payload, UVM_ALL_ON)
`uvm_field_object(next, UVM_ALL_ON)
`uvm_object_utils_end
endclass
106
`uvm_field_* Macros
uvm_field_int(ARG, FLAG)
uvm_field_real(ARG, FLAG)
uvm_field_event(ARG, FLAG)
uvm_field_object(ARG, FLAG)
uvm_field_string(ARG, FLAG)
uvm_field_enum(T, ARG, FLAG) // T – enum data type
uvm_field_sarray_*(ARG, FLAG) // fixed size array: _type
uvm_field_array_*(ARG, FLAG) // dynamic array: _type
uvm_field_queue_*(ARG, FLAG) // queue: _type
uvm_field_aa_*_*(ARG, FLAG) // associative array: _type_index
107
Methods Specified by FLAG
n FLAG is a collection of ON/OFF bits associated with
the base class methods
//A=ABSTRACT Y=PHYSICAL, F=REFERENCE, S=SHALLOW, D=DEEP
//K=PACK, R=RECORD, P=PRINT, M=COMPARE, C=COPY
//------------------------- AYFSD K R P M C
parameter UVM_DEFAULT = 'b000010101010101;
parameter UVM_ALL_ON = 'b000000101010101;
//Values are or'ed into a 32 bit value
parameter UVM_COPY = (1<<0); // copy(...)
parameter UVM_NOCOPY = (1<<1);
parameter UVM_COMPARE = (1<<2); // compare(...)
parameter UVM_NOCOMPARE = (1<<3);
parameter UVM_PRINT = (1<<4); // sprint(...)
parameter UVM_NOPRINT = (1<<5);
parameter UVM_RECORD = (1<<6); // record(...)
parameter UVM_NORECORD = (1<<7);
parameter UVM_PACK = (1<<8); // pack(...)
parameter UVM_NOPACK = (1<<9);
Radix for printing and recording can be specified by OR'ing one of the following constants
in the ~FLAG~ argument
// printing in decimal
`uvm_field_int(field, UVM_ALL_ON | UVM_DEC)
109
Transaction Methods
110
Method Descriptions
methods function
clone The clone method creates and returns an exact copy of this object.
Calls create followed by copy
copy Returns a deep copy of this object
compare Compare method deep compares this data object with the object
provided in the rhs
pack/unpack Bitwise-concatenate object’s properties into an array of bits, bytes, or
ints.
record Deep-records this object’s properties according to an optional
recorder policy
111
Customization of Methods
112
Using Transaction Methods
name
packet pkt0, pkt1, pkt2;
bit bit_stream[];
string
pkt0 = packet::type_id::create(“pkt0”);
pkt1 = packet::type_id::create(“pkt1”);
pkt0.sa = 10;
pkt0.print(); // display content of object on stdio
pkt0.copy(pkt1); // copy content of pkt1 into memory of pkt0
// name string is not copied
$cast(pkt2, pkt1.clone()); // make pkt2 an exact duplication of pkt1
// name string is copied
if(!pkt0.compare(pkt2)) begin // compare the contents of pkt0 against pkt2
`uvm_fatal(“MISMATCH”, {“\n”, pkt0.sprint(), pkt2.sprint()});
end // sprint() returns string for logging
pkt0.pack(bit_stream); // pack content of pkt0 into bit_stream array
pkt2.unpack(bit_stream); // unpack bit_stream array into pkt2 object
113
Modify Constraint in Transactions by Type
Simulate with:
simv +UVM_TESTNAME=test_sa_3_type
Type Overrides:
uvm_sequence_item Generic
bu_data Company-specific
OOP
usb_packet Protocol-specific
Reuse
across
projects Environment-specific
dut_usb_packet
test_usb_packet Test-specific
118
Lab 2 Introduction
Implement configurable sequence
Compile
and
Simulate
119
Appendix
uvm_object_utils Macro
120
uvm_object_utils Macros
`uvm_object_utils[_begin](cname) Macro creates a
proxy class called
n Implements the following: type_id
typedef uvm_object_registry #(cname, “cname”) type_id;
static const string type_name = “cname”;
static function type_id get_type();
virtual function uvm_object_wrapper get_object_type();
virtual function string get_type_name();
DAY
1
1 OOP Inheritance Review
2 UVM Overview
3 Modeling Transactions
125
Unit Objectives
126
Typical Sequence Execution Protocol
n Sequencer and driver are Test
synchronized via TLM port Environment
Sequencer Sequencer
Sequencer randomizes
sequence default_sequence
(referenced by Sequence
default_sequence) Sequence_item
Sequencer executes
sequence’s Driver
start() method
Sequence driver
Driver requests for
start() executes pre_body() sequence item
start() executes body() Driver waits for sequence
body() generates sequence item
item Driver processes sequence
(Subject of this unit) item
start() executes Driver flags sequence item
post_body() done
127
Mapping Protocol to Code (1/2)
Sequence driver
Driver requests for
start() executes pre_body() sequence item
start() executes body() Driver waits for sequence
body() generates sequence item
item Driver processes
(Subject of this unit) sequence item
start() executes Driver flags sequence item
post_body() done
130
User Sequence Class Implementation
Simplify sequence implementation:
n Create base sequence to raise and drop objections
n Create user sequence extending from base sequence
n virtual body();
taskmanually
User can execute the embedded methods:
// Instead of `uvm_do_with(req, {sa == 3;})
// User can populate own item:
`uvm_create(req); // constructs an item and sets item ids and link to parent
sequencer
start_item(req); // wait for parent sequencer to get request from driver
req.sa = 3; // populate item with user value
...
finish_item(req); // use parent sequencer to pass item to driver and wait for
done
endtask 132
User Can Implement Scenario Sequence
134
Executing User Sequences in Test
135
Sequence Can Be Configured (Local)
n Reference configuration field through parent sequencer
class packet_sequence extends base_sequence;
int item_count = 10; // utils macro and constructor not shown
task body();
Parent Tag to get
sequencer value
uvm_config_db#(int)::get(m_sequencer,"*","item_count",item_count);
repeat(item_count) begin
`uvm_do(req)
end
Sequence instance Variable to store
endtask name value
n Set in test
endclass unchanged if not
set
class test_20_items extends test_base;
// utils and constructor not shown
function void build_phase(uvm_phase phase); Tag to set
super.build_phase(phase);
value
uvm_config_db#(int)::set(this, "*.seqr.*", "item_count", 20);
endfunction
endclass Context of Instance name in Valu
search context e
136
Sequence Can Be Configured (Global)
n Use resource database to configure sequence
class packet_sequence extends base_sequence;
int item_count = 1; // utils macro and constructor not shown
task body(); Scope where resource
reside
uvm_resource_db#(int)::read_by_name("SEQ_CNTRL",
"item_count", item_count);
repeat(item_count)begin
`uvm_do(req);
end
Field tag within resource Variable to store
endtask pool value
endclass unchanged if not
n Set in test set
140
Lab 3 Introduction
Implement configurable sequence
30 min Create
configurable
sequence
Implement
Test
Compile
and
Simulate
141
Appendix
Sequencer-Driver
Communication
Sequencer-Driver Response
Port
142
Sequencer-Driver Communication
143
Sequencer-Driver Communication Detailed
n Pseudo code illustration:
task body();
Sequencer repeat (10) begin
my_seq `uvm_do(req);
`uvm_do(tr); end
‘define uvm_do(req)
endtask
`uvm_create(req); task start_item(req);
start_item(req); seqr.wait_for_grant();
req.randomize(); seqr.begin_tr(req);
get_next_item(req)
send(req) finish_item(req); endtask
item_done();
Driver
class driver …
task run_phase(…); task finish_item(req);
forever begin seqr.send_request(req);
seq_item_port.get_next_item(req); seqr.wait_for_item_done();
send(req); seqr.end_tr(req);
seq_item_port.item_done(); endtask
end
endtask
endclass Caution: Pseudo code, not actual code
7
6
5
4
3
2
1 144
Another View of Sequencer-Driver Interaction
n Pseudo code illustration:
task xxx_phase(…);
start_default_sequence();
endtask task start_default_sequence();
uvm_sequence seq = default_sequence;
seq.randomize()
seq.start(this);
endtask task start (uvm_sequencer_base seqr);
pre_body();
task body();
body();
`uvm_create(req);
Sequencer post_body();
seqr.wait_for_grant();
endtask
xxx_phase(…) seqr.begin_tr(req);
get_next_item() req.randomize();
task get_next_item();
select_sequence(); seqr.send_request(req);
seqr.wait_for_item_done();
endtask
seqr.end_tr(req);
port.get_next_item(req) endtask
send(req)
item_done();
Driver
Caution: Pseudo code, not actual code
145
Sequencer-Driver Response Port
146
Sequencer-Driver Response Port (1/2)
n Driver can send response back to sequence
task body();
test.sv
repeat (10) begin
`uvm_do(req); Sequencer
my_seq
Optional
Retrieve get_response(rsp); `uvm_do(tr);
get_response(rsp) response
// process response
response
end
endtask
get_next_item(req)
class driver extends uvm_driver #(packet); send(req)
task run_phase(uvm_phase phase); ...
forever begin item_done(rsp);
seq_item_port.get_next_item(req); Driver
send(req);
rsp = packet::type_id::create(“rsp”); Create and
rsp.set_id_info(req); set response
// set rsp response id
seq_item_port.item_done(rsp);
end (required!)
endtask Set response
endclass
147
Sequencer-Driver Response Port (2/2)
n Alternative if the response timing is not immediate
l E.g. out of order processing
task body();
repeat (10) begin
`uvm_do(req);
// create thread to wait for response
Retrieve get_response(rsp);
response // process response
end class driver extends uvm_driver #(packet);
endtask task run_phase(uvm_phase phase);
forever begin
seq_item_port.get_next_item(req);
send(req);
rsp = packet::type_id::create(“rsp”);
rsp.set_id_info(req);
seq_item_port.item_done();
// other activities
seq_item_port.put_response(rsp);
end
endtask
endclass Set response
148
Agenda: Day 2
DAY
2
5 Component Configuration & Factory
6 TLM Communication
8 UVM Callback
149
Unit Objectives
150
UVM Component Base Class Structure
uvm_report_object
build
uvm_component
connect
uvm_test
end_of_elaboration
start_of_simulation
uvm_env run*
is_active extract
uvm_agent
req, rsp
check
uvm_sequencer_base report
final
uvm_monitor uvm_sequencer_param_base
uvm_scoreboard uvm_sequencer
req, rsp
uvm_driver
151
Component Parent-Child Relationships
n Logical relationship is established at creation of
component object
components
class child extends
only
uvm_component; // utils macro
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction Pass parent in via
endclass
constructor
class BFM extends uvm_component; // utils macro
child child1, child2;
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
function void build_phase(…); super.build_phase(…);
blk
child1 = child::type_id::create("child1", this);
child2 = child::type_id::create("child2", this);
endfunction
child1 child2 endclass
Establish logical
... hierarchy
BFM blk = BFM::type_id::create("blk", null);
152
Display & Querying
n Rich set of methods for query & display
Get handle to
uvm_component obj;
parent obj = top.vip.get_parent();
158
Configuring Component’s DUT Interface
n In component, use uvm_config_db#(intf)::get()
in build_phase to retrieve DUT signal
class driver extends …; // simplified code
virtual router_io sigs;
function void build_phase(uvm_phase phase);
super.build_phase(phase);
if (!uvm_config_db#(virtual router_io)::get(this, "",
"router_io", sigs))
`uvm_fatal("CFGERR", "Driver DUT interface not set");
endfunction
endclass
n In test, use uvm_config_db#(intf)::set() in
build_phase to set DUT signal
l Read by type
Variable of data type
uvm_resource_db#(d_type)::read_by_name(“scope”,“key”,type_var,accessor);
uvm_resource_db#(d_type)::read_by_type(“scope”, type_field, accessor);
Implementation flow
n Factory instrumentation/registration
l `uvm_object_utils(Type)
Macro creates a proxy class
l `uvm_component_utils(Type) to represent the
object/component called
type_id
And, registers an instance of
n Construct object using static proxy class
the proxy method
class in
uvm_factory
l ClassName obj = ClassName::type_id::create(…);
n Class overrides
l set_type_override (…); Use proxy class to create
l set_inst_override (…); object
Proxy class in uvm_factory can
be overridden to create
modified object
165
Transaction Factory
N
tr = new("tr");
167
Customize Transaction in Test
n Globally change all “packet” type Make modifications
class newPkt extends packet;
to existing
int serial_no; transaction
constraint test_constraint {...} Required!
`uvm_object_utils_begin(newPkt) Creates proxy class
...
endclass class packet_test extends test_base;
`uvm_component_utils(packet_test)
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
set_type_override("packet", “newPkt");
endfunction
endclass
n Or change just Change all existing
instances found “packet” proxypath
in search to “newPkt”
Search path
168
Component Factory
Search path
171
Command-line Override
No space character!
172
Visually Inspect Structural Correctness
n Topology of the test can be printed with
uvm_top.print_topology()
Type Overrides:
176
Unit Objectives Review
177
Appendix
SystemVerilog Interface
Command Line Configuration
uvm_component_utils Macro
178
SystemVerilog Interface
179
Physical Interface: SystemVerilog Interface
180
What is a Virtual Interface?
n A virtual interface is a pointer to a physical interface
l Think of it as: ref router_io sigs; // Psuedo-code
n RTL connects blocks with physical interfaces
n Testbench drives and samples these interfaces
l Testbench class objects can not create interfaces
l Virtual interface is needed to point to interfaces in RTL
n Virtual interface separates testbench from RTL
l Testbench use virtual interface to access RTL signals
l Testbench classes are design independent
class router_vi_wrapper extends uvm_object;
virtual router_io sigs;
`uvm_object_utils(router_vi_wrapper)
function new(string name=“”, virtual router_io sigs=null);
super.new(name);
this.sigs = sigs;
endfunction
endclass 181
Command Line Configuration
182
Command-Line Configuration
183
uvm_component_utils Macro
184
uvm_component_utils Macros
`uvm_component_utils[_begin](cname)
n Implements the following:
typedef uvm_component_registry #(cname, “cname”) type_id;
const static string type_name = “cname”;
static function type_id get_type();
virtual function uvm_object_wrapper get_object_type();
virtual function string get_type_name();
DAY
2
5 Component Configuration & Factory
6 TLM Communication
8 UVM Callback
187
Unit Objectives
188
Component Interface: Overview
Component
Interfaces
Coverage
Stimulus Response
Sequencer Sequencer
Component Scoreboard
Interfaces
189
Component Interface: Method Interface
n Component can embed method for communication
class Consumer extends uvm_component;
...
virtual task put(transaction tr);
endclass
n But, the interface method should not be called through
the component object’s handle
l Code becomes too inflexible for testbench structure
u In example below, Producer is stuck with communicating with
only a specific Consumer type
Producer
consumer.put(tr);
190
Component Interface: Method Interface
Call interface
method through
an interface
object
Producer
consumer.put(tr); Producer
tlm_port.put(tr);
Consumer
put(tr)
task put(…);
TLM port
Consumer
task put(…);
191
Component Interface: Method Interface
n Through the intermediary interface object (TLM)
components can be re-connected to any other
component on a testcase by testcase basis
Other_Producer
tlm_port.put(tr);
TLM port
Producer Consumer
tlm_port.put(tr); task put(…);
TLM port
Consumer Producer
task put(…); tlm_port.put(tr);
TLM port
Other_Consumer
task put(…);
192
Communication in UVM: TLM 1.0, 2.0
n TLM Classes
l uvm_*_export
l uvm_*_imp
l uvm_*_port
l uvm_*_fifo
l uvm_*_socket
simple_env
simple_sequencer
simple_sequence default_sequence
simple_item
simple_driver
193
UVM TLM 1.0
put()
n Push put_producer put_consumer
n Pull get()
get_producer get_consumer
n Fifo
producer fifo consumer
nOne-to-One
Analysis
(broadcast) write()
write_producer write_subscriber
write_subscriber
write_subscriber
One-to-Many Many-to-One
194
Push Mode
put()
n Push mode put_producer put_consumer
get()
n Pull mode get_producer get_consumer
197
Analysis Port
n Analysis write()
write_producer write_subscriber
(broadcast)
l Analysis port can be left unconnected write_subscriber
n Blocking
b_transport(tx,delay)
initiator target
n Non-Blocking
nb_transport(tx,p,delay)
initiator target
200
Blocking Transport Initiator
b_transport(tx, delay)
initiator target
201
Blocking Transport Target
b_transport(tx,delay)
initiator target
nb_transport_fw(tx, p, delay)
initiator nb_transport_bw(tx, p, delay) target
203
Non-Blocking Transport Target
nb_transport_fw(tx, p, delay)
initiator nb_transport_bw(tx, p, delay) target
204
UVM Transaction Debug
205
UVM Transaction Debug
206
UVM Transaction Debug in DVE
Master transaction
stream
Hierarchical
Transaction View
207
Debugging UVM Transaction Log Messages
Log stream
Transaction
stream
208
Getting Help on DVE
209
Unit Objectives Review
210
Lab 4 Introduction
Implement & configure physical device drivers
Configure virtual
interface in Test
Compile
and
Simulate
211
Appendix
212
TLM 2.0 Generic Payload (1/4)
n TLM 2.0 Generic Payload is a generic bus read/write
access transaction type
l Used for cross-platform interoperability (e.g. SystemC)
typedef enum {
UVM_TLM_READ_COMMAND, // Bus read operation
UVM_TLM_WRITE_COMMAND, // Bus write operation
UVM_TLM_IGNORE_COMMAND // No bus operation
} uvm_tlm_command_e;
typedef enum {
UVM_TLM_OK_RESPONSE = 1, // Bus operation completed succesfully
UVM_TLM_INCOMPLETE_RESPONSE = 0, // Transaction was not delivered to
target
UVM_TLM_GENERIC_ERROR_RESPONSE = -1, // Bus operation had an error
UVM_TLM_ADDRESS_ERROR_RESPONSE = -2, // Invalid address specified
UVM_TLM_COMMAND_ERROR_RESPONSE = -3, // Invalid command specified
UVM_TLM_BURST_ERROR_RESPONSE = -4, // Invalid burst specified
UVM_TLM_BYTE_ENABLE_ERROR_RESPONSE = -5 // Invalid byte enabling specified
} uvm_tlm_response_status_e;
213
TLM 2.0 Generic Payload (2/4)
class uvm_tlm_generic_payload extends uvm_sequence_item;
rand bit [63:0] m_address;
rand uvm_tlm_command_e m_command;
rand byte unsigned m_data[];
rand int unsigned m_length; // Number of bytes to be copied to or from
// the m_data array
rand uvm_tlm_response_status_e m_response_status;
rand byte unsigned m_byte_enable[]; // Indicates valid m_data array elements
rand int unsigned m_byte_enable_length; // Number of elements in
m_byte_enable array
rand int unsigned m_streaming_width; // Number of bytes transferred on each
beat
`uvm_object_utils_begin(uvm_tlm_generic_payload)
`uvm_field_int(m_address, UVM_ALL_ON);
`uvm_field_enum(uvm_tlm_command_e, m_command, UVM_ALL_ON);
`uvm_field_array_int(m_data, UVM_ALL_ON);
`uvm_field_int(m_length, UVM_ALL_ON);
`uvm_field_enum(uvm_tlm_response_status_e, m_response_status, UVM_ALL_ON);
`uvm_field_array_int(m_byte_enable, UVM_ALL_ON);
`uvm_field_int(m_streaming_width, UVM_ALL_ON);
`uvm_object_utils_end
… Continued on next slide
214
TLM 2.0 Generic Payload (3/4)
function new(string name="");
virtual function uvm_tlm_command_e get_command();
virtual function void set_command(uvm_tlm_command_e command);
virtual function bit is_read();
virtual function void set_read();
virtual function bit is_write();
virtual function void set_write();
virtual function void set_address(bit [63:0] addr);
virtual function bit [63:0] get_address();
virtual function void get_data (output byte unsigned p []);
virtual function void set_data(ref byte unsigned p []);
virtual function int unsigned get_data_length();
virtual function void set_data_length(int unsigned length);
virtual function int unsigned get_streaming_width();
virtual function void set_streaming_width(int unsigned width);
virtual function void get_byte_enable(output byte unsigned p[]);
virtual function void set_byte_enable(ref byte unsigned p[]);
virtual function int unsigned get_byte_enable_length();
virtual function void set_byte_enable_length(int unsigned length);
virtual function uvm_tlm_response_status_e get_response_status();
virtual function void set_response_status(uvm_tlm_response_status_e status);
virtual function bit is_response_ok();
virtual function bit is_response_error();
virtual function string get_response_string(); // Continued on next page 215
TLM 2.0 Generic Payload (4/4)
n TLM 2.0 Generic Payload can be extended to add
additional members
l Requires implementation of uvm_tlm_extension class
// Continued from previous page
local uvm_tlm_extension_base m_extensions [uvm_tlm_extension_base];
function uvm_tlm_extension_base set_extension(uvm_tlm_extension_base ext);
function int get_num_extensions();
function uvm_tlm_extension_base get_extension(uvm_tlm_extension_base
ext_handle);
function void clear_extension(uvm_tlm_extension_base ext_handle);
function void clear_extensions();
endclass
class uvm_tlm_extension #(type T=int) extends
uvm_tlm_extension_base;
typedef uvm_tlm_extension#(T) this_type;
local static this_type m_my_tlm_ext_type = ID();
function new(string name="");
static function this_type ID();
virtual function uvm_tlm_extension_base get_type_handle();
virtual function string get_type_handle_name();
endclass 216
Agenda: Day 2
DAY
2
5 Component Configuration & Factory
6 TLM Communication
8 UVM Callback
217
Unit Objectives
218
Scoreboard - Introduction
n Today’s challenges
l Self checking testbenches need scoreboards
l Develop a scoreboard once, re-use many times in different
testbenches
l Need different scoreboarding mechanisms for different
applications
l Must be aware of DUT’s data transformation
219
Scoreboard – Data Streams
221
Scoreboarding: Monitor
n Monitors supplies scoreboard with Environment
expected and actual transactions Scoreboard
223
UVM Agent Example
228
Scoreboard: Out-Of-Order
229
Functional Coverage
230
Connecting Coverage to Testbench
n SystemVerilog Testbench Structure
Testcase Cover
Configuration
Cover
Configure Coverage
Stimulus
DUT
231
Configuration Coverage
covergroup router_cfg_cg(…); … endgroup
class config_coverage extends uvm_component;
bit coverage_enable = 0;
router_cfg cfg; router_cfg_cg cfg_cg;
`uvm_component_utils_begin(config_coverage)
`uvm_field_object(cfg, UVM_DEFAULT)
`uvm_field_int(coverage_enable, UVM_DEFAULT)
`uvm_component_utils_end;
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
if (coverage_enable) begin
if (!uvm_config_db #(router_cfg)::get(this, "", "cfg", cfg) begin
`uvm_fatal(…);
end
cfg_cg = new();
end
endfunction
virtual function void end_of_elaboration_phase(uvm_phase phase);
if (coverage_enable)
cfg_cg.sample(cfg.num_of_active_ports);
endfunction
endclass
232
Configuration Coverage
endfunction
endclass
233
Stimulus Coverage
`uvm_analysis_imp_decl(_before)
`uvm_analysis_imp_decl(_after)
class scoreboard #(type T = packet) extends uvm_scoreboard;
bit coverage_enable = 0; Packet cover
packet_sb_cg pkt_cg; group
// component_utils and other code
virtual function void write_after(T pkt); Export method
...; called with
if (pkt.compare(pkt_ref) begin
m_matches++;
monitored packets
if (coverage_enable) pkt_cg.sample(pkt_ref.sa, pkt_ref.da);
end else begin
m_mismatches++;
end
...;
endfunction : write_after
endclass
235
Unit Objectives Review
236
Appendix
Multi-Stream Scoreboard
237
Scoreboard: Multi-Stream
`uvm_analysis_imp_decl(_before)
`uvm_analysis_imp_decl(_after)
class scoreboard #(type T = packet, int num=16) extends uvm_scoreboard;
typedef scoreboard #(T) this_type;
`uvm_component_param_utils(this_type)
uvm_analysis_imp_before #(T, this_type) before_export;
uvm_analysis_imp_after #(T, this_type) after_export;
uvm_analysis_port #(T) comparator_before_port[num];
uvm_analysis_port #(T) comparator_after_port[num];
uvm_in_order_class_comparator #(T) comparator[num];
function new (string name, uvm_component parent);
super.new(name, parent);
before_export = new(“before_export”, this);
after_export = new(“after_export”, this);
for (int i=0; i < num; i++) begin
comparator[i] = new($sformatf(“comparator_%0d”, i), this);
comparator_before_port[i] =
new($sformatf(“comparator_before_port_%0d”, i), this);
comparator_after_port[i] =
new($sformatf(“comparator_after_port_%0d”, i), this);
end
endfunction
... // Continued on next page
238
Scoreboard: Multi-Stream
239
240
Agenda: Day 2
DAY
2
5 Component Configuration & Factory
6 TLM Communication
8 UVM Callback
241
Unit Objectives
242
Changing Behavior of Components
?
l How to add multiple extensions? error_driver delay_driver
class delay_driver extends my_driver;
?
class delay_driver extends error_driver; driver
4
3
2
1
243
Implementing UVM Callbacks
n Embed callback methods in components
n Create a façade callback class
n Develop callback classes extending from façade callback class
n Create and register callback objects in environment
uvm_object class
uvm_callbacks_base class
1
uvm_component class uvm_callbacks class 2
Embed Create
callback Component class User callback façade class façade
methods class
Create and 4
register in Test
Error Injection callback class
Coverage callback class
Test class
3 Implement callback methods
244
Step 1: Embed Callback Methods
245
Step 2: Declare the façade Class
246
Step 3: Implement Callback: Error
247
Step 4: Create and Register Callback Objects
248
Driver Coverage Example
n If there are no analysis ports in driver
l Callbacks can be the hooks for coverage also
typedef class driver;
class driver_callback extends uvm_callback;
// constructor not shown
virtual task pre_send(driver drv, packet tr); endtask
virtual task post_send(driver drv, packet tr); endtask
endclass
class driver extends uvm_driver #(packet);
`uvm_register_cb(driver, driver_callback)
// utils macro and constructor not shown
task run_phase(uvm_phase phase);
forever begin
seq_item_port.get_next_item(req);
`uvm_do_callbacks(driver, driver_callback, pre_send(this, req));
send(req);
`uvm_do_callbacks(driver, driver_callback, post_send(this, req));
seq_item_port.item_done();
end
endtask
endclass
249
Implement Coverage via Callback
n Create coverage class by extending from façade class
l Define covergroup in coverage class
l Construct covergroup in class constructor
l Sample coverage in callback method
250
Create and Register Callback Objects
251
Sequence Callback Methods
n uvm_sequence::pre_do() (task)
l called after the sequence::wait_for_grant() call and after the
sequencer has selected this sequence, but before the item is
randomized
n uvm_sequence::mid_do() (function)
l called after the sequence item randomized, but before it is sent
to driver
n uvm_sequence::post_do() (function)
l called after the driver indicates item completion,using
item_done/put
n uvm_sequence::pre_body() (task) User should not call
l Called before sequence body execution these methods directly.
Instead override in
n uvm_sequence::post_body() (task) sequence definition
l Called after sequence body execution
252
Unit Objectives Review
253
Lab 5 Introduction
Implement monitors and scoreboard
60 min Implement
Monitor
Classes
Implement
Scoreboard
Class
Compile
and
Simulate
254
Agenda: Day 3
DAY
3
9 Sequence Library/Virtual Sequencer
10 More on Phasing
12 Summary
255
Unit Objectives
256
UVM 1.0 Sequence Library
257
Building a Sequence Library Package
To enhance reuseability,
encapsulate sequence library
classes in a package A library class is a
package packet_seq_lib_pkg; repository of
import uvm_pkg::*; sequences of a
class packet extends uvm_sequence_item; particular data
... type
endclass
class packet_seq_lib extends uvm_sequence_library #(packet);
`uvm_object_utils(packet_seq_lib)
Macro builds the
`uvm_sequence_library_utils(packet_seq_lib)
infrastructure of
function new(string name = "packet_seq_lib");
super.new(name);
the sequence
init_sequence_library(); library
endfunction
Method allows
endclass
registration of
// continued on next page sequences into the
library
258
Building a Sequence Library
n Add base sequence and user sequence(s) to package
// continued from previous page
class packet_base_sequence extends uvm_sequence #(packet);
// object_utils macro and constructor not shown
virtual task pre_body();
if (starting_phase != null) See note
starting_phase.raise_objection(this);
endtask
virtual task post_body(); Extend from base
if (starting_phase != null) sequence to
starting_phase.drop_objection(this); create user
endtask
sequence
endclass
class atomic_sequence extends packet_base_sequence;
`uvm_object_utils(atomic_sequence)
`uvm_add_to_seq_lib(atomic_sequence, packet_seq_lib)
// Constructor not shown registers sequence in the
virtual task body();
`uvm_do(req);
library
endtask
endclass
endpackage
259
Register Sequence in Sequence Library
n Register additional test sequences as needed
class generic_sequence extends packet_sequence;
int item_count = 1; // utils macro and constructor not shown
`uvm_add_to_seq_lib(generic_sequence, packet_seq_lib)
task body();
if (!uvm_resource_db#(int)::read_by_name(…))
...
repeat(item_count)begin
`uvm_do(req);
end
endtask class SAeq3_sequence extends generic_sequence;
endclass `uvm_object_utils(SAeq3_sequence)
`uvm_add_to_seq_lib(SAeq3_sequence, packet_seq_lib)
// Constructor not shown
virtual task body();
if (!uvm_resource_db#(int)::read_by_name(…))
…
repeat(item_count) begin
`uvm_do_with(req, { sa == 3; } );
end
endtask
endclass
260
Reference Sequence Library in Environment
261
Create Test with Random Sequences
n By default ten random sequences from the
sequence library will be executed
program automatic test;
import uvm_pkg::*;
import packet_seq_lib_pkg::*;
// include other classes
class test_base extends uvm_test;
router_env env;
// component_utils and constructor not shown
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
env = router_env::type_id::create(“env”, this);
endfunction
endclass
initial
run_test();
endprogram Compile with vcs: (using UVM in VCS installation)
vcs –sverilog–ntb_opts uvm packet_seq_lib_pkg.sv test.sv
Simulate with:
simv +UVM_TESTNAME=test_base
262
Configure Sequence Library
n The default execution behavior can be modified via
the UVM uvm_sequence_library_cfg class
class uvm_sequence_library_cfg extends uvm_object;
`uvm_object_utils(uvm_sequence_library_cfg)
uvm_sequence_lib_mode selection_mode;
int unsigned min_random_count, max_random_count;
function new(string name="",
uvm_sequence_lib_mode mode=UVM_SEQ_LIB_RAND,
int unsigned min=1, int unsigned max=10);
endclass
n Combination of min_/max_random_count sets the
number of sequences to execute
n selection_mode can be one of four modes:
UVM_SEQ_LIB_RAND (Random sequence)
UVM_SEQ_LIB_RANDC (Random cyclic sequence)
UVM_SEQ_LIB_ITEM (Random item. No sequence)
UVM_SEQ_LIB_USER (User defined sequence execution)
263
Configure Sequence Library Example
264
Virtual Sequences
265
Virtual Sequence/Sequencer
n Typical sequence interacts with a single DUT interface
n When multiple DUT interfaces need to be synchronized
a virtual sequence is required
n Virtual Sequences in environment/test synchronize
timing and data between different interfaces
TOP
Environment
Virtual Sequencer
Agent Agent
Sequencer Sequencer
sequences Sequences
266
Virtual Sequence
n Embed sequence from different agents
n In body() method, control these sequences
class virtual_sequence extends uvm_sequence;
`uvm_object_utils(virtual_sequence)
`uvm_declare_p_sequencer(virtual_sequencer)
bfm_sequence bfm0_seq;
bfm_sequence bfm1_seq;
virtual task body();
`uvm_do_on(bfm0_seq, p_sequencer.bfm0_sqr);
`uvm_do_on(bfm1_seq, p_sequencer.bfm1_sqr);
endtask Environment
endclass
Virtual Sequencer
bfm_agt0 bfm_agt1
bfm_sqr bfm_sqr
bfm_seq bfm_seq
267
Virtual Sequencer
bfm_agt0 bfm_agt1
bfm_sqr bfm_sqr
bfm_seq bfm_seq
268
Connect Sequencer to Virtual Sequencer
Environment
Virtual Sequencer
bfm0_sqr Virtual sequence
bfm_agt0 bfm_agt1
bfm_sqr bfm_sqr
bfm_seq bfm_seq
270
Protecting Stimulus (Grab/Ungrab )
271
Unit Objectives Review
272
Agenda: Day 3
DAY
3
9 Sequence Library/Virtual Sequencer
10 More on Phasing
12 Summary
273
Unit Objectives
274
UVM Phasing
build
connect
end_of_elaboration
start_of_simulation
run reset
configure
main
shutdown
extract
check
report
final 275
Common Phases
Reset phase
reset reset reset
287
Lab 6 Introduction
Implement sequence library
30 min Implement
Sequence
library
Compile
and
Simulate
288
Agenda: Day 3
DAY
3
9 Sequence Library/Virtual Sequencer
10 More on Phasing
12 Summary
289
Unit Objectives
290
Register & Memories
291
Testbench without RAL
What about
sequence
•
coverage?
A typical test •
self-checking?
•
check reset value body() Host Sequencer •
randomization?
•
write value •
portability?
•
check value
device
drivers Host Driver
address HOST_ID
example
Port Ports
Host Other
data DUT LOCK
r_w register
REG_FILE
register
mapping
Memory
Memory
n Abstracts reading/writing to
configuration fields and Simulation
memories User Pre-defined
tests tests
n Supports both front door
and back door access Coverage Model
Spec
uvm_reg
n Mirrors register data backdoor
293
Testbench with RAL:
Sequencer
Register model with
Unchanged sequence Built-in:
body() Register model
•
coverage
New sequence uses •
self-checking
register models’ Adapter
•
randomization
abstraction to read •
portable structure
and write DUT fields
device
drivers
Driver Unchanged
address HOST_ID
Port Ports
Host Other
data DUT LOCK
r_w
REG_FILE
register
Memory
Memory
Coverage Model
Spec RAL Backdoor
RAL
access
Frontdoor RTL DUT
access BFM
295
Example Specification
Reset 0x00
data DUT LOCK
r_w
REG_FILE
register RAM (4K)
Memory Bits 15-0
RAM
Mode rw
296
Create Host Transaction and Component
class host_data extends uvm_sequence_item;
sequence Host Sequencer // constructor and utils macro not shown
typedef enum int unsigned {
body() READ,
WRITE
} kind_e;
rand kind_e kind;
run_phase Host Driver rand bit[15:0] addr, data;
endclass: host_data
device
drivers class host_driver extends uvm_driver
#(host_data);
// constructor and utils macro not shown
address task run_phase(uvm_phase phase);
Port Ports
Host Other
data DUT
r_w forever begin
register seq_item_port.get_next_item(req);
Memory data_rw(req); // call device driver
seq_item_port.item_done();
end
endtask
// device drivers not shown;
endclass: host_driver
297
Create Host BFM Sequence
sequencer
n Implement host sequence sequence
body()
298
Verify Frontdoor Host BFM is Working
memory
300
Step 2: Create .ralf File Based on Spec
system
module instance name in
DUT block
system dut_regmodel { block
bytes 2; register memory
register memory
block host_regmodel=HOST0 (blk0) @'h0000;
field field
block host_regmodel=HOST1 (blk1) @'h8000; field field
}
register
register
regfile
register
field
field
Optional: register
field
register
register
Create register model to be used at system
level
301
RAL File Field Syntax
n Field
l Contains Bits, Access, Reset Value, Constraints
field field_name {
[bits n;]
[access rw|ro|wo|w1|w0c|w1c|rc|...;]
[reset value;]
[<constraint name { <expressions> }>]
[enum { <name[=val],> }]
} system
block
block
register memory
register memory
field REV_ID { field field
field field
bits 8;
access ro; register
register
regfile
register
reset ’h03; field
field
register
field
register
register
}
302
RAL: Field Properties
303
RAL: Field Access Types
RW read-write
RO read-only
WO write-only; read error
W1 write-once
WO1 write-once; read error
W0C/S/T write a 0 to bitwise-clear/set/toggle matching bits
W1C/S/T write a 1 to bitwise-clear/set/toggle matching bits
RC/S read clear /set all bits
WC/S write clear /set all bits
WOC/S write-only clear/set matching bits; read error
WRC/S read clear/set all bits
WSRC [WCRS] write sets all bits; read clears all bits [inverse]
W1SRC [W1CRS] write one set matching bits; read clears all bits [inverse]
W0SRC [W0CRS] write zero set matching bits; read clears all bits [inverse]
304
RAL File Register Syntax
n Register
l Contains fields
register reg_name {
[bytes n;]
[left_to_right;]
[<field name[=rename] [[n]] [@bit_offset[+incr]];>]
[<field name[[n]] [(hdl_path)] [@bit_offset] {<properties>}>]
[<constraint name {<expression>}>]
[shared [(hdl_path)];]
[doc {<text>}] system
} block
block
register memory
register memory
field field
register HOST_ID { field field
field REV_ID; register
register
regfile
register
field CHIP_ID { ... }
field
field
} register
field
register
register
305
RAL: Register Properties
306
RAL File Register FILE Syntax
n Register File
l Contains register(s)
regfile regfile_name {
[<register name[=rename][[n]][(hdl_path)][@offset];>]
[<register name[[n]] [(hdl_path)] [@offset]
{<property>}]
[<constraint name {<expression>}>]
[shared [(hdl_path)];]
[doc {<text>}] system
} block
block
regfile REG_FILE { register memory
register memory
register HOST_REG { field field
field USER_REG { field field
bits 16; register
register
regfile
register
access rw; field
reset ’h00; field
register
field
register
register
}}}
307
RAL: Register File Properties
308
RAL File Memory Syntax
n Memory
l Leaf level component
memory mem_name {
size m[k|M|G];
bits n;
[access rw|ro;]
[initial x|0|1|addr|literal[++|--];]
[shared [(hdl_path)];]
[doc {<text>}] system
} block
block
register memory
register memory
memory RAM { field field
field field
size 4k;
register
register
bits 16; regfile
register
access rw; field
field
register
field
register
register
}
309
RAL: Memory Properties
310
RAL File Block Syntax
n Blocks
l Instantiated in system
l The smallest functional unit that can be verified is a block
l Can have domains specified for corresponding physical
interfaces (minimum of two if specified)
block blk_name {
<proptery>
system
}
block
block
block blk_name { register memory
register memory
domain name { field field
field field
<property>
} register
register
regfile
register
<domain name { field
field
register
field
register
register
<property>
}
}
311
RAL File Block Syntax
n Blocks
l Contains register or memory elements
block blk_name {
bytes n;
[endian no|little|big|fifo_ls|fifo_ms;]
[<register name[=rename] [[n]][(hdl_path)] [@offset];>]
[<register name[[n]][(hdl_path)][@offset] {<property>}]
[<regfile name[=rename] [[n]] [(hdl_path)] [@offset] [+incr];>]
[<regfile name[[n]][(hdl_path)][@offset] [+incr] {<property>}]
[<memory name[=rename] [(hdl_path)] [@offset];>]
[<memory name [(hdl_path)] [@offset] {<property>}>]
[<constraint name {<expression>}>]
[doc {<text>}] block host_regmodel {
} bytes 2;
register HOST_ID (host_id)
@’h0000;
register PORT_LOCK (lock)
@’h0100;
register HOST_REG[256] (host_reg[%d])
@’h1000; Must add
index 312
RAL: Block Properties
313
RAL File System Syntax
system sys_name {
<proptery>
}
system
system sys_name { block
block
domain name { register
register memory
<property> memory
field field
} field field
<domain name { register
register
regfile
register
<property>
field
field
} register
field
register
register
}
314
RAL File System Syntax
system sys_name {
bytes n;
[endian no|little|big|fifo_ls|fifo_ms;]
[<block name[[.domain]=rename][[n]][(hdl_path)]@offset[+incr];>]
[<block name[[n]] [(hdl_path)] @offset [+incr] {<property>}>]
[<system name[[.domain]=rename][[n]][(hdl_path)]@offset[+incr];>]
[<system name[[n]][(hdl_path)] @offset [+incr] {<property>}]
[<constraint name {<expression>}>]
[doc {<text>}]
}
system dut_regmodel {
bytes 2;
block host_regmodel=HOST0 @'h0000;
block host_regmodel=HOST1 @'h8000;
}
315
Step 3: Use ralgen to Create RAL Model
// host.ralf // ral_dut_regmodel.sv
register HOST_ID {
class ral_reg_HOST_ID extends uvm_reg; UVM
uvm_reg_field REV_ID; RAL
field REV_ID {…} uvm_reg_field CHIP_ID;
field CHIP_ID {…} ... Classes
} endclass : ral_reg_HOST_ID
register PORT_LOCK { class ral_reg_PORT_LOCK extends uvm_reg;
field LOCK {…} class ral_reg_HOST_REG extends uvm_reg;
} class ral_mem_RAM extends uvm_mem;
class ral_block_host_regmodel extends uvm_reg_block;
register HOST_REG { rand ral_reg_HOST_ID HOST_ID;
field USER_REG {…} rand ral_reg_PORT_LOCK PORT_LOCK;
} rand ral_reg_HOST_REG HOST_REG[256];
memory RAM {…} rand ral_mem_RAM RAM;
block host_regmodel {…}
host.ralf ...
system dut_regmodel {…} endclass : ral_block_host_regmodel
class ral_sys_dut_regmodel extends uvm_reg_block;
rand ral_block_host_regmodel HOST0;
rand ral_block_host_regmodel HOST1;
...
endclass : ral_sys_dut_regmodel
316
UVM Sequence Using RAL
class host_bfm_sequence extends uvm_sequence#(host_data);
// utils macro and constructor
virtual task body();
if (starting_phase != null) starting_phase.raise_objection(this);
`uvm_do_with(req, {addr==’h000; kind==host_data::READ;});
`uvm_do_with(req, {addr==’h100; data==’1; kind==host_data::WRITE;});
if (starting_phase != null) starting_phase.drop_objection(this);
endtask
endclass
Becomes
Adapter is required to
use existing test
Sequencer
structure
Unchanged sequence
body() Register model Ralgen
generated
Adapter
classes
device
drivers
Driver Unchanged
address HOST_ID
Port Ports
Host Other
320
Connect RAL in Environment
sequence
body() Register model
Adapter
device
drivers
321
Step 6: RAL Test
endfunction
322
Built-in Test Implementation
n Instantiate built-in test to do self-tests
class hw_reset_test extends test_base;
reset_sequence reset_seq;
uvm_reg_hw_reset_seq reset_test; Built-in test
instance
// utils macro and constructor left off
324
Appendix
325
UVM RAL Register Modes
326
UVM RAL Register Modes
n Mirror set/get/update
...
reg
Mirrored
reg
...
reg
run
sequence
run
device ...
body() drivers
reg
327
Frontdoor Write
n register.write(.value(data), .path(UVM_FRONTDOOR));
l Sequence creates WRITE transaction with value
l Sequencer passes transaction to driver via TLM port
l Driver calls device drivers to set value Mirror
l Mirror content is updated with value Desired
reg
if auto predict is set in map
regmodel.default_map.set_auto_predict(1); ...
reg
Mirrored
reg
...
reg
run
sequence
run
device ...
body() drivers
reg
328
Frontdoor Read
n register.read(.value(data), .path(UVM_FRONTDOOR));
l Sequence creates READ transaction with value
l Sequencer passes transaction to driver via TLM port
l Driver calls device drivers to read value Mirror
l Mirror content is updated with value Desired
Mirrored
reg
...
reg
run
sequence
run
device ...
body() drivers
reg
329
Backdoor Write
n register.write(.value(data) , .path(UVM_BACKDOOR));
l Write method set value in DUT via XMR
Mirror
l Mirror content is updated with value Desired
if auto predict is set in map reg
regmodel.default_map.set_auto_predict(1); ...
reg
Mirrored
reg
...
reg
run
sequence
run
device ...
body() drivers
reg
330
Backdoor Read
n register.read(.value(data) , .path(UVM_BACKDOOR));
l Read method get value from DUT via XMR
Mirror
l Mirror content is updated with value Desired
if auto predict is set in map reg
regmodel.default_map.set_auto_predict(1); ...
reg
Mirrored
reg
...
reg
run
sequence
run
device ...
body() drivers
reg
331
Mirror Read
n data = register.get();
l Get value from desired mirror
Mirror
Desired
reg
...
reg
Mirrored
reg
...
reg
run
sequence run
device ...
body() drivers
reg
332
Mirror Write
n register.set(.value(data));
l Set method set value in desired mirror
Mirror
Desired
reg
...
reg
Mirrored
reg
...
reg
run
sequence run
device ...
body() drivers
reg
333
Mirror Value Creation
n register.randomize();
l Populate desired mirror with random value
Mirror
Desired
reg
...
reg
Mirrored
reg
...
reg
run
sequence run
device ...
body() drivers
reg
334
Mirrored & DUT Value Update
n register.update();
l Update DUT and mirrored values with desired mirror
value if mirrored value is different from desired value
Mirror
Desired
reg
...
reg
Mirrored
reg
...
reg
run
sequence run
device ...
body() drivers
reg
335
Mirrored & Desired Value Update
n register.mirror();
l Update mirrored and desired values with DUT register
content
Mirror
Desired
reg
...
reg
Mirrored
reg
...
reg
run
sequence run
device ...
body() drivers
reg
336
UVM RAL Built-In Tests
337
UVM RAL Test Sequences
n Some of these test sequences depend on mirror to
be updated when backdoor is used to access DUT
registers
n You should set auto predict in test
regmodel.default_map.set_auto_predict(1);
DAY
3
9 Sequence Library/Virtual Sequencer
10 More on Phasing
12 Summary
339
Key Elements of UVM
n Methodology
n Scalable architecture
n Standardized component communication
n Customizable component phase execution
n Flexible components configuration
n Reusable register abstraction
340
UVM Methodology Guiding Principles
n Approaches
Directed
l Reuse Testcase Functional
Add
u Across tests constraints Coverage
u Across blocks
Minimal Code Identify
u Across systems
Modifications holes
u Across projects
l One verification environment, many tests
l Minimize test-specific code
341
Scalable Architecture
n Interface based agent enables block to system reuse
Top Level Harness
Test
Environment
Scoreboard
DUTA DUTB
342
Standardized Component Communication
n TLM 1.0 built into the base class
n TLM 2.0 for cross language support
Scoreboard/
coverage
DUTA
343
Customizable Component Phase Execution
n Component phases are synchronized
l Ensures correctly organized configuration and execution
l Can be customized
component A component B component C
configure
configure
time
main main
main
shutdown
shutdown
344
Flexible Components Configuration (1/3)
n uvm_config_db#(_type)::get(...)
class driver extends …; // simplified code
virtual router_io sigs;
function void build_phase(uvm_phase phase);
super.build_phase(phase);
if (!uvm_config_db#(virtual router_io)::get(this, "",
"router_io", sigs))
`uvm_fatal("CFGERR", "Driver DUT interface not set");
endfunction
endclass
n uvm_config_db#(_type)::set(...)
345
Flexible Components Configuration (2/3)
sequence
n Physical addresses body() Register model
are abstracted away
Translator
n Sequences does not
need modification device
throughout block to drivers
system integration
address HOST_ID
Port Ports
Host Other
data DUT LOCK
r_w
REG_FILE
register
Memory
Memory
349
Lab 7 Introduction
Implement RAL
Implement
register sequence
without RAL
60 min
Compile and
Simulate
Create RAL
representation
Create register
sequence with RAL
Compile and
Simulate
350
That’s all Folks!
351
352