summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/allocator_test.c9
-rw-r--r--test/failing_allocator.c24
2 files changed, 33 insertions, 0 deletions
diff --git a/test/allocator_test.c b/test/allocator_test.c
index a6087e1..5275ce8 100644
--- a/test/allocator_test.c
+++ b/test/allocator_test.c
@@ -6,6 +6,7 @@
#include "zix/allocator.h"
#include <assert.h>
+#include <stdint.h>
static void
test_allocator(void)
@@ -40,6 +41,14 @@ test_allocator(void)
assert(realloced[6] == 6);
assert(realloced[7] == 7);
+ char* const aligned = (char*)zix_aligned_alloc(allocator, 4096, 4096);
+ assert((uintptr_t)aligned % 4096 == 0);
+ aligned[0] = 0;
+ aligned[3] = 3;
+ assert(aligned[0] == 0);
+ assert(aligned[3] == 3);
+
+ zix_aligned_free(allocator, aligned);
zix_free(allocator, realloced);
zix_free(allocator, malloced);
}
diff --git a/test/failing_allocator.c b/test/failing_allocator.c
index eda762b..684a8ec 100644
--- a/test/failing_allocator.c
+++ b/test/failing_allocator.c
@@ -66,6 +66,28 @@ zix_failing_free(ZixAllocator* const allocator, void* const ptr)
base->free(base, ptr);
}
+ZIX_MALLOC_FUNC
+static void*
+zix_failing_aligned_alloc(ZixAllocator* const allocator,
+ const size_t alignment,
+ const size_t size)
+{
+ ZixFailingAllocator* const state = (ZixFailingAllocator*)allocator;
+ ZixAllocator* const base = zix_default_allocator();
+
+ return attempt(state) ? base->aligned_alloc(base, alignment, size) : NULL;
+}
+
+static void
+zix_failing_aligned_free(ZixAllocator* const allocator, void* const ptr)
+{
+ (void)allocator;
+
+ ZixAllocator* const base = zix_default_allocator();
+
+ base->aligned_free(base, ptr);
+}
+
ZIX_CONST_FUNC
ZixFailingAllocator
zix_failing_allocator(void)
@@ -76,6 +98,8 @@ zix_failing_allocator(void)
zix_failing_calloc,
zix_failing_realloc,
zix_failing_free,
+ zix_failing_aligned_alloc,
+ zix_failing_aligned_free,
},
0,
SIZE_MAX,