* [dpdk-dev] [PATCH] add sample functions for packet forwarding @ 2018-07-06 17:07 Jananee Parthasarathy 2018-07-10 9:53 ` Pattan, Reshma 2018-07-12 8:53 ` [dpdk-dev] [PATCH v2] " Jananee Parthasarathy 0 siblings, 2 replies; 37+ messages in thread From: Jananee Parthasarathy @ 2018-07-06 17:07 UTC (permalink / raw) To: dev Cc: remy.horton, reshma.pattan, Jananee Parthasarathy, Chaitanya Babu Talluri From: Jananee Parthasarathy <jananeex.m.parthasarathy@intel.com> Add sample test functions for packet forwarding. These can be used for unit test cases for LatencyStats and BitrateStats libraries. Signed-off-by: Chaitanya Babu Talluri <tallurix.chaitanya.babu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> --- test/test/Makefile | 1 + test/test/sample_packet_forward.c | 80 +++++++++++++++++++++++++++++++++++++++ test/test/sample_packet_forward.h | 22 +++++++++++ 3 files changed, 103 insertions(+) create mode 100644 test/test/sample_packet_forward.c create mode 100644 test/test/sample_packet_forward.h diff --git a/test/test/Makefile b/test/test/Makefile index eccc8efcf..1e69f37a1 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -133,6 +133,7 @@ SRCS-y += test_version.c SRCS-y += test_func_reentrancy.c SRCS-y += test_service_cores.c +SRCS-y += sample_packet_forward.c SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline.c SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline_num.c diff --git a/test/test/sample_packet_forward.c b/test/test/sample_packet_forward.c new file mode 100644 index 000000000..6f66b83f8 --- /dev/null +++ b/test/test/sample_packet_forward.c @@ -0,0 +1,80 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include <string.h> +#include <errno.h> +#include <time.h> + +#include <rte_memcpy.h> +#include <rte_common.h> +#include <rte_eth_ring.h> +#include <rte_ethdev.h> + +#include "sample_packet_forward.h" +#include "test.h" +#include <rte_mbuf.h> + +#define NB_MBUF 512 + +static struct rte_mempool *mp; +uint16_t tx_portid, rx_portid; + +/* Sample test to create virtual rings and tx,rx portid from rings */ +int +test_ring_setup(void) +{ + uint16_t socket_id = rte_socket_id(); + struct rte_ring *rxtx[NUM_RINGS]; + rxtx[0] = rte_ring_create("R0", RING_SIZE, socket_id, + RING_F_SP_ENQ|RING_F_SC_DEQ); + if (rxtx[0] == NULL) { + printf("%s() line %u: rte_ring_create R0 failed", + __func__, __LINE__); + return TEST_FAILED; + } + rxtx[1] = rte_ring_create("R1", RING_SIZE, socket_id, + RING_F_SP_ENQ|RING_F_SC_DEQ); + if (rxtx[1] == NULL) { + printf("%s() line %u: rte_ring_create R1 failed", + __func__, __LINE__); + return TEST_FAILED; + } + tx_portid = rte_eth_from_rings("net_ringa", rxtx, NUM_RINGS, rxtx, + NUM_RINGS, SOCKET0); + rx_portid = rte_eth_from_rings("net_ringb", rxtx, NUM_RINGS, rxtx, + NUM_RINGS, SOCKET0); + + return TEST_SUCCESS; +} + +/* Sample test to forward packets using virtual portids */ +int +test_packet_forward(void) +{ + struct rte_mbuf *pbuf[NUM_PACKETS]; + + mp = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF, 32, 0, + RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); + if (mp == NULL) + return -1; + if (rte_pktmbuf_alloc_bulk(mp, pbuf, NUM_PACKETS) != 0) + printf("%s() line %u: rte_pktmbuf_alloc_bulk failed" + , __func__, __LINE__); + /* send and receive packet and check for stats update */ + if (rte_eth_tx_burst(tx_portid, 0, pbuf, NUM_PACKETS) != + NUM_PACKETS) { + printf("%s() line %u: Error sending packet to" + " port %d\n", __func__, __LINE__, + tx_portid); + return TEST_FAILED; + } + if (rte_eth_rx_burst(rx_portid, 0, pbuf, NUM_PACKETS) != + NUM_PACKETS) { + printf("%s() line %u: Error receiving packet from" + " port %d\n", __func__, __LINE__, + rx_portid); + return TEST_FAILED; + } + return TEST_SUCCESS; +} diff --git a/test/test/sample_packet_forward.h b/test/test/sample_packet_forward.h new file mode 100644 index 000000000..464f97c33 --- /dev/null +++ b/test/test/sample_packet_forward.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#ifndef _SAMPLE_PACKET_FORWARD_H_ +#define _SAMPLE_PACKET_FORWARD_H_ + +/* MACROS to support virtual ring creation */ +#define SOCKET0 0 +#define RING_SIZE 256 +#define NUM_RINGS 2 + +#define NUM_PACKETS 10 + +/* Sample test to create virtual rings and tx,rx portid from rings */ +int test_ring_setup(void); + +/* Sample test to forward packet using virtual port id */ +int test_packet_forward(void); + +#endif /* _SAMPLE_PACKET_FORWARD_H_ */ + -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [dpdk-dev] [PATCH] add sample functions for packet forwarding 2018-07-06 17:07 [dpdk-dev] [PATCH] add sample functions for packet forwarding Jananee Parthasarathy @ 2018-07-10 9:53 ` Pattan, Reshma 2018-07-12 8:53 ` [dpdk-dev] [PATCH v2] " Jananee Parthasarathy 1 sibling, 0 replies; 37+ messages in thread From: Pattan, Reshma @ 2018-07-10 9:53 UTC (permalink / raw) To: Parthasarathy, JananeeX M, dev; +Cc: Horton, Remy, Chaitanya Babu, TalluriX Hi Jananee, > -----Original Message----- > From: Parthasarathy, JananeeX M > Sent: Friday, July 6, 2018 6:07 PM > To: dev@dpdk.org > Cc: Horton, Remy <remy.horton@intel.com>; Pattan, Reshma > <reshma.pattan@intel.com>; Parthasarathy, JananeeX M > <jananeex.m.parthasarathy@intel.com>; Chaitanya Babu, TalluriX > <tallurix.chaitanya.babu@intel.com> > Subject: [PATCH] add sample functions for packet forwarding > > From: Jananee Parthasarathy <jananeex.m.parthasarathy@intel.com> > > Add sample test functions for packet forwarding. > These can be used for unit test cases for LatencyStats and BitrateStats > libraries. > > Signed-off-by: Chaitanya Babu Talluri <tallurix.chaitanya.babu@intel.com> > Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> > --- > a/test/test/sample_packet_forward.c b/test/test/sample_packet_forward.c > new file mode 100644 > index 000000000..6f66b83f8 > --- /dev/null > +++ b/test/test/sample_packet_forward.c > @@ -0,0 +1,80 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2018 Intel Corporation > + */ > +int > +test_ring_setup(void) > +{ > + uint16_t socket_id = rte_socket_id(); > + rxtx[1] = rte_ring_create("R1", RING_SIZE, socket_id, > + RING_F_SP_ENQ|RING_F_SC_DEQ); > + if (rxtx[1] == NULL) { > + printf("%s() line %u: rte_ring_create R1 failed", > + __func__, __LINE__); > + return TEST_FAILED; > + } > + tx_portid = rte_eth_from_rings("net_ringa", rxtx, NUM_RINGS, rxtx, > + NUM_RINGS, SOCKET0); > + rx_portid = rte_eth_from_rings("net_ringb", rxtx, NUM_RINGS, rxtx, > + NUM_RINGS, SOCKET0); > + Here also socket_id should be used, so u can remove SOCKET0 and its macro. > diff --git a/test/test/sample_packet_forward.h > b/test/test/sample_packet_forward.h #define SOCKET0 0 This can be removed now as rte_socke_id() is used now. #define > +RING_SIZE 256 #define NUM_RINGS 2 Instead of NUM_RINGS, you can name it as NUM_QUEUES. You can have this value as 1, as you are using only 1 queue anyway in *tx_burst and rx_burst. Thanks, Reshma ^ permalink raw reply [flat|nested] 37+ messages in thread
* [dpdk-dev] [PATCH v2] add sample functions for packet forwarding 2018-07-06 17:07 [dpdk-dev] [PATCH] add sample functions for packet forwarding Jananee Parthasarathy 2018-07-10 9:53 ` Pattan, Reshma @ 2018-07-12 8:53 ` Jananee Parthasarathy 2018-07-12 16:00 ` Pattan, Reshma 2018-07-16 16:00 ` [dpdk-dev] [PATCH v3] test: " Jananee Parthasarathy 1 sibling, 2 replies; 37+ messages in thread From: Jananee Parthasarathy @ 2018-07-12 8:53 UTC (permalink / raw) To: dev Cc: remy.horton, reshma.pattan, Jananee Parthasarathy, Chaitanya Babu Talluri Add sample test functions for packet forwarding. These can be used for unit test cases for LatencyStats and BitrateStats libraries. Signed-off-by: Chaitanya Babu Talluri <tallurix.chaitanya.babu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> --- v2: SOCKET0 is removed and NUM_QUEUES is used accordingly --- test/test/Makefile | 1 + test/test/sample_packet_forward.c | 80 +++++++++++++++++++++++++++++++++++++++ test/test/sample_packet_forward.h | 22 +++++++++++ 3 files changed, 103 insertions(+) create mode 100644 test/test/sample_packet_forward.c create mode 100644 test/test/sample_packet_forward.h diff --git a/test/test/Makefile b/test/test/Makefile index eccc8efcf..1e69f37a1 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -133,6 +133,7 @@ SRCS-y += test_version.c SRCS-y += test_func_reentrancy.c SRCS-y += test_service_cores.c +SRCS-y += sample_packet_forward.c SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline.c SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline_num.c diff --git a/test/test/sample_packet_forward.c b/test/test/sample_packet_forward.c new file mode 100644 index 000000000..ec79f7e6e --- /dev/null +++ b/test/test/sample_packet_forward.c @@ -0,0 +1,80 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include <string.h> +#include <errno.h> +#include <time.h> + +#include <rte_memcpy.h> +#include <rte_common.h> +#include <rte_eth_ring.h> +#include <rte_ethdev.h> + +#include "sample_packet_forward.h" +#include "test.h" +#include <rte_mbuf.h> + +#define NB_MBUF 512 + +static struct rte_mempool *mp; +uint16_t tx_portid, rx_portid; + +/* Sample test to create virtual rings and tx,rx portid from rings */ +int +test_ring_setup(void) +{ + uint16_t socket_id = rte_socket_id(); + struct rte_ring *rxtx[NUM_RINGS]; + rxtx[0] = rte_ring_create("R0", RING_SIZE, socket_id, + RING_F_SP_ENQ|RING_F_SC_DEQ); + if (rxtx[0] == NULL) { + printf("%s() line %u: rte_ring_create R0 failed", + __func__, __LINE__); + return TEST_FAILED; + } + rxtx[1] = rte_ring_create("R1", RING_SIZE, socket_id, + RING_F_SP_ENQ|RING_F_SC_DEQ); + if (rxtx[1] == NULL) { + printf("%s() line %u: rte_ring_create R1 failed", + __func__, __LINE__); + return TEST_FAILED; + } + tx_portid = rte_eth_from_rings("net_ringa", rxtx, NUM_QUEUES, rxtx, + NUM_QUEUES, socket_id); + rx_portid = rte_eth_from_rings("net_ringb", rxtx, NUM_QUEUES, rxtx, + NUM_QUEUES, socket_id); + + return TEST_SUCCESS; +} + +/* Sample test to forward packets using virtual portids */ +int +test_packet_forward(void) +{ + struct rte_mbuf *pbuf[NUM_PACKETS]; + + mp = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF, 32, 0, + RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); + if (mp == NULL) + return -1; + if (rte_pktmbuf_alloc_bulk(mp, pbuf, NUM_PACKETS) != 0) + printf("%s() line %u: rte_pktmbuf_alloc_bulk failed" + , __func__, __LINE__); + /* send and receive packet and check for stats update */ + if (rte_eth_tx_burst(tx_portid, 0, pbuf, NUM_PACKETS) != + NUM_PACKETS) { + printf("%s() line %u: Error sending packet to" + " port %d\n", __func__, __LINE__, + tx_portid); + return TEST_FAILED; + } + if (rte_eth_rx_burst(rx_portid, 0, pbuf, NUM_PACKETS) != + NUM_PACKETS) { + printf("%s() line %u: Error receiving packet from" + " port %d\n", __func__, __LINE__, + rx_portid); + return TEST_FAILED; + } + return TEST_SUCCESS; +} diff --git a/test/test/sample_packet_forward.h b/test/test/sample_packet_forward.h new file mode 100644 index 000000000..f6226e34b --- /dev/null +++ b/test/test/sample_packet_forward.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#ifndef _SAMPLE_PACKET_FORWARD_H_ +#define _SAMPLE_PACKET_FORWARD_H_ + +/* MACROS to support virtual ring creation */ +#define RING_SIZE 256 +#define NUM_RINGS 2 +#define NUM_QUEUES 1 + +#define NUM_PACKETS 10 + +/* Sample test to create virtual rings and tx,rx portid from rings */ +int test_ring_setup(void); + +/* Sample test to forward packet using virtual port id */ +int test_packet_forward(void); + +#endif /* _SAMPLE_PACKET_FORWARD_H_ */ + -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [dpdk-dev] [PATCH v2] add sample functions for packet forwarding 2018-07-12 8:53 ` [dpdk-dev] [PATCH v2] " Jananee Parthasarathy @ 2018-07-12 16:00 ` Pattan, Reshma 2018-07-16 16:00 ` [dpdk-dev] [PATCH v3] test: " Jananee Parthasarathy 1 sibling, 0 replies; 37+ messages in thread From: Pattan, Reshma @ 2018-07-12 16:00 UTC (permalink / raw) To: Parthasarathy, JananeeX M, dev; +Cc: Horton, Remy, Chaitanya Babu, TalluriX Hi Jananee, > -----Original Message----- > From: Parthasarathy, JananeeX M > Sent: Thursday, July 12, 2018 9:53 AM > To: dev@dpdk.org > Cc: Horton, Remy <remy.horton@intel.com>; Pattan, Reshma > <reshma.pattan@intel.com>; Parthasarathy, JananeeX M > <jananeex.m.parthasarathy@intel.com>; Chaitanya Babu, TalluriX > <tallurix.chaitanya.babu@intel.com> > Subject: [PATCH v2] add sample functions for packet forwarding > I could apply the patch succefully but there was a warning, just check is the white line can be removed. git apply v2-add-sample-functions-for-packet-forwarding v2-add-sample-functions-for-packet-forwarding:160: new blank line at EOF. + warning: 1 line adds whitespace errors. > + uint16_t socket_id = rte_socket_id(); > + struct rte_ring *rxtx[NUM_RINGS]; > + rxtx[0] = rte_ring_create("R0", RING_SIZE, socket_id, > + RING_F_SP_ENQ|RING_F_SC_DEQ); > + if (rxtx[0] == NULL) { > + printf("%s() line %u: rte_ring_create R0 failed", > + __func__, __LINE__); > + return TEST_FAILED; > + } > + rxtx[1] = rte_ring_create("R1", RING_SIZE, socket_id, > + RING_F_SP_ENQ|RING_F_SC_DEQ); > + if (rxtx[1] == NULL) { > + printf("%s() line %u: rte_ring_create R1 failed", > + __func__, __LINE__); > + return TEST_FAILED; > + } > + tx_portid = rte_eth_from_rings("net_ringa", rxtx, NUM_QUEUES, rxtx, > + NUM_QUEUES, socket_id); > + rx_portid = rte_eth_from_rings("net_ringb", rxtx, NUM_QUEUES, rxtx, > + NUM_QUEUES, socket_id); Also can you see if you can create only one port using rings instead of 2 and use it for two ports rx_port id and tx_ports ids? And will that fit for all the UTs that you are writing. Thanks, Reshma ^ permalink raw reply [flat|nested] 37+ messages in thread
* [dpdk-dev] [PATCH v3] test: add sample functions for packet forwarding 2018-07-12 8:53 ` [dpdk-dev] [PATCH v2] " Jananee Parthasarathy 2018-07-12 16:00 ` Pattan, Reshma @ 2018-07-16 16:00 ` Jananee Parthasarathy 2018-07-17 8:15 ` Pattan, Reshma 2018-07-17 10:00 ` [dpdk-dev] [PATCH v4] " Jananee Parthasarathy 1 sibling, 2 replies; 37+ messages in thread From: Jananee Parthasarathy @ 2018-07-16 16:00 UTC (permalink / raw) To: dev Cc: remy.horton, reshma.pattan, Jananee Parthasarathy, Chaitanya Babu Talluri Add sample test functions for packet forwarding. These can be used for unit test cases for LatencyStats and BitrateStats libraries. Signed-off-by: Chaitanya Babu Talluri <tallurix.chaitanya.babu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> --- v3: Used same port for tx,rx and removed extra line v2: SOCKET0 is removed and NUM_QUEUES is used accordingly --- test/test/Makefile | 1 + test/test/sample_packet_forward.c | 71 +++++++++++++++++++++++++++++++++++++++ test/test/sample_packet_forward.h | 21 ++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 test/test/sample_packet_forward.c create mode 100644 test/test/sample_packet_forward.h diff --git a/test/test/Makefile b/test/test/Makefile index e6967bab6..8032ce53b 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -135,6 +135,7 @@ SRCS-y += test_version.c SRCS-y += test_func_reentrancy.c SRCS-y += test_service_cores.c +SRCS-y += sample_packet_forward.c SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline.c SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline_num.c diff --git a/test/test/sample_packet_forward.c b/test/test/sample_packet_forward.c new file mode 100644 index 000000000..4afc0b69a --- /dev/null +++ b/test/test/sample_packet_forward.c @@ -0,0 +1,71 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include <string.h> +#include <errno.h> +#include <time.h> + +#include <rte_memcpy.h> +#include <rte_common.h> +#include <rte_eth_ring.h> +#include <rte_ethdev.h> + +#include "sample_packet_forward.h" +#include "test.h" +#include <rte_mbuf.h> + +#define NB_MBUF 512 + +static struct rte_mempool *mp; +uint16_t portid; + +/* Sample test to create virtual rings and tx,rx portid from rings */ +int +test_ring_setup(void) +{ + uint16_t socket_id = rte_socket_id(); + struct rte_ring *rxtx[NUM_RINGS]; + rxtx[0] = rte_ring_create("R0", RING_SIZE, socket_id, + RING_F_SP_ENQ|RING_F_SC_DEQ); + if (rxtx[0] == NULL) { + printf("%s() line %u: rte_ring_create R0 failed", + __func__, __LINE__); + return TEST_FAILED; + } + portid = rte_eth_from_rings("net_ringa", rxtx, NUM_QUEUES, rxtx, + NUM_QUEUES, socket_id); + + return TEST_SUCCESS; +} + +/* Sample test to forward packets using virtual portids */ +int +test_packet_forward(void) +{ + struct rte_mbuf *pbuf[NUM_PACKETS]; + + mp = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF, 32, 0, + RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); + if (mp == NULL) + return -1; + if (rte_pktmbuf_alloc_bulk(mp, pbuf, NUM_PACKETS) != 0) + printf("%s() line %u: rte_pktmbuf_alloc_bulk failed" + , __func__, __LINE__); + /* send and receive packet and check for stats update */ + if (rte_eth_tx_burst(portid, 0, pbuf, NUM_PACKETS) != + NUM_PACKETS) { + printf("%s() line %u: Error sending packet to" + " port %d\n", __func__, __LINE__, + portid); + return TEST_FAILED; + } + if (rte_eth_rx_burst(portid, 0, pbuf, NUM_PACKETS) != + NUM_PACKETS) { + printf("%s() line %u: Error receiving packet from" + " port %d\n", __func__, __LINE__, + portid); + return TEST_FAILED; + } + return TEST_SUCCESS; +} diff --git a/test/test/sample_packet_forward.h b/test/test/sample_packet_forward.h new file mode 100644 index 000000000..a4880316f --- /dev/null +++ b/test/test/sample_packet_forward.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#ifndef _SAMPLE_PACKET_FORWARD_H_ +#define _SAMPLE_PACKET_FORWARD_H_ + +/* MACROS to support virtual ring creation */ +#define RING_SIZE 256 +#define NUM_RINGS 1 +#define NUM_QUEUES 1 + +#define NUM_PACKETS 10 + +/* Sample test to create virtual rings and tx,rx portid from rings */ +int test_ring_setup(void); + +/* Sample test to forward packet using virtual port id */ +int test_packet_forward(void); + +#endif /* _SAMPLE_PACKET_FORWARD_H_ */ -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [dpdk-dev] [PATCH v3] test: add sample functions for packet forwarding 2018-07-16 16:00 ` [dpdk-dev] [PATCH v3] test: " Jananee Parthasarathy @ 2018-07-17 8:15 ` Pattan, Reshma 2018-07-17 10:00 ` [dpdk-dev] [PATCH v4] " Jananee Parthasarathy 1 sibling, 0 replies; 37+ messages in thread From: Pattan, Reshma @ 2018-07-17 8:15 UTC (permalink / raw) To: Parthasarathy, JananeeX M, dev; +Cc: Horton, Remy, Chaitanya Babu, TalluriX Hi > -----Original Message----- > From: Parthasarathy, JananeeX M > Sent: Monday, July 16, 2018 5:01 PM > To: dev@dpdk.org > Cc: Horton, Remy <remy.horton@intel.com>; Pattan, Reshma > <reshma.pattan@intel.com>; Parthasarathy, JananeeX M > <jananeex.m.parthasarathy@intel.com>; Chaitanya Babu, TalluriX > <tallurix.chaitanya.babu@intel.com> > Subject: [PATCH v3] test: add sample functions for packet forwarding > > Add sample test functions for packet forwarding. > These can be used for unit test cases for LatencyStats and BitrateStats > libraries. > > Signed-off-by: Chaitanya Babu Talluri <tallurix.chaitanya.babu@intel.com> > Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> > --- > + */ > +/* Sample test to forward packets using virtual portids */ int > +test_packet_forward(void) > +{ > + struct rte_mbuf *pbuf[NUM_PACKETS]; > + > + mp = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF, 32, 0, > + RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); > + if (mp == NULL) > + return -1; Instead of return -1 , please return TEST_FAILED, that seems to be the correct way as autotest expects TEST_SUCESS or TEST_FAILED from the test result. Rest of the code looks ok, I am done with the review. In next patch version don't forget to add my Ack. Acked-by: Reshma Pattan <reshma.pattan@intel.com> ^ permalink raw reply [flat|nested] 37+ messages in thread
* [dpdk-dev] [PATCH v4] test: add sample functions for packet forwarding 2018-07-16 16:00 ` [dpdk-dev] [PATCH v3] test: " Jananee Parthasarathy 2018-07-17 8:15 ` Pattan, Reshma @ 2018-07-17 10:00 ` Jananee Parthasarathy 2018-07-17 10:22 ` Burakov, Anatoly 2018-07-24 10:54 ` [dpdk-dev] [PATCH v5 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu 1 sibling, 2 replies; 37+ messages in thread From: Jananee Parthasarathy @ 2018-07-17 10:00 UTC (permalink / raw) To: dev Cc: remy.horton, reshma.pattan, Jananee Parthasarathy, Chaitanya Babu Talluri Add sample test functions for packet forwarding. These can be used for unit test cases for LatencyStats and BitrateStats libraries. Signed-off-by: Chaitanya Babu Talluri <tallurix.chaitanya.babu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> Acked-by: Reshma Pattan <reshma.pattan@intel.com> --- v4: Updated return value as TEST_FAILED instead of -1 v3: Used same port for tx,rx and removed extra line v2: SOCKET0 is removed and NUM_QUEUES is used accordingly --- test/test/Makefile | 1 + test/test/sample_packet_forward.c | 71 +++++++++++++++++++++++++++++++++++++++ test/test/sample_packet_forward.h | 21 ++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 test/test/sample_packet_forward.c create mode 100644 test/test/sample_packet_forward.h diff --git a/test/test/Makefile b/test/test/Makefile index e6967bab6..8032ce53b 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -135,6 +135,7 @@ SRCS-y += test_version.c SRCS-y += test_func_reentrancy.c SRCS-y += test_service_cores.c +SRCS-y += sample_packet_forward.c SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline.c SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline_num.c diff --git a/test/test/sample_packet_forward.c b/test/test/sample_packet_forward.c new file mode 100644 index 000000000..4a13d5001 --- /dev/null +++ b/test/test/sample_packet_forward.c @@ -0,0 +1,71 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include <string.h> +#include <errno.h> +#include <time.h> + +#include <rte_memcpy.h> +#include <rte_common.h> +#include <rte_eth_ring.h> +#include <rte_ethdev.h> + +#include "sample_packet_forward.h" +#include "test.h" +#include <rte_mbuf.h> + +#define NB_MBUF 512 + +static struct rte_mempool *mp; +uint16_t portid; + +/* Sample test to create virtual rings and tx,rx portid from rings */ +int +test_ring_setup(void) +{ + uint16_t socket_id = rte_socket_id(); + struct rte_ring *rxtx[NUM_RINGS]; + rxtx[0] = rte_ring_create("R0", RING_SIZE, socket_id, + RING_F_SP_ENQ|RING_F_SC_DEQ); + if (rxtx[0] == NULL) { + printf("%s() line %u: rte_ring_create R0 failed", + __func__, __LINE__); + return TEST_FAILED; + } + portid = rte_eth_from_rings("net_ringa", rxtx, NUM_QUEUES, rxtx, + NUM_QUEUES, socket_id); + + return TEST_SUCCESS; +} + +/* Sample test to forward packets using virtual portids */ +int +test_packet_forward(void) +{ + struct rte_mbuf *pbuf[NUM_PACKETS]; + + mp = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF, 32, 0, + RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); + if (mp == NULL) + return TEST_FAILED; + if (rte_pktmbuf_alloc_bulk(mp, pbuf, NUM_PACKETS) != 0) + printf("%s() line %u: rte_pktmbuf_alloc_bulk failed" + , __func__, __LINE__); + /* send and receive packet and check for stats update */ + if (rte_eth_tx_burst(portid, 0, pbuf, NUM_PACKETS) != + NUM_PACKETS) { + printf("%s() line %u: Error sending packet to" + " port %d\n", __func__, __LINE__, + portid); + return TEST_FAILED; + } + if (rte_eth_rx_burst(portid, 0, pbuf, NUM_PACKETS) != + NUM_PACKETS) { + printf("%s() line %u: Error receiving packet from" + " port %d\n", __func__, __LINE__, + portid); + return TEST_FAILED; + } + return TEST_SUCCESS; +} diff --git a/test/test/sample_packet_forward.h b/test/test/sample_packet_forward.h new file mode 100644 index 000000000..a4880316f --- /dev/null +++ b/test/test/sample_packet_forward.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#ifndef _SAMPLE_PACKET_FORWARD_H_ +#define _SAMPLE_PACKET_FORWARD_H_ + +/* MACROS to support virtual ring creation */ +#define RING_SIZE 256 +#define NUM_RINGS 1 +#define NUM_QUEUES 1 + +#define NUM_PACKETS 10 + +/* Sample test to create virtual rings and tx,rx portid from rings */ +int test_ring_setup(void); + +/* Sample test to forward packet using virtual port id */ +int test_packet_forward(void); + +#endif /* _SAMPLE_PACKET_FORWARD_H_ */ -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [dpdk-dev] [PATCH v4] test: add sample functions for packet forwarding 2018-07-17 10:00 ` [dpdk-dev] [PATCH v4] " Jananee Parthasarathy @ 2018-07-17 10:22 ` Burakov, Anatoly 2018-07-24 10:54 ` [dpdk-dev] [PATCH v5 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu 1 sibling, 0 replies; 37+ messages in thread From: Burakov, Anatoly @ 2018-07-17 10:22 UTC (permalink / raw) To: Jananee Parthasarathy, dev Cc: remy.horton, reshma.pattan, Chaitanya Babu Talluri On 17-Jul-18 11:00 AM, Jananee Parthasarathy wrote: > Add sample test functions for packet forwarding. > These can be used for unit test cases for > LatencyStats and BitrateStats libraries. > > Signed-off-by: Chaitanya Babu Talluri <tallurix.chaitanya.babu@intel.com> > Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> > Acked-by: Reshma Pattan <reshma.pattan@intel.com> > --- > v4: Updated return value as TEST_FAILED instead of -1 > v3: Used same port for tx,rx and removed extra line > v2: SOCKET0 is removed and NUM_QUEUES is used accordingly > --- > test/test/Makefile | 1 + > test/test/sample_packet_forward.c | 71 +++++++++++++++++++++++++++++++++++++++ > test/test/sample_packet_forward.h | 21 ++++++++++++ > 3 files changed, 93 insertions(+) > create mode 100644 test/test/sample_packet_forward.c > create mode 100644 test/test/sample_packet_forward.h > > diff --git a/test/test/Makefile b/test/test/Makefile > index e6967bab6..8032ce53b 100644 > --- a/test/test/Makefile > +++ b/test/test/Makefile > @@ -135,6 +135,7 @@ SRCS-y += test_version.c > SRCS-y += test_func_reentrancy.c > > SRCS-y += test_service_cores.c > +SRCS-y += sample_packet_forward.c > > SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline.c > SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline_num.c > diff --git a/test/test/sample_packet_forward.c b/test/test/sample_packet_forward.c > new file mode 100644 > index 000000000..4a13d5001 > --- /dev/null > +++ b/test/test/sample_packet_forward.c > @@ -0,0 +1,71 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2018 Intel Corporation > + */ > + > +#include <string.h> > +#include <errno.h> > +#include <time.h> > + > +#include <rte_memcpy.h> > +#include <rte_common.h> > +#include <rte_eth_ring.h> > +#include <rte_ethdev.h> > + > +#include "sample_packet_forward.h" > +#include "test.h" > +#include <rte_mbuf.h> > + > +#define NB_MBUF 512 > + > +static struct rte_mempool *mp; > +uint16_t portid; > + > +/* Sample test to create virtual rings and tx,rx portid from rings */ > +int > +test_ring_setup(void) > +{ > + uint16_t socket_id = rte_socket_id(); > + struct rte_ring *rxtx[NUM_RINGS]; > + rxtx[0] = rte_ring_create("R0", RING_SIZE, socket_id, > + RING_F_SP_ENQ|RING_F_SC_DEQ); > + if (rxtx[0] == NULL) { > + printf("%s() line %u: rte_ring_create R0 failed", > + __func__, __LINE__); > + return TEST_FAILED; > + } > + portid = rte_eth_from_rings("net_ringa", rxtx, NUM_QUEUES, rxtx, > + NUM_QUEUES, socket_id); > + > + return TEST_SUCCESS; I am probably missing something, but 1) Why are there 256 rings maximum, but only one is used? 2) You're creating these rings - where are you destroying them? 3) Some more comments on why this would be needed would be great as well. Right now, it looks like it's ripped out of the middle of a patchset - i don't see it being used anywhere. > +} > + > +/* Sample test to forward packets using virtual portids */ > +int > +test_packet_forward(void) > +{ > + struct rte_mbuf *pbuf[NUM_PACKETS]; > + > + mp = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF, 32, 0, > + RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); > + if (mp == NULL) > + return TEST_FAILED; > + if (rte_pktmbuf_alloc_bulk(mp, pbuf, NUM_PACKETS) != 0) > + printf("%s() line %u: rte_pktmbuf_alloc_bulk failed" > + , __func__, __LINE__); > + /* send and receive packet and check for stats update */ > + if (rte_eth_tx_burst(portid, 0, pbuf, NUM_PACKETS) != > + NUM_PACKETS) { > + printf("%s() line %u: Error sending packet to" > + " port %d\n", __func__, __LINE__, > + portid); > + return TEST_FAILED; > + } > + if (rte_eth_rx_burst(portid, 0, pbuf, NUM_PACKETS) != > + NUM_PACKETS) { > + printf("%s() line %u: Error receiving packet from" > + " port %d\n", __func__, __LINE__, > + portid); > + return TEST_FAILED; > + } > + return TEST_SUCCESS; Same as above. > +} > diff --git a/test/test/sample_packet_forward.h b/test/test/sample_packet_forward.h > new file mode 100644 > index 000000000..a4880316f > --- /dev/null > +++ b/test/test/sample_packet_forward.h > @@ -0,0 +1,21 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2018 Intel Corporation > + */ > + > +#ifndef _SAMPLE_PACKET_FORWARD_H_ > +#define _SAMPLE_PACKET_FORWARD_H_ > + > +/* MACROS to support virtual ring creation */ > +#define RING_SIZE 256 > +#define NUM_RINGS 1 > +#define NUM_QUEUES 1 > + > +#define NUM_PACKETS 10 > + > +/* Sample test to create virtual rings and tx,rx portid from rings */ > +int test_ring_setup(void); > + > +/* Sample test to forward packet using virtual port id */ > +int test_packet_forward(void); > + > +#endif /* _SAMPLE_PACKET_FORWARD_H_ */ > -- Thanks, Anatoly ^ permalink raw reply [flat|nested] 37+ messages in thread
* [dpdk-dev] [PATCH v5 0/4] add unit tests for bitrate, latency and pdump libraries 2018-07-17 10:00 ` [dpdk-dev] [PATCH v4] " Jananee Parthasarathy 2018-07-17 10:22 ` Burakov, Anatoly @ 2018-07-24 10:54 ` Naga Suresh Somarowthu 2018-07-24 10:54 ` [dpdk-dev] [PATCH v5 1/4] test: add ring pmd based packet rx/tx for UT Naga Suresh Somarowthu ` (4 more replies) 1 sibling, 5 replies; 37+ messages in thread From: Naga Suresh Somarowthu @ 2018-07-24 10:54 UTC (permalink / raw) To: dev; +Cc: remy.horton, reshma.pattan, Naga Suresh Somarowthu 1/4: add ring pmd based packet helper functions for UT 2/4: unit test cases added for bitrate library 3/4: unit test cases added for latencystats library 4/4: unit test cases added for pdump library Patches 2/4,3/4 and 4/4 depends on 1/4 Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> Reviewed-by: Anatoly Burakov <anatoly.burakov@intel.com> Reviewed-by: Remy Horton <remy.horton@intel.com> --- v5: rebased, freed pools and rings, created common patch set --- Naga Suresh Somarowthu (4): test: add ring pmd based packet rx/tx for UT test: add unit tests for bitrate library test: add unit tests for latencystats library test: add unit test for pdump library test/test/Makefile | 4 + test/test/autotest_data.py | 12 ++ test/test/sample_packet_forward.c | 115 +++++++++++++++++ test/test/sample_packet_forward.h | 41 ++++++ test/test/test_bitratestats.c | 227 +++++++++++++++++++++++++++++++++ test/test/test_latencystats.c | 216 ++++++++++++++++++++++++++++++++ test/test/test_pdump.c | 256 ++++++++++++++++++++++++++++++++++++++ test/test/test_pdump.h | 40 ++++++ 8 files changed, 911 insertions(+) create mode 100644 test/test/sample_packet_forward.c create mode 100644 test/test/sample_packet_forward.h create mode 100644 test/test/test_bitratestats.c create mode 100644 test/test/test_latencystats.c create mode 100644 test/test/test_pdump.c create mode 100644 test/test/test_pdump.h -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* [dpdk-dev] [PATCH v5 1/4] test: add ring pmd based packet rx/tx for UT 2018-07-24 10:54 ` [dpdk-dev] [PATCH v5 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu @ 2018-07-24 10:54 ` Naga Suresh Somarowthu 2018-07-24 11:21 ` Burakov, Anatoly 2018-07-24 10:54 ` [dpdk-dev] [PATCH v5 2/4] test: add unit tests for bitrate library Naga Suresh Somarowthu ` (3 subsequent siblings) 4 siblings, 1 reply; 37+ messages in thread From: Naga Suresh Somarowthu @ 2018-07-24 10:54 UTC (permalink / raw) To: dev; +Cc: remy.horton, reshma.pattan, Naga Suresh Somarowthu Added ring pmd based packet rx/tx helper functions for verifying Latency, Bitrate and pdump lib UTs. Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> Reviewed-by: Anatoly Burakov <anatoly.burakov@intel.com> --- test/test/Makefile | 1 + test/test/sample_packet_forward.c | 115 ++++++++++++++++++++++++++++++++++++++ test/test/sample_packet_forward.h | 41 ++++++++++++++ 3 files changed, 157 insertions(+) create mode 100644 test/test/sample_packet_forward.c create mode 100644 test/test/sample_packet_forward.h diff --git a/test/test/Makefile b/test/test/Makefile index e6967bab6..9f7d398e4 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -165,6 +165,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_REORDER) += test_reorder.c SRCS-y += virtual_pmd.c SRCS-y += packet_burst_generator.c +SRCS-y += sample_packet_forward.c SRCS-$(CONFIG_RTE_LIBRTE_ACL) += test_acl.c ifeq ($(CONFIG_RTE_LIBRTE_PMD_RING),y) diff --git a/test/test/sample_packet_forward.c b/test/test/sample_packet_forward.c new file mode 100644 index 000000000..8f9d7009a --- /dev/null +++ b/test/test/sample_packet_forward.c @@ -0,0 +1,115 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include <string.h> +#include <errno.h> +#include <time.h> + +#include <rte_memcpy.h> +#include <rte_common.h> +#include <rte_eth_ring.h> +#include <rte_ethdev.h> +#include <rte_mbuf.h> +#include <rte_bus_vdev.h> + +#include "sample_packet_forward.h" +#include "test.h" + +/* Sample test to create virtual rings and tx,rx portid from rings */ +int +test_ring_setup(struct rte_ring *ring[], uint16_t *portid) +{ + ring[0] = rte_ring_create("R0", RING_SIZE, rte_socket_id(), + RING_F_SP_ENQ | RING_F_SC_DEQ); + if (ring[0] == NULL) { + printf("%s() line %u: rte_ring_create R0 failed", + __func__, __LINE__); + return TEST_FAILED; + } + *portid = rte_eth_from_rings("net_ringa", ring, NUM_QUEUES, + ring, NUM_QUEUES, rte_socket_id()); + + return TEST_SUCCESS; +} + +/* Sample test to free the mempool */ +void +test_mp_free(struct rte_mempool *mp) +{ + rte_mempool_free(mp); +} + +/* Sample test to free the virtual rings */ +void +test_ring_free(struct rte_ring *rxtx) +{ + rte_ring_free(rxtx); +} + +/* Sample test to release the vdev */ +void +test_vdev_uninit(const char *vdev) +{ + rte_vdev_uninit(vdev); +} + +/* sample test to deallocate the allocated buffers */ +int +test_get_mempool(struct rte_mempool **mp, char *poolname) +{ + *mp = rte_pktmbuf_pool_create(poolname, NB_MBUF, 32, 0, + RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); + if (*mp == NULL) + return TEST_FAILED; + return TEST_SUCCESS; +} + +/* sample test to allocate buffer for pkts */ +int +test_get_mbuf_from_pool(struct rte_mempool **mp, struct rte_mbuf **pbuf, + char *poolname) +{ + int ret = 0; + + ret = test_get_mempool(mp, poolname); + if (ret < 0) + return TEST_FAILED; + if (rte_pktmbuf_alloc_bulk(*mp, pbuf, NUM_PACKETS) != 0) { + printf("%s() line %u: rte_pktmbuf_alloc_bulk failed", __func__, + __LINE__); + return TEST_FAILED; + } + return TEST_SUCCESS; +} + +/* sample test to deallocate the allocated buffers */ +void +test_put_mbuf_to_pool(struct rte_mempool *mp, struct rte_mbuf **pbuf) +{ + int itr = 0; + + for (itr = 0; itr < NUM_PACKETS; itr++) + rte_pktmbuf_free(pbuf[itr]); + rte_mempool_free(mp); +} + +/* Sample test to forward packets using virtual portids */ +int +test_packet_forward(struct rte_mbuf **pbuf, uint16_t portid, uint16_t queue_id) +{ + /* send and receive packet and check for stats update */ + if (rte_eth_tx_burst(portid, queue_id, pbuf, NUM_PACKETS) + < NUM_PACKETS) { + printf("%s() line %u: Error sending packet to" + " port %d\n", __func__, __LINE__, portid); + return TEST_FAILED; + } + if (rte_eth_rx_burst(portid, queue_id, pbuf, NUM_PACKETS) + < NUM_PACKETS) { + printf("%s() line %u: Error receiving packet from" + " port %d\n", __func__, __LINE__, portid); + return TEST_FAILED; + } + return TEST_SUCCESS; +} diff --git a/test/test/sample_packet_forward.h b/test/test/sample_packet_forward.h new file mode 100644 index 000000000..1293ee0a8 --- /dev/null +++ b/test/test/sample_packet_forward.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#ifndef _SAMPLE_PACKET_FORWARD_H_ +#define _SAMPLE_PACKET_FORWARD_H_ + +/* MACROS to support virtual ring creation */ +#define RING_SIZE 256 +#define NUM_RINGS 1 +#define NUM_QUEUES 1 +#define NB_MBUF 512 + +#define NUM_PACKETS 10 + +/* Sample test to create virtual rings and tx,rx portid from rings */ +int test_ring_setup(struct rte_ring *ring_server[], uint16_t *portid); + +/* Sample test to free the virtual rings */ +void test_ring_free(struct rte_ring *rxtx); + +/* Sample test to forward packet using virtual port id */ +int test_packet_forward(struct rte_mbuf **pbuf, uint16_t portid, + uint16_t queue_id); + +/* sample test to allocate buffer for pkts */ +int test_get_mbuf_from_pool(struct rte_mempool **mp, struct rte_mbuf **pbuf, + char *poolname); + +/* Sample test to create the mempool */ +int test_get_mempool(struct rte_mempool **mp, char *poolname); + +/* sample test to deallocate the allocated buffers */ +void test_put_mbuf_to_pool(struct rte_mempool *mp, struct rte_mbuf **pbuf); + +/* Sample test to free the mempool */ +void test_mp_free(struct rte_mempool *mp); + +/* Sample test to release the vdev */ +void test_vdev_uninit(const char *vdev); +#endif /* _SAMPLE_PACKET_FORWARD_H_ */ -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [dpdk-dev] [PATCH v5 1/4] test: add ring pmd based packet rx/tx for UT 2018-07-24 10:54 ` [dpdk-dev] [PATCH v5 1/4] test: add ring pmd based packet rx/tx for UT Naga Suresh Somarowthu @ 2018-07-24 11:21 ` Burakov, Anatoly 0 siblings, 0 replies; 37+ messages in thread From: Burakov, Anatoly @ 2018-07-24 11:21 UTC (permalink / raw) To: Naga Suresh Somarowthu, dev; +Cc: remy.horton, reshma.pattan On 24-Jul-18 11:54 AM, Naga Suresh Somarowthu wrote: > Added ring pmd based packet rx/tx helper functions > for verifying Latency, Bitrate and pdump lib UTs. > > Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> > Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> > Reviewed-by: Anatoly Burakov <anatoly.burakov@intel.com> Why is it carrying my Reviewed-by: ? I do not recall sending it... > --- > test/test/Makefile | 1 + > test/test/sample_packet_forward.c | 115 ++++++++++++++++++++++++++++++++++++++ > test/test/sample_packet_forward.h | 41 ++++++++++++++ > 3 files changed, 157 insertions(+) > create mode 100644 test/test/sample_packet_forward.c > create mode 100644 test/test/sample_packet_forward.h > > diff --git a/test/test/Makefile b/test/test/Makefile > index e6967bab6..9f7d398e4 100644 <snip> > +/* Sample test to create virtual rings and tx,rx portid from rings */ > +int > +test_ring_setup(struct rte_ring *ring[], uint16_t *portid) > +{ > + ring[0] = rte_ring_create("R0", RING_SIZE, rte_socket_id(), > + RING_F_SP_ENQ | RING_F_SC_DEQ); > + if (ring[0] == NULL) { > + printf("%s() line %u: rte_ring_create R0 failed", > + __func__, __LINE__); > + return TEST_FAILED; > + } > + *portid = rte_eth_from_rings("net_ringa", ring, NUM_QUEUES, > + ring, NUM_QUEUES, rte_socket_id()); > + > + return TEST_SUCCESS; > +} Previous comments have not been addressed. You are always creating one ring, yet you create an array of rings (with a size of one). Why? Even assuming you need to create multiple rings (which, as far as i can tell from other patches, you don't), why not just accept a pointer-to-pointer, like this: int test_ring_setup(struct rte_ring **ring) { *ring = rte_ring_create(); } // calling code struct rte_ring *ring; test_ring_setup(&ring); Surely this would be more understandable? (in fact, you do this with mempools - why not rings?) Also, here and in lots of other places: why is this function returning TEST_SUCCESS? Is this an autotest? If not, then it shouldn't return these values. > + > +/* Sample test to free the mempool */ > +void > +test_mp_free(struct rte_mempool *mp) > +{ > + rte_mempool_free(mp); > +} > + > +/* Sample test to free the virtual rings */ > +void > +test_ring_free(struct rte_ring *rxtx) > +{ > + rte_ring_free(rxtx); > +} <snip> > +} > diff --git a/test/test/sample_packet_forward.h b/test/test/sample_packet_forward.h > new file mode 100644 > index 000000000..1293ee0a8 > --- /dev/null > +++ b/test/test/sample_packet_forward.h > @@ -0,0 +1,41 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2018 Intel Corporation > + */ > + > +#ifndef _SAMPLE_PACKET_FORWARD_H_ > +#define _SAMPLE_PACKET_FORWARD_H_ > + > +/* MACROS to support virtual ring creation */ > +#define RING_SIZE 256 > +#define NUM_RINGS 1 > +#define NUM_QUEUES 1 > +#define NB_MBUF 512 > + > +#define NUM_PACKETS 10 Some of the above #define's are not used in this patch. They probably should be added in later patches? > + > +/* Sample test to create virtual rings and tx,rx portid from rings */ > +int test_ring_setup(struct rte_ring *ring_server[], uint16_t *portid); > + > +/* Sample test to free the virtual rings */ > +void test_ring_free(struct rte_ring *rxtx); > + > +/* Sample test to forward packet using virtual port id */ > +int test_packet_forward(struct rte_mbuf **pbuf, uint16_t portid, > + uint16_t queue_id); > + > +/* sample test to allocate buffer for pkts */ > +int test_get_mbuf_from_pool(struct rte_mempool **mp, struct rte_mbuf **pbuf, > + char *poolname); > + > +/* Sample test to create the mempool */ > +int test_get_mempool(struct rte_mempool **mp, char *poolname); > + > +/* sample test to deallocate the allocated buffers */ > +void test_put_mbuf_to_pool(struct rte_mempool *mp, struct rte_mbuf **pbuf); > + > +/* Sample test to free the mempool */ > +void test_mp_free(struct rte_mempool *mp); > + > +/* Sample test to release the vdev */ > +void test_vdev_uninit(const char *vdev); > +#endif /* _SAMPLE_PACKET_FORWARD_H_ */ > -- Thanks, Anatoly ^ permalink raw reply [flat|nested] 37+ messages in thread
* [dpdk-dev] [PATCH v5 2/4] test: add unit tests for bitrate library 2018-07-24 10:54 ` [dpdk-dev] [PATCH v5 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu 2018-07-24 10:54 ` [dpdk-dev] [PATCH v5 1/4] test: add ring pmd based packet rx/tx for UT Naga Suresh Somarowthu @ 2018-07-24 10:54 ` Naga Suresh Somarowthu 2018-07-24 10:54 ` [dpdk-dev] [PATCH v5 3/4] test: add unit tests for latencystats library Naga Suresh Somarowthu ` (2 subsequent siblings) 4 siblings, 0 replies; 37+ messages in thread From: Naga Suresh Somarowthu @ 2018-07-24 10:54 UTC (permalink / raw) To: dev; +Cc: remy.horton, reshma.pattan, Naga Suresh Somarowthu Unit Test Cases for BitRate library. Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> Reviewed-by: Remy Horton <remy.horton@intel.com> --- test/test/Makefile | 1 + test/test/autotest_data.py | 6 ++ test/test/test_bitratestats.c | 227 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 234 insertions(+) create mode 100644 test/test/test_bitratestats.c diff --git a/test/test/Makefile b/test/test/Makefile index 9f7d398e4..8407ae36e 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -166,6 +166,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_REORDER) += test_reorder.c SRCS-y += virtual_pmd.c SRCS-y += packet_burst_generator.c SRCS-y += sample_packet_forward.c +SRCS-$(CONFIG_RTE_LIBRTE_BITRATE) += test_bitratestats.c SRCS-$(CONFIG_RTE_LIBRTE_ACL) += test_acl.c ifeq ($(CONFIG_RTE_LIBRTE_PMD_RING),y) diff --git a/test/test/autotest_data.py b/test/test/autotest_data.py index aacfe0a66..419520342 100644 --- a/test/test/autotest_data.py +++ b/test/test/autotest_data.py @@ -293,6 +293,12 @@ def per_sockets(num): "Tests": [ { + "Name": "Bitratestats autotest", + "Command": "bitratestats_autotest", + "Func": default_autotest, + "Report": None, + }, + { "Name": "PMD ring autotest", "Command": "ring_pmd_autotest", "Func": default_autotest, diff --git a/test/test/test_bitratestats.c b/test/test/test_bitratestats.c new file mode 100644 index 000000000..ccb0acd7c --- /dev/null +++ b/test/test/test_bitratestats.c @@ -0,0 +1,227 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include <string.h> +#include <errno.h> +#include <time.h> + +#include <rte_log.h> +#include <rte_lcore.h> +#include <rte_mbuf.h> +#include <rte_malloc.h> +#include <rte_common.h> +#include <rte_metrics.h> +#include <rte_bitrate.h> + +#include "test.h" +#include "sample_packet_forward.h" + +#define BIT_NUM_PACKETS 10 +#define QUEUE_ID 0 + +uint16_t portid; +struct rte_stats_bitrates *bitrate_data; +struct rte_ring *ring[NUM_RINGS]; + +/* To test whether rte_stats_bitrate_create is successful */ +static int +test_stats_bitrate_create(void) +{ + bitrate_data = rte_stats_bitrate_create(); + TEST_ASSERT(bitrate_data != NULL, "rte_stats_bitrate_create failed"); + + return TEST_SUCCESS; +} + +/* To test bit rate registration */ +static int +test_stats_bitrate_reg(void) +{ + int ret = 0; + + /* Test to register bit rate without metrics init */ + ret = rte_stats_bitrate_reg(bitrate_data); + TEST_ASSERT(ret < 0, "Test Failed: rte_stats_bitrate_reg succeeded " + "without metrics init, ret:%d", ret); + + /* Metrics initialization */ + rte_metrics_init(rte_socket_id()); + /* Test to register bit rate after metrics init */ + ret = rte_stats_bitrate_reg(bitrate_data); + TEST_ASSERT((ret >= 0), "Test Failed: rte_stats_bitrate_reg %d", ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate registration with invalid pointer */ +static int +test_stats_bitrate_reg_invalidpointer(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_reg(NULL); + TEST_ASSERT(ret < 0, "Test Failed: Expected failure < 0 but " + "got %d", ret); + + return TEST_SUCCESS; +} + +/* To test bit rate calculation with invalid bit rate data pointer */ +static int +test_stats_bitrate_calc_invalid_bitrate_data(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(NULL, portid); + TEST_ASSERT(ret < 0, "Test Failed: rte_stats_bitrate_calc " + "ret:%d", ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate calculation with invalid portid + * (higher than max ports) + */ +static int +test_stats_bitrate_calc_invalid_portid_1(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(bitrate_data, 33); + TEST_ASSERT(ret == -EINVAL, "Test Failed: Expected -%d for higher " + "portid rte_stats_bitrate_calc ret:%d", EINVAL, ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate calculation with invalid portid (lesser than 0) */ +static int +test_stats_bitrate_calc_invalid_portid_2(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(bitrate_data, -1); + TEST_ASSERT(ret == -EINVAL, "Test Failed: Expected -%d for invalid " + "portid rte_stats_bitrate_calc ret:%d", EINVAL, ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate calculation with non-existing portid */ +static int +test_stats_bitrate_calc_non_existing_portid(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(bitrate_data, 31); + TEST_ASSERT(ret == -EINVAL, "Test Failed: Expected -%d for " + "non-existing portid rte_stats_bitrate_calc ret:%d", + EINVAL, ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate calculation with valid bit rate data, valid portid */ +static int +test_stats_bitrate_calc(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(bitrate_data, portid); + TEST_ASSERT(ret >= 0, "Test Failed: Expected >=0 for valid portid " + "rte_stats_bitrate_calc ret:%d", ret); + + return TEST_SUCCESS; +} + +static int +test_bit_packet_forward(void) +{ + int ret; + struct rte_mbuf *pbuf[BIT_NUM_PACKETS] = { }; + struct rte_mempool *mp; + char poolname[] = "mbuf_pool"; + ret = test_get_mbuf_from_pool(&mp, pbuf, poolname); + if (ret < 0) { + printf("allocate mbuf pool Failed\n"); + return TEST_FAILED; + } + ret = test_packet_forward(pbuf, portid, QUEUE_ID); + if (ret < 0) + printf("send pkts Failed\n"); + test_put_mbuf_to_pool(mp, pbuf); + + return TEST_SUCCESS; +} + +static int +test_bit_ring_setup(void) +{ + test_ring_setup(ring, &portid); + printf("port in ring setup : %d\n", portid); + + return TEST_SUCCESS; +} + +static void +test_bit_ring_free(void) +{ + test_ring_free(ring[0]); + test_vdev_uninit("net_ring_net_ringa"); +} + +static struct +unit_test_suite bitratestats_testsuite = { + .suite_name = "BitRate Stats Unit Test Suite", + .setup = test_bit_ring_setup, + .teardown = test_bit_ring_free, + .unit_test_cases = { + /* TEST CASE 1: Test to create bit rate data */ + TEST_CASE(test_stats_bitrate_create), + + /* TEST CASE 2: Test to register bit rate metrics + * without metrics init and after metrics init + */ + TEST_CASE(test_stats_bitrate_reg), + + /* TEST CASE 3: Test to register bit rate metrics + * with invalid bit rate data + */ + TEST_CASE(test_stats_bitrate_reg_invalidpointer), + + /* TEST CASE 4: Test to calculate bit rate data metrics + * with invalid bit rate data + */ + TEST_CASE(test_stats_bitrate_calc_invalid_bitrate_data), + + /* TEST CASE 5: Test to calculate bit rate data metrics + * with portid exceeding the max ports + */ + TEST_CASE(test_stats_bitrate_calc_invalid_portid_1), + + /* TEST CASE 6: Test to calculate bit rate data metrics + * with portid less than 0 + */ + TEST_CASE(test_stats_bitrate_calc_invalid_portid_2), + + /* TEST CASE 7: Test to calculate bit rate data metrics + * with non-existing portid + */ + TEST_CASE(test_stats_bitrate_calc_non_existing_portid), + + /* TEST CASE 8: Test to calculate bit rate data metrics + * with valid portid, valid bit rate data + */ + TEST_CASE_ST(test_bit_packet_forward, NULL, + test_stats_bitrate_calc), + TEST_CASES_END() + } +}; + +static int +test_bitratestats(void) +{ + return unit_test_suite_runner(&bitratestats_testsuite); +} +REGISTER_TEST_COMMAND(bitratestats_autotest, test_bitratestats); -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* [dpdk-dev] [PATCH v5 3/4] test: add unit tests for latencystats library 2018-07-24 10:54 ` [dpdk-dev] [PATCH v5 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu 2018-07-24 10:54 ` [dpdk-dev] [PATCH v5 1/4] test: add ring pmd based packet rx/tx for UT Naga Suresh Somarowthu 2018-07-24 10:54 ` [dpdk-dev] [PATCH v5 2/4] test: add unit tests for bitrate library Naga Suresh Somarowthu @ 2018-07-24 10:54 ` Naga Suresh Somarowthu 2018-07-24 10:54 ` [dpdk-dev] [PATCH v5 4/4] test: add unit test for pdump library Naga Suresh Somarowthu 2018-07-25 17:05 ` [dpdk-dev] [PATCH v6 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu 4 siblings, 0 replies; 37+ messages in thread From: Naga Suresh Somarowthu @ 2018-07-24 10:54 UTC (permalink / raw) To: dev; +Cc: remy.horton, reshma.pattan, Naga Suresh Somarowthu Unit Test Cases added for latencystats library. Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> --- test/test/Makefile | 1 + test/test/autotest_data.py | 6 ++ test/test/test_latencystats.c | 216 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 223 insertions(+) create mode 100644 test/test/test_latencystats.c diff --git a/test/test/Makefile b/test/test/Makefile index 8407ae36e..1c08b906a 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -167,6 +167,7 @@ SRCS-y += virtual_pmd.c SRCS-y += packet_burst_generator.c SRCS-y += sample_packet_forward.c SRCS-$(CONFIG_RTE_LIBRTE_BITRATE) += test_bitratestats.c +SRCS-$(CONFIG_RTE_LIBRTE_LATENCY_STATS) += test_latencystats.c SRCS-$(CONFIG_RTE_LIBRTE_ACL) += test_acl.c ifeq ($(CONFIG_RTE_LIBRTE_PMD_RING),y) diff --git a/test/test/autotest_data.py b/test/test/autotest_data.py index 419520342..3eccc4e1a 100644 --- a/test/test/autotest_data.py +++ b/test/test/autotest_data.py @@ -299,6 +299,12 @@ def per_sockets(num): "Report": None, }, { + "Name": "Latencystats autotest", + "Command": "latencystats_autotest", + "Func": default_autotest, + "Report": None, + }, + { "Name": "PMD ring autotest", "Command": "ring_pmd_autotest", "Func": default_autotest, diff --git a/test/test/test_latencystats.c b/test/test/test_latencystats.c new file mode 100644 index 000000000..8fdc0c8b0 --- /dev/null +++ b/test/test/test_latencystats.c @@ -0,0 +1,216 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <time.h> + +#include <rte_common.h> +#include <rte_metrics.h> +#include <rte_latencystats.h> +#include <rte_eth_ring.h> +#include <rte_ethdev.h> +#include <rte_mbuf.h> +#include "test.h" +#include "sample_packet_forward.h" +#define NUM_STATS 4 +#define LATENCY_NUM_PACKETS 10 +#define QUEUE_ID 0 + +uint16_t portid; +struct rte_ring *ring[NUM_RINGS]; + +struct rte_metric_name lat_stats_strings[] = { + {"min_latency_ns"}, + {"avg_latency_ns"}, + {"max_latency_ns"}, + {"jitter_ns"}, +}; + +/* Test case for latency init with metrics init */ +static int test_latency_init(void) +{ + int ret = 0; + + /* Metrics Initialization */ + rte_metrics_init(rte_socket_id()); + + ret = rte_latencystats_init(1, NULL); + TEST_ASSERT(ret >= 0, "Test Failed: rte_latencystats_init failed"); + + return TEST_SUCCESS; +} + +/* Test case to update the latency stats */ +static int test_latency_update(void) +{ + int ret = 0; + + ret = rte_latencystats_update(); + TEST_ASSERT(ret >= 0, "Test Failed: rte_latencystats_update failed"); + + return TEST_SUCCESS; +} + +/* Test case to uninit latency stats */ +static int test_latency_uninit(void) +{ + int ret = 0; + + ret = rte_latencystats_uninit(); + TEST_ASSERT(ret >= 0, "Test Failed: rte_latencystats_uninit failed"); + + return TEST_SUCCESS; +} + +/* Test case to get names of latency stats */ +static int test_latencystats_get_names(void) +{ + int ret = 0; + int size = 0; + struct rte_metric_name names[NUM_STATS] = { 0 }; + struct rte_metric_name wrongnames[NUM_STATS - 2] = { 0 }; + + /* Success Test: Valid names and size */ + size = NUM_STATS; + ret = rte_latencystats_get_names(names, size); + for (int i = 0; i <= NUM_STATS; i++) { + if (strcmp(lat_stats_strings[i].name, names[i].name) == 0) + printf(" %s\n", names[i].name); + else + printf("Failed: Names are not matched\n"); + } + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get metrics names"); + + /* Failure Test: Invalid names and valid size */ + ret = rte_latencystats_get_names(NULL, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get the metrics count," + "Actual: %d Expected: %d", ret, NUM_STATS); + + /* Failure Test: Valid names and invalid size */ + size = 0; + ret = rte_latencystats_get_names(names, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get the metrics count," + "Actual: %d Expected: %d", ret, NUM_STATS); + + /* Failure Test: Invalid names (array size lesser than size) */ + size = NUM_STATS + 1; + ret = rte_latencystats_get_names(wrongnames, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get metrics names"); + return TEST_SUCCESS; +} + +/* Test case to get latency stats values */ +static int test_latencystats_get(void) +{ + int ret = 0; + int size = 0; + struct rte_metric_value values[NUM_STATS] = { 0 }; + struct rte_metric_value wrongvalues[NUM_STATS - 2] = { 0 }; + + /* Success Test: Valid values and valid size */ + size = NUM_STATS; + ret = rte_latencystats_get(values, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get latency metrics" + " values"); + for (int i = 0; i < NUM_STATS; i++) + printf("values: %ld\n", values[i].value); + + /* Failure Test: Invalid values and valid size */ + ret = rte_latencystats_get(NULL, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get the stats count," + "Actual: %d Expected: %d", ret, NUM_STATS); + + /* Failure Test: Valid values and invalid size */ + size = 0; + ret = rte_latencystats_get(values, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get the stats count," + "Actual: %d Expected: %d", ret, NUM_STATS); + + /* Failure Test: Invalid values(array size lesser than size) + * and invalid size + */ + size = NUM_STATS + 2; + ret = rte_latencystats_get(wrongvalues, size); + TEST_ASSERT(ret == NUM_STATS, "Test Failed to get latency metrics" + " values"); + + return TEST_SUCCESS; +} + +static int test_latency_ring_setup(void) +{ + test_ring_setup(ring, &portid); + + return TEST_SUCCESS; +} + +static void test_latency_ring_free(void) +{ + test_ring_free(ring[0]); + test_vdev_uninit("net_ring_net_ringa"); +} + +static int test_latency_packet_forward(void) +{ + int ret; + struct rte_mbuf *pbuf[LATENCY_NUM_PACKETS] = { }; + struct rte_mempool *mp; + char poolname[] = "mbuf_pool"; + + ret = test_get_mbuf_from_pool(&mp, pbuf, poolname); + if (ret < 0) { + printf("allocate mbuf pool Failed\n"); + return TEST_FAILED; + } + ret = test_packet_forward(pbuf, portid, QUEUE_ID); + if (ret < 0) + printf("send pkts Failed\n"); + test_put_mbuf_to_pool(mp, pbuf); + + return TEST_SUCCESS; +} + +static struct +unit_test_suite latencystats_testsuite = { + .suite_name = "Latency Stats Unit Test Suite", + .setup = test_latency_ring_setup, + .teardown = test_latency_ring_free, + .unit_test_cases = { + + /* Test Case 1: To check latency init with + * metrics init + */ + TEST_CASE_ST(NULL, NULL, test_latency_init), + + /* Test Case 2: Do packet forwarding for metrics + * calculation and check the latency metrics values + * are updated + */ + TEST_CASE_ST(test_latency_packet_forward, NULL, + test_latency_update), + /* Test Case 3: To check whether latency stats names + * are retrieved + */ + TEST_CASE_ST(NULL, NULL, test_latencystats_get_names), + + /* Test Case 4: To check whether latency stats + * values are retrieved + */ + TEST_CASE_ST(NULL, NULL, test_latencystats_get), + + /* Test Case 5: To check uninit of latency test */ + TEST_CASE_ST(NULL, NULL, test_latency_uninit), + + TEST_CASES_END() + } +}; + +static int test_latencystats(void) +{ + return unit_test_suite_runner(&latencystats_testsuite); +} + +REGISTER_TEST_COMMAND(latencystats_autotest, test_latencystats); -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* [dpdk-dev] [PATCH v5 4/4] test: add unit test for pdump library 2018-07-24 10:54 ` [dpdk-dev] [PATCH v5 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu ` (2 preceding siblings ...) 2018-07-24 10:54 ` [dpdk-dev] [PATCH v5 3/4] test: add unit tests for latencystats library Naga Suresh Somarowthu @ 2018-07-24 10:54 ` Naga Suresh Somarowthu 2018-07-24 12:27 ` Burakov, Anatoly 2018-07-25 17:05 ` [dpdk-dev] [PATCH v6 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu 4 siblings, 1 reply; 37+ messages in thread From: Naga Suresh Somarowthu @ 2018-07-24 10:54 UTC (permalink / raw) To: dev; +Cc: remy.horton, reshma.pattan, Naga Suresh Somarowthu Unit test cases are added for pdump library. Primary process will act as server, forks a child secondary process. Secondary process acts as client. Server will do pdump init to serve any pdump client requests. Server will create a vdev, send/receive packets continuously in a separate thread. Client will create virtual rings to receive the packet dump. Client sends pdump enable/disable requests using either port id or device id. Packet flow direction can be tx/rx/tx&rx. In Server, appropriate pdump callbacks are triggered when packets are transmitted/received. Pdump packet is copied to client rings. Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> --- test/test/Makefile | 1 + test/test/test_pdump.c | 256 +++++++++++++++++++++++++++++++++++++++++++++++++ test/test/test_pdump.h | 40 ++++++++ 3 files changed, 297 insertions(+) create mode 100644 test/test/test_pdump.c create mode 100644 test/test/test_pdump.h diff --git a/test/test/Makefile b/test/test/Makefile index 1c08b906a..5e4f50787 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -168,6 +168,7 @@ SRCS-y += packet_burst_generator.c SRCS-y += sample_packet_forward.c SRCS-$(CONFIG_RTE_LIBRTE_BITRATE) += test_bitratestats.c SRCS-$(CONFIG_RTE_LIBRTE_LATENCY_STATS) += test_latencystats.c +SRCS-$(CONFIG_RTE_LIBRTE_PDUMP) += test_pdump.c SRCS-$(CONFIG_RTE_LIBRTE_ACL) += test_acl.c ifeq ($(CONFIG_RTE_LIBRTE_PMD_RING),y) diff --git a/test/test/test_pdump.c b/test/test/test_pdump.c new file mode 100644 index 000000000..c7f0a0740 --- /dev/null +++ b/test/test/test_pdump.c @@ -0,0 +1,256 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include <time.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdarg.h> +#include <inttypes.h> +#include <sys/queue.h> +#include <string.h> +#include <unistd.h> +#include <sys/wait.h> + +#include <rte_common.h> +#include <rte_mbuf.h> +#include <rte_pdump.h> +#include <rte_eth_ctrl.h> +#include <rte_memory.h> +#include <rte_memzone.h> +#include <rte_eal.h> +#include <rte_ring.h> +#include <rte_mempool.h> +#include <rte_eth_ring.h> +#include <rte_ethdev_driver.h> + +#include "test.h" +#include "sample_packet_forward.h" +#include "test_pdump.h" +#include "process.h" + +#define launch_p(ARGV) process_dup(ARGV, \ + sizeof(ARGV)/(sizeof(ARGV[0])), __func__) + +struct rte_ring *ring_server[NUM_RINGS]; +uint16_t portid; +uint16_t flag_for_send_pkts = 1; + +#ifdef RTE_EXEC_ENV_LINUXAPP +static char * +get_current_prefix(char *prefix, int size) +{ + char path[PATH_MAX] = { 0 }; + char buf[PATH_MAX] = { 0 }; + + /* get file for config (fd is always 3) */ + snprintf(path, sizeof(path), "/proc/self/fd/%d", 3); + + /* return NULL on error */ + if (readlink(path, buf, sizeof(buf)) == -1) + return NULL; + + /* get the basename */ + snprintf(buf, sizeof(buf), "%s", basename(buf)); + + /* copy string all the way from second char up to start of _config */ + snprintf(prefix, size, "%.*s", + (int)(strnlen(buf, sizeof(buf)) - sizeof("_config")), &buf[1]); + + return prefix; +} +#endif + +int +test_pdump_init(void) +{ + int ret = 0; + + ret = rte_pdump_init(NULL); + if (ret < 0) { + printf("rte_pdump_init failed\n"); + return -1; + } + ret = test_ring_setup(ring_server, &portid); + if (ret < 0) { + printf("test_ring_setup failed\n"); + return -1; + } + printf("pdump_init success\n"); + return ret; +} + +int +run_pdump_client_tests(void) +{ + int flags = RTE_PDUMP_FLAG_TX, ret = 0, itr; + char deviceid[] = "net_ring_net_ringa"; + struct rte_ring *ring_client; + struct rte_mempool *mp = NULL; + struct rte_eth_dev *eth_dev = NULL; + char poolname[] = "mbuf_pool_client"; + + ret = test_get_mempool(&mp, poolname); + if (ret < 0) + return -1; + mp->flags = 0x0000; + ring_client = rte_ring_create("SR0", RING_SIZE, rte_socket_id(), + RING_F_SP_ENQ | RING_F_SC_DEQ); + if (ring_client == NULL) { + printf("rte_ring_create SR0 failed"); + return -1; + } + + eth_dev = rte_eth_dev_attach_secondary(deviceid); + if (!eth_dev) { + printf("Failed to probe %s", deviceid); + return -1; + } + rte_eth_dev_probing_finish(eth_dev); + + ring_client->prod.single = 0; + ring_client->cons.single = 0; + + printf("\n***** flags = RTE_PDUMP_FLAG_TX *****\n"); + + for (itr = 0; itr < NUM_ITR; itr++) { + ret = rte_pdump_enable(portid, QUEUE_ID, flags, ring_client, + mp, NULL); + if (ret < 0) { + printf("rte_pdump_enable failed\n"); + return -1; + } + printf("pdump_enable success\n"); + + ret = rte_pdump_disable(portid, QUEUE_ID, flags); + if (ret < 0) { + printf("rte_pdump_disable failed\n"); + return -1; + } + printf("pdump_disable success\n"); + + ret = rte_pdump_enable_by_deviceid(deviceid, QUEUE_ID, flags, + ring_client, mp, NULL); + if (ret < 0) { + printf("rte_pdump_enable_by_deviceid failed\n"); + return -1; + } + printf("pdump_enable_by_deviceid success\n"); + + ret = rte_pdump_disable_by_deviceid(deviceid, QUEUE_ID, flags); + if (ret < 0) { + printf("rte_pdump_disable_by_deviceid failed\n"); + return -1; + } + printf("pdump_disable_by_deviceid success\n"); + + if (itr == 0) { + flags = RTE_PDUMP_FLAG_RX; + printf("\n***** flags = RTE_PDUMP_FLAG_RX *****\n"); + } else if (itr == 1) { + flags = RTE_PDUMP_FLAG_RXTX; + printf("\n***** flags = RTE_PDUMP_FLAG_RXTX *****\n"); + } + } + if (ring_client != NULL) + test_ring_free(ring_client); + if (mp != NULL) + test_mp_free(mp); + + return ret; +} + +int +test_pdump_uninit(void) +{ + int ret = 0; + + ret = rte_pdump_uninit(); + if (ret < 0) { + printf("rte_pdump_uninit failed\n"); + return -1; + } + if (ring_server[NUM_RINGS - 1] != NULL) + test_ring_free(ring_server[NUM_RINGS - 1]); + printf("pdump_uninit success\n"); + test_vdev_uninit("net_ring_net_ringa"); + return ret; +} + +void * +send_pkts(void *empty) +{ + int ret = 0; + struct rte_mbuf *pbuf[NUM_PACKETS] = { }; + struct rte_mempool *mp; + char poolname[] = "mbuf_pool_server"; + + ret = test_get_mbuf_from_pool(&mp, pbuf, poolname); + if (ret < 0) + printf("get_mbuf_from_pool failed\n"); + do { + ret = test_packet_forward(pbuf, portid, QUEUE_ID); + if (ret < 0) + printf("send pkts Failed\n"); + } while (flag_for_send_pkts); + test_put_mbuf_to_pool(mp, pbuf); + return empty; +} + +/* + * This function is called in the primary i.e. main test, to spawn off secondary + * processes to run actual mp tests. Uses fork() and exec pair + */ + +int +run_pdump_server_tests(void) +{ + int ret = 0; + char coremask[10]; + +#ifdef RTE_EXEC_ENV_LINUXAPP + char tmp[PATH_MAX] = { 0 }; + char prefix[PATH_MAX] = { 0 }; + + get_current_prefix(tmp, sizeof(tmp)); + snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); +#else + const char *prefix = ""; +#endif + + /* good case, using secondary */ + const char *const argv1[] = { + prgname, "-c", coremask, "--proc-type=secondary", + prefix + }; + + snprintf(coremask, sizeof(coremask), "%x", + (1 << rte_get_master_lcore())); + + ret = test_pdump_init(); + ret |= launch_p(argv1); + ret |= test_pdump_uninit(); + return ret; +} + +int +test_pdump(void) +{ + int ret = 0; + if (rte_eal_process_type() == RTE_PROC_PRIMARY) { + printf("IN PRIMARY PROCESS\n"); + ret = run_pdump_server_tests(); + if (ret < 0) + return TEST_FAILED; + } else if (rte_eal_process_type() == RTE_PROC_SECONDARY) { + printf("IN SECONDARY PROCESS\n"); + sleep(5); + ret = run_pdump_client_tests(); + if (ret < 0) + return TEST_FAILED; + } + return TEST_SUCCESS; +} + +REGISTER_TEST_COMMAND(pdump_autotest, test_pdump); diff --git a/test/test/test_pdump.h b/test/test/test_pdump.h new file mode 100644 index 000000000..2f78b83b8 --- /dev/null +++ b/test/test/test_pdump.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#ifndef _TEST_PDUMP_H_ +#define _TEST_PDUMP_H_ + + +#define QUEUE_ID 0 +#define NUM_ITR 3 + +#ifdef RTE_EXEC_ENV_BSDAPP +#define self "curproc" +#define exe "file" +#else +#define self "self" +#define exe "exe" +#endif + +/* sample test to send packets to the pdump client recursively */ +void *send_pkts(void *port); + +/* Sample test to create setup for the pdump server tests */ +int test_pdump_init(void); + +/* Sample test to teardown the pdump server setup */ +int test_pdump_uninit(void); + +/* Sample test to run the pdump client tests */ +int run_pdump_client_tests(void); + +/* Sample test to run the pdump server tests */ +int run_pdump_server_tests(void); + +/* Sample test to run the pdump client and server tests based on + * the process type + */ +int test_pdump(void); + +#endif /* _TEST_PDUMP_H_ */ -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [dpdk-dev] [PATCH v5 4/4] test: add unit test for pdump library 2018-07-24 10:54 ` [dpdk-dev] [PATCH v5 4/4] test: add unit test for pdump library Naga Suresh Somarowthu @ 2018-07-24 12:27 ` Burakov, Anatoly 0 siblings, 0 replies; 37+ messages in thread From: Burakov, Anatoly @ 2018-07-24 12:27 UTC (permalink / raw) To: Naga Suresh Somarowthu, dev; +Cc: remy.horton, reshma.pattan On 24-Jul-18 11:54 AM, Naga Suresh Somarowthu wrote: > Unit test cases are added for pdump library. > Primary process will act as server, forks a child secondary process. > Secondary process acts as client. > Server will do pdump init to serve any pdump client requests. > Server will create a vdev, send/receive packets continuously in a separate thread. > Client will create virtual rings to receive the packet dump. > Client sends pdump enable/disable requests using either port id or device id. > Packet flow direction can be tx/rx/tx&rx. > In Server, appropriate pdump callbacks are triggered when packets are transmitted/received. > Pdump packet is copied to client rings. > > Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> > Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> > --- <snip> > + char buf[PATH_MAX] = { 0 }; > + > + /* get file for config (fd is always 3) */ > + snprintf(path, sizeof(path), "/proc/self/fd/%d", 3); > + > + /* return NULL on error */ > + if (readlink(path, buf, sizeof(buf)) == -1) > + return NULL; > + > + /* get the basename */ > + snprintf(buf, sizeof(buf), "%s", basename(buf)); > + > + /* copy string all the way from second char up to start of _config */ > + snprintf(prefix, size, "%.*s", > + (int)(strnlen(buf, sizeof(buf)) - sizeof("_config")), &buf[1]); > + > + return prefix; > +} > +#endif This will not work in 18.08, see http://patches.dpdk.org/patch/43102/ Can we perhaps make it a standard test-app function? It is already duplicated in two places, this will make it third. > + > +int > +test_pdump_init(void) > +{ > + int ret = 0; > + > + ret = rte_pdump_init(NULL); > + if (ret < 0) { > + printf("rte_pdump_init failed\n"); > + return -1; > + } > + ret = test_ring_setup(ring_server, &portid); > + if (ret < 0) { > + printf("test_ring_setup failed\n"); > + return -1; > + } > + printf("pdump_init success\n"); > + return ret; > +} -- Thanks, Anatoly ^ permalink raw reply [flat|nested] 37+ messages in thread
* [dpdk-dev] [PATCH v6 0/4] add unit tests for bitrate, latency and pdump libraries 2018-07-24 10:54 ` [dpdk-dev] [PATCH v5 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu ` (3 preceding siblings ...) 2018-07-24 10:54 ` [dpdk-dev] [PATCH v5 4/4] test: add unit test for pdump library Naga Suresh Somarowthu @ 2018-07-25 17:05 ` Naga Suresh Somarowthu 2018-07-25 17:05 ` [dpdk-dev] [PATCH v6 1/4] test: add ring pmd based packet rx/tx for UT Naga Suresh Somarowthu ` (4 more replies) 4 siblings, 5 replies; 37+ messages in thread From: Naga Suresh Somarowthu @ 2018-07-25 17:05 UTC (permalink / raw) To: dev; +Cc: remy.horton, reshma.pattan, Naga Suresh Somarowthu 1/4: add ring pmd based packet helper functions for UT 2/4: unit test cases added for bitrate library 3/4: unit test cases added for latencystats library 4/4: unit test cases added for pdump library Patches 2/4,3/4 depends on 1/4 Patch 4/4 depends on 1/4 and the below patch http://patches.dpdk.org/patch/43354/ Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> Reviewed-by: Remy Horton <remy.horton@intel.com> --- v6: updated ring variable appropriately v5: rebased, freed pools and rings, created common patch set --- Naga Suresh Somarowthu (4): test: add ring pmd based packet rx/tx for UT test: add unit tests for bitrate library test: add unit tests for latencystats library test: add unit test for pdump library test/test/Makefile | 9 ++ test/test/autotest_data.py | 12 ++ test/test/process.h | 12 ++ test/test/sample_packet_forward.c | 115 +++++++++++++++++++ test/test/sample_packet_forward.h | 40 +++++++ test/test/test.c | 2 + test/test/test_bitratestats.c | 227 +++++++++++++++++++++++++++++++++++++ test/test/test_latencystats.c | 216 +++++++++++++++++++++++++++++++++++ test/test/test_pdump.c | 232 ++++++++++++++++++++++++++++++++++++++ test/test/test_pdump.h | 40 +++++++ 10 files changed, 905 insertions(+) create mode 100644 test/test/sample_packet_forward.c create mode 100644 test/test/sample_packet_forward.h create mode 100644 test/test/test_bitratestats.c create mode 100644 test/test/test_latencystats.c create mode 100644 test/test/test_pdump.c create mode 100644 test/test/test_pdump.h -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* [dpdk-dev] [PATCH v6 1/4] test: add ring pmd based packet rx/tx for UT 2018-07-25 17:05 ` [dpdk-dev] [PATCH v6 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu @ 2018-07-25 17:05 ` Naga Suresh Somarowthu 2018-07-26 9:59 ` Burakov, Anatoly 2018-07-25 17:05 ` [dpdk-dev] [PATCH v6 2/4] test: add unit tests for bitrate library Naga Suresh Somarowthu ` (3 subsequent siblings) 4 siblings, 1 reply; 37+ messages in thread From: Naga Suresh Somarowthu @ 2018-07-25 17:05 UTC (permalink / raw) To: dev; +Cc: remy.horton, reshma.pattan, Naga Suresh Somarowthu Added ring pmd based packet rx/tx helper functions for verifying Latency, Bitrate and pdump lib UTs. Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> --- test/test/Makefile | 1 + test/test/sample_packet_forward.c | 115 ++++++++++++++++++++++++++++++++++++++ test/test/sample_packet_forward.h | 40 +++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 test/test/sample_packet_forward.c create mode 100644 test/test/sample_packet_forward.h diff --git a/test/test/Makefile b/test/test/Makefile index e6967bab6..9f7d398e4 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -165,6 +165,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_REORDER) += test_reorder.c SRCS-y += virtual_pmd.c SRCS-y += packet_burst_generator.c +SRCS-y += sample_packet_forward.c SRCS-$(CONFIG_RTE_LIBRTE_ACL) += test_acl.c ifeq ($(CONFIG_RTE_LIBRTE_PMD_RING),y) diff --git a/test/test/sample_packet_forward.c b/test/test/sample_packet_forward.c new file mode 100644 index 000000000..467735264 --- /dev/null +++ b/test/test/sample_packet_forward.c @@ -0,0 +1,115 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include <string.h> +#include <errno.h> +#include <time.h> + +#include <rte_memcpy.h> +#include <rte_common.h> +#include <rte_eth_ring.h> +#include <rte_ethdev.h> +#include <rte_mbuf.h> +#include <rte_bus_vdev.h> + +#include "sample_packet_forward.h" +#include "test.h" + +/* Sample test to create virtual rings and tx,rx portid from rings */ +int +test_ring_setup(struct rte_ring **ring, uint16_t *portid) +{ + *ring = rte_ring_create("R0", RING_SIZE, rte_socket_id(), + RING_F_SP_ENQ | RING_F_SC_DEQ); + if (*ring == NULL) { + printf("%s() line %u: rte_ring_create R0 failed", + __func__, __LINE__); + return -1; + } + *portid = rte_eth_from_rings("net_ringa", ring, NUM_QUEUES, + ring, NUM_QUEUES, rte_socket_id()); + + return 0; +} + +/* Sample test to free the mempool */ +void +test_mp_free(struct rte_mempool *mp) +{ + rte_mempool_free(mp); +} + +/* Sample test to free the virtual rings */ +void +test_ring_free(struct rte_ring *rxtx) +{ + rte_ring_free(rxtx); +} + +/* Sample test to release the vdev */ +void +test_vdev_uninit(const char *vdev) +{ + rte_vdev_uninit(vdev); +} + +/* sample test to deallocate the allocated buffers */ +int +test_get_mempool(struct rte_mempool **mp, char *poolname) +{ + *mp = rte_pktmbuf_pool_create(poolname, NB_MBUF, 32, 0, + RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); + if (*mp == NULL) + return -1; + return 0; +} + +/* sample test to allocate buffer for pkts */ +int +test_get_mbuf_from_pool(struct rte_mempool **mp, struct rte_mbuf **pbuf, + char *poolname) +{ + int ret = 0; + + ret = test_get_mempool(mp, poolname); + if (ret < 0) + return -1; + if (rte_pktmbuf_alloc_bulk(*mp, pbuf, NUM_PACKETS) != 0) { + printf("%s() line %u: rte_pktmbuf_alloc_bulk failed", __func__, + __LINE__); + return -1; + } + return 0; +} + +/* sample test to deallocate the allocated buffers */ +void +test_put_mbuf_to_pool(struct rte_mempool *mp, struct rte_mbuf **pbuf) +{ + int itr = 0; + + for (itr = 0; itr < NUM_PACKETS; itr++) + rte_pktmbuf_free(pbuf[itr]); + rte_mempool_free(mp); +} + +/* Sample test to forward packets using virtual portids */ +int +test_packet_forward(struct rte_mbuf **pbuf, uint16_t portid, uint16_t queue_id) +{ + /* send and receive packet and check for stats update */ + if (rte_eth_tx_burst(portid, queue_id, pbuf, NUM_PACKETS) + < NUM_PACKETS) { + printf("%s() line %u: Error sending packet to" + " port %d\n", __func__, __LINE__, portid); + return -1; + } + if (rte_eth_rx_burst(portid, queue_id, pbuf, NUM_PACKETS) + < NUM_PACKETS) { + printf("%s() line %u: Error receiving packet from" + " port %d\n", __func__, __LINE__, portid); + return -1; + } + return 0; +} diff --git a/test/test/sample_packet_forward.h b/test/test/sample_packet_forward.h new file mode 100644 index 000000000..0f0ecf877 --- /dev/null +++ b/test/test/sample_packet_forward.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#ifndef _SAMPLE_PACKET_FORWARD_H_ +#define _SAMPLE_PACKET_FORWARD_H_ + +/* MACROS to support virtual ring creation */ +#define RING_SIZE 256 +#define NUM_QUEUES 1 +#define NB_MBUF 512 + +#define NUM_PACKETS 10 + +/* Sample test to create virtual rings and tx,rx portid from rings */ +int test_ring_setup(struct rte_ring **ring, uint16_t *portid); + +/* Sample test to free the virtual rings */ +void test_ring_free(struct rte_ring *rxtx); + +/* Sample test to forward packet using virtual port id */ +int test_packet_forward(struct rte_mbuf **pbuf, uint16_t portid, + uint16_t queue_id); + +/* sample test to allocate buffer for pkts */ +int test_get_mbuf_from_pool(struct rte_mempool **mp, struct rte_mbuf **pbuf, + char *poolname); + +/* Sample test to create the mempool */ +int test_get_mempool(struct rte_mempool **mp, char *poolname); + +/* sample test to deallocate the allocated buffers */ +void test_put_mbuf_to_pool(struct rte_mempool *mp, struct rte_mbuf **pbuf); + +/* Sample test to free the mempool */ +void test_mp_free(struct rte_mempool *mp); + +/* Sample test to release the vdev */ +void test_vdev_uninit(const char *vdev); +#endif /* _SAMPLE_PACKET_FORWARD_H_ */ -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [dpdk-dev] [PATCH v6 1/4] test: add ring pmd based packet rx/tx for UT 2018-07-25 17:05 ` [dpdk-dev] [PATCH v6 1/4] test: add ring pmd based packet rx/tx for UT Naga Suresh Somarowthu @ 2018-07-26 9:59 ` Burakov, Anatoly 0 siblings, 0 replies; 37+ messages in thread From: Burakov, Anatoly @ 2018-07-26 9:59 UTC (permalink / raw) To: Naga Suresh Somarowthu, dev; +Cc: remy.horton, reshma.pattan On 25-Jul-18 6:05 PM, Naga Suresh Somarowthu wrote: > Added ring pmd based packet rx/tx helper functions > for verifying Latency, Bitrate and pdump lib UTs. > > Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> > Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> > --- <snip> > + ret = test_get_mempool(mp, poolname); > + if (ret < 0) > + return -1; > + if (rte_pktmbuf_alloc_bulk(*mp, pbuf, NUM_PACKETS) != 0) { > + printf("%s() line %u: rte_pktmbuf_alloc_bulk failed", __func__, > + __LINE__); > + return -1; > + } > + return 0; > +} > + > +/* sample test to deallocate the allocated buffers */ > +void > +test_put_mbuf_to_pool(struct rte_mempool *mp, struct rte_mbuf **pbuf) > +{ > + int itr = 0; > + > + for (itr = 0; itr < NUM_PACKETS; itr++) > + rte_pktmbuf_free(pbuf[itr]); > + rte_mempool_free(mp); > +} The name and description of the above function is a little misleading. It says it will deallocate buffers, but nowhere does it say that it will also deallocate the mempool. Is that intentional? Other than that, Reviewed-by: Anatoly Burakov <anatoly.burakov@intel.com> -- Thanks, Anatoly ^ permalink raw reply [flat|nested] 37+ messages in thread
* [dpdk-dev] [PATCH v6 2/4] test: add unit tests for bitrate library 2018-07-25 17:05 ` [dpdk-dev] [PATCH v6 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu 2018-07-25 17:05 ` [dpdk-dev] [PATCH v6 1/4] test: add ring pmd based packet rx/tx for UT Naga Suresh Somarowthu @ 2018-07-25 17:05 ` Naga Suresh Somarowthu 2018-07-25 17:05 ` [dpdk-dev] [PATCH v6 3/4] test: add unit tests for latencystats library Naga Suresh Somarowthu ` (2 subsequent siblings) 4 siblings, 0 replies; 37+ messages in thread From: Naga Suresh Somarowthu @ 2018-07-25 17:05 UTC (permalink / raw) To: dev; +Cc: remy.horton, reshma.pattan, Naga Suresh Somarowthu Unit Test Cases for BitRate library. Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> Reviewed-by: Remy Horton <remy.horton@intel.com> --- test/test/Makefile | 1 + test/test/autotest_data.py | 6 ++ test/test/test_bitratestats.c | 227 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 234 insertions(+) create mode 100644 test/test/test_bitratestats.c diff --git a/test/test/Makefile b/test/test/Makefile index 9f7d398e4..c619877f0 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -183,6 +183,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_PMD_RING) += test_pmd_ring_perf.c SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev_blockcipher.c SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev.c SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev_asym.c +SRCS-$(CONFIG_RTE_LIBRTE_BITRATE) += test_bitratestats.c ifeq ($(CONFIG_RTE_COMPRESSDEV_TEST),y) SRCS-$(CONFIG_RTE_LIBRTE_COMPRESSDEV) += test_compressdev.c diff --git a/test/test/autotest_data.py b/test/test/autotest_data.py index aacfe0a66..419520342 100644 --- a/test/test/autotest_data.py +++ b/test/test/autotest_data.py @@ -293,6 +293,12 @@ def per_sockets(num): "Tests": [ { + "Name": "Bitratestats autotest", + "Command": "bitratestats_autotest", + "Func": default_autotest, + "Report": None, + }, + { "Name": "PMD ring autotest", "Command": "ring_pmd_autotest", "Func": default_autotest, diff --git a/test/test/test_bitratestats.c b/test/test/test_bitratestats.c new file mode 100644 index 000000000..62a175865 --- /dev/null +++ b/test/test/test_bitratestats.c @@ -0,0 +1,227 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include <string.h> +#include <errno.h> +#include <time.h> + +#include <rte_log.h> +#include <rte_lcore.h> +#include <rte_mbuf.h> +#include <rte_malloc.h> +#include <rte_common.h> +#include <rte_metrics.h> +#include <rte_bitrate.h> + +#include "test.h" +#include "sample_packet_forward.h" + +#define BIT_NUM_PACKETS 10 +#define QUEUE_ID 0 + +uint16_t portid; +struct rte_stats_bitrates *bitrate_data; +struct rte_ring *ring; + +/* To test whether rte_stats_bitrate_create is successful */ +static int +test_stats_bitrate_create(void) +{ + bitrate_data = rte_stats_bitrate_create(); + TEST_ASSERT(bitrate_data != NULL, "rte_stats_bitrate_create failed"); + + return TEST_SUCCESS; +} + +/* To test bit rate registration */ +static int +test_stats_bitrate_reg(void) +{ + int ret = 0; + + /* Test to register bit rate without metrics init */ + ret = rte_stats_bitrate_reg(bitrate_data); + TEST_ASSERT(ret < 0, "Test Failed: rte_stats_bitrate_reg succeeded " + "without metrics init, ret:%d", ret); + + /* Metrics initialization */ + rte_metrics_init(rte_socket_id()); + /* Test to register bit rate after metrics init */ + ret = rte_stats_bitrate_reg(bitrate_data); + TEST_ASSERT((ret >= 0), "Test Failed: rte_stats_bitrate_reg %d", ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate registration with invalid pointer */ +static int +test_stats_bitrate_reg_invalidpointer(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_reg(NULL); + TEST_ASSERT(ret < 0, "Test Failed: Expected failure < 0 but " + "got %d", ret); + + return TEST_SUCCESS; +} + +/* To test bit rate calculation with invalid bit rate data pointer */ +static int +test_stats_bitrate_calc_invalid_bitrate_data(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(NULL, portid); + TEST_ASSERT(ret < 0, "Test Failed: rte_stats_bitrate_calc " + "ret:%d", ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate calculation with invalid portid + * (higher than max ports) + */ +static int +test_stats_bitrate_calc_invalid_portid_1(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(bitrate_data, 33); + TEST_ASSERT(ret == -EINVAL, "Test Failed: Expected -%d for higher " + "portid rte_stats_bitrate_calc ret:%d", EINVAL, ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate calculation with invalid portid (lesser than 0) */ +static int +test_stats_bitrate_calc_invalid_portid_2(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(bitrate_data, -1); + TEST_ASSERT(ret == -EINVAL, "Test Failed: Expected -%d for invalid " + "portid rte_stats_bitrate_calc ret:%d", EINVAL, ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate calculation with non-existing portid */ +static int +test_stats_bitrate_calc_non_existing_portid(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(bitrate_data, 31); + TEST_ASSERT(ret == -EINVAL, "Test Failed: Expected -%d for " + "non-existing portid rte_stats_bitrate_calc ret:%d", + EINVAL, ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate calculation with valid bit rate data, valid portid */ +static int +test_stats_bitrate_calc(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(bitrate_data, portid); + TEST_ASSERT(ret >= 0, "Test Failed: Expected >=0 for valid portid " + "rte_stats_bitrate_calc ret:%d", ret); + + return TEST_SUCCESS; +} + +static int +test_bit_packet_forward(void) +{ + int ret; + struct rte_mbuf *pbuf[BIT_NUM_PACKETS] = { }; + struct rte_mempool *mp; + char poolname[] = "mbuf_pool"; + ret = test_get_mbuf_from_pool(&mp, pbuf, poolname); + if (ret < 0) { + printf("allocate mbuf pool Failed\n"); + return TEST_FAILED; + } + ret = test_packet_forward(pbuf, portid, QUEUE_ID); + if (ret < 0) + printf("send pkts Failed\n"); + test_put_mbuf_to_pool(mp, pbuf); + + return TEST_SUCCESS; +} + +static int +test_bit_ring_setup(void) +{ + test_ring_setup(&ring, &portid); + printf("port in ring setup : %d\n", portid); + + return TEST_SUCCESS; +} + +static void +test_bit_ring_free(void) +{ + test_ring_free(ring); + test_vdev_uninit("net_ring_net_ringa"); +} + +static struct +unit_test_suite bitratestats_testsuite = { + .suite_name = "BitRate Stats Unit Test Suite", + .setup = test_bit_ring_setup, + .teardown = test_bit_ring_free, + .unit_test_cases = { + /* TEST CASE 1: Test to create bit rate data */ + TEST_CASE(test_stats_bitrate_create), + + /* TEST CASE 2: Test to register bit rate metrics + * without metrics init and after metrics init + */ + TEST_CASE(test_stats_bitrate_reg), + + /* TEST CASE 3: Test to register bit rate metrics + * with invalid bit rate data + */ + TEST_CASE(test_stats_bitrate_reg_invalidpointer), + + /* TEST CASE 4: Test to calculate bit rate data metrics + * with invalid bit rate data + */ + TEST_CASE(test_stats_bitrate_calc_invalid_bitrate_data), + + /* TEST CASE 5: Test to calculate bit rate data metrics + * with portid exceeding the max ports + */ + TEST_CASE(test_stats_bitrate_calc_invalid_portid_1), + + /* TEST CASE 6: Test to calculate bit rate data metrics + * with portid less than 0 + */ + TEST_CASE(test_stats_bitrate_calc_invalid_portid_2), + + /* TEST CASE 7: Test to calculate bit rate data metrics + * with non-existing portid + */ + TEST_CASE(test_stats_bitrate_calc_non_existing_portid), + + /* TEST CASE 8: Test to calculate bit rate data metrics + * with valid portid, valid bit rate data + */ + TEST_CASE_ST(test_bit_packet_forward, NULL, + test_stats_bitrate_calc), + TEST_CASES_END() + } +}; + +static int +test_bitratestats(void) +{ + return unit_test_suite_runner(&bitratestats_testsuite); +} +REGISTER_TEST_COMMAND(bitratestats_autotest, test_bitratestats); -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* [dpdk-dev] [PATCH v6 3/4] test: add unit tests for latencystats library 2018-07-25 17:05 ` [dpdk-dev] [PATCH v6 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu 2018-07-25 17:05 ` [dpdk-dev] [PATCH v6 1/4] test: add ring pmd based packet rx/tx for UT Naga Suresh Somarowthu 2018-07-25 17:05 ` [dpdk-dev] [PATCH v6 2/4] test: add unit tests for bitrate library Naga Suresh Somarowthu @ 2018-07-25 17:05 ` Naga Suresh Somarowthu 2018-07-25 17:06 ` [dpdk-dev] [PATCH v6 4/4] test: add unit test for pdump library Naga Suresh Somarowthu 2018-07-26 12:50 ` [dpdk-dev] [PATCH v7 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu 4 siblings, 0 replies; 37+ messages in thread From: Naga Suresh Somarowthu @ 2018-07-25 17:05 UTC (permalink / raw) To: dev; +Cc: remy.horton, reshma.pattan, Naga Suresh Somarowthu Unit Test Cases added for latencystats library. Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> --- test/test/Makefile | 1 + test/test/autotest_data.py | 6 ++ test/test/test_latencystats.c | 216 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 223 insertions(+) create mode 100644 test/test/test_latencystats.c diff --git a/test/test/Makefile b/test/test/Makefile index c619877f0..bba3be1be 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -184,6 +184,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev_blockcipher.c SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev.c SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev_asym.c SRCS-$(CONFIG_RTE_LIBRTE_BITRATE) += test_bitratestats.c +SRCS-$(CONFIG_RTE_LIBRTE_LATENCY_STATS) += test_latencystats.c ifeq ($(CONFIG_RTE_COMPRESSDEV_TEST),y) SRCS-$(CONFIG_RTE_LIBRTE_COMPRESSDEV) += test_compressdev.c diff --git a/test/test/autotest_data.py b/test/test/autotest_data.py index 419520342..3eccc4e1a 100644 --- a/test/test/autotest_data.py +++ b/test/test/autotest_data.py @@ -299,6 +299,12 @@ def per_sockets(num): "Report": None, }, { + "Name": "Latencystats autotest", + "Command": "latencystats_autotest", + "Func": default_autotest, + "Report": None, + }, + { "Name": "PMD ring autotest", "Command": "ring_pmd_autotest", "Func": default_autotest, diff --git a/test/test/test_latencystats.c b/test/test/test_latencystats.c new file mode 100644 index 000000000..f2287a2b7 --- /dev/null +++ b/test/test/test_latencystats.c @@ -0,0 +1,216 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <time.h> + +#include <rte_common.h> +#include <rte_metrics.h> +#include <rte_latencystats.h> +#include <rte_eth_ring.h> +#include <rte_ethdev.h> +#include <rte_mbuf.h> +#include "test.h" +#include "sample_packet_forward.h" +#define NUM_STATS 4 +#define LATENCY_NUM_PACKETS 10 +#define QUEUE_ID 0 + +uint16_t portid; +struct rte_ring *ring; + +struct rte_metric_name lat_stats_strings[] = { + {"min_latency_ns"}, + {"avg_latency_ns"}, + {"max_latency_ns"}, + {"jitter_ns"}, +}; + +/* Test case for latency init with metrics init */ +static int test_latency_init(void) +{ + int ret = 0; + + /* Metrics Initialization */ + rte_metrics_init(rte_socket_id()); + + ret = rte_latencystats_init(1, NULL); + TEST_ASSERT(ret >= 0, "Test Failed: rte_latencystats_init failed"); + + return TEST_SUCCESS; +} + +/* Test case to update the latency stats */ +static int test_latency_update(void) +{ + int ret = 0; + + ret = rte_latencystats_update(); + TEST_ASSERT(ret >= 0, "Test Failed: rte_latencystats_update failed"); + + return TEST_SUCCESS; +} + +/* Test case to uninit latency stats */ +static int test_latency_uninit(void) +{ + int ret = 0; + + ret = rte_latencystats_uninit(); + TEST_ASSERT(ret >= 0, "Test Failed: rte_latencystats_uninit failed"); + + return TEST_SUCCESS; +} + +/* Test case to get names of latency stats */ +static int test_latencystats_get_names(void) +{ + int ret = 0; + int size = 0; + struct rte_metric_name names[NUM_STATS] = { 0 }; + struct rte_metric_name wrongnames[NUM_STATS - 2] = { 0 }; + + /* Success Test: Valid names and size */ + size = NUM_STATS; + ret = rte_latencystats_get_names(names, size); + for (int i = 0; i <= NUM_STATS; i++) { + if (strcmp(lat_stats_strings[i].name, names[i].name) == 0) + printf(" %s\n", names[i].name); + else + printf("Failed: Names are not matched\n"); + } + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get metrics names"); + + /* Failure Test: Invalid names and valid size */ + ret = rte_latencystats_get_names(NULL, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get the metrics count," + "Actual: %d Expected: %d", ret, NUM_STATS); + + /* Failure Test: Valid names and invalid size */ + size = 0; + ret = rte_latencystats_get_names(names, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get the metrics count," + "Actual: %d Expected: %d", ret, NUM_STATS); + + /* Failure Test: Invalid names (array size lesser than size) */ + size = NUM_STATS + 1; + ret = rte_latencystats_get_names(wrongnames, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get metrics names"); + return TEST_SUCCESS; +} + +/* Test case to get latency stats values */ +static int test_latencystats_get(void) +{ + int ret = 0; + int size = 0; + struct rte_metric_value values[NUM_STATS] = { 0 }; + struct rte_metric_value wrongvalues[NUM_STATS - 2] = { 0 }; + + /* Success Test: Valid values and valid size */ + size = NUM_STATS; + ret = rte_latencystats_get(values, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get latency metrics" + " values"); + for (int i = 0; i < NUM_STATS; i++) + printf("values: %ld\n", values[i].value); + + /* Failure Test: Invalid values and valid size */ + ret = rte_latencystats_get(NULL, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get the stats count," + "Actual: %d Expected: %d", ret, NUM_STATS); + + /* Failure Test: Valid values and invalid size */ + size = 0; + ret = rte_latencystats_get(values, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get the stats count," + "Actual: %d Expected: %d", ret, NUM_STATS); + + /* Failure Test: Invalid values(array size lesser than size) + * and invalid size + */ + size = NUM_STATS + 2; + ret = rte_latencystats_get(wrongvalues, size); + TEST_ASSERT(ret == NUM_STATS, "Test Failed to get latency metrics" + " values"); + + return TEST_SUCCESS; +} + +static int test_latency_ring_setup(void) +{ + test_ring_setup(&ring, &portid); + + return TEST_SUCCESS; +} + +static void test_latency_ring_free(void) +{ + test_ring_free(ring); + test_vdev_uninit("net_ring_net_ringa"); +} + +static int test_latency_packet_forward(void) +{ + int ret; + struct rte_mbuf *pbuf[LATENCY_NUM_PACKETS] = { }; + struct rte_mempool *mp; + char poolname[] = "mbuf_pool"; + + ret = test_get_mbuf_from_pool(&mp, pbuf, poolname); + if (ret < 0) { + printf("allocate mbuf pool Failed\n"); + return TEST_FAILED; + } + ret = test_packet_forward(pbuf, portid, QUEUE_ID); + if (ret < 0) + printf("send pkts Failed\n"); + test_put_mbuf_to_pool(mp, pbuf); + + return TEST_SUCCESS; +} + +static struct +unit_test_suite latencystats_testsuite = { + .suite_name = "Latency Stats Unit Test Suite", + .setup = test_latency_ring_setup, + .teardown = test_latency_ring_free, + .unit_test_cases = { + + /* Test Case 1: To check latency init with + * metrics init + */ + TEST_CASE_ST(NULL, NULL, test_latency_init), + + /* Test Case 2: Do packet forwarding for metrics + * calculation and check the latency metrics values + * are updated + */ + TEST_CASE_ST(test_latency_packet_forward, NULL, + test_latency_update), + /* Test Case 3: To check whether latency stats names + * are retrieved + */ + TEST_CASE_ST(NULL, NULL, test_latencystats_get_names), + + /* Test Case 4: To check whether latency stats + * values are retrieved + */ + TEST_CASE_ST(NULL, NULL, test_latencystats_get), + + /* Test Case 5: To check uninit of latency test */ + TEST_CASE_ST(NULL, NULL, test_latency_uninit), + + TEST_CASES_END() + } +}; + +static int test_latencystats(void) +{ + return unit_test_suite_runner(&latencystats_testsuite); +} + +REGISTER_TEST_COMMAND(latencystats_autotest, test_latencystats); -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* [dpdk-dev] [PATCH v6 4/4] test: add unit test for pdump library 2018-07-25 17:05 ` [dpdk-dev] [PATCH v6 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu ` (2 preceding siblings ...) 2018-07-25 17:05 ` [dpdk-dev] [PATCH v6 3/4] test: add unit tests for latencystats library Naga Suresh Somarowthu @ 2018-07-25 17:06 ` Naga Suresh Somarowthu 2018-07-26 10:02 ` Burakov, Anatoly 2018-07-26 12:50 ` [dpdk-dev] [PATCH v7 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu 4 siblings, 1 reply; 37+ messages in thread From: Naga Suresh Somarowthu @ 2018-07-25 17:06 UTC (permalink / raw) To: dev; +Cc: remy.horton, reshma.pattan, Naga Suresh Somarowthu Unit test cases are added for pdump library. Primary process will act as server, forks a child secondary process. Secondary process acts as client. Server will do pdump init to serve any pdump client requests. Server will create a vdev, send/receive packets continuously in a separate thread. Client will create virtual rings to receive the packet dump. Client sends pdump enable/disable requests using either port/device id. Packet flow direction can be tx/rx/tx&rx. In Server, appropriate pdump callbacks are triggered, when packets are transmitted/received. Pdump packet is copied to client rings. Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> --- test/test/Makefile | 6 ++ test/test/process.h | 12 +++ test/test/test.c | 2 + test/test/test_pdump.c | 232 +++++++++++++++++++++++++++++++++++++++++++++++++ test/test/test_pdump.h | 40 +++++++++ 5 files changed, 292 insertions(+) create mode 100644 test/test/test_pdump.c create mode 100644 test/test/test_pdump.h diff --git a/test/test/Makefile b/test/test/Makefile index bba3be1be..3e7baef76 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -185,6 +185,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev.c SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev_asym.c SRCS-$(CONFIG_RTE_LIBRTE_BITRATE) += test_bitratestats.c SRCS-$(CONFIG_RTE_LIBRTE_LATENCY_STATS) += test_latencystats.c +SRCS-$(CONFIG_RTE_LIBRTE_PDUMP) += test_pdump.c ifeq ($(CONFIG_RTE_COMPRESSDEV_TEST),y) SRCS-$(CONFIG_RTE_LIBRTE_COMPRESSDEV) += test_compressdev.c @@ -214,6 +215,11 @@ CFLAGS += $(WERROR_FLAGS) CFLAGS += -D_GNU_SOURCE LDLIBS += -lm + +ifeq ($(CONFIG_RTE_LIBRTE_PDUMP),y) +LDLIBS += -lpthread +endif + ifeq ($(CONFIG_RTE_COMPRESSDEV_TEST),y) ifeq ($(CONFIG_RTE_LIBRTE_COMPRESSDEV),y) LDLIBS += -lz diff --git a/test/test/process.h b/test/test/process.h index 11986d5c2..1e7adde0e 100644 --- a/test/test/process.h +++ b/test/test/process.h @@ -13,6 +13,10 @@ #define exe "exe" #endif +#include <pthread.h> +extern void *send_pkts(void *empty); +extern uint16_t flag_for_send_pkts; + /* * launches a second copy of the test process using the given argv parameters, * which should include argv[0] as the process name. To identify in the @@ -26,6 +30,7 @@ process_dup(const char *const argv[], int numargs, const char *env_value) char *argv_cpy[numargs + 1]; int i, fd, status; char path[32]; + pthread_t thread; pid_t pid = fork(); if (pid < 0) @@ -56,8 +61,15 @@ process_dup(const char *const argv[], int numargs, const char *env_value) rte_panic("Cannot exec\n"); } /* parent process does a wait */ + if ((strcmp(env_value, "run_pdump_server_tests") == 0)) + pthread_create(&thread, NULL, &send_pkts, NULL); + while (wait(&status) != pid) ; + if ((strcmp(env_value, "run_pdump_server_tests") == 0)) { + flag_for_send_pkts = 0; + pthread_join(thread, NULL); + } return status; } diff --git a/test/test/test.c b/test/test/test.c index 44dfe20ef..a54b0d142 100644 --- a/test/test/test.c +++ b/test/test/test.c @@ -30,6 +30,7 @@ extern cmdline_parse_ctx_t main_ctx[]; #endif #include "test.h" +#include "test_pdump.h" #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1 @@ -49,6 +50,7 @@ do_recursive_call(void) int (*action_fn)(void); } actions[] = { { "run_secondary_instances", test_mp_secondary }, + { "run_pdump_server_tests", test_pdump }, { "test_missing_c_flag", no_action }, { "test_master_lcore_flag", no_action }, { "test_invalid_n_flag", no_action }, diff --git a/test/test/test_pdump.c b/test/test/test_pdump.c new file mode 100644 index 000000000..cfdda4d39 --- /dev/null +++ b/test/test/test_pdump.c @@ -0,0 +1,232 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include <time.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdarg.h> +#include <inttypes.h> +#include <sys/queue.h> +#include <string.h> +#include <unistd.h> +#include <sys/wait.h> + +#include <rte_common.h> +#include <rte_mbuf.h> +#include <rte_pdump.h> +#include <rte_eth_ctrl.h> +#include <rte_memory.h> +#include <rte_memzone.h> +#include <rte_eal.h> +#include <rte_ring.h> +#include <rte_mempool.h> +#include <rte_eth_ring.h> +#include <rte_ethdev_driver.h> +#include <libgen.h> + +#include "test.h" +#include "sample_packet_forward.h" +#include "test_pdump.h" +#include "process.h" + +#define launch_p(ARGV) process_dup(ARGV, \ + sizeof(ARGV)/(sizeof(ARGV[0])), __func__) + +struct rte_ring *ring_server; +uint16_t portid; +uint16_t flag_for_send_pkts = 1; + +int +test_pdump_init(void) +{ + int ret = 0; + + ret = rte_pdump_init(NULL); + if (ret < 0) { + printf("rte_pdump_init failed\n"); + return -1; + } + ret = test_ring_setup(&ring_server, &portid); + if (ret < 0) { + printf("test_ring_setup failed\n"); + return -1; + } + printf("pdump_init success\n"); + return ret; +} + +int +run_pdump_client_tests(void) +{ + int flags = RTE_PDUMP_FLAG_TX, ret = 0, itr; + char deviceid[] = "net_ring_net_ringa"; + struct rte_ring *ring_client; + struct rte_mempool *mp = NULL; + struct rte_eth_dev *eth_dev = NULL; + char poolname[] = "mbuf_pool_client"; + + ret = test_get_mempool(&mp, poolname); + if (ret < 0) + return -1; + mp->flags = 0x0000; + ring_client = rte_ring_create("SR0", RING_SIZE, rte_socket_id(), + RING_F_SP_ENQ | RING_F_SC_DEQ); + if (ring_client == NULL) { + printf("rte_ring_create SR0 failed"); + return -1; + } + + eth_dev = rte_eth_dev_attach_secondary(deviceid); + if (!eth_dev) { + printf("Failed to probe %s", deviceid); + return -1; + } + rte_eth_dev_probing_finish(eth_dev); + + ring_client->prod.single = 0; + ring_client->cons.single = 0; + + printf("\n***** flags = RTE_PDUMP_FLAG_TX *****\n"); + + for (itr = 0; itr < NUM_ITR; itr++) { + ret = rte_pdump_enable(portid, QUEUE_ID, flags, ring_client, + mp, NULL); + if (ret < 0) { + printf("rte_pdump_enable failed\n"); + return -1; + } + printf("pdump_enable success\n"); + + ret = rte_pdump_disable(portid, QUEUE_ID, flags); + if (ret < 0) { + printf("rte_pdump_disable failed\n"); + return -1; + } + printf("pdump_disable success\n"); + + ret = rte_pdump_enable_by_deviceid(deviceid, QUEUE_ID, flags, + ring_client, mp, NULL); + if (ret < 0) { + printf("rte_pdump_enable_by_deviceid failed\n"); + return -1; + } + printf("pdump_enable_by_deviceid success\n"); + + ret = rte_pdump_disable_by_deviceid(deviceid, QUEUE_ID, flags); + if (ret < 0) { + printf("rte_pdump_disable_by_deviceid failed\n"); + return -1; + } + printf("pdump_disable_by_deviceid success\n"); + + if (itr == 0) { + flags = RTE_PDUMP_FLAG_RX; + printf("\n***** flags = RTE_PDUMP_FLAG_RX *****\n"); + } else if (itr == 1) { + flags = RTE_PDUMP_FLAG_RXTX; + printf("\n***** flags = RTE_PDUMP_FLAG_RXTX *****\n"); + } + } + if (ring_client != NULL) + test_ring_free(ring_client); + if (mp != NULL) + test_mp_free(mp); + + return ret; +} + +int +test_pdump_uninit(void) +{ + int ret = 0; + + ret = rte_pdump_uninit(); + if (ret < 0) { + printf("rte_pdump_uninit failed\n"); + return -1; + } + if (ring_server != NULL) + test_ring_free(ring_server); + printf("pdump_uninit success\n"); + test_vdev_uninit("net_ring_net_ringa"); + return ret; +} + +void * +send_pkts(void *empty) +{ + int ret = 0; + struct rte_mbuf *pbuf[NUM_PACKETS] = { }; + struct rte_mempool *mp; + char poolname[] = "mbuf_pool_server"; + + ret = test_get_mbuf_from_pool(&mp, pbuf, poolname); + if (ret < 0) + printf("get_mbuf_from_pool failed\n"); + do { + ret = test_packet_forward(pbuf, portid, QUEUE_ID); + if (ret < 0) + printf("send pkts Failed\n"); + } while (flag_for_send_pkts); + test_put_mbuf_to_pool(mp, pbuf); + return empty; +} + +/* + * This function is called in the primary i.e. main test, to spawn off secondary + * processes to run actual mp tests. Uses fork() and exec pair + */ + +int +run_pdump_server_tests(void) +{ + int ret = 0; + char coremask[10]; + +#ifdef RTE_EXEC_ENV_LINUXAPP + char tmp[PATH_MAX] = { 0 }; + char prefix[PATH_MAX] = { 0 }; + + get_current_prefix(tmp, sizeof(tmp)); + snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); +#else + const char *prefix = ""; +#endif + + /* good case, using secondary */ + const char *const argv1[] = { + prgname, "-c", coremask, "--proc-type=secondary", + prefix + }; + + snprintf(coremask, sizeof(coremask), "%x", + (1 << rte_get_master_lcore())); + + ret = test_pdump_init(); + ret |= launch_p(argv1); + ret |= test_pdump_uninit(); + return ret; +} + +int +test_pdump(void) +{ + int ret = 0; + if (rte_eal_process_type() == RTE_PROC_PRIMARY) { + printf("IN PRIMARY PROCESS\n"); + ret = run_pdump_server_tests(); + if (ret < 0) + return TEST_FAILED; + } else if (rte_eal_process_type() == RTE_PROC_SECONDARY) { + printf("IN SECONDARY PROCESS\n"); + sleep(5); + ret = run_pdump_client_tests(); + if (ret < 0) + return TEST_FAILED; + } + return TEST_SUCCESS; +} + +REGISTER_TEST_COMMAND(pdump_autotest, test_pdump); diff --git a/test/test/test_pdump.h b/test/test/test_pdump.h new file mode 100644 index 000000000..2f78b83b8 --- /dev/null +++ b/test/test/test_pdump.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#ifndef _TEST_PDUMP_H_ +#define _TEST_PDUMP_H_ + + +#define QUEUE_ID 0 +#define NUM_ITR 3 + +#ifdef RTE_EXEC_ENV_BSDAPP +#define self "curproc" +#define exe "file" +#else +#define self "self" +#define exe "exe" +#endif + +/* sample test to send packets to the pdump client recursively */ +void *send_pkts(void *port); + +/* Sample test to create setup for the pdump server tests */ +int test_pdump_init(void); + +/* Sample test to teardown the pdump server setup */ +int test_pdump_uninit(void); + +/* Sample test to run the pdump client tests */ +int run_pdump_client_tests(void); + +/* Sample test to run the pdump server tests */ +int run_pdump_server_tests(void); + +/* Sample test to run the pdump client and server tests based on + * the process type + */ +int test_pdump(void); + +#endif /* _TEST_PDUMP_H_ */ -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [dpdk-dev] [PATCH v6 4/4] test: add unit test for pdump library 2018-07-25 17:06 ` [dpdk-dev] [PATCH v6 4/4] test: add unit test for pdump library Naga Suresh Somarowthu @ 2018-07-26 10:02 ` Burakov, Anatoly 0 siblings, 0 replies; 37+ messages in thread From: Burakov, Anatoly @ 2018-07-26 10:02 UTC (permalink / raw) To: Naga Suresh Somarowthu, dev; +Cc: remy.horton, reshma.pattan On 25-Jul-18 6:06 PM, Naga Suresh Somarowthu wrote: > Unit test cases are added for pdump library. > Primary process will act as server, forks a child secondary process. > Secondary process acts as client. > Server will do pdump init to serve any pdump client requests. > Server will create a vdev, send/receive packets continuously > in a separate thread. > Client will create virtual rings to receive the packet dump. > Client sends pdump enable/disable requests using either port/device id. > Packet flow direction can be tx/rx/tx&rx. > In Server, appropriate pdump callbacks are triggered, > when packets are transmitted/received. > Pdump packet is copied to client rings. > > Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> > Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> > --- <snip> > + > +#define QUEUE_ID 0 > +#define NUM_ITR 3 > + > +#ifdef RTE_EXEC_ENV_BSDAPP > +#define self "curproc" > +#define exe "file" > +#else > +#define self "self" > +#define exe "exe" > +#endif Why is all of this here? This looks like a copy paste from process.h > + > +/* sample test to send packets to the pdump client recursively */ > +void *send_pkts(void *port); > + > +/* Sample test to create setup for the pdump server tests */ > +int test_pdump_init(void); > + > +/* Sample test to teardown the pdump server setup */ > +int test_pdump_uninit(void); > + > +/* Sample test to run the pdump client tests */ > +int run_pdump_client_tests(void); > + > +/* Sample test to run the pdump server tests */ > +int run_pdump_server_tests(void); > + > +/* Sample test to run the pdump client and server tests based on > + * the process type > + */ > +int test_pdump(void); > + > +#endif /* _TEST_PDUMP_H_ */ > -- Thanks, Anatoly ^ permalink raw reply [flat|nested] 37+ messages in thread
* [dpdk-dev] [PATCH v7 0/4] add unit tests for bitrate, latency and pdump libraries 2018-07-25 17:05 ` [dpdk-dev] [PATCH v6 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu ` (3 preceding siblings ...) 2018-07-25 17:06 ` [dpdk-dev] [PATCH v6 4/4] test: add unit test for pdump library Naga Suresh Somarowthu @ 2018-07-26 12:50 ` Naga Suresh Somarowthu 2018-07-26 12:50 ` [dpdk-dev] [PATCH v7 1/4] test: add ring pmd based packet rx/tx for UT Naga Suresh Somarowthu ` (5 more replies) 4 siblings, 6 replies; 37+ messages in thread From: Naga Suresh Somarowthu @ 2018-07-26 12:50 UTC (permalink / raw) To: dev; +Cc: remy.horton, reshma.pattan, Naga Suresh Somarowthu 1/4: add ring pmd based packet helper functions for UT 2/4: unit test cases added for bitrate library 3/4: unit test cases added for latencystats library 4/4: unit test cases added for pdump library Patches 2/4,3/4 depends on 1/4 Patch 4/4 depends on 1/4 and the below patch http://patches.dpdk.org/patch/43354/ Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> Reviewed-by: Remy Horton <remy.horton@intel.com> Reviewed-by: Anatoly Burakov <anatoly.burakov@intel.com> --- v7: removed unused macros and corrected the comment v6: updated ring variable appropriately v5: rebased, freed pools and rings, created common patch set --- Naga Suresh Somarowthu (4): test: add ring pmd based packet rx/tx for UT test: add unit tests for bitrate library test: add unit tests for latencystats library test: add unit test for pdump library test/test/Makefile | 9 ++ test/test/autotest_data.py | 12 ++ test/test/process.h | 12 ++ test/test/sample_packet_forward.c | 115 +++++++++++++++++++ test/test/sample_packet_forward.h | 40 +++++++ test/test/test.c | 2 + test/test/test_bitratestats.c | 227 +++++++++++++++++++++++++++++++++++++ test/test/test_latencystats.c | 216 +++++++++++++++++++++++++++++++++++ test/test/test_pdump.c | 232 ++++++++++++++++++++++++++++++++++++++ test/test/test_pdump.h | 31 +++++ 10 files changed, 896 insertions(+) create mode 100644 test/test/sample_packet_forward.c create mode 100644 test/test/sample_packet_forward.h create mode 100644 test/test/test_bitratestats.c create mode 100644 test/test/test_latencystats.c create mode 100644 test/test/test_pdump.c create mode 100644 test/test/test_pdump.h -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* [dpdk-dev] [PATCH v7 1/4] test: add ring pmd based packet rx/tx for UT 2018-07-26 12:50 ` [dpdk-dev] [PATCH v7 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu @ 2018-07-26 12:50 ` Naga Suresh Somarowthu 2018-07-26 16:43 ` Pattan, Reshma 2018-07-26 12:50 ` [dpdk-dev] [PATCH v7 2/4] test: add unit tests for bitrate library Naga Suresh Somarowthu ` (4 subsequent siblings) 5 siblings, 1 reply; 37+ messages in thread From: Naga Suresh Somarowthu @ 2018-07-26 12:50 UTC (permalink / raw) To: dev; +Cc: remy.horton, reshma.pattan, Naga Suresh Somarowthu Added ring pmd based packet rx/tx helper functions for verifying Latency, Bitrate and pdump lib UTs. Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> Reviewed-by: Anatoly Burakov <anatoly.burakov@intel.com> --- test/test/Makefile | 1 + test/test/sample_packet_forward.c | 115 ++++++++++++++++++++++++++++++++++++++ test/test/sample_packet_forward.h | 40 +++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 test/test/sample_packet_forward.c create mode 100644 test/test/sample_packet_forward.h diff --git a/test/test/Makefile b/test/test/Makefile index e6967bab6..9f7d398e4 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -165,6 +165,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_REORDER) += test_reorder.c SRCS-y += virtual_pmd.c SRCS-y += packet_burst_generator.c +SRCS-y += sample_packet_forward.c SRCS-$(CONFIG_RTE_LIBRTE_ACL) += test_acl.c ifeq ($(CONFIG_RTE_LIBRTE_PMD_RING),y) diff --git a/test/test/sample_packet_forward.c b/test/test/sample_packet_forward.c new file mode 100644 index 000000000..3822577b9 --- /dev/null +++ b/test/test/sample_packet_forward.c @@ -0,0 +1,115 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include <string.h> +#include <errno.h> +#include <time.h> + +#include <rte_memcpy.h> +#include <rte_common.h> +#include <rte_eth_ring.h> +#include <rte_ethdev.h> +#include <rte_mbuf.h> +#include <rte_bus_vdev.h> + +#include "sample_packet_forward.h" +#include "test.h" + +/* Sample test to create virtual rings and tx,rx portid from rings */ +int +test_ring_setup(struct rte_ring **ring, uint16_t *portid) +{ + *ring = rte_ring_create("R0", RING_SIZE, rte_socket_id(), + RING_F_SP_ENQ | RING_F_SC_DEQ); + if (*ring == NULL) { + printf("%s() line %u: rte_ring_create R0 failed", + __func__, __LINE__); + return -1; + } + *portid = rte_eth_from_rings("net_ringa", ring, NUM_QUEUES, + ring, NUM_QUEUES, rte_socket_id()); + + return 0; +} + +/* Sample test to free the mempool */ +void +test_mp_free(struct rte_mempool *mp) +{ + rte_mempool_free(mp); +} + +/* Sample test to free the virtual rings */ +void +test_ring_free(struct rte_ring *rxtx) +{ + rte_ring_free(rxtx); +} + +/* Sample test to release the vdev */ +void +test_vdev_uninit(const char *vdev) +{ + rte_vdev_uninit(vdev); +} + +/* sample test to allocate the mempool */ +int +test_get_mempool(struct rte_mempool **mp, char *poolname) +{ + *mp = rte_pktmbuf_pool_create(poolname, NB_MBUF, 32, 0, + RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); + if (*mp == NULL) + return -1; + return 0; +} + +/* sample test to allocate buffer for pkts */ +int +test_get_mbuf_from_pool(struct rte_mempool **mp, struct rte_mbuf **pbuf, + char *poolname) +{ + int ret = 0; + + ret = test_get_mempool(mp, poolname); + if (ret < 0) + return -1; + if (rte_pktmbuf_alloc_bulk(*mp, pbuf, NUM_PACKETS) != 0) { + printf("%s() line %u: rte_pktmbuf_alloc_bulk failed", __func__, + __LINE__); + return -1; + } + return 0; +} + +/* sample test to deallocate the allocated buffers and mempool */ +void +test_put_mbuf_to_pool(struct rte_mempool *mp, struct rte_mbuf **pbuf) +{ + int itr = 0; + + for (itr = 0; itr < NUM_PACKETS; itr++) + rte_pktmbuf_free(pbuf[itr]); + rte_mempool_free(mp); +} + +/* Sample test to forward packets using virtual portids */ +int +test_packet_forward(struct rte_mbuf **pbuf, uint16_t portid, uint16_t queue_id) +{ + /* send and receive packet and check for stats update */ + if (rte_eth_tx_burst(portid, queue_id, pbuf, NUM_PACKETS) + < NUM_PACKETS) { + printf("%s() line %u: Error sending packet to" + " port %d\n", __func__, __LINE__, portid); + return -1; + } + if (rte_eth_rx_burst(portid, queue_id, pbuf, NUM_PACKETS) + < NUM_PACKETS) { + printf("%s() line %u: Error receiving packet from" + " port %d\n", __func__, __LINE__, portid); + return -1; + } + return 0; +} diff --git a/test/test/sample_packet_forward.h b/test/test/sample_packet_forward.h new file mode 100644 index 000000000..433bd3ba2 --- /dev/null +++ b/test/test/sample_packet_forward.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#ifndef _SAMPLE_PACKET_FORWARD_H_ +#define _SAMPLE_PACKET_FORWARD_H_ + +/* MACROS to support virtual ring creation */ +#define RING_SIZE 256 +#define NUM_QUEUES 1 +#define NB_MBUF 512 + +#define NUM_PACKETS 10 + +/* Sample test to create virtual rings and tx,rx portid from rings */ +int test_ring_setup(struct rte_ring **ring, uint16_t *portid); + +/* Sample test to free the virtual rings */ +void test_ring_free(struct rte_ring *rxtx); + +/* Sample test to forward packet using virtual port id */ +int test_packet_forward(struct rte_mbuf **pbuf, uint16_t portid, + uint16_t queue_id); + +/* sample test to allocate buffer for pkts */ +int test_get_mbuf_from_pool(struct rte_mempool **mp, struct rte_mbuf **pbuf, + char *poolname); + +/* Sample test to create the mempool */ +int test_get_mempool(struct rte_mempool **mp, char *poolname); + +/* sample test to deallocate the allocated buffers and mempool */ +void test_put_mbuf_to_pool(struct rte_mempool *mp, struct rte_mbuf **pbuf); + +/* Sample test to free the mempool */ +void test_mp_free(struct rte_mempool *mp); + +/* Sample test to release the vdev */ +void test_vdev_uninit(const char *vdev); +#endif /* _SAMPLE_PACKET_FORWARD_H_ */ -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [dpdk-dev] [PATCH v7 1/4] test: add ring pmd based packet rx/tx for UT 2018-07-26 12:50 ` [dpdk-dev] [PATCH v7 1/4] test: add ring pmd based packet rx/tx for UT Naga Suresh Somarowthu @ 2018-07-26 16:43 ` Pattan, Reshma 2018-07-27 7:40 ` Burakov, Anatoly 0 siblings, 1 reply; 37+ messages in thread From: Pattan, Reshma @ 2018-07-26 16:43 UTC (permalink / raw) To: Somarowthu, Naga SureshX, dev; +Cc: Horton, Remy Hi, > -----Original Message----- > From: Somarowthu, Naga SureshX > Sent: Thursday, July 26, 2018 1:50 PM > To: dev@dpdk.org > Cc: Horton, Remy <remy.horton@intel.com>; Pattan, Reshma > <reshma.pattan@intel.com>; Somarowthu, Naga SureshX > <naga.sureshx.somarowthu@intel.com> > Subject: [PATCH v7 1/4] test: add ring pmd based packet rx/tx for UT > dpdk-dpdk]$ ./devtools/check-git-log.sh Wrong headline lowercase: test: add ring pmd based packet rx/tx for UT Thanks, Reshma ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [dpdk-dev] [PATCH v7 1/4] test: add ring pmd based packet rx/tx for UT 2018-07-26 16:43 ` Pattan, Reshma @ 2018-07-27 7:40 ` Burakov, Anatoly 0 siblings, 0 replies; 37+ messages in thread From: Burakov, Anatoly @ 2018-07-27 7:40 UTC (permalink / raw) To: Pattan, Reshma, Somarowthu, Naga SureshX, dev; +Cc: Horton, Remy On 26-Jul-18 5:43 PM, Pattan, Reshma wrote: > Hi, > >> -----Original Message----- >> From: Somarowthu, Naga SureshX >> Sent: Thursday, July 26, 2018 1:50 PM >> To: dev@dpdk.org >> Cc: Horton, Remy <remy.horton@intel.com>; Pattan, Reshma >> <reshma.pattan@intel.com>; Somarowthu, Naga SureshX >> <naga.sureshx.somarowthu@intel.com> >> Subject: [PATCH v7 1/4] test: add ring pmd based packet rx/tx for UT >> > > dpdk-dpdk]$ ./devtools/check-git-log.sh > Wrong headline lowercase: > test: add ring pmd based packet rx/tx for UT > > Thanks, > Reshma > Suggestion: do not refer to "unit tests" as "UT" as it may not be immediately clear what you mean by that. IME they tend to be referred to as autotests or just tests :) So, suggested rewording would be: test: add helper functions for tests using ring-pmd rx/tx or something like that. -- Thanks, Anatoly ^ permalink raw reply [flat|nested] 37+ messages in thread
* [dpdk-dev] [PATCH v7 2/4] test: add unit tests for bitrate library 2018-07-26 12:50 ` [dpdk-dev] [PATCH v7 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu 2018-07-26 12:50 ` [dpdk-dev] [PATCH v7 1/4] test: add ring pmd based packet rx/tx for UT Naga Suresh Somarowthu @ 2018-07-26 12:50 ` Naga Suresh Somarowthu 2018-07-26 12:50 ` [dpdk-dev] [PATCH v7 3/4] test: add unit tests for latencystats library Naga Suresh Somarowthu ` (3 subsequent siblings) 5 siblings, 0 replies; 37+ messages in thread From: Naga Suresh Somarowthu @ 2018-07-26 12:50 UTC (permalink / raw) To: dev; +Cc: remy.horton, reshma.pattan, Naga Suresh Somarowthu Unit Test Cases for BitRate library. Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> Reviewed-by: Remy Horton <remy.horton@intel.com> --- test/test/Makefile | 1 + test/test/autotest_data.py | 6 ++ test/test/test_bitratestats.c | 227 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 234 insertions(+) create mode 100644 test/test/test_bitratestats.c diff --git a/test/test/Makefile b/test/test/Makefile index 9f7d398e4..c619877f0 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -183,6 +183,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_PMD_RING) += test_pmd_ring_perf.c SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev_blockcipher.c SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev.c SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev_asym.c +SRCS-$(CONFIG_RTE_LIBRTE_BITRATE) += test_bitratestats.c ifeq ($(CONFIG_RTE_COMPRESSDEV_TEST),y) SRCS-$(CONFIG_RTE_LIBRTE_COMPRESSDEV) += test_compressdev.c diff --git a/test/test/autotest_data.py b/test/test/autotest_data.py index aacfe0a66..419520342 100644 --- a/test/test/autotest_data.py +++ b/test/test/autotest_data.py @@ -293,6 +293,12 @@ def per_sockets(num): "Tests": [ { + "Name": "Bitratestats autotest", + "Command": "bitratestats_autotest", + "Func": default_autotest, + "Report": None, + }, + { "Name": "PMD ring autotest", "Command": "ring_pmd_autotest", "Func": default_autotest, diff --git a/test/test/test_bitratestats.c b/test/test/test_bitratestats.c new file mode 100644 index 000000000..62a175865 --- /dev/null +++ b/test/test/test_bitratestats.c @@ -0,0 +1,227 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include <string.h> +#include <errno.h> +#include <time.h> + +#include <rte_log.h> +#include <rte_lcore.h> +#include <rte_mbuf.h> +#include <rte_malloc.h> +#include <rte_common.h> +#include <rte_metrics.h> +#include <rte_bitrate.h> + +#include "test.h" +#include "sample_packet_forward.h" + +#define BIT_NUM_PACKETS 10 +#define QUEUE_ID 0 + +uint16_t portid; +struct rte_stats_bitrates *bitrate_data; +struct rte_ring *ring; + +/* To test whether rte_stats_bitrate_create is successful */ +static int +test_stats_bitrate_create(void) +{ + bitrate_data = rte_stats_bitrate_create(); + TEST_ASSERT(bitrate_data != NULL, "rte_stats_bitrate_create failed"); + + return TEST_SUCCESS; +} + +/* To test bit rate registration */ +static int +test_stats_bitrate_reg(void) +{ + int ret = 0; + + /* Test to register bit rate without metrics init */ + ret = rte_stats_bitrate_reg(bitrate_data); + TEST_ASSERT(ret < 0, "Test Failed: rte_stats_bitrate_reg succeeded " + "without metrics init, ret:%d", ret); + + /* Metrics initialization */ + rte_metrics_init(rte_socket_id()); + /* Test to register bit rate after metrics init */ + ret = rte_stats_bitrate_reg(bitrate_data); + TEST_ASSERT((ret >= 0), "Test Failed: rte_stats_bitrate_reg %d", ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate registration with invalid pointer */ +static int +test_stats_bitrate_reg_invalidpointer(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_reg(NULL); + TEST_ASSERT(ret < 0, "Test Failed: Expected failure < 0 but " + "got %d", ret); + + return TEST_SUCCESS; +} + +/* To test bit rate calculation with invalid bit rate data pointer */ +static int +test_stats_bitrate_calc_invalid_bitrate_data(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(NULL, portid); + TEST_ASSERT(ret < 0, "Test Failed: rte_stats_bitrate_calc " + "ret:%d", ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate calculation with invalid portid + * (higher than max ports) + */ +static int +test_stats_bitrate_calc_invalid_portid_1(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(bitrate_data, 33); + TEST_ASSERT(ret == -EINVAL, "Test Failed: Expected -%d for higher " + "portid rte_stats_bitrate_calc ret:%d", EINVAL, ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate calculation with invalid portid (lesser than 0) */ +static int +test_stats_bitrate_calc_invalid_portid_2(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(bitrate_data, -1); + TEST_ASSERT(ret == -EINVAL, "Test Failed: Expected -%d for invalid " + "portid rte_stats_bitrate_calc ret:%d", EINVAL, ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate calculation with non-existing portid */ +static int +test_stats_bitrate_calc_non_existing_portid(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(bitrate_data, 31); + TEST_ASSERT(ret == -EINVAL, "Test Failed: Expected -%d for " + "non-existing portid rte_stats_bitrate_calc ret:%d", + EINVAL, ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate calculation with valid bit rate data, valid portid */ +static int +test_stats_bitrate_calc(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(bitrate_data, portid); + TEST_ASSERT(ret >= 0, "Test Failed: Expected >=0 for valid portid " + "rte_stats_bitrate_calc ret:%d", ret); + + return TEST_SUCCESS; +} + +static int +test_bit_packet_forward(void) +{ + int ret; + struct rte_mbuf *pbuf[BIT_NUM_PACKETS] = { }; + struct rte_mempool *mp; + char poolname[] = "mbuf_pool"; + ret = test_get_mbuf_from_pool(&mp, pbuf, poolname); + if (ret < 0) { + printf("allocate mbuf pool Failed\n"); + return TEST_FAILED; + } + ret = test_packet_forward(pbuf, portid, QUEUE_ID); + if (ret < 0) + printf("send pkts Failed\n"); + test_put_mbuf_to_pool(mp, pbuf); + + return TEST_SUCCESS; +} + +static int +test_bit_ring_setup(void) +{ + test_ring_setup(&ring, &portid); + printf("port in ring setup : %d\n", portid); + + return TEST_SUCCESS; +} + +static void +test_bit_ring_free(void) +{ + test_ring_free(ring); + test_vdev_uninit("net_ring_net_ringa"); +} + +static struct +unit_test_suite bitratestats_testsuite = { + .suite_name = "BitRate Stats Unit Test Suite", + .setup = test_bit_ring_setup, + .teardown = test_bit_ring_free, + .unit_test_cases = { + /* TEST CASE 1: Test to create bit rate data */ + TEST_CASE(test_stats_bitrate_create), + + /* TEST CASE 2: Test to register bit rate metrics + * without metrics init and after metrics init + */ + TEST_CASE(test_stats_bitrate_reg), + + /* TEST CASE 3: Test to register bit rate metrics + * with invalid bit rate data + */ + TEST_CASE(test_stats_bitrate_reg_invalidpointer), + + /* TEST CASE 4: Test to calculate bit rate data metrics + * with invalid bit rate data + */ + TEST_CASE(test_stats_bitrate_calc_invalid_bitrate_data), + + /* TEST CASE 5: Test to calculate bit rate data metrics + * with portid exceeding the max ports + */ + TEST_CASE(test_stats_bitrate_calc_invalid_portid_1), + + /* TEST CASE 6: Test to calculate bit rate data metrics + * with portid less than 0 + */ + TEST_CASE(test_stats_bitrate_calc_invalid_portid_2), + + /* TEST CASE 7: Test to calculate bit rate data metrics + * with non-existing portid + */ + TEST_CASE(test_stats_bitrate_calc_non_existing_portid), + + /* TEST CASE 8: Test to calculate bit rate data metrics + * with valid portid, valid bit rate data + */ + TEST_CASE_ST(test_bit_packet_forward, NULL, + test_stats_bitrate_calc), + TEST_CASES_END() + } +}; + +static int +test_bitratestats(void) +{ + return unit_test_suite_runner(&bitratestats_testsuite); +} +REGISTER_TEST_COMMAND(bitratestats_autotest, test_bitratestats); -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* [dpdk-dev] [PATCH v7 3/4] test: add unit tests for latencystats library 2018-07-26 12:50 ` [dpdk-dev] [PATCH v7 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu 2018-07-26 12:50 ` [dpdk-dev] [PATCH v7 1/4] test: add ring pmd based packet rx/tx for UT Naga Suresh Somarowthu 2018-07-26 12:50 ` [dpdk-dev] [PATCH v7 2/4] test: add unit tests for bitrate library Naga Suresh Somarowthu @ 2018-07-26 12:50 ` Naga Suresh Somarowthu 2018-07-26 12:50 ` [dpdk-dev] [PATCH v7 4/4] test: add unit test for pdump library Naga Suresh Somarowthu ` (2 subsequent siblings) 5 siblings, 0 replies; 37+ messages in thread From: Naga Suresh Somarowthu @ 2018-07-26 12:50 UTC (permalink / raw) To: dev; +Cc: remy.horton, reshma.pattan, Naga Suresh Somarowthu Unit Test Cases added for latencystats library. Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> --- test/test/Makefile | 1 + test/test/autotest_data.py | 6 ++ test/test/test_latencystats.c | 216 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 223 insertions(+) create mode 100644 test/test/test_latencystats.c diff --git a/test/test/Makefile b/test/test/Makefile index c619877f0..bba3be1be 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -184,6 +184,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev_blockcipher.c SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev.c SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev_asym.c SRCS-$(CONFIG_RTE_LIBRTE_BITRATE) += test_bitratestats.c +SRCS-$(CONFIG_RTE_LIBRTE_LATENCY_STATS) += test_latencystats.c ifeq ($(CONFIG_RTE_COMPRESSDEV_TEST),y) SRCS-$(CONFIG_RTE_LIBRTE_COMPRESSDEV) += test_compressdev.c diff --git a/test/test/autotest_data.py b/test/test/autotest_data.py index 419520342..3eccc4e1a 100644 --- a/test/test/autotest_data.py +++ b/test/test/autotest_data.py @@ -299,6 +299,12 @@ def per_sockets(num): "Report": None, }, { + "Name": "Latencystats autotest", + "Command": "latencystats_autotest", + "Func": default_autotest, + "Report": None, + }, + { "Name": "PMD ring autotest", "Command": "ring_pmd_autotest", "Func": default_autotest, diff --git a/test/test/test_latencystats.c b/test/test/test_latencystats.c new file mode 100644 index 000000000..f2287a2b7 --- /dev/null +++ b/test/test/test_latencystats.c @@ -0,0 +1,216 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <time.h> + +#include <rte_common.h> +#include <rte_metrics.h> +#include <rte_latencystats.h> +#include <rte_eth_ring.h> +#include <rte_ethdev.h> +#include <rte_mbuf.h> +#include "test.h" +#include "sample_packet_forward.h" +#define NUM_STATS 4 +#define LATENCY_NUM_PACKETS 10 +#define QUEUE_ID 0 + +uint16_t portid; +struct rte_ring *ring; + +struct rte_metric_name lat_stats_strings[] = { + {"min_latency_ns"}, + {"avg_latency_ns"}, + {"max_latency_ns"}, + {"jitter_ns"}, +}; + +/* Test case for latency init with metrics init */ +static int test_latency_init(void) +{ + int ret = 0; + + /* Metrics Initialization */ + rte_metrics_init(rte_socket_id()); + + ret = rte_latencystats_init(1, NULL); + TEST_ASSERT(ret >= 0, "Test Failed: rte_latencystats_init failed"); + + return TEST_SUCCESS; +} + +/* Test case to update the latency stats */ +static int test_latency_update(void) +{ + int ret = 0; + + ret = rte_latencystats_update(); + TEST_ASSERT(ret >= 0, "Test Failed: rte_latencystats_update failed"); + + return TEST_SUCCESS; +} + +/* Test case to uninit latency stats */ +static int test_latency_uninit(void) +{ + int ret = 0; + + ret = rte_latencystats_uninit(); + TEST_ASSERT(ret >= 0, "Test Failed: rte_latencystats_uninit failed"); + + return TEST_SUCCESS; +} + +/* Test case to get names of latency stats */ +static int test_latencystats_get_names(void) +{ + int ret = 0; + int size = 0; + struct rte_metric_name names[NUM_STATS] = { 0 }; + struct rte_metric_name wrongnames[NUM_STATS - 2] = { 0 }; + + /* Success Test: Valid names and size */ + size = NUM_STATS; + ret = rte_latencystats_get_names(names, size); + for (int i = 0; i <= NUM_STATS; i++) { + if (strcmp(lat_stats_strings[i].name, names[i].name) == 0) + printf(" %s\n", names[i].name); + else + printf("Failed: Names are not matched\n"); + } + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get metrics names"); + + /* Failure Test: Invalid names and valid size */ + ret = rte_latencystats_get_names(NULL, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get the metrics count," + "Actual: %d Expected: %d", ret, NUM_STATS); + + /* Failure Test: Valid names and invalid size */ + size = 0; + ret = rte_latencystats_get_names(names, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get the metrics count," + "Actual: %d Expected: %d", ret, NUM_STATS); + + /* Failure Test: Invalid names (array size lesser than size) */ + size = NUM_STATS + 1; + ret = rte_latencystats_get_names(wrongnames, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get metrics names"); + return TEST_SUCCESS; +} + +/* Test case to get latency stats values */ +static int test_latencystats_get(void) +{ + int ret = 0; + int size = 0; + struct rte_metric_value values[NUM_STATS] = { 0 }; + struct rte_metric_value wrongvalues[NUM_STATS - 2] = { 0 }; + + /* Success Test: Valid values and valid size */ + size = NUM_STATS; + ret = rte_latencystats_get(values, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get latency metrics" + " values"); + for (int i = 0; i < NUM_STATS; i++) + printf("values: %ld\n", values[i].value); + + /* Failure Test: Invalid values and valid size */ + ret = rte_latencystats_get(NULL, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get the stats count," + "Actual: %d Expected: %d", ret, NUM_STATS); + + /* Failure Test: Valid values and invalid size */ + size = 0; + ret = rte_latencystats_get(values, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get the stats count," + "Actual: %d Expected: %d", ret, NUM_STATS); + + /* Failure Test: Invalid values(array size lesser than size) + * and invalid size + */ + size = NUM_STATS + 2; + ret = rte_latencystats_get(wrongvalues, size); + TEST_ASSERT(ret == NUM_STATS, "Test Failed to get latency metrics" + " values"); + + return TEST_SUCCESS; +} + +static int test_latency_ring_setup(void) +{ + test_ring_setup(&ring, &portid); + + return TEST_SUCCESS; +} + +static void test_latency_ring_free(void) +{ + test_ring_free(ring); + test_vdev_uninit("net_ring_net_ringa"); +} + +static int test_latency_packet_forward(void) +{ + int ret; + struct rte_mbuf *pbuf[LATENCY_NUM_PACKETS] = { }; + struct rte_mempool *mp; + char poolname[] = "mbuf_pool"; + + ret = test_get_mbuf_from_pool(&mp, pbuf, poolname); + if (ret < 0) { + printf("allocate mbuf pool Failed\n"); + return TEST_FAILED; + } + ret = test_packet_forward(pbuf, portid, QUEUE_ID); + if (ret < 0) + printf("send pkts Failed\n"); + test_put_mbuf_to_pool(mp, pbuf); + + return TEST_SUCCESS; +} + +static struct +unit_test_suite latencystats_testsuite = { + .suite_name = "Latency Stats Unit Test Suite", + .setup = test_latency_ring_setup, + .teardown = test_latency_ring_free, + .unit_test_cases = { + + /* Test Case 1: To check latency init with + * metrics init + */ + TEST_CASE_ST(NULL, NULL, test_latency_init), + + /* Test Case 2: Do packet forwarding for metrics + * calculation and check the latency metrics values + * are updated + */ + TEST_CASE_ST(test_latency_packet_forward, NULL, + test_latency_update), + /* Test Case 3: To check whether latency stats names + * are retrieved + */ + TEST_CASE_ST(NULL, NULL, test_latencystats_get_names), + + /* Test Case 4: To check whether latency stats + * values are retrieved + */ + TEST_CASE_ST(NULL, NULL, test_latencystats_get), + + /* Test Case 5: To check uninit of latency test */ + TEST_CASE_ST(NULL, NULL, test_latency_uninit), + + TEST_CASES_END() + } +}; + +static int test_latencystats(void) +{ + return unit_test_suite_runner(&latencystats_testsuite); +} + +REGISTER_TEST_COMMAND(latencystats_autotest, test_latencystats); -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* [dpdk-dev] [PATCH v7 4/4] test: add unit test for pdump library 2018-07-26 12:50 ` [dpdk-dev] [PATCH v7 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu ` (2 preceding siblings ...) 2018-07-26 12:50 ` [dpdk-dev] [PATCH v7 3/4] test: add unit tests for latencystats library Naga Suresh Somarowthu @ 2018-07-26 12:50 ` Naga Suresh Somarowthu 2018-07-26 16:04 ` [dpdk-dev] [PATCH v7 0/4] add unit tests for bitrate, latency and pdump libraries Pattan, Reshma 2018-07-27 14:26 ` [dpdk-dev] [PATCH v8 " Naga Suresh Somarowthu 5 siblings, 0 replies; 37+ messages in thread From: Naga Suresh Somarowthu @ 2018-07-26 12:50 UTC (permalink / raw) To: dev; +Cc: remy.horton, reshma.pattan, Naga Suresh Somarowthu Unit test cases are added for pdump library. Primary process will act as server, forks a child secondary process. Secondary process acts as client. Server will do pdump init to serve any pdump client requests. Server will create a vdev, send/receive packets continuously in a separate thread. Client will create virtual rings to receive the packet dump. Client sends pdump enable/disable requests using either port/device id. Packet flow direction can be tx/rx/tx&rx. In Server, appropriate pdump callbacks are triggered, when packets are transmitted/received. Pdump packet is copied to client rings. Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> --- test/test/Makefile | 6 ++ test/test/process.h | 12 +++ test/test/test.c | 2 + test/test/test_pdump.c | 232 +++++++++++++++++++++++++++++++++++++++++++++++++ test/test/test_pdump.h | 31 +++++++ 5 files changed, 283 insertions(+) create mode 100644 test/test/test_pdump.c create mode 100644 test/test/test_pdump.h diff --git a/test/test/Makefile b/test/test/Makefile index bba3be1be..3e7baef76 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -185,6 +185,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev.c SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev_asym.c SRCS-$(CONFIG_RTE_LIBRTE_BITRATE) += test_bitratestats.c SRCS-$(CONFIG_RTE_LIBRTE_LATENCY_STATS) += test_latencystats.c +SRCS-$(CONFIG_RTE_LIBRTE_PDUMP) += test_pdump.c ifeq ($(CONFIG_RTE_COMPRESSDEV_TEST),y) SRCS-$(CONFIG_RTE_LIBRTE_COMPRESSDEV) += test_compressdev.c @@ -214,6 +215,11 @@ CFLAGS += $(WERROR_FLAGS) CFLAGS += -D_GNU_SOURCE LDLIBS += -lm + +ifeq ($(CONFIG_RTE_LIBRTE_PDUMP),y) +LDLIBS += -lpthread +endif + ifeq ($(CONFIG_RTE_COMPRESSDEV_TEST),y) ifeq ($(CONFIG_RTE_LIBRTE_COMPRESSDEV),y) LDLIBS += -lz diff --git a/test/test/process.h b/test/test/process.h index 11986d5c2..1e7adde0e 100644 --- a/test/test/process.h +++ b/test/test/process.h @@ -13,6 +13,10 @@ #define exe "exe" #endif +#include <pthread.h> +extern void *send_pkts(void *empty); +extern uint16_t flag_for_send_pkts; + /* * launches a second copy of the test process using the given argv parameters, * which should include argv[0] as the process name. To identify in the @@ -26,6 +30,7 @@ process_dup(const char *const argv[], int numargs, const char *env_value) char *argv_cpy[numargs + 1]; int i, fd, status; char path[32]; + pthread_t thread; pid_t pid = fork(); if (pid < 0) @@ -56,8 +61,15 @@ process_dup(const char *const argv[], int numargs, const char *env_value) rte_panic("Cannot exec\n"); } /* parent process does a wait */ + if ((strcmp(env_value, "run_pdump_server_tests") == 0)) + pthread_create(&thread, NULL, &send_pkts, NULL); + while (wait(&status) != pid) ; + if ((strcmp(env_value, "run_pdump_server_tests") == 0)) { + flag_for_send_pkts = 0; + pthread_join(thread, NULL); + } return status; } diff --git a/test/test/test.c b/test/test/test.c index 44dfe20ef..a54b0d142 100644 --- a/test/test/test.c +++ b/test/test/test.c @@ -30,6 +30,7 @@ extern cmdline_parse_ctx_t main_ctx[]; #endif #include "test.h" +#include "test_pdump.h" #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1 @@ -49,6 +50,7 @@ do_recursive_call(void) int (*action_fn)(void); } actions[] = { { "run_secondary_instances", test_mp_secondary }, + { "run_pdump_server_tests", test_pdump }, { "test_missing_c_flag", no_action }, { "test_master_lcore_flag", no_action }, { "test_invalid_n_flag", no_action }, diff --git a/test/test/test_pdump.c b/test/test/test_pdump.c new file mode 100644 index 000000000..cfdda4d39 --- /dev/null +++ b/test/test/test_pdump.c @@ -0,0 +1,232 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include <time.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdarg.h> +#include <inttypes.h> +#include <sys/queue.h> +#include <string.h> +#include <unistd.h> +#include <sys/wait.h> + +#include <rte_common.h> +#include <rte_mbuf.h> +#include <rte_pdump.h> +#include <rte_eth_ctrl.h> +#include <rte_memory.h> +#include <rte_memzone.h> +#include <rte_eal.h> +#include <rte_ring.h> +#include <rte_mempool.h> +#include <rte_eth_ring.h> +#include <rte_ethdev_driver.h> +#include <libgen.h> + +#include "test.h" +#include "sample_packet_forward.h" +#include "test_pdump.h" +#include "process.h" + +#define launch_p(ARGV) process_dup(ARGV, \ + sizeof(ARGV)/(sizeof(ARGV[0])), __func__) + +struct rte_ring *ring_server; +uint16_t portid; +uint16_t flag_for_send_pkts = 1; + +int +test_pdump_init(void) +{ + int ret = 0; + + ret = rte_pdump_init(NULL); + if (ret < 0) { + printf("rte_pdump_init failed\n"); + return -1; + } + ret = test_ring_setup(&ring_server, &portid); + if (ret < 0) { + printf("test_ring_setup failed\n"); + return -1; + } + printf("pdump_init success\n"); + return ret; +} + +int +run_pdump_client_tests(void) +{ + int flags = RTE_PDUMP_FLAG_TX, ret = 0, itr; + char deviceid[] = "net_ring_net_ringa"; + struct rte_ring *ring_client; + struct rte_mempool *mp = NULL; + struct rte_eth_dev *eth_dev = NULL; + char poolname[] = "mbuf_pool_client"; + + ret = test_get_mempool(&mp, poolname); + if (ret < 0) + return -1; + mp->flags = 0x0000; + ring_client = rte_ring_create("SR0", RING_SIZE, rte_socket_id(), + RING_F_SP_ENQ | RING_F_SC_DEQ); + if (ring_client == NULL) { + printf("rte_ring_create SR0 failed"); + return -1; + } + + eth_dev = rte_eth_dev_attach_secondary(deviceid); + if (!eth_dev) { + printf("Failed to probe %s", deviceid); + return -1; + } + rte_eth_dev_probing_finish(eth_dev); + + ring_client->prod.single = 0; + ring_client->cons.single = 0; + + printf("\n***** flags = RTE_PDUMP_FLAG_TX *****\n"); + + for (itr = 0; itr < NUM_ITR; itr++) { + ret = rte_pdump_enable(portid, QUEUE_ID, flags, ring_client, + mp, NULL); + if (ret < 0) { + printf("rte_pdump_enable failed\n"); + return -1; + } + printf("pdump_enable success\n"); + + ret = rte_pdump_disable(portid, QUEUE_ID, flags); + if (ret < 0) { + printf("rte_pdump_disable failed\n"); + return -1; + } + printf("pdump_disable success\n"); + + ret = rte_pdump_enable_by_deviceid(deviceid, QUEUE_ID, flags, + ring_client, mp, NULL); + if (ret < 0) { + printf("rte_pdump_enable_by_deviceid failed\n"); + return -1; + } + printf("pdump_enable_by_deviceid success\n"); + + ret = rte_pdump_disable_by_deviceid(deviceid, QUEUE_ID, flags); + if (ret < 0) { + printf("rte_pdump_disable_by_deviceid failed\n"); + return -1; + } + printf("pdump_disable_by_deviceid success\n"); + + if (itr == 0) { + flags = RTE_PDUMP_FLAG_RX; + printf("\n***** flags = RTE_PDUMP_FLAG_RX *****\n"); + } else if (itr == 1) { + flags = RTE_PDUMP_FLAG_RXTX; + printf("\n***** flags = RTE_PDUMP_FLAG_RXTX *****\n"); + } + } + if (ring_client != NULL) + test_ring_free(ring_client); + if (mp != NULL) + test_mp_free(mp); + + return ret; +} + +int +test_pdump_uninit(void) +{ + int ret = 0; + + ret = rte_pdump_uninit(); + if (ret < 0) { + printf("rte_pdump_uninit failed\n"); + return -1; + } + if (ring_server != NULL) + test_ring_free(ring_server); + printf("pdump_uninit success\n"); + test_vdev_uninit("net_ring_net_ringa"); + return ret; +} + +void * +send_pkts(void *empty) +{ + int ret = 0; + struct rte_mbuf *pbuf[NUM_PACKETS] = { }; + struct rte_mempool *mp; + char poolname[] = "mbuf_pool_server"; + + ret = test_get_mbuf_from_pool(&mp, pbuf, poolname); + if (ret < 0) + printf("get_mbuf_from_pool failed\n"); + do { + ret = test_packet_forward(pbuf, portid, QUEUE_ID); + if (ret < 0) + printf("send pkts Failed\n"); + } while (flag_for_send_pkts); + test_put_mbuf_to_pool(mp, pbuf); + return empty; +} + +/* + * This function is called in the primary i.e. main test, to spawn off secondary + * processes to run actual mp tests. Uses fork() and exec pair + */ + +int +run_pdump_server_tests(void) +{ + int ret = 0; + char coremask[10]; + +#ifdef RTE_EXEC_ENV_LINUXAPP + char tmp[PATH_MAX] = { 0 }; + char prefix[PATH_MAX] = { 0 }; + + get_current_prefix(tmp, sizeof(tmp)); + snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); +#else + const char *prefix = ""; +#endif + + /* good case, using secondary */ + const char *const argv1[] = { + prgname, "-c", coremask, "--proc-type=secondary", + prefix + }; + + snprintf(coremask, sizeof(coremask), "%x", + (1 << rte_get_master_lcore())); + + ret = test_pdump_init(); + ret |= launch_p(argv1); + ret |= test_pdump_uninit(); + return ret; +} + +int +test_pdump(void) +{ + int ret = 0; + if (rte_eal_process_type() == RTE_PROC_PRIMARY) { + printf("IN PRIMARY PROCESS\n"); + ret = run_pdump_server_tests(); + if (ret < 0) + return TEST_FAILED; + } else if (rte_eal_process_type() == RTE_PROC_SECONDARY) { + printf("IN SECONDARY PROCESS\n"); + sleep(5); + ret = run_pdump_client_tests(); + if (ret < 0) + return TEST_FAILED; + } + return TEST_SUCCESS; +} + +REGISTER_TEST_COMMAND(pdump_autotest, test_pdump); diff --git a/test/test/test_pdump.h b/test/test/test_pdump.h new file mode 100644 index 000000000..abef9a85e --- /dev/null +++ b/test/test/test_pdump.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#ifndef _TEST_PDUMP_H_ +#define _TEST_PDUMP_H_ + +#define QUEUE_ID 0 +#define NUM_ITR 3 + +/* sample test to send packets to the pdump client recursively */ +void *send_pkts(void *port); + +/* Sample test to create setup for the pdump server tests */ +int test_pdump_init(void); + +/* Sample test to teardown the pdump server setup */ +int test_pdump_uninit(void); + +/* Sample test to run the pdump client tests */ +int run_pdump_client_tests(void); + +/* Sample test to run the pdump server tests */ +int run_pdump_server_tests(void); + +/* Sample test to run the pdump client and server tests based on + * the process type + */ +int test_pdump(void); + +#endif /* _TEST_PDUMP_H_ */ -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [dpdk-dev] [PATCH v7 0/4] add unit tests for bitrate, latency and pdump libraries 2018-07-26 12:50 ` [dpdk-dev] [PATCH v7 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu ` (3 preceding siblings ...) 2018-07-26 12:50 ` [dpdk-dev] [PATCH v7 4/4] test: add unit test for pdump library Naga Suresh Somarowthu @ 2018-07-26 16:04 ` Pattan, Reshma 2018-07-27 14:26 ` [dpdk-dev] [PATCH v8 " Naga Suresh Somarowthu 5 siblings, 0 replies; 37+ messages in thread From: Pattan, Reshma @ 2018-07-26 16:04 UTC (permalink / raw) To: Somarowthu, Naga SureshX, dev; +Cc: Horton, Remy Hi, > -----Original Message----- > From: Somarowthu, Naga SureshX > Sent: Thursday, July 26, 2018 1:50 PM > To: dev@dpdk.org > Cc: Horton, Remy <remy.horton@intel.com>; Pattan, Reshma > <reshma.pattan@intel.com>; Somarowthu, Naga SureshX > <naga.sureshx.somarowthu@intel.com> > Subject: [PATCH v7 0/4] add unit tests for bitrate, latency and pdump libraries > > 1/4: add ring pmd based packet helper functions for UT > 2/4: unit test cases added for bitrate library > 3/4: unit test cases added for latencystats library > 4/4: unit test cases added for pdump library > 3/4 and 4/4 patches have been tested, 3/4 fails in its second run, reason latency_stats library not cleaning the memzone during the uninit. Will send the fix patch for the library. Acked-by: Reshma Pattan <reshma.pattan@intel.com> ^ permalink raw reply [flat|nested] 37+ messages in thread
* [dpdk-dev] [PATCH v8 0/4] add unit tests for bitrate, latency and pdump libraries 2018-07-26 12:50 ` [dpdk-dev] [PATCH v7 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu ` (4 preceding siblings ...) 2018-07-26 16:04 ` [dpdk-dev] [PATCH v7 0/4] add unit tests for bitrate, latency and pdump libraries Pattan, Reshma @ 2018-07-27 14:26 ` Naga Suresh Somarowthu 2018-07-27 14:26 ` [dpdk-dev] [PATCH v8 1/4] test: add helper functions for tests using ring-PMD Rx/Tx Naga Suresh Somarowthu ` (4 more replies) 5 siblings, 5 replies; 37+ messages in thread From: Naga Suresh Somarowthu @ 2018-07-27 14:26 UTC (permalink / raw) To: dev; +Cc: remy.horton, reshma.pattan, Naga Suresh Somarowthu 1/4: add helper functions for tests using ring-PMD Rx/Tx 2/4: unit test cases added for bitrate library 3/4: unit test cases added for latencystats library 4/4: unit test cases added for pdump library Patches 2/4,3/4 depends on 1/4 Patch 4/4 depends on 1/4 and the below patch http://patches.dpdk.org/patch/43354/ Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> Reviewed-by: Remy Horton <remy.horton@intel.com> Reviewed-by: Anatoly Burakov <anatoly.burakov@intel.com> Acked-by: Reshma Pattan <reshma.pattan@intel.com> --- v8: renamed commit headline and freed the metrics memzone for bitrate ut v7: removed unused macros and corrected the comment v6: updated ring variable appropriately v5: rebased, freed pools and rings, created common patch set --- Naga Suresh Somarowthu (4): test: add helper functions for tests using ring-PMD Rx/Tx test: add unit tests for bitrate library test: add unit tests for latencystats library test: add unit test for pdump library test/test/Makefile | 9 ++ test/test/autotest_data.py | 12 ++ test/test/process.h | 12 ++ test/test/sample_packet_forward.c | 115 +++++++++++++++++++ test/test/sample_packet_forward.h | 40 +++++++ test/test/test.c | 2 + test/test/test_bitratestats.c | 229 +++++++++++++++++++++++++++++++++++++ test/test/test_latencystats.c | 216 +++++++++++++++++++++++++++++++++++ test/test/test_pdump.c | 232 ++++++++++++++++++++++++++++++++++++++ test/test/test_pdump.h | 31 +++++ 10 files changed, 898 insertions(+) create mode 100644 test/test/sample_packet_forward.c create mode 100644 test/test/sample_packet_forward.h create mode 100644 test/test/test_bitratestats.c create mode 100644 test/test/test_latencystats.c create mode 100644 test/test/test_pdump.c create mode 100644 test/test/test_pdump.h -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* [dpdk-dev] [PATCH v8 1/4] test: add helper functions for tests using ring-PMD Rx/Tx 2018-07-27 14:26 ` [dpdk-dev] [PATCH v8 " Naga Suresh Somarowthu @ 2018-07-27 14:26 ` Naga Suresh Somarowthu 2018-07-27 14:26 ` [dpdk-dev] [PATCH v8 2/4] test: add unit tests for bitrate library Naga Suresh Somarowthu ` (3 subsequent siblings) 4 siblings, 0 replies; 37+ messages in thread From: Naga Suresh Somarowthu @ 2018-07-27 14:26 UTC (permalink / raw) To: dev; +Cc: remy.horton, reshma.pattan, Naga Suresh Somarowthu Added ring pmd based packet rx/tx helper functions for verifying Latency, Bitrate and pdump lib UTs. Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> Reviewed-by: Anatoly Burakov <anatoly.burakov@intel.com> --- test/test/Makefile | 1 + test/test/sample_packet_forward.c | 115 ++++++++++++++++++++++++++++++++++++++ test/test/sample_packet_forward.h | 40 +++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 test/test/sample_packet_forward.c create mode 100644 test/test/sample_packet_forward.h diff --git a/test/test/Makefile b/test/test/Makefile index e6967bab6..9f7d398e4 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -165,6 +165,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_REORDER) += test_reorder.c SRCS-y += virtual_pmd.c SRCS-y += packet_burst_generator.c +SRCS-y += sample_packet_forward.c SRCS-$(CONFIG_RTE_LIBRTE_ACL) += test_acl.c ifeq ($(CONFIG_RTE_LIBRTE_PMD_RING),y) diff --git a/test/test/sample_packet_forward.c b/test/test/sample_packet_forward.c new file mode 100644 index 000000000..3822577b9 --- /dev/null +++ b/test/test/sample_packet_forward.c @@ -0,0 +1,115 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include <string.h> +#include <errno.h> +#include <time.h> + +#include <rte_memcpy.h> +#include <rte_common.h> +#include <rte_eth_ring.h> +#include <rte_ethdev.h> +#include <rte_mbuf.h> +#include <rte_bus_vdev.h> + +#include "sample_packet_forward.h" +#include "test.h" + +/* Sample test to create virtual rings and tx,rx portid from rings */ +int +test_ring_setup(struct rte_ring **ring, uint16_t *portid) +{ + *ring = rte_ring_create("R0", RING_SIZE, rte_socket_id(), + RING_F_SP_ENQ | RING_F_SC_DEQ); + if (*ring == NULL) { + printf("%s() line %u: rte_ring_create R0 failed", + __func__, __LINE__); + return -1; + } + *portid = rte_eth_from_rings("net_ringa", ring, NUM_QUEUES, + ring, NUM_QUEUES, rte_socket_id()); + + return 0; +} + +/* Sample test to free the mempool */ +void +test_mp_free(struct rte_mempool *mp) +{ + rte_mempool_free(mp); +} + +/* Sample test to free the virtual rings */ +void +test_ring_free(struct rte_ring *rxtx) +{ + rte_ring_free(rxtx); +} + +/* Sample test to release the vdev */ +void +test_vdev_uninit(const char *vdev) +{ + rte_vdev_uninit(vdev); +} + +/* sample test to allocate the mempool */ +int +test_get_mempool(struct rte_mempool **mp, char *poolname) +{ + *mp = rte_pktmbuf_pool_create(poolname, NB_MBUF, 32, 0, + RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); + if (*mp == NULL) + return -1; + return 0; +} + +/* sample test to allocate buffer for pkts */ +int +test_get_mbuf_from_pool(struct rte_mempool **mp, struct rte_mbuf **pbuf, + char *poolname) +{ + int ret = 0; + + ret = test_get_mempool(mp, poolname); + if (ret < 0) + return -1; + if (rte_pktmbuf_alloc_bulk(*mp, pbuf, NUM_PACKETS) != 0) { + printf("%s() line %u: rte_pktmbuf_alloc_bulk failed", __func__, + __LINE__); + return -1; + } + return 0; +} + +/* sample test to deallocate the allocated buffers and mempool */ +void +test_put_mbuf_to_pool(struct rte_mempool *mp, struct rte_mbuf **pbuf) +{ + int itr = 0; + + for (itr = 0; itr < NUM_PACKETS; itr++) + rte_pktmbuf_free(pbuf[itr]); + rte_mempool_free(mp); +} + +/* Sample test to forward packets using virtual portids */ +int +test_packet_forward(struct rte_mbuf **pbuf, uint16_t portid, uint16_t queue_id) +{ + /* send and receive packet and check for stats update */ + if (rte_eth_tx_burst(portid, queue_id, pbuf, NUM_PACKETS) + < NUM_PACKETS) { + printf("%s() line %u: Error sending packet to" + " port %d\n", __func__, __LINE__, portid); + return -1; + } + if (rte_eth_rx_burst(portid, queue_id, pbuf, NUM_PACKETS) + < NUM_PACKETS) { + printf("%s() line %u: Error receiving packet from" + " port %d\n", __func__, __LINE__, portid); + return -1; + } + return 0; +} diff --git a/test/test/sample_packet_forward.h b/test/test/sample_packet_forward.h new file mode 100644 index 000000000..433bd3ba2 --- /dev/null +++ b/test/test/sample_packet_forward.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#ifndef _SAMPLE_PACKET_FORWARD_H_ +#define _SAMPLE_PACKET_FORWARD_H_ + +/* MACROS to support virtual ring creation */ +#define RING_SIZE 256 +#define NUM_QUEUES 1 +#define NB_MBUF 512 + +#define NUM_PACKETS 10 + +/* Sample test to create virtual rings and tx,rx portid from rings */ +int test_ring_setup(struct rte_ring **ring, uint16_t *portid); + +/* Sample test to free the virtual rings */ +void test_ring_free(struct rte_ring *rxtx); + +/* Sample test to forward packet using virtual port id */ +int test_packet_forward(struct rte_mbuf **pbuf, uint16_t portid, + uint16_t queue_id); + +/* sample test to allocate buffer for pkts */ +int test_get_mbuf_from_pool(struct rte_mempool **mp, struct rte_mbuf **pbuf, + char *poolname); + +/* Sample test to create the mempool */ +int test_get_mempool(struct rte_mempool **mp, char *poolname); + +/* sample test to deallocate the allocated buffers and mempool */ +void test_put_mbuf_to_pool(struct rte_mempool *mp, struct rte_mbuf **pbuf); + +/* Sample test to free the mempool */ +void test_mp_free(struct rte_mempool *mp); + +/* Sample test to release the vdev */ +void test_vdev_uninit(const char *vdev); +#endif /* _SAMPLE_PACKET_FORWARD_H_ */ -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* [dpdk-dev] [PATCH v8 2/4] test: add unit tests for bitrate library 2018-07-27 14:26 ` [dpdk-dev] [PATCH v8 " Naga Suresh Somarowthu 2018-07-27 14:26 ` [dpdk-dev] [PATCH v8 1/4] test: add helper functions for tests using ring-PMD Rx/Tx Naga Suresh Somarowthu @ 2018-07-27 14:26 ` Naga Suresh Somarowthu 2018-07-27 14:26 ` [dpdk-dev] [PATCH v8 3/4] test: add unit tests for latencystats library Naga Suresh Somarowthu ` (2 subsequent siblings) 4 siblings, 0 replies; 37+ messages in thread From: Naga Suresh Somarowthu @ 2018-07-27 14:26 UTC (permalink / raw) To: dev; +Cc: remy.horton, reshma.pattan, Naga Suresh Somarowthu Unit Test Cases for BitRate library. Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> Reviewed-by: Remy Horton <remy.horton@intel.com> --- test/test/Makefile | 1 + test/test/autotest_data.py | 6 ++ test/test/test_bitratestats.c | 229 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 236 insertions(+) create mode 100644 test/test/test_bitratestats.c diff --git a/test/test/Makefile b/test/test/Makefile index 9f7d398e4..c619877f0 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -183,6 +183,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_PMD_RING) += test_pmd_ring_perf.c SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev_blockcipher.c SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev.c SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev_asym.c +SRCS-$(CONFIG_RTE_LIBRTE_BITRATE) += test_bitratestats.c ifeq ($(CONFIG_RTE_COMPRESSDEV_TEST),y) SRCS-$(CONFIG_RTE_LIBRTE_COMPRESSDEV) += test_compressdev.c diff --git a/test/test/autotest_data.py b/test/test/autotest_data.py index aacfe0a66..419520342 100644 --- a/test/test/autotest_data.py +++ b/test/test/autotest_data.py @@ -293,6 +293,12 @@ def per_sockets(num): "Tests": [ { + "Name": "Bitratestats autotest", + "Command": "bitratestats_autotest", + "Func": default_autotest, + "Report": None, + }, + { "Name": "PMD ring autotest", "Command": "ring_pmd_autotest", "Func": default_autotest, diff --git a/test/test/test_bitratestats.c b/test/test/test_bitratestats.c new file mode 100644 index 000000000..38f7da4b5 --- /dev/null +++ b/test/test/test_bitratestats.c @@ -0,0 +1,229 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include <string.h> +#include <errno.h> +#include <time.h> + +#include <rte_log.h> +#include <rte_lcore.h> +#include <rte_mbuf.h> +#include <rte_memzone.h> +#include <rte_malloc.h> +#include <rte_common.h> +#include <rte_metrics.h> +#include <rte_bitrate.h> + +#include "test.h" +#include "sample_packet_forward.h" + +#define BIT_NUM_PACKETS 10 +#define QUEUE_ID 0 + +uint16_t portid; +struct rte_stats_bitrates *bitrate_data; +struct rte_ring *ring; + +/* To test whether rte_stats_bitrate_create is successful */ +static int +test_stats_bitrate_create(void) +{ + bitrate_data = rte_stats_bitrate_create(); + TEST_ASSERT(bitrate_data != NULL, "rte_stats_bitrate_create failed"); + + return TEST_SUCCESS; +} + +/* To test bit rate registration */ +static int +test_stats_bitrate_reg(void) +{ + int ret = 0; + + /* Test to register bit rate without metrics init */ + ret = rte_stats_bitrate_reg(bitrate_data); + TEST_ASSERT(ret < 0, "Test Failed: rte_stats_bitrate_reg succeeded " + "without metrics init, ret:%d", ret); + + /* Metrics initialization */ + rte_metrics_init(rte_socket_id()); + /* Test to register bit rate after metrics init */ + ret = rte_stats_bitrate_reg(bitrate_data); + TEST_ASSERT((ret >= 0), "Test Failed: rte_stats_bitrate_reg %d", ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate registration with invalid pointer */ +static int +test_stats_bitrate_reg_invalidpointer(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_reg(NULL); + TEST_ASSERT(ret < 0, "Test Failed: Expected failure < 0 but " + "got %d", ret); + + return TEST_SUCCESS; +} + +/* To test bit rate calculation with invalid bit rate data pointer */ +static int +test_stats_bitrate_calc_invalid_bitrate_data(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(NULL, portid); + TEST_ASSERT(ret < 0, "Test Failed: rte_stats_bitrate_calc " + "ret:%d", ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate calculation with invalid portid + * (higher than max ports) + */ +static int +test_stats_bitrate_calc_invalid_portid_1(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(bitrate_data, 33); + TEST_ASSERT(ret == -EINVAL, "Test Failed: Expected -%d for higher " + "portid rte_stats_bitrate_calc ret:%d", EINVAL, ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate calculation with invalid portid (lesser than 0) */ +static int +test_stats_bitrate_calc_invalid_portid_2(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(bitrate_data, -1); + TEST_ASSERT(ret == -EINVAL, "Test Failed: Expected -%d for invalid " + "portid rte_stats_bitrate_calc ret:%d", EINVAL, ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate calculation with non-existing portid */ +static int +test_stats_bitrate_calc_non_existing_portid(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(bitrate_data, 31); + TEST_ASSERT(ret == -EINVAL, "Test Failed: Expected -%d for " + "non-existing portid rte_stats_bitrate_calc ret:%d", + EINVAL, ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate calculation with valid bit rate data, valid portid */ +static int +test_stats_bitrate_calc(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(bitrate_data, portid); + TEST_ASSERT(ret >= 0, "Test Failed: Expected >=0 for valid portid " + "rte_stats_bitrate_calc ret:%d", ret); + + return TEST_SUCCESS; +} + +static int +test_bit_packet_forward(void) +{ + int ret; + struct rte_mbuf *pbuf[BIT_NUM_PACKETS] = { }; + struct rte_mempool *mp; + char poolname[] = "mbuf_pool"; + ret = test_get_mbuf_from_pool(&mp, pbuf, poolname); + if (ret < 0) { + printf("allocate mbuf pool Failed\n"); + return TEST_FAILED; + } + ret = test_packet_forward(pbuf, portid, QUEUE_ID); + if (ret < 0) + printf("send pkts Failed\n"); + test_put_mbuf_to_pool(mp, pbuf); + + return TEST_SUCCESS; +} + +static int +test_bit_ring_setup(void) +{ + test_ring_setup(&ring, &portid); + printf("port in ring setup : %d\n", portid); + + return TEST_SUCCESS; +} + +static void +test_bit_ring_free(void) +{ + test_ring_free(ring); + test_vdev_uninit("net_ring_net_ringa"); + rte_memzone_free(rte_memzone_lookup("RTE_METRICS")); +} + +static struct +unit_test_suite bitratestats_testsuite = { + .suite_name = "BitRate Stats Unit Test Suite", + .setup = test_bit_ring_setup, + .teardown = test_bit_ring_free, + .unit_test_cases = { + /* TEST CASE 1: Test to create bit rate data */ + TEST_CASE(test_stats_bitrate_create), + + /* TEST CASE 2: Test to register bit rate metrics + * without metrics init and after metrics init + */ + TEST_CASE(test_stats_bitrate_reg), + + /* TEST CASE 3: Test to register bit rate metrics + * with invalid bit rate data + */ + TEST_CASE(test_stats_bitrate_reg_invalidpointer), + + /* TEST CASE 4: Test to calculate bit rate data metrics + * with invalid bit rate data + */ + TEST_CASE(test_stats_bitrate_calc_invalid_bitrate_data), + + /* TEST CASE 5: Test to calculate bit rate data metrics + * with portid exceeding the max ports + */ + TEST_CASE(test_stats_bitrate_calc_invalid_portid_1), + + /* TEST CASE 6: Test to calculate bit rate data metrics + * with portid less than 0 + */ + TEST_CASE(test_stats_bitrate_calc_invalid_portid_2), + + /* TEST CASE 7: Test to calculate bit rate data metrics + * with non-existing portid + */ + TEST_CASE(test_stats_bitrate_calc_non_existing_portid), + + /* TEST CASE 8: Test to calculate bit rate data metrics + * with valid portid, valid bit rate data + */ + TEST_CASE_ST(test_bit_packet_forward, NULL, + test_stats_bitrate_calc), + TEST_CASES_END() + } +}; + +static int +test_bitratestats(void) +{ + return unit_test_suite_runner(&bitratestats_testsuite); +} +REGISTER_TEST_COMMAND(bitratestats_autotest, test_bitratestats); -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* [dpdk-dev] [PATCH v8 3/4] test: add unit tests for latencystats library 2018-07-27 14:26 ` [dpdk-dev] [PATCH v8 " Naga Suresh Somarowthu 2018-07-27 14:26 ` [dpdk-dev] [PATCH v8 1/4] test: add helper functions for tests using ring-PMD Rx/Tx Naga Suresh Somarowthu 2018-07-27 14:26 ` [dpdk-dev] [PATCH v8 2/4] test: add unit tests for bitrate library Naga Suresh Somarowthu @ 2018-07-27 14:26 ` Naga Suresh Somarowthu 2018-07-27 14:26 ` [dpdk-dev] [PATCH v8 4/4] test: add unit test for pdump library Naga Suresh Somarowthu 2018-07-31 14:57 ` [dpdk-dev] [PATCH v8 0/4] add unit tests for bitrate, latency and pdump libraries Thomas Monjalon 4 siblings, 0 replies; 37+ messages in thread From: Naga Suresh Somarowthu @ 2018-07-27 14:26 UTC (permalink / raw) To: dev; +Cc: remy.horton, reshma.pattan, Naga Suresh Somarowthu Unit Test Cases added for latencystats library. Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> --- test/test/Makefile | 1 + test/test/autotest_data.py | 6 ++ test/test/test_latencystats.c | 216 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 223 insertions(+) create mode 100644 test/test/test_latencystats.c diff --git a/test/test/Makefile b/test/test/Makefile index c619877f0..bba3be1be 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -184,6 +184,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev_blockcipher.c SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev.c SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev_asym.c SRCS-$(CONFIG_RTE_LIBRTE_BITRATE) += test_bitratestats.c +SRCS-$(CONFIG_RTE_LIBRTE_LATENCY_STATS) += test_latencystats.c ifeq ($(CONFIG_RTE_COMPRESSDEV_TEST),y) SRCS-$(CONFIG_RTE_LIBRTE_COMPRESSDEV) += test_compressdev.c diff --git a/test/test/autotest_data.py b/test/test/autotest_data.py index 419520342..3eccc4e1a 100644 --- a/test/test/autotest_data.py +++ b/test/test/autotest_data.py @@ -299,6 +299,12 @@ def per_sockets(num): "Report": None, }, { + "Name": "Latencystats autotest", + "Command": "latencystats_autotest", + "Func": default_autotest, + "Report": None, + }, + { "Name": "PMD ring autotest", "Command": "ring_pmd_autotest", "Func": default_autotest, diff --git a/test/test/test_latencystats.c b/test/test/test_latencystats.c new file mode 100644 index 000000000..f2287a2b7 --- /dev/null +++ b/test/test/test_latencystats.c @@ -0,0 +1,216 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <time.h> + +#include <rte_common.h> +#include <rte_metrics.h> +#include <rte_latencystats.h> +#include <rte_eth_ring.h> +#include <rte_ethdev.h> +#include <rte_mbuf.h> +#include "test.h" +#include "sample_packet_forward.h" +#define NUM_STATS 4 +#define LATENCY_NUM_PACKETS 10 +#define QUEUE_ID 0 + +uint16_t portid; +struct rte_ring *ring; + +struct rte_metric_name lat_stats_strings[] = { + {"min_latency_ns"}, + {"avg_latency_ns"}, + {"max_latency_ns"}, + {"jitter_ns"}, +}; + +/* Test case for latency init with metrics init */ +static int test_latency_init(void) +{ + int ret = 0; + + /* Metrics Initialization */ + rte_metrics_init(rte_socket_id()); + + ret = rte_latencystats_init(1, NULL); + TEST_ASSERT(ret >= 0, "Test Failed: rte_latencystats_init failed"); + + return TEST_SUCCESS; +} + +/* Test case to update the latency stats */ +static int test_latency_update(void) +{ + int ret = 0; + + ret = rte_latencystats_update(); + TEST_ASSERT(ret >= 0, "Test Failed: rte_latencystats_update failed"); + + return TEST_SUCCESS; +} + +/* Test case to uninit latency stats */ +static int test_latency_uninit(void) +{ + int ret = 0; + + ret = rte_latencystats_uninit(); + TEST_ASSERT(ret >= 0, "Test Failed: rte_latencystats_uninit failed"); + + return TEST_SUCCESS; +} + +/* Test case to get names of latency stats */ +static int test_latencystats_get_names(void) +{ + int ret = 0; + int size = 0; + struct rte_metric_name names[NUM_STATS] = { 0 }; + struct rte_metric_name wrongnames[NUM_STATS - 2] = { 0 }; + + /* Success Test: Valid names and size */ + size = NUM_STATS; + ret = rte_latencystats_get_names(names, size); + for (int i = 0; i <= NUM_STATS; i++) { + if (strcmp(lat_stats_strings[i].name, names[i].name) == 0) + printf(" %s\n", names[i].name); + else + printf("Failed: Names are not matched\n"); + } + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get metrics names"); + + /* Failure Test: Invalid names and valid size */ + ret = rte_latencystats_get_names(NULL, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get the metrics count," + "Actual: %d Expected: %d", ret, NUM_STATS); + + /* Failure Test: Valid names and invalid size */ + size = 0; + ret = rte_latencystats_get_names(names, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get the metrics count," + "Actual: %d Expected: %d", ret, NUM_STATS); + + /* Failure Test: Invalid names (array size lesser than size) */ + size = NUM_STATS + 1; + ret = rte_latencystats_get_names(wrongnames, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get metrics names"); + return TEST_SUCCESS; +} + +/* Test case to get latency stats values */ +static int test_latencystats_get(void) +{ + int ret = 0; + int size = 0; + struct rte_metric_value values[NUM_STATS] = { 0 }; + struct rte_metric_value wrongvalues[NUM_STATS - 2] = { 0 }; + + /* Success Test: Valid values and valid size */ + size = NUM_STATS; + ret = rte_latencystats_get(values, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get latency metrics" + " values"); + for (int i = 0; i < NUM_STATS; i++) + printf("values: %ld\n", values[i].value); + + /* Failure Test: Invalid values and valid size */ + ret = rte_latencystats_get(NULL, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get the stats count," + "Actual: %d Expected: %d", ret, NUM_STATS); + + /* Failure Test: Valid values and invalid size */ + size = 0; + ret = rte_latencystats_get(values, size); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get the stats count," + "Actual: %d Expected: %d", ret, NUM_STATS); + + /* Failure Test: Invalid values(array size lesser than size) + * and invalid size + */ + size = NUM_STATS + 2; + ret = rte_latencystats_get(wrongvalues, size); + TEST_ASSERT(ret == NUM_STATS, "Test Failed to get latency metrics" + " values"); + + return TEST_SUCCESS; +} + +static int test_latency_ring_setup(void) +{ + test_ring_setup(&ring, &portid); + + return TEST_SUCCESS; +} + +static void test_latency_ring_free(void) +{ + test_ring_free(ring); + test_vdev_uninit("net_ring_net_ringa"); +} + +static int test_latency_packet_forward(void) +{ + int ret; + struct rte_mbuf *pbuf[LATENCY_NUM_PACKETS] = { }; + struct rte_mempool *mp; + char poolname[] = "mbuf_pool"; + + ret = test_get_mbuf_from_pool(&mp, pbuf, poolname); + if (ret < 0) { + printf("allocate mbuf pool Failed\n"); + return TEST_FAILED; + } + ret = test_packet_forward(pbuf, portid, QUEUE_ID); + if (ret < 0) + printf("send pkts Failed\n"); + test_put_mbuf_to_pool(mp, pbuf); + + return TEST_SUCCESS; +} + +static struct +unit_test_suite latencystats_testsuite = { + .suite_name = "Latency Stats Unit Test Suite", + .setup = test_latency_ring_setup, + .teardown = test_latency_ring_free, + .unit_test_cases = { + + /* Test Case 1: To check latency init with + * metrics init + */ + TEST_CASE_ST(NULL, NULL, test_latency_init), + + /* Test Case 2: Do packet forwarding for metrics + * calculation and check the latency metrics values + * are updated + */ + TEST_CASE_ST(test_latency_packet_forward, NULL, + test_latency_update), + /* Test Case 3: To check whether latency stats names + * are retrieved + */ + TEST_CASE_ST(NULL, NULL, test_latencystats_get_names), + + /* Test Case 4: To check whether latency stats + * values are retrieved + */ + TEST_CASE_ST(NULL, NULL, test_latencystats_get), + + /* Test Case 5: To check uninit of latency test */ + TEST_CASE_ST(NULL, NULL, test_latency_uninit), + + TEST_CASES_END() + } +}; + +static int test_latencystats(void) +{ + return unit_test_suite_runner(&latencystats_testsuite); +} + +REGISTER_TEST_COMMAND(latencystats_autotest, test_latencystats); -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* [dpdk-dev] [PATCH v8 4/4] test: add unit test for pdump library 2018-07-27 14:26 ` [dpdk-dev] [PATCH v8 " Naga Suresh Somarowthu ` (2 preceding siblings ...) 2018-07-27 14:26 ` [dpdk-dev] [PATCH v8 3/4] test: add unit tests for latencystats library Naga Suresh Somarowthu @ 2018-07-27 14:26 ` Naga Suresh Somarowthu 2018-07-31 14:57 ` [dpdk-dev] [PATCH v8 0/4] add unit tests for bitrate, latency and pdump libraries Thomas Monjalon 4 siblings, 0 replies; 37+ messages in thread From: Naga Suresh Somarowthu @ 2018-07-27 14:26 UTC (permalink / raw) To: dev; +Cc: remy.horton, reshma.pattan, Naga Suresh Somarowthu Unit test cases are added for pdump library. Primary process will act as server, forks a child secondary process. Secondary process acts as client. Server will do pdump init to serve any pdump client requests. Server will create a vdev, send/receive packets continuously in a separate thread. Client will create virtual rings to receive the packet dump. Client sends pdump enable/disable requests using either port/device id. Packet flow direction can be tx/rx/tx&rx. In Server, appropriate pdump callbacks are triggered, when packets are transmitted/received. Pdump packet is copied to client rings. Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com> Reviewed-by: Reshma Pattan <reshma.pattan@intel.com> --- test/test/Makefile | 6 ++ test/test/process.h | 12 +++ test/test/test.c | 2 + test/test/test_pdump.c | 232 +++++++++++++++++++++++++++++++++++++++++++++++++ test/test/test_pdump.h | 31 +++++++ 5 files changed, 283 insertions(+) create mode 100644 test/test/test_pdump.c create mode 100644 test/test/test_pdump.h diff --git a/test/test/Makefile b/test/test/Makefile index bba3be1be..3e7baef76 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -185,6 +185,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev.c SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev_asym.c SRCS-$(CONFIG_RTE_LIBRTE_BITRATE) += test_bitratestats.c SRCS-$(CONFIG_RTE_LIBRTE_LATENCY_STATS) += test_latencystats.c +SRCS-$(CONFIG_RTE_LIBRTE_PDUMP) += test_pdump.c ifeq ($(CONFIG_RTE_COMPRESSDEV_TEST),y) SRCS-$(CONFIG_RTE_LIBRTE_COMPRESSDEV) += test_compressdev.c @@ -214,6 +215,11 @@ CFLAGS += $(WERROR_FLAGS) CFLAGS += -D_GNU_SOURCE LDLIBS += -lm + +ifeq ($(CONFIG_RTE_LIBRTE_PDUMP),y) +LDLIBS += -lpthread +endif + ifeq ($(CONFIG_RTE_COMPRESSDEV_TEST),y) ifeq ($(CONFIG_RTE_LIBRTE_COMPRESSDEV),y) LDLIBS += -lz diff --git a/test/test/process.h b/test/test/process.h index 11986d5c2..1e7adde0e 100644 --- a/test/test/process.h +++ b/test/test/process.h @@ -13,6 +13,10 @@ #define exe "exe" #endif +#include <pthread.h> +extern void *send_pkts(void *empty); +extern uint16_t flag_for_send_pkts; + /* * launches a second copy of the test process using the given argv parameters, * which should include argv[0] as the process name. To identify in the @@ -26,6 +30,7 @@ process_dup(const char *const argv[], int numargs, const char *env_value) char *argv_cpy[numargs + 1]; int i, fd, status; char path[32]; + pthread_t thread; pid_t pid = fork(); if (pid < 0) @@ -56,8 +61,15 @@ process_dup(const char *const argv[], int numargs, const char *env_value) rte_panic("Cannot exec\n"); } /* parent process does a wait */ + if ((strcmp(env_value, "run_pdump_server_tests") == 0)) + pthread_create(&thread, NULL, &send_pkts, NULL); + while (wait(&status) != pid) ; + if ((strcmp(env_value, "run_pdump_server_tests") == 0)) { + flag_for_send_pkts = 0; + pthread_join(thread, NULL); + } return status; } diff --git a/test/test/test.c b/test/test/test.c index 44dfe20ef..a54b0d142 100644 --- a/test/test/test.c +++ b/test/test/test.c @@ -30,6 +30,7 @@ extern cmdline_parse_ctx_t main_ctx[]; #endif #include "test.h" +#include "test_pdump.h" #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1 @@ -49,6 +50,7 @@ do_recursive_call(void) int (*action_fn)(void); } actions[] = { { "run_secondary_instances", test_mp_secondary }, + { "run_pdump_server_tests", test_pdump }, { "test_missing_c_flag", no_action }, { "test_master_lcore_flag", no_action }, { "test_invalid_n_flag", no_action }, diff --git a/test/test/test_pdump.c b/test/test/test_pdump.c new file mode 100644 index 000000000..cfdda4d39 --- /dev/null +++ b/test/test/test_pdump.c @@ -0,0 +1,232 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include <time.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdarg.h> +#include <inttypes.h> +#include <sys/queue.h> +#include <string.h> +#include <unistd.h> +#include <sys/wait.h> + +#include <rte_common.h> +#include <rte_mbuf.h> +#include <rte_pdump.h> +#include <rte_eth_ctrl.h> +#include <rte_memory.h> +#include <rte_memzone.h> +#include <rte_eal.h> +#include <rte_ring.h> +#include <rte_mempool.h> +#include <rte_eth_ring.h> +#include <rte_ethdev_driver.h> +#include <libgen.h> + +#include "test.h" +#include "sample_packet_forward.h" +#include "test_pdump.h" +#include "process.h" + +#define launch_p(ARGV) process_dup(ARGV, \ + sizeof(ARGV)/(sizeof(ARGV[0])), __func__) + +struct rte_ring *ring_server; +uint16_t portid; +uint16_t flag_for_send_pkts = 1; + +int +test_pdump_init(void) +{ + int ret = 0; + + ret = rte_pdump_init(NULL); + if (ret < 0) { + printf("rte_pdump_init failed\n"); + return -1; + } + ret = test_ring_setup(&ring_server, &portid); + if (ret < 0) { + printf("test_ring_setup failed\n"); + return -1; + } + printf("pdump_init success\n"); + return ret; +} + +int +run_pdump_client_tests(void) +{ + int flags = RTE_PDUMP_FLAG_TX, ret = 0, itr; + char deviceid[] = "net_ring_net_ringa"; + struct rte_ring *ring_client; + struct rte_mempool *mp = NULL; + struct rte_eth_dev *eth_dev = NULL; + char poolname[] = "mbuf_pool_client"; + + ret = test_get_mempool(&mp, poolname); + if (ret < 0) + return -1; + mp->flags = 0x0000; + ring_client = rte_ring_create("SR0", RING_SIZE, rte_socket_id(), + RING_F_SP_ENQ | RING_F_SC_DEQ); + if (ring_client == NULL) { + printf("rte_ring_create SR0 failed"); + return -1; + } + + eth_dev = rte_eth_dev_attach_secondary(deviceid); + if (!eth_dev) { + printf("Failed to probe %s", deviceid); + return -1; + } + rte_eth_dev_probing_finish(eth_dev); + + ring_client->prod.single = 0; + ring_client->cons.single = 0; + + printf("\n***** flags = RTE_PDUMP_FLAG_TX *****\n"); + + for (itr = 0; itr < NUM_ITR; itr++) { + ret = rte_pdump_enable(portid, QUEUE_ID, flags, ring_client, + mp, NULL); + if (ret < 0) { + printf("rte_pdump_enable failed\n"); + return -1; + } + printf("pdump_enable success\n"); + + ret = rte_pdump_disable(portid, QUEUE_ID, flags); + if (ret < 0) { + printf("rte_pdump_disable failed\n"); + return -1; + } + printf("pdump_disable success\n"); + + ret = rte_pdump_enable_by_deviceid(deviceid, QUEUE_ID, flags, + ring_client, mp, NULL); + if (ret < 0) { + printf("rte_pdump_enable_by_deviceid failed\n"); + return -1; + } + printf("pdump_enable_by_deviceid success\n"); + + ret = rte_pdump_disable_by_deviceid(deviceid, QUEUE_ID, flags); + if (ret < 0) { + printf("rte_pdump_disable_by_deviceid failed\n"); + return -1; + } + printf("pdump_disable_by_deviceid success\n"); + + if (itr == 0) { + flags = RTE_PDUMP_FLAG_RX; + printf("\n***** flags = RTE_PDUMP_FLAG_RX *****\n"); + } else if (itr == 1) { + flags = RTE_PDUMP_FLAG_RXTX; + printf("\n***** flags = RTE_PDUMP_FLAG_RXTX *****\n"); + } + } + if (ring_client != NULL) + test_ring_free(ring_client); + if (mp != NULL) + test_mp_free(mp); + + return ret; +} + +int +test_pdump_uninit(void) +{ + int ret = 0; + + ret = rte_pdump_uninit(); + if (ret < 0) { + printf("rte_pdump_uninit failed\n"); + return -1; + } + if (ring_server != NULL) + test_ring_free(ring_server); + printf("pdump_uninit success\n"); + test_vdev_uninit("net_ring_net_ringa"); + return ret; +} + +void * +send_pkts(void *empty) +{ + int ret = 0; + struct rte_mbuf *pbuf[NUM_PACKETS] = { }; + struct rte_mempool *mp; + char poolname[] = "mbuf_pool_server"; + + ret = test_get_mbuf_from_pool(&mp, pbuf, poolname); + if (ret < 0) + printf("get_mbuf_from_pool failed\n"); + do { + ret = test_packet_forward(pbuf, portid, QUEUE_ID); + if (ret < 0) + printf("send pkts Failed\n"); + } while (flag_for_send_pkts); + test_put_mbuf_to_pool(mp, pbuf); + return empty; +} + +/* + * This function is called in the primary i.e. main test, to spawn off secondary + * processes to run actual mp tests. Uses fork() and exec pair + */ + +int +run_pdump_server_tests(void) +{ + int ret = 0; + char coremask[10]; + +#ifdef RTE_EXEC_ENV_LINUXAPP + char tmp[PATH_MAX] = { 0 }; + char prefix[PATH_MAX] = { 0 }; + + get_current_prefix(tmp, sizeof(tmp)); + snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp); +#else + const char *prefix = ""; +#endif + + /* good case, using secondary */ + const char *const argv1[] = { + prgname, "-c", coremask, "--proc-type=secondary", + prefix + }; + + snprintf(coremask, sizeof(coremask), "%x", + (1 << rte_get_master_lcore())); + + ret = test_pdump_init(); + ret |= launch_p(argv1); + ret |= test_pdump_uninit(); + return ret; +} + +int +test_pdump(void) +{ + int ret = 0; + if (rte_eal_process_type() == RTE_PROC_PRIMARY) { + printf("IN PRIMARY PROCESS\n"); + ret = run_pdump_server_tests(); + if (ret < 0) + return TEST_FAILED; + } else if (rte_eal_process_type() == RTE_PROC_SECONDARY) { + printf("IN SECONDARY PROCESS\n"); + sleep(5); + ret = run_pdump_client_tests(); + if (ret < 0) + return TEST_FAILED; + } + return TEST_SUCCESS; +} + +REGISTER_TEST_COMMAND(pdump_autotest, test_pdump); diff --git a/test/test/test_pdump.h b/test/test/test_pdump.h new file mode 100644 index 000000000..abef9a85e --- /dev/null +++ b/test/test/test_pdump.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#ifndef _TEST_PDUMP_H_ +#define _TEST_PDUMP_H_ + +#define QUEUE_ID 0 +#define NUM_ITR 3 + +/* sample test to send packets to the pdump client recursively */ +void *send_pkts(void *port); + +/* Sample test to create setup for the pdump server tests */ +int test_pdump_init(void); + +/* Sample test to teardown the pdump server setup */ +int test_pdump_uninit(void); + +/* Sample test to run the pdump client tests */ +int run_pdump_client_tests(void); + +/* Sample test to run the pdump server tests */ +int run_pdump_server_tests(void); + +/* Sample test to run the pdump client and server tests based on + * the process type + */ +int test_pdump(void); + +#endif /* _TEST_PDUMP_H_ */ -- 2.13.6 ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [dpdk-dev] [PATCH v8 0/4] add unit tests for bitrate, latency and pdump libraries 2018-07-27 14:26 ` [dpdk-dev] [PATCH v8 " Naga Suresh Somarowthu ` (3 preceding siblings ...) 2018-07-27 14:26 ` [dpdk-dev] [PATCH v8 4/4] test: add unit test for pdump library Naga Suresh Somarowthu @ 2018-07-31 14:57 ` Thomas Monjalon 2018-07-31 16:43 ` Pattan, Reshma 4 siblings, 1 reply; 37+ messages in thread From: Thomas Monjalon @ 2018-07-31 14:57 UTC (permalink / raw) To: Naga Suresh Somarowthu; +Cc: dev, remy.horton, reshma.pattan 27/07/2018 16:26, Naga Suresh Somarowthu: > Naga Suresh Somarowthu (4): > test: add helper functions for tests using ring-PMD Rx/Tx > test: add unit tests for bitrate library > test: add unit tests for latencystats library > test: add unit test for pdump library The patch 2 does not apply on top of autotest rework. Please rebase I think it will be for 18.11. ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: [dpdk-dev] [PATCH v8 0/4] add unit tests for bitrate, latency and pdump libraries 2018-07-31 14:57 ` [dpdk-dev] [PATCH v8 0/4] add unit tests for bitrate, latency and pdump libraries Thomas Monjalon @ 2018-07-31 16:43 ` Pattan, Reshma 0 siblings, 0 replies; 37+ messages in thread From: Pattan, Reshma @ 2018-07-31 16:43 UTC (permalink / raw) To: Thomas Monjalon, Somarowthu, Naga SureshX Cc: dev, Horton, Remy, Parthasarathy, JananeeX M Hi Thomas, > -----Original Message----- > From: Thomas Monjalon [mailto:thomas@monjalon.net] > Sent: Tuesday, July 31, 2018 3:57 PM > To: Somarowthu, Naga SureshX <naga.sureshx.somarowthu@intel.com> > Cc: dev@dpdk.org; Horton, Remy <remy.horton@intel.com>; Pattan, Reshma > <reshma.pattan@intel.com> > Subject: Re: [dpdk-dev] [PATCH v8 0/4] add unit tests for bitrate, latency and > pdump libraries > > 27/07/2018 16:26, Naga Suresh Somarowthu: > > Naga Suresh Somarowthu (4): > > test: add helper functions for tests using ring-PMD Rx/Tx > > test: add unit tests for bitrate library > > test: add unit tests for latencystats library > > test: add unit test for pdump library > > The patch 2 does not apply on top of autotest rework. > > Please rebase I have rebased and sent v9 version of patch series on behalf of Suresh. > > I think it will be for 18.11. > Please include them in 18.08 as now v9 is available . Thanks, Reshma ^ permalink raw reply [flat|nested] 37+ messages in thread
end of thread, other threads:[~2018-07-31 16:43 UTC | newest] Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-07-06 17:07 [dpdk-dev] [PATCH] add sample functions for packet forwarding Jananee Parthasarathy 2018-07-10 9:53 ` Pattan, Reshma 2018-07-12 8:53 ` [dpdk-dev] [PATCH v2] " Jananee Parthasarathy 2018-07-12 16:00 ` Pattan, Reshma 2018-07-16 16:00 ` [dpdk-dev] [PATCH v3] test: " Jananee Parthasarathy 2018-07-17 8:15 ` Pattan, Reshma 2018-07-17 10:00 ` [dpdk-dev] [PATCH v4] " Jananee Parthasarathy 2018-07-17 10:22 ` Burakov, Anatoly 2018-07-24 10:54 ` [dpdk-dev] [PATCH v5 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu 2018-07-24 10:54 ` [dpdk-dev] [PATCH v5 1/4] test: add ring pmd based packet rx/tx for UT Naga Suresh Somarowthu 2018-07-24 11:21 ` Burakov, Anatoly 2018-07-24 10:54 ` [dpdk-dev] [PATCH v5 2/4] test: add unit tests for bitrate library Naga Suresh Somarowthu 2018-07-24 10:54 ` [dpdk-dev] [PATCH v5 3/4] test: add unit tests for latencystats library Naga Suresh Somarowthu 2018-07-24 10:54 ` [dpdk-dev] [PATCH v5 4/4] test: add unit test for pdump library Naga Suresh Somarowthu 2018-07-24 12:27 ` Burakov, Anatoly 2018-07-25 17:05 ` [dpdk-dev] [PATCH v6 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu 2018-07-25 17:05 ` [dpdk-dev] [PATCH v6 1/4] test: add ring pmd based packet rx/tx for UT Naga Suresh Somarowthu 2018-07-26 9:59 ` Burakov, Anatoly 2018-07-25 17:05 ` [dpdk-dev] [PATCH v6 2/4] test: add unit tests for bitrate library Naga Suresh Somarowthu 2018-07-25 17:05 ` [dpdk-dev] [PATCH v6 3/4] test: add unit tests for latencystats library Naga Suresh Somarowthu 2018-07-25 17:06 ` [dpdk-dev] [PATCH v6 4/4] test: add unit test for pdump library Naga Suresh Somarowthu 2018-07-26 10:02 ` Burakov, Anatoly 2018-07-26 12:50 ` [dpdk-dev] [PATCH v7 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu 2018-07-26 12:50 ` [dpdk-dev] [PATCH v7 1/4] test: add ring pmd based packet rx/tx for UT Naga Suresh Somarowthu 2018-07-26 16:43 ` Pattan, Reshma 2018-07-27 7:40 ` Burakov, Anatoly 2018-07-26 12:50 ` [dpdk-dev] [PATCH v7 2/4] test: add unit tests for bitrate library Naga Suresh Somarowthu 2018-07-26 12:50 ` [dpdk-dev] [PATCH v7 3/4] test: add unit tests for latencystats library Naga Suresh Somarowthu 2018-07-26 12:50 ` [dpdk-dev] [PATCH v7 4/4] test: add unit test for pdump library Naga Suresh Somarowthu 2018-07-26 16:04 ` [dpdk-dev] [PATCH v7 0/4] add unit tests for bitrate, latency and pdump libraries Pattan, Reshma 2018-07-27 14:26 ` [dpdk-dev] [PATCH v8 " Naga Suresh Somarowthu 2018-07-27 14:26 ` [dpdk-dev] [PATCH v8 1/4] test: add helper functions for tests using ring-PMD Rx/Tx Naga Suresh Somarowthu 2018-07-27 14:26 ` [dpdk-dev] [PATCH v8 2/4] test: add unit tests for bitrate library Naga Suresh Somarowthu 2018-07-27 14:26 ` [dpdk-dev] [PATCH v8 3/4] test: add unit tests for latencystats library Naga Suresh Somarowthu 2018-07-27 14:26 ` [dpdk-dev] [PATCH v8 4/4] test: add unit test for pdump library Naga Suresh Somarowthu 2018-07-31 14:57 ` [dpdk-dev] [PATCH v8 0/4] add unit tests for bitrate, latency and pdump libraries Thomas Monjalon 2018-07-31 16:43 ` Pattan, Reshma
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).