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>
This commit is contained in:
parent
fcee050aa1
commit
05c4345ef5
@ -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>
|
||||
@ -159,6 +160,25 @@ test_align(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@ -166,6 +186,7 @@ test_common(void)
|
||||
ret |= test_align();
|
||||
ret |= test_macros(0);
|
||||
ret |= test_misc();
|
||||
ret |= test_log2();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user