/* Copyright (c) 2001-2018 Dovecot authors, see the included COPYING file */
/* Unit tests for bit twiddles library */
#include "test-lib.h"
#include <stdio.h>
/* nearest_power(0) = error bits_requiredXX(0) = 0
nearest_power(1) = 1 = 1<<0 bits_requiredXX(1) = 1
nearest_power(2) = 2 = 1<<1 bits_requiredXX(2) = 2
nearest_power(3) = 4 = 1<<2 bits_requiredXX(3) = 2
nearest_power(4) = 4 = 1<<2 bits_requiredXX(4) = 3
nearest_power(5) = 8 = 1<<3 bits_requiredXX(5) = 3
nearest_power(7) = 8 = 1<<3 bits_requiredXX(7) = 3
nearest_power(8) = 8 = 1<<3 bits_requiredXX(8) = 4
*/
/* nearest_power(num) == 1ULL << bits_required64(num-1) */
static void test_nearest_power(void)
{
unsigned int b;
test_begin("nearest_power()");
/* b=2 tests 3,4,5; b=3 tests 7,8,9; ... b=30 tests ~1G */
}
/* With 32-bit size_t, now: b=31 tests 2G-1, 2G, not 2G+1. */
/* i_assert()s: test_assert_idx(nearest_power(num+1) == num<<1, b); */
test_end();
}
static void test_bits_is_power_of_two(void)
{
test_begin("bits_is_power_of_two()");
for (unsigned int i = 0; i < 64; i++)
for (unsigned int i = 2; i < 64; i++) {
}
test_end();
}
static void test_bits_requiredXX(void)
{
/* As ..64 depends on ..32 and tests it twice,
* and ..32 depends on ..16 and tests it twice,
* etc., we only test ..64
*/
unsigned int b;
test_begin("bits_requiredXX()");
test_assert(bits_required64(0) == 0);
for (b = 2; b < 64; ++b) {
/* b=2 tests 3,4,5; b=3 tests 7,8,9; ... */
}
test_end();
}
static void test_sum_overflows(void)
{
static const struct {
uint64_t a, b;
bool overflows;
} tests[] = {
};
unsigned int i;
test_begin("UINT64_SUM_OVERFLOWS");
for (i = 0; i < N_ELEMENTS(tests); i++)
test_end();
}
static void test_bits_fraclog(void)
{
unsigned int fracbits;
unsigned int i;
unsigned int last_end = ~0u;
for (i = 0; i < BITS_FRACLOG_BUCKETS(fracbits); i++) {
}
test_end();
}
}
/* The compiler *should* generate different code when the fracbits parameter
is a compile-time constant, so we also need to check that's the case.
*/
static void test_bits_fraclog_const(void)
{
#define STR2(s) #s
unsigned int i;
unsigned int last_end = ~0u;
for (i = 0; i < BITS_FRACLOG_BUCKETS(FRACBITS); i++) {
}
test_assert(last_end == ~0u);
test_end();
}
static void test_bits_rotl32(void)
{
test_begin("bits_rotl32");
test_end();
}
static void test_bits_rotl64(void)
{
test_begin("bits_rotl64");
test_end();
}
static void test_bits_rotr32(void)
{
test_begin("bits_rotr32");
test_end();
}
static void test_bits_rotr64(void)
{
test_begin("bits_rotr64");
test_end();
}
void test_bits(void)
{
}