Skip to content

Commit 69ab584

Browse files
committed
Add allocFreeAligned test to poolFixtures.hpp
Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 23759db commit 69ab584

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test/poolFixtures.hpp

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

153+
TEST_P(umfPoolTest, allocFreeAligned) {
154+
#ifdef _WIN32
155+
// TODO: implement support for windows
156+
GTEST_SKIP();
157+
#else
158+
if (!umf_test::isAlignedAllocSupported(pool.get())) {
159+
GTEST_SKIP();
160+
}
161+
162+
size_t alignment = 4 * 1024; // 4kB
163+
void *ptr = umfPoolAlignedMalloc(pool.get(), 1, alignment);
164+
ASSERT_NE(ptr, nullptr);
165+
ASSERT_TRUE(reinterpret_cast<uintptr_t>(ptr) % alignment == 0);
166+
*(reinterpret_cast<unsigned char *>(ptr)) = (unsigned char)0xFF;
167+
168+
umf_result_t umf_result = umfPoolFree(pool.get(), ptr);
169+
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
170+
#endif
171+
}
172+
153173
TEST_P(umfPoolTest, reallocFree) {
154174
if (!umf_test::isReallocSupported(pool.get())) {
155175
GTEST_SKIP();
@@ -203,6 +223,24 @@ void pow2AlignedAllocHelper(umf_memory_pool_handle_t pool) {
203223
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
204224
}
205225
}
226+
227+
// the same for size = 1
228+
for (size_t alignment = 1; alignment <= maxAlignment; alignment <<= 1) {
229+
std::vector<void *> allocs;
230+
231+
for (size_t alloc = 0; alloc < numAllocs; alloc++) {
232+
auto *ptr = umfPoolAlignedMalloc(pool, 1, alignment);
233+
ASSERT_NE(ptr, nullptr);
234+
ASSERT_TRUE(reinterpret_cast<uintptr_t>(ptr) % alignment == 0);
235+
*(reinterpret_cast<unsigned char *>(ptr)) = (unsigned char)0xFF;
236+
allocs.push_back(ptr);
237+
}
238+
239+
for (auto &ptr : allocs) {
240+
umf_result_t umf_result = umfPoolFree(pool, ptr);
241+
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
242+
}
243+
}
206244
}
207245

208246
TEST_P(umfPoolTest, pow2AlignedAlloc) {

0 commit comments

Comments
 (0)