parser: ausdruecke wie "x+y+z" koennen schon ausgewertet werden
[hwmod.git] / src / beh_parser_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 beh_parser_tb is
7 end entity beh_parser_tb;
8
9 architecture sim of beh_parser_tb is
10         -- system
11         signal sys_clk, sys_res_n : std_logic;
12         -- history
13         signal p_rw, p_rget, p_rdone, p_wtake, p_wdone, p_finished : std_logic;
14         signal p_read, p_write : hbyte;
15         signal p_spalte : hspalte;
16
17         -- alu
18         signal opcode : alu_ops;
19         signal op1, op2, op3 : csigned;
20         signal do_calc, calc_done : std_logic;
21
22         --scanner
23         signal do_it : std_logic;
24         signal finished : std_logic;
25
26         signal stop : boolean := false;
27 begin
28         inst : entity work.parser(beh)
29         port map
30         (
31                 sys_clk => sys_clk,
32                 sys_res_n => sys_res_n,
33                 p_rw => p_rw,
34                 p_spalte => p_spalte,
35                 p_rget => p_rget,
36                 p_rdone => p_rdone,
37                 p_read => p_read,
38                 p_wtake => p_wtake,
39                 p_wdone => p_wdone,
40                 p_write => p_write,
41                 p_finished => p_finished,
42                 -- ALU
43                 opcode => opcode,
44                 op1 => op1,
45                 op2 => op2,
46                 op3 => op3,
47                 do_calc => do_calc,
48                 calc_done => calc_done,
49                 -- TODO: calc_error : in std_logic;
50                 -- Scanner
51                 do_it => do_it,
52                 finished => finished
53         );
54
55         instalu : entity work.alu(beh)
56         port map
57         (
58                 sys_clk => sys_clk,
59                 sys_res_n => sys_res_n,
60                 do_calc => do_calc,
61                 calc_done => calc_done,
62                 op1 => op1,
63                 op2 => op2,
64                 op3 => op3,
65                 opcode => opcode
66         );
67
68         process
69         begin
70                 sys_clk <= '0';
71                 wait for 15 ns;
72                 sys_clk <= '1';
73                 wait for 15 ns;
74                 if stop = true then
75                         wait;
76                 end if;
77         end process;
78
79         process
80                 -- textio stuff
81                 use std.textio.all;
82                 file f : text open read_mode is "../../src/parser.test";
83                 variable l : line;
84
85                 variable input : hstring;
86                 variable expectedresult : hstring;
87                 variable realresult : hstring;
88                 variable hstrtmp : hstring;
89
90                 variable checkall : boolean := true;
91                 variable run_tc : boolean := true;
92                 variable i, j, k, y : natural;
93         begin
94                 -- init & reset
95                 sys_res_n <= '0';
96                 p_rdone <= '0';
97                 p_wdone <= '0';
98                 p_read <= (others => '0');
99                 do_it <= '0';
100
101                 icwait(sys_clk, 5);
102                 sys_res_n <= '1';
103
104                 i := 1;
105                 f_loop : while not endfile(f) loop
106                         realresult := (71 => character'val(0), others => character'val(32));
107
108                         f1_loop : while not endfile(f) loop
109                                 readline (f, l);
110                                 input := (others => character'val(0));
111                                 if (l'length <= 72) then
112                                         input(1 to l'length) := l.all;
113                                         if (input(1) = '#') then
114                                                 next f1_loop;
115                                         else
116                                                 exit f1_loop;
117                                         end if;
118                                 else
119                                         report "fehler in parser.test: eingabe zu lange in testfall " & natural'image(i);
120                                         next f_loop;
121                                 end if;
122                         end loop f1_loop;
123
124                         f2_loop : while not endfile(f) loop
125                                 readline (f, l);
126                                 expectedresult := (others => character'val(0));
127                                 if (l'length <= 72) then
128                                         expectedresult(1 to l'length) := l.all;
129                                         if (expectedresult(1) = '#') then
130                                                 next f2_loop;
131                                         else
132                                                 y := l'length;
133                                                 exit f2_loop;
134                                         end if;
135                                 else
136                                         report "fehler in parser.test: eingabe zu lange in testfall " & natural'image(i);
137                                         next f_loop;
138                                 end if;
139                         end loop f2_loop;
140
141                         -- ergebnis string richtig formatieren
142                         hstrtmp := expectedresult;
143                         expectedresult := (71 => character'val(0), others => character'val(32));
144                         for x in 1 to 70 loop
145                                 if hstrtmp(x) /= character'val(0) then
146                                         expectedresult((70-y) + x) := hstrtmp(x);
147                                 end if;
148                         end loop;
149
150
151                         report "testcase(" & natural'image(i) & ").input: " & input;
152                         report "testcase(" & natural'image(i) & ").expectedresult: " & expectedresult;
153                         i := i + 1;
154
155                         icwait(sys_clk, 5);
156                         do_it <= '1';
157                         run_tc := true;
158                         j := 1; k := 70;
159
160                         while run_tc loop
161                                 wait on p_rget, p_wtake, p_finished, finished;
162                                 icwait(sys_clk, 2);
163
164                                 if p_rget = '1' then
165                                         p_read <= hbyte( to_unsigned(character'pos(input(j)),8) );
166                                         p_rdone <= '1';
167                                         j := j + 1;
168                                 end if;
169                                 if p_rget = '0' then
170                                         p_rdone <= '0';
171                                 end if;
172
173                                 if p_wtake = '1' then
174                                         realresult(k) := character'val(to_integer(unsigned(p_write)));
175                                         p_wdone <= '1';
176                                         k := k - 1;
177                                 end if;
178                                 if p_wtake = '0' then
179                                         p_wdone <= '0';
180                                 end if;
181
182                                 if p_finished = '1' or finished = '1' then
183                                         run_tc := false;
184                                 end if;
185                         end loop;
186                         
187                         do_it <= '0';
188                         report "realresult                : " & realresult;
189                         if realresult /= expectedresult then
190                                 checkall := false;
191                         end if;
192                         report "==================";
193                 end loop f_loop;
194
195                 if checkall then
196                         report "alle testfaelle des Parser waren erfolgreich!";
197                 else
198                         report "nicht alle testfaelle des Parsers waren erfolgreich!";
199                 end if;
200                 stop <= true;
201                 wait;
202         end process;
203 end architecture sim;