X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=app%2Ftest%2Ftest_pmd_ring.c;h=7490112ca3d42b0ae405a1ad4a688ad52953436f;hb=c11f17d7f913ed306bc4296c8b555d4b0267b390;hp=1fe38fa658fddcf9e61671db06745d2572b859ec;hpb=61934c0956d4816cf4bdb797f943264b9f476095;p=dpdk.git diff --git a/app/test/test_pmd_ring.c b/app/test/test_pmd_ring.c index 1fe38fa658..7490112ca3 100644 --- a/app/test/test_pmd_ring.c +++ b/app/test/test_pmd_ring.c @@ -1,13 +1,13 @@ /*- * BSD LICENSE - * + * * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright @@ -17,7 +17,7 @@ * * Neither the name of Intel Corporation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -32,25 +32,18 @@ */ #include "test.h" -#ifdef RTE_LIBRTE_PMD_RING - #include #include #include -/* two test rings, r1 is used by two ports, r2 just by one */ -static struct rte_ring *r1[2], *r2; - static struct rte_mempool *mp; -static uint8_t start_idx; /* will store the port id of the first of our new ports */ - -#define TX_PORT (uint8_t)(start_idx + 1) -#define RX_PORT (uint8_t)(start_idx + 2) -#define RXTX_PORT (uint8_t)(start_idx + 3) -#define RXTX_PORT2 (uint8_t)(start_idx + 4) -#define RXTX_PORT4 (uint8_t)(start_idx + 6) -#define RXTX_PORT5 (uint8_t)(start_idx + 7) + +#define TX_PORT 0 +#define RX_PORT 1 +#define RXTX_PORT 2 +#define RXTX_PORT2 3 +#define RXTX_PORT3 4 #define SOCKET0 0 #define RING_SIZE 256 @@ -65,7 +58,7 @@ test_ethdev_configure(void) struct rte_eth_link link; memset(&null_conf, 0, sizeof(struct rte_eth_conf)); - + if ((TX_PORT >= RTE_MAX_ETHPORTS) || (RX_PORT >= RTE_MAX_ETHPORTS)\ || (RXTX_PORT >= RTE_MAX_ETHPORTS)) { printf(" TX/RX port exceed max eth ports\n"); @@ -86,7 +79,7 @@ test_ethdev_configure(void) return -1; } if (rte_eth_dev_configure(RXTX_PORT, 1, 1, &null_conf) < 0) { - printf("Configure failed for RX port\n"); + printf("Configure failed for RXTX port\n"); return -1; } @@ -206,7 +199,7 @@ test_stats_reset(void) printf("Testing ring PMD stats reset\n"); rte_eth_stats_reset(RXTX_PORT); - + /* check stats of RXTX port, should all be zero */ rte_eth_stats_get(RXTX_PORT, &stats); if (stats.ipackets != 0 || stats.opackets != 0 || @@ -236,7 +229,7 @@ test_stats_reset(void) } rte_eth_stats_reset(RXTX_PORT); - + /* check stats of RXTX port, should all be zero */ rte_eth_stats_get(RXTX_PORT, &stats); if (stats.ipackets != 0 || stats.opackets != 0 || @@ -249,216 +242,170 @@ test_stats_reset(void) return 0; } -static int -test_pmd_ring_init(void) +static int +test_pmd_ring_pair_create_attach(void) { - struct rte_eth_stats stats; + struct rte_eth_stats stats, stats2; struct rte_mbuf buf, *pbuf = &buf; struct rte_eth_conf null_conf; - printf("Testing ring pmd init\n"); - - if (RXTX_PORT2 >= RTE_MAX_ETHPORTS) { + if ((RXTX_PORT2 >= RTE_MAX_ETHPORTS) || (RXTX_PORT3 >= RTE_MAX_ETHPORTS)) { printf(" TX/RX port exceed max eth ports\n"); return -1; } - if (rte_eth_dev_configure(RXTX_PORT2, 1, 1, &null_conf) < 0) { + if ((rte_eth_dev_configure(RXTX_PORT2, 1, 1, &null_conf) < 0) + || (rte_eth_dev_configure(RXTX_PORT3, 1, 1, &null_conf) < 0)) { printf("Configure failed for RXTX port\n"); return -1; } - if (rte_eth_tx_queue_setup(RXTX_PORT2, 0, RING_SIZE, SOCKET0, NULL) < 0) { + if ((rte_eth_tx_queue_setup(RXTX_PORT2, 0, RING_SIZE, SOCKET0, NULL) < 0) + || (rte_eth_tx_queue_setup(RXTX_PORT3, 0, RING_SIZE, SOCKET0, NULL) < 0)) { printf("TX queue setup failed\n"); return -1; } - if (rte_eth_rx_queue_setup(RXTX_PORT2, 0, RING_SIZE, SOCKET0, - NULL, mp) < 0) { + if ((rte_eth_rx_queue_setup(RXTX_PORT2, 0, RING_SIZE, SOCKET0, NULL, mp) < 0) + || (rte_eth_rx_queue_setup(RXTX_PORT3, 0, RING_SIZE, SOCKET0, NULL, mp) < 0)) { printf("RX queue setup failed\n"); return -1; } - if (rte_eth_dev_start(RXTX_PORT2) < 0) { - printf("Error starting RX port\n"); + if ((rte_eth_dev_start(RXTX_PORT2) < 0) + || (rte_eth_dev_start(RXTX_PORT3) < 0)) { + printf("Error starting RXTX port\n"); return -1; } - /* send and receive 1 packet and check for stats update */ + /* + * send and receive 1 packet (RXTX_PORT2 -> RXTX_PORT3) + * and check for stats update + */ if (rte_eth_tx_burst(RXTX_PORT2, 0, &pbuf, 1) != 1) { printf("Error sending packet to RXTX port\n"); return -1; } - if (rte_eth_rx_burst(RXTX_PORT2, 0, &pbuf, 1) != 1) { + if (rte_eth_rx_burst(RXTX_PORT3, 0, &pbuf, 1) != 1) { printf("Error receiving packet from RXTX port\n"); return -1; } rte_eth_stats_get(RXTX_PORT2, &stats); - if (stats.ipackets != 1 || stats.opackets != 1 || + rte_eth_stats_get(RXTX_PORT3, &stats2); + if (stats.ipackets != 0 || stats.opackets != 1 || stats.ibytes != 0 || stats.obytes != 0 || stats.ierrors != 0 || stats.oerrors != 0) { printf("Error: RXTX port stats are not as expected\n"); return -1; } - rte_eth_dev_stop(RXTX_PORT2); - - return 0; -} - -static int -test_pmd_ring_pair_create(void) -{ - struct rte_eth_stats stats, stats2; - struct rte_mbuf buf, *pbuf = &buf; - struct rte_eth_conf null_conf; - - if ((RXTX_PORT4 >= RTE_MAX_ETHPORTS) || (RXTX_PORT5 >= RTE_MAX_ETHPORTS)) { - printf(" TX/RX port exceed max eth ports\n"); - return -1; - } - if ((rte_eth_dev_configure(RXTX_PORT4, 1, 1, &null_conf) < 0) - || (rte_eth_dev_configure(RXTX_PORT5, 1, 1, &null_conf) < 0)) { - printf("Configure failed for RXTX port\n"); - return -1; - } - - if ((rte_eth_tx_queue_setup(RXTX_PORT4, 0, RING_SIZE, SOCKET0, NULL) < 0) - || (rte_eth_tx_queue_setup(RXTX_PORT5, 0, RING_SIZE, SOCKET0, NULL) < 0)) { - printf("TX queue setup failed\n"); - return -1; - } - - if ((rte_eth_rx_queue_setup(RXTX_PORT4, 0, RING_SIZE, SOCKET0, NULL, mp) < 0) - || (rte_eth_rx_queue_setup(RXTX_PORT5, 0, RING_SIZE, SOCKET0, NULL, mp) < 0)) { - printf("RX queue setup failed\n"); - return -1; - } - - if ((rte_eth_dev_start(RXTX_PORT4) < 0) - || (rte_eth_dev_start(RXTX_PORT5) < 0)) { - printf("Error starting RXTX port\n"); + if (stats2.ipackets != 1 || stats2.opackets != 0 || + stats2.ibytes != 0 || stats2.obytes != 0 || + stats2.ierrors != 0 || stats2.oerrors != 0) { + printf("Error: RXTX port stats are not as expected\n"); return -1; } - /* send and receive 1 packet and check for stats update */ - if (rte_eth_tx_burst(RXTX_PORT4, 0, &pbuf, 1) != 1) { + /* + * send and receive 1 packet (RXTX_PORT3 -> RXTX_PORT2) + * and check for stats update + */ + if (rte_eth_tx_burst(RXTX_PORT3, 0, &pbuf, 1) != 1) { printf("Error sending packet to RXTX port\n"); return -1; } - if (rte_eth_rx_burst(RXTX_PORT5, 0, &pbuf, 1) != 1) { + if (rte_eth_rx_burst(RXTX_PORT2, 0, &pbuf, 1) != 1) { printf("Error receiving packet from RXTX port\n"); return -1; } - rte_eth_stats_get(RXTX_PORT4, &stats); - rte_eth_stats_get(RXTX_PORT5, &stats2); - if (stats.ipackets != 0 || stats.opackets != 1 || + rte_eth_stats_get(RXTX_PORT2, &stats); + rte_eth_stats_get(RXTX_PORT3, &stats2); + if (stats.ipackets != 1 || stats.opackets != 1 || stats.ibytes != 0 || stats.obytes != 0 || stats.ierrors != 0 || stats.oerrors != 0) { printf("Error: RXTX port stats are not as expected\n"); return -1; } - if (stats2.ipackets != 1 || stats2.opackets != 0 || + if (stats2.ipackets != 1 || stats2.opackets != 1 || stats2.ibytes != 0 || stats2.obytes != 0 || stats2.ierrors != 0 || stats2.oerrors != 0) { printf("Error: RXTX port stats are not as expected\n"); return -1; } - rte_eth_dev_stop(RXTX_PORT4); - rte_eth_dev_stop(RXTX_PORT5); - - return 0; -} - -static int -test_pmd_ring_pair_attach(void) -{ - struct rte_eth_stats stats, stats2; - struct rte_mbuf buf, *pbuf = &buf; - struct rte_eth_conf null_conf; - - if ((RXTX_PORT4 >= RTE_MAX_ETHPORTS) || (RXTX_PORT5 >= RTE_MAX_ETHPORTS)) { - printf(" TX/RX port exceed max eth ports\n"); - return -1; - } - if ((rte_eth_dev_configure(RXTX_PORT4, 1, 1, &null_conf) < 0) - || (rte_eth_dev_configure(RXTX_PORT5, 1, 1, &null_conf) < 0)) { - printf("Configure failed for RXTX port\n"); + /* + * send and receive 1 packet (RXTX_PORT2 -> RXTX_PORT2) + * and check for stats update + */ + if (rte_eth_tx_burst(RXTX_PORT2, 0, &pbuf, 1) != 1) { + printf("Error sending packet to RXTX port\n"); return -1; } - if ((rte_eth_tx_queue_setup(RXTX_PORT4, 0, RING_SIZE, SOCKET0, NULL) < 0) - || (rte_eth_tx_queue_setup(RXTX_PORT5, 0, RING_SIZE, SOCKET0, NULL) < 0)) { - printf("TX queue setup failed\n"); + if (rte_eth_rx_burst(RXTX_PORT2, 0, &pbuf, 1) != 1) { + printf("Error receiving packet from RXTX port\n"); return -1; } - if ((rte_eth_rx_queue_setup(RXTX_PORT4, 0, RING_SIZE, SOCKET0, NULL, mp) < 0) - || (rte_eth_rx_queue_setup(RXTX_PORT5, 0, RING_SIZE, SOCKET0, NULL, mp) < 0)) { - printf("RX queue setup failed\n"); + rte_eth_stats_get(RXTX_PORT2, &stats); + rte_eth_stats_get(RXTX_PORT3, &stats2); + if (stats.ipackets != 2 || stats.opackets != 2 || + stats.ibytes != 0 || stats.obytes != 0 || + stats.ierrors != 0 || stats.oerrors != 0) { + printf("Error: RXTX port stats are not as expected\n"); return -1; } - if ((rte_eth_dev_start(RXTX_PORT4) < 0) - || (rte_eth_dev_start(RXTX_PORT5) < 0)) { - printf("Error starting RXTX port\n"); + if (stats2.ipackets != 1 || stats2.opackets != 1 || + stats2.ibytes != 0 || stats2.obytes != 0 || + stats2.ierrors != 0 || stats2.oerrors != 0) { + printf("Error: RXTX port stats are not as expected\n"); return -1; } - - rte_eth_stats_reset(RXTX_PORT4); - rte_eth_stats_reset(RXTX_PORT5); - /* send and receive 1 packet and check for stats update */ - if (rte_eth_tx_burst(RXTX_PORT4, 0, &pbuf, 1) != 1) { + /* + * send and receive 1 packet (RXTX_PORT3 -> RXTX_PORT3) + * and check for stats update + */ + if (rte_eth_tx_burst(RXTX_PORT3, 0, &pbuf, 1) != 1) { printf("Error sending packet to RXTX port\n"); return -1; } - if (rte_eth_rx_burst(RXTX_PORT5, 0, &pbuf, 1) != 1) { + + if (rte_eth_rx_burst(RXTX_PORT3, 0, &pbuf, 1) != 1) { printf("Error receiving packet from RXTX port\n"); return -1; } - rte_eth_stats_get(RXTX_PORT4, &stats); - rte_eth_stats_get(RXTX_PORT5, &stats2); - if (stats.ipackets != 0 || stats.opackets != 1 || + rte_eth_stats_get(RXTX_PORT2, &stats); + rte_eth_stats_get(RXTX_PORT3, &stats2); + if (stats.ipackets != 2 || stats.opackets != 2 || stats.ibytes != 0 || stats.obytes != 0 || stats.ierrors != 0 || stats.oerrors != 0) { printf("Error: RXTX port stats are not as expected\n"); return -1; } - if (stats2.ipackets != 1 || stats2.opackets != 0 || + if (stats2.ipackets != 2 || stats2.opackets != 2 || stats2.ibytes != 0 || stats2.obytes != 0 || stats2.ierrors != 0 || stats2.oerrors != 0) { printf("Error: RXTX port stats are not as expected\n"); return -1; } - rte_eth_dev_stop(RXTX_PORT4); - rte_eth_dev_stop(RXTX_PORT5); - + rte_eth_dev_stop(RXTX_PORT2); + rte_eth_dev_stop(RXTX_PORT3); + return 0; } -int +static int test_pmd_ring(void) { - r1[0] = rte_ring_create("R1", RING_SIZE, 0, 0); - r1[1] = rte_ring_create("R2", RING_SIZE, 0, 0); - if (r1[0] == NULL && (r1[0] = rte_ring_lookup("R1")) == NULL) - return -1; - if (r1[1] == NULL && (r1[1] = rte_ring_lookup("R2")) == NULL) - return -1; - - r2 = rte_ring_create("R3", RING_SIZE, 0, RING_F_SP_ENQ|RING_F_SC_DEQ); - if (r2 == NULL && (r2 = rte_ring_lookup("R3")) == NULL) - return -1; - mp = rte_mempool_create("mbuf_pool", NB_MBUF, MBUF_SIZE, 32, sizeof(struct rte_pktmbuf_pool_private), @@ -468,8 +415,6 @@ test_pmd_ring(void) if (mp == NULL) return -1; - start_idx = rte_eth_dev_count(); - if ((TX_PORT >= RTE_MAX_ETHPORTS) || (RX_PORT >= RTE_MAX_ETHPORTS)\ || (RXTX_PORT >= RTE_MAX_ETHPORTS)) { printf(" TX/RX port exceed max eth ports\n"); @@ -492,24 +437,14 @@ test_pmd_ring(void) rte_eth_dev_stop(TX_PORT); rte_eth_dev_stop(RXTX_PORT); - if (test_pmd_ring_init() < 0) + if (test_pmd_ring_pair_create_attach() < 0) return -1; - if (test_pmd_ring_pair_create() < 0) - return -1; - - if (test_pmd_ring_pair_attach() < 0) - return -1; return 0; } -#else - -int -test_pmd_ring(void) -{ - return 0; -} - -#endif - +static struct test_command ring_pmd_cmd = { + .command = "ring_pmd_autotest", + .callback = test_pmd_ring, +}; +REGISTER_TEST_COMMAND(ring_pmd_cmd);