-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHA_TB.vhd
72 lines (64 loc) · 1.45 KB
/
HA_TB.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
-- ******************************************************************
-- Author: Pritam Sethuraman
--
-- File: HA_TB.vhd
--
-- Revision History
-- Version 1.0
-- Date: 24/09/2022
-- Comments: Original
-- ******************************************************************
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity half_adder_testbench is
end half_adder_testbench;
architecture TB_arch of half_adder_testbench is
component half_adder
port (
IN1, IN2: in STD_LOGIC;
SUM, COUT: out STD_LOGIC
);
end component;
-- test signals
signal P, Q: STD_LOGIC := '0';
signal S, C: STD_LOGIC;
begin
unit1: half_adder
port map(IN1 => P, IN2 => Q, SUM => S, COUT => C);
-- test bits
process
begin
P <= '0';
Q <= '0';
wait for 100 ns;
P <= '0';
Q <= '1';
wait for 100 ns;
P <= '1';
Q <= '0';
wait for 100 ns;
P <= '1';
Q <= '1';
wait for 100 ns;
end process;
-- verifier
process
variable error_flag: boolean;
begin
wait on P, Q;
wait for 100 ns;
if ((P = '0' and Q = '0' and S = '0' and C = '0') or
(P = '0' and Q = '1' and S = '1' and C = '0') or
(P = '1' and Q = '0' and S = '1' and C = '0') or
(P = '1' and Q = '1' and S = '0' and C = '1'))
then
error_flag := false;
else
error_flag := true;
end if;
-- error reporting
assert not error_flag
report "test failed."
severity note;
end process;
end TB_arch;