Skip to content

Commit 9ce2e8d

Browse files
ldoraulukaszstolarczuk
authored andcommitted
Add allocFreeAligned test to poolFixtures.hpp
Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
1 parent 2880017 commit 9ce2e8d

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

test/poolFixtures.hpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,28 @@ TEST_P(umfPoolTest, allocFreeNonAlignedSizes) {
150150
}
151151
}
152152

153+
TEST_P(umfPoolTest, allocFreeAligned) {
154+
// ::aligned_alloc(alignment=4096, size=1) does not work under sanitizers for unknown reason
155+
#if defined(_WIN32) || defined(__SANITIZE_ADDRESS__) || \
156+
defined(__SANITIZE_THREAD__)
157+
// TODO: implement support for windows
158+
GTEST_SKIP();
159+
#else
160+
if (!umf_test::isAlignedAllocSupported(pool.get())) {
161+
GTEST_SKIP();
162+
}
163+
164+
size_t alignment = 4 * 1024; // 4kB
165+
void *ptr = umfPoolAlignedMalloc(pool.get(), 1, alignment);
166+
ASSERT_NE(ptr, nullptr);
167+
ASSERT_TRUE(reinterpret_cast<uintptr_t>(ptr) % alignment == 0);
168+
*(reinterpret_cast<unsigned char *>(ptr)) = (unsigned char)0xFF;
169+
170+
umf_result_t umf_result = umfPoolFree(pool.get(), ptr);
171+
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
172+
#endif
173+
}
174+
153175
TEST_P(umfPoolTest, reallocFree) {
154176
if (!umf_test::isReallocSupported(pool.get())) {
155177
GTEST_SKIP();
@@ -203,6 +225,27 @@ void pow2AlignedAllocHelper(umf_memory_pool_handle_t pool) {
203225
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
204226
}
205227
}
228+
229+
// ::aligned_alloc(alignment=4096, size=1) does not work under sanitizers for unknown reason
230+
#if !defined(__SANITIZE_ADDRESS__) && !defined(__SANITIZE_THREAD__)
231+
// the same for size = 1
232+
for (size_t alignment = 1; alignment <= maxAlignment; alignment <<= 1) {
233+
std::vector<void *> allocs;
234+
235+
for (size_t alloc = 0; alloc < numAllocs; alloc++) {
236+
auto *ptr = umfPoolAlignedMalloc(pool, 1, alignment);
237+
ASSERT_NE(ptr, nullptr);
238+
ASSERT_TRUE(reinterpret_cast<uintptr_t>(ptr) % alignment == 0);
239+
*(reinterpret_cast<unsigned char *>(ptr)) = (unsigned char)0xFF;
240+
allocs.push_back(ptr);
241+
}
242+
243+
for (auto &ptr : allocs) {
244+
umf_result_t umf_result = umfPoolFree(pool, ptr);
245+
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
246+
}
247+
}
248+
#endif
206249
}
207250

208251
TEST_P(umfPoolTest, pow2AlignedAlloc) {

0 commit comments

Comments
 (0)