Vous êtes sur la page 1sur 12

COMMENT RÉDIGER UN

TESTBENCH?
1 Nada SLIMANE
4MécaT
19/20
DÉFINITION
 Un TestBench (banc de test) est une description
d’une éventuelle séquence d’un comportement d’un
circuit pour le test. Il sert comme un stimuli (vecteur
de test) qui décrit les signaux d’entrée au cours du
temps.

2
SIMULATION ET VALIDATION
Comment faire une simulation ?
 instanciation du composant à tester

 initialisation des signaux d'entrées

 application d'une séquence de stimuli :

- à partir d'un process et d'affectations des signaux


d'entrées
- à partir d'un fichier contenant des vecteurs de test
 analyse des résultats, analyse des transitions des
sorties :
- affichage des erreurs éventuelles
3
TESTBENCH
 Un test bench est un module VHDL comme un
autre, mais qui n’a ni entrées ni sorties, il est
autonome.
 Il sert à tester le comportement d’un autre module.

 Il produit lui même les signaux à envoyer au circuit


à tester et vérifie que les sorties du circuit sont
correctes

4
EXEMPLE
Code VHDL porte OR:
 -- Simple OR gate design
 library IEEE;
 use IEEE.std_logic_1164.all;

 entity or_gate is
 port(
 a: in std_logic;
 b: in std_logic;
 q: out std_logic);
 end or_gate;

 architecture rtl of or_gate is


 begin
 process(a, b)
 begin
 q <= a or b;
 end process; 5
 end rtl;
EXEMPLE
Testbench porte OR:
 library IEEE;
 use IEEE.std_logic_1164.all;

 entity testbench is
 -- empty
 end testbench;
 architecture tb of testbench is
 -- DUT component
 component or_gate is
 port(
 a: in std_logic;
 b: in std_logic;
 q: out std_logic);
 end component;

 signal a_in, b_in, q_out: std_logic; 6


 begin
 DUT: or_gate port map(a_in, b_in, q_out); -- Connect DUT
 process
 begin
 a_in <= '0';
 b_in <= '0';
 wait for 1 ns;
 assert(q_out='0') report "Fail 0/0" severity error;
 a_in <= '0';
 b_in <= '1';
 wait for 1 ns;
 assert(q_out='1') report "Fail 0/1" severity error;
 a_in <= '1';
 b_in <= ‘0';
 wait for 1 ns;
 assert(q_out='1') report "Fail 1/0" severity error;
 a_in <= '1';
 b_in <= '1';
 wait for 1 ns;
 assert(q_out='1') report "Fail 1/1" severity error;
 a_in <= '0'; -- Clear inputs
 b_in <= '0';
 assert false report "Test done." severity note;
7
 wait;
 end process;
 end tb;
CODE VHDL D’UN ½ ADDITIONNEUR
 -- half_adder.vhd
 library ieee;
 use ieee.std_logic_1164.all;
 entity half_adder is
 port (a, b : in std_logic;
 sum, carry : out std_logic
 );
 end half_adder;
 architecture arch of half_adder is
 begin
 sum <= a xor b;
 carry <= a and b;
 end arch; 8
TESTBENCH D’UN 1/2ADDITIONNEUR
 library ieee;
 use ieee.std_logic_1164.all;
 entity half_adder_simple_tb is
 end half_adder_simple_tb;
 architecture tb of half_adder_simple_tb is
 Component half_adder is
 port (a, b : in std_logic;
 sum, carry : out std_logic
 );
 end component;
 signal a, b : std_logic;-- inputs
 signal sum, carry : std_logic; -- outputs
 begin -- connecting testbench signals with half_adder.vhd
 UUT : half_adder port map (a => a, b => b, sum => sum, carry => carry);
 -- inputs -- 00 at 0 ns -- 10 at 20 ns, as b is 0 at 20 ns and a is changed to 1 at 20
ns -- 01 at 40 ns -- 11 at 60 ns
 a <= '0', '1' after 20 ns, '0' after 40 ns, '1' after 60 ns;
 b <= '0', '1' after 40 ns; 9
 end tb ;
CODE VHDL D’UNE BASCULE D
 Entity bascule is
 port (d,clk : in bit;
 q : out bit);
 end bascule;
 Architecture simple of bascule is
 begin
 copie: process
 begin -- on attend une transition sur clk -- -> le process est
bloqué sur cette instruction tant que clk n'évolue pas
 wait on clk; -- si il y a transition on teste si elle est montante
 if clk='1' then -- dans ce cas d est copié sur q après 5 ns
 q <= d after 5 ns;
 end if;
 end process copie;
 end simple; 10
TESTBENCH D’UNE BASCULE D
 entity test_bascule is
 end test_bascule;
 architecture test_bench of test_bascule is
 component latch
 port( d,clk : in bit; q : out bit);
 end component;
 signal din,dout: bit;
 signal horloge : bit:=‘0’;
 Begin
 IC1 : latch port map (din,horloge,dout);
 horloge <= not horloge after 20 ns;
 din <= '1','0' after 35 ns,'1' after 70 ns;
 end test_bench; 11
SIMULATION ET VALIDATION
 Pour réaliser un test, il faut faire un certain nombre
de choses. On doit décrire un composant
"TestBench« (banc de test)
 Ce composant doit :

- instancier le composant à tester


- initialiser les signaux d'entrées
- appliquer des stimuli sur ces signaux
- observer les activités des sorties.

12

Vous aimerez peut-être aussi