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 |
|
|
begin
|
53 |
16 |
leonardoar |
-- Pass ---------------------------------------------------------------------------
|
54 |
9 |
leonardoar |
wait for 1 ps;
|
55 |
16 |
leonardoar |
REPORT "Pass input A to output" SEVERITY NOTE;
|
56 |
|
|
sel <= alu_pass;
|
57 |
|
|
A <= conv_std_logic_vector(22, nBits);
|
58 |
|
|
wait for 1 ns; -- Wait to stabilize the response
|
59 |
|
|
assert S = (A ) report "Invalid Pass output" severity FAILURE;
|
60 |
|
|
|
61 |
|
|
-- AND ---------------------------------------------------------------------------
|
62 |
|
|
wait for 1 ps;
|
63 |
9 |
leonardoar |
REPORT "AND without carry 2(10) AND 3(11)" SEVERITY NOTE;
|
64 |
|
|
sel <= alu_and;
|
65 |
|
|
A <= conv_std_logic_vector(2, nBits);
|
66 |
|
|
B <= conv_std_logic_vector(3, nBits);
|
67 |
|
|
wait for 1 ns; -- Wait to stabilize the response
|
68 |
|
|
assert S = (A and B) report "Invalid AND output" severity FAILURE;
|
69 |
|
|
|
70 |
|
|
-- OR ---------------------------------------------------------------------------
|
71 |
|
|
wait for 1 ns;
|
72 |
|
|
REPORT "OR without carry 5 OR 7" SEVERITY NOTE;
|
73 |
|
|
sel <= alu_or;
|
74 |
|
|
A <= conv_std_logic_vector(5, nBits);
|
75 |
|
|
B <= conv_std_logic_vector(7, nBits);
|
76 |
|
|
wait for 1 ns; -- Wait to stabilize the response
|
77 |
|
|
assert S = (A or B) report "Invalid OR output" severity FAILURE;
|
78 |
|
|
|
79 |
|
|
-- XOR ---------------------------------------------------------------------------
|
80 |
|
|
wait for 1 ns;
|
81 |
|
|
REPORT "OR without carry 11 XOR 9" SEVERITY NOTE;
|
82 |
|
|
sel <= alu_xor;
|
83 |
|
|
A <= conv_std_logic_vector(11, nBits);
|
84 |
|
|
B <= conv_std_logic_vector(9, nBits);
|
85 |
|
|
wait for 1 ns; -- Wait to stabilize the response
|
86 |
|
|
assert S = (A xor B) report "Invalid XOR output" severity FAILURE;
|
87 |
|
|
|
88 |
|
|
-- NOT ---------------------------------------------------------------------------
|
89 |
|
|
wait for 1 ns;
|
90 |
|
|
REPORT "NOT 10" SEVERITY NOTE;
|
91 |
|
|
sel <= alu_not;
|
92 |
|
|
A <= conv_std_logic_vector(10, nBits);
|
93 |
|
|
B <= (others => 'X');
|
94 |
|
|
wait for 1 ns; -- Wait to stabilize the response
|
95 |
|
|
assert S = (not A) report "Invalid NOT output" severity FAILURE;
|
96 |
|
|
|
97 |
|
|
wait;
|
98 |
|
|
end process;
|
99 |
|
|
|
100 |
|
|
END;
|