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

Subversion Repositories opencpu32

[/] [opencpu32/] [trunk/] [hdl/] [opencpu32/] [testAlu.vhd] - Blame information for rev 28

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 leonardoar
--! @file
2
--! @brief Testbench for Alu
3
 
4
--! Use standard library and import the packages (std_logic_1164,std_logic_unsigned,std_logic_arith)
5
library IEEE;
6
use ieee.std_logic_1164.all;
7
use ieee.std_logic_unsigned.all;
8
use ieee.std_logic_arith.all;
9
 
10
--! Use CPU Definitions package
11
use work.pkgOpenCPU32.all;
12
 
13
ENTITY testAlu IS
14
END testAlu;
15
 
16
--! @brief Alu Testbench file
17
--! @details Exercise each Alu operation to verify if the description work as planned 
18
--! for more information: http://vhdlguru.blogspot.com/2010/03/how-to-write-testbench.html
19
ARCHITECTURE behavior OF testAlu IS
20
 
21
 
22
         --! Component declaration to instantiate the Alu circuit
23
    COMPONENT Alu
24 28 leonardoar
    generic (n : integer := nBits - 1);                                         --! Generic value (Used to easily change the size of the Alu on the package)
25
         Port ( A : in  STD_LOGIC_VECTOR (n downto 0);                   --! Alu Operand 1
26
           B : in  STD_LOGIC_VECTOR (n downto 0);                        --! Alu Operand 2
27
           S : out  STD_LOGIC_VECTOR (n downto 0);                       --! Alu Output
28
                          flagsOut : out STD_LOGIC_VECTOR(2 downto 0);   --! Flags from current operation
29
           sel : in  aluOps);                                                                           --! Select operation                                                            --! Select operation
30 9 leonardoar
    END COMPONENT;
31
 
32
 
33
   --Inputs
34 12 leonardoar
   signal A : std_logic_vector((nBits - 1) downto 0) := (others => '0');  --! Wire to connect Test signal to component
35
   signal B : std_logic_vector((nBits - 1) downto 0) := (others => '0');  --! Wire to connect Test signal to component
36
   signal sel : aluOps := alu_sum;                                                                                                              --! Wire to connect Test signal to component
37 9 leonardoar
 
38
        --Outputs
39 12 leonardoar
   signal S : std_logic_vector((nBits - 1) downto 0);                                                            --! Wire to connect Test signal to component
40 28 leonardoar
        signal flagsOut : std_logic_vector(2 downto 0);                                                                  --! Wire to connect Test signal to component
41 9 leonardoar
 
42
BEGIN
43
 
44 12 leonardoar
        --! Instantiate the Unit Under Test (Alu) (Doxygen bug if it's not commented!)
45 9 leonardoar
   uut: Alu PORT MAP (
46
          A => A,
47
          B => B,
48
          S => S,
49 28 leonardoar
                         flagsOut => flagsOut,
50 9 leonardoar
          sel => sel
51
        );
52
 
53
   --! Process that will stimulate all of the Alu operations
54
   stim_proc: process
55 17 leonardoar
        variable mulResult : std_logic_vector(((nBits*2) - 1)downto 0);
56 9 leonardoar
   begin
57 16 leonardoar
      -- Pass ---------------------------------------------------------------------------
58 9 leonardoar
                wait for 1 ps;
59 16 leonardoar
                REPORT "Pass input A to output" SEVERITY NOTE;
60
                sel <= alu_pass;
61
                A <= conv_std_logic_vector(22, nBits);
62
                wait for 1 ns;  -- Wait to stabilize the response
63 17 leonardoar
                assert S = (A ) report "Invalid Pass output" severity FAILURE;
64
 
65
                -- Sum ---------------------------------------------------------------------------
66
                wait for 1 ps;
67
                REPORT "Sum without carry 12 AND 13" SEVERITY NOTE;
68
                sel <= alu_sum;
69
                A <= conv_std_logic_vector(12, nBits);
70
                B <= conv_std_logic_vector(13, nBits);
71
                wait for 1 ns;  -- Wait to stabilize the response       
72
                assert S = (A + B) report "Invalid Sum output" severity FAILURE;
73
 
74
                -- Sub ---------------------------------------------------------------------------
75
                wait for 1 ps;
76
                REPORT "Sub without carry 34 AND 30" SEVERITY NOTE;
77
                sel <= alu_sub;
78
                A <= conv_std_logic_vector(34, nBits);
79
                B <= conv_std_logic_vector(30, nBits);
80
                wait for 1 ns;  -- Wait to stabilize the response
81
                assert S = (A - B) report "Invalid Sum Sub" severity FAILURE;
82 16 leonardoar
 
83 17 leonardoar
                -- Inc ---------------------------------------------------------------------------
84
                wait for 1 ps;
85
                REPORT "Inc without carry 1" SEVERITY NOTE;
86
                sel <= alu_inc;
87
                A <= conv_std_logic_vector(1, nBits);
88
                wait for 1 ns;  -- Wait to stabilize the response
89
                assert S = (A + 1) report "Invalid Sum Sub" severity FAILURE;
90
 
91
                -- Dec ---------------------------------------------------------------------------
92
                wait for 1 ps;
93
                REPORT "Dec without carry 1" SEVERITY NOTE;
94
                sel <= alu_dec;
95
                A <= conv_std_logic_vector(1, nBits);
96
                wait for 1 ns;  -- Wait to stabilize the response
97
                assert S = (A - 1) report "Invalid Sum Sub" severity FAILURE;
98
 
99
                -- Mul ---------------------------------------------------------------------------
100
                wait for 1 ps;
101
                REPORT "Sub without carry 34 AND 30" SEVERITY NOTE;
102
                sel <= alu_mul;
103
                A <= conv_std_logic_vector(3, nBits);
104
                B <= conv_std_logic_vector(5, nBits);
105
                wait for 1 ns;  -- Wait to stabilize the response
106
                mulResult := (A * B);
107
                assert S = (mulResult((nBits - 1) downto 0)) report "Invalid Sum Sub" severity FAILURE;
108
 
109 16 leonardoar
                -- AND ---------------------------------------------------------------------------
110
                wait for 1 ps;
111 9 leonardoar
                REPORT "AND without carry 2(10) AND 3(11)" SEVERITY NOTE;
112
                sel <= alu_and;
113
                A <= conv_std_logic_vector(2, nBits);
114
                B <= conv_std_logic_vector(3, nBits);
115
                wait for 1 ns;  -- Wait to stabilize the response
116
                assert S = (A and B) report "Invalid AND output" severity FAILURE;
117
 
118
                -- OR ---------------------------------------------------------------------------
119
                wait for 1 ns;
120
                REPORT "OR without carry 5 OR 7" SEVERITY NOTE;
121
                sel <= alu_or;
122
                A <= conv_std_logic_vector(5, nBits);
123
                B <= conv_std_logic_vector(7, nBits);
124
                wait for 1 ns;  -- Wait to stabilize the response
125
                assert S = (A or B) report "Invalid OR output" severity FAILURE;
126
 
127
                -- XOR ---------------------------------------------------------------------------
128
                wait for 1 ns;
129
                REPORT "OR without carry 11 XOR 9" SEVERITY NOTE;
130
                sel <= alu_xor;
131
                A <= conv_std_logic_vector(11, nBits);
132
                B <= conv_std_logic_vector(9, nBits);
133
                wait for 1 ns;  -- Wait to stabilize the response
134
                assert S = (A xor B) report "Invalid XOR output" severity FAILURE;
135
 
136
                -- NOT ---------------------------------------------------------------------------
137
                wait for 1 ns;
138
                REPORT "NOT 10" SEVERITY NOTE;
139
                sel <= alu_not;
140
                A <= conv_std_logic_vector(10, nBits);
141
                B <= (others => 'X');
142
                wait for 1 ns;  -- Wait to stabilize the response
143
                assert S = (not A) report "Invalid NOT output" severity FAILURE;
144 28 leonardoar
 
145
                -- Shift left---------------------------------------------------------------------
146
                wait for 1 ns;
147
                REPORT "Shift left 2" SEVERITY NOTE;
148
                sel <= alu_shfLt;
149
                A <= conv_std_logic_vector(2, nBits);
150
                B <= (others => 'X');
151
                wait for 1 ns;  -- Wait to stabilize the response
152
                assert S = conv_std_logic_vector(4, nBits) report "Invalid shift left output expected " severity FAILURE;
153
 
154
                -- Shift right---------------------------------------------------------------------
155
                wait for 1 ns;
156
                REPORT "Shift right 4" SEVERITY NOTE;
157
                sel <= alu_shfRt;
158
                A <= conv_std_logic_vector(4, nBits);
159
                B <= (others => 'X');
160
                wait for 1 ns;  -- Wait to stabilize the response
161
                assert S = conv_std_logic_vector(2, nBits) report "Invalid shift left output expected " severity FAILURE;
162
 
163
                -- Test flag zero ------------------------------------------------------------------
164
                wait for 1 ps;
165
                REPORT "Test zero flag 10 sub 10" SEVERITY NOTE;
166
                sel <= alu_sub;
167
                A <= conv_std_logic_vector(10, nBits);
168
                B <= conv_std_logic_vector(10, nBits);
169
                wait for 1 ns;  -- Wait to stabilize the response
170
                assert flagsOut(flag_zero) = '1' report "Invalid zero flag" severity FAILURE;
171
 
172
                -- Test flag carry ------------------------------------------------------------------
173
                wait for 1 ps;
174
                REPORT "Test carry flag 4294967056 sum 4294967056" SEVERITY NOTE;
175
                sel <= alu_sum;
176
                A <= "11111111111111111111111100010000";
177
                B <= "11111111111111111111111100010000";
178
                wait for 1 ns;  -- Wait to stabilize the response
179
                assert flagsOut(flag_carry) = '1' report "Invalid carry flag" severity FAILURE;
180
 
181
                -- Test flag sign ------------------------------------------------------------------
182
                wait for 1 ps;
183
                REPORT "Test sign flag -4 sub 4" SEVERITY NOTE;
184
                sel <= alu_sub;
185
                A <= conv_std_logic_vector(-4, nBits);
186
                B <= conv_std_logic_vector(4, nBits);
187
                wait for 1 ns;  -- Wait to stabilize the response
188
                assert flagsOut(flag_sign) = '1' report "Invalid sign flag" severity FAILURE;
189
                assert S = conv_std_logic_vector(-8, nBits) report "Invalid Sub" severity FAILURE;
190 9 leonardoar
 
191 18 leonardoar
      -- Finish simulation
192
                assert false report "NONE. End of simulation." severity failure;
193 9 leonardoar
   end process;
194
 
195
END;

powered by: WebSVN 2.1.0

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