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