Vous êtes sur la page 1sur 29

Banc de test

Test Bench
Cours 7
25 oct 2017
Banc de test- Test Bench
• Test bench = entité VHDL qui applique des stimuli
(les entrées) pour le circuit sous test
(DUT) et (éventuellement) vérifie les résultats
attendus.
• Le même banc d'essai peut être utilisé pour
tester plusieurs implémentations d'un même
circuit (architectures multiples)
• Les résultats peuvent être visualisés dans une
fenêtre chronogramme ou écrites dans un fichier.
Vecteurs de Test
Ensemble de paires: {Entrée i, Sortie désirée i}
Entrée 1, Sortie désirée1
Entrée 2, Sortie désirée 2
……………………………
Entrée N, Sortie désirée N

Les vecteurs de test peuvent être:


- Définis dans le fichier source Testbench
- Stockés dans un fichier de données
Structure d’un test bench
ENTITY my_entity_tb IS
--TB entity has no ports
END my_entity_tb;

ARCHITECTURE behavioral OF my_entity_tb IS


--Local signals and constants

BEGIN
DUT: entity work.TestComp(dataflow) PORT MAP( -- Instantiations de
circuits sous test (DUTs));
testSequence: PROCESS
-- Input stimuli Génération des exemples
END PROCESS;
END behavioral;
TEST Bench XOR3
LIBRARY ieee;
USE ieee.std_logic_1164.all;

ENTITY xor3_tb IS
END xor3_tb;

ARCHITECTURE behavioral OF xor3_tb IS


-- Stimulus signals - signals mapped to the input and inout ports of tested entity
SIGNAL test_vector: STD_LOGIC_VECTOR(2 DOWNTO 0);
SIGNAL test_result : STD_LOGIC;
BEGIN
UUT : entity work.xor3(struct)
PORT MAP (
A => test_vector(2),
B => test_vector(1),
C => test_vector(0),
Result => test_result);
Testing: PROCESS
BEGIN
test_vector <= "000";
WAIT FOR 10 ns;
test_vector <= "001";
WAIT FOR 10 ns;
test_vector <= "010";
WAIT FOR 10 ns;
test_vector <= "011";
WAIT FOR 10 ns;
test_vector <= "100";
WAIT FOR 10 ns;
test_vector <= "101";
WAIT FOR 10 ns;
test_vector <= "110";
WAIT FOR 10 ns;
test_vector <= "111";
WAIT FOR 10 ns;

END PROCESS;
END behavioral;
utilisation de PROCESS sans liste de
sensibilité dans les Test benches
PROCESS avec une instruction WAIT
WAIT FOR vs WAIT
-- fichier du composant ET_2.vhd
library ieee;
use ieee.std_logic_1164.all;

Entity ET_2 is port( A,B : in std_logic;


C: out std_logic);
End ET_2;
Architecture Struct of ET_2 is
Begin
C<= A and B;
End struct;
-- fichier du composant ET_3.vhd
library ieee;
use ieee.std_logic_1164.all;

Entity ET_3 is port( e1,e2,e3 : in std_logic;


S: out std_logic);
End ET_3;
architecture struct of et_3 is
component ET_2 port ( a , b : in std_logic ;
c : out std_logic ) ;
end component ;
signal S1 : std_logic;

begin
-- utilisation :
et1 : ET_2 port map ( e1, e2,S1) ;
et2 : ET_2 port map ( S1, e3,S) ;
End struct ;
constant n : positive := 10;
-- dans la zone de déclaration de l’architecture
begin
-- début du corps d’ architecture boucle :
process
begin
loop1: For i in 1 to n-1 loop
a <= '1';
wait for i*100 ns;
a <= '0';
wait for (n-i)*100 ns;
end loop;
end process;
b <= '1' after 10 us;
Exemples
ex1 ADD SUB
Additionneur –soustracteur
• On considère un circuit arithmétique simple qui
réalise les 2 opérations: (addition , soustraction).
• Un signal de contrôle , ctrl , spécifie l’opération
demandé.
ctrl opération
0 A+B
1 A-B

Le premier design suit le tableau de fonctionnement


et le code VHDL est donné par:
library ieee ;
use ieee.Std_logic_1164. all ;
Code vhdl
use ieee.Numeric_std. all ;

entity addsub is port(


a, b : in std_logic_vector (7 downto 0) ;
ctrl: in std_logic;
r : out std_logic _ vector(7 downto 0));
end addsub;
architecture direct_arch of addsub is
signal src0, src1 , res: signed(7 downto 0) ;
begin
src0 <= signed(a);
src1 <= signed(b);

res<= src0 + src1 when ctrl=‘0’ else


src0-src1;
r <= std_logic_vector(res);
end direct_arch;
Optimisation du code à travers
partage (sharing)
a+(-b) = a+ Compl à 2(b) = a+(not b +1)
architecture shared_arch of addsub is
signal src0, src1 , res: signed(7 downto 0) ;
A1 : std_logic_vector(8 downto 0);
signal cin: signed(0 downto 0); -- carry -in bit
Begin
a1<=a & ‘1’;
src0 <= signed(a1);
src1 <= signed(b) when ctrl=’0’ else
signed (not b) ;
cin <= “0” when ctrl= else
“1”;
res <= src0 + src1 + cin;
r <= std_logic_vector(sum);
end shared_arch ;
• ²
a = a7a6a5a4a3a2a1a0
b = b7b6b5b4b3b2b10

Les opérandes étendues:


a7a6a5a4a3a2a1a0 1
b7b6b5b4b3b2b1b0
architecture manual_carry_arch of addsub is
signal src0, src1, res: signed(8 downto 0);
signal b_tmp: std_logic_vector ( 7 downto 0) ;
signal cin: std_logic; -- carry - in bit
src0 <= signed(a & ‘1’);
b_tmp <= b when ctrl=>’0’ else
not b;
cin <= ‘0’ when ctrl=‘0’ else
src1 <= signed(b_tmp & cin);
res <= src0 + src1;
r <= std_logic_vector (res( 8 downto 1)) ;
end manual_carry_arch ;
Exemple 2
Une calculatrice arithmétique très simple.
• On va concevoir un circuit qui possède une entrée de données de
8 bits DIN, une sortie de données de 8 bits result et les entrées de
commande clr , load et add.
• Il dispose d'un registre de stockage interne qui permet de stocker
une valeur de 8 bits.
La sortie est la valeur stockée dans ce registre.
Lorsque l'entrée clr est affirmée, la valeur stockée est effacée,
lorsque l'entrée load est affirmé la valeur DIN est stocké,
et lorsque l'entrée add est affirmé, la valeur DIN est ajouté à la
valeur stockée.
• Le CLK contrôle le moment où le circuit répond à des entrées de
commande.
En particulier, il effectue une opération que lorsque l'entrée CLK
fait une transition de bas en haut.
Entité
• La déclaration de l'entité pour le circuit est
représenté ci-dessous:
entity calculator is
port ( clk: in std_logic;
clear, load, add: in std_logic;
dIn: in std_logic_vector(7 downto 0);
result: out std_logic_vector(7 downto 0));
end calculator;
architecture
• Voici donc l'architecture d'un circuit qui met en œuvre
la fonctionnalité désirée.
architecture calcArch of calculator is
signal dReg: std_logic_vector(7 downto 0);
begin
process (clk)
begin
if rising_edge(clk) then
if clear = '1' then
dReg <= x"00";
elsif load = '1' then
dReg <= dIn;
elsif add = '1' then
dReg <= dReg + dIn;
end if;
end if;
end process;
result <= dReg;
end calcArc
Test bench
entity testit1_vhd is
end testit1_vhd;
architecture a1 of testit1_vhd is
component calculator
port(clk : in std_logic;
clear, load, add : in std_logic;
dIn : in std_logic_vector(7 downto 0);
result : out std_logic_vector(7 downto 0));
end component;
Library ieee;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
use IEEE.std_logic_unsigned.all;

entity ALU is
port(A: in std_logic_vector(1 downto 0);
B: in std_logic_vector(1 downto 0);
Sel: in std_logic_vector(1 downto 0);
Res: out std_logic_vector(1 downto 0));
end ALU;
Architecture behv of ALU is
begin
process(A,B,Sel)
begin
case Sel is
when "00" =>
Res <= A + B;
when "01" =>
Res <= A + (not B) + 1;
when "10" =>
Res <= A and B;
when "11" =>
Res <= A or B;
when others =>
Res <= "XX";
end case;
end process;
end behv;
---- Le test bench
library IEEE;
use IEEE.std_logic_1164. all;

entity ALU_tb is
end ALU_tb;

architecture TB of ALU_tb is

component ALU
port(A: in std_logic_vector(1 downto 0);
B: in std_logic_vector(1 downto 0);
Sel: in std_logic_vector(1 downto 0);
Res: out std_logic_vector(1 downto 0)
);
end component;

signal A, B, Res: std_logic_vector(1 downto 0):="00"; --valeur initiale

signal Sel: std_logic_vector(1 downto 0);


begin

U_ALU: ALU port map (A, B, Sel, Res);


process
begin
process
Sel <= "00";
begin
A <= "00";
B <= "01";
Sel <= "00";
wait for 10 ns;
A <= "01";
B <= "10"; A <= "00";
B <= "01";
wait for 10 ns;

Sel <= "10"; wait for 10 ns;


A <= "11"; A <= "01";
B <= "01"; B <= "10";
wait for 10 ns;
A <= "10"; wait for 10 ns;
B <= "10";

wait for 10 ns; Sel <= "10";

Vous aimerez peut-être aussi