We recently started to get random failures on the common_autotest ut with
clang on Ubuntu 16.04.6.
Example: https://travis-ci.com/DPDK/dpdk/jobs/
263177424
Wrong rte_log2_u64(0) val 0, expected
ffffffff
Test Failed
The ut passes 0 to log2() to get an expected value.
Quoting log2 / log(3) manual:
If x is zero, then a pole error occurs, and the functions return
-HUGE_VAL, -HUGE_VALF, or -HUGE_VALL, respectively.
rte_log2_uXX helpers handle 0 as a special value and return 0.
Let's have dedicated tests for this case.
Fixes:
05c4345ef5c2 ("test: add unit test for integer log2 function")
Cc: stable@dpdk.org
Signed-off-by: David Marchand <david.marchand@redhat.com>
Acked-by: Aaron Conole <aconole@redhat.com>
const uint32_t max = 0x10000;
const uint32_t step = 1;
- for (i = 0; i < max; i = i + step) {
+ compare = rte_log2_u32(0);
+ if (compare != 0) {
+ printf("Wrong rte_log2_u32(0) val %x, expected 0\n", compare);
+ return TEST_FAILED;
+ }
+
+ compare = rte_log2_u64(0);
+ if (compare != 0) {
+ printf("Wrong rte_log2_u64(0) val %x, expected 0\n", compare);
+ return TEST_FAILED;
+ }
+
+ for (i = 1; i < max; i = i + step) {
uint64_t i64;
/* extend range for 64-bit */
/**
* Return the rounded-up log2 of a integer.
*
+ * @note Contrary to the logarithm mathematical operation,
+ * rte_log2_u32(0) == 0 and not -inf.
+ *
* @param v
* The input parameter.
* @return
/**
* Return the rounded-up log2 of a 64-bit integer.
*
+ * @note Contrary to the logarithm mathematical operation,
+ * rte_log2_u64(0) == 0 and not -inf.
+ *
* @param v
* The input parameter.
* @return