31
DAC2003 Accellera SystemVerilog Workshop 127 Agenda Session 3: SystemVerilog Assertions Language Tutorial Bassam Tabbara, Novas Software Technology and User Experience Alon Flaisher, Intel Session 1: SystemVerilog for Design Language Tutorial Johny Srouji, Intel User Experience Matt Maidment, Intel Introduction: SystemVerilog Motivation Vassilios Gerousis, Infineon Technologies Accellera Technical Committee Chair Using SystemVerilog Assertions and Testbench Together Jon Michelson, Verification Central Session 4: SystemVerilog APIs Doug Warmke, Model Technology Lunch: 12:15 – 1:00pm Session 2: SystemVerilog for Verification Session 5: SystemVerilog Momentum Verilog2001 to SystemVerilog Stuart Sutherland, Sutherland HDL Language Tutorial Tom Fitzpatrick, Synopsys SystemVerilog Industry Support Vassilios Gerousis, Infineon User Experience Faisal Haque, Verification Central End: 5:00pm

Ethernet Testbench SV

Embed Size (px)

Citation preview

Page 1: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 127

AgendaSession 3: SystemVerilog Assertions

Language TutorialBassam Tabbara, Novas Software

Technology and User ExperienceAlon Flaisher, IntelSession 1:

SystemVerilog for DesignLanguage Tutorial

Johny Srouji, IntelUser ExperienceMatt Maidment, Intel

Introduction:SystemVerilog Motivation

Vassilios Gerousis, Infineon TechnologiesAccellera Technical Committee Chair

Using SystemVerilog Assertionsand Testbench Together

Jon Michelson, Verification Central

Session 4: SystemVerilog APIsDoug Warmke, Model Technology

Lunch: 12:15 – 1:00pm

Session 2:SystemVerilog for Verification Session 5: SystemVerilog Momentum

Verilog2001 to SystemVerilogStuart Sutherland, Sutherland HDLLanguage Tutorial

Tom Fitzpatrick, SynopsysSystemVerilog Industry Support

Vassilios Gerousis, InfineonUser Experience

Faisal Haque, Verification CentralEnd: 5:00pm

Page 2: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 128

Goals of this presentation• Understand the testbench model for

SystemVerilog • Show how SystemVerilog constructs are

used to build testbenches• Walk through the construction of a

testbench for an Ethernet MAC

Page 3: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 129

My Background• Chair of SystemVerilog Assertions

committee• Co-author of “The Art of Verification with

Vera” • Co-author of upcoming SystemVerilog

book

www.verificationcentral.com

Page 4: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 130

packets

tran

sact

or

0101010

Gen

erat

or

Des

ign

Und

er T

est

0101010

tran

sact

or

Che

cker

packets

Dire

ctor

PredictResponse

Coverage Monitor

classes interfaces

A Typical TestbenchAdapted from “The Art of Verification with Vera”

Page 5: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 131

Recommended SV constructs for use in testbench• Program block• Classes• Interfaces• Clocking• Mailboxes, semaphores• Constraints and random variables• Assertions

Page 6: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 132

Program Block• Testbench implemented as multiple program blocks– For example: generator, checker in separate program blocks

• Testbench implemented as a single program block – Classes instantiated within program block

• Program block with classes instantiated within the interface

Page 7: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 133

Testbench implementation options

DUT

interface(s)Transactor(s)

ProgramGen

ProgramChecker

test_top.v

DUT

interface(s)Transactors

Program

GenChecker

test_top.v

DUT

interface(s)Transactors

GenChecker

test_top.v

Page 8: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 134

Classes• Provide a mechanism to encapsulate data • Recommended for almost all testbench

components• Layer classes to build powerful structures

Generator

Pkt Gen MII EventGen

Network Event Gen

Packet

Page 9: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 135

Interfacing to the Design Under Test (DUT)• Use interface to logically group ports• interfaces can also instantiate tasks, program blocks or classes to act as transactors

• Classes instantiated inside program blocks will execute in the reactive region of SystemVerilog (Cycle based)

• Classes instantiated outside program blocks will display event based semantics

• Use clocking to define synchronization of the DUT ports with the Testbench

Page 10: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 136

Mailboxes and Semaphores• Use Mailboxes to pass messages between

two threads– Can be used to represent FIFO

implementations• Use semaphores to arbitrate between two

or more threads

Page 11: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 137

Ethernet MAC Testbench

MAC

MII xctor Monitor

Hostxctor

Monitor

cpu transactor

cpu monitor

classes

Expect queue

Pkt Gen

HostxctorFifo Event

Gen

Pkt GenMII

xctorEvent Gen

Interface-tasks

Page 12: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 138

Ethernet MAC

TXU

TxReady

TxSelect

TxEN

TxEOP

TxSOP

TxData 31-0

RXU

Reg

interface host_tx;input [31:0] txdata;input txselect;input txsop;input txeop;input txen;output txrdy;

task drive_packet (Packet packet);...endtask

endinterface

interface host_rx;. . . interface mii_tx;. . .interface mii_rx;. . .

Page 13: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 139

interfaces as TransactorsInterfaces

MAC

host_tx

host_rx

cpu

Interfaces

mii_tx

mii_rx

Page 14: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 140

Using clocking to interface to DUT

Gen

MonXa

ctor

Program Block

Clocking

DUT

clocking mac_host_tx_host @(posedge CLK);input [31:0] txdata;input txselect;input txsop;input txeop;input txen;output txrdy;

endclocking

Page 15: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 141

Program Blockprogram mac_tb (host_tx, host_rx, mii_rx, mii_tx);

clocking mac_host_tx_host @(posedge CLK);

. . .

endclocking

Host_gen host_gen;

Host_mon host_mon;

MII_gen mii_gen;

Mii_mon mii_mon;

initial begin

host_gen = new (…);

host_mon = new ();

mii_gen = new ();

mii_mon = new (…);

end

endprogram

Page 16: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 142

Generators• Implemented as classes instantiated

inside program block

RandomVariables

ControlVariables

constraints

• Use random variables and constraints to generate stimulus

• Three components– Random variables– Control variables– Constraints

Page 17: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 143

Packet Generator:Overview• Must generate Ethernet packets• Host Side, MII Side• Vary length from 64- to 1522– byte

packages• Generate destination address

– Dest. address match MAC address or not match MAC address

– Unicast, multicast or broadcast addresses• Calculate CRC

Page 18: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 144

A Simple Packet Classclass Packet;

rand bit [47:0] sa;rand bit [47:0] da;rand bit [15:0] typeLen;rand byte payld [];rand bit [31:0] crc;

//control variablesint min_length;int max_length;bit [47:0] mac_addr;

constraint len_lim {payld.size >= min_length;payld.size <= max_length;

}

extern task new ();extern task calc_crc ();extern task set_lim (int maxlen,

int minlen=64);extern task pr ();extern function Packet cp ();extern task set_mac_addr ();

endclass

Random variables

Dynamic arrayBoth length and contents

will be randomized

Controlvariables

Constraints

Methods

Page 19: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 145

Destination Address Generation

typedef enum {unicast, multicast, bcast} pkt_type;

class GenDa ;bit [47:0] mac_addr;rand bit [47:0] dest_addr;rand pkt_type pktType;rand bit match_mac_addr;rand bit [1:0] cast;

constraint da_lim {match_mac_addr=>(dest_addr == mac_addr);

}

constraint cast_lim {(pktType == unicast)=> cast = 2'b10;(pktType == multicast) => cast = 2'b11;(pktType == bcast)=> dest_addr= 48{1’b1};

}extern task new ();extern task set_mac_addr ();task post_randomize ();

if ((pktType == unicast) || (pktType == multicast))dest_addr [47:46] = cast [1:0];

endtask

endclass

User-Defined post_randomize

method called automatically after

randomize

Page 20: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 146

Simple Packet Generator• Uses

– Packet randomization class

– Destination address generation class

class Gen;rand Packet packet;rand Destaddr destaddr;rand int pktcnt;extern task genPkt ();extern task send_packet ();

endclass

task Gen::genPkt ();set_ctl_var ();if (!this.randomize ())

$display (“randomize failed”);for (i=0; i < pktcnt; i++) begin

void=packet.randomize();packet.calc_crc ();send_packet ();repeat (10)@(posedge CLOCK);

endendtask

Randomize data

Calculate CRC

Send packet to transactor

Page 21: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 147

Checkers and monitors: Overview• One checker on each side

– Host side– MII side

• Relies on expect queues to determine correctness of packet received– Implemented using mailboxes

• Issue with packet drops

Page 22: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 148

Testbench Implementation : Response Checking• Expect Queue predicts packet arrival order

– Issue with discontinuities in packet arrival• Packet drops

MAC

Host xactr 0101010 0101010

Expect QueuePackets

Transmit Unit

Monitor

Packets

ProcessMessages

==

packets

Page 23: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 149

Implementation of Expect Queue• Simple FIFO implemented using

mailboxes– Handling dropped packets

• Occupancy counter to predict overflows in the FIFO

– Drop incoming packets on FIFO overflow

• Linked list implementation using classes– Packets removed from queue if dropped

Page 24: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 150

Implementation of Expect Queueclass Expqueue;

mailbox#(Packet) exp_mbx;int qsize;int max_qsize;

function new (int max_size, int mbxid);extern task push(Packet p);extern task pop (Packet p);

endclass

task Expqueue::push (Packet p);if ((qsize+1) <= max_qsize) begin

exp_mbx.put (p);qsize++;

endendtasktask Expqueue::pop (Packet p);

exp_mbx.get (p);qsize –-;

endtask

qsize

push

pop

+ -

Page 25: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 151

Example Checker

Host RxXactor

Get packet fromexpect queuecheck packet

rcv_packet();

Compare packetsUpdate statsPrint results

check_packet();

Packetreceived

Hos

t C

heck

er

Exp Q

class Hostchk ;mailbox#(Packet) exp_mbx;Packet rx_packet;Packet exp_packet;

Stats test_stats;

extern function new (Stats stats, int mblen=0);extern task rcv_packet (Packet rcv_p);extern task check_packet ();

endclass

task Hostchk::new (Stats stats, int mblen=0);test_stats =stats;exp_mbx = new(mblen);

endtask

Page 26: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 152

Example Checker (cont’d)

task Hostchk::check_packet ();

if (rx_packet.cmp(exp_packet)) begin

$display (“Packet Received”);rx_packet.pr();test_stats.rx_good_packet(rx_packet);

end

else begin

$display (“ERROR: Incorrect packet Rcvd”);

rx_packet.pr();

exp_packet.pr();

test_stats.rx_err_packet(rx_packet,err_cause);

end

endtask

task Hostchk::rcv_packet (Packet rcv_p) ;

rx_packet=rcv_p;

exp_pkt_cnt=expmbx.try_get(exp_packet);

if (exp_pkt_cnt == 0)

$display (“ERROR:Unexpcted packet Rcvd”);

else

check_packet ();

endtask

Xcto

r

pkt

ExpQ

pkt

==

Page 27: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 153

Coverage tracking• Need to grade the effectiveness of the test

– Did the desired events happen– What is the quality of the stimulus

• Create a statistics class– Used to track stimulus and response statistics

• For example: Total packets generated and total packets received

– Can also be used to track events of interest• For example: Total packets dropped, Queue

occupancy

Page 28: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 154

Example of coverage classclass Counter ;

int count;

int limit;

extern task new (int lim=1000);

extern task inc ();

extern task dec ();

endclass

class Stats;

Counter counter [string];

Counter event_counter [string];

task new ();

counter[”GenPkts”] = new;

counter [”RxPkts”] = new;

counter [”UcPkts”] = new;

counter [”McPkts”] = new;

event_counter [”DropPkts”] = new;

endtask

extern task inc_stats (string PktType);

extern task inc_events (string EventType);

extern task pr ();

endclass

Track statistics to grade test effectiveness

Assoc array of counters

Indexed by counter name

Page 29: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 155

Style Guidelines• One class hierarchy per file• File name same as base class name• Class name capitalized

– Hostxactor• Define methods external to class• Constraints should be defined external to

class• Use interfaces for BFM, drivers or

transactors

Page 30: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 156

Summary• Use classes where possible

– Layered classes make it easier to build sophisticated structures

• Use interfaces to abstract out physical ports– More concise code

• Keep to higher levels of abstraction • New SystemVerilog features let you add

automation to your testbench• Let’s you focus on corner cases

Page 31: Ethernet Testbench SV

DAC2003 Accellera SystemVerilog Workshop 157

Agenda

Session 2:SystemVerilog for Verification

Language TutorialTom Fitzpatrick, Synopsys

User ExperienceFaisal Haque, Verification Central

Session 3: SystemVerilog AssertionsLanguage Tutorial

Bassam Tabbara, Novas SoftwareTecnhology and User Experience

Alon Flaisher, IntelSession 1:SystemVerilog for Design

Language TutorialJohny Srouji, Intel

User ExperienceMatt Maidment, Intel

Introduction:SystemVerilog Motivation

Vassilios Gerousis, Infineon TechnologiesAccellera Technical Committee Chair

Using SystemVerilog Assertionsand Testbench Together

Jon Michelson, Verification Central

Session 4: SystemVerilog APIsDoug Warmke, Model Technology

Session 5: SystemVerilog MomentumVerilog2001 to SystemVerilog

Stuart Sutherland, Sutherland HDL

SystemVerilog Industry SupportVassilios Gerousis, Infineon

Lunch: 12:15 – 1:00pm End: 5:00pm