use work.gen_pkg.all;
entity alu_tb is
- end entity alu_tb;
+end entity alu_tb;
architecture sim of alu_tb is
component alu is
sys_clk : in std_logic;
sys_res_n : in std_logic;
opcode : in alu_ops;
- op1 : in signed(31 downto 0);
- op2 : in signed(31 downto 0);
- op3 : out signed(31 downto 0);
+ op1 : in csigned;
+ op2 : in csigned;
+ op3 : out csigned;
do_calc : in std_logic;
calc_done : out std_logic
);
end component alu;
- signal sys_clk, sys_res_n, do_calc, calc_done : std_ulogic;
+ signal sys_clk, sys_res_n, do_calc, calc_done : std_logic;
signal opcode : alu_ops;
- signal op1, op2, op3, optmp : signed(31 downto 0);
+ signal op1, op2, op3 : csigned;
signal stop : boolean := false;
begin
bla : alu
sys_clk <= '0';
wait for 15 ns;
sys_clk <= '1';
+ wait for 15 ns;
if stop = true then
wait;
end if;
- wait for 15 ns;
end process;
process
+ type alu_testv is record
+ o1 : cinteger;
+ o : alu_ops;
+ o2 : cinteger;
+ expected : cinteger;
+ end record alu_testv;
+
+ -- ggf. groesse des arrays erhoehen
+ type alu_testv_array is array (natural range 0 to 20) of alu_testv;
+
+ variable testmatrix : alu_testv_array :=
+ ( 0 => (7, ADD, 3, 10),
+ 1 => (7, SUB, 1, 6),
+ 2 => (7, DIV, 1, 7),
+ 3 => (7, DIV, 2, 3),
+ 4 => (7, ADD, 1, 8),
+ 5 => (7, MUL, 3, 21),
+ 6 => (-7, MUL, 3, -21),
+ 7 => (268435456, MUL, -2, -536870912),
+ 8 => (268435456, MUL, 2**5, 0), -- um fuenf nach links shiften
+ 9 => (268435456 + 5, MUL, 2**5, 160), -- = 5 * (2^5)
+ others => (0, ADD, 0, 0)
+ );
+
begin
sys_res_n <= '0';
- wait for 100 ns;
+ wait for 50 ns;
sys_res_n <= '1';
- wait for 200 ns;
- op1(31 downto 0) <= (0 => '1', 1 => '1', 2 => '1', others => '0');
- op2(31 downto 0) <= (0 => '1', 2 => '1', others => '0');
- opcode <= ADD;
- wait for 30ns;
- do_calc <= '1';
- wait for 300ns;
- optmp <= op3;
- wait for 400ns;
+ for i in testmatrix'range loop
+ wait for 100 ns;
+ op1 <= to_signed(testmatrix(i).o1,CBITS);
+ opcode <= testmatrix(i).o;
+ op2 <= to_signed(testmatrix(i).o2,CBITS);
+
+ -- berechnung kann los gehen
+ do_calc <= '1';
+
+ -- warten auf die alu einheit
+ wait on calc_done;
+
+ assert op3 = to_signed(testmatrix(i).expected,CBITS)
+ report "" & cinteger'image(testmatrix(i).o1) &
+ " " & alu_ops'image(opcode) &
+ " " & cinteger'image(testmatrix(i).o2) &
+ "/= " & integer'image(to_integer(op3)) &
+ " -- erwartet: " & cinteger'image(testmatrix(i).expected);
+
+ wait for 5 ns;
+ -- ack it!
+ do_calc <= '0';
+ end loop;
+ assert false
+ report "alle testfaelle der ALU waren erfolgreich!";
stop <= true;
wait;
end process;