OpenCores
URL https://opencores.org/ocsvn/tinycpu/tinycpu/trunk

Subversion Repositories tinycpu

[/] [tinycpu/] [trunk/] [testbench/] [alu_tb.vhd] - Blame information for rev 24

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 earlz
LIBRARY ieee;
2
USE ieee.std_logic_1164.ALL;
3
USE ieee.numeric_std.ALL;
4
use work.tinycpu.all;
5
 
6
ENTITY alu_tb IS
7
END alu_tb;
8
 
9
ARCHITECTURE behavior OF alu_tb IS
10
 
11
-- Component Declaration for the Unit Under Test (UUT)
12
 
13
  component alu is
14
    port(
15
      Op: in std_logic_vector(4 downto 0);
16
      DataIn1: in std_logic_vector(7 downto 0);
17
      DataIn2: in std_logic_vector(7 downto 0);
18
      DataOut: out std_logic_vector(7 downto 0);
19
      TR: out std_logic
20
    );
21
  end component;
22
 
23
 
24
  --Inputs
25
  signal Op: std_logic_vector(4 downto 0) := "00000";
26
  signal DataIn1: std_logic_vector(7 downto 0) := "00000000";
27
  signal DataIn2: std_logic_vector(7 downto 0) := "00000000";
28
  --Outputs
29
  signal DataOut: std_logic_vector(7 downto 0);
30
  signal TR: std_logic;
31
 
32
  signal Clock: std_logic;
33
  constant clock_period : time := 10 ns;
34
 
35
BEGIN
36
 
37
  -- Instantiate the Unit Under Test (UUT)
38
  uut: alu PORT MAP (
39
    Op => Op,
40
    DataIn1 => DataIn1,
41
    DataIn2 => DataIn2,
42
    DataOut => DataOut,
43
    TR => TR
44
  );
45
 
46
  -- Clock process definitions
47
  clock_process :process
48
  begin
49
    Clock <= '0';
50
    wait for clock_period/2;
51
    Clock <= '1';
52
    wait for clock_period/2;
53
  end process;
54
 
55
 
56
  -- Stimulus process
57
  stim_proc: process
58
    variable err_cnt: integer :=0;
59
  begin
60
    -- hold reset state for 20 ns.
61
    wait for 20 ns;
62
 
63
    --wait for clock_period*10;
64
 
65
    -- case 1
66
    Op <= "00000"; --and
67
    DataIn1 <= "10000001";
68
    DataIn2 <= "11111110";
69
    wait for 10 ns;
70
    assert (DataOut="10000000") report "And operation error case 1" severity error;
71
    -- case 2
72
    Op <= "00001"; --or
73
    DataIn1 <= "10000001";
74
    DataIn2 <= "11111100";
75
    wait for 10 ns;
76
    assert (DataOut="11111101") report "Or operation error" severity error;
77
 
78
    Op <= "00010"; --xor
79
    DataIn1 <= "10000001";
80
    DataIn2 <= "11111100";
81
    wait for 10 ns;
82
    assert (DataOut="01111101") report "Xor operation error" severity error;
83
 
84
    Op <= "00011"; --not
85
    DataIn1 <= "10000001";
86
    DataIn2 <= "11111100";
87
    wait for 10 ns;
88
    assert (DataOut="00000011") report "Not operation error" severity error;
89
 
90
    Op <= "00100"; --shift left
91
    DataIn1 <= "11110011";
92
    DataIn2 <= x"02";
93
    wait for 10 ns;
94
    assert (DataOut="11001100") report "shift left operation error" severity error;
95
 
96
    Op <= "00101"; --shift right
97
    DataIn1 <= "11110011";
98
    DataIn2 <= x"02";
99
    wait for 10 ns;
100
    assert (DataOut="00111100") report "shift right operation error" severity error;
101
 
102
    Op <= "00110"; --rotate left
103
    DataIn1 <= "11110011";
104
    DataIn2 <= x"02";
105
    wait for 10 ns;
106
    assert (DataOut="11001111") report "rotate left operation error" severity error;
107
 
108
    Op <= "00111"; --rotate right
109
    DataIn1 <= "11110011";
110
    DataIn2 <= x"02";
111
    wait for 10 ns;
112
    assert (DataOut="11111100") report "rotate right operation error" severity error;
113
 
114
    Op <= "01000"; --is greater than
115
    DataIn1 <= x"20";
116
    DataIn2 <= x"40";
117
    wait for 10 ns;
118
    assert (TR='0') report "is greater than operation error" severity error;
119
 
120
    Op <= "01001"; --is greater than or equal
121
    DataIn1 <= x"20";
122
    DataIn2 <= x"40";
123
    wait for 10 ns;
124
    assert (TR='0') report "greater than or equal operation error case 1" severity error;
125
 
126
    Op <= "01001"; --is greater than or equal
127
    DataIn1 <= x"40";
128
    DataIn2 <= x"40";
129
    wait for 10 ns;
130
    assert (TR='1') report "greater than or equal operation error case 2" severity error;
131
 
132
    Op <= "01010"; --is less than
133
    DataIn1 <= x"20";
134
    DataIn2 <= x"40";
135
    wait for 10 ns;
136
    assert (TR='1') report "less than operation error case 1" severity error;
137
 
138
    Op <= "01010"; --less than
139
    DataIn1 <= x"40";
140
    DataIn2 <= x"40";
141
    wait for 10 ns;
142
    assert (TR='0') report "less than operation error case 2" severity error;
143
 
144
    Op <= "01011"; --less than or equal
145
    DataIn1 <= x"20";
146
    DataIn2 <= x"40";
147
    wait for 10 ns;
148
    assert (TR='1') report "less than or equal operation error" severity error;
149
 
150
    Op <= "01100"; --equal
151
    DataIn1 <= x"20";
152
    DataIn2 <= x"40";
153
    wait for 10 ns;
154
    assert (TR='0') report "equal operation error" severity error;
155
 
156
    Op <= "01100"; --equal
157
    DataIn1 <= x"40";
158
    DataIn2 <= x"40";
159
    wait for 10 ns;
160
    assert (TR='1') report "equal operation error" severity error;
161
 
162
    Op <= "01101"; --not equal
163
    DataIn1 <= x"20";
164
    DataIn2 <= x"40";
165
    wait for 10 ns;
166
    assert (TR='1') report "not equal operation error" severity error;
167
 
168
    Op <= "01101"; --not equal
169
    DataIn1 <= x"40";
170
    DataIn2 <= x"40";
171
    wait for 10 ns;
172
    assert (TR='0') report "not equal operation error" severity error;
173
 
174
    Op <= "01110"; --equal to 0
175
    DataIn1 <= x"40";
176
    DataIn2 <= x"50";
177
    wait for 10 ns;
178
    assert (TR='0') report "equal to 0 operation error" severity error;
179
    Op <= "01110"; --equal to 0
180
    DataIn1 <= x"00";
181
    DataIn2 <= x"50";
182
    wait for 10 ns;
183
    assert (TR='1') report "equal to 0 operation error" severity error;
184
 
185
    Op <= "01111"; --not equal to 0
186
    DataIn1 <= x"40";
187
    DataIn2 <= x"50";
188
    wait for 10 ns;
189
    assert (TR='1') report "not equal to 0 operation error" severity error;
190
    Op <= "01111"; --not equal to 0
191
    DataIn1 <= x"00";
192
    DataIn2 <= x"50";
193
    wait for 10 ns;
194
    assert (TR='0') report "not equal to 0 operation error" severity error;
195
 
196
    Op <= "10000"; --set TR
197
    wait for 10 ns;
198
    assert (TR='1') report "set TR operation error" severity error;
199
    Op <= "10001"; --reset TR
200
    wait for 10 ns;
201
    assert (TR='0') report "reset TR operation error" severity error;
202
 
203
    Op <= "10010"; --increment
204
    DataIn1 <= x"42";
205
    DataIn2 <= x"50";
206
    wait for 10 ns;
207
    assert (DataOut=x"43") report "increment operation error" severity error;
208
 
209
    Op <= "10011"; --decrement
210
    DataIn1 <= x"42";
211
    DataIn2 <= x"50";
212
    wait for 10 ns;
213
    assert (DataOut=x"41") report "decrement operation error" severity error;
214
 
215
    Op <= "10100"; --add
216
    DataIn1 <= x"42";
217
    DataIn2 <= x"50";
218
    wait for 10 ns;
219
    assert (DataOut=x"92") report "add operation error" severity error;
220
 
221
    Op <= "10101"; --subtract
222
    DataIn1 <= x"50";
223
    DataIn2 <= x"42";
224
    wait for 10 ns;
225
    assert (DataOut=x"0E") report "subtract operation error" severity error;
226
 
227
    Op <= "10100"; --add
228
    DataIn1 <= x"FF";
229
    DataIn2 <= x"02";
230
    wait for 10 ns;
231
    assert (DataOut=x"01") report "add overflow operation error" severity error;
232
 
233
    Op <= "10101"; --subtract
234
    DataIn1 <= x"00";
235
    DataIn2 <= x"02";
236
    wait for 10 ns;
237
    assert (DataOut=x"FE") report "subtract underflow operation error" severity error;
238
 
239
    Op <= "10000"; --set TR
240
    wait for 10 ns;
241
    Op <= "10011"; --decrement
242
    DataIn1 <= x"12";
243
    wait for 10 ns;
244
    assert (TR='1') report "TR persistence error" severity error;
245
 
246
 
247
 
248
    -- summary of testbench
249
    assert false
250
    report "Testbench of alu completed successfully!"
251
    severity note;
252
 
253
    wait;
254
 
255
    -- insert stimulus here 
256
 
257
    wait;
258
  end process;
259
 
260
 
261
END;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.