You are on page 1of 20

Advanced UVM

Architecting a UVM Testbench

Tom Fitzpatrick
Verification Evangelist

info@verificationacademy.com | www.verificationacademy.com
UVM Testbench - Architectural Design
For Each Interface:
• How does the interface work?
• What information is transferred?
• Transaction variants? DUT
• Uni/bidirectional? Pipelined? APB

SPI
For the Design: IRQ I/F

• What does it do?


• What are the use cases?
• Which test cases are required?
• What type of stimulus scenarios are required?
• What represents correct behavior?
• What kind of functional coverage do I need?
© 2013 Mentor Graphics Corporation, all rights reserved.
UVM Structural Building Block: Agent

Analysis port: Send Detects transactions


transactions for checking on the interface

- Contains virtual Agent


interface handle One per
Configuration interface
- Pass information Monitor
on how agent Object
should behave
Sequencer
Driver DUT
Sends stimulus seq_item
to Driver

Stimulus Converts seq_item to pin wiggles


© 2013 Mentor Graphics Corporation, all rights reserved.
UVM Architecture: Block-Level Env/Test

Test
Test
Test
Test
Test
Test
Test
Environment
Coverage
Test
seq Collector
Seqs

Agent
Bkgrnd
seq Configuration
Seqs Object
Monitor DUT
Env Config Config Sequencer
A Config A Config Driver

© 2013 Mentor Graphics Corporation, all rights reserved.


UVM Architecture: Block-Level Env/Test
Test
Test
Test
Environment

Agent2
Test Configuration
Monitor
Seqs Object
Environment
Coverage Sequencer
Collector Driver

Score

Agent1
Bkgrnd Configuration
Seqs Monitor
Object

Env Config Config Sequencer


Driver
DUT
A2 Config A2 Config
A1 Config A1 Config

© 2013 Mentor Graphics Corporation, all rights reserved.


UVM Architecture: Integration-Level Env/Test
Test
Test
Test
Environment

Agent2
Test Configuration
Seqs Object
Monitor DUT
Score
Coverage Sequencer
Collector Driver

Score

Agent1
Bkgrnd Configuration
Seqs Monitor
Object

Env Config Config Sequencer


Driver
DUT
E2 Config E2 Config
A2
E1 Config E1 Config
A1

© 2013 Mentor Graphics Corporation, all rights reserved.


Introducing Phasing
• UVM execution is controlled by phases
<task/func> phasename_phase(uvm_phase phase); build
connect
• Build is called top-down end_of_elab
• Facilitates hierarchical instantiation and start_of_sim
configuration run
(task)
• All others called bottom-up
extract
• run_phase() is the only task check
report
• All run_phase methods execute in parallel final
• Don’t use alternate run-time phases
© 2013 Mentor Graphics Corporation, all rights reserved.
Building the Agent
class dut_agent extends uvm_component;
`uvm_component_utils(dut_agent)
dut_agent_cfg m_cfg;
dut_driver m_driver;
uvm_sequencer #(dut_txn) m_seqr;
dut_monitor m_monitor;
uvm_analysis_port #(dut_txn) ap;

function void new(string name, uvm_component parent);


super.new(name, parent); Agent
endfunction Configuration
Object Monitor

Sequencer
endclass Driver DUT

© 2013 Mentor Graphics Corporation, all rights reserved.


Agent: The Build Phase
class dut_agent extends uvm_component;
function void build_phase(uvm_phase phase);
if(!uvm_config_db #(dut_agent_cfg)::get(this,“”,“cfg”,m_cfg))
`uvm_fatal(“Config fatal”,“Can’t get config”);
if(m_cfg.active == UVM_ACTIVE) begin
m_seqr = uvm_sequencer#(dut_txn)::type_id::create(“sq”,this);
m_driver = dut_driver::type_id::create(“driver”,this);
end
m_monitor = dut_monitor::type_id::create(“monitor”,this);
… Agent
endfunction Configuration
Object Monitor

endclass
Sequencer
Driver DUT

© 2013 Mentor Graphics Corporation, all rights reserved.


Agent: The Connect Phase
class dut_agent extends uvm_component;
function void connect_phase(uvm_phase phase);
m_monitor.vif = m_cfg.vif;
ap = m_monitor.ap;
if(m_cfg.active == UVM_ACTIVE) begin
m_driver.seq_item_port.connect(m_seqr.seq_item_export);
m_driver.vif = m_cfg.vif;
end

endfunction Agent
Configuration
Object Monitor

endclass
Sequencer
Driver DUT

© 2013 Mentor Graphics Corporation, all rights reserved.


The Environment: Declaration
class my_env extends uvm_env;
`uvm_component_utils(my_env)
agent1 m_agent1;
agent2 m_agent2;
my_score m_score;
my_cov m_cov;
my_env_config m_cfg;

function new(string name = “my_env”,


Environment

uvm_component parent = null);


Agent2

super.new(name, parent);
Environment
Coverage
Collector

endfunction Score

Agent1

Config
A2 Config
DUT

endclass
A1 Config

© 2013 Mentor Graphics Corporation, all rights reserved.


The Environment: Build_phase
class my_env extends uvm_env;
function void build_phase(uvm_phase phase);
if(!uvm_config_db #( my_env_config )::get( this , "",
“my_env_config" , m_cfg ) begin
`uvm_fatal("build_phase", "unable to get my_env_config")
end
uvm_config_db #(agent1_config)::set(this , "m_agent1*",
"agent1_config", m_cfg.m_agent1_cfg );
m_agent1 = agent1::type_id::create(
Environment

"m_agent1", this);
Agent2


Environment
Coverage
Collector

endfunction:build_phase Score

endclass
Agent1

Config
A2 Config
DUT
A1 Config

© 2013 Mentor Graphics Corporation, all rights reserved.


The Environment: Build_phase
class my_env extends uvm_env;
function void build_phase(uvm_phase phase);

uvm_config_db #(agent2_config)::set(this , "m_agent2*",
"agent2_config", m_cfg.m_agent2_cfg );
m_agent2 = agent2::type_id::create("m_agent2", this);
if(m_cfg.has_my_score)
m_score = my_score::type_id::create("m_score", this);
if(m_cfg.has_coverage)
Environment

m_cov = my_cov::type_id::create(“m_cov”,
Agent2

this);
Environment
Coverage
Collector

endfunction:build_phase Score

endclass
Agent1

Config
A2 Config
DUT
A1 Config

© 2013 Mentor Graphics Corporation, all rights reserved.


The Environment: Connect_phase
class my_env extends uvm_env;
function void connect_phase(uvm_phase phase);
if(m_cfg.has_my_score) begin
m_agent1.ap.connect(m_score.apb.analysis_export);
m_agent2.ap.connect(m_score.spi.analysis_export);
end
if(m_cfg.has_coverage)
m_agent1.ap.connect(m_cov.analysis_export);
endfunction: connect_phase
Environment

Agent2

Environment
Coverage
Collector

Score

endclass
Agent1

Config
A2 Config
DUT
A1 Config

© 2013 Mentor Graphics Corporation, all rights reserved.


The Base Test
class my_test_base extends uvm_test;
`uvm_component_utils(my_test_base)

my_env m_env;
my_agent1_config m_a1_cfg;
my_agent2_config m_a2_cfg;
my_env_cfg m_cfg; Config
A2 Config
A1 Config

function new(string name = “my_test_base”,


Environment

uvm_component parent = null);


Agent2

super.new(name, parent);
Environment
Coverage
Collector

endfunction Score

Agent1

Config
A2 Config
DUT

endclass
A1 Config

© 2013 Mentor Graphics Corporation, all rights reserved.


The Base Test: Build_phase
class my_test_base extends uvm_test;
`uvm_component_utils(my_test_base)

function void build_phase( uvm_phase phase );


m_cfg = my_env_cfg::type_id::create(“m_env_cfg”);
configure_env();// setup configuration for env and agents
uvm_config_db#(my_env_cfg)::set(this,"*",
“my_env_config", m_cfg);
Config
A2 Config
A1 Config

m_env = my_env::type_id::create("m_env",
Environment

this);
Agent2

endfunction
Environment
Coverage
Collector

Score

endclass
Agent1

Config
A2 Config
DUT
A1 Config

© 2013 Mentor Graphics Corporation, all rights reserved.


The Actual Test
class my_test extends uvm_test_base;
`uvm_component_utils(my_test)
my_virt_seq m_vseq;

function new(string name = “my_test”,


uvm_component parent = null);
super.new(name, parent);
endfunction vseq
Config
A2 Config
A1 Config

function void build_phase( uvm_phase phase ); Agent2

super.build_phase(phase); Coverage
Collector

endfunction Score

endclass
Agent1

Config
A2 Config
DUT
A1 Config

© 2013 Mentor Graphics Corporation, all rights reserved.


The Actual Test
class my_test extends uvm_test_base;
`uvm_component_utils(my_test)

task run_phase(uvm_phase phase);


m_vseq = my_virt_seq::type_id::create(“my virtual seq”);
phase.raise_objection(this, “Starting virtual sequence”);
m_vseq.start();
phase.drop_objection(this, vseq
Config
seq2
seq1 A2 Config
A1 Config

“Finished virtual sequence”); Environment

endtask Agent2

Environment
Coverage
Collector

Score

endclass
Agent1

Config
A2 Config
DUT
A1 Config

© 2013 Mentor Graphics Corporation, all rights reserved.


Architecture Summary
• Agents are protocol-specific
• Environments define the testbench topology
• Which agents and how many
• Other components
• Base Test instantiates env and handles default
configuration
• Extend the base test to define your test
• Tweek configuration and/or factory settings
• Start (virtual) sequence(s)
• Test handles phase objections
• Keep to basic phasing
© 2013 Mentor Graphics Corporation, all rights reserved.
Advanced UVM
Architecting a UVM Testbench

Tom Fitzpatrick
Verification Evangelist

info@verificationacademy.com | www.verificationacademy.com

You might also like