4 * Copyright(c) 2010-2014 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;
54 test_ethdev_configure(void)
56 struct rte_eth_conf null_conf;
57 struct rte_eth_link link;
59 memset(&null_conf, 0, sizeof(struct rte_eth_conf));
61 if ((TX_PORT >= RTE_MAX_ETHPORTS) || (RX_PORT >= RTE_MAX_ETHPORTS)\
62 || (RXTX_PORT >= RTE_MAX_ETHPORTS)) {
63 printf(" TX/RX port exceed max eth ports\n");
66 if (rte_eth_dev_configure(TX_PORT, 1, 2, &null_conf) < 0) {
67 printf("Configure failed for TX port\n");
71 /* Test queue release */
72 if (rte_eth_dev_configure(TX_PORT, 1, 1, &null_conf) < 0) {
73 printf("Configure failed for TX port\n");
76 if (rte_eth_dev_configure(RX_PORT, 1, 1, &null_conf) < 0) {
77 printf("Configure failed for RX port\n");
80 if (rte_eth_dev_configure(RXTX_PORT, 1, 1, &null_conf) < 0) {
81 printf("Configure failed for RXTX port\n");
85 if (rte_eth_tx_queue_setup(TX_PORT, 0, RING_SIZE, SOCKET0, NULL) < 0) {
86 printf("TX queue setup failed\n");
89 if (rte_eth_rx_queue_setup(RX_PORT, 0, RING_SIZE, SOCKET0,
91 printf("RX queue setup failed\n");
94 if (rte_eth_tx_queue_setup(RXTX_PORT, 0, RING_SIZE, SOCKET0, NULL) < 0) {
95 printf("TX queue setup failed\n");
98 if (rte_eth_rx_queue_setup(RXTX_PORT, 0, RING_SIZE, SOCKET0,
100 printf("RX queue setup failed\n");
104 if (rte_eth_dev_start(TX_PORT) < 0) {
105 printf("Error starting TX port\n");
108 if (rte_eth_dev_start(RX_PORT) < 0) {
109 printf("Error starting RX port\n");
112 if (rte_eth_dev_start(RXTX_PORT) < 0) {
113 printf("Error starting RX port\n");
117 rte_eth_link_get(TX_PORT, &link);
118 rte_eth_link_get(RX_PORT, &link);
119 rte_eth_link_get(RXTX_PORT, &link);
125 test_send_basic_packets(void)
127 struct rte_mbuf bufs[RING_SIZE];
128 struct rte_mbuf *pbufs[RING_SIZE];
131 printf("Testing ring pmd RX/TX\n");
133 for (i = 0; i < RING_SIZE/2; i++)
136 if (rte_eth_tx_burst(TX_PORT, 0, pbufs, RING_SIZE/2) < RING_SIZE/2) {
137 printf("Failed to transmit packet burst\n");
141 if (rte_eth_rx_burst(RX_PORT, 0, pbufs, RING_SIZE) != RING_SIZE/2) {
142 printf("Failed to receive packet burst\n");
146 for (i = 0; i < RING_SIZE/2; i++)
147 if (pbufs[i] != &bufs[i]) {
148 printf("Error: received data does not match that transmitted\n");
158 struct rte_eth_stats stats;
159 struct rte_mbuf buf, *pbuf = &buf;
161 printf("Testing ring PMD stats\n");
163 /* check stats of RXTX port, should all be zero */
164 rte_eth_stats_get(RXTX_PORT, &stats);
165 if (stats.ipackets != 0 || stats.opackets != 0 ||
166 stats.ibytes != 0 || stats.obytes != 0 ||
167 stats.ierrors != 0 || stats.oerrors != 0) {
168 printf("Error: RXTX port stats are not zero\n");
172 /* send and receive 1 packet and check for stats update */
173 if (rte_eth_tx_burst(RXTX_PORT, 0, &pbuf, 1) != 1) {
174 printf("Error sending packet to RXTX port\n");
177 if (rte_eth_rx_burst(RXTX_PORT, 0, &pbuf, 1) != 1) {
178 printf("Error receiving packet from RXTX port\n");
182 rte_eth_stats_get(RXTX_PORT, &stats);
183 if (stats.ipackets != 1 || stats.opackets != 1 ||
184 stats.ibytes != 0 || stats.obytes != 0 ||
185 stats.ierrors != 0 || stats.oerrors != 0) {
186 printf("Error: RXTX port stats are not as expected\n");
193 test_stats_reset(void)
195 struct rte_eth_stats stats;
196 struct rte_mbuf buf, *pbuf = &buf;
198 printf("Testing ring PMD stats reset\n");
200 rte_eth_stats_reset(RXTX_PORT);
202 /* check stats of RXTX port, should all be zero */
203 rte_eth_stats_get(RXTX_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: RXTX port stats are not zero\n");
211 /* send and receive 1 packet and check for stats update */
212 if (rte_eth_tx_burst(RXTX_PORT, 0, &pbuf, 1) != 1) {
213 printf("Error sending packet to RXTX port\n");
217 if (rte_eth_rx_burst(RXTX_PORT, 0, &pbuf, 1) != 1) {
218 printf("Error receiving packet from RXTX port\n");
222 rte_eth_stats_get(RXTX_PORT, &stats);
223 if (stats.ipackets != 1 || stats.opackets != 1 ||
224 stats.ibytes != 0 || stats.obytes != 0 ||
225 stats.ierrors != 0 || stats.oerrors != 0) {
226 printf("Error: RXTX port stats are not as expected\n");
230 rte_eth_stats_reset(RXTX_PORT);
232 /* check stats of RXTX port, should all be zero */
233 rte_eth_stats_get(RXTX_PORT, &stats);
234 if (stats.ipackets != 0 || stats.opackets != 0 ||
235 stats.ibytes != 0 || stats.obytes != 0 ||
236 stats.ierrors != 0 || stats.oerrors != 0) {
237 printf("Error: RXTX port stats are not zero\n");
245 test_pmd_ring_pair_create_attach(void)
247 struct rte_eth_stats stats, stats2;
248 struct rte_mbuf buf, *pbuf = &buf;
249 struct rte_eth_conf null_conf;
251 if ((RXTX_PORT2 >= RTE_MAX_ETHPORTS) || (RXTX_PORT3 >= RTE_MAX_ETHPORTS)) {
252 printf(" TX/RX port exceed max eth ports\n");
255 if ((rte_eth_dev_configure(RXTX_PORT2, 1, 1, &null_conf) < 0)
256 || (rte_eth_dev_configure(RXTX_PORT3, 1, 1, &null_conf) < 0)) {
257 printf("Configure failed for RXTX port\n");
261 if ((rte_eth_tx_queue_setup(RXTX_PORT2, 0, RING_SIZE, SOCKET0, NULL) < 0)
262 || (rte_eth_tx_queue_setup(RXTX_PORT3, 0, RING_SIZE, SOCKET0, NULL) < 0)) {
263 printf("TX queue setup failed\n");
267 if ((rte_eth_rx_queue_setup(RXTX_PORT2, 0, RING_SIZE, SOCKET0, NULL, mp) < 0)
268 || (rte_eth_rx_queue_setup(RXTX_PORT3, 0, RING_SIZE, SOCKET0, NULL, mp) < 0)) {
269 printf("RX queue setup failed\n");
273 if ((rte_eth_dev_start(RXTX_PORT2) < 0)
274 || (rte_eth_dev_start(RXTX_PORT3) < 0)) {
275 printf("Error starting RXTX port\n");
280 * send and receive 1 packet (RXTX_PORT2 -> RXTX_PORT3)
281 * and check for stats update
283 if (rte_eth_tx_burst(RXTX_PORT2, 0, &pbuf, 1) != 1) {
284 printf("Error sending packet to RXTX port\n");
288 if (rte_eth_rx_burst(RXTX_PORT3, 0, &pbuf, 1) != 1) {
289 printf("Error receiving packet from RXTX port\n");
293 rte_eth_stats_get(RXTX_PORT2, &stats);
294 rte_eth_stats_get(RXTX_PORT3, &stats2);
295 if (stats.ipackets != 0 || stats.opackets != 1 ||
296 stats.ibytes != 0 || stats.obytes != 0 ||
297 stats.ierrors != 0 || stats.oerrors != 0) {
298 printf("Error: RXTX port stats are not as expected\n");
302 if (stats2.ipackets != 1 || stats2.opackets != 0 ||
303 stats2.ibytes != 0 || stats2.obytes != 0 ||
304 stats2.ierrors != 0 || stats2.oerrors != 0) {
305 printf("Error: RXTX port stats are not as expected\n");
310 * send and receive 1 packet (RXTX_PORT3 -> RXTX_PORT2)
311 * and check for stats update
313 if (rte_eth_tx_burst(RXTX_PORT3, 0, &pbuf, 1) != 1) {
314 printf("Error sending packet to RXTX port\n");
318 if (rte_eth_rx_burst(RXTX_PORT2, 0, &pbuf, 1) != 1) {
319 printf("Error receiving packet from RXTX port\n");
323 rte_eth_stats_get(RXTX_PORT2, &stats);
324 rte_eth_stats_get(RXTX_PORT3, &stats2);
325 if (stats.ipackets != 1 || stats.opackets != 1 ||
326 stats.ibytes != 0 || stats.obytes != 0 ||
327 stats.ierrors != 0 || stats.oerrors != 0) {
328 printf("Error: RXTX port stats are not as expected\n");
332 if (stats2.ipackets != 1 || stats2.opackets != 1 ||
333 stats2.ibytes != 0 || stats2.obytes != 0 ||
334 stats2.ierrors != 0 || stats2.oerrors != 0) {
335 printf("Error: RXTX port stats are not as expected\n");
340 * send and receive 1 packet (RXTX_PORT2 -> RXTX_PORT2)
341 * and check for stats update
343 if (rte_eth_tx_burst(RXTX_PORT2, 0, &pbuf, 1) != 1) {
344 printf("Error sending packet to RXTX port\n");
348 if (rte_eth_rx_burst(RXTX_PORT2, 0, &pbuf, 1) != 1) {
349 printf("Error receiving packet from RXTX port\n");
353 rte_eth_stats_get(RXTX_PORT2, &stats);
354 rte_eth_stats_get(RXTX_PORT3, &stats2);
355 if (stats.ipackets != 2 || stats.opackets != 2 ||
356 stats.ibytes != 0 || stats.obytes != 0 ||
357 stats.ierrors != 0 || stats.oerrors != 0) {
358 printf("Error: RXTX port stats are not as expected\n");
362 if (stats2.ipackets != 1 || stats2.opackets != 1 ||
363 stats2.ibytes != 0 || stats2.obytes != 0 ||
364 stats2.ierrors != 0 || stats2.oerrors != 0) {
365 printf("Error: RXTX port stats are not as expected\n");
370 * send and receive 1 packet (RXTX_PORT3 -> RXTX_PORT3)
371 * and check for stats update
373 if (rte_eth_tx_burst(RXTX_PORT3, 0, &pbuf, 1) != 1) {
374 printf("Error sending packet to RXTX port\n");
378 if (rte_eth_rx_burst(RXTX_PORT3, 0, &pbuf, 1) != 1) {
379 printf("Error receiving packet from RXTX port\n");
383 rte_eth_stats_get(RXTX_PORT2, &stats);
384 rte_eth_stats_get(RXTX_PORT3, &stats2);
385 if (stats.ipackets != 2 || stats.opackets != 2 ||
386 stats.ibytes != 0 || stats.obytes != 0 ||
387 stats.ierrors != 0 || stats.oerrors != 0) {
388 printf("Error: RXTX port stats are not as expected\n");
392 if (stats2.ipackets != 2 || stats2.opackets != 2 ||
393 stats2.ibytes != 0 || stats2.obytes != 0 ||
394 stats2.ierrors != 0 || stats2.oerrors != 0) {
395 printf("Error: RXTX port stats are not as expected\n");
399 rte_eth_dev_stop(RXTX_PORT2);
400 rte_eth_dev_stop(RXTX_PORT3);
408 mp = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF, 32,
409 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
413 if ((TX_PORT >= RTE_MAX_ETHPORTS) || (RX_PORT >= RTE_MAX_ETHPORTS)\
414 || (RXTX_PORT >= RTE_MAX_ETHPORTS)) {
415 printf(" TX/RX port exceed max eth ports\n");
419 if (test_ethdev_configure() < 0)
422 if (test_send_basic_packets() < 0)
425 if (test_get_stats() < 0)
428 if (test_stats_reset() < 0)
431 rte_eth_dev_stop(RX_PORT);
432 rte_eth_dev_stop(TX_PORT);
433 rte_eth_dev_stop(RXTX_PORT);
435 if (test_pmd_ring_pair_create_attach() < 0)
441 static struct test_command ring_pmd_cmd = {
442 .command = "ring_pmd_autotest",
443 .callback = test_pmd_ring,
445 REGISTER_TEST_COMMAND(ring_pmd_cmd);