[dpdk-dev] [PATCH v14 1/4] test: add helper functions for tests using ring-PMD Rx/Tx
Naga Suresh Somarowthu
naga.sureshx.somarowthu at intel.com
Mon Oct 8 14:12:44 CEST 2018
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 at intel.com>
Reviewed-by: Reshma Pattan <reshma.pattan at intel.com>
Reviewed-by: Anatoly Burakov <anatoly.burakov at intel.com>
---
MAINTAINERS | 5 ++
test/test/Makefile | 1 +
test/test/meson.build | 1 +
test/test/sample_packet_forward.c | 114 ++++++++++++++++++++++++++++++++++++++
test/test/sample_packet_forward.h | 46 +++++++++++++++
5 files changed, 167 insertions(+)
create mode 100644 test/test/sample_packet_forward.c
create mode 100644 test/test/sample_packet_forward.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 84b9ff786..c00081cd8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1188,6 +1188,11 @@ F: test/test/test_resource.c
F: test/test/virtual_pmd.c
F: test/test/virtual_pmd.h
+Sample packet helper functions for unit test
+M: Reshma Pattan <reshma.pattan at intel.com>
+F: test/test/sample_packet_forward.c
+F: test/test/sample_packet_forward.h
+
Driver testing tool
M: Wenzhuo Lu <wenzhuo.lu at intel.com>
M: Jingjing Wu <jingjing.wu at intel.com>
diff --git a/test/test/Makefile b/test/test/Makefile
index dcea4410d..66e98066f 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/meson.build b/test/test/meson.build
index bacb5b144..087ffdb91 100644
--- a/test/test/meson.build
+++ b/test/test/meson.build
@@ -3,6 +3,7 @@
test_sources = files('commands.c',
'packet_burst_generator.c',
+ 'sample_packet_forward.c',
'test.c',
'test_acl.c',
'test_alarm.c',
diff --git a/test/test/sample_packet_forward.c b/test/test/sample_packet_forward.c
new file mode 100644
index 000000000..61384b3d9
--- /dev/null
+++ b/test/test/sample_packet_forward.c
@@ -0,0 +1,114 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include <rte_eth_ring.h>
+#include <rte_ethdev.h>
+#include <rte_mbuf.h>
+#include <rte_bus_vdev.h>
+#include "rte_lcore.h"
+#include "rte_mempool.h"
+#include "rte_ring.h"
+
+#include "sample_packet_forward.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..b2ed618b2
--- /dev/null
+++ b/test/test/sample_packet_forward.h
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#ifndef _SAMPLE_PACKET_FORWARD_H_
+#define _SAMPLE_PACKET_FORWARD_H_
+
+#include <stdint.h>
+
+/* MACROS to support virtual ring creation */
+#define RING_SIZE 256
+#define NUM_QUEUES 1
+#define NB_MBUF 512
+
+#define NUM_PACKETS 10
+
+struct rte_mbuf;
+struct rte_mempool;
+struct rte_ring;
+
+/* 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
More information about the dev
mailing list