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