Міністерство освіти і науки України
Національний університет “Львівська політехніка”
Кафедра ЕОМ
Звіт по лабораторній роботі №3
з предмету “Теорія і проектування комп'ютерних систем та мереж”
Львів – 2004
Тема роботи: розробка системи тестування простого пристрою.
Мета роботи: ознайомитись з технологією виготовлення та принципами функціонування тестуючих програм, створити середовище тестування (тестбенч) пристрою, перевірити його роботоздатність та коректність його роботи.
VHDL-код тестувальної програми:
library ieee;
use ieee.std_logic_1164.all;
use std.textio.all;
use ieee.std_logic_textio.all;
entity adder_tb is
generic(
period : time := 100ns;
in_data : string := "In_data.txt";
out_data : string := "out_data.txt"
);
end adder_tb;
architecture tb_arch of adder_tb is
component addsub
port (
ADDSUB : in std_logic;
OV : out std_logic;
CO : out std_logic;
A, B : in std_logic_vector (11 downto 0);
Q : out std_logic_vector (11 downto 0);
CLK : in std_logic;
RST : in std_logic
);
end component;
signal A, B, Q : STD_LOGIC_VECTOR (11 downto 0);
signal OV, CO, ASUB: STD_LOGIC;
signal CLK, RST : std_logic;
begin
uut: addsub
port map(
ADDSUB => ASUB,
A =>A,
B => B,
Q => Q,
OV => OV,
CO => CO,
CLK => CLK,
RST => RST
);
clk_proc: process
begin
clk <= '1';
wait for 0.5*period;
clk <= '0';
wait for 0.5*period;
end process clk_proc;
reset_proc: process
begin
rst <= '1';
wait for period;
rst <= '0';
wait;
end process reset_proc;
data_rd_proc: process
file dat: text is in_data;
variable data_line : line;
variable in_tmp_a, in_tmp_b, in_tmp_addsub: STD_LOGIC_VECTOR (11 downto 0);
begin
A <= (others => '0');
B <= (others => '0');
ASUB <= '0';
wait for 2.01*period;
data_rd_a: while not (endfile(dat)) loop
--wait for 0.5*period;
readline (dat, data_line);
hread (data_line, in_tmp_a);
hread (data_line, in_tmp_b);
hread (data_line, in_tmp_addsub);
A(11 downto 0) <= in_tmp_a(11 downto 0);
B(11 downto 0) <= in_tmp_b(11 downto 0);
ASUB <= in_tmp_addsub(0);
wait for period;
assert false report "DATA READING In_data_a and In_data_b and In_data_addsub..." severity note;
end loop data_rd_a;
end process data_rd_proc;
data_comp_proc: process
file pat:text is out_data;
variable pat_line : line;
variable pat_tmp_q : STD_LOGIC_VECTOR (11 downto 0);
variable pat_tmp_co : STD_LOGIC_VECTOR (11 downto 0);
variable pat_tmp_ov : STD_LOGIC_VECTOR (11 downto 0);
begin
wait for 4*period;
pat_rd: while not (endfile(pat)) loop
--wait for 0.5*period;
readline (pat, pat_line);
hread (pat_line, pat_tmp_q);
hread (pat_line, pat_tmp_co);
hread (pat_line, pat_tmp_ov);
wait for period;
if pat_tmp_q (11 downto 0) /= Q (11 downto 0) then
assert false report "ERROR IN DATA COMPARING Q!!!#" severity warning;
else
assert false report "DATA COMPARED SUCCESSFULLY Q!#" severity note;
end if;
if pat_tmp_ov(0) /= OV then
assert false report "ERROR IN DATA COMPARING OV!!!#" severity warning;
else
assert false report "DATA COMPARED SUCCESSFULLY OV!#" severity note;
end if;
if pat_tmp_co(0) /= CO then
assert false report "ERROR IN DATA COMPARING CO!!!#" severity warning;
else
assert false report "DATA COMPARED SUCCESSFULLY CO!#" severity note;
end if;
end loop;
end process data_comp_proc;
end tb_arch;
Тексти тестувальних і перевірочних файлів:
In_data_a.txt
005 004 001
008 004 000
00E 005 000
001 009 001
out_data_q.txt
009 0 0
004 0 0
009 0 0
00A 0 0
Результати симуляціїї:
# : NOTE : DATA READING In_data_a and In_data_b and In_data_addsub...
# : Time: 401 ns, Iteration: 0, TOP instance.
# : NOTE : DATA COMPARED SUCCESSFULLY Q!#
# : Time: 500 ns, Iteration: 0, TOP instance.
# : NOTE : DATA COMPARED SUCCESSFULLY OV!#
# : Time: 500 ns, Iteration: 0, TOP instance.
# : NOTE : DATA COMPARED SUCCESSFULLY CO!#
# : Time: 500 ns, Iteration: 0, TOP instance.
# : NOTE : TextIO internal note: Attempt to read type
# : Time: 501 ns, Iteration: 0, TOP instance.
# : NOTE : DATA COMPARED SUCCESSFULLY Q!#
# : Time: 600 ns, Iteration: 0, TOP instance.
# : NOTE : DATA COMPARED SUCCESSFULLY OV!#
# : Time: 600 ns, Iteration: 0, TOP instance.
# : NOTE : DATA COMPARED SUCCESSFULLY CO!#
# : Time: 600 ns, Iteration: 0, TOP instance.
run 100 ns
# : Time: 601 ns, Iteration: 0, TOP instance.
# : NOTE : DATA COMPARED SUCCESSFULLY Q!#
# : Time: 700 ns, Iteration: 0, TOP instance.
# : NOTE : DATA COMPARED SUCCESSFULLY OV!#
# : Time: 700 ns, Iteration: 0, TOP instance.
# : NOTE : DATA COMPARED SUCCESSFULLY CO!#
# : Time: 700 ns, Iteration: 0, TOP instance.
run 100 ns
# : NOTE : DATA COMPARED SUCCESSFULLY Q!#
# : Time: 800 ns, Iteration: 0, TOP instance.
# : NOTE : DATA COMPARED SUCCESSFULLY OV!#
# : Time: 800 ns, Iteration: 0, TOP instance.
# : NOTE : DATA COMPARED SUCCESSFULLY CO!#
# : Time: 800 ns, Iteration: 0, TOP instance.