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 memset(&null_conf, 0, sizeof(struct rte_eth_conf));
252 if ((rte_eth_dev_configure(portd, 1, 1, &null_conf) < 0)
253 || (rte_eth_dev_configure(porte, 1, 1, &null_conf) < 0)) {
254 printf("Configure failed for port\n");
258 if ((rte_eth_tx_queue_setup(portd, 0, RING_SIZE, SOCKET0, NULL) < 0)
259 || (rte_eth_tx_queue_setup(porte, 0, RING_SIZE, SOCKET0, NULL) < 0)) {
260 printf("TX queue setup failed\n");
264 if ((rte_eth_rx_queue_setup(portd, 0, RING_SIZE, SOCKET0, NULL, mp) < 0)
265 || (rte_eth_rx_queue_setup(porte, 0, RING_SIZE, SOCKET0, NULL, mp) < 0)) {
266 printf("RX queue setup failed\n");
270 if ((rte_eth_dev_start(portd) < 0)
271 || (rte_eth_dev_start(porte) < 0)) {
272 printf("Error starting port\n");
276 rte_eth_stats_reset(portd);
277 /* check stats of port, should all be zero */
278 rte_eth_stats_get(portd, &stats);
279 if (stats.ipackets != 0 || stats.opackets != 0 ||
280 stats.ibytes != 0 || stats.obytes != 0 ||
281 stats.ierrors != 0 || stats.oerrors != 0) {
282 printf("Error: port %d stats are not zero\n", portd);
286 rte_eth_stats_reset(porte);
287 /* check stats of port, should all be zero */
288 rte_eth_stats_get(porte, &stats2);
289 if (stats2.ipackets != 0 || 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 zero\n", porte);
297 * send and receive 1 packet (portd -> porte)
298 * and check for stats update
300 printf("Testing send and receive 1 packet (portd -> porte)\n");
301 if (rte_eth_tx_burst(portd, 0, &pbuf, 1) != 1) {
302 printf("Error sending packet to port %d\n", portd);
306 if (rte_eth_rx_burst(porte, 0, &pbuf, 1) != 1) {
307 printf("Error receiving packet from port %d\n", porte);
311 rte_eth_stats_get(portd, &stats);
312 rte_eth_stats_get(porte, &stats2);
313 if (stats.ipackets != 0 || 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 != 0 ||
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 (porte -> portd)
329 * and check for stats update
331 printf("Testing send and receive 1 packet (porte -> portd)\n");
332 if (rte_eth_tx_burst(porte, 0, &pbuf, 1) != 1) {
333 printf("Error sending packet to port %d\n", porte);
337 if (rte_eth_rx_burst(portd, 0, &pbuf, 1) != 1) {
338 printf("Error receiving packet from port %d\n", portd);
342 rte_eth_stats_get(portd, &stats);
343 rte_eth_stats_get(porte, &stats2);
344 if (stats.ipackets != 1 || stats.opackets != 1 ||
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 (portd -> portd)
360 * and check for stats update
362 printf("Testing send and receive 1 packet (portd -> portd)\n");
363 if (rte_eth_tx_burst(portd, 0, &pbuf, 1) != 1) {
364 printf("Error sending packet to port %d\n", portd);
368 if (rte_eth_rx_burst(portd, 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 != 1 || stats2.opackets != 1 ||
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);
390 * send and receive 1 packet (porte -> porte)
391 * and check for stats update
393 printf("Testing send and receive 1 packet (porte -> porte)\n");
394 if (rte_eth_tx_burst(porte, 0, &pbuf, 1) != 1) {
395 printf("Error sending packet to port %d\n", porte);
399 if (rte_eth_rx_burst(porte, 0, &pbuf, 1) != 1) {
400 printf("Error receiving packet from port %d\n", porte);
404 rte_eth_stats_get(portd, &stats);
405 rte_eth_stats_get(porte, &stats2);
406 if (stats.ipackets != 2 || stats.opackets != 2 ||
407 stats.ibytes != 0 || stats.obytes != 0 ||
408 stats.ierrors != 0 || stats.oerrors != 0) {
409 printf("Error: port %d stats are not as expected\n", portd);
413 if (stats2.ipackets != 2 || stats2.opackets != 2 ||
414 stats2.ibytes != 0 || stats2.obytes != 0 ||
415 stats2.ierrors != 0 || stats2.oerrors != 0) {
416 printf("Error: port %d stats are not as expected\n", porte);
420 rte_eth_dev_stop(portd);
421 rte_eth_dev_stop(porte);
429 struct rte_ring *rxtx[NUM_RINGS];
430 int port, cmdl_port0 = -1;
433 nb_ports = rte_eth_dev_count();
434 printf("nb_ports=%d\n", (int)nb_ports);
436 /* create the rings and eth_rings in the test code.
437 * This does not test the rte_pmd_ring_devinit function.
439 * Test with the command line option --vdev=net_ring0 to test rte_pmd_ring_devinit.
441 rxtx[0] = rte_ring_create("R0", RING_SIZE, SOCKET0, RING_F_SP_ENQ|RING_F_SC_DEQ);
442 if (rxtx[0] == NULL) {
443 printf("rte_ring_create R0 failed");
447 rxtx[1] = rte_ring_create("R1", RING_SIZE, SOCKET0, RING_F_SP_ENQ|RING_F_SC_DEQ);
448 if (rxtx[1] == NULL) {
449 printf("rte_ring_create R1 failed");
453 tx_porta = rte_eth_from_rings("net_ringa", rxtx, NUM_RINGS, rxtx, NUM_RINGS, SOCKET0);
454 rx_portb = rte_eth_from_rings("net_ringb", rxtx, NUM_RINGS, rxtx, NUM_RINGS, SOCKET0);
455 rxtx_portc = rte_eth_from_rings("net_ringc", rxtx, NUM_RINGS, rxtx, NUM_RINGS, SOCKET0);
456 rxtx_portd = rte_eth_from_rings("net_ringd", rxtx, NUM_RINGS, rxtx, NUM_RINGS, SOCKET0);
457 rxtx_porte = rte_eth_from_rings("net_ringe", rxtx, NUM_RINGS, rxtx, NUM_RINGS, SOCKET0);
459 printf("tx_porta=%d rx_portb=%d rxtx_portc=%d rxtx_portd=%d rxtx_porte=%d\n",
460 tx_porta, rx_portb, rxtx_portc, rxtx_portd, rxtx_porte);
462 if ((tx_porta == -1) || (rx_portb == -1) || (rxtx_portc == -1)
463 || (rxtx_portd == -1) || (rxtx_porte == -1)) {
464 printf("rte_eth_from rings failed\n");
468 mp = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF, 32,
469 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
473 if ((tx_porta >= RTE_MAX_ETHPORTS) || (rx_portb >= RTE_MAX_ETHPORTS)
474 || (rxtx_portc >= RTE_MAX_ETHPORTS)
475 || (rxtx_portd >= RTE_MAX_ETHPORTS)
476 || (rxtx_porte >= RTE_MAX_ETHPORTS)) {
477 printf(" port exceed max eth ports\n");
481 if (test_ethdev_configure_port(tx_porta) < 0)
484 if (test_ethdev_configure_port(rx_portb) < 0)
487 if (test_ethdev_configure_port(rxtx_portc) < 0)
490 if (test_send_basic_packets() < 0)
493 if (test_get_stats(rxtx_portc) < 0)
496 if (test_stats_reset(rxtx_portc) < 0)
499 rte_eth_dev_stop(tx_porta);
500 rte_eth_dev_stop(rx_portb);
501 rte_eth_dev_stop(rxtx_portc);
503 if (test_pmd_ring_pair_create_attach(rxtx_portd, rxtx_porte) < 0)
506 /* find a port created with the --vdev=net_ring0 command line option */
507 for (port = 0; port < nb_ports; port++) {
508 struct rte_eth_dev_info dev_info;
510 rte_eth_dev_info_get(port, &dev_info);
511 if (!strcmp(dev_info.driver_name, "Rings PMD")) {
512 printf("found a command line ring port=%d\n", port);
517 if (cmdl_port0 != -1) {
518 if (test_ethdev_configure_port(cmdl_port0) < 0)
520 if (test_send_basic_packets_port(cmdl_port0) < 0)
522 if (test_stats_reset(cmdl_port0) < 0)
524 if (test_get_stats(cmdl_port0) < 0)
526 rte_eth_dev_stop(cmdl_port0);
531 REGISTER_TEST_COMMAND(ring_pmd_autotest, test_pmd_ring);