--! @file
|
--! @file
|
--! @brief Testbench for Alu
|
--! @brief Testbench for Alu
|
|
|
--! Use standard library and import the packages (std_logic_1164,std_logic_unsigned,std_logic_arith)
|
--! Use standard library and import the packages (std_logic_1164,std_logic_unsigned,std_logic_arith)
|
library IEEE;
|
library IEEE;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_unsigned.all;
|
use ieee.std_logic_unsigned.all;
|
use ieee.std_logic_arith.all;
|
use ieee.std_logic_arith.all;
|
|
|
--! Use CPU Definitions package
|
--! Use CPU Definitions package
|
use work.pkgOpenCPU32.all;
|
use work.pkgOpenCPU32.all;
|
|
|
ENTITY testAlu IS
|
ENTITY testAlu IS
|
END testAlu;
|
END testAlu;
|
|
|
--! @brief Alu Testbench file
|
--! @brief Alu Testbench file
|
--! @details Exercise each Alu operation to verify if the description work as planned
|
--! @details Exercise each Alu operation to verify if the description work as planned
|
--! for more information: http://vhdlguru.blogspot.com/2010/03/how-to-write-testbench.html
|
--! for more information: http://vhdlguru.blogspot.com/2010/03/how-to-write-testbench.html
|
ARCHITECTURE behavior OF testAlu IS
|
ARCHITECTURE behavior OF testAlu IS
|
|
|
|
|
--! Component declaration to instantiate the Alu circuit
|
--! Component declaration to instantiate the Alu circuit
|
COMPONENT Alu
|
COMPONENT Alu
|
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the Alu on the package)
|
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the Alu on the package)
|
Port ( A : in STD_LOGIC_VECTOR (n downto 0); --! Alu Operand 1
|
Port ( A : in STD_LOGIC_VECTOR (n downto 0); --! Alu Operand 1
|
B : in STD_LOGIC_VECTOR (n downto 0); --! Alu Operand 2
|
B : in STD_LOGIC_VECTOR (n downto 0); --! Alu Operand 2
|
S : out STD_LOGIC_VECTOR (n downto 0); --! Alu Output
|
S : out STD_LOGIC_VECTOR (n downto 0); --! Alu Output
|
sel : in aluOps); --! Select operation
|
sel : in aluOps); --! Select operation
|
END COMPONENT;
|
END COMPONENT;
|
|
|
|
|
--Inputs
|
--Inputs
|
signal A : std_logic_vector((nBits - 1) downto 0) := (others => '0');
|
signal A : std_logic_vector((nBits - 1) downto 0) := (others => '0'); --! Wire to connect Test signal to component
|
signal B : std_logic_vector((nBits - 1) downto 0) := (others => '0');
|
signal B : std_logic_vector((nBits - 1) downto 0) := (others => '0'); --! Wire to connect Test signal to component
|
signal sel : aluOps := alu_sum;
|
signal sel : aluOps := alu_sum; --! Wire to connect Test signal to component
|
|
|
--Outputs
|
--Outputs
|
signal S : std_logic_vector((nBits - 1) downto 0);
|
signal S : std_logic_vector((nBits - 1) downto 0); --! Wire to connect Test signal to component
|
|
|
BEGIN
|
BEGIN
|
|
|
-- Instantiate the Unit Under Test (UUT)
|
--! Instantiate the Unit Under Test (Alu) (Doxygen bug if it's not commented!)
|
uut: Alu PORT MAP (
|
uut: Alu PORT MAP (
|
A => A,
|
A => A,
|
B => B,
|
B => B,
|
S => S,
|
S => S,
|
sel => sel
|
sel => sel
|
);
|
);
|
|
|
--! Process that will stimulate all of the Alu operations
|
--! Process that will stimulate all of the Alu operations
|
stim_proc: process
|
stim_proc: process
|
begin
|
begin
|
-- AND ---------------------------------------------------------------------------
|
-- AND ---------------------------------------------------------------------------
|
wait for 1 ps;
|
wait for 1 ps;
|
REPORT "AND without carry 2(10) AND 3(11)" SEVERITY NOTE;
|
REPORT "AND without carry 2(10) AND 3(11)" SEVERITY NOTE;
|
sel <= alu_and;
|
sel <= alu_and;
|
A <= conv_std_logic_vector(2, nBits);
|
A <= conv_std_logic_vector(2, nBits);
|
B <= conv_std_logic_vector(3, nBits);
|
B <= conv_std_logic_vector(3, nBits);
|
wait for 1 ns; -- Wait to stabilize the response
|
wait for 1 ns; -- Wait to stabilize the response
|
assert S = (A and B) report "Invalid AND output" severity FAILURE;
|
assert S = (A and B) report "Invalid AND output" severity FAILURE;
|
|
|
-- OR ---------------------------------------------------------------------------
|
-- OR ---------------------------------------------------------------------------
|
wait for 1 ns;
|
wait for 1 ns;
|
REPORT "OR without carry 5 OR 7" SEVERITY NOTE;
|
REPORT "OR without carry 5 OR 7" SEVERITY NOTE;
|
sel <= alu_or;
|
sel <= alu_or;
|
A <= conv_std_logic_vector(5, nBits);
|
A <= conv_std_logic_vector(5, nBits);
|
B <= conv_std_logic_vector(7, nBits);
|
B <= conv_std_logic_vector(7, nBits);
|
wait for 1 ns; -- Wait to stabilize the response
|
wait for 1 ns; -- Wait to stabilize the response
|
assert S = (A or B) report "Invalid OR output" severity FAILURE;
|
assert S = (A or B) report "Invalid OR output" severity FAILURE;
|
|
|
-- XOR ---------------------------------------------------------------------------
|
-- XOR ---------------------------------------------------------------------------
|
wait for 1 ns;
|
wait for 1 ns;
|
REPORT "OR without carry 11 XOR 9" SEVERITY NOTE;
|
REPORT "OR without carry 11 XOR 9" SEVERITY NOTE;
|
sel <= alu_xor;
|
sel <= alu_xor;
|
A <= conv_std_logic_vector(11, nBits);
|
A <= conv_std_logic_vector(11, nBits);
|
B <= conv_std_logic_vector(9, nBits);
|
B <= conv_std_logic_vector(9, nBits);
|
wait for 1 ns; -- Wait to stabilize the response
|
wait for 1 ns; -- Wait to stabilize the response
|
assert S = (A xor B) report "Invalid XOR output" severity FAILURE;
|
assert S = (A xor B) report "Invalid XOR output" severity FAILURE;
|
|
|
-- NOT ---------------------------------------------------------------------------
|
-- NOT ---------------------------------------------------------------------------
|
wait for 1 ns;
|
wait for 1 ns;
|
REPORT "NOT 10" SEVERITY NOTE;
|
REPORT "NOT 10" SEVERITY NOTE;
|
sel <= alu_not;
|
sel <= alu_not;
|
A <= conv_std_logic_vector(10, nBits);
|
A <= conv_std_logic_vector(10, nBits);
|
B <= (others => 'X');
|
B <= (others => 'X');
|
wait for 1 ns; -- Wait to stabilize the response
|
wait for 1 ns; -- Wait to stabilize the response
|
assert S = (not A) report "Invalid NOT output" severity FAILURE;
|
assert S = (not A) report "Invalid NOT output" severity FAILURE;
|
|
|
wait;
|
wait;
|
end process;
|
end process;
|
|
|
END;
|
END;
|
|
|