test/pdump: add unit test for pdump library
authorNaga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com>
Mon, 8 Oct 2018 12:12:47 +0000 (13:12 +0100)
committerThomas Monjalon <thomas@monjalon.net>
Fri, 18 Jan 2019 01:33:29 +0000 (02:33 +0100)
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>
MAINTAINERS
test/test/Makefile
test/test/autotest_data.py
test/test/meson.build
test/test/process.h
test/test/test.c
test/test/test_pdump.c [new file with mode: 0644]
test/test/test_pdump.h [new file with mode: 0644]

index 7f7052e..6610440 100644 (file)
@@ -1082,9 +1082,11 @@ Packet capture
 M: Reshma Pattan <reshma.pattan@intel.com>
 F: lib/librte_pdump/
 F: doc/guides/prog_guide/pdump_lib.rst
+F: test/test/test_pdump.*
 F: app/pdump/
 F: doc/guides/tools/pdump.rst
 
+
 Packet Framework
 ----------------
 M: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
index ac2b425..89949c2 100644 (file)
@@ -167,6 +167,8 @@ SRCS-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR) += test_distributor_perf.c
 
 SRCS-$(CONFIG_RTE_LIBRTE_REORDER) += test_reorder.c
 
+SRCS-$(CONFIG_RTE_LIBRTE_PDUMP) += test_pdump.c
+
 SRCS-y += virtual_pmd.c
 SRCS-y += packet_burst_generator.c
 SRCS-y += sample_packet_forward.c
@@ -222,6 +224,11 @@ CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 
 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
index 63cc1f4..948a625 100644 (file)
@@ -506,6 +506,12 @@ parallel_test_list = [
         "Func":    default_autotest,
         "Report":  None,
     },
+    {
+        "Name":    "Pdump autotest",
+        "Comamnd": "pdump_autotest",
+        "Func":    default_autotest,
+        "Report":  None,
+    },
     #
     #Please always keep all dump tests at the end and together!
     #
index 35fad4b..045d7c8 100644 (file)
@@ -76,6 +76,7 @@ test_sources = files('commands.c',
        'test_meter.c',
        'test_metrics.c',
        'test_mp_secondary.c',
+       'test_pdump.c',
        'test_per_lcore.c',
        'test_pmd_perf.c',
        'test_pmd_ring.c',
@@ -214,6 +215,7 @@ test_names = [
        'meter_autotest',
        'metrics_autotest',
        'multiprocess_autotest',
+       'pdump_autotest',
        'per_lcore_autotest',
        'pmd_perf_autotest',
        'power_acpi_cpufreq_autotest',
index ba3a185..7f62f64 100644 (file)
@@ -9,6 +9,7 @@
 #include <libgen.h> /* basename et al */
 #include <stdlib.h> /* NULL */
 #include <unistd.h> /* readlink */
+#include <sys/wait.h>
 
 #ifdef RTE_EXEC_ENV_BSDAPP
 #define self "curproc"
 #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 +36,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 +67,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;
 }
 
index 12fabd0..351c7f2 100644 (file)
@@ -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 (file)
index 0000000..4a894c0
--- /dev/null
@@ -0,0 +1,219 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+#include <stdio.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <limits.h>
+
+#include <rte_ethdev_driver.h>
+#include <rte_pdump.h>
+#include "rte_eal.h"
+#include "rte_lcore.h"
+#include "rte_mempool.h"
+#include "rte_ring.h"
+
+#include "sample_packet_forward.h"
+#include "test.h"
+#include "process.h"
+#include "test_pdump.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();
+       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 (file)
index 0000000..abef9a8
--- /dev/null
@@ -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_ */