1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2015 Intel Corporation
8 #include <rte_eth_ring.h>
9 #include <rte_ethdev.h>
11 static struct rte_mempool
*mp
;
12 static int tx_porta
, rx_portb
, rxtx_portc
, rxtx_portd
, rxtx_porte
;
21 test_ethdev_configure_port(int port
)
23 struct rte_eth_conf null_conf
;
24 struct rte_eth_link link
;
26 memset(&null_conf
, 0, sizeof(struct rte_eth_conf
));
28 if (rte_eth_dev_configure(port
, 1, 2, &null_conf
) < 0) {
29 printf("Configure failed for port %d\n", port
);
33 /* Test queue release */
34 if (rte_eth_dev_configure(port
, 1, 1, &null_conf
) < 0) {
35 printf("Configure failed for port %d\n", port
);
39 if (rte_eth_tx_queue_setup(port
, 0, RING_SIZE
, SOCKET0
, NULL
) < 0) {
40 printf("TX queue setup failed port %d\n", port
);
44 if (rte_eth_rx_queue_setup(port
, 0, RING_SIZE
, SOCKET0
,
46 printf("RX queue setup failed port %d\n", port
);
50 if (rte_eth_dev_start(port
) < 0) {
51 printf("Error starting port %d\n", port
);
55 rte_eth_link_get(port
, &link
);
61 test_send_basic_packets(void)
63 struct rte_mbuf bufs
[RING_SIZE
];
64 struct rte_mbuf
*pbufs
[RING_SIZE
];
67 printf("Testing send and receive RING_SIZE/2 packets (tx_porta -> rx_portb)\n");
69 for (i
= 0; i
< RING_SIZE
/2; i
++)
72 if (rte_eth_tx_burst(tx_porta
, 0, pbufs
, RING_SIZE
/2) < RING_SIZE
/2) {
73 printf("Failed to transmit packet burst port %d\n", tx_porta
);
77 if (rte_eth_rx_burst(rx_portb
, 0, pbufs
, RING_SIZE
) != RING_SIZE
/2) {
78 printf("Failed to receive packet burst on port %d\n", rx_portb
);
82 for (i
= 0; i
< RING_SIZE
/2; i
++)
83 if (pbufs
[i
] != &bufs
[i
]) {
84 printf("Error: received data does not match that transmitted\n");
92 test_send_basic_packets_port(int port
)
94 struct rte_mbuf bufs
[RING_SIZE
];
95 struct rte_mbuf
*pbufs
[RING_SIZE
];
98 printf("Testing send and receive RING_SIZE/2 packets (cmdl_port0 -> cmdl_port0)\n");
100 for (i
= 0; i
< RING_SIZE
/2; i
++)
103 if (rte_eth_tx_burst(port
, 0, pbufs
, RING_SIZE
/2) < RING_SIZE
/2) {
104 printf("Failed to transmit packet burst port %d\n", port
);
108 if (rte_eth_rx_burst(port
, 0, pbufs
, RING_SIZE
) != RING_SIZE
/2) {
109 printf("Failed to receive packet burst on port %d\n", port
);
113 for (i
= 0; i
< RING_SIZE
/2; i
++)
114 if (pbufs
[i
] != &bufs
[i
]) {
115 printf("Error: received data does not match that transmitted\n");
124 test_get_stats(int port
)
126 struct rte_eth_stats stats
;
127 struct rte_mbuf buf
, *pbuf
= &buf
;
129 printf("Testing ring PMD stats_get port %d\n", port
);
131 /* check stats of RXTX port, should all be zero */
133 rte_eth_stats_get(port
, &stats
);
134 if (stats
.ipackets
!= 0 || stats
.opackets
!= 0 ||
135 stats
.ibytes
!= 0 || stats
.obytes
!= 0 ||
136 stats
.ierrors
!= 0 || stats
.oerrors
!= 0) {
137 printf("Error: port %d stats are not zero\n", port
);
141 /* send and receive 1 packet and check for stats update */
142 if (rte_eth_tx_burst(port
, 0, &pbuf
, 1) != 1) {
143 printf("Error sending packet to port %d\n", port
);
147 if (rte_eth_rx_burst(port
, 0, &pbuf
, 1) != 1) {
148 printf("Error receiving packet from port %d\n", port
);
152 rte_eth_stats_get(port
, &stats
);
153 if (stats
.ipackets
!= 1 || stats
.opackets
!= 1 ||
154 stats
.ibytes
!= 0 || stats
.obytes
!= 0 ||
155 stats
.ierrors
!= 0 || stats
.oerrors
!= 0) {
156 printf("Error: port %d stats are not as expected\n", port
);
163 test_stats_reset(int port
)
165 struct rte_eth_stats stats
;
166 struct rte_mbuf buf
, *pbuf
= &buf
;
168 printf("Testing ring PMD stats_reset port %d\n", port
);
170 rte_eth_stats_reset(port
);
172 /* check stats of RXTX port, should all be zero */
173 rte_eth_stats_get(port
, &stats
);
174 if (stats
.ipackets
!= 0 || stats
.opackets
!= 0 ||
175 stats
.ibytes
!= 0 || stats
.obytes
!= 0 ||
176 stats
.ierrors
!= 0 || stats
.oerrors
!= 0) {
177 printf("Error: port %d stats are not zero\n", port
);
181 /* send and receive 1 packet and check for stats update */
182 if (rte_eth_tx_burst(port
, 0, &pbuf
, 1) != 1) {
183 printf("Error sending packet to port %d\n", port
);
187 if (rte_eth_rx_burst(port
, 0, &pbuf
, 1) != 1) {
188 printf("Error receiving packet from port %d\n", port
);
192 rte_eth_stats_get(port
, &stats
);
193 if (stats
.ipackets
!= 1 || stats
.opackets
!= 1 ||
194 stats
.ibytes
!= 0 || stats
.obytes
!= 0 ||
195 stats
.ierrors
!= 0 || stats
.oerrors
!= 0) {
196 printf("Error: port %d stats are not as expected\n", port
);
200 rte_eth_stats_reset(port
);
202 /* check stats of RXTX port, should all be zero */
203 rte_eth_stats_get(port
, &stats
);
204 if (stats
.ipackets
!= 0 || stats
.opackets
!= 0 ||
205 stats
.ibytes
!= 0 || stats
.obytes
!= 0 ||
206 stats
.ierrors
!= 0 || stats
.oerrors
!= 0) {
207 printf("Error: port %d stats are not zero\n", port
);
215 test_pmd_ring_pair_create_attach(int portd
, int porte
)
217 struct rte_eth_stats stats
, stats2
;
218 struct rte_mbuf buf
, *pbuf
= &buf
;
219 struct rte_eth_conf null_conf
;
221 memset(&null_conf
, 0, sizeof(struct rte_eth_conf
));
223 if ((rte_eth_dev_configure(portd
, 1, 1, &null_conf
) < 0)
224 || (rte_eth_dev_configure(porte
, 1, 1, &null_conf
) < 0)) {
225 printf("Configure failed for port\n");
229 if ((rte_eth_tx_queue_setup(portd
, 0, RING_SIZE
, SOCKET0
, NULL
) < 0)
230 || (rte_eth_tx_queue_setup(porte
, 0, RING_SIZE
, SOCKET0
, NULL
) < 0)) {
231 printf("TX queue setup failed\n");
235 if ((rte_eth_rx_queue_setup(portd
, 0, RING_SIZE
, SOCKET0
, NULL
, mp
) < 0)
236 || (rte_eth_rx_queue_setup(porte
, 0, RING_SIZE
, SOCKET0
, NULL
, mp
) < 0)) {
237 printf("RX queue setup failed\n");
241 if ((rte_eth_dev_start(portd
) < 0)
242 || (rte_eth_dev_start(porte
) < 0)) {
243 printf("Error starting port\n");
247 rte_eth_stats_reset(portd
);
248 /* check stats of port, should all be zero */
249 rte_eth_stats_get(portd
, &stats
);
250 if (stats
.ipackets
!= 0 || stats
.opackets
!= 0 ||
251 stats
.ibytes
!= 0 || stats
.obytes
!= 0 ||
252 stats
.ierrors
!= 0 || stats
.oerrors
!= 0) {
253 printf("Error: port %d stats are not zero\n", portd
);
257 rte_eth_stats_reset(porte
);
258 /* check stats of port, should all be zero */
259 rte_eth_stats_get(porte
, &stats2
);
260 if (stats2
.ipackets
!= 0 || stats2
.opackets
!= 0 ||
261 stats2
.ibytes
!= 0 || stats2
.obytes
!= 0 ||
262 stats2
.ierrors
!= 0 || stats2
.oerrors
!= 0) {
263 printf("Error: port %d stats are not zero\n", porte
);
268 * send and receive 1 packet (portd -> porte)
269 * and check for stats update
271 printf("Testing send and receive 1 packet (portd -> porte)\n");
272 if (rte_eth_tx_burst(portd
, 0, &pbuf
, 1) != 1) {
273 printf("Error sending packet to port %d\n", portd
);
277 if (rte_eth_rx_burst(porte
, 0, &pbuf
, 1) != 1) {
278 printf("Error receiving packet from port %d\n", porte
);
282 rte_eth_stats_get(portd
, &stats
);
283 rte_eth_stats_get(porte
, &stats2
);
284 if (stats
.ipackets
!= 0 || stats
.opackets
!= 1 ||
285 stats
.ibytes
!= 0 || stats
.obytes
!= 0 ||
286 stats
.ierrors
!= 0 || stats
.oerrors
!= 0) {
287 printf("Error: port %d stats are not as expected\n", portd
);
291 if (stats2
.ipackets
!= 1 || stats2
.opackets
!= 0 ||
292 stats2
.ibytes
!= 0 || stats2
.obytes
!= 0 ||
293 stats2
.ierrors
!= 0 || stats2
.oerrors
!= 0) {
294 printf("Error: port %d stats are not as expected\n", porte
);
299 * send and receive 1 packet (porte -> portd)
300 * and check for stats update
302 printf("Testing send and receive 1 packet (porte -> portd)\n");
303 if (rte_eth_tx_burst(porte
, 0, &pbuf
, 1) != 1) {
304 printf("Error sending packet to port %d\n", porte
);
308 if (rte_eth_rx_burst(portd
, 0, &pbuf
, 1) != 1) {
309 printf("Error receiving packet from port %d\n", portd
);
313 rte_eth_stats_get(portd
, &stats
);
314 rte_eth_stats_get(porte
, &stats2
);
315 if (stats
.ipackets
!= 1 || stats
.opackets
!= 1 ||
316 stats
.ibytes
!= 0 || stats
.obytes
!= 0 ||
317 stats
.ierrors
!= 0 || stats
.oerrors
!= 0) {
318 printf("Error: port %d stats are not as expected\n", portd
);
322 if (stats2
.ipackets
!= 1 || stats2
.opackets
!= 1 ||
323 stats2
.ibytes
!= 0 || stats2
.obytes
!= 0 ||
324 stats2
.ierrors
!= 0 || stats2
.oerrors
!= 0) {
325 printf("Error: port %d stats are not as expected\n", porte
);
330 * send and receive 1 packet (portd -> portd)
331 * and check for stats update
333 printf("Testing send and receive 1 packet (portd -> portd)\n");
334 if (rte_eth_tx_burst(portd
, 0, &pbuf
, 1) != 1) {
335 printf("Error sending packet to port %d\n", portd
);
339 if (rte_eth_rx_burst(portd
, 0, &pbuf
, 1) != 1) {
340 printf("Error receiving packet from port %d\n", porte
);
344 rte_eth_stats_get(portd
, &stats
);
345 rte_eth_stats_get(porte
, &stats2
);
346 if (stats
.ipackets
!= 2 || stats
.opackets
!= 2 ||
347 stats
.ibytes
!= 0 || stats
.obytes
!= 0 ||
348 stats
.ierrors
!= 0 || stats
.oerrors
!= 0) {
349 printf("Error: port %d stats are not as expected\n", portd
);
353 if (stats2
.ipackets
!= 1 || stats2
.opackets
!= 1 ||
354 stats2
.ibytes
!= 0 || stats2
.obytes
!= 0 ||
355 stats2
.ierrors
!= 0 || stats2
.oerrors
!= 0) {
356 printf("Error: port %d stats are not as expected\n", porte
);
361 * send and receive 1 packet (porte -> porte)
362 * and check for stats update
364 printf("Testing send and receive 1 packet (porte -> porte)\n");
365 if (rte_eth_tx_burst(porte
, 0, &pbuf
, 1) != 1) {
366 printf("Error sending packet to port %d\n", porte
);
370 if (rte_eth_rx_burst(porte
, 0, &pbuf
, 1) != 1) {
371 printf("Error receiving packet from port %d\n", porte
);
375 rte_eth_stats_get(portd
, &stats
);
376 rte_eth_stats_get(porte
, &stats2
);
377 if (stats
.ipackets
!= 2 || stats
.opackets
!= 2 ||
378 stats
.ibytes
!= 0 || stats
.obytes
!= 0 ||
379 stats
.ierrors
!= 0 || stats
.oerrors
!= 0) {
380 printf("Error: port %d stats are not as expected\n", portd
);
384 if (stats2
.ipackets
!= 2 || stats2
.opackets
!= 2 ||
385 stats2
.ibytes
!= 0 || stats2
.obytes
!= 0 ||
386 stats2
.ierrors
!= 0 || stats2
.oerrors
!= 0) {
387 printf("Error: port %d stats are not as expected\n", porte
);
391 rte_eth_dev_stop(portd
);
392 rte_eth_dev_stop(porte
);
400 struct rte_ring
*rxtx
[NUM_RINGS
];
401 int port
, cmdl_port0
= -1;
404 nb_ports
= rte_eth_dev_count_avail();
405 printf("nb_ports=%d\n", (int)nb_ports
);
407 /* create the rings and eth_rings in the test code.
408 * This does not test the rte_pmd_ring_devinit function.
410 * Test with the command line option --vdev=net_ring0 to test rte_pmd_ring_devinit.
412 rxtx
[0] = rte_ring_create("R0", RING_SIZE
, SOCKET0
, RING_F_SP_ENQ
|RING_F_SC_DEQ
);
413 if (rxtx
[0] == NULL
) {
414 printf("rte_ring_create R0 failed");
418 rxtx
[1] = rte_ring_create("R1", RING_SIZE
, SOCKET0
, RING_F_SP_ENQ
|RING_F_SC_DEQ
);
419 if (rxtx
[1] == NULL
) {
420 printf("rte_ring_create R1 failed");
424 tx_porta
= rte_eth_from_rings("net_ringa", rxtx
, NUM_RINGS
, rxtx
, NUM_RINGS
, SOCKET0
);
425 rx_portb
= rte_eth_from_rings("net_ringb", rxtx
, NUM_RINGS
, rxtx
, NUM_RINGS
, SOCKET0
);
426 rxtx_portc
= rte_eth_from_rings("net_ringc", rxtx
, NUM_RINGS
, rxtx
, NUM_RINGS
, SOCKET0
);
427 rxtx_portd
= rte_eth_from_rings("net_ringd", rxtx
, NUM_RINGS
, rxtx
, NUM_RINGS
, SOCKET0
);
428 rxtx_porte
= rte_eth_from_rings("net_ringe", rxtx
, NUM_RINGS
, rxtx
, NUM_RINGS
, SOCKET0
);
430 printf("tx_porta=%d rx_portb=%d rxtx_portc=%d rxtx_portd=%d rxtx_porte=%d\n",
431 tx_porta
, rx_portb
, rxtx_portc
, rxtx_portd
, rxtx_porte
);
433 if ((tx_porta
== -1) || (rx_portb
== -1) || (rxtx_portc
== -1)
434 || (rxtx_portd
== -1) || (rxtx_porte
== -1)) {
435 printf("rte_eth_from rings failed\n");
439 mp
= rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF
, 32,
440 0, RTE_MBUF_DEFAULT_BUF_SIZE
, rte_socket_id());
444 if ((tx_porta
>= RTE_MAX_ETHPORTS
) || (rx_portb
>= RTE_MAX_ETHPORTS
)
445 || (rxtx_portc
>= RTE_MAX_ETHPORTS
)
446 || (rxtx_portd
>= RTE_MAX_ETHPORTS
)
447 || (rxtx_porte
>= RTE_MAX_ETHPORTS
)) {
448 printf(" port exceed max eth ports\n");
452 if (test_ethdev_configure_port(tx_porta
) < 0)
455 if (test_ethdev_configure_port(rx_portb
) < 0)
458 if (test_ethdev_configure_port(rxtx_portc
) < 0)
461 if (test_send_basic_packets() < 0)
464 if (test_get_stats(rxtx_portc
) < 0)
467 if (test_stats_reset(rxtx_portc
) < 0)
470 rte_eth_dev_stop(tx_porta
);
471 rte_eth_dev_stop(rx_portb
);
472 rte_eth_dev_stop(rxtx_portc
);
474 if (test_pmd_ring_pair_create_attach(rxtx_portd
, rxtx_porte
) < 0)
477 /* find a port created with the --vdev=net_ring0 command line option */
478 RTE_ETH_FOREACH_DEV(port
) {
479 struct rte_eth_dev_info dev_info
;
481 rte_eth_dev_info_get(port
, &dev_info
);
482 if (!strcmp(dev_info
.driver_name
, "Rings PMD")) {
483 printf("found a command line ring port=%d\n", port
);
488 if (cmdl_port0
!= -1) {
489 if (test_ethdev_configure_port(cmdl_port0
) < 0)
491 if (test_send_basic_packets_port(cmdl_port0
) < 0)
493 if (test_stats_reset(cmdl_port0
) < 0)
495 if (test_get_stats(cmdl_port0
) < 0)
497 rte_eth_dev_stop(cmdl_port0
);
502 REGISTER_TEST_COMMAND(ring_pmd_autotest
, test_pmd_ring
);