diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-06-19 10:45:00 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-06-19 10:45:00 +0400 |
commit | 16d64a99b42171f201496a33f987fb687e3dabb1 (patch) | |
tree | c6d17ac55f3fb2f8423066ecea531b9ee52800ed /tests/gtests/guardedalloc/guardedalloc_alignment_test.cc | |
parent | 89ee6e08087dedd543da569a2ae0a4d64c43f368 (diff) |
Add unit tests for aligned alloc
This was really handy on initial work of aligned alloc
and would be handy as well when we'll need to support
arbitrary alignment on Apple platforms.
Diffstat (limited to 'tests/gtests/guardedalloc/guardedalloc_alignment_test.cc')
-rw-r--r-- | tests/gtests/guardedalloc/guardedalloc_alignment_test.cc | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/gtests/guardedalloc/guardedalloc_alignment_test.cc b/tests/gtests/guardedalloc/guardedalloc_alignment_test.cc new file mode 100644 index 00000000000..34c47738276 --- /dev/null +++ b/tests/gtests/guardedalloc/guardedalloc_alignment_test.cc @@ -0,0 +1,47 @@ +#include "testing/testing.h" + +#include "MEM_guardedalloc.h" + +#define CHECK_ALIGNMENT(ptr, align) EXPECT_EQ(0, (size_t)ptr % align) + +namespace { + +void DoBasicAlignmentChecks(const int alignment) { + int *foo, *bar; + + foo = (int *) MEM_mallocN_aligned(sizeof(int) * 10, alignment, "test"); + CHECK_ALIGNMENT(foo, alignment); + + bar = (int *) MEM_dupallocN(foo); + CHECK_ALIGNMENT(bar, alignment); + MEM_freeN(bar); + + foo = (int *) MEM_reallocN(foo, sizeof(int) * 5); + CHECK_ALIGNMENT(foo, alignment); + + foo = (int *) MEM_recallocN(foo, sizeof(int) * 5); + CHECK_ALIGNMENT(foo, alignment); + + MEM_freeN(foo); +} + +} // namespace + +TEST(guardedalloc, LockfreeAlignedAlloc16) { + DoBasicAlignmentChecks(16); +} + +TEST(guardedalloc, GuardedAlignedAlloc16) { + MEM_use_guarded_allocator(); + DoBasicAlignmentChecks(16); +} + +// On Apple we currently support 16 bit alignment only. +// Harmless for Blender, but would be nice to support +// eventually. +#ifndef __APPLE__ +TEST(guardedalloc, GuardedAlignedAlloc32) { + MEM_use_guarded_allocator(); + DoBasicAlignmentChecks(16); +} +#endif |