From patchwork Fri Jul 6 17:21:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jananee Parthasarathy X-Patchwork-Id: 42553 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 E5CC01BF9A; Fri, 6 Jul 2018 19:21:56 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 82CDD1BF38 for ; Fri, 6 Jul 2018 19:21:46 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jul 2018 10:21:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,317,1526367600"; d="scan'208";a="72787342" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga002.jf.intel.com with ESMTP; 06 Jul 2018 10:21:38 -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 w66HLc2t001258; Fri, 6 Jul 2018 18:21:38 +0100 Received: from wgcvswdev001.ir.intel.com (localhost [127.0.0.1]) by wgcvswdev001.ir.intel.com with ESMTP id w66HLbwG022822; Fri, 6 Jul 2018 18:21:37 +0100 Received: (from jmparthx@localhost) by wgcvswdev001.ir.intel.com with ? id w66HLb0H022818; Fri, 6 Jul 2018 18:21:37 +0100 From: Jananee Parthasarathy To: dev@dpdk.org Cc: remy.horton@intel.com, reshma.pattan@intel.com, Jananee Parthasarathy , Chaitanya Babu Talluri Date: Fri, 6 Jul 2018 18:21:28 +0100 Message-Id: <1530897688-22716-1-git-send-email-jananeex.m.parthasarathy@intel.com> X-Mailer: git-send-email 1.7.12.2 Subject: [dpdk-dev] [PATCH] 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Jananee Parthasarathy Unit Test Cases for BitRate library. Signed-off-by: Chaitanya Babu Talluri Reviewed-by: Reshma Pattan --- test/test/Makefile | 1 + test/test/autotest_data.py | 6 ++ test/test/test_bitratestats.c | 187 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 194 insertions(+) create mode 100644 test/test/test_bitratestats.c diff --git a/test/test/Makefile b/test/test/Makefile index eccc8efcf..039b6ac6d 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -179,6 +179,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_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 aacfe0a66..419520342 100644 --- a/test/test/autotest_data.py +++ b/test/test/autotest_data.py @@ -293,6 +293,12 @@ def per_sockets(num): "Tests": [ { + "Name": "Bitratestats autotest", + "Command": "bitratestats_autotest", + "Func": default_autotest, + "Report": None, + }, + { "Name": "PMD ring autotest", "Command": "ring_pmd_autotest", "Func": default_autotest, diff --git a/test/test/test_bitratestats.c b/test/test/test_bitratestats.c new file mode 100644 index 000000000..8014475af --- /dev/null +++ b/test/test/test_bitratestats.c @@ -0,0 +1,187 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "test.h" +#include "sample_packet_forward.h" + +extern int tx_portid, rx_portid; +struct rte_stats_bitrates *bitrate_data; + +/* 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, tx_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, tx_portid); + TEST_ASSERT(ret >= 0, "Test Failed: Expected >=0 for valid portid " + "rte_stats_bitrate_calc ret:%d", ret); + + return TEST_SUCCESS; +} + +static struct +unit_test_suite bitratestats_testsuite = { + .suite_name = "BitRate Stats Unit Test Suite", + .setup = test_ring_setup, + .teardown = NULL, + .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_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);