Skip to content

Commit 64f701d

Browse files
committed
Add test for umfPoolMallocUsableSize
1 parent 882a4c8 commit 64f701d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/poolFixtures.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,4 +456,30 @@ TEST_P(umfPoolTest, allocMaxSize) {
456456
ASSERT_EQ(ptr, nullptr);
457457
}
458458

459+
#if defined(__has_feature)
460+
#if __has_feature(address_sanitizer)
461+
#define __SANITIZE_ADDRESS__
462+
#endif
463+
#endif
464+
465+
#ifndef __SANITIZE_ADDRESS__
466+
// Sanitizer replaces malloc_usable_size implementation with it's own,
467+
// what results in a failure.
468+
469+
TEST_P(umfPoolTest, mallocUsableSize) {
470+
for (size_t allocSize : {32, 48, 1024, 8192}) {
471+
char *ptr = static_cast<char *>(umfPoolMalloc(pool.get(), allocSize));
472+
size_t result = umfPoolMallocUsableSize(pool.get(), ptr);
473+
EXPECT_TRUE(result == 0 or result >= allocSize);
474+
475+
for (size_t i = 0; i < result; i++) {
476+
ptr[i] = 123;
477+
}
478+
479+
umfPoolFree(pool.get(), ptr);
480+
}
481+
}
482+
483+
#endif
484+
459485
#endif /* UMF_TEST_POOL_FIXTURES_HPP */

0 commit comments

Comments
 (0)