--! @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
|
flagsOut : out STD_LOGIC_VECTOR(2 downto 0); --! Flags from current operation
|
|
sel : in aluOps); --! Select operation --! Select operation
|
END COMPONENT;
|
END COMPONENT;
|
|
|
|
|
--Inputs
|
--Inputs
|
signal A : std_logic_vector((nBits - 1) downto 0) := (others => '0'); --! Wire to connect Test signal to component
|
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'); --! Wire to connect Test signal to component
|
signal B : std_logic_vector((nBits - 1) downto 0) := (others => '0'); --! Wire to connect Test signal to component
|
signal sel : aluOps := alu_sum; --! Wire to connect Test signal to component
|
signal sel : aluOps := alu_sum; --! Wire to connect Test signal to component
|
|
|
--Outputs
|
--Outputs
|
signal S : std_logic_vector((nBits - 1) downto 0); --! Wire to connect Test signal to component
|
signal S : std_logic_vector((nBits - 1) downto 0); --! Wire to connect Test signal to component
|
|
signal flagsOut : std_logic_vector(2 downto 0); --! Wire to connect Test signal to component
|
|
|
BEGIN
|
BEGIN
|
|
|
--! Instantiate the Unit Under Test (Alu) (Doxygen bug if it's not commented!)
|
--! 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,
|
|
flagsOut => flagsOut,
|
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
|
variable mulResult : std_logic_vector(((nBits*2) - 1)downto 0);
|
variable mulResult : std_logic_vector(((nBits*2) - 1)downto 0);
|
begin
|
begin
|
-- Pass ---------------------------------------------------------------------------
|
-- Pass ---------------------------------------------------------------------------
|
wait for 1 ps;
|
wait for 1 ps;
|
REPORT "Pass input A to output" SEVERITY NOTE;
|
REPORT "Pass input A to output" SEVERITY NOTE;
|
sel <= alu_pass;
|
sel <= alu_pass;
|
A <= conv_std_logic_vector(22, nBits);
|
A <= conv_std_logic_vector(22, nBits);
|
wait for 1 ns; -- Wait to stabilize the response
|
wait for 1 ns; -- Wait to stabilize the response
|
assert S = (A ) report "Invalid Pass output" severity FAILURE;
|
assert S = (A ) report "Invalid Pass output" severity FAILURE;
|
|
|
-- Sum ---------------------------------------------------------------------------
|
-- Sum ---------------------------------------------------------------------------
|
wait for 1 ps;
|
wait for 1 ps;
|
REPORT "Sum without carry 12 AND 13" SEVERITY NOTE;
|
REPORT "Sum without carry 12 AND 13" SEVERITY NOTE;
|
sel <= alu_sum;
|
sel <= alu_sum;
|
A <= conv_std_logic_vector(12, nBits);
|
A <= conv_std_logic_vector(12, nBits);
|
B <= conv_std_logic_vector(13, nBits);
|
B <= conv_std_logic_vector(13, nBits);
|
wait for 1 ns; -- Wait to stabilize the response
|
wait for 1 ns; -- Wait to stabilize the response
|
assert S = (A + B) report "Invalid Sum output" severity FAILURE;
|
assert S = (A + B) report "Invalid Sum output" severity FAILURE;
|
|
|
-- Sub ---------------------------------------------------------------------------
|
-- Sub ---------------------------------------------------------------------------
|
wait for 1 ps;
|
wait for 1 ps;
|
REPORT "Sub without carry 34 AND 30" SEVERITY NOTE;
|
REPORT "Sub without carry 34 AND 30" SEVERITY NOTE;
|
sel <= alu_sub;
|
sel <= alu_sub;
|
A <= conv_std_logic_vector(34, nBits);
|
A <= conv_std_logic_vector(34, nBits);
|
B <= conv_std_logic_vector(30, nBits);
|
B <= conv_std_logic_vector(30, nBits);
|
wait for 1 ns; -- Wait to stabilize the response
|
wait for 1 ns; -- Wait to stabilize the response
|
assert S = (A - B) report "Invalid Sum Sub" severity FAILURE;
|
assert S = (A - B) report "Invalid Sum Sub" severity FAILURE;
|
|
|
-- Inc ---------------------------------------------------------------------------
|
-- Inc ---------------------------------------------------------------------------
|
wait for 1 ps;
|
wait for 1 ps;
|
REPORT "Inc without carry 1" SEVERITY NOTE;
|
REPORT "Inc without carry 1" SEVERITY NOTE;
|
sel <= alu_inc;
|
sel <= alu_inc;
|
A <= conv_std_logic_vector(1, nBits);
|
A <= conv_std_logic_vector(1, nBits);
|
wait for 1 ns; -- Wait to stabilize the response
|
wait for 1 ns; -- Wait to stabilize the response
|
assert S = (A + 1) report "Invalid Sum Sub" severity FAILURE;
|
assert S = (A + 1) report "Invalid Sum Sub" severity FAILURE;
|
|
|
-- Dec ---------------------------------------------------------------------------
|
-- Dec ---------------------------------------------------------------------------
|
wait for 1 ps;
|
wait for 1 ps;
|
REPORT "Dec without carry 1" SEVERITY NOTE;
|
REPORT "Dec without carry 1" SEVERITY NOTE;
|
sel <= alu_dec;
|
sel <= alu_dec;
|
A <= conv_std_logic_vector(1, nBits);
|
A <= conv_std_logic_vector(1, nBits);
|
wait for 1 ns; -- Wait to stabilize the response
|
wait for 1 ns; -- Wait to stabilize the response
|
assert S = (A - 1) report "Invalid Sum Sub" severity FAILURE;
|
assert S = (A - 1) report "Invalid Sum Sub" severity FAILURE;
|
|
|
-- Mul ---------------------------------------------------------------------------
|
-- Mul ---------------------------------------------------------------------------
|
wait for 1 ps;
|
wait for 1 ps;
|
REPORT "Sub without carry 34 AND 30" SEVERITY NOTE;
|
REPORT "Sub without carry 34 AND 30" SEVERITY NOTE;
|
sel <= alu_mul;
|
sel <= alu_mul;
|
A <= conv_std_logic_vector(3, nBits);
|
A <= conv_std_logic_vector(3, nBits);
|
B <= conv_std_logic_vector(5, nBits);
|
B <= conv_std_logic_vector(5, nBits);
|
wait for 1 ns; -- Wait to stabilize the response
|
wait for 1 ns; -- Wait to stabilize the response
|
mulResult := (A * B);
|
mulResult := (A * B);
|
assert S = (mulResult((nBits - 1) downto 0)) report "Invalid Sum Sub" severity FAILURE;
|
assert S = (mulResult((nBits - 1) downto 0)) report "Invalid Sum Sub" severity FAILURE;
|
|
|
-- 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;
|
|
|
|
-- Shift left---------------------------------------------------------------------
|
|
wait for 1 ns;
|
|
REPORT "Shift left 2" SEVERITY NOTE;
|
|
sel <= alu_shfLt;
|
|
A <= conv_std_logic_vector(2, nBits);
|
|
B <= (others => 'X');
|
|
wait for 1 ns; -- Wait to stabilize the response
|
|
assert S = conv_std_logic_vector(4, nBits) report "Invalid shift left output expected " severity FAILURE;
|
|
|
|
-- Shift right---------------------------------------------------------------------
|
|
wait for 1 ns;
|
|
REPORT "Shift right 4" SEVERITY NOTE;
|
|
sel <= alu_shfRt;
|
|
A <= conv_std_logic_vector(4, nBits);
|
|
B <= (others => 'X');
|
|
wait for 1 ns; -- Wait to stabilize the response
|
|
assert S = conv_std_logic_vector(2, nBits) report "Invalid shift left output expected " severity FAILURE;
|
|
|
|
-- Test flag zero ------------------------------------------------------------------
|
|
wait for 1 ps;
|
|
REPORT "Test zero flag 10 sub 10" SEVERITY NOTE;
|
|
sel <= alu_sub;
|
|
A <= conv_std_logic_vector(10, nBits);
|
|
B <= conv_std_logic_vector(10, nBits);
|
|
wait for 1 ns; -- Wait to stabilize the response
|
|
assert flagsOut(flag_zero) = '1' report "Invalid zero flag" severity FAILURE;
|
|
|
|
-- Test flag carry ------------------------------------------------------------------
|
|
wait for 1 ps;
|
|
REPORT "Test carry flag 4294967056 sum 4294967056" SEVERITY NOTE;
|
|
sel <= alu_sum;
|
|
A <= "11111111111111111111111100010000";
|
|
B <= "11111111111111111111111100010000";
|
|
wait for 1 ns; -- Wait to stabilize the response
|
|
assert flagsOut(flag_carry) = '1' report "Invalid carry flag" severity FAILURE;
|
|
|
|
-- Test flag sign ------------------------------------------------------------------
|
|
wait for 1 ps;
|
|
REPORT "Test sign flag -4 sub 4" SEVERITY NOTE;
|
|
sel <= alu_sub;
|
|
A <= conv_std_logic_vector(-4, nBits);
|
|
B <= conv_std_logic_vector(4, nBits);
|
|
wait for 1 ns; -- Wait to stabilize the response
|
|
assert flagsOut(flag_sign) = '1' report "Invalid sign flag" severity FAILURE;
|
|
assert S = conv_std_logic_vector(-8, nBits) report "Invalid Sub" severity FAILURE;
|
|
|
-- Finish simulation
|
-- Finish simulation
|
assert false report "NONE. End of simulation." severity failure;
|
assert false report "NONE. End of simulation." severity failure;
|
end process;
|
end process;
|
|
|
END;
|
END;
|
|
|