diff --git a/test/poolFixtures.hpp b/test/poolFixtures.hpp index e1c1cc7225..bb3c2a9940 100644 --- a/test/poolFixtures.hpp +++ b/test/poolFixtures.hpp @@ -9,6 +9,7 @@ #include "provider.hpp" #include "umf/providers/provider_coarse.h" #include "umf/providers/provider_devdax_memory.h" +#include "utils/utils_sanitizers.h" #include #include @@ -456,4 +457,26 @@ TEST_P(umfPoolTest, allocMaxSize) { ASSERT_EQ(ptr, nullptr); } +TEST_P(umfPoolTest, mallocUsableSize) { +#ifdef __SANITIZE_ADDRESS__ + // Sanitizer replaces malloc_usable_size implementation with its own + GTEST_SKIP() + << "This test is invalid with AddressSanitizer instrumentation"; +#endif + + for (size_t allocSize : {32, 48, 1024, 8192}) { + char *ptr = static_cast(umfPoolMalloc(pool.get(), allocSize)); + ASSERT_NE(ptr, nullptr); + size_t result = umfPoolMallocUsableSize(pool.get(), ptr); + ASSERT_TRUE(result == 0 || result >= allocSize); + + // Make sure we can write to this memory + for (size_t i = 0; i < result; i++) { + ptr[i] = 123; + } + + umfPoolFree(pool.get(), ptr); + } +} + #endif /* UMF_TEST_POOL_FIXTURES_HPP */