summaryrefslogtreecommitdiffstats
path: root/regressions/ck_ec/validate/prop_test_timeutil_scale.c
blob: eb3040fa02a5d24eb789b2b740678bf1781003a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <assert.h>

#include "../../../src/ck_ec_timeutil.h"
#include "fuzz_harness.h"

struct example {
	uint32_t nsec;
	uint32_t multiplier;
	unsigned int shift;
};

static const struct example examples[] = {
	{
		UINT32_MAX,
		UINT32_MAX,
		1
	},
	{
		10,
		20,
		0
	}
};

static inline int test_wait_time_scale(const struct example *example)
{
	const uint32_t nsec = example->nsec;
	const uint32_t multiplier = example->multiplier;
	const unsigned int shift = example->shift % 32;
	uint32_t actual = wait_time_scale(nsec, multiplier, shift);
	uint64_t expected = ((uint64_t)nsec * multiplier) >> shift;

	if (expected > UINT32_MAX) {
		expected = UINT32_MAX;
	}

	assert(actual == expected);
	return 0;
}

TEST(test_wait_time_scale, examples)