DPDK patches and discussions
 help / color / mirror / Atom feed
From: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com>
To: dev@dpdk.org
Cc: remy.horton@intel.com, reshma.pattan@intel.com,
	Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com>
Subject: [dpdk-dev] [PATCH v11 2/6] test: add unit tests for bitrate library
Date: Fri,  3 Aug 2018 13:05:49 +0100	[thread overview]
Message-ID: <1533297953-9149-3-git-send-email-naga.sureshx.somarowthu@intel.com> (raw)
In-Reply-To: <1533297953-9149-1-git-send-email-naga.sureshx.somarowthu@intel.com>

Unit Test Cases for BitRate library.

Signed-off-by: Naga Suresh Somarowthu <naga.sureshx.somarowthu@intel.com>
Reviewed-by: Reshma Pattan <reshma.pattan@intel.com>
Reviewed-by: Remy Horton <remy.horton@intel.com>
---
 test/test/Makefile            |   1 +
 test/test/test_bitratestats.c | 229 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 230 insertions(+)
 create mode 100644 test/test/test_bitratestats.c

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/test_bitratestats.c b/test/test/test_bitratestats.c
new file mode 100644
index 000000000..38f7da4b5
--- /dev/null
+++ b/test/test/test_bitratestats.c
@@ -0,0 +1,229 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+
+#include <rte_log.h>
+#include <rte_lcore.h>
+#include <rte_mbuf.h>
+#include <rte_memzone.h>
+#include <rte_malloc.h>
+#include <rte_common.h>
+#include <rte_metrics.h>
+#include <rte_bitrate.h>
+
+#include "test.h"
+#include "sample_packet_forward.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

  parent reply	other threads:[~2018-08-03 12:06 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-31 22:18 [dpdk-dev] [PATCH v10 0/5] add unit tests for bitrate, latency and pdump libraries Reshma Pattan
2018-07-31 22:18 ` [dpdk-dev] [PATCH v10 1/5] test: add helper functions for tests using ring-PMD Rx/Tx Reshma Pattan
2018-07-31 22:18 ` [dpdk-dev] [PATCH v10 2/5] test: add unit tests for bitrate library Reshma Pattan
2018-07-31 22:18 ` [dpdk-dev] [PATCH v10 3/5] test: add unit tests for latencystats library Reshma Pattan
2018-07-31 22:18 ` [dpdk-dev] [PATCH v10 4/5] test: add unit test for pdump library Reshma Pattan
2018-07-31 22:18 ` [dpdk-dev] [PATCH v10 5/5] autotest: add new unit tests to autotest list Reshma Pattan
2018-07-31 22:30 ` [dpdk-dev] [PATCH v10 0/5] add unit tests for bitrate, latency and pdump libraries Thomas Monjalon
2018-08-01  7:52 ` Thomas Monjalon
2018-08-03 13:45   ` Pattan, Reshma
2018-08-03 14:11     ` Thomas Monjalon
2018-08-03 14:16     ` Parthasarathy, JananeeX M
2018-08-03 15:01       ` Thomas Monjalon
2018-08-03 12:05 ` [dpdk-dev] [PATCH v11 0/6] " Naga Suresh Somarowthu
2018-08-03 12:05   ` [dpdk-dev] [PATCH v11 1/6] test: add helper functions for tests using ring-PMD Rx/Tx Naga Suresh Somarowthu
2018-08-03 12:05   ` Naga Suresh Somarowthu [this message]
2018-08-03 12:05   ` [dpdk-dev] [PATCH v11 3/6] test: add unit tests for latencystats library Naga Suresh Somarowthu
2018-08-03 12:05   ` [dpdk-dev] [PATCH v11 4/6] test: add unit test for pdump library Naga Suresh Somarowthu
2018-08-03 12:05   ` [dpdk-dev] [PATCH v11 5/6] autotest: add new unit tests to autotest list Naga Suresh Somarowthu
2018-08-03 12:05   ` [dpdk-dev] [PATCH v11 6/6] maintainers: add bitrate latency pdump tests Naga Suresh Somarowthu
2018-08-03 12:34   ` [dpdk-dev] [PATCH v12 0/6] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu
2018-08-03 12:34     ` [dpdk-dev] [PATCH v12 1/6] test: add helper functions for tests using ring-PMD Rx/Tx Naga Suresh Somarowthu
2018-08-03 12:34     ` [dpdk-dev] [PATCH v12 2/6] test: add unit tests for bitrate library Naga Suresh Somarowthu
2018-08-03 12:34     ` [dpdk-dev] [PATCH v12 3/6] test: add unit tests for latencystats library Naga Suresh Somarowthu
2018-08-03 12:34     ` [dpdk-dev] [PATCH v12 4/6] test: add unit test for pdump library Naga Suresh Somarowthu
2018-08-03 12:34     ` [dpdk-dev] [PATCH v12 5/6] autotest: add new unit tests to autotest list Naga Suresh Somarowthu
2018-08-03 12:34     ` [dpdk-dev] [PATCH v12 6/6] maintainers: add bitrate latency pdump tests Naga Suresh Somarowthu
2018-08-24 12:51     ` [dpdk-dev] [PATCH v13 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu
2018-08-24 12:51       ` [dpdk-dev] [PATCH v13 1/4] test: add helper functions for tests using ring-PMD Rx/Tx Naga Suresh Somarowthu
2018-08-24 12:51       ` [dpdk-dev] [PATCH v13 2/4] test: add unit tests for bitrate library Naga Suresh Somarowthu
2018-08-24 12:51       ` [dpdk-dev] [PATCH v13 3/4] test: add unit tests for latencystats library Naga Suresh Somarowthu
2018-08-24 12:51       ` [dpdk-dev] [PATCH v13 4/4] test: add unit test for pdump library Naga Suresh Somarowthu
2018-08-07  8:46   ` [dpdk-dev] [PATCH v11 0/6] add unit tests for bitrate, latency and pdump libraries Burakov, Anatoly

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1533297953-9149-3-git-send-email-naga.sureshx.somarowthu@intel.com \
    --to=naga.sureshx.somarowthu@intel.com \
    --cc=dev@dpdk.org \
    --cc=remy.horton@intel.com \
    --cc=reshma.pattan@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).