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