From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id 2D9754C95 for ; Fri, 24 Aug 2018 14:51:43 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Aug 2018 05:51:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,281,1531810800"; d="scan'208";a="67568753" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga007.jf.intel.com with ESMTP; 24 Aug 2018 05:51:41 -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 w7OCpeCd031744; Fri, 24 Aug 2018 13:51:40 +0100 Received: from wgcvswdev001.ir.intel.com (localhost [127.0.0.1]) by wgcvswdev001.ir.intel.com with ESMTP id w7OCpXO4002537; Fri, 24 Aug 2018 13:51:33 +0100 Received: (from jmparthx@localhost) by wgcvswdev001.ir.intel.com with œ id w7OCpX1N002532; Fri, 24 Aug 2018 13:51:33 +0100 From: Naga Suresh Somarowthu To: dev@dpdk.org Cc: reshma.pattan@intel.com, Naga Suresh Somarowthu Date: Fri, 24 Aug 2018 13:51:25 +0100 Message-Id: <1535115087-2442-3-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 2/4] test: add unit tests for bitrate 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: Fri, 24 Aug 2018 12:51:44 -0000 Unit Test Cases for BitRate library. Signed-off-by: Naga Suresh Somarowthu Reviewed-by: Reshma Pattan Reviewed-by: Remy Horton --- MAINTAINERS | 1 + test/test/Makefile | 1 + test/test/autotest_data.py | 6 ++ test/test/meson.build | 4 + test/test/test_bitratestats.c | 226 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 238 insertions(+) create mode 100644 test/test/test_bitratestats.c diff --git a/MAINTAINERS b/MAINTAINERS index e2e0a27da..4e55c97e1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1144,6 +1144,7 @@ F: lib/librte_metrics/ Bit-rate statistics M: Remy Horton F: lib/librte_bitratestats/ +F: test/test/test_bitratestats.c Latency statistics M: Reshma Pattan diff --git a/test/test/Makefile b/test/test/Makefile index 9f7d398e4..c619877f0 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -183,6 +183,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_PMD_RING) += test_pmd_ring_perf.c 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 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 f68d9b111..b253bf8f0 100644 --- a/test/test/autotest_data.py +++ b/test/test/autotest_data.py @@ -482,6 +482,12 @@ "Func": default_autotest, "Report": None, }, + { + "Name": "Bitratestats autotest", + "Command": "bitratestats_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 2a7e7d074..f9fab3109 100644 --- a/test/test/meson.build +++ b/test/test/meson.build @@ -9,6 +9,7 @@ test_sources = files('commands.c', 'test_alarm.c', 'test_atomic.c', 'test_barrier.c', + 'test_bitratestats.c', 'test_bpf.c', 'test_byteorder.c', 'test_cmdline.c', @@ -100,6 +101,7 @@ test_sources = files('commands.c', ) test_deps = ['acl', + 'bitratestats', 'bpf', 'cfgfile', 'cmdline', @@ -112,6 +114,7 @@ test_deps = ['acl', 'hash', 'lpm', 'member', + 'metrics', 'pipeline', 'port', 'reorder', @@ -124,6 +127,7 @@ test_names = [ 'alarm_autotest', 'atomic_autotest', 'barrier_autotest', + 'bitratestats_autotest', 'byteorder_autotest', 'cmdline_autotest', 'common_autotest', diff --git a/test/test/test_bitratestats.c b/test/test/test_bitratestats.c new file mode 100644 index 000000000..32b1b0fc0 --- /dev/null +++ b/test/test/test_bitratestats.c @@ -0,0 +1,226 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "sample_packet_forward.h" +#include "test.h" + +#define BIT_NUM_PACKETS 10 +#define QUEUE_ID 0 + +uint16_t portid; +struct rte_stats_bitrates *bitrate_data; +struct rte_ring *ring; + +/* To test whether rte_stats_bitrate_create is successful */ +static int +test_stats_bitrate_create(void) +{ + bitrate_data = rte_stats_bitrate_create(); + TEST_ASSERT(bitrate_data != NULL, "rte_stats_bitrate_create failed"); + + return TEST_SUCCESS; +} + +/* To test bit rate registration */ +static int +test_stats_bitrate_reg(void) +{ + int ret = 0; + + /* Test to register bit rate without metrics init */ + ret = rte_stats_bitrate_reg(bitrate_data); + TEST_ASSERT(ret < 0, "Test Failed: rte_stats_bitrate_reg succeeded " + "without metrics init, ret:%d", ret); + + /* Metrics initialization */ + rte_metrics_init(rte_socket_id()); + /* Test to register bit rate after metrics init */ + ret = rte_stats_bitrate_reg(bitrate_data); + TEST_ASSERT((ret >= 0), "Test Failed: rte_stats_bitrate_reg %d", ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate registration with invalid pointer */ +static int +test_stats_bitrate_reg_invalidpointer(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_reg(NULL); + TEST_ASSERT(ret < 0, "Test Failed: Expected failure < 0 but " + "got %d", ret); + + return TEST_SUCCESS; +} + +/* To test bit rate calculation with invalid bit rate data pointer */ +static int +test_stats_bitrate_calc_invalid_bitrate_data(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(NULL, portid); + TEST_ASSERT(ret < 0, "Test Failed: rte_stats_bitrate_calc " + "ret:%d", ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate calculation with invalid portid + * (higher than max ports) + */ +static int +test_stats_bitrate_calc_invalid_portid_1(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(bitrate_data, 33); + TEST_ASSERT(ret == -EINVAL, "Test Failed: Expected -%d for higher " + "portid rte_stats_bitrate_calc ret:%d", EINVAL, ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate calculation with invalid portid (lesser than 0) */ +static int +test_stats_bitrate_calc_invalid_portid_2(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(bitrate_data, -1); + TEST_ASSERT(ret == -EINVAL, "Test Failed: Expected -%d for invalid " + "portid rte_stats_bitrate_calc ret:%d", EINVAL, ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate calculation with non-existing portid */ +static int +test_stats_bitrate_calc_non_existing_portid(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(bitrate_data, 31); + TEST_ASSERT(ret == -EINVAL, "Test Failed: Expected -%d for " + "non-existing portid rte_stats_bitrate_calc ret:%d", + EINVAL, ret); + + return TEST_SUCCESS; +} + +/* To test the bit rate calculation with valid bit rate data, valid portid */ +static int +test_stats_bitrate_calc(void) +{ + int ret = 0; + + ret = rte_stats_bitrate_calc(bitrate_data, portid); + TEST_ASSERT(ret >= 0, "Test Failed: Expected >=0 for valid portid " + "rte_stats_bitrate_calc ret:%d", ret); + + return TEST_SUCCESS; +} + +static int +test_bit_packet_forward(void) +{ + int ret; + struct rte_mbuf *pbuf[BIT_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 int +test_bit_ring_setup(void) +{ + test_ring_setup(&ring, &portid); + printf("port in ring setup : %d\n", portid); + + return TEST_SUCCESS; +} + +static void +test_bit_ring_free(void) +{ + test_ring_free(ring); + test_vdev_uninit("net_ring_net_ringa"); + rte_memzone_free(rte_memzone_lookup("RTE_METRICS")); +} + +static struct +unit_test_suite bitratestats_testsuite = { + .suite_name = "BitRate Stats Unit Test Suite", + .setup = test_bit_ring_setup, + .teardown = test_bit_ring_free, + .unit_test_cases = { + /* TEST CASE 1: Test to create bit rate data */ + TEST_CASE(test_stats_bitrate_create), + + /* TEST CASE 2: Test to register bit rate metrics + * without metrics init and after metrics init + */ + TEST_CASE(test_stats_bitrate_reg), + + /* TEST CASE 3: Test to register bit rate metrics + * with invalid bit rate data + */ + TEST_CASE(test_stats_bitrate_reg_invalidpointer), + + /* TEST CASE 4: Test to calculate bit rate data metrics + * with invalid bit rate data + */ + TEST_CASE(test_stats_bitrate_calc_invalid_bitrate_data), + + /* TEST CASE 5: Test to calculate bit rate data metrics + * with portid exceeding the max ports + */ + TEST_CASE(test_stats_bitrate_calc_invalid_portid_1), + + /* TEST CASE 6: Test to calculate bit rate data metrics + * with portid less than 0 + */ + TEST_CASE(test_stats_bitrate_calc_invalid_portid_2), + + /* TEST CASE 7: Test to calculate bit rate data metrics + * with non-existing portid + */ + TEST_CASE(test_stats_bitrate_calc_non_existing_portid), + + /* TEST CASE 8: Test to calculate bit rate data metrics + * with valid portid, valid bit rate data + */ + TEST_CASE_ST(test_bit_packet_forward, NULL, + test_stats_bitrate_calc), + TEST_CASES_END() + } +}; + +static int +test_bitratestats(void) +{ + return unit_test_suite_runner(&bitratestats_testsuite); +} +REGISTER_TEST_COMMAND(bitratestats_autotest, test_bitratestats); -- 2.13.6