| 1 |
#include <assert.h> |
| 2 |
|
| 3 |
#include "../../../src/ck_ec_timeutil.h" |
| 4 |
#include "fuzz_harness.h" |
| 5 |
|
| 6 |
struct example { |
| 7 |
uint32_t nsec; |
| 8 |
uint32_t multiplier; |
| 9 |
unsigned int shift; |
| 10 |
}; |
| 11 |
|
| 12 |
static const struct example examples[] = { |
| 13 |
{ |
| 14 |
UINT32_MAX, |
| 15 |
UINT32_MAX, |
| 16 |
1 |
| 17 |
}, |
| 18 |
{ |
| 19 |
10, |
| 20 |
20, |
| 21 |
0 |
| 22 |
} |
| 23 |
}; |
| 24 |
|
| 25 |
static inline int test_wait_time_scale(const struct example *example) |
| 26 |
{ |
| 27 |
const uint32_t nsec = example->nsec; |
| 28 |
const uint32_t multiplier = example->multiplier; |
| 29 |
const unsigned int shift = example->shift % 32; |
| 30 |
uint32_t actual = wait_time_scale(nsec, multiplier, shift); |
| 31 |
uint64_t expected = ((uint64_t)nsec * multiplier) >> shift; |
| 32 |
|
| 33 |
if (expected > UINT32_MAX) { |
| 34 |
expected = UINT32_MAX; |
| 35 |
} |
| 36 |
|
| 37 |
assert(actual == expected); |
| 38 |
return 0; |
| 39 |
} |
| 40 |
|
| 41 |
TEST(test_wait_time_scale, examples) |