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;
51 #define MBUF_SIZE (2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
55 test_ethdev_configure(void)
57 struct rte_eth_conf null_conf;
58 struct rte_eth_link link;
60 memset(&null_conf, 0, sizeof(struct rte_eth_conf));
62 if ((TX_PORT >= RTE_MAX_ETHPORTS) || (RX_PORT >= RTE_MAX_ETHPORTS)\
63 || (RXTX_PORT >= RTE_MAX_ETHPORTS)) {
64 printf(" TX/RX port exceed max eth ports\n");
67 if (rte_eth_dev_configure(TX_PORT, 1, 2, &null_conf) < 0) {
68 printf("Configure failed for TX port\n");
72 /* Test queue release */
73 if (rte_eth_dev_configure(TX_PORT, 1, 1, &null_conf) < 0) {
74 printf("Configure failed for TX port\n");
77 if (rte_eth_dev_configure(RX_PORT, 1, 1, &null_conf) < 0) {
78 printf("Configure failed for RX port\n");
81 if (rte_eth_dev_configure(RXTX_PORT, 1, 1, &null_conf) < 0) {
82 printf("Configure failed for RXTX port\n");
86 if (rte_eth_tx_queue_setup(TX_PORT, 0, RING_SIZE, SOCKET0, NULL) < 0) {
87 printf("TX queue setup failed\n");
90 if (rte_eth_rx_queue_setup(RX_PORT, 0, RING_SIZE, SOCKET0,
92 printf("RX queue setup failed\n");
95 if (rte_eth_tx_queue_setup(RXTX_PORT, 0, RING_SIZE, SOCKET0, NULL) < 0) {
96 printf("TX queue setup failed\n");
99 if (rte_eth_rx_queue_setup(RXTX_PORT, 0, RING_SIZE, SOCKET0,
101 printf("RX queue setup failed\n");
105 if (rte_eth_dev_start(TX_PORT) < 0) {
106 printf("Error starting TX port\n");
109 if (rte_eth_dev_start(RX_PORT) < 0) {
110 printf("Error starting RX port\n");
113 if (rte_eth_dev_start(RXTX_PORT) < 0) {
114 printf("Error starting RX port\n");
118 rte_eth_link_get(TX_PORT, &link);
119 rte_eth_link_get(RX_PORT, &link);
120 rte_eth_link_get(RXTX_PORT, &link);
126 test_send_basic_packets(void)
128 struct rte_mbuf bufs[RING_SIZE];
129 struct rte_mbuf *pbufs[RING_SIZE];
132 printf("Testing ring pmd RX/TX\n");
134 for (i = 0; i < RING_SIZE/2; i++)
137 if (rte_eth_tx_burst(TX_PORT, 0, pbufs, RING_SIZE/2) < RING_SIZE/2) {
138 printf("Failed to transmit packet burst\n");
142 if (rte_eth_rx_burst(RX_PORT, 0, pbufs, RING_SIZE) != RING_SIZE/2) {
143 printf("Failed to receive packet burst\n");
147 for (i = 0; i < RING_SIZE/2; i++)
148 if (pbufs[i] != &bufs[i]) {
149 printf("Error: received data does not match that transmitted\n");
159 struct rte_eth_stats stats;
160 struct rte_mbuf buf, *pbuf = &buf;
162 printf("Testing ring PMD stats\n");
164 /* check stats of RXTX port, should all be zero */
165 rte_eth_stats_get(RXTX_PORT, &stats);
166 if (stats.ipackets != 0 || stats.opackets != 0 ||
167 stats.ibytes != 0 || stats.obytes != 0 ||
168 stats.ierrors != 0 || stats.oerrors != 0) {
169 printf("Error: RXTX port stats are not zero\n");
173 /* send and receive 1 packet and check for stats update */
174 if (rte_eth_tx_burst(RXTX_PORT, 0, &pbuf, 1) != 1) {
175 printf("Error sending packet to RXTX port\n");
178 if (rte_eth_rx_burst(RXTX_PORT, 0, &pbuf, 1) != 1) {
179 printf("Error receiving packet from RXTX port\n");
183 rte_eth_stats_get(RXTX_PORT, &stats);
184 if (stats.ipackets != 1 || stats.opackets != 1 ||
185 stats.ibytes != 0 || stats.obytes != 0 ||
186 stats.ierrors != 0 || stats.oerrors != 0) {
187 printf("Error: RXTX port stats are not as expected\n");
194 test_stats_reset(void)
196 struct rte_eth_stats stats;
197 struct rte_mbuf buf, *pbuf = &buf;
199 printf("Testing ring PMD stats reset\n");
201 rte_eth_stats_reset(RXTX_PORT);
203 /* check stats of RXTX port, should all be zero */
204 rte_eth_stats_get(RXTX_PORT, &stats);
205 if (stats.ipackets != 0 || stats.opackets != 0 ||
206 stats.ibytes != 0 || stats.obytes != 0 ||
207 stats.ierrors != 0 || stats.oerrors != 0) {
208 printf("Error: RXTX port stats are not zero\n");
212 /* send and receive 1 packet and check for stats update */
213 if (rte_eth_tx_burst(RXTX_PORT, 0, &pbuf, 1) != 1) {
214 printf("Error sending packet to RXTX port\n");
218 if (rte_eth_rx_burst(RXTX_PORT, 0, &pbuf, 1) != 1) {
219 printf("Error receiving packet from RXTX port\n");
223 rte_eth_stats_get(RXTX_PORT, &stats);
224 if (stats.ipackets != 1 || stats.opackets != 1 ||
225 stats.ibytes != 0 || stats.obytes != 0 ||
226 stats.ierrors != 0 || stats.oerrors != 0) {
227 printf("Error: RXTX port stats are not as expected\n");
231 rte_eth_stats_reset(RXTX_PORT);
233 /* check stats of RXTX port, should all be zero */
234 rte_eth_stats_get(RXTX_PORT, &stats);
235 if (stats.ipackets != 0 || stats.opackets != 0 ||
236 stats.ibytes != 0 || stats.obytes != 0 ||
237 stats.ierrors != 0 || stats.oerrors != 0) {
238 printf("Error: RXTX port stats are not zero\n");
246 test_pmd_ring_pair_create_attach(void)
248 struct rte_eth_stats stats, stats2;
249 struct rte_mbuf buf, *pbuf = &buf;
250 struct rte_eth_conf null_conf;
252 if ((RXTX_PORT2 >= RTE_MAX_ETHPORTS) || (RXTX_PORT3 >= RTE_MAX_ETHPORTS)) {
253 printf(" TX/RX port exceed max eth ports\n");
256 if ((rte_eth_dev_configure(RXTX_PORT2, 1, 1, &null_conf) < 0)
257 || (rte_eth_dev_configure(RXTX_PORT3, 1, 1, &null_conf) < 0)) {
258 printf("Configure failed for RXTX port\n");
262 if ((rte_eth_tx_queue_setup(RXTX_PORT2, 0, RING_SIZE, SOCKET0, NULL) < 0)
263 || (rte_eth_tx_queue_setup(RXTX_PORT3, 0, RING_SIZE, SOCKET0, NULL) < 0)) {
264 printf("TX queue setup failed\n");
268 if ((rte_eth_rx_queue_setup(RXTX_PORT2, 0, RING_SIZE, SOCKET0, NULL, mp) < 0)
269 || (rte_eth_rx_queue_setup(RXTX_PORT3, 0, RING_SIZE, SOCKET0, NULL, mp) < 0)) {
270 printf("RX queue setup failed\n");
274 if ((rte_eth_dev_start(RXTX_PORT2) < 0)
275 || (rte_eth_dev_start(RXTX_PORT3) < 0)) {
276 printf("Error starting RXTX port\n");
281 * send and receive 1 packet (RXTX_PORT2 -> RXTX_PORT3)
282 * and check for stats update
284 if (rte_eth_tx_burst(RXTX_PORT2, 0, &pbuf, 1) != 1) {
285 printf("Error sending packet to RXTX port\n");
289 if (rte_eth_rx_burst(RXTX_PORT3, 0, &pbuf, 1) != 1) {
290 printf("Error receiving packet from RXTX port\n");
294 rte_eth_stats_get(RXTX_PORT2, &stats);
295 rte_eth_stats_get(RXTX_PORT3, &stats2);
296 if (stats.ipackets != 0 || stats.opackets != 1 ||
297 stats.ibytes != 0 || stats.obytes != 0 ||
298 stats.ierrors != 0 || stats.oerrors != 0) {
299 printf("Error: RXTX port stats are not as expected\n");
303 if (stats2.ipackets != 1 || stats2.opackets != 0 ||
304 stats2.ibytes != 0 || stats2.obytes != 0 ||
305 stats2.ierrors != 0 || stats2.oerrors != 0) {
306 printf("Error: RXTX port stats are not as expected\n");
311 * send and receive 1 packet (RXTX_PORT3 -> RXTX_PORT2)
312 * and check for stats update
314 if (rte_eth_tx_burst(RXTX_PORT3, 0, &pbuf, 1) != 1) {
315 printf("Error sending packet to RXTX port\n");
319 if (rte_eth_rx_burst(RXTX_PORT2, 0, &pbuf, 1) != 1) {
320 printf("Error receiving packet from RXTX port\n");
324 rte_eth_stats_get(RXTX_PORT2, &stats);
325 rte_eth_stats_get(RXTX_PORT3, &stats2);
326 if (stats.ipackets != 1 || stats.opackets != 1 ||
327 stats.ibytes != 0 || stats.obytes != 0 ||
328 stats.ierrors != 0 || stats.oerrors != 0) {
329 printf("Error: RXTX port stats are not as expected\n");
333 if (stats2.ipackets != 1 || stats2.opackets != 1 ||
334 stats2.ibytes != 0 || stats2.obytes != 0 ||
335 stats2.ierrors != 0 || stats2.oerrors != 0) {
336 printf("Error: RXTX port stats are not as expected\n");
341 * send and receive 1 packet (RXTX_PORT2 -> RXTX_PORT2)
342 * and check for stats update
344 if (rte_eth_tx_burst(RXTX_PORT2, 0, &pbuf, 1) != 1) {
345 printf("Error sending packet to RXTX port\n");
349 if (rte_eth_rx_burst(RXTX_PORT2, 0, &pbuf, 1) != 1) {
350 printf("Error receiving packet from RXTX port\n");
354 rte_eth_stats_get(RXTX_PORT2, &stats);
355 rte_eth_stats_get(RXTX_PORT3, &stats2);
356 if (stats.ipackets != 2 || stats.opackets != 2 ||
357 stats.ibytes != 0 || stats.obytes != 0 ||
358 stats.ierrors != 0 || stats.oerrors != 0) {
359 printf("Error: RXTX port stats are not as expected\n");
363 if (stats2.ipackets != 1 || stats2.opackets != 1 ||
364 stats2.ibytes != 0 || stats2.obytes != 0 ||
365 stats2.ierrors != 0 || stats2.oerrors != 0) {
366 printf("Error: RXTX port stats are not as expected\n");
371 * send and receive 1 packet (RXTX_PORT3 -> RXTX_PORT3)
372 * and check for stats update
374 if (rte_eth_tx_burst(RXTX_PORT3, 0, &pbuf, 1) != 1) {
375 printf("Error sending packet to RXTX port\n");
379 if (rte_eth_rx_burst(RXTX_PORT3, 0, &pbuf, 1) != 1) {
380 printf("Error receiving packet from RXTX port\n");
384 rte_eth_stats_get(RXTX_PORT2, &stats);
385 rte_eth_stats_get(RXTX_PORT3, &stats2);
386 if (stats.ipackets != 2 || stats.opackets != 2 ||
387 stats.ibytes != 0 || stats.obytes != 0 ||
388 stats.ierrors != 0 || stats.oerrors != 0) {
389 printf("Error: RXTX port stats are not as expected\n");
393 if (stats2.ipackets != 2 || stats2.opackets != 2 ||
394 stats2.ibytes != 0 || stats2.obytes != 0 ||
395 stats2.ierrors != 0 || stats2.oerrors != 0) {
396 printf("Error: RXTX port stats are not as expected\n");
400 rte_eth_dev_stop(RXTX_PORT2);
401 rte_eth_dev_stop(RXTX_PORT3);
409 mp = rte_mempool_create("mbuf_pool", NB_MBUF,
411 sizeof(struct rte_pktmbuf_pool_private),
412 rte_pktmbuf_pool_init, NULL,
413 rte_pktmbuf_init, NULL,
418 if ((TX_PORT >= RTE_MAX_ETHPORTS) || (RX_PORT >= RTE_MAX_ETHPORTS)\
419 || (RXTX_PORT >= RTE_MAX_ETHPORTS)) {
420 printf(" TX/RX port exceed max eth ports\n");
424 if (test_ethdev_configure() < 0)
427 if (test_send_basic_packets() < 0)
430 if (test_get_stats() < 0)
433 if (test_stats_reset() < 0)
436 rte_eth_dev_stop(RX_PORT);
437 rte_eth_dev_stop(TX_PORT);
438 rte_eth_dev_stop(RXTX_PORT);
440 if (test_pmd_ring_pair_create_attach() < 0)
446 static struct test_command ring_pmd_cmd = {
447 .command = "ring_pmd_autotest",
448 .callback = test_pmd_ring,
450 REGISTER_TEST_COMMAND(ring_pmd_cmd);