From patchwork Fri Aug 24 12:51:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naga Suresh Somarowthu X-Patchwork-Id: 43858 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id EA41A4F9C; Fri, 24 Aug 2018 14:52:03 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id 00A334F90 for ; Fri, 24 Aug 2018 14:52:01 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Aug 2018 05:52:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,281,1531810800"; d="scan'208";a="64899924" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga007.fm.intel.com with ESMTP; 24 Aug 2018 05:51:42 -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 w7OCpfdm031747; Fri, 24 Aug 2018 13:51:41 +0100 Received: from wgcvswdev001.ir.intel.com (localhost [127.0.0.1]) by wgcvswdev001.ir.intel.com with ESMTP id w7OCpYhg002546; Fri, 24 Aug 2018 13:51:34 +0100 Received: (from jmparthx@localhost) by wgcvswdev001.ir.intel.com with ? id w7OCpY4E002541; Fri, 24 Aug 2018 13:51:34 +0100 From: Naga Suresh Somarowthu To: dev@dpdk.org Cc: reshma.pattan@intel.com, Naga Suresh Somarowthu Date: Fri, 24 Aug 2018 13:51:26 +0100 Message-Id: <1535115087-2442-4-git-send-email-naga.sureshx.somarowthu@intel.com> X-Mailer: git-send-email 1.7.12.2 In-Reply-To: <1535115087-2442-1-git-send-email-naga.sureshx.somarowthu@intel.com> References: <1533299698-20950-1-git-send-email-naga.sureshx.somarowthu@intel.com> <1535115087-2442-1-git-send-email-naga.sureshx.somarowthu@intel.com> Subject: [dpdk-dev] [PATCH v13 3/4] test: add unit tests for latencystats 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Unit Test Cases added for latencystats library. Signed-off-by: Naga Suresh Somarowthu Reviewed-by: Reshma Pattan --- MAINTAINERS | 1 + test/test/Makefile | 1 + test/test/autotest_data.py | 6 ++ test/test/meson.build | 3 + test/test/test_latencystats.c | 224 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 235 insertions(+) create mode 100644 test/test/test_latencystats.c diff --git a/MAINTAINERS b/MAINTAINERS index 4e55c97e1..886646fd1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1149,6 +1149,7 @@ F: test/test/test_bitratestats.c Latency statistics M: Reshma Pattan F: lib/librte_latencystats/ +F: test/test/test_latencystats.c BPF - EXPERIMENTAL M: Konstantin Ananyev 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 b253bf8f0..f44e31d33 100644 --- a/test/test/autotest_data.py +++ b/test/test/autotest_data.py @@ -488,6 +488,12 @@ "Func": default_autotest, "Report": None, }, + { + "Name": "Latencystats autotest", + "Command": "latencystats_autotest", + "Func": default_autotest, + "Report": None, + }, # #Please always keep all dump tests at the end and together! # diff --git a/test/test/meson.build b/test/test/meson.build index f9fab3109..d3385a3e2 100644 --- a/test/test/meson.build +++ b/test/test/meson.build @@ -47,6 +47,7 @@ test_sources = files('commands.c', 'test_interrupts.c', 'test_kni.c', 'test_kvargs.c', + 'test_latencystats.c', 'test_link_bonding.c', 'test_link_bonding_mode4.c', 'test_logs.c', @@ -112,6 +113,7 @@ test_deps = ['acl', 'eventdev', 'flow_classify', 'hash', + 'latencystats', 'lpm', 'member', 'metrics', @@ -170,6 +172,7 @@ test_names = [ 'interrupt_autotest', 'kni_autotest', 'kvargs_autotest', + 'latencystats_autotest', 'link_bonding_autotest', 'link_bonding_mode4_autotest', 'logs_autotest', diff --git a/test/test/test_latencystats.c b/test/test/test_latencystats.c new file mode 100644 index 000000000..039c508cd --- /dev/null +++ b/test/test/test_latencystats.c @@ -0,0 +1,224 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include +#include +#include + +#include +#include "rte_lcore.h" +#include "rte_metrics.h" + +#include "sample_packet_forward.h" +#include "test.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, i = 0; + int size = 0; + struct rte_metric_name names[NUM_STATS]; + struct rte_metric_name wrongnames[NUM_STATS - 2]; + + size_t m_size = sizeof(struct rte_metric_name); + for (i = 0; i < NUM_STATS; i++) + memset(&names[i], 0, m_size); + for (i = 0; i < NUM_STATS - 2; i++) + memset(&wrongnames[i], 0, m_size); + + /* Success Test: Valid names and size */ + size = NUM_STATS; + ret = rte_latencystats_get_names(names, size); + for (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, i = 0; + int size = 0; + struct rte_metric_value values[NUM_STATS]; + struct rte_metric_value wrongvalues[NUM_STATS - 2]; + + size_t v_size = sizeof(struct rte_metric_value); + for (i = 0; i < NUM_STATS; i++) + memset(&values[i], 0, v_size); + for (i = 0; i < NUM_STATS - 2; i++) + memset(&wrongvalues[i], 0, v_size); + + /* 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"); + + /* 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);