MCPcopy Create free account
hub / github.com/F-Stack/f-stack / test_log2

Function test_log2

dpdk/app/test/test_common.c:242–289  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

240}
241
242static int
243test_log2(void)
244{
245 uint32_t i, base, compare;
246 const uint32_t max = 0x10000;
247 const uint32_t step = 1;
248
249 compare = rte_log2_u32(0);
250 if (compare != 0) {
251 printf("Wrong rte_log2_u32(0) val %x, expected 0\n", compare);
252 return TEST_FAILED;
253 }
254
255 compare = rte_log2_u64(0);
256 if (compare != 0) {
257 printf("Wrong rte_log2_u64(0) val %x, expected 0\n", compare);
258 return TEST_FAILED;
259 }
260
261 for (i = 1; i < max; i = i + step) {
262 uint64_t i64;
263
264 /* extend range for 64-bit */
265 i64 = (uint64_t)i << 32;
266 base = (uint32_t)ceilf(log2(i64));
267 compare = rte_log2_u64(i64);
268 if (base != compare) {
269 printf("Wrong rte_log2_u64(%" PRIx64 ") val %x, expected %x\n",
270 i64, compare, base);
271 return TEST_FAILED;
272 }
273
274 base = (uint32_t)ceilf(log2((uint32_t)i));
275 compare = rte_log2_u32((uint32_t)i);
276 if (base != compare) {
277 printf("Wrong rte_log2_u32(%x) val %x, expected %x\n",
278 i, compare, base);
279 return TEST_FAILED;
280 }
281 compare = rte_log2_u64((uint64_t)i);
282 if (base != compare) {
283 printf("Wrong rte_log2_u64(%x) val %x, expected %x\n",
284 i, compare, base);
285 return TEST_FAILED;
286 }
287 }
288 return 0;
289}
290
291static int
292test_fls(void)

Callers 1

test_commonFunction · 0.85

Calls 4

log2Function · 0.85
rte_log2_u32Function · 0.50
printfFunction · 0.50
rte_log2_u64Function · 0.50

Tested by

no test coverage detected