Professional Documents
Culture Documents
Objectives
After completing this module, you will be able to:
Introduction to Testbenches - 6 - 3
Outline
Introduction to Testbenches - 6 - 4
Testbench Concept
An upper-level hierarchical VHDL structure that applies input stimulus to a Unit Under Test (UUT) and monitors the output to verify functionality
CNTR32_TB
entity
CNTR32
entity
Q_OUT
TC
Introduction to Testbenches - 6 - 5
Application of a Testbench
Fewer details, verify design concept
Behavioral
RTL
AND_OR2 DFF
Logic
Technologyspecific details, slower design entry and simulation
Introduction to Testbenches - 6 - 6
Layout
2007 Xilinx, Inc. All Rights Reserved
CLB_ R5C5
CLB_ R5C6
VHDL provides considerable flexibility for declaring and accessing files, along with various formats of data inputs and outputs
Introduction to Testbenches - 6 - 8
Maintaining Consistency
1. Behavioral/RTL simulation: Execute RTL source code 2. Post-synthesis VHDL simulation: Execute structural VHD file 3. VHDL timing simulation: Execute post-layout structural VHD and SDF file
VITAL
Synthesis
Introduction to Testbenches - 6 - 9
Outline
Introduction to Testbenches - 6 - 10
Behavioral Coding
A testbench (behavioral) description has advantages not available in RTL-level code or actual hardware
No need to consider propagation delay Model timing as necessary Arbitrary sequencing of events
Z <= A and B after 2 ns ; RST <= 1 after 25 ns, 0 after 50 ns ;
Introduction to Testbenches - 6 - 11
A VHDL design is typically built from the bottom up; a unique testbench should be used to verify the logic at each hierarchical stage
Introduction to Testbenches - 6 - 12
Outline
Introduction to Testbenches - 6 - 13
Assertion statements can be used to test conditions during simulation without creating additional logic
TEST_FULL_ADD : process begin for i in DATA_FRAMErange loop SUM_EXPECTED <= DATA_FRAME.EXP; SUM_OUT <= ALU_OUT ; ... wait for 100 ns; assert SUM_EXPECTED = SUM_OUT report "ERROR: output SUM is incorrect" severity warning ; end loop; wait; end process ; end architecture TEST ;
Introduction to Testbenches - 6 - 14
Assertion Syntax
VHDL sequential statement Suitable for behavioral/RTL code User-defined Boolean expression If true, nothing happens
Optional User-defined text string, including concatenations Should be concise and informative
assert
SUM_EXPECTED = SUM_OUT
report
severity
Can also use predefined text (for example, constants of type string)
Communicate to simulator
User sets threshold to halt simulation Note that semicolon appears here
Introduction to Testbenches - 6 - 15
Outline
Introduction to Testbenches - 6 - 16
Components of a Testbench
Internal signals, which will drive the stimuli into the UUT and monitor the response from the UUT
Write statements to create stimulus Process Self-testing statements that will report values, error, and warnings Text I/O routines in VHDL
2007 Xilinx, Inc. All Rights Reserved
Introduction to Testbenches - 6 - 17
Label (Optional)
STIM1: process begin CLK <= not CLK ; wait for PERIOD / 2 ;
Wait Condition
Sequential Statements;
Indefinite Suspension
STIM2: process begin wait for 500 ns; LOAD <= 1 ; wait for PERIOD ; LOAD <= 0 ; wait ; end process STIM2 ;
2007 Xilinx, Inc. All Rights Reserved
Sequential Statements;
Introduction to Testbenches - 6 - 18
entity MUX21 is port ( A, B, SEL: in std_logic ; OUT1 : out std_logic ); end entity MUX21 ; architecture RTL of MUX21 is begin
MUX2: process ( A, B, SEL ) begin case SEL is when 0 => OUT1 <= A ; when 1 => OUT1 <= B ; when others => OUT1 <= X ; end case ; end process MUX2 ;
end architecture RTL ;
Sequential Statements;
Introduction to Testbenches - 6 - 19
CNTR32 Testbench
LOAD component CNTR32 port ( D_IN : in std_logic_vector (31 downto 0 ); CLK, RST, LOAD : in std_logic ; Q_OUT : out std_logic_vector (31 downto 0 ) ; end component ; signal D_BUS, Q_BUS : std_logic_vector (31 downto 0 ); signal CLOCK, RESET, LOAD : std_logic ; begin UUT : CNTR32 port map ( D_BUS, CLOCK, RESET, LOAD, Q_BUS ); ( continued )
CLOCK
RESET
Lab
Marker
Introduction to Testbenches - 6 - 20
Stimulus
The most important component of the testbench is the process that actually provides the stimulus
(continued)
STIMULUS : process
begin RESET <= 1; wait for 100 ns; RESET <= 0; D_BUS <= XFFFF0000 ; CLOCK <= 1;
wait for 25 ns; D_BUS <= X00000001 ; CLOCK <= 0; LOAD <= 1 : wait for 25 ns; CLOCK <= 1; wait ; end process STIMULUS ; end architecture TEST ;
In simulation, default initialization for type std_logic is U and 0 for type bit
Lab
Marker
Introduction to Testbenches - 6 - 21
2. Create a concurrent assignment that inverts the clock signal at the appropriate interval for the intended frequency
Introduction to Testbenches - 6 - 22
The example on the left shows a non-50/50 duty-cycle clock; the example on the right includes the clock signal initialization
architecture TEST of CNTR32 is signal CLK_SIG : std_logic ; constant PERIOD : time := 10 ns ; begin architecture TEST of CNTR32 is signal CLK_SIG : std_logic ; constant PERIOD : time := 10 ns ; begin
CLK_STIM: process begin CLK_SIG <= 1 ; wait for PERIOD * 0.4 ; CLK_SIG <= 0 ; wait for PERIOD * 0.6 ; end process CLK_STIM ;
CLK_STIM2: process begin if CLK_SIG = 'U' then CLK_SIG <= '1' ; wait for PERIOD /2 ; end if; CLK_SIG <= not CLK_SIG ; wait for PERIOD /2 ; end process CLK_STIM2 ;
2007 Xilinx, Inc. All Rights Reserved
Introduction to Testbenches - 6 - 23
Initializing Signals
In both cases, the signal RST_sig is initialized to 1 at time zero, then 0 at time 50 ns; 75 ns later, it is deasserted for the duration of the simulation
Outline
Introduction to Testbenches - 6 - 25
Knowledge Check
Which of the following declarations would not be part of a testbench? [ ] Signal(s) [ ] Component(s) [ ] Port(s) [ ] Architecture
How can a stimulus process be made to repeat throughout simulation?
Introduction to Testbenches - 6 - 27
Answers
Top-level entity, UUT, signals for inputs and outputs, and input stimulus Yes
Which of the following declarations would not be part of a testbench? [ ] Signal(s) [ ] Component(s) [X ] Port(s) [ ] Architecture How can a stimulus process be made to repeat throughout simulation?
By not using the unconditional wait command within the process block
Introduction to Testbenches - 6 - 28
Summary
A VHDL testbench is used to verify functionality Testbenches cannot be synthesized Testbenches utilize the full range of the VHDL language VHDL models hardware by using concurrent operations The same testbench can be applied at each stage of verification
Introduction to Testbenches - 6 - 29