summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJerin Jacob <jerin.jacob@caviumnetworks.com>2017-07-06 19:50:24 +0530
committerThomas Monjalon <thomas@monjalon.net>2017-07-10 16:49:11 +0200
commit05c4345ef5c2c39334d187738bce21c95c33aa82 (patch)
tree3717ed9a5e1643bec43a2dc8076ae58f7e513be0 /test
parentfcee050aa1d74b3e65ea349f401728ece7cbdc50 (diff)
downloaddpdk-05c4345ef5c2c39334d187738bce21c95c33aa82.zip
dpdk-05c4345ef5c2c39334d187738bce21c95c33aa82.tar.gz
dpdk-05c4345ef5c2c39334d187738bce21c95c33aa82.tar.xz
test: add unit test for integer log2 function
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>
Diffstat (limited to 'test')
-rw-r--r--test/test/test_common.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/test/test_common.c b/test/test/test_common.c
index 6e803f5..ae3482d 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;
}