| 1 |
#include <assert.h> |
| 2 |
#include <ck_ec.h> |
| 3 |
|
| 4 |
#include "fuzz_harness.h" |
| 5 |
|
| 6 |
static int gettime(const struct ck_ec_ops *, struct timespec *out); |
| 7 |
static void wake32(const struct ck_ec_ops *, const uint32_t *); |
| 8 |
static void wait32(const struct ck_ec_wait_state *, const uint32_t *, |
| 9 |
uint32_t, const struct timespec *); |
| 10 |
static void wake64(const struct ck_ec_ops *, const uint64_t *); |
| 11 |
static void wait64(const struct ck_ec_wait_state *, const uint64_t *, |
| 12 |
uint64_t, const struct timespec *); |
| 13 |
|
| 14 |
static const struct ck_ec_ops test_ops = { |
| 15 |
.gettime = gettime, |
| 16 |
.wait32 = wait32, |
| 17 |
.wait64 = wait64, |
| 18 |
.wake32 = wake32, |
| 19 |
.wake64 = wake64 |
| 20 |
}; |
| 21 |
|
| 22 |
static int gettime(const struct ck_ec_ops *ops, struct timespec *out) |
| 23 |
{ |
| 24 |
(void)out; |
| 25 |
|
| 26 |
assert(ops == &test_ops); |
| 27 |
return -1; |
| 28 |
} |
| 29 |
|
| 30 |
static void wait32(const struct ck_ec_wait_state *wait_state, |
| 31 |
const uint32_t *addr, uint32_t expected, |
| 32 |
const struct timespec *deadline) |
| 33 |
{ |
| 34 |
(void)addr; |
| 35 |
(void)expected; |
| 36 |
(void)deadline; |
| 37 |
|
| 38 |
assert(wait_state->ops == &test_ops); |
| 39 |
return; |
| 40 |
} |
| 41 |
|
| 42 |
static void wait64(const struct ck_ec_wait_state *wait_state, |
| 43 |
const uint64_t *addr, uint64_t expected, |
| 44 |
const struct timespec *deadline) |
| 45 |
{ |
| 46 |
(void)addr; |
| 47 |
(void)expected; |
| 48 |
(void)deadline; |
| 49 |
|
| 50 |
assert(wait_state->ops == &test_ops); |
| 51 |
return; |
| 52 |
} |
| 53 |
|
| 54 |
static void wake32(const struct ck_ec_ops *ops, const uint32_t *addr) |
| 55 |
{ |
| 56 |
(void)addr; |
| 57 |
|
| 58 |
assert(ops == &test_ops); |
| 59 |
return; |
| 60 |
} |
| 61 |
|
| 62 |
static void wake64(const struct ck_ec_ops *ops, const uint64_t *addr) |
| 63 |
{ |
| 64 |
(void)addr; |
| 65 |
|
| 66 |
assert(ops == &test_ops); |
| 67 |
return; |
| 68 |
} |
| 69 |
|
| 70 |
/* |
| 71 |
* Check that calling ck_ec{32,64}_wake always clears the waiting bit. |
| 72 |
*/ |
| 73 |
|
| 74 |
struct example { |
| 75 |
uint64_t value; |
| 76 |
}; |
| 77 |
|
| 78 |
const struct example examples[] = { |
| 79 |
{ 0 }, |
| 80 |
{ 1 }, |
| 81 |
{ 1UL << 30 }, |
| 82 |
{ 1UL << 31 }, |
| 83 |
{ INT32_MAX }, |
| 84 |
{ INT64_MAX }, |
| 85 |
{ 1ULL << 62 }, |
| 86 |
{ 1ULL << 63 }, |
| 87 |
}; |
| 88 |
|
| 89 |
static inline int test_slow_wakeup(const struct example *example) |
| 90 |
{ |
| 91 |
{ |
| 92 |
struct ck_ec32 ec = { .counter = example->value }; |
| 93 |
|
| 94 |
ck_ec32_wake(&ec, &test_ops); |
| 95 |
assert(!ck_ec32_has_waiters(&ec)); |
| 96 |
} |
| 97 |
|
| 98 |
#ifdef CK_F_EC64 |
| 99 |
{ |
| 100 |
struct ck_ec64 ec = { .counter = example->value }; |
| 101 |
|
| 102 |
ck_ec64_wake(&ec, &test_ops); |
| 103 |
assert(!ck_ec64_has_waiters(&ec)); |
| 104 |
} |
| 105 |
#endif /* CK_F_EC64 */ |
| 106 |
|
| 107 |
return 0; |
| 108 |
} |
| 109 |
|
| 110 |
TEST(test_slow_wakeup, examples) |