[dpdk-dev,1/2] test: add unit test case for rte log2

Message ID 20170706142025.24034-1-jerin.jacob@caviumnetworks.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Jerin Jacob July 6, 2017, 2:20 p.m. UTC
  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(+)
  

Comments

Olivier Matz July 10, 2017, 12:29 p.m. UTC | #1
On Thu,  6 Jul 2017 19:50:24 +0530, Jerin Jacob <jerin.jacob@caviumnetworks.com> wrote:
> add a unit testcase for rte_log2_u32.
> 
> Signed-off-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>

Reviewed-by: Olivier Matz <olivier.matz@6wind.com>
  
Thomas Monjalon July 10, 2017, 2:56 p.m. UTC | #2
10/07/2017 14:29, Olivier Matz:
> On Thu,  6 Jul 2017 19:50:24 +0530, Jerin Jacob <jerin.jacob@caviumnetworks.com> wrote:
> > add a unit testcase for rte_log2_u32.
> > 
> > Signed-off-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
> 
> Reviewed-by: Olivier Matz <olivier.matz@6wind.com>

Series applied, thanks
  

Patch

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;
 }