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