From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id A6B9998 for ; Tue, 24 Jul 2018 12:55:01 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jul 2018 03:54:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,397,1526367600"; d="scan'208";a="57444754" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga008.fm.intel.com with ESMTP; 24 Jul 2018 03:54:58 -0700 Received: from wgcvswdev001.ir.intel.com (wgcvswdev001.ir.intel.com [10.102.246.100]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id w6OAswOM013929; Tue, 24 Jul 2018 11:54:58 +0100 Received: from wgcvswdev001.ir.intel.com (localhost [127.0.0.1]) by wgcvswdev001.ir.intel.com with ESMTP id w6OAsubf001781; Tue, 24 Jul 2018 11:54:56 +0100 Received: (from jmparthx@localhost) by wgcvswdev001.ir.intel.com with œ id w6OAsuKA001777; Tue, 24 Jul 2018 11:54:56 +0100 From: Naga Suresh Somarowthu To: dev@dpdk.org Cc: remy.horton@intel.com, reshma.pattan@intel.com, Naga Suresh Somarowthu Date: Tue, 24 Jul 2018 11:54:31 +0100 Message-Id: <1532429671-1606-5-git-send-email-naga.sureshx.somarowthu@intel.com> X-Mailer: git-send-email 1.7.12.2 In-Reply-To: <1532429671-1606-1-git-send-email-naga.sureshx.somarowthu@intel.com> References: <1531821650-5506-1-git-send-email-jananeex.m.parthasarathy@intel.com> <1532429671-1606-1-git-send-email-naga.sureshx.somarowthu@intel.com> Subject: [dpdk-dev] [PATCH v5 4/4] test: add unit test for pdump library X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Jul 2018 10:55:02 -0000 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 Reviewed-by: Reshma Pattan --- 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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