@@ -136,18 +136,42 @@ TEST_P(umfPoolTest, allocFree) {
136136 auto *ptr = umfPoolMalloc (pool.get (), allocSize);
137137 ASSERT_NE (ptr, nullptr );
138138 std::memset (ptr, 0 , allocSize);
139- umfPoolFree (pool.get (), ptr);
139+ umf_result_t umf_result = umfPoolFree (pool.get (), ptr);
140+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
140141}
141142
142143TEST_P (umfPoolTest, allocFreeNonAlignedSizes) {
143144 for (const auto &allocSize : nonAlignedAllocSizes) {
144145 auto *ptr = umfPoolMalloc (pool.get (), allocSize);
145146 ASSERT_NE (ptr, nullptr );
146147 std::memset (ptr, 0 , allocSize);
147- umfPoolFree (pool.get (), ptr);
148+ umf_result_t umf_result = umfPoolFree (pool.get (), ptr);
149+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
148150 }
149151}
150152
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+
151175TEST_P (umfPoolTest, reallocFree) {
152176 if (!umf_test::isReallocSupported (pool.get ())) {
153177 GTEST_SKIP ();
@@ -160,7 +184,8 @@ TEST_P(umfPoolTest, reallocFree) {
160184 auto *new_ptr = umfPoolRealloc (pool.get (), ptr, allocSize * multiplier);
161185 ASSERT_NE (new_ptr, nullptr );
162186 std::memset (new_ptr, 0 , allocSize * multiplier);
163- umfPoolFree (pool.get (), new_ptr);
187+ umf_result_t umf_result = umfPoolFree (pool.get (), new_ptr);
188+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
164189}
165190
166191TEST_P (umfPoolTest, callocFree) {
@@ -174,7 +199,8 @@ TEST_P(umfPoolTest, callocFree) {
174199 for (size_t i = 0 ; i < num; ++i) {
175200 ASSERT_EQ (((int *)ptr)[i], 0 );
176201 }
177- umfPoolFree (pool.get (), ptr);
202+ umf_result_t umf_result = umfPoolFree (pool.get (), ptr);
203+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
178204}
179205
180206void pow2AlignedAllocHelper (umf_memory_pool_handle_t pool) {
@@ -195,9 +221,31 @@ void pow2AlignedAllocHelper(umf_memory_pool_handle_t pool) {
195221 }
196222
197223 for (auto &ptr : allocs) {
198- umfPoolFree (pool, ptr);
224+ umf_result_t umf_result = umfPoolFree (pool, ptr);
225+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
199226 }
200227 }
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
201249}
202250
203251TEST_P (umfPoolTest, pow2AlignedAlloc) {
@@ -227,7 +275,8 @@ TEST_P(umfPoolTest, multiThreadedMallocFree) {
227275 }
228276
229277 for (auto allocation : allocations) {
230- umfPoolFree (inPool, allocation);
278+ umf_result_t umf_result = umfPoolFree (inPool, allocation);
279+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
231280 }
232281 };
233282
@@ -280,7 +329,8 @@ TEST_P(umfPoolTest, multiThreadedReallocFree) {
280329 for (auto allocation : allocations) {
281330 auto *ptr =
282331 umfPoolRealloc (inPool, allocation, allocSize * multiplier);
283- umfPoolFree (inPool, ptr);
332+ umf_result_t umf_result = umfPoolFree (inPool, ptr);
333+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
284334 }
285335 };
286336
@@ -310,7 +360,8 @@ TEST_P(umfPoolTest, multiThreadedCallocFree) {
310360 }
311361
312362 for (auto allocation : allocations) {
313- umfPoolFree (inPool, allocation);
363+ umf_result_t umf_result = umfPoolFree (inPool, allocation);
364+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
314365 }
315366 };
316367
@@ -335,7 +386,8 @@ TEST_P(umfPoolTest, multiThreadedMallocFreeRandomSizes) {
335386 }
336387
337388 for (auto allocation : allocations) {
338- umfPoolFree (inPool, allocation);
389+ umf_result_t umf_result = umfPoolFree (inPool, allocation);
390+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
339391 }
340392 };
341393
@@ -375,7 +427,8 @@ TEST_P(umfMemTest, outOfMem) {
375427 ASSERT_NE (allocations.back (), nullptr );
376428
377429 for (int i = 0 ; i < expectedRecycledPoolAllocs; i++) {
378- umfPoolFree (hPool, allocations.back ());
430+ umf_result_t umf_result = umfPoolFree (hPool, allocations.back ());
431+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
379432 allocations.pop_back ();
380433 }
381434
@@ -385,7 +438,8 @@ TEST_P(umfMemTest, outOfMem) {
385438 }
386439
387440 for (auto allocation : allocations) {
388- umfPoolFree (hPool, allocation);
441+ umf_result_t umf_result = umfPoolFree (hPool, allocation);
442+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
389443 }
390444}
391445
@@ -490,7 +544,8 @@ TEST_P(umfPoolTest, mallocUsableSize) {
490544 // Make sure we can write to this memory
491545 memset (ptr, 123 , result);
492546
493- umfPoolFree (pool.get (), ptr);
547+ umf_result_t umf_result = umfPoolFree (pool.get (), ptr);
548+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
494549 }
495550 }
496551}
0 commit comments