Welcome to mirror list, hosted at ThFree Co, Russian Federation.

guardedalloc_alignment_test.cc « guardedalloc « gtests « tests - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4c676c6cc765b8d61163e5c0ed8411210c7f09fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* Apache License, Version 2.0 */

#include "testing/testing.h"

#include "BLI_utildefines.h"

#include "MEM_guardedalloc.h"

#define CHECK_ALIGNMENT(ptr, align) EXPECT_EQ((size_t)ptr % align, 0)

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, LockfreeAlignedAlloc1)
{
  DoBasicAlignmentChecks(1);
}

TEST(guardedalloc, GuardedAlignedAlloc1)
{
  MEM_use_guarded_allocator();
  DoBasicAlignmentChecks(1);
}

TEST(guardedalloc, LockfreeAlignedAlloc2)
{
  DoBasicAlignmentChecks(2);
}

TEST(guardedalloc, GuardedAlignedAlloc2)
{
  MEM_use_guarded_allocator();
  DoBasicAlignmentChecks(2);
}

TEST(guardedalloc, LockfreeAlignedAlloc4)
{
  DoBasicAlignmentChecks(4);
}

TEST(guardedalloc, GuardedAlignedAlloc4)
{
  MEM_use_guarded_allocator();
  DoBasicAlignmentChecks(4);
}

TEST(guardedalloc, LockfreeAlignedAlloc8)
{
  DoBasicAlignmentChecks(8);
}

TEST(guardedalloc, GuardedAlignedAlloc8)
{
  MEM_use_guarded_allocator();
  DoBasicAlignmentChecks(8);
}

TEST(guardedalloc, LockfreeAlignedAlloc16)
{
  DoBasicAlignmentChecks(16);
}

TEST(guardedalloc, GuardedAlignedAlloc16)
{
  MEM_use_guarded_allocator();
  DoBasicAlignmentChecks(16);
}

TEST(guardedalloc, LockfreeAlignedAlloc32)
{
  DoBasicAlignmentChecks(32);
}

TEST(guardedalloc, GuardedAlignedAlloc32)
{
  MEM_use_guarded_allocator();
  DoBasicAlignmentChecks(32);
}

TEST(guardedalloc, LockfreeAlignedAlloc256)
{
  DoBasicAlignmentChecks(256);
}

TEST(guardedalloc, GuardedAlignedAlloc256)
{
  MEM_use_guarded_allocator();
  DoBasicAlignmentChecks(256);
}

TEST(guardedalloc, LockfreeAlignedAlloc512)
{
  DoBasicAlignmentChecks(512);
}

TEST(guardedalloc, GuardedAlignedAlloc512)
{
  MEM_use_guarded_allocator();
  DoBasicAlignmentChecks(512);
}