DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: olivier.matz@6wind.com, jerin.jacob@caviumnetworks.com,
	Bruce Richardson <bruce.richardson@intel.com>
Subject: [dpdk-dev] [PATCH v2 2/5] test/test: add unit tests for exact size rings
Date: Fri, 30 Jun 2017 16:06:18 +0100	[thread overview]
Message-ID: <20170630150621.156365-3-bruce.richardson@intel.com> (raw)
In-Reply-To: <20170630150621.156365-1-bruce.richardson@intel.com>

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>

---
V2: tear down allocated rings on error
---
 test/test/test_ring.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/test/test/test_ring.c b/test/test/test_ring.c
index 858ebc1da..d68654eb8 100644
--- a/test/test/test_ring.c
+++ b/test/test/test_ring.c
@@ -770,6 +770,77 @@ test_ring_basic_ex(void)
 }
 
 static int
+test_ring_with_exact_size(void)
+{
+	struct rte_ring *std_ring = NULL, *exact_sz_ring = NULL;
+	void *ptr_array[16];
+	static const unsigned int ring_sz = RTE_DIM(ptr_array);
+	unsigned int i;
+	int ret = -1;
+
+	std_ring = rte_ring_create("std", ring_sz, rte_socket_id(),
+			RING_F_SP_ENQ | RING_F_SC_DEQ);
+	if (std_ring == NULL) {
+		printf("%s: error, can't create std ring\n", __func__);
+		goto end;
+	}
+	exact_sz_ring = rte_ring_create("exact sz", ring_sz, rte_socket_id(),
+			RING_F_SP_ENQ | RING_F_SC_DEQ | RING_F_EXACT_SZ);
+	if (exact_sz_ring == NULL) {
+		printf("%s: error, can't create exact size ring\n", __func__);
+		goto end;
+	}
+
+	/*
+	 * Check that the exact size ring is bigger than the standard ring
+	 */
+	if (rte_ring_get_size(std_ring) >= rte_ring_get_size(exact_sz_ring)) {
+		printf("%s: error, std ring (size: %u) is not smaller than exact size one (size %u)\n",
+				__func__,
+				rte_ring_get_size(std_ring),
+				rte_ring_get_size(exact_sz_ring));
+		goto end;
+	}
+	/*
+	 * check that the exact_sz_ring can hold one more element than the
+	 * standard ring. (16 vs 15 elements)
+	 */
+	for (i = 0; i < ring_sz - 1; i++) {
+		rte_ring_enqueue(std_ring, NULL);
+		rte_ring_enqueue(exact_sz_ring, NULL);
+	}
+	if (rte_ring_enqueue(std_ring, NULL) != -ENOBUFS) {
+		printf("%s: error, unexpected successful enqueue\n", __func__);
+		goto end;
+	}
+	if (rte_ring_enqueue(exact_sz_ring, NULL) == -ENOBUFS) {
+		printf("%s: error, enqueue failed\n", __func__);
+		goto end;
+	}
+
+	/* check that dequeue returns the expected number of elements */
+	if (rte_ring_dequeue_burst(exact_sz_ring, ptr_array,
+			RTE_DIM(ptr_array), NULL) != ring_sz) {
+		printf("%s: error, failed to dequeue expected nb of elements\n",
+				__func__);
+		goto end;
+	}
+
+	/* check that the capacity function returns expected value */
+	if (rte_ring_get_capacity(exact_sz_ring) != ring_sz) {
+		printf("%s: error, incorrect ring capacity reported\n",
+				__func__);
+		goto end;
+	}
+
+	ret = 0; /* all ok if we get here */
+end:
+	rte_ring_free(std_ring);
+	rte_ring_free(exact_sz_ring);
+	return ret;
+}
+
+static int
 test_ring(void)
 {
 	/* some more basic operations */
@@ -820,6 +891,9 @@ test_ring(void)
 	if (test_ring_creation_with_an_used_name() < 0)
 		return -1;
 
+	if (test_ring_with_exact_size() < 0)
+		return -1;
+
 	/* dump the ring status */
 	rte_ring_list_dump(stdout);
 
-- 
2.13.0

  parent reply	other threads:[~2017-06-30 15:06 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-07 13:36 [dpdk-dev] [PATCH 0/5] create event rings type Bruce Richardson
2017-06-07 13:36 ` [dpdk-dev] [PATCH 1/5] ring: allow rings with non power-of-2 sizes Bruce Richardson
2017-06-30  9:40   ` Olivier Matz
2017-06-30 11:32     ` Bruce Richardson
2017-06-30 12:24       ` Olivier Matz
2017-06-30 13:59         ` Bruce Richardson
2017-06-07 13:36 ` [dpdk-dev] [PATCH 2/5] test/test: add unit tests for exact size rings Bruce Richardson
2017-06-30  9:42   ` Olivier Matz
2017-06-07 13:36 ` [dpdk-dev] [PATCH 3/5] eventdev: add ring structure for events Bruce Richardson
2017-06-12  5:15   ` Jerin Jacob
2017-06-12  8:53     ` Bruce Richardson
2017-06-30 13:24     ` Bruce Richardson
2017-06-07 13:36 ` [dpdk-dev] [PATCH 4/5] test/test: add auto-tests for event ring functions Bruce Richardson
2017-06-07 13:36 ` [dpdk-dev] [PATCH 5/5] event/sw: change worker rings to standard event rings Bruce Richardson
2017-06-30 15:06 ` [dpdk-dev] [PATCH v2 0/5] create event rings type Bruce Richardson
2017-06-30 15:06   ` [dpdk-dev] [PATCH v2 1/5] ring: allow rings with non power-of-2 sizes Bruce Richardson
2017-07-03  8:46     ` Olivier Matz
2017-06-30 15:06   ` Bruce Richardson [this message]
2017-07-03  8:47     ` [dpdk-dev] [PATCH v2 2/5] test/test: add unit tests for exact size rings Olivier Matz
2017-06-30 15:06   ` [dpdk-dev] [PATCH v2 3/5] eventdev: add ring structure for events Bruce Richardson
2017-07-03  9:52     ` Van Haaren, Harry
2017-06-30 15:06   ` [dpdk-dev] [PATCH v2 4/5] test/test: add auto-tests for event ring functions Bruce Richardson
2017-07-03 12:30     ` Van Haaren, Harry
2017-06-30 15:06   ` [dpdk-dev] [PATCH v2 5/5] event/sw: change worker rings to standard event rings Bruce Richardson
2017-07-03 12:28     ` Van Haaren, Harry
2017-07-03 12:44       ` Jerin Jacob
2017-07-03 13:01         ` Van Haaren, Harry
2017-07-04  5:36           ` Jerin Jacob

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=20170630150621.156365-3-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=jerin.jacob@caviumnetworks.com \
    --cc=olivier.matz@6wind.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).