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)
27 sys_res_n => sys_res_n,
35 s_backspace => s_backspace,
53 function ascii2sc (x : hbyte) return hbyte is
57 when x"30" => y := SC_KP_0;
58 when x"31" => y := SC_KP_1;
59 when x"32" => y := SC_KP_2;
60 when x"33" => y := SC_KP_3;
61 when x"34" => y := SC_KP_4;
62 when x"35" => y := SC_KP_5;
63 when x"36" => y := SC_KP_6;
64 when x"37" => y := SC_KP_7;
65 when x"38" => y := SC_KP_8;
66 when x"39" => y := SC_KP_9;
67 when x"2b" => y := SC_KP_PLUS;
68 when x"2d" => y := SC_KP_MINUS;
69 when x"2a" => y := SC_KP_MUL;
70 when x"2f" => y := SC_KP_DIV;
71 when x"20" => y := SC_SPACE;
72 when x"1c" => y := SC_ENTER;
73 when x"0e" => y := SC_BKSP;
74 when others => y := x"41";
79 function valid_char (x : std_logic_vector(7 downto 0)) return boolean is
83 when SC_KP_0 | SC_KP_1 | SC_KP_2 | SC_KP_3 |
84 SC_KP_4 | SC_KP_5 | SC_KP_6 | SC_KP_7 |
85 SC_KP_8 | SC_KP_9 | SC_KP_PLUS |
86 SC_KP_MINUS | SC_KP_MUL |
87 SC_KP_DIV | SC_SPACE |
90 when others => y := false;
97 file f : text open read_mode is "../../src/scanner.test";
100 variable input : hstring;
101 variable expectedresult : hstring;
102 variable realresult : hstring;
104 variable checkall : boolean := true;
105 variable run_tc, run_inner : boolean := true;
106 variable i, j, k, y : natural;
111 data <= (others => '0');
119 f_loop : while not endfile(f) loop
120 data <= (others => '0');
121 realresult := (others => nul);
123 f1_loop : while not endfile(f) loop
125 input := (others => nul);
126 if (l'length <= 72) then
127 input(1 to l'length) := l.all;
128 if (input(1) = '#') then
134 report "fehler in scanner.test: eingabe zu lange in testfall " & natural'image(i);
139 f2_loop : while not endfile(f) loop
141 expectedresult := (others => nul);
142 if (l'length <= 72) then
143 expectedresult(1 to l'length) := l.all;
144 if (expectedresult(1) = '#') then
151 report "fehler in scanner.test: eingabe zu lange in testfall " & natural'image(i);
158 report "testcase(" & natural'image(i) & ").input: " & input;
159 report "testcase(" & natural'image(i) & ").expectedresult: " & expectedresult;
166 mainl : while run_tc loop
172 assert(false) report "wtf @ schleife";
179 when nul => data <= ascii2sc(x"1c"); -- $ (enter)
180 when '!' => data <= ascii2sc(x"0e"); -- ! (backspace)
188 when others => data <= ascii2sc(std_logic_vector(to_unsigned(character'pos(input(j)),8)));
193 -- ack'en skippen, falls es ein "spezielles" zeichen ist
194 if(not valid_char(data)) then
198 -- wuenschswert waere das hier:
199 -- > wait on s_backspace, s_take, do_it;
200 -- geht aber leider nicht, weil sich die signale vllt schon
203 main_inner : while run_inner loop
207 if s_backspace = '1' then
209 realresult(k) := nul;
211 realresult(k) := nul;
215 wait on s_take; -- = '0'
218 elsif do_it = '1' then
219 -- dauert normalweiser noch laenger (parser braucht
223 wait on do_it; -- = '0'
228 elsif s_take = '1' then
229 realresult(k) := character'val(to_integer(unsigned(s_char)));
234 wait on s_take; -- = '0'
238 -- assert(false) report "scanner_tb: kann passieren. wenn tb haengt, dann hier auskommentieren";
244 report "realresult : " & realresult;
245 if realresult /= expectedresult then
248 report "==================";
252 report "alle testfaelle des Scanners waren erfolgreich!";
254 report "nicht alle testfaelle des Scanners waren erfolgreich!";
259 end architecture sim;