Lab2 Layered Verficiation
Lab2 Layered Verficiation
Objectives:
The overcome the limitations of flat testbench, a key concept that was developed is the layered
testbench. Initially it would seem, to make the testbench more complex, but actually it makes the
task easier by dividing the code into smaller pieces that can be developed separately. If we write a
single routine that can randomly generate all types of stimuli, both legal and illegal, plus inject
errors with a multi-layer protocol, the routine will quickly become complex and unmaintainable. In
addition, a layered approach allows reuse and encapsulation of Verification IP (VIP) which are
Object Oriented Programming (OOP) concepts. These requirements can not be fulfilled by a
hardware description language such as Verilog. This limitations leads to the development of the
hardware verification language SystemVerilog which is an OOP language.
A digital hardware design language such as Verilog has to represent digital hardware at the
following levels:
1. Netlist: A netlist describes logic gates and switches (pass transistors) connected by wires,
organized into a hierarchical structure of modules, with a naming system. The leaf modules are
cells (in ASIC designs).
2. Register transfer: At register transfer level, a logic design consists of Boolean and integer
arithmetic expressions and concurrent assignments to clocked registers. The expressions that
represent combinational logic may be evaluated by asynchronous data flow and should not contain
loops (cycles). In the concurrent assignments, all the expressions on the right hand side must be
evaluated before the left hand sides are updated. To describe complex and regular Boolean
expressions, it is convenient to be able to use procedural code including user-defined functions, like
in a general-purpose programming language.
However, besides the above 2 levels, a digital hardware verification language such as
SystemVerilog has to represent digital hardware at the following additional levels:
3. General programming: To model the scenarios of the environment for simulation, and to
instrument the code for debugging, it is necessary to have I/O functions like in a general purpose
programming language, as well as concurrent processes with waiting for times or events. It is
useful to be able to link to other code, such as a third party tool.
4. Testbench: A very concise way of generating a variety of test cases is to use constrained
randomized data and sequences. For example a data packet can be constructed with various header
5. Temporal properties: Many of the bugs in hardware design are caused by incorrect sequences
of signals. Specifying and checking a hardware communication protocol requires the expression of
temporal properties. These are most conveniently written like the regular expressions of a finite
state grammar, with sequences of Boolean expressions and timing.
6. Functional coverage: It is important to check that verification has included all control states,
significant data values, and combinations of these. For this purpose it is necessary to specify when
they are sampled and what values or ranges are significant.
The following table shows the basic difference between Verilog and SystemVerilog in terms of
capability of hardware verification.
Object Oriented Programming (OOP) in SystemVerilog is supported through the “Class Data
type”. SystemVerilog OOP comprises of few key concepts, listed below:
Class - a basic building block containing routines and variables. A class encapsulates the data
together with the routines that manipulate it. One of the most important features of classes (and
Object - an instance of a class. An “object” may contain data (data fields - strings, integers, etc.)
and methods (member functions) that operate on the data.
Method - the procedural code that manipulates variables, contained in tasks and functions.
Prototype - the header of a routine that shows the name, type, and argument list. The body of the
routine contains the executable code.
The following shows defining a class named as somecls. It has two data types and a void function
named as print();
class somecls;
//CLass Properties
int some_int;
bit [7:0] some_byte;
//Class Methods
function void print();
$display("*****************************************");
$display(" SumCls Data ");
$display("*****************************************");
$display(" some_int = %0d", some_int );
$display(" some_byte = %b" , some_byte );
$display("*****************************************");
`include "somecls.sv"
module toptb;
somecls somecls0, somecls1, somecls2;
initial begin
somecls0 = new();
somecls0.some_int = 5;
somecls0.some_byte = 8'b10100110;
$display("");
$display("Displaying data for somecls0");
$display("");
somecls0.print();
end
endmodule
The irun utility provides a use-model to run simulations with Incisive Unified Simulator (IUS) in a
simple and consistent manner. The main benefit of irun is that it can simulate the multi-language
design & verification environments in a single step by simply specifying all input source files and
options on a single command line!!
After the run the following Design hierarchy summary will be displayed:
Instances Unique
Modules: 1 1
Registers: 7 9
Initial blocks: 1 1
Compilation units: 1 1
*****************************************
SumCls Data
*****************************************
some_int = 5
some_byte = 10100110
*****************************************
ncsim: *W,RNQUIE: Simulation is complete.
ncsim> exit
Examine the output with the source code and try to understand Class properties.
Next we will observe the copy function of class properties. To do this open the ex2_tb.sv file and
see how somecls1 is defined and copied the properties and data of somecls0.
Now modify the run.sh shell command to run the ex2_tb.sv file and observe the output.
Repeat this for ex3_tb and find some more properties of class.
Both Verilog and OOP have the concept of instantiation, but there are some differences in the
details. SystemVerilog stimulus objects are constantly being created and used to drive the DUT and
check the results. Later, the objects may be freed so their memory can be used by new ones.
In example below ‘sc’ is a handle that points to an object of type simpleclass . For brevity, you can
just say ‘sc’ is a simpleclass handle.
//example of instantiation
initial
begin
simpleclass sc; //declare a handle
sc = new(); //Allocate a simpleclass object.
end
When you declare the handle sc, it is initialized to the special value null. A handle is an indirect
reference to a class object, like a pointer to an address in memory. Unlike pointers in other
languages such as C/C++, you are very limited in what you can do with a handle in SystemVerilog.
It allocates the space to hold handle sc of simpleclass, but not the objects itself.
On the next line, call the new() function to construct the simpleclass object. The new keyword is a
constructor, it creates the object.
The signals of the alu developed in Lab 1 are put to-gather in an interface. The clock can be part of
the interface or a separate port. The interface is defined with a clocking block. Clocking blocks
have been introduced in SystemVerilog to address the problem of specifying the timing and
synchronisation requirements of a design in a testbench. A clocking block is a set of signals
synchronised on a particular clock. It basically separates the time related details from the structural,
functional and procedural elements of a testbench. It helps the designer develop testbenches in
terms of transactions and cycles. Clocking blocks can only be declared inside a module, interface or
program. The following figure shows alu interface and an example code is shown below:
Driver_cb Mon_cb
endinterface
Once you have defined a clocking block, your testbench can wait for the clocking expression with
@alu_if.cb rather than having to spell out the exact clock and edge. Now if you change the clock or
edge in the clocking block, you do not have to change your testbench.
There are two ways to use these modport names in your design. You can specify them in the
modules that connect to the interface signals. The alternative is to specify the modport when you
instantiate the module.
There are Here we will use interface and clocking block to simulate a counter.
Move to Demo_4_CB and execute the irun in the run directory. After the program is executed the
output waveform will be generated.
Cadence simvision EDA tool is used to view waveform generated by digital simulators such as
ncsim. To view the waveforms in simvision
Open Simvision in your RUN directory with the command $simvision &
In simvision
Click File Open Database Display File of Type VCD File.
Select the signals and you will get the waveform as shown below :
A testbench has many threads running in parallel. All of these threads need to synchronize and
exchange data. At the most basic level, one thread waits for another, such as the environment
object waiting for the generator to complete. Multiple threads might try to access a single resource
such as bus in the DUT, so the testbench needs to ensure that one and only one thread is granted
access. At the highest level, threads need to exchange data such as transaction objects that are
passed from the generator to the agent. All of this data exchange and control synchronization is
called interprocess communication (IPC), which is implemented in SystemVerilog with events,
semaphores, and mailboxes. These are described in the remainder of this chapter.
There are generally three parts to IPC: a producer that creates the information, a consumer that
accepts the information, and the channel that carries the information.
Events operations are of two staged processes in which one process will trigger the event, and the
other processes will wait for an event to be triggered.
SystemVerilog events act as handles to synchronization queues. Thus, they can be passed as
arguments to tasks, and they can be assigned to one another or compared.
Event triggering
-> operator : Named events are triggered via the -> operator. Triggering an event unblocks all
processes currently waiting on that event.
->> operator : Non-blocking events are triggered using the ->> operator
@ operator
@(event_name.triggered);
The @ operator blocks the calling process until the given event is triggered.
For a trigger to unblock a process waiting on an event, the waiting process must execute the @
statement before the triggering process executes the trigger operator, ->
4-2 Mailboxes
How can we pass information between two threads? A mailbox is a communication mechanism that
allows messages to be exchanged between processes. The process which wants to talk to another
process posts the message to a mailbox, which stores the messages temporarily in a system defined
memory object, to pass it to the desired process.
Based on the sizes mailboxes are categorized as,
bounded mailbox
unbounded mailbox
A bounded mailbox is with the size defined. Mailbox becomes full on storing a bounded number of
messages. A process that attempts to place a message into a full mailbox shall be suspended until
enough space becomes available in the mailbox queue.
Unbounded mailboxes are with unlimited size.
Mailbox types
There are two types of mailboxes,
Generic Mailbox
Parameterized mailbox
Generic Mailbox (type-less mailbox) :The default mailbox is type-less, that is, a single mailbox
can send and receive data of any type.
mailbox mailbox_name;
Parameterized mailbox (mailbox with particular type) : Parameterized mailbox is used to transfer
a data of particular type.
mailbox #(type) mailbox_name;
Mailbox Methods :SystemVerilog Mailbox is a built-in class that provides the following methods.
These are applicable for both Generic and Parameterized mailboxes
new(); - Create a mailbox
put(); - Place a message in a mailbox
try_put(); - Try to place a message in a mailbox without blocking
get(); or peek(); - Retrieve a message from a mailbox
num(); - Returns the number of messages in the mailbox
try_get(); or try_peek(); - Try to retrieve a message from a mailbox without blocking
Inheritance is an OOP concept that allows one to extend a class to create another class with the
ability to access to all the properties and methods of the original parent class from the handle of a
new class object. This allows us to create modification without touching the base class at all.
SystemVerilog Methods declared with the keyword virtual are referred to as virtual methods.
Virtual Methods
Virtual Functions : A function declared with a virtual keyword before the function
keyword is referred to as virtual Function
Virtual Tasks : Task declared with a virtual keyword before the task keyword is referred
to as virtual task
In a virtual method, if the base_class handle is referring to the extended class, then the extended
class method handle will get assigned to the base class handle.
In the below explanation, extended_class is an extended class of base_class.
base_class pbr;
extended_class epr;
bpr = epr;
On calling bpr.display()
if display() method in base_class is virtual, then extended class display method will get called
if display() method in base_class is non-virtual, then base class display method will get called
Move to ALU_layered and move to the run directory. Study the run shell script and see which one
is the top level testbench. Study all the dependent files and see how layered testing of ALU is
planned and coded.
ncsim> run
------------------Scoreboard Test Starts--------------------
Passed : a= 0 b=128 s=15 Expected out=65535 Resulted out=65535
Passed : a= 8 b=235 s=15 Expected out= 7 Resulted out= 7
Passed : a= 19 b=137 s=15 Expected out= 18 Resulted out= 18
Passed : a= 97 b= 77 s=14 Expected out= 98 Resulted out= 98
Passed : a= 34 b= 91 s=15 Expected out= 33 Resulted out= 33
------------------Scoreboard Test Ends--------------------
Simulation complete via $finish(1) at time 65 NS + 1
../testbench/environment.sv:39 $finish;
Report :
1. Intentionally introduce some bugs in the RTL code of the ALU and use layered testbench to
identify the bugs. Modify your testbench to increase coverage as much as possible and to
identify all the errors.
2. Report the performance of your testbench and suggest testing strategies that can enhance
coverage, reduce verification time and efforts.