DPDK patches and discussions
 help / color / mirror / Atom feed
From: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com>
To: dev@dpdk.org
Cc: remy.horton@intel.com, reshma.pattan@intel.com,
	Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com>
Subject: [dpdk-dev] [PATCH v11 4/6]  test: add unit test for pdump library
Date: Fri,  3 Aug 2018 13:05:51 +0100	[thread overview]
Message-ID: <1533297953-9149-5-git-send-email-naga.sureshx.somarowthu@intel.com> (raw)
In-Reply-To: <1533297953-9149-1-git-send-email-naga.sureshx.somarowthu@intel.com>

 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 ba3a18502..c015c9030 100644
--- a/test/test/process.h
+++ b/test/test/process.h
@@ -18,6 +18,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
@@ -31,6 +35,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)
@@ -61,8 +66,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

  parent reply	other threads:[~2018-08-03 12:06 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-31 22:18 [dpdk-dev] [PATCH v10 0/5] add unit tests for bitrate, latency and pdump libraries Reshma Pattan
2018-07-31 22:18 ` [dpdk-dev] [PATCH v10 1/5] test: add helper functions for tests using ring-PMD Rx/Tx Reshma Pattan
2018-07-31 22:18 ` [dpdk-dev] [PATCH v10 2/5] test: add unit tests for bitrate library Reshma Pattan
2018-07-31 22:18 ` [dpdk-dev] [PATCH v10 3/5] test: add unit tests for latencystats library Reshma Pattan
2018-07-31 22:18 ` [dpdk-dev] [PATCH v10 4/5] test: add unit test for pdump library Reshma Pattan
2018-07-31 22:18 ` [dpdk-dev] [PATCH v10 5/5] autotest: add new unit tests to autotest list Reshma Pattan
2018-07-31 22:30 ` [dpdk-dev] [PATCH v10 0/5] add unit tests for bitrate, latency and pdump libraries Thomas Monjalon
2018-08-01  7:52 ` Thomas Monjalon
2018-08-03 13:45   ` Pattan, Reshma
2018-08-03 14:11     ` Thomas Monjalon
2018-08-03 14:16     ` Parthasarathy, JananeeX M
2018-08-03 15:01       ` Thomas Monjalon
2018-08-03 12:05 ` [dpdk-dev] [PATCH v11 0/6] " Naga Suresh Somarowthu
2018-08-03 12:05   ` [dpdk-dev] [PATCH v11 1/6] test: add helper functions for tests using ring-PMD Rx/Tx Naga Suresh Somarowthu
2018-08-03 12:05   ` [dpdk-dev] [PATCH v11 2/6] test: add unit tests for bitrate library Naga Suresh Somarowthu
2018-08-03 12:05   ` [dpdk-dev] [PATCH v11 3/6] test: add unit tests for latencystats library Naga Suresh Somarowthu
2018-08-03 12:05   ` Naga Suresh Somarowthu [this message]
2018-08-03 12:05   ` [dpdk-dev] [PATCH v11 5/6] autotest: add new unit tests to autotest list Naga Suresh Somarowthu
2018-08-03 12:05   ` [dpdk-dev] [PATCH v11 6/6] maintainers: add bitrate latency pdump tests Naga Suresh Somarowthu
2018-08-03 12:34   ` [dpdk-dev] [PATCH v12 0/6] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu
2018-08-03 12:34     ` [dpdk-dev] [PATCH v12 1/6] test: add helper functions for tests using ring-PMD Rx/Tx Naga Suresh Somarowthu
2018-08-03 12:34     ` [dpdk-dev] [PATCH v12 2/6] test: add unit tests for bitrate library Naga Suresh Somarowthu
2018-08-03 12:34     ` [dpdk-dev] [PATCH v12 3/6] test: add unit tests for latencystats library Naga Suresh Somarowthu
2018-08-03 12:34     ` [dpdk-dev] [PATCH v12 4/6] test: add unit test for pdump library Naga Suresh Somarowthu
2018-08-03 12:34     ` [dpdk-dev] [PATCH v12 5/6] autotest: add new unit tests to autotest list Naga Suresh Somarowthu
2018-08-03 12:34     ` [dpdk-dev] [PATCH v12 6/6] maintainers: add bitrate latency pdump tests Naga Suresh Somarowthu
2018-08-24 12:51     ` [dpdk-dev] [PATCH v13 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu
2018-08-24 12:51       ` [dpdk-dev] [PATCH v13 1/4] test: add helper functions for tests using ring-PMD Rx/Tx Naga Suresh Somarowthu
2018-08-24 12:51       ` [dpdk-dev] [PATCH v13 2/4] test: add unit tests for bitrate library Naga Suresh Somarowthu
2018-08-24 12:51       ` [dpdk-dev] [PATCH v13 3/4] test: add unit tests for latencystats library Naga Suresh Somarowthu
2018-08-24 12:51       ` [dpdk-dev] [PATCH v13 4/4] test: add unit test for pdump library Naga Suresh Somarowthu
2018-08-07  8:46   ` [dpdk-dev] [PATCH v11 0/6] add unit tests for bitrate, latency and pdump libraries Burakov, Anatoly

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1533297953-9149-5-git-send-email-naga.sureshx.somarowthu@intel.com \
    --to=naga.sureshx.somarowthu@intel.com \
    --cc=dev@dpdk.org \
    --cc=remy.horton@intel.com \
    --cc=reshma.pattan@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).