summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/.clang-tidy2
-rw-r--r--test/allocator_test.c6
-rw-r--r--test/bitset_test.c2
-rw-r--r--test/btree_test.c52
-rw-r--r--test/digest_test.c32
-rw-r--r--test/hash_test.c36
-rw-r--r--test/ring_test.c12
-rw-r--r--test/test_data.h12
-rw-r--r--test/tree_test.c4
9 files changed, 78 insertions, 80 deletions
diff --git a/test/.clang-tidy b/test/.clang-tidy
index 0924b8f..ac418d7 100644
--- a/test/.clang-tidy
+++ b/test/.clang-tidy
@@ -4,7 +4,6 @@
Checks: >
*,
-*-magic-numbers,
- -*-uppercase-literal-suffix,
-altera-*,
-android-cloexec-fopen,
-bugprone-easily-swappable-parameters,
@@ -12,7 +11,6 @@ Checks: >
-cppcoreguidelines-avoid-non-const-global-variables,
-google-readability-casting,
-hicpp-multiway-paths-covered,
- -hicpp-uppercase-literal-suffix,
-llvm-header-guard,
-llvmlibc-*,
-misc-no-recursion,
diff --git a/test/allocator_test.c b/test/allocator_test.c
index b4aec16..e146de6 100644
--- a/test/allocator_test.c
+++ b/test/allocator_test.c
@@ -65,14 +65,14 @@ test_bump_allocator(void)
char* const malloced = (char*)zix_malloc(&allocator.base, 3);
assert(malloced >= buffer);
assert(malloced <= buffer + sizeof(buffer));
- assert((uintptr_t)malloced % sizeof(uintmax_t) == 0u);
+ assert((uintptr_t)malloced % sizeof(uintmax_t) == 0U);
assert(!zix_calloc(&allocator.base, 1017, 1));
char* const calloced = (char*)zix_calloc(&allocator.base, 4, 1);
assert(calloced > malloced);
assert(calloced <= buffer + sizeof(buffer));
- assert((uintptr_t)calloced % sizeof(uintmax_t) == 0u);
+ assert((uintptr_t)calloced % sizeof(uintmax_t) == 0U);
assert(!calloced[0]);
assert(!calloced[1]);
assert(!calloced[2]);
@@ -104,7 +104,7 @@ test_bump_allocator(void)
assert(aligned);
assert(aligned >= reclaimed);
assert(aligned <= buffer + sizeof(buffer));
- assert((uintptr_t)aligned % 128 == 0u);
+ assert((uintptr_t)aligned % 128 == 0U);
zix_aligned_free(&allocator.base, aligned);
zix_free(&allocator.base, reclaimed); // Correct, but a noop
diff --git a/test/bitset_test.c b/test/bitset_test.c
index ef61eeb..ef0528f 100644
--- a/test/bitset_test.c
+++ b/test/bitset_test.c
@@ -7,7 +7,7 @@
#include <assert.h>
-#define N_BITS 256u
+#define N_BITS 256U
#define N_ELEMS (ZIX_BITSET_ELEMS(N_BITS))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
diff --git a/test/btree_test.c b/test/btree_test.c
index 150a29d..878eef9 100644
--- a/test/btree_test.c
+++ b/test/btree_test.c
@@ -27,8 +27,8 @@ int_cmp(const void* a, const void* b, const void* ZIX_UNUSED(user_data))
const uintptr_t ia = (uintptr_t)a;
const uintptr_t ib = (uintptr_t)b;
- assert(ia != 0u); // No wildcards
- assert(ib != 0u); // No wildcards
+ assert(ia != 0U); // No wildcards
+ assert(ib != 0U); // No wildcards
return ia < ib ? -1 : ia > ib ? 1 : 0;
}
@@ -42,7 +42,7 @@ ith_elem(const unsigned test_num, const size_t n_elems, const size_t i)
case 1:
return n_elems - i; // Decreasing
default:
- return 1u + unique_rand(i); // Pseudo-random
+ return 1U + unique_rand(i); // Pseudo-random
}
}
@@ -103,7 +103,7 @@ test_fail(ZixBTree* t, const char* fmt, ...)
return EXIT_FAILURE;
}
-static const size_t n_clear_insertions = 1024u;
+static const size_t n_clear_insertions = 1024U;
static void
destroy(void* const ptr, const void* const user_data)
@@ -125,8 +125,8 @@ test_clear(void)
{
ZixBTree* t = zix_btree_new(NULL, int_cmp, NULL);
- for (uintptr_t r = 0u; r < n_clear_insertions; ++r) {
- assert(!zix_btree_insert(t, (void*)(r + 1u)));
+ for (uintptr_t r = 0U; r < n_clear_insertions; ++r) {
+ assert(!zix_btree_insert(t, (void*)(r + 1U)));
}
zix_btree_clear(t, destroy, NULL);
@@ -140,8 +140,8 @@ test_free(void)
{
ZixBTree* t = zix_btree_new(NULL, int_cmp, NULL);
- for (uintptr_t r = 0u; r < n_clear_insertions; ++r) {
- assert(!zix_btree_insert(t, (void*)(r + 1u)));
+ for (uintptr_t r = 0U; r < n_clear_insertions; ++r) {
+ assert(!zix_btree_insert(t, (void*)(r + 1U)));
}
assert(zix_btree_size(t) == n_clear_insertions);
@@ -152,12 +152,12 @@ test_free(void)
static void
test_iter_comparison(void)
{
- static const size_t n_elems = 4096u;
+ static const size_t n_elems = 4096U;
ZixBTree* const t = zix_btree_new(NULL, int_cmp, NULL);
// Store increasing numbers from 1 (jammed into the pointers themselves)
- for (uintptr_t r = 1u; r < n_elems; ++r) {
+ for (uintptr_t r = 1U; r < n_elems; ++r) {
assert(!zix_btree_insert(t, (void*)r));
}
@@ -174,7 +174,7 @@ test_iter_comparison(void)
assert(zix_btree_iter_equals(begin, j));
// Advance it and check that they are no longer equal
- for (size_t r = 1u; r < n_elems - 1u; ++r) {
+ for (size_t r = 1U; r < n_elems - 1U; ++r) {
j = zix_btree_iter_next(j);
assert(!zix_btree_iter_is_end(j));
assert(!zix_btree_iter_equals(begin, j));
@@ -195,13 +195,13 @@ test_iter_comparison(void)
static void
test_insert_split_value(void)
{
- static const size_t n_insertions = 767u; // Number of insertions to split
- static const uintptr_t split_value = 512u; // Value that will be pulled up
+ static const size_t n_insertions = 767U; // Number of insertions to split
+ static const uintptr_t split_value = 512U; // Value that will be pulled up
ZixBTree* const t = zix_btree_new(NULL, int_cmp, NULL);
// Insert right up until it would cause a split
- for (uintptr_t r = 1u; r < n_insertions; ++r) {
+ for (uintptr_t r = 1U; r < n_insertions; ++r) {
assert(!zix_btree_insert(t, (void*)r));
}
@@ -218,16 +218,16 @@ test_remove_cases(void)
even multiples. This spreads the load around to hit as many cases as
possible. */
- static const uintptr_t s1 = 2u;
- static const uintptr_t s2 = 255u;
- const size_t n_insertions = s1 * s2 * 1000u;
+ static const uintptr_t s1 = 2U;
+ static const uintptr_t s2 = 255U;
+ const size_t n_insertions = s1 * s2 * 1000U;
ZixBTree* const t = zix_btree_new(NULL, int_cmp, NULL);
// Insert in s1-sized chunks
- for (uintptr_t phase = 0u; phase < s1; ++phase) {
- for (uintptr_t r = 0u; r < n_insertions / s1; ++r) {
- const uintptr_t value = (s1 * r) + phase + 1u;
+ for (uintptr_t phase = 0U; phase < s1; ++phase) {
+ for (uintptr_t r = 0U; r < n_insertions / s1; ++r) {
+ const uintptr_t value = (s1 * r) + phase + 1U;
assert(!zix_btree_insert(t, (void*)value));
}
@@ -235,9 +235,9 @@ test_remove_cases(void)
// Remove in s2-sized chunks
ZixBTreeIter next = zix_btree_end(t);
- for (uintptr_t phase = 0u; phase < s2; ++phase) {
- for (uintptr_t r = 0u; r < n_insertions / s2; ++r) {
- const uintptr_t value = (s2 * r) + phase + 1u;
+ for (uintptr_t phase = 0U; phase < s2; ++phase) {
+ for (uintptr_t r = 0U; r < n_insertions / s2; ++r) {
+ const uintptr_t value = (s2 * r) + phase + 1U;
void* out = NULL;
assert(!zix_btree_remove(t, (void*)value, &out, &next));
@@ -604,7 +604,7 @@ test_failed_alloc(void)
// Test that each allocation failing is handled gracefully
const size_t n_new_allocs = allocator.n_allocations;
- for (size_t i = 0u; i < n_new_allocs; ++i) {
+ for (size_t i = 0U; i < n_new_allocs; ++i) {
allocator.n_remaining = i;
assert(stress(&allocator.base, 0, 4096));
}
@@ -625,8 +625,8 @@ main(int argc, char** argv)
test_remove_cases();
test_failed_alloc();
- const unsigned n_tests = 3u;
- const size_t n_elems = (argc > 1) ? strtoul(argv[1], NULL, 10) : 131072u;
+ const unsigned n_tests = 3U;
+ const size_t n_elems = (argc > 1) ? strtoul(argv[1], NULL, 10) : 131072U;
printf("Running %u tests with %" PRIuPTR " elements", n_tests, n_elems);
for (unsigned i = 0; i < n_tests; ++i) {
diff --git a/test/digest_test.c b/test/digest_test.c
index 59d28b3..c1a16a8 100644
--- a/test/digest_test.c
+++ b/test/digest_test.c
@@ -16,12 +16,12 @@ test_digest(void)
static const uint8_t data[] = {
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
- size_t last = 0u;
+ size_t last = 0U;
for (size_t offset = 0; offset < 7; ++offset) {
- const size_t len = 8u - offset;
+ const size_t len = 8U - offset;
for (size_t i = offset; i < 8; ++i) {
- const size_t h = zix_digest(0u, &data[i], len);
+ const size_t h = zix_digest(0U, &data[i], len);
assert(h != last);
last = h;
}
@@ -33,11 +33,11 @@ test_digest32(void)
{
static const uint8_t data[] = {1, 2, 3, 4, 5, 6, 7, 8};
- uint32_t last = 0u;
+ uint32_t last = 0U;
for (size_t offset = 0; offset < 3; ++offset) {
for (size_t i = offset; i < 4; ++i) {
- const uint32_t h = zix_digest32(0u, &data[i], 4);
+ const uint32_t h = zix_digest32(0U, &data[i], 4);
assert(h != last);
last = h;
}
@@ -50,11 +50,11 @@ test_digest64(void)
static const uint8_t data[] = {
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
- uint64_t last = 0u;
+ uint64_t last = 0U;
for (size_t offset = 0; offset < 7; ++offset) {
for (size_t i = offset; i < 8; ++i) {
- const uint64_t h = zix_digest64(0u, &data[i], 8);
+ const uint64_t h = zix_digest64(0U, &data[i], 8);
assert(h != last);
last = h;
}
@@ -66,13 +66,13 @@ test_digest32_aligned(void)
{
static const uint32_t data[] = {1, 2, 3, 4, 5, 6, 7, 8};
- uint32_t last = 0u;
+ uint32_t last = 0U;
for (size_t offset = 0; offset < 3; ++offset) {
- const size_t len = 4u - offset;
+ const size_t len = 4U - offset;
for (size_t i = offset; i < 4; ++i) {
const uint32_t h =
- zix_digest32_aligned(0u, &data[i], len * sizeof(uint32_t));
+ zix_digest32_aligned(0U, &data[i], len * sizeof(uint32_t));
assert(h != last);
last = h;
}
@@ -84,13 +84,13 @@ test_digest64_aligned(void)
{
static const uint64_t data[] = {1, 2, 3, 4, 5, 6, 7, 8};
- uint64_t last = 0u;
+ uint64_t last = 0U;
for (size_t offset = 0; offset < 3; ++offset) {
- const size_t len = 4u - offset;
+ const size_t len = 4U - offset;
for (size_t i = offset; i < 4; ++i) {
const uint64_t h =
- zix_digest64_aligned(0u, &data[i], len * sizeof(uint64_t));
+ zix_digest64_aligned(0U, &data[i], len * sizeof(uint64_t));
assert(h != last);
last = h;
}
@@ -102,12 +102,12 @@ test_digest_aligned(void)
{
static const size_t data[] = {1, 2, 3, 4, 5, 6, 7, 8};
- size_t last = 0u;
+ size_t last = 0U;
for (size_t offset = 0; offset < 3; ++offset) {
- const size_t len = 4u - offset;
+ const size_t len = 4U - offset;
for (size_t i = offset; i < 4; ++i) {
- const size_t h = zix_digest_aligned(0u, &data[i], len * sizeof(size_t));
+ const size_t h = zix_digest_aligned(0U, &data[i], len * sizeof(size_t));
assert(h != last);
last = h;
}
diff --git a/test/hash_test.c b/test/hash_test.c
index 9dbcadd..287dbaa 100644
--- a/test/hash_test.c
+++ b/test/hash_test.c
@@ -59,15 +59,15 @@ identity(const char* record)
ZIX_PURE_FUNC static size_t
decent_string_hash(const char* const str)
{
- return zix_digest(0u, str, strlen(str));
+ return zix_digest(0U, str, strlen(str));
}
/// Terrible hash function from K&R first edition
ZIX_PURE_FUNC static size_t
terrible_string_hash(const char* str)
{
- size_t hash = 0u;
- uint8_t c = 0u;
+ size_t hash = 0U;
+ uint8_t c = 0U;
while ((c = (uint8_t)*str++)) {
hash += c;
@@ -82,19 +82,19 @@ string_hash_aligned(const char* const str)
size_t length = strlen(str);
length = (length + (sizeof(size_t) - 1)) / sizeof(size_t) * sizeof(size_t);
- return zix_digest_aligned(0u, str, length);
+ return zix_digest_aligned(0U, str, length);
}
ZIX_PURE_FUNC static size_t
string_hash32(const char* const str)
{
- return (size_t)zix_digest32(0u, str, strlen(str));
+ return (size_t)zix_digest32(0U, str, strlen(str));
}
ZIX_PURE_FUNC static size_t
string_hash64(const char* const str)
{
- return (size_t)zix_digest64(0u, str, strlen(str));
+ return (size_t)zix_digest64(0U, str, strlen(str));
}
ZIX_PURE_FUNC static size_t
@@ -102,8 +102,8 @@ string_hash32_aligned(const char* const str)
{
size_t length = strlen(str);
- length = (length + 3u) / 4u * 4u;
- return (size_t)zix_digest32_aligned(0u, str, length);
+ length = (length + 3U) / 4U * 4U;
+ return (size_t)zix_digest32_aligned(0U, str, length);
}
#if UINTPTR_MAX >= UINT64_MAX
@@ -113,8 +113,8 @@ string_hash64_aligned(const char* const str)
{
size_t length = strlen(str);
- length = (length + 7u) / 8u * 8u;
- return (size_t)zix_digest64_aligned(0u, str, length);
+ length = (length + 7U) / 8U * 8U;
+ return (size_t)zix_digest64_aligned(0U, str, length);
}
#endif
@@ -143,13 +143,13 @@ stress_with(ZixAllocator* const allocator,
return test_fail(hash, buffer, strings, "Failed to allocate strings\n");
}
- uint32_t seed = 1u;
- for (size_t i = 0u; i < n_elems; ++i) {
+ uint32_t seed = 1U;
+ for (size_t i = 0U; i < n_elems; ++i) {
strings[i] = buffer + i * (string_length + 1);
assert((uintptr_t)strings[i] % sizeof(size_t) == 0);
assert((uintptr_t)strings[i] % sizeof(uint32_t) == 0);
- for (size_t j = 0u; j < string_length; ++j) {
+ for (size_t j = 0U; j < string_length; ++j) {
seed = lcg32(seed);
strings[i][j] = (char)('!' + (seed % 92));
}
@@ -285,7 +285,7 @@ stress_with(ZixAllocator* const allocator,
}
// Check key == value (and test zix_hash_foreach)
- size_t n_checked = 0u;
+ size_t n_checked = 0U;
for (ZixHashIter i = zix_hash_begin(hash); i != zix_hash_end(hash);
i = zix_hash_next(hash, i)) {
const char* const string = (const char*)zix_hash_get(hash, i);
@@ -366,7 +366,7 @@ test_all_tombstones(void)
zix_hash_new(NULL, identity, identity_index_hash, string_equal);
// Insert each element then immediately remove it
- for (unsigned i = 0u; i < N_STRINGS; ++i) {
+ for (unsigned i = 0U; i < N_STRINGS; ++i) {
const char* removed = NULL;
assert(!zix_hash_insert(hash, original_strings[i]));
@@ -377,7 +377,7 @@ test_all_tombstones(void)
assert(zix_hash_size(hash) == 0);
// Insert clashing elements which should hit the "all tombstones" case
- for (unsigned i = 0u; i < N_STRINGS; ++i) {
+ for (unsigned i = 0U; i < N_STRINGS; ++i) {
assert(!zix_hash_insert(hash, collision_strings[i]));
assert(!st);
}
@@ -397,7 +397,7 @@ test_failed_alloc(void)
// Test that each allocation failing is handled gracefully
const size_t n_new_allocs = allocator.n_allocations;
- for (size_t i = 0u; i < n_new_allocs; ++i) {
+ for (size_t i = 0U; i < n_new_allocs; ++i) {
allocator.n_remaining = i;
assert(stress(&allocator.base, 16));
}
@@ -411,7 +411,7 @@ main(void)
test_all_tombstones();
test_failed_alloc();
- static const size_t n_elems = 1024u;
+ static const size_t n_elems = 1024U;
if (stress(NULL, n_elems)) {
return 1;
diff --git a/test/ring_test.c b/test/ring_test.c
index af54e0e..79aa0f1 100644
--- a/test/ring_test.c
+++ b/test/ring_test.c
@@ -16,7 +16,7 @@
#include <stdio.h>
#include <stdlib.h>
-#define MSG_SIZE 20u
+#define MSG_SIZE 20U
static ZixRing* ring = 0;
static unsigned n_writes = 0;
@@ -25,7 +25,7 @@ static bool read_error = false;
static int
gen_msg(int* const msg, int start)
{
- for (unsigned i = 0u; i < MSG_SIZE; ++i) {
+ for (unsigned i = 0U; i < MSG_SIZE; ++i) {
msg[i] = start;
start = (start + 1) % INT_MAX;
}
@@ -36,7 +36,7 @@ ZIX_PURE_FUNC
static int
cmp_msg(const int* const msg1, const int* const msg2)
{
- for (unsigned i = 0u; i < MSG_SIZE; ++i) {
+ for (unsigned i = 0U; i < MSG_SIZE; ++i) {
assert(msg1[i] == msg2[i]);
}
@@ -103,10 +103,10 @@ test_ring(const unsigned size)
zix_ring_mlock(ring);
ZixThread reader_thread; // NOLINT
- assert(!zix_thread_create(&reader_thread, MSG_SIZE * 4ul, reader, NULL));
+ assert(!zix_thread_create(&reader_thread, MSG_SIZE * 4UL, reader, NULL));
ZixThread writer_thread; // NOLINT
- assert(!zix_thread_create(&writer_thread, MSG_SIZE * 4ul, writer, NULL));
+ assert(!zix_thread_create(&writer_thread, MSG_SIZE * 4UL, writer, NULL));
zix_thread_join(reader_thread, NULL);
zix_thread_join(writer_thread, NULL);
@@ -168,7 +168,7 @@ test_failed_alloc(void)
// Test that each allocation failing is handled gracefully
const size_t n_new_allocs = allocator.n_allocations;
- for (size_t i = 0u; i < n_new_allocs; ++i) {
+ for (size_t i = 0U; i < n_new_allocs; ++i) {
allocator.n_remaining = i;
assert(!zix_ring_new(&allocator.base, 512));
}
diff --git a/test/test_data.h b/test/test_data.h
index c5eaace..603a6c2 100644
--- a/test/test_data.h
+++ b/test/test_data.h
@@ -11,8 +11,8 @@
static inline uint32_t
lcg32(const uint32_t i)
{
- static const uint32_t a = 134775813u;
- static const uint32_t c = 1u;
+ static const uint32_t a = 134775813U;
+ static const uint32_t c = 1U;
return (a * i) + c;
}
@@ -21,8 +21,8 @@ lcg32(const uint32_t i)
static inline uint64_t
lcg64(const uint64_t i)
{
- static const uint64_t a = 6364136223846793005ull;
- static const uint64_t c = 1ull;
+ static const uint64_t a = 6364136223846793005ULL;
+ static const uint64_t c = 1ULL;
return (a * i) + c;
}
@@ -42,10 +42,10 @@ lcg(const uintptr_t i)
static inline size_t
unique_rand(size_t i)
{
- i ^= 0x5CA1AB1Eu; // Juggle bits to avoid linear clumps
+ i ^= 0x5CA1AB1EU; // Juggle bits to avoid linear clumps
// Largest prime < 2^32 which satisfies (2^32 = 3 mod 4)
- static const size_t prime = 4294967291u;
+ static const size_t prime = 4294967291U;
if (i >= prime) {
return i; // Values >= prime are mapped to themselves
}
diff --git a/test/tree_test.c b/test/tree_test.c
index a68437c..7c7fcf4 100644
--- a/test/tree_test.c
+++ b/test/tree_test.c
@@ -34,7 +34,7 @@ ith_elem(unsigned test_num, size_t n_elems, size_t i)
return n_elems - i; // Decreasing (worse case)
case 2:
default:
- return lcg(seed + i) % 100u; // Random
+ return lcg(seed + i) % 100U; // Random
}
}
@@ -47,7 +47,7 @@ test_fail(void)
static int
stress(unsigned test_num, size_t n_elems)
{
- uintptr_t r = 0u;
+ uintptr_t r = 0U;
ZixTreeIter* ti = NULL;
ZixTree* t = zix_tree_new(NULL, true, int_cmp, NULL, NULL, NULL);