1 |
145 |
lanttu |
-------------------------------------------------------------------------------
|
2 |
|
|
-- Title : testbench for the allmighty ctrl_regs block
|
3 |
|
|
-- Project : UDP2HIBI
|
4 |
|
|
-------------------------------------------------------------------------------
|
5 |
|
|
-- File : tb_ctrl_regs.vhd
|
6 |
|
|
-- Author : Jussi Nieminen <niemin95@galapagosinkeiju.cs.tut.fi>
|
7 |
|
|
-- Last update: 2012-03-22
|
8 |
|
|
-- Platform : Sim only
|
9 |
|
|
-------------------------------------------------------------------------------
|
10 |
|
|
-- Description: A couple of hard-coded test cases for ctrl-registers.
|
11 |
|
|
-------------------------------------------------------------------------------
|
12 |
|
|
-- Revisions :
|
13 |
|
|
-- Date Version Author Description
|
14 |
|
|
-- 2009/12/08 1.0 niemin95 Created
|
15 |
|
|
-------------------------------------------------------------------------------
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
library ieee;
|
20 |
|
|
use ieee.std_logic_1164.all;
|
21 |
|
|
use std.textio.all; -- es
|
22 |
|
|
|
23 |
|
|
use work.udp2hibi_pkg.all;
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
entity tb_ctrl_regs is
|
28 |
|
|
end tb_ctrl_regs;
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
architecture tb of tb_ctrl_regs is
|
32 |
|
|
|
33 |
|
|
constant period_c : time := 20 ns;
|
34 |
|
|
signal clk : std_logic := '1';
|
35 |
|
|
signal rst_n : std_logic := '0';
|
36 |
|
|
|
37 |
|
|
signal test_id : integer;
|
38 |
|
|
signal test_name : string(1 to 6) :=" reset";
|
39 |
|
|
|
40 |
|
|
constant hibi_addr_width_c : integer := 32;
|
41 |
|
|
constant receiver_table_size_c : integer := 2;
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
-- to hibi_receiver
|
45 |
|
|
signal release_lock_to_duv : std_logic := '0';
|
46 |
|
|
signal new_tx_conf_to_duv : std_logic := '0';
|
47 |
|
|
signal new_rx_conf_to_duv : std_logic := '0';
|
48 |
|
|
signal ip_to_duv : std_logic_vector(ip_addr_w_c-1 downto 0) := (others => '0');
|
49 |
|
|
signal dest_port_to_duv : std_logic_vector(udp_port_w_c-1 downto 0) := (others => '0');
|
50 |
|
|
signal source_port_to_duv : std_logic_vector(udp_port_w_c-1 downto 0) := (others => '0');
|
51 |
|
|
signal lock_addr_to_duv : std_logic_vector(hibi_addr_width_c-1 downto 0) := (others => '0');
|
52 |
|
|
signal response_addr_to_duv : std_logic_vector(hibi_addr_width_c-1 downto 0) := (others => '0');
|
53 |
|
|
signal lock_from_duv : std_logic;
|
54 |
|
|
signal lock_addr_from_duv : std_logic_vector(hibi_addr_width_c-1 downto 0);
|
55 |
|
|
-- to tx_ctrl
|
56 |
|
|
signal tx_ip_from_duv : std_logic_vector(ip_addr_w_c-1 downto 0);
|
57 |
|
|
signal tx_dest_port_from_duv : std_logic_vector(udp_port_w_c-1 downto 0);
|
58 |
|
|
signal tx_source_port_from_duv : std_logic_vector(udp_port_w_c-1 downto 0);
|
59 |
|
|
signal timeout_release_to_duv : std_logic := '0';
|
60 |
|
|
-- from rx_ctrl
|
61 |
|
|
signal rx_ip_to_duv : std_logic_vector(ip_addr_w_c-1 downto 0) := (others => '0');
|
62 |
|
|
signal rx_dest_port_to_duv : std_logic_vector(udp_port_w_c-1 downto 0) := (others => '0');
|
63 |
|
|
signal rx_source_port_to_duv : std_logic_vector(udp_port_w_c-1 downto 0) := (others => '0');
|
64 |
|
|
signal rx_addr_valid_from_duv : std_logic;
|
65 |
|
|
-- to hibi_transmitter
|
66 |
|
|
signal ack_addr_from_duv : std_logic_vector(hibi_addr_width_c-1 downto 0);
|
67 |
|
|
signal rx_addr_from_duv : std_logic_vector(hibi_addr_width_c-1 downto 0);
|
68 |
|
|
signal send_tx_ack_from_duv : std_logic;
|
69 |
|
|
signal send_tx_nack_from_duv : std_logic;
|
70 |
|
|
signal send_rx_ack_from_duv : std_logic;
|
71 |
|
|
signal send_rx_nack_from_duv : std_logic;
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
-- test values:
|
75 |
|
|
constant test_ip1_c : std_logic_vector(ip_addr_w_c-1 downto 0) := x"01234567";
|
76 |
|
|
constant test_ip2_c : std_logic_vector(ip_addr_w_c-1 downto 0) := x"98765432";
|
77 |
|
|
constant test_dest_port1_c : std_logic_vector(udp_port_w_c-1 downto 0) := x"0123";
|
78 |
|
|
constant test_dest_port2_c : std_logic_vector(udp_port_w_c-1 downto 0) := x"4567";
|
79 |
|
|
constant test_dest_port3_c : std_logic_vector(udp_port_w_c-1 downto 0) := x"8743";
|
80 |
|
|
constant test_source_port1_c : std_logic_vector(udp_port_w_c-1 downto 0) := x"2345";
|
81 |
|
|
constant test_source_port2_c : std_logic_vector(udp_port_w_c-1 downto 0) := x"5432";
|
82 |
|
|
constant test_lock_addr1_c : std_logic_vector(hibi_addr_width_c-1 downto 0) := x"fedcba98";
|
83 |
|
|
constant test_lock_addr2_c : std_logic_vector(hibi_addr_width_c-1 downto 0) := x"89abcdef";
|
84 |
|
|
constant test_resp_addr1_c : std_logic_vector(hibi_addr_width_c-1 downto 0) := x"1f2e3d4c";
|
85 |
|
|
constant test_resp_addr2_c : std_logic_vector(hibi_addr_width_c-1 downto 0) := x"f1e2d3c4";
|
86 |
|
|
constant test_resp_addr3_c : std_logic_vector(hibi_addr_width_c-1 downto 0) := x"12fe34dc";
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
-------------------------------------------------------------------------------
|
90 |
|
|
begin -- tb
|
91 |
|
|
-------------------------------------------------------------------------------
|
92 |
|
|
|
93 |
|
|
duv : entity work.ctrl_regs
|
94 |
|
|
generic map (
|
95 |
|
|
receiver_table_size_g => receiver_table_size_c,
|
96 |
|
|
hibi_addr_width_g => hibi_addr_width_c
|
97 |
|
|
)
|
98 |
|
|
port map (
|
99 |
|
|
clk => clk,
|
100 |
|
|
rst_n => rst_n,
|
101 |
|
|
-- from hibi_receiver
|
102 |
|
|
release_lock_in => release_lock_to_duv,
|
103 |
|
|
new_tx_conf_in => new_tx_conf_to_duv,
|
104 |
|
|
new_rx_conf_in => new_rx_conf_to_duv,
|
105 |
|
|
ip_in => ip_to_duv,
|
106 |
|
|
dest_port_in => dest_port_to_duv,
|
107 |
|
|
source_port_in => source_port_to_duv,
|
108 |
|
|
lock_addr_in => lock_addr_to_duv,
|
109 |
|
|
response_addr_in => response_addr_to_duv,
|
110 |
|
|
lock_out => lock_from_duv,
|
111 |
|
|
lock_addr_out => lock_addr_from_duv,
|
112 |
|
|
|
113 |
|
|
-- to tx_ctrl
|
114 |
|
|
tx_ip_out => tx_ip_from_duv,
|
115 |
|
|
tx_dest_port_out => tx_dest_port_from_duv,
|
116 |
|
|
tx_source_port_out => tx_source_port_from_duv,
|
117 |
|
|
timeout_release_in => timeout_release_to_duv,
|
118 |
|
|
|
119 |
|
|
-- from rx_ctrl
|
120 |
|
|
rx_ip_in => rx_ip_to_duv,
|
121 |
|
|
rx_dest_port_in => rx_dest_port_to_duv,
|
122 |
|
|
rx_source_port_in => rx_source_port_to_duv,
|
123 |
|
|
rx_addr_valid_out => rx_addr_valid_from_duv,
|
124 |
|
|
|
125 |
|
|
-- to hibi_transmitter
|
126 |
|
|
ack_addr_out => ack_addr_from_duv,
|
127 |
|
|
rx_addr_out => rx_addr_from_duv,
|
128 |
|
|
send_tx_ack_out => send_tx_ack_from_duv,
|
129 |
|
|
send_tx_nack_out => send_tx_nack_from_duv,
|
130 |
|
|
send_rx_ack_out => send_rx_ack_from_duv,
|
131 |
|
|
send_rx_nack_out => send_rx_nack_from_duv,
|
132 |
|
|
|
133 |
|
|
-- from toplevel
|
134 |
|
|
eth_link_up_in => '1'
|
135 |
|
|
);
|
136 |
|
|
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
clk <= not clk after period_c/2;
|
140 |
|
|
rst_n <= '1' after 4*period_c;
|
141 |
|
|
|
142 |
|
|
|
143 |
|
|
tester: process
|
144 |
|
|
|
145 |
|
|
begin -- process
|
146 |
|
|
|
147 |
|
|
if rst_n = '0' then
|
148 |
|
|
wait until rst_n = '1';
|
149 |
|
|
end if;
|
150 |
|
|
test_id <= 0;
|
151 |
|
|
test_name <= " alku";
|
152 |
|
|
|
153 |
|
|
wait for period_c*4;
|
154 |
|
|
|
155 |
|
|
-- start testing, cases:
|
156 |
|
|
|
157 |
|
|
-- 1. new tx conf
|
158 |
|
|
-- 2. new rx_conf
|
159 |
|
|
-- 3. new tx conf from other sender (should result in nack)
|
160 |
|
|
-- 4. new tx conf from same sender (should update tx info)
|
161 |
|
|
-- 5. release
|
162 |
|
|
-- 6. so many new rx_confs that there is finally too much (should result in
|
163 |
|
|
-- nack)
|
164 |
|
|
-- 7. change rx info, and make sure rx addr is valid
|
165 |
|
|
-- 8. new tx conf, and after that, timeout from tx_ctrl (should release lock)
|
166 |
|
|
|
167 |
|
|
---------------------------------------------------------------------------
|
168 |
|
|
|
169 |
|
|
-- 1. new tx conf
|
170 |
|
|
test_id <= test_id +1;
|
171 |
|
|
test_name <= "tx ok";
|
172 |
|
|
ip_to_duv <= test_ip1_c;
|
173 |
|
|
dest_port_to_duv <= test_dest_port1_c;
|
174 |
|
|
source_port_to_duv <= test_source_port1_c;
|
175 |
|
|
lock_addr_to_duv <= test_lock_addr1_c;
|
176 |
|
|
response_addr_to_duv <= test_resp_addr1_c;
|
177 |
|
|
new_tx_conf_to_duv <= '1';
|
178 |
|
|
|
179 |
|
|
wait for period_c;
|
180 |
|
|
-- clear inputs
|
181 |
|
|
new_tx_conf_to_duv <= '0';
|
182 |
|
|
|
183 |
|
|
-- wait until values update
|
184 |
|
|
wait for period_c;
|
185 |
|
|
|
186 |
|
|
-- check correct values
|
187 |
|
|
assert
|
188 |
|
|
lock_from_duv = '1' and
|
189 |
|
|
lock_addr_from_duv = test_lock_addr1_c and
|
190 |
|
|
tx_ip_from_duv = test_ip1_c and
|
191 |
|
|
tx_dest_port_from_duv = test_dest_port1_c and
|
192 |
|
|
tx_source_port_from_duv = test_source_port1_c
|
193 |
|
|
report "Failure in test 1: invalid tx info." severity failure;
|
194 |
|
|
assert
|
195 |
|
|
ack_addr_from_duv = test_resp_addr1_c and
|
196 |
|
|
send_tx_ack_from_duv = '1'
|
197 |
|
|
report "Failure in test 1: Ack not sent." severity failure;
|
198 |
|
|
|
199 |
|
|
wait for period_c*10;
|
200 |
|
|
|
201 |
|
|
|
202 |
|
|
---------------------------------------------------------------------------
|
203 |
|
|
-- 2. new rx_conf
|
204 |
|
|
test_id <= test_id +1;
|
205 |
|
|
test_name <= "rx ok";
|
206 |
|
|
ip_to_duv <= test_ip2_c;
|
207 |
|
|
dest_port_to_duv <= x"FFFF";
|
208 |
|
|
source_port_to_duv <= test_source_port2_c;
|
209 |
|
|
lock_addr_to_duv <= test_lock_addr2_c;
|
210 |
|
|
response_addr_to_duv <= test_resp_addr2_c;
|
211 |
|
|
new_rx_conf_to_duv <= '1';
|
212 |
|
|
|
213 |
|
|
wait for period_c;
|
214 |
|
|
-- clear inputs
|
215 |
|
|
new_rx_conf_to_duv <= '0';
|
216 |
|
|
|
217 |
|
|
-- wait until values update
|
218 |
|
|
wait for period_c;
|
219 |
|
|
|
220 |
|
|
-- check correct values
|
221 |
|
|
assert
|
222 |
|
|
ack_addr_from_duv = test_resp_addr2_c and
|
223 |
|
|
send_rx_ack_from_duv = '1'
|
224 |
|
|
report "Failure in test 2: Ack not sent." severity failure;
|
225 |
|
|
|
226 |
|
|
wait for period_c*10;
|
227 |
|
|
|
228 |
|
|
|
229 |
|
|
---------------------------------------------------------------------------
|
230 |
|
|
-- 3. new tx conf from other sender (should result in nack)
|
231 |
|
|
-- most test values set in the last stage are fine for this test too
|
232 |
|
|
test_id <= test_id +1;
|
233 |
|
|
test_name <= "txnack";
|
234 |
|
|
dest_port_to_duv <= test_dest_port2_c;
|
235 |
|
|
response_addr_to_duv <= test_resp_addr3_c;
|
236 |
|
|
new_tx_conf_to_duv <= '1';
|
237 |
|
|
wait for period_c;
|
238 |
|
|
new_tx_conf_to_duv <= '0';
|
239 |
|
|
wait for period_c;
|
240 |
|
|
|
241 |
|
|
assert
|
242 |
|
|
ack_addr_from_duv = test_resp_addr3_c and
|
243 |
|
|
send_tx_nack_from_duv = '1'
|
244 |
|
|
report "Failure in test 3: Nack not sent." severity failure;
|
245 |
|
|
|
246 |
|
|
wait for period_c*10;
|
247 |
|
|
|
248 |
|
|
|
249 |
|
|
---------------------------------------------------------------------------
|
250 |
|
|
-- 4. new tx conf from same sender (should update tx info)
|
251 |
|
|
-- again, most of the old values (values with number 2) are good
|
252 |
|
|
test_id <= test_id +1;
|
253 |
|
|
test_name <= "tx ok";
|
254 |
|
|
lock_addr_to_duv <= test_lock_addr1_c;
|
255 |
|
|
response_addr_to_duv <= test_resp_addr1_c;
|
256 |
|
|
new_tx_conf_to_duv <= '1';
|
257 |
|
|
wait for period_c;
|
258 |
|
|
new_tx_conf_to_duv <= '0';
|
259 |
|
|
wait for period_c;
|
260 |
|
|
|
261 |
|
|
assert
|
262 |
|
|
lock_from_duv = '1' and
|
263 |
|
|
lock_addr_from_duv = test_lock_addr1_c and
|
264 |
|
|
tx_ip_from_duv = test_ip2_c and
|
265 |
|
|
tx_dest_port_from_duv = test_dest_port2_c and
|
266 |
|
|
tx_source_port_from_duv = test_source_port2_c
|
267 |
|
|
report "Failure in test 4: invalid tx info." severity failure;
|
268 |
|
|
assert
|
269 |
|
|
ack_addr_from_duv = test_resp_addr1_c and
|
270 |
|
|
send_tx_ack_from_duv = '1'
|
271 |
|
|
report "Failure in test 4: Ack not sent." severity failure;
|
272 |
|
|
|
273 |
|
|
wait for period_c*10;
|
274 |
|
|
|
275 |
|
|
|
276 |
|
|
---------------------------------------------------------------------------
|
277 |
|
|
-- 5. release
|
278 |
|
|
test_id <= test_id +1;
|
279 |
|
|
test_name <= "releas";
|
280 |
|
|
release_lock_to_duv <= '1';
|
281 |
|
|
wait for period_c;
|
282 |
|
|
release_lock_to_duv <= '0';
|
283 |
|
|
wait for period_c;
|
284 |
|
|
|
285 |
|
|
assert lock_from_duv = '0' report "Failure in test 5: Lock was not removed." severity failure;
|
286 |
|
|
|
287 |
|
|
wait for period_c*10;
|
288 |
|
|
|
289 |
|
|
|
290 |
|
|
---------------------------------------------------------------------------
|
291 |
|
|
-- 6. so many new rx_confs that there is finally too much (should result in
|
292 |
|
|
-- nack)
|
293 |
|
|
-- there is one already, add two more (receiver_table_size_c should be 2)
|
294 |
|
|
test_id <= test_id +1;
|
295 |
|
|
test_name <= "rxnack";
|
296 |
|
|
ip_to_duv <= test_ip1_c;
|
297 |
|
|
dest_port_to_duv <= test_dest_port1_c;
|
298 |
|
|
source_port_to_duv <= test_source_port1_c;
|
299 |
|
|
lock_addr_to_duv <= test_lock_addr1_c;
|
300 |
|
|
response_addr_to_duv <= test_resp_addr1_c;
|
301 |
|
|
new_rx_conf_to_duv <= '1';
|
302 |
|
|
|
303 |
|
|
wait for period_c;
|
304 |
|
|
-- clear input
|
305 |
|
|
new_rx_conf_to_duv <= '0';
|
306 |
|
|
|
307 |
|
|
-- wait for a while, check the ack, and add another one
|
308 |
|
|
wait for period_c;
|
309 |
|
|
assert
|
310 |
|
|
ack_addr_from_duv = test_resp_addr1_c and
|
311 |
|
|
send_rx_ack_from_duv = '1'
|
312 |
|
|
report "Failure in test 6: Ack not sent." severity failure;
|
313 |
|
|
|
314 |
|
|
wait for period_c*3;
|
315 |
|
|
|
316 |
|
|
-- same values will do for the next conf, just change the reply addr
|
317 |
|
|
response_addr_to_duv <= test_resp_addr3_c;
|
318 |
|
|
new_rx_conf_to_duv <= '1';
|
319 |
|
|
wait for period_c;
|
320 |
|
|
new_rx_conf_to_duv <= '0';
|
321 |
|
|
wait for period_c;
|
322 |
|
|
|
323 |
|
|
assert
|
324 |
|
|
ack_addr_from_duv = test_resp_addr3_c and
|
325 |
|
|
send_rx_nack_from_duv = '1'
|
326 |
|
|
report "Failure in test 6: Nack not sent." severity failure;
|
327 |
|
|
|
328 |
|
|
wait for period_c*10;
|
329 |
|
|
|
330 |
|
|
|
331 |
|
|
---------------------------------------------------------------------------
|
332 |
|
|
-- 7. change rx info, and make sure rx addr is valid
|
333 |
|
|
-- check both entries and then a false entry
|
334 |
|
|
test_id <= test_id +1;
|
335 |
|
|
test_name <= "rx fif";
|
336 |
|
|
rx_ip_to_duv <= test_ip2_c;
|
337 |
|
|
rx_source_port_to_duv <= test_source_port2_c;
|
338 |
|
|
-- test that the joker value (x"FFFF") works by giving some random port
|
339 |
|
|
rx_dest_port_to_duv <= test_dest_port3_c;
|
340 |
|
|
wait for period_c*2;
|
341 |
|
|
|
342 |
|
|
assert
|
343 |
|
|
rx_addr_from_duv = test_resp_addr2_c and
|
344 |
|
|
rx_addr_valid_from_duv = '1'
|
345 |
|
|
report "Failure in test 7.1: Invalid address from duv." severity failure;
|
346 |
|
|
|
347 |
|
|
wait for period_c*2;
|
348 |
|
|
|
349 |
|
|
-- and the other entry:
|
350 |
|
|
rx_ip_to_duv <= test_ip1_c;
|
351 |
|
|
rx_source_port_to_duv <= test_source_port1_c;
|
352 |
|
|
rx_dest_port_to_duv <= test_dest_port1_c;
|
353 |
|
|
wait for period_c*2;
|
354 |
|
|
|
355 |
|
|
assert
|
356 |
|
|
rx_addr_from_duv = test_resp_addr1_c and
|
357 |
|
|
rx_addr_valid_from_duv = '1'
|
358 |
|
|
report "Failure in test 7.2: Ivalid address from duv." severity failure;
|
359 |
|
|
|
360 |
|
|
wait for period_c*2;
|
361 |
|
|
|
362 |
|
|
-- the false entry
|
363 |
|
|
rx_source_port_to_duv <= test_source_port2_c;
|
364 |
|
|
wait for period_c*2;
|
365 |
|
|
|
366 |
|
|
assert
|
367 |
|
|
rx_addr_valid_from_duv = '0'
|
368 |
|
|
report "Failure in test 7.3: Address should be invalid." severity failure;
|
369 |
|
|
|
370 |
|
|
|
371 |
|
|
wait for period_c*10;
|
372 |
|
|
|
373 |
|
|
|
374 |
|
|
---------------------------------------------------------------------------
|
375 |
|
|
-- 8. new tx conf, and after that, timeout from tx_ctrl (should release lock)
|
376 |
|
|
-- use whatever values there are, they don't matter
|
377 |
|
|
test_id <= test_id +1;
|
378 |
|
|
test_name <= "tx tim";
|
379 |
|
|
new_tx_conf_to_duv <= '1';
|
380 |
|
|
wait for period_c;
|
381 |
|
|
new_tx_conf_to_duv <= '0';
|
382 |
|
|
wait for period_c;
|
383 |
|
|
|
384 |
|
|
assert lock_from_duv = '1' report "Failure in test 8: Block not locked." severity failure;
|
385 |
|
|
|
386 |
|
|
wait for period_c*5;
|
387 |
|
|
-- timeout!
|
388 |
|
|
timeout_release_to_duv <= '1';
|
389 |
|
|
wait for period_c;
|
390 |
|
|
timeout_release_to_duv <= '0';
|
391 |
|
|
wait for period_c;
|
392 |
|
|
|
393 |
|
|
assert lock_from_duv = '0' report "Failure in test 8: Timeout didn't remove the lock." severity failure;
|
394 |
|
|
|
395 |
|
|
|
396 |
|
|
---------------------------------------------------------------------------
|
397 |
|
|
wait for period_c*20;
|
398 |
|
|
report "Simulation done." severity failure;
|
399 |
|
|
|
400 |
|
|
end process tester;
|
401 |
|
|
end tb;
|