2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
6 entity beh_scanner_tb is
7 end entity beh_scanner_tb;
9 architecture sim of beh_scanner_tb is
11 signal sys_clk, sys_res_n : std_logic;
13 signal new_data : std_logic;
14 signal data : std_logic_vector(7 downto 0);
16 signal s_char : hbyte;
17 signal s_take, s_done, s_backspace : std_logic;
19 signal do_it : std_logic;
20 signal finished : std_logic;
22 signal stop : boolean := false;
24 inst : entity work.scanner(beh)
28 sys_res_n => sys_res_n,
36 s_backspace => s_backspace,
54 function valid_char (x : std_logic_vector(7 downto 0); last : std_logic_vector(7 downto 0)) return boolean is
58 -- nur gueltig wenn davor ein numpad-mod byte gekommen ist
60 when x"30" | x"31" | x"32" | x"33" | x"34" => y := last = x"e0";
62 when x"35" | x"36" | x"37" | x"38" | x"39" => y := last = x"e0";
64 when x"2a" | x"2b" | x"2d" | x"2f" => y := last = x"e0";
67 when x"20" => y := true; -- ' '
68 when x"1c" => y := true; -- enter
69 when x"0e" => y := true; -- backspace
71 -- alle anderen zeichen sind immer ungueltig
72 when others => y := false;
74 -- assert(false) report "x: " & integer'image(to_integer(unsigned(x))) & ", last: " & integer'image(to_integer(unsigned(last))) & ", result: " & boolean'image(y);
80 file f : text open read_mode is "../../src/scanner.test";
83 variable input : hstring;
84 variable expectedresult : hstring;
85 variable realresult : hstring;
87 variable checkall : boolean := true;
88 variable run_tc, run_inner : boolean := true;
89 variable i, j, k, y : natural;
90 variable last : std_logic_vector(7 downto 0);
95 data <= (others => '0');
103 f_loop : while not endfile(f) loop
104 data <= (others => '0');
105 realresult := (others => nul);
107 f1_loop : while not endfile(f) loop
109 input := (others => nul);
110 if (l'length <= 71) then
111 input(1 to l'length) := l.all;
112 if (input(1) = '#') then
118 report "fehler in scanner.test: eingabe zu lange in testfall " & natural'image(i);
123 f2_loop : while not endfile(f) loop
125 expectedresult := (others => nul);
126 if (l'length <= 71) then
127 expectedresult(1 to l'length) := l.all;
128 if (expectedresult(1) = '#') then
135 report "fehler in scanner.test: eingabe zu lange in testfall " & natural'image(i);
142 report "testcase(" & natural'image(i) & ").input: " & input;
143 report "testcase(" & natural'image(i) & ").expectedresult: " & expectedresult;
150 mainl : while run_tc loop
157 when '$' => data <= x"1c"; -- $ (enter)
158 when '!' => data <= x"0e"; -- ! (backspace)
159 when '.' => data <= x"e0"; -- . (modifier fuer Numpad)
160 when others => data <= std_logic_vector(to_unsigned(character'pos(input(j)),8));
165 -- ack'en skippen, falls es ein "spezielles" zeichen ist (steht
166 -- in abhaengigkeit zum vorherigen zeichen)
167 if(not valid_char(data, last)) then
171 -- wuenschswert waere das hier:
172 -- > wait on s_backspace, s_take, do_it;
173 -- geht aber leider nicht, weil sich die signale vllt schon
176 main_inner : while run_inner loop
180 if s_backspace = '1' then
182 realresult(k) := nul;
184 realresult(k) := nul;
188 wait on s_take; -- = '0'
191 elsif do_it = '1' then
192 -- dauert normalweiser noch laenger (parser braucht
196 wait on do_it; -- = '0'
201 elsif s_take = '1' then
202 realresult(k) := character'val(to_integer(unsigned(s_char)));
207 wait on s_take; -- = '0'
211 -- assert(false) report "scanner_tb: kann passieren. wenn tb haengt, dann hier auskommentieren";
217 report "realresult : " & realresult;
218 if realresult /= expectedresult then
221 report "==================";
225 report "alle testfaelle des Scanners waren erfolgreich!";
227 report "nicht alle testfaelle des Scanners waren erfolgreich!";
232 end architecture sim;