Professional Documents
Culture Documents
Chapter 9 - Testbench Verification
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
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
Simulation by testbench
Qsim in Quartus II
(ModelSim,VCS)
UIT
Test plan
Test plan is a documment that may include:
-
A test environment
UIT
A bugs list
Self-checking model
UIT
10
Test plan
basic components in a testbench
Initialization
Clock generation
Input stimuli
DUT
(Design Under
Test)
Monitor output
UIT
11
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
12
UIT
13
UIT
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
15
Testbench - Introduction
For writing testbenches it is important to have the design specification of
UIT
16
Testbench - Example
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
Style 1
UIT
19
UIT
20
UIT
21
UIT
22
Module testAdd (testbench) generated inputs for module halfAdd (DUT) and
display changes. Module tBench is top level
UIT
23
UIT
24
UIT
25
UIT
26
// DUT
UIT
27
UIT
28
UIT
29
Testbench techniques
Simulation control
$stop, $finish: stop and finish a simulation.
UIT
30
Testbench techniques
Limiting data set
Instead of setting simulation time limit, a testbench can put a
31
Testbench techniques
Applying synchronized data
Synchronize data with clock
UIT
32
Testbench techniques
Synchronized display of result
UIT
33
Testcases
Test vector definition
UIT
34
UIT
35
UIT
36
UIT
37
UIT
38
UIT
39
UIT
40
UIT
41
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
42
UIT
43
Example
Example 1
UIT
44
Example 1 (cont.)
UIT
45
Example 2
Encoder 8-to-3
UIT
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
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
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=???-------##############################
49
Debuging
Source: http://www.synopsys.com/Tools/Verification/FunctionalVerification/Pages/VCS.aspx
UIT
50
Debuging (cont.)
51
Coverage report
Source: http://www.synopsys.com/Tools/Verification/FunctionalVerification/Pages/VCS.aspx
UIT
52
53
verification activities
UIT
54
More reference
http://www.asic-world.com/verilog/art_testbench_writing.html
http://testbench.in/
UIT
55