Professional Documents
Culture Documents
11 2 PDF
11 2 PDF
Verification Testbench
What to expect?
What is a testbench?
An ALU has
an input clock
A[7:0]
two 8-bit inputs as operands
a 3-bit opcode as an operator
a 16-bit output
OUT [15:0]
B[7:0]
clk
SystemVerilog
SystemVerilog as a hardware verification language provides a rich set of features
Data Types & Aggregate data types
Class, Event, Enum, Cast, Parameterization, Arrays, Associative arrays, Queues and manipulating methods
OOP functionality
Classes, Inheritance, Encapsulation, Polymorphism, memory management
Processes
fork-join control, wait statements
Clocking blocks
Interprocess synchronization & communication
Semaphores, Mailboxes, named events
Assertions
Functional Coverage
Virtual Interfaces
Constraints
Data Types
10
11
enum define enumerated types where variables can take any value from a set of all
possible values
enum { ADD=0, SUB=1, MUL=2, AND=4, OR=5, XOR=6, XNOR=7 } OPTYPE;
struct define structures containing multiple variables of same or different types
they can be packed or unpacked like arrays
struct { bit [9:0] src_addr; bit [1023:0] data; bit [3:0] crc} packet;
union define a variable that can be accessed as many different types (byte, int, etc.)
union {int a; byte b;} var;
string define a string type variable that can hold a sequence of characters
typedef add user defined types from the basic types
12
dynamic arrays the size of the array varies at run time based on need or behaviour.
to allocate storage new and delete methods can be used
dynamic arrays are declared as shown below
int dynamic_array[];
13
associative arrays a set of key:value pairs usually used for sparse data or when the size
of the array is not known
they can be declared as shown below
int associative_array[int];
Methods that can be used on associative arrays are:
first()
last()
next()
prev()
exists()
num()
delete()
14
15
Interfaces
interface dut_in;
logic [31:0] A, B;
logic clk, rst;
endinterface
Interfaces
CLK RST
Master Modport
DAT_O DAT_I
Slave Modport
WE_O WE_I
SEL_O SEL_I
STB_O STB_I
ACK_I ACK_O
CYC_I CYC_O
17
Interfaces
interface WB (input CLK, input RST);
logic [31:0] ADR, RDAT, WDAT;
logic [15:0] SEL;
logic WE, STB, ACK, CYC;
modport Master (output ADR, WDAT, WE, SEL, STB, input RDAT, ACK, CYC);
modport Slave (input ADR, WDAT, WE, SEL, STB, output RDAT, ACK, CYC);
endinterface
18
Virtual Interfaces
Testbench Design
Driver
Virtual IF
IF DUT
19
20
An object may contain data (data fields - strings, integers, etc.) and methods (member
functions) that operate on the data.
Encapsulation - The concept of keeping the data and the methods/functions that work
on that data in one structure. This also allows to keep the data safe, as the only allowed
ways that the data can be modified is usually through the methods in that class.
Objects are created as instances of a class. Class is a user-defined type in OOPS.
One of the most important features of classes (and OOPS in general) is inheritance. It
allows for new classes to be created by inheriting properties from previously defined
classes. The new class is called the derived class while the old class is referred to as
the base class.
21
Class Shape:
Data area(int), perimeter(int), color(string)
Methods getarea(), getperimeter(), getcolor()
22
23
24
25
26
Randomization Constructs
27
Constraints
Constraints are necessary to direct the randomization towards interesting corner cases
Constraint blocks are defined using the keyword constraint
Constraint blocks can be specified using any of the below expressions
set membership
distribution
implication
if else
iterative
variable ordering
28
class packet;
rand bit[9:0] src_addr;
rand bit[1023:0] data;
rand bit[3:0]crc;
constraint src_addr_set_const;
endclass : packet
constraint packet::src_addr_set_const {
src_addr inside {[100:127], [1000:1023]};
}
29
Constraints Distribution
class packet;
rand bit[9:0] src_addr;
rand bit[1023:0] data;
rand bit[3:0]crc;
constraint src_addr_dist_const;
endclass : packet
constraint packet::src_addr_dist_const {
src_addr dist {
[100:127] :/ 50
[1000:1023] :/ 50
}
}
30
Constraints Implication
class packet;
rand bit[9:0] src_addr;
rand bit[1023:0] data;
rand bit[3:0]crc;
constraint src_addr_impl_const;
endclass : packet
constraint packet::src_addr_impl_const {
(src_addr == 10d100) (data !inside {0})
}
31
class packet;
rand bit[9:0] src_addr;
rand bit[1023:0] data;
rand bit[3:0]crc;
constraint src_addr_vo_const;
endclass : packet
constraint packet::src_addr_vo_const {
solve src_addr before data;
}
32
Constraints Iterative
class eth_packet;
rand byte data[10];
constraint each_elem;
endclass : eth_packet
constraint eth_packet::each_elem {
foreach(data[i])
data[i] > 32;
}
33
Process Control
34
Process Control
wait and disable constructs can be used to control individual threads of execution
wait is used when the parent process is outside the fork join_any or join_none
case, but the parent wants to wait for the children to finish before continuing execution.
disable is used when the parent process is outside the fork join_any or join_none
case, but the parent wants to kill the children before continuing execution.
35
Components of a testbench
The top testbench now looks different
It creates an interface handle
It instantiates the DUT
36
Testbench TOP
A program block is the main entry point
A bfm object and a scoreboard object are
created
All the components are started
A fork/join process ensures that they all
start in parallel
We exit the fork statement at 0 time
Simulation is stopped when $finish is called
Multiple initial blocks execute in parallel
37
Transaction class
38
BFM/driver
The BFM/driver class:
Has a handle to a virtual interface
Declares a alu_trxn data type
Has a constructor
drive() task:
Does not end
Creates a new transaction
Randomizes the transaction
Passes the handle to drive_trxn() task
drive_trxn () task
consumes time
drives the input signals based on the values in the
trxn class
Uses clocking block and non-blocking assignments
Adheres to pin level timing of signals
39
Scoreboard
The Scoreboard:
Functionality is to continuously check the output
independent of the input stimulus
check() task:
Collects information from the interface and
populates the trxn class
Calls a compute_expected_out function
compute_expected_out() task
Implements the model of the deisign
Takes in the inputs and gets an expected output
Compares the actual output against the expected
output
Issues an error message if the comparison fails
40
clk
A OUT
alu_bfm ALU
ALU
B
alu_sb
41
With a random testbench it is difficult to know what scenarios have been exercised
Two techniques are typically used to get a measure of whats done
Code Coverage
No additional instrumentation is needed
Toggle, Statement, Expression, Branch coverage
Functional Coverage
Requires planning
Requires instrumenting code
SystemVerilog provide constructs to support functional coverage
Provides detailed reports on how frequently coverage was hit with the test sample
Coverage closure is an important aspect of verification quality
42
Coverage Point
43
Coverage Point
44
Covergroup
Keyword bins is used to collect sampled values into various named bins
Simulator keeps a count for each bin
Cross Coverage
Cross Coverage
47
Transition Coverage
48
49
Useful pointers
https://verificationacademy.com/
SV Unit YouTube Video
EDA Playground
http://testbench.in/
Search for SystemVerilog on YouTube
50
51
52
53