-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathALUTest.vhd
141 lines (113 loc) · 4.1 KB
/
ALUTest.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--USE ieee.numeric_std.ALL;
ENTITY ALUTest IS
END ALUTest;
ARCHITECTURE behavior OF ALUTest IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT ALU
PORT(
data1 : IN std_logic_vector(31 downto 0);
data2 : IN std_logic_vector(31 downto 0);
aluop : IN std_logic_vector(3 downto 0);
cin : IN std_logic;
dataout : OUT std_logic_vector(31 downto 0);
cflag : OUT std_logic;
zflag : OUT std_logic;
oflag : OUT std_logic
);
END COMPONENT;
--Inputs
signal data1 : std_logic_vector(31 downto 0) := (others => '0');
signal data2 : std_logic_vector(31 downto 0) := (others => '0');
signal aluop : std_logic_vector(3 downto 0) := (others => '0');
signal cin : std_logic := '0';
--Outputs
signal dataout : std_logic_vector(31 downto 0);
signal cflag : std_logic;
signal zflag : std_logic;
signal oflag : std_logic;
-- No clocks detected in port list. Replace <clock> below with
-- appropriate port name
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: ALU PORT MAP (
data1 => data1,
data2 => data2,
aluop => aluop,
cin => cin,
dataout => dataout,
cflag => cflag,
zflag => zflag,
oflag => oflag
);
-- Stimulus process
stim_proc: process
begin
-- hold reset state for 100 ns.
wait for 10ns;
--AND testcase
data1 <= "11000000000000000000000000000000" ;
data2 <= "10100000000000000000000000000000" ;
aluop <= "0000" ;
wait for 10ns;
report "Test1";
assert(dataout = "10000000000000000000000000000000" and zflag = '0') report "1:Fail" severity error;
wait for 1ns;
--OR testcase
data1 <= "11000000000000000000000000000000" ;
data2 <= "10100000000000000000000000000000" ;
aluop <= "0001" ;
wait for 10ns;
report "Test2";
assert(dataout = "11100000000000000000000000000000" and zflag = '0') report "2:Fail" severity error;
wait for 1ns;
--ADD testcase1 (overflow = 1, cout = 0)
data1 <= "01110000000000000000000000000000" ;
data2 <= "01100000000000000000000000000000" ;
aluop <= "0010" ;
wait for 10ns;
report "Test3";
assert(dataout = "11010000000000000000000000000000" and oflag = '1' and cflag = '0' and zflag = '0') report "3:Fail" severity error;
wait for 1ns;
--ADD testcase2 (zero = 1, cout = 1)
data1 <= "11110000000000000000000000000000" ;
data2 <= "00010000000000000000000000000000" ;
aluop <= "0010" ;
wait for 10ns;
report "Test4";
assert(dataout = "00000000000000000000000000000000" and oflag = '0' and cflag = '1' and zflag = '1') report "4:Fail" severity error;
wait for 1ns;
--SUB testcase1 (cout = 1)
data1 <= "00000000000000000000000000000111" ; --a = 7
data2 <= "00000000000000000000000000000110" ; --b = 6
cin <= '1' ;
aluop <= "0110" ;
wait for 10ns;
report "Test5";
assert(dataout = "00000000000000000000000000000001" and oflag = '0' and cflag = '1' and zflag = '0') report "5:Fail" severity error;
wait for 1ns;
--SUB testcase2 (cout = 0)
data1 <= "00000000000000000000000000000110" ; --a = 6
data2 <= "00000000000000000000000000000111" ; --b = 7
cin <= '1' ;
aluop <= "0110" ;
wait for 10ns;
report "Test6";
assert(dataout = "11111111111111111111111111111111" and oflag = '0' and cflag = '0' and zflag = '0') report "6:Fail" severity error;
wait for 1ns;
--SUB testcase3 (overflow = 1)
data1 <= "11111111111111111111111111111000" ; --a = -8
data2 <= "00000000000000000000000000000001" ; --b = 1
cin <= '1' ;
aluop <= "0110" ;
wait for 10ns;
report "Test7";
assert(dataout = "11111111111111111111111111110111" and oflag = '1' and cflag = '1' and zflag = '0') report "7:Fail" severity error;
wait for 1ns;
report "Test Complete";
wait;
end process;
END;