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); last : 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;
107 variable last : std_logic_vector(7 downto 0);
112 data <= (others => '0');
120 f_loop : while not endfile(f) loop
121 data <= (others => '0');
122 realresult := (others => nul);
124 f1_loop : while not endfile(f) loop
126 input := (others => nul);
127 if (l'length <= 72) then
128 input(1 to l'length) := l.all;
129 if (input(1) = '#') then
135 report "fehler in scanner.test: eingabe zu lange in testfall " & natural'image(i);
140 f2_loop : while not endfile(f) loop
142 expectedresult := (others => nul);
143 if (l'length <= 72) then
144 expectedresult(1 to l'length) := l.all;
145 if (expectedresult(1) = '#') then
152 report "fehler in scanner.test: eingabe zu lange in testfall " & natural'image(i);
159 report "testcase(" & natural'image(i) & ").input: " & input;
160 report "testcase(" & natural'image(i) & ").expectedresult: " & expectedresult;
167 mainl : while run_tc loop
174 assert(false) report "wtf @ schleife";
187 when nul => data <= ascii2sc(x"1c"); -- $ (enter)
188 when '!' => data <= ascii2sc(x"0e"); -- ! (backspace)
189 when others => data <= ascii2sc(std_logic_vector(to_unsigned(character'pos(input(j)),8)));
194 -- ack'en skippen, falls es ein "spezielles" zeichen ist (steht
195 -- in abhaengigkeit zum vorherigen zeichen)
196 if(not valid_char(data, last)) then
200 -- wuenschswert waere das hier:
201 -- > wait on s_backspace, s_take, do_it;
202 -- geht aber leider nicht, weil sich die signale vllt schon
205 main_inner : while run_inner loop
209 if s_backspace = '1' then
211 realresult(k) := nul;
213 realresult(k) := nul;
217 wait on s_take; -- = '0'
220 elsif do_it = '1' then
221 -- dauert normalweiser noch laenger (parser braucht
225 wait on do_it; -- = '0'
230 elsif s_take = '1' then
231 realresult(k) := character'val(to_integer(unsigned(s_char)));
236 wait on s_take; -- = '0'
240 -- assert(false) report "scanner_tb: kann passieren. wenn tb haengt, dann hier auskommentieren";
246 report "realresult : " & realresult;
247 if realresult /= expectedresult then
250 report "==================";
254 report "alle testfaelle des Scanners waren erfolgreich!";
256 report "nicht alle testfaelle des Scanners waren erfolgreich!";
261 end architecture sim;