1#include "mem/slab/tests/test_internal.h"
2
3#define ASSERT_ALIGNED(ptr, alignment) \
4 TEST_ASSERT_EQ(((uintptr_t) (ptr) & ((alignment) - 1)), 0)
5
6#define KMALLOC_ALIGNMENT_TEST(name, align) \
7 TEST_DECLARE_SMOKE(slab, aligned_alloc##name##_test, \
8 TEST_INTENSITY(32, 512, 2048)) { \
9 ABORT_IF_RAM_LOW(); \
10 size_t alloc_times = ctx->intensity_val ? ctx->intensity_val : 512; \
11 for (uint64_t i = 0; i < alloc_times; i++) { \
12 void *ptr = kmalloc_aligned(align, align); \
13 TEST_ASSERT_NONNULL(ptr); \
14 ASSERT_ALIGNED(ptr, align); \
15 kfree_aligned(ptr); \
16 } \
17 return TEST_SUCCESS; \
18 }
19
20KMALLOC_ALIGNMENT_TEST(32, 32)
21KMALLOC_ALIGNMENT_TEST(64, 64)
22KMALLOC_ALIGNMENT_TEST(128, 128)
23KMALLOC_ALIGNMENT_TEST(256, 256)
24