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 if ((rte_eth_dev_configure(portd, 1, 1, &null_conf) < 0)
222 || (rte_eth_dev_configure(porte, 1, 1, &null_conf) < 0)) {
223 printf("Configure failed for port\n");
227 if ((rte_eth_tx_queue_setup(portd, 0, RING_SIZE, SOCKET0, NULL) < 0)
228 || (rte_eth_tx_queue_setup(porte, 0, RING_SIZE, SOCKET0, NULL) < 0)) {
229 printf("TX queue setup failed\n");
233 if ((rte_eth_rx_queue_setup(portd, 0, RING_SIZE, SOCKET0, NULL, mp) < 0)
234 || (rte_eth_rx_queue_setup(porte, 0, RING_SIZE, SOCKET0, NULL, mp) < 0)) {
235 printf("RX queue setup failed\n");
239 if ((rte_eth_dev_start(portd) < 0)
240 || (rte_eth_dev_start(porte) < 0)) {
241 printf("Error starting port\n");
245 rte_eth_stats_reset(portd);
246 /* check stats of port, should all be zero */
247 rte_eth_stats_get(portd, &stats);
248 if (stats.ipackets != 0 || stats.opackets != 0 ||
249 stats.ibytes != 0 || stats.obytes != 0 ||
250 stats.ierrors != 0 || stats.oerrors != 0) {
251 printf("Error: port %d stats are not zero\n", portd);
255 rte_eth_stats_reset(porte);
256 /* check stats of port, should all be zero */
257 rte_eth_stats_get(porte, &stats2);
258 if (stats2.ipackets != 0 || stats2.opackets != 0 ||
259 stats2.ibytes != 0 || stats2.obytes != 0 ||
260 stats2.ierrors != 0 || stats2.oerrors != 0) {
261 printf("Error: port %d stats are not zero\n", porte);
266 * send and receive 1 packet (portd -> porte)
267 * and check for stats update
269 printf("Testing send and receive 1 packet (portd -> porte)\n");
270 if (rte_eth_tx_burst(portd, 0, &pbuf, 1) != 1) {
271 printf("Error sending packet to port %d\n", portd);
275 if (rte_eth_rx_burst(porte, 0, &pbuf, 1) != 1) {
276 printf("Error receiving packet from port %d\n", porte);
280 rte_eth_stats_get(portd, &stats);
281 rte_eth_stats_get(porte, &stats2);
282 if (stats.ipackets != 0 || stats.opackets != 1 ||
283 stats.ibytes != 0 || stats.obytes != 0 ||
284 stats.ierrors != 0 || stats.oerrors != 0) {
285 printf("Error: port %d stats are not as expected\n", portd);
289 if (stats2.ipackets != 1 || stats2.opackets != 0 ||
290 stats2.ibytes != 0 || stats2.obytes != 0 ||
291 stats2.ierrors != 0 || stats2.oerrors != 0) {
292 printf("Error: port %d stats are not as expected\n", porte);
297 * send and receive 1 packet (porte -> portd)
298 * and check for stats update
300 printf("Testing send and receive 1 packet (porte -> portd)\n");
301 if (rte_eth_tx_burst(porte, 0, &pbuf, 1) != 1) {
302 printf("Error sending packet to port %d\n", porte);
306 if (rte_eth_rx_burst(portd, 0, &pbuf, 1) != 1) {
307 printf("Error receiving packet from port %d\n", portd);
311 rte_eth_stats_get(portd, &stats);
312 rte_eth_stats_get(porte, &stats2);
313 if (stats.ipackets != 1 || stats.opackets != 1 ||
314 stats.ibytes != 0 || stats.obytes != 0 ||
315 stats.ierrors != 0 || stats.oerrors != 0) {
316 printf("Error: port %d stats are not as expected\n", portd);
320 if (stats2.ipackets != 1 || stats2.opackets != 1 ||
321 stats2.ibytes != 0 || stats2.obytes != 0 ||
322 stats2.ierrors != 0 || stats2.oerrors != 0) {
323 printf("Error: port %d stats are not as expected\n", porte);
328 * send and receive 1 packet (portd -> portd)
329 * and check for stats update
331 printf("Testing send and receive 1 packet (portd -> portd)\n");
332 if (rte_eth_tx_burst(portd, 0, &pbuf, 1) != 1) {
333 printf("Error sending packet to port %d\n", portd);
337 if (rte_eth_rx_burst(portd, 0, &pbuf, 1) != 1) {
338 printf("Error receiving packet from port %d\n", porte);
342 rte_eth_stats_get(portd, &stats);
343 rte_eth_stats_get(porte, &stats2);
344 if (stats.ipackets != 2 || stats.opackets != 2 ||
345 stats.ibytes != 0 || stats.obytes != 0 ||
346 stats.ierrors != 0 || stats.oerrors != 0) {
347 printf("Error: port %d stats are not as expected\n", portd);
351 if (stats2.ipackets != 1 || stats2.opackets != 1 ||
352 stats2.ibytes != 0 || stats2.obytes != 0 ||
353 stats2.ierrors != 0 || stats2.oerrors != 0) {
354 printf("Error: port %d stats are not as expected\n", porte);
359 * send and receive 1 packet (porte -> porte)
360 * and check for stats update
362 printf("Testing send and receive 1 packet (porte -> porte)\n");
363 if (rte_eth_tx_burst(porte, 0, &pbuf, 1) != 1) {
364 printf("Error sending packet to port %d\n", porte);
368 if (rte_eth_rx_burst(porte, 0, &pbuf, 1) != 1) {
369 printf("Error receiving packet from port %d\n", porte);
373 rte_eth_stats_get(portd, &stats);
374 rte_eth_stats_get(porte, &stats2);
375 if (stats.ipackets != 2 || stats.opackets != 2 ||
376 stats.ibytes != 0 || stats.obytes != 0 ||
377 stats.ierrors != 0 || stats.oerrors != 0) {
378 printf("Error: port %d stats are not as expected\n", portd);
382 if (stats2.ipackets != 2 || stats2.opackets != 2 ||
383 stats2.ibytes != 0 || stats2.obytes != 0 ||
384 stats2.ierrors != 0 || stats2.oerrors != 0) {
385 printf("Error: port %d stats are not as expected\n", porte);
389 rte_eth_dev_stop(portd);
390 rte_eth_dev_stop(porte);
398 struct rte_ring *rxtx[NUM_RINGS];
399 int port, cmdl_port0 = -1;
402 nb_ports = rte_eth_dev_count();
403 printf("nb_ports=%d\n", (int)nb_ports);
405 /* create the rings and eth_rings in the test code.
406 * This does not test the rte_pmd_ring_devinit function.
408 * Test with the command line option --vdev=net_ring0 to test rte_pmd_ring_devinit.
410 rxtx[0] = rte_ring_create("R0", RING_SIZE, SOCKET0, RING_F_SP_ENQ|RING_F_SC_DEQ);
411 if (rxtx[0] == NULL) {
412 printf("rte_ring_create R0 failed");
416 rxtx[1] = rte_ring_create("R1", RING_SIZE, SOCKET0, RING_F_SP_ENQ|RING_F_SC_DEQ);
417 if (rxtx[1] == NULL) {
418 printf("rte_ring_create R1 failed");
422 tx_porta = rte_eth_from_rings("net_ringa", rxtx, NUM_RINGS, rxtx, NUM_RINGS, SOCKET0);
423 rx_portb = rte_eth_from_rings("net_ringb", rxtx, NUM_RINGS, rxtx, NUM_RINGS, SOCKET0);
424 rxtx_portc = rte_eth_from_rings("net_ringc", rxtx, NUM_RINGS, rxtx, NUM_RINGS, SOCKET0);
425 rxtx_portd = rte_eth_from_rings("net_ringd", rxtx, NUM_RINGS, rxtx, NUM_RINGS, SOCKET0);
426 rxtx_porte = rte_eth_from_rings("net_ringe", rxtx, NUM_RINGS, rxtx, NUM_RINGS, SOCKET0);
428 printf("tx_porta=%d rx_portb=%d rxtx_portc=%d rxtx_portd=%d rxtx_porte=%d\n",
429 tx_porta, rx_portb, rxtx_portc, rxtx_portd, rxtx_porte);
431 if ((tx_porta == -1) || (rx_portb == -1) || (rxtx_portc == -1)
432 || (rxtx_portd == -1) || (rxtx_porte == -1)) {
433 printf("rte_eth_from rings failed\n");
437 mp = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF, 32,
438 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
442 if ((tx_porta >= RTE_MAX_ETHPORTS) || (rx_portb >= RTE_MAX_ETHPORTS)
443 || (rxtx_portc >= RTE_MAX_ETHPORTS)
444 || (rxtx_portd >= RTE_MAX_ETHPORTS)
445 || (rxtx_porte >= RTE_MAX_ETHPORTS)) {
446 printf(" port exceed max eth ports\n");
450 if (test_ethdev_configure_port(tx_porta) < 0)
453 if (test_ethdev_configure_port(rx_portb) < 0)
456 if (test_ethdev_configure_port(rxtx_portc) < 0)
459 if (test_send_basic_packets() < 0)
462 if (test_get_stats(rxtx_portc) < 0)
465 if (test_stats_reset(rxtx_portc) < 0)
468 rte_eth_dev_stop(tx_porta);
469 rte_eth_dev_stop(rx_portb);
470 rte_eth_dev_stop(rxtx_portc);
472 if (test_pmd_ring_pair_create_attach(rxtx_portd, rxtx_porte) < 0)
475 /* find a port created with the --vdev=net_ring0 command line option */
476 for (port = 0; port < nb_ports; port++) {
477 struct rte_eth_dev_info dev_info;
479 rte_eth_dev_info_get(port, &dev_info);
480 if (!strcmp(dev_info.driver_name, "Rings PMD")) {
481 printf("found a command line ring port=%d\n", port);
486 if (cmdl_port0 != -1) {
487 if (test_ethdev_configure_port(cmdl_port0) < 0)
489 if (test_send_basic_packets_port(cmdl_port0) < 0)
491 if (test_stats_reset(cmdl_port0) < 0)
493 if (test_get_stats(cmdl_port0) < 0)
495 rte_eth_dev_stop(cmdl_port0);
500 REGISTER_TEST_COMMAND(ring_pmd_autotest, test_pmd_ring);