4 * Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include <rte_eth_ring.h>
38 #include <rte_ethdev.h>
40 static struct rte_mempool
*mp
;
41 static int tx_porta
, rx_portb
, rxtx_portc
, rxtx_portd
, rxtx_porte
;
50 test_ethdev_configure_port(int port
)
52 struct rte_eth_conf null_conf
;
53 struct rte_eth_link link
;
55 memset(&null_conf
, 0, sizeof(struct rte_eth_conf
));
57 if (rte_eth_dev_configure(port
, 1, 2, &null_conf
) < 0) {
58 printf("Configure failed for port %d\n", port
);
62 /* Test queue release */
63 if (rte_eth_dev_configure(port
, 1, 1, &null_conf
) < 0) {
64 printf("Configure failed for port %d\n", port
);
68 if (rte_eth_tx_queue_setup(port
, 0, RING_SIZE
, SOCKET0
, NULL
) < 0) {
69 printf("TX queue setup failed port %d\n", port
);
73 if (rte_eth_rx_queue_setup(port
, 0, RING_SIZE
, SOCKET0
,
75 printf("RX queue setup failed port %d\n", port
);
79 if (rte_eth_dev_start(port
) < 0) {
80 printf("Error starting port %d\n", port
);
84 rte_eth_link_get(port
, &link
);
90 test_send_basic_packets(void)
92 struct rte_mbuf bufs
[RING_SIZE
];
93 struct rte_mbuf
*pbufs
[RING_SIZE
];
96 printf("Testing send and receive RING_SIZE/2 packets (tx_porta -> rx_portb)\n");
98 for (i
= 0; i
< RING_SIZE
/2; i
++)
101 if (rte_eth_tx_burst(tx_porta
, 0, pbufs
, RING_SIZE
/2) < RING_SIZE
/2) {
102 printf("Failed to transmit packet burst port %d\n", tx_porta
);
106 if (rte_eth_rx_burst(rx_portb
, 0, pbufs
, RING_SIZE
) != RING_SIZE
/2) {
107 printf("Failed to receive packet burst on port %d\n", rx_portb
);
111 for (i
= 0; i
< RING_SIZE
/2; i
++)
112 if (pbufs
[i
] != &bufs
[i
]) {
113 printf("Error: received data does not match that transmitted\n");
121 test_send_basic_packets_port(int port
)
123 struct rte_mbuf bufs
[RING_SIZE
];
124 struct rte_mbuf
*pbufs
[RING_SIZE
];
127 printf("Testing send and receive RING_SIZE/2 packets (cmdl_port0 -> cmdl_port0)\n");
129 for (i
= 0; i
< RING_SIZE
/2; i
++)
132 if (rte_eth_tx_burst(port
, 0, pbufs
, RING_SIZE
/2) < RING_SIZE
/2) {
133 printf("Failed to transmit packet burst port %d\n", port
);
137 if (rte_eth_rx_burst(port
, 0, pbufs
, RING_SIZE
) != RING_SIZE
/2) {
138 printf("Failed to receive packet burst on port %d\n", port
);
142 for (i
= 0; i
< RING_SIZE
/2; i
++)
143 if (pbufs
[i
] != &bufs
[i
]) {
144 printf("Error: received data does not match that transmitted\n");
153 test_get_stats(int port
)
155 struct rte_eth_stats stats
;
156 struct rte_mbuf buf
, *pbuf
= &buf
;
158 printf("Testing ring PMD stats_get port %d\n", port
);
160 /* check stats of RXTX port, should all be zero */
162 rte_eth_stats_get(port
, &stats
);
163 if (stats
.ipackets
!= 0 || stats
.opackets
!= 0 ||
164 stats
.ibytes
!= 0 || stats
.obytes
!= 0 ||
165 stats
.ierrors
!= 0 || stats
.oerrors
!= 0) {
166 printf("Error: port %d stats are not zero\n", port
);
170 /* send and receive 1 packet and check for stats update */
171 if (rte_eth_tx_burst(port
, 0, &pbuf
, 1) != 1) {
172 printf("Error sending packet to port %d\n", port
);
176 if (rte_eth_rx_burst(port
, 0, &pbuf
, 1) != 1) {
177 printf("Error receiving packet from port %d\n", port
);
181 rte_eth_stats_get(port
, &stats
);
182 if (stats
.ipackets
!= 1 || stats
.opackets
!= 1 ||
183 stats
.ibytes
!= 0 || stats
.obytes
!= 0 ||
184 stats
.ierrors
!= 0 || stats
.oerrors
!= 0) {
185 printf("Error: port %d stats are not as expected\n", port
);
192 test_stats_reset(int port
)
194 struct rte_eth_stats stats
;
195 struct rte_mbuf buf
, *pbuf
= &buf
;
197 printf("Testing ring PMD stats_reset port %d\n", port
);
199 rte_eth_stats_reset(port
);
201 /* check stats of RXTX port, should all be zero */
202 rte_eth_stats_get(port
, &stats
);
203 if (stats
.ipackets
!= 0 || stats
.opackets
!= 0 ||
204 stats
.ibytes
!= 0 || stats
.obytes
!= 0 ||
205 stats
.ierrors
!= 0 || stats
.oerrors
!= 0) {
206 printf("Error: port %d stats are not zero\n", port
);
210 /* send and receive 1 packet and check for stats update */
211 if (rte_eth_tx_burst(port
, 0, &pbuf
, 1) != 1) {
212 printf("Error sending packet to port %d\n", port
);
216 if (rte_eth_rx_burst(port
, 0, &pbuf
, 1) != 1) {
217 printf("Error receiving packet from port %d\n", port
);
221 rte_eth_stats_get(port
, &stats
);
222 if (stats
.ipackets
!= 1 || stats
.opackets
!= 1 ||
223 stats
.ibytes
!= 0 || stats
.obytes
!= 0 ||
224 stats
.ierrors
!= 0 || stats
.oerrors
!= 0) {
225 printf("Error: port %d stats are not as expected\n", port
);
229 rte_eth_stats_reset(port
);
231 /* check stats of RXTX port, should all be zero */
232 rte_eth_stats_get(port
, &stats
);
233 if (stats
.ipackets
!= 0 || stats
.opackets
!= 0 ||
234 stats
.ibytes
!= 0 || stats
.obytes
!= 0 ||
235 stats
.ierrors
!= 0 || stats
.oerrors
!= 0) {
236 printf("Error: port %d stats are not zero\n", port
);
244 test_pmd_ring_pair_create_attach(int portd
, int porte
)
246 struct rte_eth_stats stats
, stats2
;
247 struct rte_mbuf buf
, *pbuf
= &buf
;
248 struct rte_eth_conf null_conf
;
250 if ((rte_eth_dev_configure(portd
, 1, 1, &null_conf
) < 0)
251 || (rte_eth_dev_configure(porte
, 1, 1, &null_conf
) < 0)) {
252 printf("Configure failed for port\n");
256 if ((rte_eth_tx_queue_setup(portd
, 0, RING_SIZE
, SOCKET0
, NULL
) < 0)
257 || (rte_eth_tx_queue_setup(porte
, 0, RING_SIZE
, SOCKET0
, NULL
) < 0)) {
258 printf("TX queue setup failed\n");
262 if ((rte_eth_rx_queue_setup(portd
, 0, RING_SIZE
, SOCKET0
, NULL
, mp
) < 0)
263 || (rte_eth_rx_queue_setup(porte
, 0, RING_SIZE
, SOCKET0
, NULL
, mp
) < 0)) {
264 printf("RX queue setup failed\n");
268 if ((rte_eth_dev_start(portd
) < 0)
269 || (rte_eth_dev_start(porte
) < 0)) {
270 printf("Error starting port\n");
274 rte_eth_stats_reset(portd
);
275 /* check stats of port, should all be zero */
276 rte_eth_stats_get(portd
, &stats
);
277 if (stats
.ipackets
!= 0 || stats
.opackets
!= 0 ||
278 stats
.ibytes
!= 0 || stats
.obytes
!= 0 ||
279 stats
.ierrors
!= 0 || stats
.oerrors
!= 0) {
280 printf("Error: port %d stats are not zero\n", portd
);
284 rte_eth_stats_reset(porte
);
285 /* check stats of port, should all be zero */
286 rte_eth_stats_get(porte
, &stats2
);
287 if (stats2
.ipackets
!= 0 || stats2
.opackets
!= 0 ||
288 stats2
.ibytes
!= 0 || stats2
.obytes
!= 0 ||
289 stats2
.ierrors
!= 0 || stats2
.oerrors
!= 0) {
290 printf("Error: port %d stats are not zero\n", porte
);
295 * send and receive 1 packet (portd -> porte)
296 * and check for stats update
298 printf("Testing send and receive 1 packet (portd -> porte)\n");
299 if (rte_eth_tx_burst(portd
, 0, &pbuf
, 1) != 1) {
300 printf("Error sending packet to port %d\n", portd
);
304 if (rte_eth_rx_burst(porte
, 0, &pbuf
, 1) != 1) {
305 printf("Error receiving packet from port %d\n", porte
);
309 rte_eth_stats_get(portd
, &stats
);
310 rte_eth_stats_get(porte
, &stats2
);
311 if (stats
.ipackets
!= 0 || stats
.opackets
!= 1 ||
312 stats
.ibytes
!= 0 || stats
.obytes
!= 0 ||
313 stats
.ierrors
!= 0 || stats
.oerrors
!= 0) {
314 printf("Error: port %d stats are not as expected\n", portd
);
318 if (stats2
.ipackets
!= 1 || stats2
.opackets
!= 0 ||
319 stats2
.ibytes
!= 0 || stats2
.obytes
!= 0 ||
320 stats2
.ierrors
!= 0 || stats2
.oerrors
!= 0) {
321 printf("Error: port %d stats are not as expected\n", porte
);
326 * send and receive 1 packet (porte -> portd)
327 * and check for stats update
329 printf("Testing send and receive 1 packet (porte -> portd)\n");
330 if (rte_eth_tx_burst(porte
, 0, &pbuf
, 1) != 1) {
331 printf("Error sending packet to port %d\n", porte
);
335 if (rte_eth_rx_burst(portd
, 0, &pbuf
, 1) != 1) {
336 printf("Error receiving packet from port %d\n", portd
);
340 rte_eth_stats_get(portd
, &stats
);
341 rte_eth_stats_get(porte
, &stats2
);
342 if (stats
.ipackets
!= 1 || stats
.opackets
!= 1 ||
343 stats
.ibytes
!= 0 || stats
.obytes
!= 0 ||
344 stats
.ierrors
!= 0 || stats
.oerrors
!= 0) {
345 printf("Error: port %d stats are not as expected\n", portd
);
349 if (stats2
.ipackets
!= 1 || stats2
.opackets
!= 1 ||
350 stats2
.ibytes
!= 0 || stats2
.obytes
!= 0 ||
351 stats2
.ierrors
!= 0 || stats2
.oerrors
!= 0) {
352 printf("Error: port %d stats are not as expected\n", porte
);
357 * send and receive 1 packet (portd -> portd)
358 * and check for stats update
360 printf("Testing send and receive 1 packet (portd -> portd)\n");
361 if (rte_eth_tx_burst(portd
, 0, &pbuf
, 1) != 1) {
362 printf("Error sending packet to port %d\n", portd
);
366 if (rte_eth_rx_burst(portd
, 0, &pbuf
, 1) != 1) {
367 printf("Error receiving packet from port %d\n", porte
);
371 rte_eth_stats_get(portd
, &stats
);
372 rte_eth_stats_get(porte
, &stats2
);
373 if (stats
.ipackets
!= 2 || stats
.opackets
!= 2 ||
374 stats
.ibytes
!= 0 || stats
.obytes
!= 0 ||
375 stats
.ierrors
!= 0 || stats
.oerrors
!= 0) {
376 printf("Error: port %d stats are not as expected\n", portd
);
380 if (stats2
.ipackets
!= 1 || stats2
.opackets
!= 1 ||
381 stats2
.ibytes
!= 0 || stats2
.obytes
!= 0 ||
382 stats2
.ierrors
!= 0 || stats2
.oerrors
!= 0) {
383 printf("Error: port %d stats are not as expected\n", porte
);
388 * send and receive 1 packet (porte -> porte)
389 * and check for stats update
391 printf("Testing send and receive 1 packet (porte -> porte)\n");
392 if (rte_eth_tx_burst(porte
, 0, &pbuf
, 1) != 1) {
393 printf("Error sending packet to port %d\n", porte
);
397 if (rte_eth_rx_burst(porte
, 0, &pbuf
, 1) != 1) {
398 printf("Error receiving packet from port %d\n", porte
);
402 rte_eth_stats_get(portd
, &stats
);
403 rte_eth_stats_get(porte
, &stats2
);
404 if (stats
.ipackets
!= 2 || stats
.opackets
!= 2 ||
405 stats
.ibytes
!= 0 || stats
.obytes
!= 0 ||
406 stats
.ierrors
!= 0 || stats
.oerrors
!= 0) {
407 printf("Error: port %d stats are not as expected\n", portd
);
411 if (stats2
.ipackets
!= 2 || stats2
.opackets
!= 2 ||
412 stats2
.ibytes
!= 0 || stats2
.obytes
!= 0 ||
413 stats2
.ierrors
!= 0 || stats2
.oerrors
!= 0) {
414 printf("Error: port %d stats are not as expected\n", porte
);
418 rte_eth_dev_stop(portd
);
419 rte_eth_dev_stop(porte
);
427 struct rte_ring
*rxtx
[NUM_RINGS
];
428 int port
, cmdl_port0
= -1;
431 nb_ports
= rte_eth_dev_count();
432 printf("nb_ports=%d\n", (int)nb_ports
);
434 /* create the rings and eth_rings in the test code.
435 * This does not test the rte_pmd_ring_devinit function.
437 * Test with the command line option --vdev=net_ring0 to test rte_pmd_ring_devinit.
439 rxtx
[0] = rte_ring_create("R0", RING_SIZE
, SOCKET0
, RING_F_SP_ENQ
|RING_F_SC_DEQ
);
440 if (rxtx
[0] == NULL
) {
441 printf("rte_ring_create R0 failed");
445 rxtx
[1] = rte_ring_create("R1", RING_SIZE
, SOCKET0
, RING_F_SP_ENQ
|RING_F_SC_DEQ
);
446 if (rxtx
[1] == NULL
) {
447 printf("rte_ring_create R1 failed");
451 tx_porta
= rte_eth_from_rings("net_ringa", rxtx
, NUM_RINGS
, rxtx
, NUM_RINGS
, SOCKET0
);
452 rx_portb
= rte_eth_from_rings("net_ringb", rxtx
, NUM_RINGS
, rxtx
, NUM_RINGS
, SOCKET0
);
453 rxtx_portc
= rte_eth_from_rings("net_ringc", rxtx
, NUM_RINGS
, rxtx
, NUM_RINGS
, SOCKET0
);
454 rxtx_portd
= rte_eth_from_rings("net_ringd", rxtx
, NUM_RINGS
, rxtx
, NUM_RINGS
, SOCKET0
);
455 rxtx_porte
= rte_eth_from_rings("net_ringe", rxtx
, NUM_RINGS
, rxtx
, NUM_RINGS
, SOCKET0
);
457 printf("tx_porta=%d rx_portb=%d rxtx_portc=%d rxtx_portd=%d rxtx_porte=%d\n",
458 tx_porta
, rx_portb
, rxtx_portc
, rxtx_portd
, rxtx_porte
);
460 if ((tx_porta
== -1) || (rx_portb
== -1) || (rxtx_portc
== -1)
461 || (rxtx_portd
== -1) || (rxtx_porte
== -1)) {
462 printf("rte_eth_from rings failed\n");
466 mp
= rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF
, 32,
467 0, RTE_MBUF_DEFAULT_BUF_SIZE
, rte_socket_id());
471 if ((tx_porta
>= RTE_MAX_ETHPORTS
) || (rx_portb
>= RTE_MAX_ETHPORTS
)
472 || (rxtx_portc
>= RTE_MAX_ETHPORTS
)
473 || (rxtx_portd
>= RTE_MAX_ETHPORTS
)
474 || (rxtx_porte
>= RTE_MAX_ETHPORTS
)) {
475 printf(" port exceed max eth ports\n");
479 if (test_ethdev_configure_port(tx_porta
) < 0)
482 if (test_ethdev_configure_port(rx_portb
) < 0)
485 if (test_ethdev_configure_port(rxtx_portc
) < 0)
488 if (test_send_basic_packets() < 0)
491 if (test_get_stats(rxtx_portc
) < 0)
494 if (test_stats_reset(rxtx_portc
) < 0)
497 rte_eth_dev_stop(tx_porta
);
498 rte_eth_dev_stop(rx_portb
);
499 rte_eth_dev_stop(rxtx_portc
);
501 if (test_pmd_ring_pair_create_attach(rxtx_portd
, rxtx_porte
) < 0)
504 /* find a port created with the --vdev=net_ring0 command line option */
505 for (port
= 0; port
< nb_ports
; port
++) {
506 struct rte_eth_dev_info dev_info
;
508 rte_eth_dev_info_get(port
, &dev_info
);
509 if (!strcmp(dev_info
.driver_name
, "Rings PMD")) {
510 printf("found a command line ring port=%d\n", port
);
515 if (cmdl_port0
!= -1) {
516 if (test_ethdev_configure_port(cmdl_port0
) < 0)
518 if (test_send_basic_packets_port(cmdl_port0
) < 0)
520 if (test_stats_reset(cmdl_port0
) < 0)
522 if (test_get_stats(cmdl_port0
) < 0)
524 rte_eth_dev_stop(cmdl_port0
);
529 REGISTER_TEST_COMMAND(ring_pmd_autotest
, test_pmd_ring
);