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 |
|
|
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 |
|
|
sel : in aluOps); --! Select operation
|
29 |
|
|
END COMPONENT;
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
--Inputs
|
33 |
12 |
leonardoar |
signal A : std_logic_vector((nBits - 1) downto 0) := (others => '0'); --! Wire to connect Test signal to component
|
34 |
|
|
signal B : std_logic_vector((nBits - 1) downto 0) := (others => '0'); --! Wire to connect Test signal to component
|
35 |
|
|
signal sel : aluOps := alu_sum; --! Wire to connect Test signal to component
|
36 |
9 |
leonardoar |
|
37 |
|
|
--Outputs
|
38 |
12 |
leonardoar |
signal S : std_logic_vector((nBits - 1) downto 0); --! Wire to connect Test signal to component
|
39 |
9 |
leonardoar |
|
40 |
|
|
BEGIN
|
41 |
|
|
|
42 |
12 |
leonardoar |
--! Instantiate the Unit Under Test (Alu) (Doxygen bug if it's not commented!)
|
43 |
9 |
leonardoar |
uut: Alu PORT MAP (
|
44 |
|
|
A => A,
|
45 |
|
|
B => B,
|
46 |
|
|
S => S,
|
47 |
|
|
sel => sel
|
48 |
|
|
);
|
49 |
|
|
|
50 |
|
|
--! Process that will stimulate all of the Alu operations
|
51 |
|
|
stim_proc: process
|
52 |
17 |
leonardoar |
variable mulResult : std_logic_vector(((nBits*2) - 1)downto 0);
|
53 |
9 |
leonardoar |
begin
|
54 |
16 |
leonardoar |
-- Pass ---------------------------------------------------------------------------
|
55 |
9 |
leonardoar |
wait for 1 ps;
|
56 |
16 |
leonardoar |
REPORT "Pass input A to output" SEVERITY NOTE;
|
57 |
|
|
sel <= alu_pass;
|
58 |
|
|
A <= conv_std_logic_vector(22, nBits);
|
59 |
|
|
wait for 1 ns; -- Wait to stabilize the response
|
60 |
17 |
leonardoar |
assert S = (A ) report "Invalid Pass output" severity FAILURE;
|
61 |
|
|
|
62 |
|
|
-- Sum ---------------------------------------------------------------------------
|
63 |
|
|
wait for 1 ps;
|
64 |
|
|
REPORT "Sum without carry 12 AND 13" SEVERITY NOTE;
|
65 |
|
|
sel <= alu_sum;
|
66 |
|
|
A <= conv_std_logic_vector(12, nBits);
|
67 |
|
|
B <= conv_std_logic_vector(13, nBits);
|
68 |
|
|
wait for 1 ns; -- Wait to stabilize the response
|
69 |
|
|
assert S = (A + B) report "Invalid Sum output" severity FAILURE;
|
70 |
|
|
|
71 |
|
|
-- Sub ---------------------------------------------------------------------------
|
72 |
|
|
wait for 1 ps;
|
73 |
|
|
REPORT "Sub without carry 34 AND 30" SEVERITY NOTE;
|
74 |
|
|
sel <= alu_sub;
|
75 |
|
|
A <= conv_std_logic_vector(34, nBits);
|
76 |
|
|
B <= conv_std_logic_vector(30, nBits);
|
77 |
|
|
wait for 1 ns; -- Wait to stabilize the response
|
78 |
|
|
assert S = (A - B) report "Invalid Sum Sub" severity FAILURE;
|
79 |
16 |
leonardoar |
|
80 |
17 |
leonardoar |
-- Inc ---------------------------------------------------------------------------
|
81 |
|
|
wait for 1 ps;
|
82 |
|
|
REPORT "Inc without carry 1" SEVERITY NOTE;
|
83 |
|
|
sel <= alu_inc;
|
84 |
|
|
A <= conv_std_logic_vector(1, nBits);
|
85 |
|
|
wait for 1 ns; -- Wait to stabilize the response
|
86 |
|
|
assert S = (A + 1) report "Invalid Sum Sub" severity FAILURE;
|
87 |
|
|
|
88 |
|
|
-- Dec ---------------------------------------------------------------------------
|
89 |
|
|
wait for 1 ps;
|
90 |
|
|
REPORT "Dec without carry 1" SEVERITY NOTE;
|
91 |
|
|
sel <= alu_dec;
|
92 |
|
|
A <= conv_std_logic_vector(1, nBits);
|
93 |
|
|
wait for 1 ns; -- Wait to stabilize the response
|
94 |
|
|
assert S = (A - 1) report "Invalid Sum Sub" severity FAILURE;
|
95 |
|
|
|
96 |
|
|
-- Mul ---------------------------------------------------------------------------
|
97 |
|
|
wait for 1 ps;
|
98 |
|
|
REPORT "Sub without carry 34 AND 30" SEVERITY NOTE;
|
99 |
|
|
sel <= alu_mul;
|
100 |
|
|
A <= conv_std_logic_vector(3, nBits);
|
101 |
|
|
B <= conv_std_logic_vector(5, nBits);
|
102 |
|
|
wait for 1 ns; -- Wait to stabilize the response
|
103 |
|
|
mulResult := (A * B);
|
104 |
|
|
assert S = (mulResult((nBits - 1) downto 0)) report "Invalid Sum Sub" severity FAILURE;
|
105 |
|
|
|
106 |
16 |
leonardoar |
-- AND ---------------------------------------------------------------------------
|
107 |
|
|
wait for 1 ps;
|
108 |
9 |
leonardoar |
REPORT "AND without carry 2(10) AND 3(11)" SEVERITY NOTE;
|
109 |
|
|
sel <= alu_and;
|
110 |
|
|
A <= conv_std_logic_vector(2, nBits);
|
111 |
|
|
B <= conv_std_logic_vector(3, nBits);
|
112 |
|
|
wait for 1 ns; -- Wait to stabilize the response
|
113 |
|
|
assert S = (A and B) report "Invalid AND output" severity FAILURE;
|
114 |
|
|
|
115 |
|
|
-- OR ---------------------------------------------------------------------------
|
116 |
|
|
wait for 1 ns;
|
117 |
|
|
REPORT "OR without carry 5 OR 7" SEVERITY NOTE;
|
118 |
|
|
sel <= alu_or;
|
119 |
|
|
A <= conv_std_logic_vector(5, nBits);
|
120 |
|
|
B <= conv_std_logic_vector(7, nBits);
|
121 |
|
|
wait for 1 ns; -- Wait to stabilize the response
|
122 |
|
|
assert S = (A or B) report "Invalid OR output" severity FAILURE;
|
123 |
|
|
|
124 |
|
|
-- XOR ---------------------------------------------------------------------------
|
125 |
|
|
wait for 1 ns;
|
126 |
|
|
REPORT "OR without carry 11 XOR 9" SEVERITY NOTE;
|
127 |
|
|
sel <= alu_xor;
|
128 |
|
|
A <= conv_std_logic_vector(11, nBits);
|
129 |
|
|
B <= conv_std_logic_vector(9, nBits);
|
130 |
|
|
wait for 1 ns; -- Wait to stabilize the response
|
131 |
|
|
assert S = (A xor B) report "Invalid XOR output" severity FAILURE;
|
132 |
|
|
|
133 |
|
|
-- NOT ---------------------------------------------------------------------------
|
134 |
|
|
wait for 1 ns;
|
135 |
|
|
REPORT "NOT 10" SEVERITY NOTE;
|
136 |
|
|
sel <= alu_not;
|
137 |
|
|
A <= conv_std_logic_vector(10, nBits);
|
138 |
|
|
B <= (others => 'X');
|
139 |
|
|
wait for 1 ns; -- Wait to stabilize the response
|
140 |
|
|
assert S = (not A) report "Invalid NOT output" severity FAILURE;
|
141 |
|
|
|
142 |
|
|
wait;
|
143 |
|
|
end process;
|
144 |
|
|
|
145 |
|
|
END;
|