Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2015 Intel Corporation
3 : : */
4 : : #include "test.h"
5 : : #include <string.h>
6 : :
7 : : #include <inttypes.h>
8 : : #include <stdbool.h>
9 : : #include <stdio.h>
10 : : #include <stdlib.h>
11 : :
12 : : #include <rte_eth_ring.h>
13 : : #include <rte_ethdev.h>
14 : : #include <rte_bus_vdev.h>
15 : :
16 : : #define SOCKET0 0
17 : : #define RING_SIZE 256
18 : : #define NUM_RINGS 2
19 : : #define NB_MBUF 512
20 : :
21 : : static struct rte_mempool *mp;
22 : : struct rte_ring *rxtx[NUM_RINGS];
23 : : static int tx_porta, rx_portb, rxtx_portc, rxtx_portd, rxtx_porte;
24 : :
25 : : static int
26 : 3 : test_ethdev_configure_port(int port)
27 : : {
28 : : struct rte_eth_conf null_conf;
29 : : struct rte_eth_link link;
30 : : int ret;
31 : :
32 : : memset(&null_conf, 0, sizeof(struct rte_eth_conf));
33 : :
34 [ - + ]: 3 : if (rte_eth_dev_configure(port, 1, 2, &null_conf) < 0) {
35 : : printf("Configure failed for port %d\n", port);
36 : 0 : return -1;
37 : : }
38 : :
39 : : /* Test queue release */
40 [ - + ]: 3 : if (rte_eth_dev_configure(port, 1, 1, &null_conf) < 0) {
41 : : printf("Configure failed for port %d\n", port);
42 : 0 : return -1;
43 : : }
44 : :
45 [ - + ]: 3 : if (rte_eth_tx_queue_setup(port, 0, RING_SIZE, SOCKET0, NULL) < 0) {
46 : : printf("TX queue setup failed port %d\n", port);
47 : 0 : return -1;
48 : : }
49 : :
50 [ - + ]: 3 : if (rte_eth_rx_queue_setup(port, 0, RING_SIZE, SOCKET0,
51 : : NULL, mp) < 0) {
52 : : printf("RX queue setup failed port %d\n", port);
53 : 0 : return -1;
54 : : }
55 : :
56 [ - + ]: 3 : if (rte_eth_dev_start(port) < 0) {
57 : : printf("Error starting port %d\n", port);
58 : 0 : return -1;
59 : : }
60 : :
61 : 3 : ret = rte_eth_link_get(port, &link);
62 [ - + ]: 3 : if (ret < 0) {
63 : 0 : printf("Link get failed for port %u: %s",
64 : : port, rte_strerror(-ret));
65 : 0 : return -1;
66 : : }
67 : :
68 : : return 0;
69 : : }
70 : :
71 : : static int
72 : 1 : test_send_basic_packets(void)
73 : : {
74 : : struct rte_mbuf bufs[RING_SIZE];
75 : : struct rte_mbuf *pbufs[RING_SIZE];
76 : : int i;
77 : :
78 : : printf("Testing send and receive RING_SIZE/2 packets (tx_porta -> rx_portb)\n");
79 : :
80 [ + + ]: 129 : for (i = 0; i < RING_SIZE/2; i++)
81 : 128 : pbufs[i] = &bufs[i];
82 : :
83 [ - + ]: 1 : if (rte_eth_tx_burst(tx_porta, 0, pbufs, RING_SIZE/2) < RING_SIZE/2) {
84 : 0 : printf("Failed to transmit packet burst port %d\n", tx_porta);
85 : 0 : return TEST_FAILED;
86 : : }
87 : :
88 [ - + ]: 1 : if (rte_eth_rx_burst(rx_portb, 0, pbufs, RING_SIZE) != RING_SIZE/2) {
89 : 0 : printf("Failed to receive packet burst on port %d\n", rx_portb);
90 : 0 : return TEST_FAILED;
91 : : }
92 : :
93 [ + + ]: 129 : for (i = 0; i < RING_SIZE/2; i++)
94 [ - + ]: 128 : if (pbufs[i] != &bufs[i]) {
95 : : printf("Error: received data does not match that transmitted\n");
96 : 0 : return TEST_FAILED;
97 : : }
98 : :
99 : : return TEST_SUCCESS;
100 : : }
101 : :
102 : : static int
103 : 0 : test_send_basic_packets_port(int port)
104 : : {
105 : : struct rte_mbuf bufs[RING_SIZE];
106 : : struct rte_mbuf *pbufs[RING_SIZE];
107 : : int i;
108 : :
109 : : printf("Testing send and receive RING_SIZE/2 packets (cmdl_port0 -> cmdl_port0)\n");
110 : :
111 [ # # ]: 0 : for (i = 0; i < RING_SIZE/2; i++)
112 : 0 : pbufs[i] = &bufs[i];
113 : :
114 [ # # ]: 0 : if (rte_eth_tx_burst(port, 0, pbufs, RING_SIZE/2) < RING_SIZE/2) {
115 : : printf("Failed to transmit packet burst port %d\n", port);
116 : 0 : return -1;
117 : : }
118 : :
119 [ # # ]: 0 : if (rte_eth_rx_burst(port, 0, pbufs, RING_SIZE) != RING_SIZE/2) {
120 : : printf("Failed to receive packet burst on port %d\n", port);
121 : 0 : return -1;
122 : : }
123 : :
124 [ # # ]: 0 : for (i = 0; i < RING_SIZE/2; i++)
125 [ # # ]: 0 : if (pbufs[i] != &bufs[i]) {
126 : : printf("Error: received data does not match that transmitted\n");
127 : 0 : return -1;
128 : : }
129 : :
130 : : return 0;
131 : : }
132 : :
133 : :
134 : : static int
135 : 1 : test_get_stats(int port)
136 : : {
137 : : struct rte_eth_stats stats;
138 : 1 : struct rte_mbuf buf, *pbuf = &buf;
139 : :
140 : : printf("Testing ring PMD stats_get port %d\n", port);
141 : :
142 : : /* check stats of RXTX port, should all be zero */
143 : :
144 : 1 : rte_eth_stats_get(port, &stats);
145 [ + - + - ]: 1 : if (stats.ipackets != 0 || stats.opackets != 0 ||
146 [ + - + - ]: 1 : stats.ibytes != 0 || stats.obytes != 0 ||
147 [ + - - + ]: 1 : stats.ierrors != 0 || stats.oerrors != 0) {
148 : : printf("Error: port %d stats are not zero\n", port);
149 : 0 : return -1;
150 : : }
151 : :
152 : : /* send and receive 1 packet and check for stats update */
153 [ - + ]: 1 : if (rte_eth_tx_burst(port, 0, &pbuf, 1) != 1) {
154 : : printf("Error sending packet to port %d\n", port);
155 : 0 : return -1;
156 : : }
157 : :
158 [ - + ]: 1 : if (rte_eth_rx_burst(port, 0, &pbuf, 1) != 1) {
159 : : printf("Error receiving packet from port %d\n", port);
160 : 0 : return -1;
161 : : }
162 : :
163 : 1 : rte_eth_stats_get(port, &stats);
164 [ + - + - ]: 1 : if (stats.ipackets != 1 || stats.opackets != 1 ||
165 [ + - + - ]: 1 : stats.ibytes != 0 || stats.obytes != 0 ||
166 [ + - - + ]: 1 : stats.ierrors != 0 || stats.oerrors != 0) {
167 : : printf("Error: port %d stats are not as expected\n", port);
168 : 0 : return -1;
169 : : }
170 : : return 0;
171 : : }
172 : :
173 : : static int
174 : 1 : test_stats_reset(int port)
175 : : {
176 : : struct rte_eth_stats stats;
177 : 1 : struct rte_mbuf buf, *pbuf = &buf;
178 : :
179 : : printf("Testing ring PMD stats_reset port %d\n", port);
180 : :
181 : 1 : rte_eth_stats_reset(port);
182 : :
183 : : /* check stats of RXTX port, should all be zero */
184 : 1 : rte_eth_stats_get(port, &stats);
185 [ + - + - ]: 1 : if (stats.ipackets != 0 || stats.opackets != 0 ||
186 [ + - + - ]: 1 : stats.ibytes != 0 || stats.obytes != 0 ||
187 [ + - - + ]: 1 : stats.ierrors != 0 || stats.oerrors != 0) {
188 : : printf("Error: port %d stats are not zero\n", port);
189 : 0 : return -1;
190 : : }
191 : :
192 : : /* send and receive 1 packet and check for stats update */
193 [ - + ]: 1 : if (rte_eth_tx_burst(port, 0, &pbuf, 1) != 1) {
194 : : printf("Error sending packet to port %d\n", port);
195 : 0 : return -1;
196 : : }
197 : :
198 [ - + ]: 1 : if (rte_eth_rx_burst(port, 0, &pbuf, 1) != 1) {
199 : : printf("Error receiving packet from port %d\n", port);
200 : 0 : return -1;
201 : : }
202 : :
203 : 1 : rte_eth_stats_get(port, &stats);
204 [ + - + - ]: 1 : if (stats.ipackets != 1 || stats.opackets != 1 ||
205 [ + - + - ]: 1 : stats.ibytes != 0 || stats.obytes != 0 ||
206 [ + - - + ]: 1 : stats.ierrors != 0 || stats.oerrors != 0) {
207 : : printf("Error: port %d stats are not as expected\n", port);
208 : 0 : return -1;
209 : : }
210 : :
211 : 1 : rte_eth_stats_reset(port);
212 : :
213 : : /* check stats of RXTX port, should all be zero */
214 : 1 : rte_eth_stats_get(port, &stats);
215 [ + - + - ]: 1 : if (stats.ipackets != 0 || stats.opackets != 0 ||
216 [ + - + - ]: 1 : stats.ibytes != 0 || stats.obytes != 0 ||
217 [ + - - + ]: 1 : stats.ierrors != 0 || stats.oerrors != 0) {
218 : : printf("Error: port %d stats are not zero\n", port);
219 : 0 : return -1;
220 : : }
221 : :
222 : : return 0;
223 : : }
224 : :
225 : : static int
226 : 1 : test_pmd_ring_pair_create_attach(void)
227 : : {
228 : : struct rte_eth_stats stats, stats2;
229 : 1 : struct rte_mbuf buf, *pbuf = &buf;
230 : : struct rte_eth_conf null_conf;
231 : : int ret;
232 : :
233 : : memset(&null_conf, 0, sizeof(struct rte_eth_conf));
234 : :
235 [ + - ]: 1 : if ((rte_eth_dev_configure(rxtx_portd, 1, 1, &null_conf) < 0)
236 [ - + ]: 1 : || (rte_eth_dev_configure(rxtx_porte, 1, 1,
237 : : &null_conf) < 0)) {
238 : : printf("Configure failed for port\n");
239 : 0 : return TEST_FAILED;
240 : : }
241 : :
242 [ + - ]: 1 : if ((rte_eth_tx_queue_setup(rxtx_portd, 0, RING_SIZE,
243 : : SOCKET0, NULL) < 0)
244 [ - + ]: 1 : || (rte_eth_tx_queue_setup(rxtx_porte, 0, RING_SIZE,
245 : : SOCKET0, NULL) < 0)) {
246 : : printf("TX queue setup failed\n");
247 : 0 : return TEST_FAILED;
248 : : }
249 : :
250 [ + - ]: 1 : if ((rte_eth_rx_queue_setup(rxtx_portd, 0, RING_SIZE,
251 : : SOCKET0, NULL, mp) < 0)
252 [ - + ]: 1 : || (rte_eth_rx_queue_setup(rxtx_porte, 0, RING_SIZE,
253 : : SOCKET0, NULL, mp) < 0)) {
254 : : printf("RX queue setup failed\n");
255 : 0 : return TEST_FAILED;
256 : : }
257 : :
258 [ + - ]: 1 : if ((rte_eth_dev_start(rxtx_portd) < 0)
259 [ - + ]: 1 : || (rte_eth_dev_start(rxtx_porte) < 0)) {
260 : : printf("Error starting port\n");
261 : 0 : return TEST_FAILED;
262 : : }
263 : :
264 : 1 : rte_eth_stats_reset(rxtx_portd);
265 : : /* check stats of port, should all be zero */
266 : 1 : rte_eth_stats_get(rxtx_portd, &stats);
267 [ + - + - ]: 1 : if (stats.ipackets != 0 || stats.opackets != 0 ||
268 [ + - + - ]: 1 : stats.ibytes != 0 || stats.obytes != 0 ||
269 [ + - - + ]: 1 : stats.ierrors != 0 || stats.oerrors != 0) {
270 : 0 : printf("Error: port %d stats are not zero\n", rxtx_portd);
271 : 0 : return TEST_FAILED;
272 : : }
273 : :
274 : 1 : rte_eth_stats_reset(rxtx_porte);
275 : : /* check stats of port, should all be zero */
276 : 1 : rte_eth_stats_get(rxtx_porte, &stats2);
277 [ + - + - ]: 1 : if (stats2.ipackets != 0 || stats2.opackets != 0 ||
278 [ + - + - ]: 1 : stats2.ibytes != 0 || stats2.obytes != 0 ||
279 [ + - - + ]: 1 : stats2.ierrors != 0 || stats2.oerrors != 0) {
280 : 0 : printf("Error: port %d stats are not zero\n", rxtx_porte);
281 : 0 : return TEST_FAILED;
282 : : }
283 : :
284 : : /*
285 : : * send and receive 1 packet (rxtx_portd -> rxtx_porte)
286 : : * and check for stats update
287 : : */
288 : : printf("Testing send and receive 1 packet (rxtx_portd -> rxtx_porte)\n");
289 [ - + ]: 1 : if (rte_eth_tx_burst(rxtx_portd, 0, &pbuf, 1) != 1) {
290 : 0 : printf("Error sending packet to port %d\n", rxtx_portd);
291 : 0 : return TEST_FAILED;
292 : : }
293 : :
294 [ - + ]: 1 : if (rte_eth_rx_burst(rxtx_porte, 0, &pbuf, 1) != 1) {
295 : 0 : printf("Error receiving packet from port %d\n", rxtx_porte);
296 : 0 : return TEST_FAILED;
297 : : }
298 : :
299 : 1 : rte_eth_stats_get(rxtx_portd, &stats);
300 : 1 : rte_eth_stats_get(rxtx_porte, &stats2);
301 [ + - + - ]: 1 : if (stats.ipackets != 0 || stats.opackets != 1 ||
302 [ + - + - ]: 1 : stats.ibytes != 0 || stats.obytes != 0 ||
303 [ + - - + ]: 1 : stats.ierrors != 0 || stats.oerrors != 0) {
304 : 0 : printf("Error: port %d stats are not as expected\n",
305 : : rxtx_portd);
306 : 0 : return TEST_FAILED;
307 : : }
308 : :
309 [ + - + - ]: 1 : if (stats2.ipackets != 1 || stats2.opackets != 0 ||
310 [ + - + - ]: 1 : stats2.ibytes != 0 || stats2.obytes != 0 ||
311 [ + - - + ]: 1 : stats2.ierrors != 0 || stats2.oerrors != 0) {
312 : 0 : printf("Error: port %d stats are not as expected\n",
313 : : rxtx_porte);
314 : 0 : return TEST_FAILED;
315 : : }
316 : :
317 : : /*
318 : : * send and receive 1 packet (rxtx_porte -> rxtx_portd)
319 : : * and check for stats update
320 : : */
321 : : printf("Testing send and receive 1 packet "
322 : : "(rxtx_porte -> rxtx_portd)\n");
323 [ - + ]: 1 : if (rte_eth_tx_burst(rxtx_porte, 0, &pbuf, 1) != 1) {
324 : 0 : printf("Error sending packet to port %d\n", rxtx_porte);
325 : 0 : return TEST_FAILED;
326 : : }
327 : :
328 [ - + ]: 1 : if (rte_eth_rx_burst(rxtx_portd, 0, &pbuf, 1) != 1) {
329 : 0 : printf("Error receiving packet from port %d\n", rxtx_portd);
330 : 0 : return TEST_FAILED;
331 : : }
332 : :
333 : 1 : rte_eth_stats_get(rxtx_portd, &stats);
334 : 1 : rte_eth_stats_get(rxtx_porte, &stats2);
335 [ + - + - ]: 1 : if (stats.ipackets != 1 || stats.opackets != 1 ||
336 [ + - + - ]: 1 : stats.ibytes != 0 || stats.obytes != 0 ||
337 [ + - - + ]: 1 : stats.ierrors != 0 || stats.oerrors != 0) {
338 : 0 : printf("Error: port %d stats are not as expected\n",
339 : : rxtx_portd);
340 : 0 : return TEST_FAILED;
341 : : }
342 : :
343 [ + - + - ]: 1 : if (stats2.ipackets != 1 || stats2.opackets != 1 ||
344 [ + - + - ]: 1 : stats2.ibytes != 0 || stats2.obytes != 0 ||
345 [ + - - + ]: 1 : stats2.ierrors != 0 || stats2.oerrors != 0) {
346 : 0 : printf("Error: port %d stats are not as expected\n",
347 : : rxtx_porte);
348 : 0 : return TEST_FAILED;
349 : : }
350 : :
351 : : /*
352 : : * send and receive 1 packet (rxtx_portd -> rxtx_portd)
353 : : * and check for stats update
354 : : */
355 : : printf("Testing send and receive 1 packet "
356 : : "(rxtx_portd -> rxtx_portd)\n");
357 [ - + ]: 1 : if (rte_eth_tx_burst(rxtx_portd, 0, &pbuf, 1) != 1) {
358 : 0 : printf("Error sending packet to port %d\n", rxtx_portd);
359 : 0 : return TEST_FAILED;
360 : : }
361 : :
362 [ - + ]: 1 : if (rte_eth_rx_burst(rxtx_portd, 0, &pbuf, 1) != 1) {
363 : 0 : printf("Error receiving packet from port %d\n", rxtx_porte);
364 : 0 : return TEST_FAILED;
365 : : }
366 : :
367 : 1 : rte_eth_stats_get(rxtx_portd, &stats);
368 : 1 : rte_eth_stats_get(rxtx_porte, &stats2);
369 [ + - + - ]: 1 : if (stats.ipackets != 2 || stats.opackets != 2 ||
370 [ + - + - ]: 1 : stats.ibytes != 0 || stats.obytes != 0 ||
371 [ + - - + ]: 1 : stats.ierrors != 0 || stats.oerrors != 0) {
372 : 0 : printf("Error: port %d stats are not as expected\n",
373 : : rxtx_portd);
374 : 0 : return TEST_FAILED;
375 : : }
376 : :
377 [ + - + - ]: 1 : if (stats2.ipackets != 1 || stats2.opackets != 1 ||
378 [ + - + - ]: 1 : stats2.ibytes != 0 || stats2.obytes != 0 ||
379 [ + - - + ]: 1 : stats2.ierrors != 0 || stats2.oerrors != 0) {
380 : 0 : printf("Error: port %d stats are not as expected\n",
381 : : rxtx_porte);
382 : 0 : return TEST_FAILED;
383 : : }
384 : :
385 : : /*
386 : : * send and receive 1 packet (rxtx_porte -> rxtx_porte)
387 : : * and check for stats update
388 : : */
389 : : printf("Testing send and receive 1 packet "
390 : : "(rxtx_porte -> rxtx_porte)\n");
391 [ - + ]: 1 : if (rte_eth_tx_burst(rxtx_porte, 0, &pbuf, 1) != 1) {
392 : 0 : printf("Error sending packet to port %d\n", rxtx_porte);
393 : 0 : return TEST_FAILED;
394 : : }
395 : :
396 [ - + ]: 1 : if (rte_eth_rx_burst(rxtx_porte, 0, &pbuf, 1) != 1) {
397 : 0 : printf("Error receiving packet from port %d\n", rxtx_porte);
398 : 0 : return TEST_FAILED;
399 : : }
400 : :
401 : 1 : rte_eth_stats_get(rxtx_portd, &stats);
402 : 1 : rte_eth_stats_get(rxtx_porte, &stats2);
403 [ + - + - ]: 1 : if (stats.ipackets != 2 || stats.opackets != 2 ||
404 [ + - + - ]: 1 : stats.ibytes != 0 || stats.obytes != 0 ||
405 [ + - - + ]: 1 : stats.ierrors != 0 || stats.oerrors != 0) {
406 : 0 : printf("Error: port %d stats are not as expected\n",
407 : : rxtx_portd);
408 : 0 : return TEST_FAILED;
409 : : }
410 : :
411 [ + - + - ]: 1 : if (stats2.ipackets != 2 || stats2.opackets != 2 ||
412 [ + - + - ]: 1 : stats2.ibytes != 0 || stats2.obytes != 0 ||
413 [ + - - + ]: 1 : stats2.ierrors != 0 || stats2.oerrors != 0) {
414 : 0 : printf("Error: port %d stats are not as expected\n",
415 : : rxtx_porte);
416 : 0 : return TEST_FAILED;
417 : : }
418 : :
419 : 1 : ret = rte_eth_dev_stop(rxtx_portd);
420 [ - + ]: 1 : if (ret != 0)
421 : 0 : printf("Error: failed to stop port %u: %s\n",
422 : : rxtx_portd, rte_strerror(-ret));
423 : 1 : ret = rte_eth_dev_stop(rxtx_porte);
424 [ - + ]: 1 : if (ret != 0)
425 : 0 : printf("Error: failed to stop port %u: %s\n",
426 : : rxtx_porte, rte_strerror(-ret));
427 : :
428 : : return TEST_SUCCESS;
429 : : }
430 : :
431 : : static void
432 : 1 : test_cleanup_resources(void)
433 : : {
434 : : int itr, ret;
435 [ + + ]: 3 : for (itr = 0; itr < NUM_RINGS; itr++)
436 : 2 : rte_ring_free(rxtx[itr]);
437 : :
438 : 1 : ret = rte_eth_dev_stop(tx_porta);
439 [ - + ]: 1 : if (ret != 0)
440 : 0 : printf("Error: failed to stop port %u: %s\n",
441 : : tx_porta, rte_strerror(-ret));
442 : 1 : ret = rte_eth_dev_stop(rx_portb);
443 [ - + ]: 1 : if (ret != 0)
444 : 0 : printf("Error: failed to stop port %u: %s\n",
445 : : rx_portb, rte_strerror(-ret));
446 : 1 : ret = rte_eth_dev_stop(rxtx_portc);
447 [ - + ]: 1 : if (ret != 0)
448 : 0 : printf("Error: failed to stop port %u: %s\n",
449 : : rxtx_portc, rte_strerror(-ret));
450 : :
451 : 1 : rte_mempool_free(mp);
452 : 1 : rte_vdev_uninit("net_ring_net_ringa");
453 : 1 : rte_vdev_uninit("net_ring_net_ringb");
454 : 1 : rte_vdev_uninit("net_ring_net_ringc");
455 : 1 : rte_vdev_uninit("net_ring_net_ringd");
456 : 1 : rte_vdev_uninit("net_ring_net_ringe");
457 : 1 : }
458 : :
459 : : static int
460 : 1 : test_pmd_ringcreate_setup(void)
461 : : {
462 : : uint8_t nb_ports;
463 : :
464 : 1 : nb_ports = rte_eth_dev_count_avail();
465 : 1 : printf("nb_ports=%d\n", (int)nb_ports);
466 : :
467 : : /* create the rings and eth_rings in the test code.
468 : : * This does not test the rte_pmd_ring_devinit function.
469 : : *
470 : : * Test with the command line option --vdev=net_ring0 to test rte_pmd_ring_devinit.
471 : : */
472 : 1 : rxtx[0] = rte_ring_create("R0", RING_SIZE, SOCKET0, RING_F_SP_ENQ|RING_F_SC_DEQ);
473 [ - + ]: 1 : if (rxtx[0] == NULL) {
474 : : printf("rte_ring_create R0 failed");
475 : 0 : return -1;
476 : : }
477 : :
478 : 1 : rxtx[1] = rte_ring_create("R1", RING_SIZE, SOCKET0, RING_F_SP_ENQ|RING_F_SC_DEQ);
479 [ - + ]: 1 : if (rxtx[1] == NULL) {
480 : : printf("rte_ring_create R1 failed");
481 : 0 : return -1;
482 : : }
483 : :
484 : 1 : tx_porta = rte_eth_from_rings("net_ringa", rxtx, NUM_RINGS, rxtx, NUM_RINGS, SOCKET0);
485 : 1 : rx_portb = rte_eth_from_rings("net_ringb", rxtx, NUM_RINGS, rxtx, NUM_RINGS, SOCKET0);
486 : 1 : rxtx_portc = rte_eth_from_rings("net_ringc", rxtx, NUM_RINGS, rxtx, NUM_RINGS, SOCKET0);
487 : 1 : rxtx_portd = rte_eth_from_rings("net_ringd", rxtx, NUM_RINGS, rxtx, NUM_RINGS, SOCKET0);
488 : 1 : rxtx_porte = rte_eth_from_rings("net_ringe", rxtx, NUM_RINGS, rxtx, NUM_RINGS, SOCKET0);
489 : :
490 : 1 : printf("tx_porta=%d rx_portb=%d rxtx_portc=%d rxtx_portd=%d rxtx_porte=%d\n",
491 : : tx_porta, rx_portb, rxtx_portc, rxtx_portd, rxtx_porte);
492 : :
493 [ + - + - : 1 : if ((tx_porta == -1) || (rx_portb == -1) || (rxtx_portc == -1)
+ - ]
494 [ + - - + ]: 1 : || (rxtx_portd == -1) || (rxtx_porte == -1)) {
495 : : printf("rte_eth_from rings failed\n");
496 : 0 : return -1;
497 : : }
498 : :
499 : 1 : mp = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF, 32,
500 : 1 : 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
501 [ + - ]: 1 : if (mp == NULL)
502 : : return -1;
503 : :
504 [ + - + - ]: 1 : if ((tx_porta >= RTE_MAX_ETHPORTS) || (rx_portb >= RTE_MAX_ETHPORTS)
505 [ + - ]: 1 : || (rxtx_portc >= RTE_MAX_ETHPORTS)
506 [ + - ]: 1 : || (rxtx_portd >= RTE_MAX_ETHPORTS)
507 [ - + ]: 1 : || (rxtx_porte >= RTE_MAX_ETHPORTS)) {
508 : : printf(" port exceed max eth ports\n");
509 : 0 : return -1;
510 : : }
511 : : return 0;
512 : : }
513 : :
514 : : static int
515 : 1 : test_command_line_ring_port(void)
516 : : {
517 : : int port, cmdl_port0 = -1;
518 : : int ret;
519 : :
520 : : /* find a port created with the --vdev=net_ring0 command line option */
521 [ + + ]: 6 : RTE_ETH_FOREACH_DEV(port) {
522 : : struct rte_eth_dev_info dev_info;
523 : :
524 : 5 : ret = rte_eth_dev_info_get(port, &dev_info);
525 [ - + ]: 5 : TEST_ASSERT((ret == 0),
526 : : "Error during getting device (port %d) info: %s\n",
527 : : port, strerror(-ret));
528 : :
529 [ - + ]: 5 : if (!strcmp(dev_info.driver_name, "Rings PMD")) {
530 : : printf("found a command line ring port=%d\n", port);
531 : : cmdl_port0 = port;
532 : 0 : break;
533 : : }
534 : : }
535 [ - + ]: 1 : if (cmdl_port0 != -1) {
536 [ # # ]: 0 : TEST_ASSERT((test_ethdev_configure_port(cmdl_port0) < 0),
537 : : "test ethdev configure port cmdl_port0 is failed");
538 [ # # ]: 0 : TEST_ASSERT((test_send_basic_packets_port(cmdl_port0) < 0),
539 : : "test send basic packets port cmdl_port0 is failed");
540 [ # # ]: 0 : TEST_ASSERT((test_stats_reset(cmdl_port0) < 0),
541 : : "test stats reset cmdl_port0 is failed");
542 [ # # ]: 0 : TEST_ASSERT((test_get_stats(cmdl_port0) < 0),
543 : : "test get stats cmdl_port0 is failed");
544 [ # # ]: 0 : TEST_ASSERT((rte_eth_dev_stop(cmdl_port0) == 0),
545 : : "test stop cmdl_port0 is failed");
546 : : }
547 : : return TEST_SUCCESS;
548 : : }
549 : :
550 : : static int
551 : 1 : test_ethdev_configure_ports(void)
552 : : {
553 [ - + ]: 1 : TEST_ASSERT((test_ethdev_configure_port(tx_porta) == 0),
554 : : "test ethdev configure ports tx_porta is failed");
555 [ - + ]: 1 : TEST_ASSERT((test_ethdev_configure_port(rx_portb) == 0),
556 : : "test ethdev configure ports rx_portb is failed");
557 [ - + ]: 1 : TEST_ASSERT((test_ethdev_configure_port(rxtx_portc) == 0),
558 : : "test ethdev configure ports rxtx_portc is failed");
559 : :
560 : : return TEST_SUCCESS;
561 : : }
562 : :
563 : : /*
564 : : * Per-queue xstats are added by ethdev for all configured queues.
565 : : * Use a port with different Rx and Tx queue counts to check that each
566 : : * direction is reported independently.
567 : : */
568 : : #define QSTATS_NB_RXQ 3
569 : : #define QSTATS_NB_TXQ 5
570 : : #define QSTATS_NB_RINGS 5 /* RTE_MAX(QSTATS_NB_RXQ, QSTATS_NB_TXQ) */
571 : :
572 : : static int
573 : 1 : test_queue_xstats(void)
574 : : {
575 : 1 : struct rte_ring *qrings[QSTATS_NB_RINGS] = { };
576 : : struct rte_eth_xstat_name *names = NULL;
577 : : struct rte_eth_xstat *xstats = NULL;
578 : : struct rte_eth_conf null_conf;
579 : : unsigned int i, nb_names, found;
580 : : char expected[RTE_ETH_XSTATS_NAME_SIZE];
581 : : int port = -1, nb_xstats, ret = -1;
582 : : uint16_t q;
583 : :
584 [ + + ]: 6 : for (q = 0; q < QSTATS_NB_RINGS; q++) {
585 : : char name[RTE_RING_NAMESIZE];
586 : :
587 : 5 : snprintf(name, sizeof(name), "RQ%u", q);
588 : 5 : qrings[q] = rte_ring_create(name, RING_SIZE, SOCKET0,
589 : : RING_F_SP_ENQ | RING_F_SC_DEQ);
590 [ - + ]: 5 : if (qrings[q] == NULL) {
591 : : printf("rte_ring_create %s failed\n", name);
592 : 0 : goto out;
593 : : }
594 : : }
595 : :
596 : 1 : port = rte_eth_from_rings("net_ringq", qrings, QSTATS_NB_RXQ,
597 : : qrings, QSTATS_NB_TXQ, SOCKET0);
598 [ - + ]: 1 : if (port < 0) {
599 : : printf("failed to create port\n");
600 : 0 : goto out;
601 : : }
602 : :
603 : : memset(&null_conf, 0, sizeof(null_conf));
604 [ - + ]: 1 : if (rte_eth_dev_configure(port, QSTATS_NB_RXQ, QSTATS_NB_TXQ,
605 : : &null_conf) < 0) {
606 : : printf("configure failed\n");
607 : 0 : goto out;
608 : : }
609 : :
610 [ + + ]: 4 : for (q = 0; q < QSTATS_NB_RXQ; q++) {
611 [ - + ]: 3 : if (rte_eth_rx_queue_setup(port, q, RING_SIZE, SOCKET0,
612 : : NULL, mp) < 0) {
613 : : printf("Rx queue %u setup failed\n", q);
614 : 0 : goto out;
615 : : }
616 : : }
617 [ + + ]: 6 : for (q = 0; q < QSTATS_NB_TXQ; q++) {
618 [ - + ]: 5 : if (rte_eth_tx_queue_setup(port, q, RING_SIZE, SOCKET0,
619 : : NULL) < 0) {
620 : : printf("Tx queue %u setup failed\n", q);
621 : 0 : goto out;
622 : : }
623 : : }
624 : :
625 : 1 : nb_xstats = rte_eth_xstats_get_names(port, NULL, 0);
626 [ - + ]: 1 : if (nb_xstats <= 0) {
627 : : printf("no xstats reported\n");
628 : 0 : goto out;
629 : : }
630 : :
631 : 1 : names = calloc(nb_xstats, sizeof(*names));
632 : 1 : xstats = calloc(nb_xstats, sizeof(*xstats));
633 [ - + ]: 1 : if (names == NULL || xstats == NULL) {
634 : : printf("out of memory\n");
635 : 0 : goto out;
636 : : }
637 : :
638 : 1 : nb_names = rte_eth_xstats_get_names(port, names, nb_xstats);
639 [ - + ]: 1 : if (nb_names != (unsigned int)nb_xstats) {
640 : : printf("got %u names, expected %d\n", nb_names, nb_xstats);
641 : 0 : goto out;
642 : : }
643 : :
644 [ - + ]: 1 : if (rte_eth_xstats_get(port, xstats, nb_xstats) != nb_xstats) {
645 : : printf("xstats count does not match names count\n");
646 : 0 : goto out;
647 : : }
648 : :
649 : : /* No traffic has passed, so every counter must still be zero. */
650 [ + + ]: 25 : for (i = 0; i < (unsigned int)nb_xstats; i++) {
651 [ - + ]: 24 : if (xstats[i].value != 0) {
652 : : printf("xstat '%s' is %"PRIu64", expected 0\n",
653 : 0 : names[xstats[i].id].name, xstats[i].value);
654 : 0 : goto out;
655 : : }
656 : : }
657 : :
658 : : /* Every configured queue must have its counters, in both directions. */
659 [ + + ]: 9 : for (q = 0; q < QSTATS_NB_RXQ + QSTATS_NB_TXQ; q++) {
660 : : bool rx = q < QSTATS_NB_RXQ;
661 : :
662 [ + + + + ]: 13 : snprintf(expected, sizeof(expected), "%s_q%u_packets",
663 : 5 : rx ? "rx" : "tx", rx ? q : q - QSTATS_NB_RXQ);
664 : :
665 [ + + ]: 200 : for (i = 0, found = 0; i < nb_names; i++)
666 [ + + ]: 192 : if (strcmp(names[i].name, expected) == 0)
667 : 8 : found++;
668 : :
669 [ - + ]: 8 : if (found != 1) {
670 : : printf("expected one '%s', got %u\n", expected, found);
671 : 0 : goto out;
672 : : }
673 : : }
674 : :
675 : : /* Queues beyond the configured count must not be reported. */
676 : : snprintf(expected, sizeof(expected), "rx_q%u_packets", QSTATS_NB_RXQ);
677 [ + + ]: 25 : for (i = 0; i < nb_names; i++) {
678 [ - + ]: 24 : if (strcmp(names[i].name, expected) == 0) {
679 : : printf("unexpected stat '%s'\n", expected);
680 : 0 : goto out;
681 : : }
682 : : }
683 : :
684 : : snprintf(expected, sizeof(expected), "tx_q%u_packets", QSTATS_NB_TXQ);
685 [ + + ]: 25 : for (i = 0; i < nb_names; i++) {
686 [ - + ]: 24 : if (strcmp(names[i].name, expected) == 0) {
687 : : printf("unexpected stat '%s'\n", expected);
688 : 0 : goto out;
689 : : }
690 : : }
691 : :
692 : : ret = TEST_SUCCESS;
693 : 1 : out:
694 : 1 : free(names);
695 : 1 : free(xstats);
696 [ + - ]: 1 : if (port >= 0)
697 : 1 : rte_eth_dev_close(port);
698 [ + + ]: 6 : for (q = 0; q < QSTATS_NB_RINGS; q++)
699 : 5 : rte_ring_free(qrings[q]);
700 : :
701 : 1 : return ret;
702 : : }
703 : :
704 : : static int
705 : 1 : test_get_stats_for_port(void)
706 : : {
707 [ - + ]: 1 : TEST_ASSERT(test_get_stats(rxtx_portc) == 0, "test get stats failed");
708 : : return TEST_SUCCESS;
709 : : }
710 : :
711 : : static int
712 : 1 : test_stats_reset_for_port(void)
713 : : {
714 [ - + ]: 1 : TEST_ASSERT(test_stats_reset(rxtx_portc) == 0, "test stats reset failed");
715 : : return TEST_SUCCESS;
716 : : }
717 : :
718 : : static struct
719 : : unit_test_suite test_pmd_ring_suite = {
720 : : .setup = test_pmd_ringcreate_setup,
721 : : .teardown = test_cleanup_resources,
722 : : .suite_name = "Test Pmd Ring Unit Test Suite",
723 : : .unit_test_cases = {
724 : : TEST_CASE(test_ethdev_configure_ports),
725 : : TEST_CASE(test_send_basic_packets),
726 : : TEST_CASE(test_get_stats_for_port),
727 : : TEST_CASE(test_stats_reset_for_port),
728 : : TEST_CASE(test_queue_xstats),
729 : : TEST_CASE(test_pmd_ring_pair_create_attach),
730 : : TEST_CASE(test_command_line_ring_port),
731 : : TEST_CASES_END()
732 : : }
733 : : };
734 : :
735 : : static int
736 : 1 : test_pmd_ring(void)
737 : : {
738 : 1 : return unit_test_suite_runner(&test_pmd_ring_suite);
739 : : }
740 : :
741 : 302 : REGISTER_FAST_TEST(ring_pmd_autotest, NOHUGE_OK, ASAN_OK, test_pmd_ring);
|