Download as pdf or txt
Download as pdf or txt
You are on page 1of 55

NATIONAL UNIVERSITY OF HO CHI MINH CITY

UNIVERSITY OF INFORMATION TECHNOLOGY


FACULTY OF COMPUTER ENGINEERING

CHAPTER 9: TESTBENCH & VERIFICATION

Agenda

Chapter 1:
Chapter 2:
Chapter 3:
Chapter 4:
Chapter 5:
Chapter 6:
Chapter 7:
Chapter 8:
Chapter 9:
Chapter 10:

UIT

Introduction
Modules and hierarchical structure
Fundamental concepts
Structural modeling (Gate- and switch-level modeling)
Dataflow modeling (Expression)
Behavioral modeling
Tasks and Functions
Finite state machines
Testbench and verification
VHDL introduction

Circuit Design with HDL - Chapter 9

Digital design flow (ASIC design flow)


Simulation & Function Verification
+ Design is simulated and tested for
functionality before turning into hardware
+ Do not consider gate, propagation delay,
hazards, glitches, race conditions, setup
and hold violations, and other related
timing issues.
+ Test data are generated by testbench or
waveform editor

Design Specification
Behavior Description
Pre-synthesis verification
Synthesis
Routing and Placement
Timing analyis

Post-synthesis verification
Physical layout
Chip
Ref. Verilog Digital System Design, Zainalabedin Navabi

UIT

Circuit Design with HDL - Chapter 9

Circuit Design with HDL - Chapter 9

Digital design flow (ASIC design flow)


Simulation by input waveform

Simulation by testbench

Circuit Design with HDL - Chapter 9

EDA (Electronic Design Automation) flow

Qsim in Quartus II

Usually good for small design


UIT

Circuit Design with HDL - Chapter 9

EDA (Electronic Design Automation) flow

(ModelSim,VCS)

Using Verilog language for testing design module -> Testbench


Testbench is a code for test, not a part of final design.
Timing & display procedures: important in designing testbench
UIT

Circuit Design with HDL - Chapter 9

Procedure to verify an IP core/Chip

UIT

Circuit Design with HDL - Chapter 9

Test plan
Test plan is a documment that may include:
-

A test environment

A test strategy (check list)

A list of testcases (detail for check list)

A method for generating testcases (random or a vast


amount of testcases)

UIT

A bugs list

Circuit Design with HDL - Chapter 9

Test plan evaluating result method

Observe result model

Self-checking model

UIT

Circuit Design with HDL - Chapter 9

10

Test plan
basic components in a testbench
Initialization

Clock generation

Input stimuli

DUT
(Design Under
Test)

Monitor output

UIT

Circuit Design with HDL - Chapter 9

11

Test plan example of a test environment


Control LCD
COMPARE
Master (LCD_ctrl)

Slave (LCD_ctrl)

ahb_monitor
2

0000-1000

1000-2000

APB
Slave
(VIP)

0000-2000

S
APB Bus

Mem
Controller
(DW)
1

AHB Bus
Clk & reset_n
gen

Sdram
smart
model

20000000-40000000

AHB
Slave
(VIP)

40001000-40002000

ahb_monitor

50000000-60000000

AHB
Master1
(VIP)

AHB/APB
Bridge

framework_top.v

tb_LCD_ctrl.v

Self-checking result with a


test pass

A test enviroment of the self-checking model


UIT

Circuit Design with HDL - Chapter 9

12

Test plan Example of a test strategy

UIT

Circuit Design with HDL - Chapter 9

13

Test plan Example of a list of testcases

UIT

Circuit Design with HDL - Chapter 9

14

Testbench - Introduction
Writing a testbench is as complex as writing the RTL code itself.
These days ASICs are getting more and more complex and thus verifying
these complex ASIC has become a challenge.
Typically 60-70% of time needed for any ASIC is spent on
verification/validation/testing.
Even though the above facts are well known to most ASIC engineers, still
engineers think that there is no glory in verification.
Source: http://www.asic-world.com/verilog/task_func1.html#Task

UIT

Circuit Design with HDL - Chapter 9

15

Testbench - Introduction
For writing testbenches it is important to have the design specification of

the Design Under Test (DUT) .


Specs (DUT) need to be understood clearly

A test plan, which basically documents the test bench architecture


The test scenarios (test cases) in detail, needs to be made.

In testbench, a dummy template which basically declares inputs/inouts to


DUT as reg and outputs from DUT as wire

Note: there is no port list for the test bench.


Source: http://www.asic-world.com/verilog/task_func1.html#Task

UIT

Circuit Design with HDL - Chapter 9

16

Testbench - Example

Circuit Design with HDL - Chapter 9

17

Structure of a testbench
A test bench is a program which
can give arbitrary inputs to Design
Under Test (DUT) and observe
their outputs.

Provide
inputs

DUT

Observer
Outputs

module testbench;
reg [7:0] dat, declaration of signals
Connection of DUT
The description of the clock
initial begin
.
end
Test case;
endmodule

A description of testbench in Verilog-HDL


18
Circuit
Design with HDL - Chapter 9

Structure of testbench (cont.)


2 styles
Stimulus and Design block instantiated
in a Dummy top-level module

Stimulus block instantiates Design block

Style 1
UIT

Style 2 (usually used)


Circuit Design with HDL - Chapter 9

19

Structure of testbench (cont.)


Style 1
Stimulus and Design block instantiated in a Dummy top-level
module

UIT

Circuit Design with HDL - Chapter 9

20

Structure of testbench (cont.)


Style 1 (cont.)

UIT

Circuit Design with HDL - Chapter 9

21

Structure of testbench (cont.)


Style 1 (cont.)
Another view of this: 3 chunks of Verilog, one for each of:

UIT

Circuit Design with HDL - Chapter 9

22

Structure of testbench (cont.)


Style 1 (cont.)

Module testAdd (testbench) generated inputs for module halfAdd (DUT) and
display changes. Module tBench is top level
UIT

Circuit Design with HDL - Chapter 9

23

Structure of testbench (cont.)


Style 1 (cont.)

UIT

Circuit Design with HDL - Chapter 9

24

Structure of testbench (cont.)


Style 2
Stimulus block instantiates Design block

UIT

Circuit Design with HDL - Chapter 9

25

Structure of testbench (cont.)


Style 2 (cont.)

UIT

Circuit Design with HDL - Chapter 9

26

Structure of testbench (cont.)


Style 2 (cont.)

// DUT

UIT

Circuit Design with HDL - Chapter 9

27

Structure of testbench (cont.)


Style 2 (cont.)

UIT

Circuit Design with HDL - Chapter 9

28

Structure of testbench (cont.)


Style 2 (cont.)

UIT

Circuit Design with HDL - Chapter 9

29

Testbench techniques
Simulation control
$stop, $finish: stop and finish a simulation.

A stop simulation can be resumed, finish one can not.

UIT

Circuit Design with HDL - Chapter 9

30

Testbench techniques
Limiting data set
Instead of setting simulation time limit, a testbench can put a

limit on the number of data put on inputs of a DUT

$random: generate random data


UIT

Circuit Design with HDL - Chapter 9

31

Testbench techniques
Applying synchronized data
Synchronize data with clock

UIT

Circuit Design with HDL - Chapter 9

32

Testbench techniques
Synchronized display of result

UIT

Circuit Design with HDL - Chapter 9

33

Testcases
Test vector definition

UIT

Circuit Design with HDL - Chapter 9

34

Test vector definition State change

UIT

Circuit Design with HDL - Chapter 9

35

Test vector definition (cont.)

UIT

Circuit Design with HDL - Chapter 9

36

Test vector definition (cont.)

UIT

Circuit Design with HDL - Chapter 9

37

Test vector definition (cont.)

UIT

Circuit Design with HDL - Chapter 9

38

Test vector definition (cont.)


Question:
For the logic below, we got output average 3,
with the input a1=4, a2=2, a3=3, and a4=3.
The result is looks OK. However what kind of bugs may exist in
the logic?

UIT

Circuit Design with HDL - Chapter 9

39

Test vector definition (cont.)


A sample answer

UIT

Circuit Design with HDL - Chapter 9

40

Test vector definition (cont.)

UIT

Circuit Design with HDL - Chapter 9

41

Test vector definition (cont.)


Many kind of bugs escape through RTL simulation test. This means that

we can not be sage from bugs even if simulation test looks OK.
Therefore the following method is the most terrible way to fix bugs.
Never do this way.

UIT

Circuit Design with HDL - Chapter 9

42

Test vector definition (cont.)

UIT

Circuit Design with HDL - Chapter 9

43

Example
Example 1

UIT

Circuit Design with HDL - Chapter 9

44

Example 1 (cont.)

UIT

Circuit Design with HDL - Chapter 9

45

Example 2
Encoder 8-to-3

UIT

Circuit Design with HDL - Chapter 9

46

Example 2 (cont.)
module encoder8_3( output reg [2:0] encoder_out, input enable, input [7:0] encoder_in );
always @ (enable or encoder_in)
begin
if (enable)
case ( encoder_in )
8'b00000001 : encoder_out = 3'b000;
8'b00000010 : encoder_out = 3'b001;
8'b00000100 : encoder_out = 3'b010;
8'b00001000 : encoder_out = 3'b011;
8'b00010000 : encoder_out = 3'b100;
8'b00100000 : encoder_out = 3'b101;
8'b01000000 : encoder_out = 3'b110;
8'b10000000 : encoder_out = 3'b111;
default : $display("Check input bits.");
endcase
end
endmodule
UIT

Circuit Design with HDL - Chapter 9

47

Example 2 (cont.)
module stimulus;
wire[2:0] encoder_out;
reg enable;
reg[7:0] encoder_in;
reg [2:0] expected;
encoder8_3 enc( encoder_out, enable, encoder_in );
initial begin
enable = 1; encoder_in = 8'b00000010, expected = 3b001;
#1 $display("enable = %b, encoder_in = %b, encoder_out = %b, expected_out =
%b", enable, encoder_in, encoder_out, expected);
#1 enable = 0; encoder_in = 8'b00000001; expected = 3b001;
#1 $display("enable = %b, encoder_in = %b, encoder_out = %b, expected_out = %b
", enable, encoder_in, encoder_out, expected);
#1 enable = 1; encoder_in = 8'b00000001; expected = 3b000;
#1 $display("enable = %b, encoder_in = %b, encoder_out = %b, expected_out = %b
", enable, encoder_in, encoder_out, expected);
#1 $finish;
end
endmodule
UIT

Circuit Design with HDL - Chapter 9

48

Self-checking simulation

##############################
Applying reset
Came out of Reset
Terminating simulation
Simulation Result : PASSED
##############################

UIT

##############################
Applying reset
Came out of Reset
Terminating simulation
Simulation Result : FAILED
---- time=???, signal_value==???,
expect_value=???-------##############################

Circuit Design with HDL - Chapter 9

49

Debuging

Debug by Synopsyss DVE tool

Source: http://www.synopsys.com/Tools/Verification/FunctionalVerification/Pages/VCS.aspx

UIT

Circuit Design with HDL - Chapter 9

50

Debuging (cont.)

Debug by Synopsyss DVE tool


UIT

Circuit Design with HDL - Chapter 9

51

Coverage report

Source: http://www.synopsys.com/Tools/Verification/FunctionalVerification/Pages/VCS.aspx

UIT

Circuit Design with HDL - Chapter 9

52

Coverage report (cont.)

Example of a code coverage report


UIT

Circuit Design with HDL - Chapter 9

53

Testbench State of the art


System Verilog has OPPs support to enhance the reusability,
special construct for randomization and coverage.
There are multiple such industry level standard verification
methodologies such as VMM, OVM and UVM.
These methodologies also provide set of base class libraries
and utilities that are very useful across the entire spectrum of

verification activities

UIT

Circuit Design with HDL - Chapter 9

54

More reference
http://www.asic-world.com/verilog/art_testbench_writing.html

http://testbench.in/

UIT

Circuit Design with HDL - Chapter 9

55

You might also like