SlideShare a Scribd company logo
2
Most read
8
Most read
9
Most read
VERILOG TESTBENCH
• Once the design of a chip is completed its
correctness must be verified or checked.
• It means the designer must convince himself that
the chip designed by him/her is functioning
according to the specs.
• So, to verify or check the correctness of a chip, a
code using any HDL is developed, called the “Test
Bench”
• A test bench is defined as a HDL code to check
the correctness of a chip, that provides the stimulus
(input vectors) to the design.
INTRODUCTION
• Define inputs to the MUT or DUT as reg and
output as wire.(MUT: Module Under Test).
• As we have to initialize the DUT inputs inside the
procedural block(s),typically ‘initial’ where only
‘reg’ type variables can be assigned.
• This initial procedural block executes only once.
• But always block can also be used to generate
some test inputs ,like a clock signal.
• Now, some test vectors are generated by the test
bench which acts as stimulus and applied to the
DUT.
How to write a Testbench
contd
• The test bench also captures the behaviour of the
device under test (DUT) by applying the set of
input vectors generated and compare this result with
predefined expected output.
• In the process of verification, the simulator
directives like $display , $monitor , $finish , $stop,
$dumpfile, $dumpvars etc. are used.
• The general architecture of a test bench is shown in
the next slide.
23 June 2020 yayavaram@yahoo.com 4
TEST BENCH STRUCTURE
• The simple structure of a Verilog test bench is
shown below.
• Here the input vectors which are (stimulus) to the
DUT are applied and the output is captured by the
monitor as shown below.
23 June 2020 yayavaram@yahoo.com 5
Procedure
• First develop the design using the HDL Verilog.
• Develop the Testbench code using the same HDL
Verilog code.
• Instantiate a copy of the Design into TB.
• Apply (connect) different input vectors (Stimulus) to
the Design Under Test (DUT).
• Capture the output of the DUT to the monitor and
compare the output with the predefined expected
results.
23 June 2020 yayavaram@yahoo.com 6
contd
• If the captured output result is matched with the
predefined ,expected results ,then the design is bug
free.
• Else the designer is asked to redesign according to
the specs.
23 June 2020 yayavaram@yahoo.com 7
Test Bench Ex: NAND
• Let us consider a simple example of nand gate
design and its test bench verification.
Design code
• module mynand(Y,A,B);
input A,B;
output Y;
assign Y =~(A&B);
endmodule
23 June 2020 yayavaram@yahoo.com 8
Test Bench Code
• module tb_nand_gate;
wire Y;
reg A,B;
nand-gate uut(Y,A,B);// Instantiate nand gate
initial begin
A = 0; B = 0; // at time 0 units
#10 A = 0 ;B = 1;
#10 A = 1 ;B = 0;
#10 A = 1 ;B = 1;
end
endmodule23 June 2020 yayavaram@yahoo.com 9
Test Bench Ex-Half adder
First let us write the design code using Verilog.
• module half-adder(S,C,A,B);
input A,B;
output S,C;
assign S= A^ B; // data flow model
assign C= A&B;
Endmodule
Let us now writ the testbench
module tb_ half-adder;
reg A,B;
23 June 2020 yayavaram@yahoo.com 10
wire S,C;
half-adder(S,C,A,B);//Instantiate the design
Initial
begin
#5 A = 0 ; B= 0;
#5 A = 0 ; B= 1;
#5 A = 1 ; B= 0;
#5 A = 1 ; B= 1;
end
endmodule
contd
Ex: Full adder
First let us write the design code using Verilog.
• module full-adder(S,C0,A,B,C);
input A,B,C;
output S,C0;
assign S= A^ B^C; // data flow model
assign C0= (A&B)| (B&C)|(C&A);
endmodule
Let us now write the test bench
module tb_ full-adder;
reg A,B,C;
23 June 2020 yayavaram@yahoo.com 12
contd
wire S, C0 ;
full_adder(S,C0,A,B,C); //Instantiation of the design
initial
begin
# 5 A =0;B=0;C=O;
# 5 A =1;B=0;C=O;
# 5 A =1;B=1;C=1;
# 5 A =0;B=1;C=1;
# 5 A =1;B=0;C=1;
# 5 A =0;B=0;C=1;
end
endmodule
23 June 2020 yayavaram@yahoo.com 13
Ex:Up Counter
module up_count (output reg[7:0] out,
input wire enable , input wire clk , input wire rst);
always @(posedge clk) //behavioural model
if (rst)
begin
out <= 8'b0;
end
else if (enable)
begin
out <= out+1;
end
endmodule
Up-Counter-TB
• module test_upcount;
wire [7:0]out;
reg enable, clk, rst;
upcount uut(out,enable,clk,rst); // Module Instantiation
initial begin
clk = 0;
rst = 1;
enable = 0; #20;
end
23 June 2020 yayavaram@yahoo.com 15
contd
initial begin
#10 rst = 0 ;
enable = 1;
end
always begin
#100 clk = ~clk;
#100 $stop;
end
endmodule
23 June 2020 yayavaram@yahoo.com 16
Self Checking Test Bench
• module fulladder(a,b,c,s,co);
input a,b,c;
output s,co;
assign s = a^b^c;
assign co = (a&b)|(b&c)|(c&a);
endmodule
Testbench :
module tb_fulladder;
reg a,b,c;
23 June 2020 yayavaram@yahoo.com 17
contd
• wire s,co;
integer success;
fulladder(a,b,c,s,co);//Instantiation
initial
begin
success = 1;
#5 a =1 ,b=1,c=0 ; #5 ;
if((s!=0)||(co!=1))
23 June 2020 yayavaram@yahoo.com 18
contd
success = 0;
#5 a =1 ,b=1,c=1 ; #5 ;
if((s!=1)||(co!=1))
success = 0;
# 5 $display(“%d”, success);
end
endmodule
23 June 2020 yayavaram@yahoo.com 19
23 June 2020 20yayavaram@yahoo.com
THANQ FOR WATCHINIG
GOOD LUCK !!

More Related Content

PPTX
gate level modeling
PDF
Overview of digital design with Verilog HDL
PPTX
Data flow model -Lecture-4
PPTX
Introduction to EDA Tools
PPTX
Verilog
PDF
Verilog lab manual (ECAD and VLSI Lab)
PDF
FPGA DESIGN FLOW.pdf
PPTX
Verilog Tutorial - Verilog HDL Tutorial with Examples
gate level modeling
Overview of digital design with Verilog HDL
Data flow model -Lecture-4
Introduction to EDA Tools
Verilog
Verilog lab manual (ECAD and VLSI Lab)
FPGA DESIGN FLOW.pdf
Verilog Tutorial - Verilog HDL Tutorial with Examples

What's hot (20)

PPT
PDF
BUilt-In-Self-Test for VLSI Design
PPT
Level sensitive scan design(LSSD) and Boundry scan(BS)
PDF
Synchronous and asynchronous clock
PDF
Data types in verilog
PPTX
CPLD (COMPLEX PROGRAMMABLE LOGIC DEVICES)
PPTX
Verilog HDL
PDF
Field Programmable Gate Array: Building Blocks and Interconnections
PPT
PPTX
Vlsi design flow
PPT
SPI Bus Protocol
PPT
PDF
Physical design
PPTX
Clock divider by 3
PDF
Digital VLSI Design : Introduction
PPTX
Divide by N clock
PPTX
Verilog presentation final
PPTX
Floor plan & Power Plan
PDF
2019 2 testing and verification of vlsi design_verification
PDF
Sta by usha_mehta
BUilt-In-Self-Test for VLSI Design
Level sensitive scan design(LSSD) and Boundry scan(BS)
Synchronous and asynchronous clock
Data types in verilog
CPLD (COMPLEX PROGRAMMABLE LOGIC DEVICES)
Verilog HDL
Field Programmable Gate Array: Building Blocks and Interconnections
Vlsi design flow
SPI Bus Protocol
Physical design
Clock divider by 3
Digital VLSI Design : Introduction
Divide by N clock
Verilog presentation final
Floor plan & Power Plan
2019 2 testing and verification of vlsi design_verification
Sta by usha_mehta
Ad

Similar to Verilog Test Bench (20)

PDF
A Verilog HDL Test Bench Primer
PDF
Vlsi lab manual exp:1
PPT
Unit 4 - Features of Verilog HDL (1).ppt
PPT
Verilog Lecture3 hust 2014
PDF
Task i
PPT
Digital Circuit Verification Hardware Descriptive Language Verilog
PPTX
Verilog overview
PPT
Verilog Lecture2 thhts
PPTX
Digital logic circuit
PPTX
Digital signals design Module 2 - HDLs (1).pptx
PDF
0.my book draft chap 1
PDF
Prepare a Verilog HDL code for the following register Positive Edge.pdf
PPTX
vlsi design using verilog presentaion 1
PPT
Unit 3 - Styles of Modeling-1 for resource management techniques
PDF
How to create SystemVerilog verification environment?
PPTX
Model simulation VHDL
PPTX
Model simulation VHDL
PDF
Vlsi lab manual exp:2
PDF
Lab3 testbench tutorial (1)
PDF
Vlsi lab manual_new
A Verilog HDL Test Bench Primer
Vlsi lab manual exp:1
Unit 4 - Features of Verilog HDL (1).ppt
Verilog Lecture3 hust 2014
Task i
Digital Circuit Verification Hardware Descriptive Language Verilog
Verilog overview
Verilog Lecture2 thhts
Digital logic circuit
Digital signals design Module 2 - HDLs (1).pptx
0.my book draft chap 1
Prepare a Verilog HDL code for the following register Positive Edge.pdf
vlsi design using verilog presentaion 1
Unit 3 - Styles of Modeling-1 for resource management techniques
How to create SystemVerilog verification environment?
Model simulation VHDL
Model simulation VHDL
Vlsi lab manual exp:2
Lab3 testbench tutorial (1)
Vlsi lab manual_new
Ad

More from Dr.YNM (20)

PPT
Introduction to DSP.ppt
PPT
Atmel.ppt
PPT
PIC Microcontrollers.ppt
PPT
Crystalstructure-.ppt
PPT
Basics of OS & RTOS.ppt
PPTX
Introducion to MSP430 Microcontroller.pptx
PPT
Microcontroller-8051.ppt
PPTX
Introduction to ASICs.pptx
PPT
VHDL-PRESENTATION.ppt
PPTX
Basics of data communications.pptx
PPTX
CPLD & FPGA Architectures and applictionsplications.pptx
PDF
Transient response of RC , RL circuits with step input
PPSX
CISC & RISC ARCHITECTURES
PPSX
Lect 4 ARM PROCESSOR ARCHITECTURE
PPSX
Lect 3 ARM PROCESSOR ARCHITECTURE
PPSX
Microprocessor Architecture 4
PPSX
Lect 2 ARM processor architecture
PPSX
Microprocessor Architecture-III
PPSX
LECT 1: ARM PROCESSORS
PPSX
Microprocessor architecture II
Introduction to DSP.ppt
Atmel.ppt
PIC Microcontrollers.ppt
Crystalstructure-.ppt
Basics of OS & RTOS.ppt
Introducion to MSP430 Microcontroller.pptx
Microcontroller-8051.ppt
Introduction to ASICs.pptx
VHDL-PRESENTATION.ppt
Basics of data communications.pptx
CPLD & FPGA Architectures and applictionsplications.pptx
Transient response of RC , RL circuits with step input
CISC & RISC ARCHITECTURES
Lect 4 ARM PROCESSOR ARCHITECTURE
Lect 3 ARM PROCESSOR ARCHITECTURE
Microprocessor Architecture 4
Lect 2 ARM processor architecture
Microprocessor Architecture-III
LECT 1: ARM PROCESSORS
Microprocessor architecture II

Recently uploaded (20)

PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Sustainable Sites - Green Building Construction
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
DOCX
573137875-Attendance-Management-System-original
PPT
Project quality management in manufacturing
PPTX
Construction Project Organization Group 2.pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
Safety Seminar civil to be ensured for safe working.
PPT
Mechanical Engineering MATERIALS Selection
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PPTX
Geodesy 1.pptx...............................................
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Foundation to blockchain - A guide to Blockchain Tech
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Sustainable Sites - Green Building Construction
bas. eng. economics group 4 presentation 1.pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
Operating System & Kernel Study Guide-1 - converted.pdf
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
573137875-Attendance-Management-System-original
Project quality management in manufacturing
Construction Project Organization Group 2.pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Embodied AI: Ushering in the Next Era of Intelligent Systems
Safety Seminar civil to be ensured for safe working.
Mechanical Engineering MATERIALS Selection
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
Geodesy 1.pptx...............................................

Verilog Test Bench

  • 2. • Once the design of a chip is completed its correctness must be verified or checked. • It means the designer must convince himself that the chip designed by him/her is functioning according to the specs. • So, to verify or check the correctness of a chip, a code using any HDL is developed, called the “Test Bench” • A test bench is defined as a HDL code to check the correctness of a chip, that provides the stimulus (input vectors) to the design. INTRODUCTION
  • 3. • Define inputs to the MUT or DUT as reg and output as wire.(MUT: Module Under Test). • As we have to initialize the DUT inputs inside the procedural block(s),typically ‘initial’ where only ‘reg’ type variables can be assigned. • This initial procedural block executes only once. • But always block can also be used to generate some test inputs ,like a clock signal. • Now, some test vectors are generated by the test bench which acts as stimulus and applied to the DUT. How to write a Testbench
  • 4. contd • The test bench also captures the behaviour of the device under test (DUT) by applying the set of input vectors generated and compare this result with predefined expected output. • In the process of verification, the simulator directives like $display , $monitor , $finish , $stop, $dumpfile, $dumpvars etc. are used. • The general architecture of a test bench is shown in the next slide. 23 June 2020 [email protected] 4
  • 5. TEST BENCH STRUCTURE • The simple structure of a Verilog test bench is shown below. • Here the input vectors which are (stimulus) to the DUT are applied and the output is captured by the monitor as shown below. 23 June 2020 [email protected] 5
  • 6. Procedure • First develop the design using the HDL Verilog. • Develop the Testbench code using the same HDL Verilog code. • Instantiate a copy of the Design into TB. • Apply (connect) different input vectors (Stimulus) to the Design Under Test (DUT). • Capture the output of the DUT to the monitor and compare the output with the predefined expected results. 23 June 2020 [email protected] 6
  • 7. contd • If the captured output result is matched with the predefined ,expected results ,then the design is bug free. • Else the designer is asked to redesign according to the specs. 23 June 2020 [email protected] 7
  • 8. Test Bench Ex: NAND • Let us consider a simple example of nand gate design and its test bench verification. Design code • module mynand(Y,A,B); input A,B; output Y; assign Y =~(A&B); endmodule 23 June 2020 [email protected] 8
  • 9. Test Bench Code • module tb_nand_gate; wire Y; reg A,B; nand-gate uut(Y,A,B);// Instantiate nand gate initial begin A = 0; B = 0; // at time 0 units #10 A = 0 ;B = 1; #10 A = 1 ;B = 0; #10 A = 1 ;B = 1; end endmodule23 June 2020 [email protected] 9
  • 10. Test Bench Ex-Half adder First let us write the design code using Verilog. • module half-adder(S,C,A,B); input A,B; output S,C; assign S= A^ B; // data flow model assign C= A&B; Endmodule Let us now writ the testbench module tb_ half-adder; reg A,B; 23 June 2020 [email protected] 10
  • 11. wire S,C; half-adder(S,C,A,B);//Instantiate the design Initial begin #5 A = 0 ; B= 0; #5 A = 0 ; B= 1; #5 A = 1 ; B= 0; #5 A = 1 ; B= 1; end endmodule contd
  • 12. Ex: Full adder First let us write the design code using Verilog. • module full-adder(S,C0,A,B,C); input A,B,C; output S,C0; assign S= A^ B^C; // data flow model assign C0= (A&B)| (B&C)|(C&A); endmodule Let us now write the test bench module tb_ full-adder; reg A,B,C; 23 June 2020 [email protected] 12
  • 13. contd wire S, C0 ; full_adder(S,C0,A,B,C); //Instantiation of the design initial begin # 5 A =0;B=0;C=O; # 5 A =1;B=0;C=O; # 5 A =1;B=1;C=1; # 5 A =0;B=1;C=1; # 5 A =1;B=0;C=1; # 5 A =0;B=0;C=1; end endmodule 23 June 2020 [email protected] 13
  • 14. Ex:Up Counter module up_count (output reg[7:0] out, input wire enable , input wire clk , input wire rst); always @(posedge clk) //behavioural model if (rst) begin out <= 8'b0; end else if (enable) begin out <= out+1; end endmodule
  • 15. Up-Counter-TB • module test_upcount; wire [7:0]out; reg enable, clk, rst; upcount uut(out,enable,clk,rst); // Module Instantiation initial begin clk = 0; rst = 1; enable = 0; #20; end 23 June 2020 [email protected] 15
  • 16. contd initial begin #10 rst = 0 ; enable = 1; end always begin #100 clk = ~clk; #100 $stop; end endmodule 23 June 2020 [email protected] 16
  • 17. Self Checking Test Bench • module fulladder(a,b,c,s,co); input a,b,c; output s,co; assign s = a^b^c; assign co = (a&b)|(b&c)|(c&a); endmodule Testbench : module tb_fulladder; reg a,b,c; 23 June 2020 [email protected] 17
  • 18. contd • wire s,co; integer success; fulladder(a,b,c,s,co);//Instantiation initial begin success = 1; #5 a =1 ,b=1,c=0 ; #5 ; if((s!=0)||(co!=1)) 23 June 2020 [email protected] 18
  • 19. contd success = 0; #5 a =1 ,b=1,c=1 ; #5 ; if((s!=1)||(co!=1)) success = 0; # 5 $display(“%d”, success); end endmodule 23 June 2020 [email protected] 19
  • 20. 23 June 2020 [email protected] THANQ FOR WATCHINIG GOOD LUCK !!

Editor's Notes

  • #21: If the value of S is 1 ,then Y= B other wise Y= A