DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jerin Jacob <jerin.jacob@caviumnetworks.com>
To: dev@dpdk.org
Cc: thomas@monjalon.net, ferruh.yigit@intel.com,
	olivier.matz@6wind.com,
	Jerin Jacob <jerin.jacob@caviumnetworks.com>
Subject: [dpdk-dev]  [PATCH 1/2] test: add unit test case for rte log2
Date: Thu,  6 Jul 2017 19:50:24 +0530	[thread overview]
Message-ID: <20170706142025.24034-1-jerin.jacob@caviumnetworks.com> (raw)

add a unit testcase for rte_log2_u32.

Signed-off-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
---
 test/test/test_common.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/test/test/test_common.c b/test/test/test_common.c
index 6e803f5d3..ae3482da7 100644
--- a/test/test/test_common.c
+++ b/test/test/test_common.c
@@ -33,6 +33,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <math.h>
 #include <rte_common.h>
 #include <rte_hexdump.h>
 #include <rte_pause.h>
@@ -160,12 +161,32 @@ test_align(void)
 }
 
 static int
+test_log2(void)
+{
+	uint32_t i, base, compare;
+	const uint32_t max = 0x10000;
+	const uint32_t step = 1;
+
+	for (i = 0; i < max; i = i + step) {
+		base = (uint32_t)ceilf(log2((uint32_t)i));
+		compare = rte_log2_u32(i);
+		if (base != compare) {
+			printf("Wrong rte_log2_u32(%x) val %x, expected %x\n",
+				i, compare, base);
+			return TEST_FAILED;
+		}
+	}
+	return 0;
+}
+
+static int
 test_common(void)
 {
 	int ret = 0;
 	ret |= test_align();
 	ret |= test_macros(0);
 	ret |= test_misc();
+	ret |= test_log2();
 
 	return ret;
 }
-- 
2.13.2

             reply	other threads:[~2017-07-06 14:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-06 14:20 Jerin Jacob [this message]
2017-07-06 14:20 ` [dpdk-dev] [PATCH 2/2] net/thunderx: remove libm dependency Jerin Jacob
2017-07-10 12:29   ` Olivier Matz
2017-07-10 12:29 ` [dpdk-dev] [PATCH 1/2] test: add unit test case for rte log2 Olivier Matz
2017-07-10 14:56   ` Thomas Monjalon

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=20170706142025.24034-1-jerin.jacob@caviumnetworks.com \
    --to=jerin.jacob@caviumnetworks.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=olivier.matz@6wind.com \
    --cc=thomas@monjalon.net \
    /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).