Fix typo in 32bytes aligned malloc test
[blender.git] / tests / gtests / guardedalloc / guardedalloc_alignment_test.cc
1 /* Apache License, Version 2.0 */
2
3 #include "testing/testing.h"
4
5 #include "MEM_guardedalloc.h"
6
7 #define CHECK_ALIGNMENT(ptr, align) EXPECT_EQ(0, (size_t)ptr % align)
8
9 namespace {
10
11 void DoBasicAlignmentChecks(const int alignment)
12 {
13         int *foo, *bar;
14
15         foo = (int *) MEM_mallocN_aligned(sizeof(int) * 10, alignment, "test");
16         CHECK_ALIGNMENT(foo, alignment);
17
18         bar = (int *) MEM_dupallocN(foo);
19         CHECK_ALIGNMENT(bar, alignment);
20         MEM_freeN(bar);
21
22         foo = (int *) MEM_reallocN(foo, sizeof(int) * 5);
23         CHECK_ALIGNMENT(foo, alignment);
24
25         foo = (int *) MEM_recallocN(foo, sizeof(int) * 5);
26         CHECK_ALIGNMENT(foo, alignment);
27
28         MEM_freeN(foo);
29 }
30
31 }  // namespace
32
33 TEST(guardedalloc, LockfreeAlignedAlloc16)
34 {
35         DoBasicAlignmentChecks(16);
36 }
37
38 TEST(guardedalloc, GuardedAlignedAlloc16)
39 {
40         MEM_use_guarded_allocator();
41         DoBasicAlignmentChecks(16);
42 }
43
44 // On Apple we currently support 16 bit alignment only.
45 // Harmless for Blender, but would be nice to support
46 // eventually.
47 #ifndef __APPLE__
48 TEST(guardedalloc, GuardedAlignedAlloc32)
49 {
50         MEM_use_guarded_allocator();
51         DoBasicAlignmentChecks(32);
52 }
53 #endif