Hi, The commit 6e20a08 ("test/pmd_ring: restructure and cleanup") has already fixed this issue. Abandon this one.
Thanks, Phil Yang > -----Original Message----- > From: dev <dev-boun...@dpdk.org> On Behalf Of Phil Yang > Sent: Friday, October 19, 2018 7:12 PM > To: dev@dpdk.org > Cc: nd <n...@arm.com> > Subject: [dpdk-dev] [PATCH v2] test/pmd_ring: release ring resources after > test > > Need to release the port and the ring resources after test. Otherwise, it will > cause failure to allocate memory when reentry the test. > > Fixes: 4ea3801 ("app/test: fix ring unit test") > > Signed-off-by: Phil Yang <phil.y...@arm.com> > Reviewed-by: Gavin Hu <gavin...@arm.com> > --- > test/test/test_pmd_ring.c | 100 ++++++++++++++++++++++++++++---------------- > -- > 1 file changed, 62 insertions(+), 38 deletions(-) > > diff --git a/test/test/test_pmd_ring.c b/test/test/test_pmd_ring.c index > 19d7d20..f332df9 100644 > --- a/test/test/test_pmd_ring.c > +++ b/test/test/test_pmd_ring.c > @@ -7,15 +7,16 @@ > > #include <rte_eth_ring.h> > #include <rte_ethdev.h> > - > -static struct rte_mempool *mp; > -static int tx_porta, rx_portb, rxtx_portc, rxtx_portd, rxtx_porte; > +#include <rte_bus_vdev.h> > > #define SOCKET0 0 > #define RING_SIZE 256 > #define NUM_RINGS 2 > #define NB_MBUF 512 > +#define NUM_PORTS 5 > > +static struct rte_mempool *mp; > +static int ports[NUM_PORTS]; > > static int > test_ethdev_configure_port(int port) > @@ -64,18 +65,19 @@ test_send_basic_packets(void) > struct rte_mbuf *pbufs[RING_SIZE]; > int i; > > - printf("Testing send and receive RING_SIZE/2 packets (tx_porta -> > rx_portb)\n"); > + printf("Testing send and receive RING_SIZE/2 " > + "packets (ports[0] -> ports[1])\n"); > > for (i = 0; i < RING_SIZE/2; i++) > pbufs[i] = &bufs[i]; > > - if (rte_eth_tx_burst(tx_porta, 0, pbufs, RING_SIZE/2) < RING_SIZE/2) { > - printf("Failed to transmit packet burst port %d\n", tx_porta); > + if (rte_eth_tx_burst(ports[0], 0, pbufs, RING_SIZE/2) < RING_SIZE/2) { > + printf("Failed to transmit packet burst port %d\n", ports[0]); > return -1; > } > > - if (rte_eth_rx_burst(rx_portb, 0, pbufs, RING_SIZE) != RING_SIZE/2) { > - printf("Failed to receive packet burst on port %d\n", rx_portb); > + if (rte_eth_rx_burst(ports[1], 0, pbufs, RING_SIZE) != RING_SIZE/2) { > + printf("Failed to receive packet burst on port %d\n", ports[1]); > return -1; > } > > @@ -95,7 +97,8 @@ test_send_basic_packets_port(int port) > struct rte_mbuf *pbufs[RING_SIZE]; > int i; > > - printf("Testing send and receive RING_SIZE/2 packets (cmdl_port0 -> > cmdl_port0)\n"); > + printf("Testing send and receive RING_SIZE/2 packets" > + "(cmdl_port0 -> cmdl_port0)\n"); > > for (i = 0; i < RING_SIZE/2; i++) > pbufs[i] = &bufs[i]; > @@ -232,8 +235,10 @@ test_pmd_ring_pair_create_attach(int portd, int porte) > return -1; > } > > - if ((rte_eth_rx_queue_setup(portd, 0, RING_SIZE, SOCKET0, NULL, mp) < > 0) > - || (rte_eth_rx_queue_setup(porte, 0, RING_SIZE, SOCKET0, > NULL, mp) < 0)) { > + if ((rte_eth_rx_queue_setup(portd, 0, RING_SIZE, > + SOCKET0, NULL, mp) < 0) > + || (rte_eth_rx_queue_setup(porte, 0, RING_SIZE, > + SOCKET0, NULL, mp) < 0)) { > printf("RX queue setup failed\n"); > return -1; > } > @@ -388,9 +393,6 @@ test_pmd_ring_pair_create_attach(int portd, int porte) > return -1; > } > > - rte_eth_dev_stop(portd); > - rte_eth_dev_stop(porte); > - > return 0; > } > > @@ -400,6 +402,7 @@ test_pmd_ring(void) > struct rte_ring *rxtx[NUM_RINGS]; > int port, cmdl_port0 = -1; > uint8_t nb_ports; > + char port_name[RTE_ETH_NAME_MAX_LEN]; > > nb_ports = rte_eth_dev_count_avail(); > printf("nb_ports=%d\n", (int)nb_ports); @@ -409,29 +412,36 @@ > test_pmd_ring(void) > * > * Test with the command line option --vdev=net_ring0 to test > rte_pmd_ring_devinit. > */ > - rxtx[0] = rte_ring_create("R0", RING_SIZE, SOCKET0, > RING_F_SP_ENQ|RING_F_SC_DEQ); > + rxtx[0] = rte_ring_create("R0", RING_SIZE, SOCKET0, > + RING_F_SP_ENQ|RING_F_SC_DEQ); > if (rxtx[0] == NULL) { > printf("rte_ring_create R0 failed"); > return -1; > } > > - rxtx[1] = rte_ring_create("R1", RING_SIZE, SOCKET0, > RING_F_SP_ENQ|RING_F_SC_DEQ); > + rxtx[1] = rte_ring_create("R1", RING_SIZE, SOCKET0, > + RING_F_SP_ENQ|RING_F_SC_DEQ); > if (rxtx[1] == NULL) { > printf("rte_ring_create R1 failed"); > return -1; > } > > - tx_porta = rte_eth_from_rings("net_ringa", rxtx, NUM_RINGS, rxtx, > NUM_RINGS, SOCKET0); > - rx_portb = rte_eth_from_rings("net_ringb", rxtx, NUM_RINGS, rxtx, > NUM_RINGS, SOCKET0); > - rxtx_portc = rte_eth_from_rings("net_ringc", rxtx, NUM_RINGS, rxtx, > NUM_RINGS, SOCKET0); > - rxtx_portd = rte_eth_from_rings("net_ringd", rxtx, NUM_RINGS, rxtx, > NUM_RINGS, SOCKET0); > - rxtx_porte = rte_eth_from_rings("net_ringe", rxtx, NUM_RINGS, rxtx, > NUM_RINGS, SOCKET0); > + ports[0] = rte_eth_from_rings("net_ringa", rxtx, > + NUM_RINGS, rxtx, NUM_RINGS, SOCKET0); > + ports[1] = rte_eth_from_rings("net_ringb", rxtx, > + NUM_RINGS, rxtx, NUM_RINGS, SOCKET0); > + ports[2] = rte_eth_from_rings("net_ringc", rxtx, > + NUM_RINGS, rxtx, NUM_RINGS, SOCKET0); > + ports[3] = rte_eth_from_rings("net_ringd", rxtx, > + NUM_RINGS, rxtx, NUM_RINGS, SOCKET0); > + ports[4] = rte_eth_from_rings("net_ringe", rxtx, > + NUM_RINGS, rxtx, NUM_RINGS, SOCKET0); > > - printf("tx_porta=%d rx_portb=%d rxtx_portc=%d rxtx_portd=%d > rxtx_porte=%d\n", > - tx_porta, rx_portb, rxtx_portc, rxtx_portd, rxtx_porte); > + printf("ports[0]=%d ports[1]=%d ports[2]=%d ports[3]=%d > ports[4]=%d\n", > + ports[0], ports[1], ports[2], ports[3], ports[4]); > > - if ((tx_porta == -1) || (rx_portb == -1) || (rxtx_portc == -1) > - || (rxtx_portd == -1) || (rxtx_porte == -1)) { > + if ((ports[0] == -1) || (ports[1] == -1) || (ports[2] == -1) > + || (ports[3] == -1) || (ports[4] == -1)) { > printf("rte_eth_from rings failed\n"); > return -1; > } > @@ -441,37 +451,35 @@ test_pmd_ring(void) > if (mp == NULL) > return -1; > > - if ((tx_porta >= RTE_MAX_ETHPORTS) || (rx_portb >= > RTE_MAX_ETHPORTS) > - || (rxtx_portc >= RTE_MAX_ETHPORTS) > - || (rxtx_portd >= RTE_MAX_ETHPORTS) > - || (rxtx_porte >= RTE_MAX_ETHPORTS)) { > + if ((ports[0] >= RTE_MAX_ETHPORTS) > + || (ports[1] >= RTE_MAX_ETHPORTS) > + || (ports[2] >= RTE_MAX_ETHPORTS) > + || (ports[3] >= RTE_MAX_ETHPORTS) > + || (ports[4] >= RTE_MAX_ETHPORTS)) { > printf(" port exceed max eth ports\n"); > return -1; > } > > - if (test_ethdev_configure_port(tx_porta) < 0) > + if (test_ethdev_configure_port(ports[0]) < 0) > return -1; > > - if (test_ethdev_configure_port(rx_portb) < 0) > + if (test_ethdev_configure_port(ports[1]) < 0) > return -1; > > - if (test_ethdev_configure_port(rxtx_portc) < 0) > + if (test_ethdev_configure_port(ports[2]) < 0) > return -1; > > if (test_send_basic_packets() < 0) > return -1; > > - if (test_get_stats(rxtx_portc) < 0) > + if (test_get_stats(ports[2]) < 0) > return -1; > > - if (test_stats_reset(rxtx_portc) < 0) > + if (test_stats_reset(ports[2]) < 0) > return -1; > > - rte_eth_dev_stop(tx_porta); > - rte_eth_dev_stop(rx_portb); > - rte_eth_dev_stop(rxtx_portc); > > - if (test_pmd_ring_pair_create_attach(rxtx_portd, rxtx_porte) < 0) > + if (test_pmd_ring_pair_create_attach(ports[3], ports[4]) < 0) > return -1; > > /* find a port created with the --vdev=net_ring0 command line option */ > @@ -495,7 +503,23 @@ test_pmd_ring(void) > if (test_get_stats(cmdl_port0) < 0) > return -1; > rte_eth_dev_stop(cmdl_port0); > + rte_eth_dev_get_name_by_port(cmdl_port0, port_name); > + rte_vdev_uninit(port_name); > } > + > + /* release ports and rings resources */ > + if (mp != NULL) > + rte_mempool_free(mp); > + > + for (int i = 0; i < NUM_PORTS; i++) { > + rte_eth_dev_stop(ports[i]); > + rte_eth_dev_get_name_by_port(ports[i], port_name); > + rte_vdev_uninit(port_name); > + } > + > + for (int i = 0; i < NUM_RINGS; i++) > + rte_ring_free(rxtx[i]); > + > return 0; > } > > -- > 2.7.4