| 1 | #include "sync/tests/test_internal.h" |
|---|---|
| 2 | |
| 3 | TEST_GROUP_DECLARE(turnstile); |
| 4 | |
| 5 | TEST_DECLARE_UNIT(turnstile, hash_and_init) { |
| 6 | /* Fibonacci hashing mask invariant */ |
| 7 | uintptr_t dummy_locks[5] = {0x1000, 0x1020, 0x2000, 0x4000, 0x8000}; |
| 8 | for (size_t i = 0; i < 5; i++) { |
| 9 | size_t h = TURNSTILE_OBJECT_HASH((void *) dummy_locks[i]); |
| 10 | TEST_ASSERT_LT(h, TURNSTILE_HASH_SIZE); |
| 11 | } |
| 12 | |
| 13 | struct turnstile ts; |
| 14 | turnstile_init(ts: &ts); |
| 15 | TEST_ASSERT_EQ(ts.state, TURNSTILE_STATE_UNUSED); |
| 16 | TEST_ASSERT_EQ(ts.waiters, 0); |
| 17 | TEST_ASSERT_NULL(ts.owner); |
| 18 | TEST_ASSERT(list_empty(&ts.hash_list)); |
| 19 | TEST_ASSERT(list_empty(&ts.freelist)); |
| 20 | |
| 21 | return TEST_SUCCESS; |
| 22 | } |
| 23 |