parser: erste gehversuche. im moment wird die eingabe einfach zurueckgegeben zur...
[hwmod.git] / src / post_alu_tb.vhd
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
4 use work.gen_pkg.all;
5
6 entity post_alu_tb is
7 end entity post_alu_tb;
8
9 architecture sim of post_alu_tb is
10         -- TODO: braucht man hier wirklich eine andere entity definition?
11         component alu is
12                 port
13                 (
14                         sys_clk : in std_logic;
15                         sys_res_n : in std_logic;
16                         opcode : in alu_ops;
17                         op1 : in std_logic_vector(31 downto 0);
18                         op2 : in std_logic_vector(31 downto 0);
19                         op3 : out std_logic_vector(31 downto 0);
20                         do_calc : in std_logic;
21                         calc_done : out std_logic
22                 );
23         end component alu;
24
25         signal sys_clk, sys_res_n, do_calc, calc_done : std_logic;
26         signal opcode : alu_ops;
27         signal op1, op2, op3 : std_logic_vector(31 downto 0);
28         signal stop : boolean := false;
29 begin
30         inst : alu
31         port map
32         (
33                 sys_clk => sys_clk,
34                 sys_res_n => sys_res_n,
35                 do_calc => do_calc,
36                 calc_done => calc_done,
37                 op1 => op1,
38                 op2 => op2,
39                 op3 => op3,
40                 opcode => opcode
41         );
42
43         process
44         begin
45                 sys_clk <= '0';
46                 wait for 15 ns;
47                 sys_clk <= '1';
48                 wait for 15 ns;
49                 if stop = true then
50                         wait;
51                 end if;
52         end process;
53
54         process
55                 type alu_testv is record
56                         o1 : cinteger;
57                         o : alu_ops;
58                         o2 : cinteger;
59                         expected : cinteger;
60                 end record alu_testv;
61
62                 -- ggf. groesse des arrays erhoehen
63                 type alu_testv_array is array (natural range 0 to 20) of alu_testv;
64
65                 variable testmatrix : alu_testv_array :=
66                         ( 0 => (-5, ALU_DIV, 3, -1),
67                           1 => (7, ALU_ADD, 3, 10),
68                           2 => (7, ALU_SUB, 1, 6),
69                           3 => (7, ALU_DIV, 1, 7),
70                           4 => (7, ALU_DIV, 3, 2),
71                           5 => (7, ALU_ADD, 1, 8),
72                           6 => (7, ALU_MUL, 3, 21),
73                           7 => (-7, ALU_MUL, 3, -21),
74                           8 => (268435456, ALU_MUL, -2, -536870912),
75                           9 => (268435456, ALU_MUL, 2**5, 0), -- um fuenf nach links shiften
76                           10 => (268435456 + 5, ALU_MUL, 2**5, 160), -- = 5 * (2^5)
77                           11 => (100, ALU_DIV, 10, 10),
78                           12 => (100, ALU_DIV, 51, 1),
79                           13 => (100, ALU_DIV, 49, 2),
80                           14 => (153156, ALU_DIV, 3543, 43),
81                           15 => (-153156, ALU_DIV, 3543, -43),
82                           16 => (153156, ALU_DIV, -3543, -43),
83                           17 => (-153156, ALU_DIV, -3543, 43),
84                           others => (0, ALU_ADD, 0, 0)
85                         );
86                 variable checkall : boolean := true;
87         begin
88                 -- init & reset
89                 sys_res_n <= '0';
90                 do_calc <= '0';
91                 opcode <= ALU_NOP;
92                 op1 <= (others => '0');
93                 op2 <= (others => '0');
94
95                 icwait(sys_clk, 30);
96                 sys_res_n <= '1';
97
98                 for i in testmatrix'range loop
99                         icwait(sys_clk, 10);
100                         op1 <= std_logic_vector(to_signed(testmatrix(i).o1,CBITS));
101                         opcode <= testmatrix(i).o;
102                         op2 <= std_logic_vector(to_signed(testmatrix(i).o2,CBITS));
103
104                         -- berechnung kann los gehen
105                         do_calc <= '1';
106
107                         -- warten auf die alu einheit
108                         wait on calc_done;
109                         icwait(sys_clk, 1);
110
111                         assert op3 = std_logic_vector(to_signed(testmatrix(i).expected,CBITS))
112                                 report "" & cinteger'image(testmatrix(i).o1) & 
113                                 " " & integer'image(to_integer(signed(opcode))) &
114                                 " " & cinteger'image(testmatrix(i).o2) &
115                                 "/= " & integer'image(to_integer(signed(op3))) &
116                                 " -- erwartet: " & cinteger'image(testmatrix(i).expected);
117                         if op3 /= std_logic_vector(to_signed(testmatrix(i).expected,CBITS)) then
118                                 checkall := false;
119                         end if;
120
121                         icwait(sys_clk, 2);
122                         -- ack it!
123                         do_calc <= '0';
124                 end loop;
125
126                 if checkall then
127                         report "alle testfaelle der ALU waren erfolgreich!";
128                 else
129                         report "nicht alle testfaelle der ALU waren erfolgreich!";
130                 end if;
131                 stop <= true;
132                 wait;
133         end process;
134 end architecture sim;