Ethernet Testbench SV
Ethernet Testbench SV
Ethernet Testbench SV
User Experience
Matt Maidment, Intel
User Experience
Faisal Haque, Verification Central
Lunch: 12:15 1:00pm
127
128
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
129 DAC2003 Accellera SystemVerilog Workshop
A Typical Testbench
Adapted from The Art of Verification with Vera
Predict Response
transactor
transactor
Generator
packets
0101010
0101010
packets
Coverage Monitor
classes
130
interfaces
DAC2003 Accellera SystemVerilog Workshop
Checker
Director
131
Program Block
Testbench implemented as multiple program blocks
For example: generator, checker in separate program blocks
test_top.v DUT
DUT
interface(s) Transactor(s) Program Gen
interface(s)
Transactors Gen Checker
Program Checker
133
Classes
Provide a mechanism to encapsulate data Recommended for almost all testbench components Layer classes to build powerful structures
Generator MII Event Gen Network Event Gen
134
Use clocking to define synchronization of the DUT ports with the Testbench
135 DAC2003 Accellera SystemVerilog Workshop
136
MAC
Monitor Host xctor MII xctor
Pkt Gen
Event Gen
cpu transactor
cpu monitor
classes Interface-tasks
137 DAC2003 Accellera SystemVerilog Workshop
Ethernet MAC
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; . . . TxData 31-0 TxSOP TxEOP TxEN TxSelect TxReady
TXU
RXU Reg
138
interfaces as Transactors
Interfaces Interfaces
host_tx
mii_tx
MAC
host_rx mii_rx
cpu
139
DUT
clocking mac_host_tx_host @(posedge CLK); input [31:0] txdata; input txselect; input txsop; input txeop; input txen; output txrdy; endclocking
140 DAC2003 Accellera SystemVerilog Workshop
Program Block
program mac_tb (host_tx, host_rx, mii_rx, mii_tx); clocking mac_host_tx_host @(posedge CLK); . . . endclocking Host_gen Host_mon MII_gen Mii_mon host_gen; host_mon; mii_gen; mii_mon;
initial begin host_gen = new (); host_mon = new (); mii_gen = new (); mii_mon = new (); end endprogram
141
Generators
Implemented as classes instantiated inside program block Use random variables and constraints to generate stimulus Three components Random
constraints
Variables
Control Variables
142
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
143 DAC2003 Accellera SystemVerilog Workshop
Random variables Dynamic array Both length and contents will be randomized Control variables Constraints
//control variables int 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
Methods
144
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{1b1}; } 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
145
146
147
Expect Queue
Packets
Host xactr
Transmit Unit
0101010
packets
==
MAC
Monitor
148
149
push
pop
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++; end endtask task Expqueue::pop (Packet p); exp_mbx.get (p); qsize -; endtask
qsize
150
Example Checker
Host Rx Xactor
Packet received class Hostchk ; mailbox#(Packet) exp_mbx; Packet rx_packet; Packet exp_packet; Stats test_stats;
Exp Q
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
Host Checker
check_packet(); Compare packets Update stats Print results
151
Exp Q
pkt
Xctor
pkt
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
==
152
Coverage tracking
Need to grade the effectiveness of the test
Did the desired events happen What is the quality of the stimulus
154
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
155 DAC2003 Accellera SystemVerilog Workshop
Summary
Use classes where possible
Layered classes make it easier to build sophisticated structures
Keep to higher levels of abstraction New SystemVerilog features let you add automation to your testbench Lets you focus on corner cases
156 DAC2003 Accellera SystemVerilog Workshop
Agenda
Introduction: SystemVerilog Motivation
Vassilios Gerousis, Infineon Technologies Accellera Technical Committee Chair
User Experience
Matt Maidment, Intel
User Experience
Faisal Haque, Verification Central
Lunch: 12:15 1:00pm
157