Vous êtes sur la page 1sur 5

Verification Academy Patterns Library

Verification Academy Patterns Library


Pattern Name: Façade Pattern
 Intent: A façade pattern provides a simple interface to a complex system,
making it easier for the client or external world to use.

 Motivation: In UVM world, if we have to send sequences across different agents


in a coordinated manner the top level sequence would need to refer to multiple
agents.

 Applicability: Façade Pattern which is a Gang of Four’s structural pattern helps


solve the problem of providing a simple interface to a complex system. It can
provide an entry point to multiple environments from the top level.

 Structure:

Page 1 © Mentor Graphics Corporation, all rights reserved.


Verification Academy Patterns Library

 Implementation: The façade pattern is implemented in 3 places in the example


below: GPIO env, UART env and SoC level env.

Using the GPIO env as an example, we see that the virtual_sequencer class has
references to the sequencer (sqr) of Bus Agent and GPIO Agent. The UART
environment level sequences (virtual sequences) can now be run using the
virtual sequencer in the UART env. Similarly, when you integrate multiple
environments together, we could have a top level virtual sequencer which has
references to lower level sequences thereby providing the top level sequence a
simpler interface to the environments below.

 Example:

// Virtual sequencer class:


class virtual_sequencer extends uvm_virtual_sequencer;

`uvm_component_utils(virtual_sequencer)

Page 2 © Mentor Graphics Corporation, all rights reserved.


Verification Academy Patterns Library

// Note that the handles are in terms that the test writer understands
bus_master_sequencer bus;
gpio_sequencer gpio;

function new(string name = "virtual_sequencer", uvm_component parent =


null);
super.new(name, parent);
endfunction

endclass: virtual_sequencer

class env extends uvm_env;

// Relevant parts of the env which combines the


// virtual_sequencer and the bus and gpio agents
//
// Build:
function void build_phase( uvm_phase phase );
m_bus_agent = bus_master_agent::type_id::create("m_bus_agent", this);
m_gpio_agent = gpio_agent::type_id::create("m_gpio_agent", this);
m_v_sqr = virtual_sequencer::type_id::create("m_v_sqr", this);
endfunction: build_phase

// Connect - where the virtual_sequencer is hooked up:


// Note that these references are constant in the context of this env
function void connect_phase( uvm_phase phase );
m_v_sqr.bus = m_bus_agent.m_sequencer;
m_v_sqr.gpio = m_gpio_agent.m_sequencer;
endfunction: connect_phase

endclass:env

// Virtual sequence base class:


//
class virtual_sequence_base extends uvm_sequence #(uvm_sequence_item);

`uvm_object_utils(virtual_sequence_base)

// This is needed to get to the sub-sequencers in the


// m_sequencer
virtual_sequencer v_sqr;

// Local sub-sequencer handles


bus_master_sequencer bus;
gpio_sequencer gpio;

function new(string name = "virtual_sequence_base");


super.new(name);
endfunction

// Assign pointers to the sub-sequences in the base body method:


task body();
if(!$cast(v_sqr, m_sequencer)) begin
`uvm_error(get_full_name(), "Virtual sequencer pointer cast
failed");
end
bus = v_sqr.bus;

Page 3 © Mentor Graphics Corporation, all rights reserved.


Verification Academy Patterns Library

gpio = v_sqr.gpio;
endtask: body
endclass: virtual_sequence_base
// Virtual sequence class:
//
class example_virtual_seq extends virtual_sequence_base;

random_bus_seq bus_seq;
random_gpio_chunk_seq gpio_seq;

`uvm_object_utils(example_virtual_seq)

function new(string name = "example_virtual_seq");


super.new(name);
endfunction

task body();
super.body; // Sets up the sub-sequencer pointers
gpio_seq = random_gpio_chunk_seq::type_id::create("gpio_seq");
bus_seq = random_bus_seq::type_id::create("bus_seq");

repeat(20) begin
bus_seq.start(bus);
gpio_seq.start(gpio);
end
endtask: body

endclass: example_virtual_seq

// Inside the test class:


//
task run;
example_virtual_sequence test_seq =
example_virtual_sequencer::type_id::create("test_seq");

//...
test_seq.start(m_env.m_v_sqr);
//...
endtask: run

 Related Patterns: Sometime it is easy to confuse Façade with the Adaptor


Pattern. Façade provides a simpler interface to the client or outside world while
an Adaptor Pattern is used to modify/change the interface of a class to suit the
client/outside world’s requirement.

 Contributor: Pradeep Salla

Verification Academy – UVM Cookbook


https://sourcemaking.com/design_patterns/facade
https://en.wikipedia.org/wiki/Facade_pattern
Page 4 © Mentor Graphics Corporation, all rights reserved.
Verification Academy Patterns Library

 Release Date: May 9, 2016

Corrections and Suggestions: To improve the quality of the Verification Academy


Patterns Library we welcome your comments, suggestions, and corrections. Please
contact us at: https://verificationacademy.com/contact

Page 5 © Mentor Graphics Corporation, all rights reserved.

Vous aimerez peut-être aussi