test benches

28
1 Test Benches Instructors: Fu-Chiung Cheng ( 鄭鄭鄭 ) Associate Professor Computer Science & Eng ineering Tatung University

Upload: brede

Post on 15-Mar-2016

69 views

Category:

Documents


1 download

DESCRIPTION

Test Benches. Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University. Test Benches. Most hardware description languages: Circuit description and test waveforms are described in different ways. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Test Benches

1

Test Benches

Instructors: Fu-Chiung Cheng

(鄭福炯 )Associate Professor

Computer Science & EngineeringTatung University

Page 2: Test Benches

2

Test Benches

• Most hardware description languages: Circuit description and test waveforms are described in different ways.• VHDL: the language itself can be used to express the testing waveforms. (called test benches.) • Test benches: a VHDL model that generates waveforms with which to test a circuit (VHDL) model.• Test benches is used only in simulation, not for synthesized.

Page 3: Test Benches

3

Test Benches

• A synthesizable model should be extensively tested in simulation before synthesis to ensure correctness.• WYSISYG: what you simulate is what you get.• Any errors in the design will be faithfully synthesized as errors in the final circuit. (Testing is very important…)• Diagnosing errors in synthesizer-generated netlists is almost impossible.• Because test benches are not synthesized, the full scope of VHDL language is available for writing them.

Page 4: Test Benches

4

Combinational Test Benches

• How to write a test bench for combinational circuits. (use testing a MUX (2x1 multiplexer) as an example). 1. Define an empty entity: 2. Create an architecture with the under-test component instance. 3. Produce test patterns: 4. Write a process to test the circuit by applying the test patterns:

Page 5: Test Benches

5

Combinational Test Benches

1. Define an empty entity: entity mux_test is

end;

muxGeninputs

Page 6: Test Benches

6

Combinational Test Benches

2. Create an architecture with the under-test component instance.

library ieee;use ieee.std_logic_1164.all;architecture test_bench of mux_test is component mux; port (in0,in1,sel:in std_logic; z: out

std_logic; end component; for all: mux use work.mux; signal in0, in1, sel, z:std_logic;begin CUT: mux port map(in0,in1,sel,z);end;

Page 7: Test Benches

7

Combinational Test Benches

3. Produce test patterns:type sample is record in0: std_logic; in1: std_logic; sel: std_logic;end;type sample_array is array (natural range <>)of sample;constant test_data: sample_array :=( (‘0’,’0’,’0’), (‘0’,’0’,’1’), (‘0’,’1’,’0’), (‘0’,’1’,’1’), (‘1’,’0’,’0’), (‘1’,’0’,’1’), (‘1’,’1’,’0’), (‘1’,’1’,’1’));

Page 8: Test Benches

8

Combinational Test Benches 4. Write a process to test the circuit by applying the test patterns:

processbegin for i in test_data’range loop in0 <=test_data(i).in0; in1 <=test_data(i).in1; sel <=test_data(i).sel; wait for 10ns; end loop; wait;end process;

Page 9: Test Benches

9

library ieee;use ieee.std_logic_1164.all; entity mux_test isend;architecture test_bench of mux_test istype sample is record in0: std_logic; in1: std_logic; sel: std_logic;end;type sample_array is array (natural range <>)of sample;constant test_data: sample_array :=( (‘0’,’0’,’0’), (‘0’,’0’,’1’), (‘0’,’1’,’0’), (‘0’,’1’,’1’), (‘1’,’0’,’0’), (‘1’,’0’,’1’), (‘1’,’1’,’0’), (‘1’,’1’,’1’));

Page 10: Test Benches

10

component mux; port (in0,in1,sel:in std_logic; z: out std_logic; end component; for all: mux use work.mux; signal in0, in1, sel, z:std_logic;begin process for i in test_data’range loop in0 <=test_data(i).in0; in1 <=test_data(i).in1; sel <=test_data(i).sel; wait for 10 ns; end loop; wait; end process; CUT: mux port map(in0,in1,sel,z);end;

Page 11: Test Benches

11

Combinational Test Benches: verifying responses

• Check the correctness through outputs • Response data:type sample is record in0: std_logic; in1: std_logic; sel: std_logic; z: std_logic;end;constant test_data: sample_array :=((‘0’,’0’,’0’,’0’),(‘0’,’0’,’1’,’0’),(‘0’,’1’,’0’,’0’), (‘0’,’1’,’1’,’1’), (‘1’,’0’,’0’,’1’),(‘1’,’0’,’1’,’0’),(‘1’,’1’,’0’,’1’), (‘1’,’1’,’1’,’1’));

Page 12: Test Benches

12

Combinational Test Benches: verifying responses

• Check the response process for i in test_data’range

loop in0 <=test_data(i).in0; in1 <=test_data(i).in1; sel <=test_data(i).sel; wait for 10ns; assert z =

test_data(i).z report “output z is

wrong!” severity error;

end loop; wait; end process;

Page 13: Test Benches

13

Test Benches: Clock & Reset

• A simple clocked circuit:

D F/F

in0

ck

zM

UX

sel

in1

Page 14: Test Benches

14

Test Benches: Clock & Reset

• under-test component instance:library ieee;use ieee.std_logic_1164.all;architecture test_bench of Dmux_test is component Dmux; port (in0,in1,sel,ck:in std_logic; z: out std_logic; end component; for all: Dmux use work.Dmux; signal in0, in1, sel, ck, z:std_logic;begin CUT: Dmux port map(in0,in1,sel, ck, z);end;

Page 15: Test Benches

15

Test Benches: Clock & Reset• Check the response

process for i in test_data’range

loop in0 <=test_data(i).in0; in1 <=test_data(i).in1; sel <=test_data(i).sel; ck <=‘0’; wait for

5 ns; ck <=‘1’; wait for

5 ns; assert z =

test_data(i).z report “output z is

wrong!” severity error;

end loop; wait; end process;

Page 16: Test Benches

16

Test Bench: count_ones

architecture behavior of count_ones is process (vec)

variable result: unsigned(4 downto 0); begin

result := to_unsigned(0, result’length)); for i in vec’range loop

next when vec(i) = ‘0’; result = result +1;

end loop count <= result;

end process;end;

Page 17: Test Benches

17

Test Bench: count_ones

• input and output of count_ones is vectors: Vec: std_logic_vector(15 downto 0); count: std_logic_vector(4 downto 0);

MUX0

+1

MUX

+1count

vec(15) vec(0)

Page 18: Test Benches

18

Test Bench: count_ones• under-test component instance:library ieee;use ieee.std_logic_1164.all;architecture test_bench of count_ones_test is component count_ones port ( vec : in std_logic_vector(15 downto 0); count: out std_logic_vector(4 downto 0); end component; for all: count_ones use work.count_ones; signal vec: std_logic_vector(15 downto 0); signal count: std_logic_vector(4 downto 0);begin CUT: count_ones port map(vec, count);end;

Page 19: Test Benches

19

Test Bench: count_ones

• Check the correctness through outputs • Response data:type sample is record vec : in std_logic_vector(15 downto 0); count : out std_logic_vector(4 downto 0); end;type sample_array is array (natural range <>) of sample;constant test_data: sample_array :=( (“0000000000000000”, “00000”), (“0000000000001111”, “00100”), ….);

Page 20: Test Benches

20

Test Bench: count_ones

• Response data with Hexadecimal: type sample is record vec:in std_logic_vector(15 downto 0); count: out std_logic_vector(4 downto 0); end; type sample_array is array (natural range <>) of sample; constant test_data: sample_array := ( (X“0000”, “00000”), (X“000F”, “00100”), …. );

Page 21: Test Benches

21

Test Bench: count_ones

• Response data with Hexadecimal input, integer output: type sample is record vec:in std_logic_vector(15 downto 0); count: out integer; end; type sample_array is array (natural range <>) of sample; constant test_data: sample_array := ( (X“0000”, 0), (X“000F”, 4), …. );

Page 22: Test Benches

22

Test Bench: count_ones

• Check the response process for i in test_data’range loop vec <=test_data(i).vec; wait for 10ns; assert count = to_unsigned(test_data(i).count,

count’length) report “output count is wrong!” severity error;

end loop; wait;end process;

Page 23: Test Benches

23

Test Bench: Don’t care

• Many circuits do not generate valid outputs on very clock cycle.• Example: pipeline• Test benches need to ignore the invalid outputs and check only valid outputs. 1. Use extra field to indicates an valid or invalid output the field’s type is boolean. 2. Use don’t care.

Page 24: Test Benches

24

Test Bench: invalid output

• Circuit to be tested: 1-bit register in the 3rd pipeline stage library ieee; use ieee.std_logic_1164.all; entity delay3 is

port (d, ck: in std_logic, q: out std_logic); end;• Sample record: type sample is record

d: std_logic;q: std_logic;valid: boolean;

end record;

Page 25: Test Benches

25

Test Bench: invalid output

• Test patten: constant test_data: sample_array:= (

(‘1’,’0’,false),(‘0’,’0’,false),(‘1’,’1’,true),

… );• test statement: if test_data(i).valid then

assert test_data(i).q = q report “q is wrong”; severity error;

end if;

Page 26: Test Benches

26

Test Bench: don’t care output

• Test patten: constant test_data: sample_array:= ( (‘1’,’-’),(‘0’,’-’),(‘1’,’1’), … );• test statement:assert std_match(test_data(i).q, q) report “q is wrong”; severity error;

Page 27: Test Benches

27

Print Response values

• It is useful to print out the expected and actual values.• A function converting std_logic to string:function toString(arg:std_logic) return string isbegin case arg is

when ‘U’ return “U”; when ‘X’ return “X”;when ‘0’ return “0”; when ‘1’ return “1”;when ‘W’ return “W”; when ‘L’ return “L”;when ‘H’ return “H”; when ‘Z’ return “Z”;when ‘-’ return “-”;

end case;end;

Page 28: Test Benches

28

Print Response values

• The assertion statement: assert test_data(i).q = q;

report “q:expected =“ & toString(test_data(i).q) &“, actural =“ & toString(q)

severity error;• See page 291-297 for predefined conversion functions.