File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 99#include " provider.hpp"
1010#include " umf/providers/provider_coarse.h"
1111#include " umf/providers/provider_devdax_memory.h"
12+ #include " utils/utils_sanitizers.h"
1213
1314#include < array>
1415#include < cstring>
@@ -461,4 +462,26 @@ TEST_P(umfPoolTest, allocMaxSize) {
461462 ASSERT_EQ (ptr, nullptr );
462463}
463464
465+ TEST_P (umfPoolTest, mallocUsableSize) {
466+ #ifdef __SANITIZE_ADDRESS__
467+ // Sanitizer replaces malloc_usable_size implementation with its own
468+ GTEST_SKIP ()
469+ << " This test is invalid with AddressSanitizer instrumentation" ;
470+ #endif
471+
472+ for (size_t allocSize : {32 , 48 , 1024 , 8192 }) {
473+ char *ptr = static_cast <char *>(umfPoolMalloc (pool.get (), allocSize));
474+ ASSERT_NE (ptr, nullptr );
475+ size_t result = umfPoolMallocUsableSize (pool.get (), ptr);
476+ ASSERT_TRUE (result == 0 || result >= allocSize);
477+
478+ // Make sure we can write to this memory
479+ for (size_t i = 0 ; i < result; i++) {
480+ ptr[i] = 123 ;
481+ }
482+
483+ umfPoolFree (pool.get (), ptr);
484+ }
485+ }
486+
464487#endif /* UMF_TEST_POOL_FIXTURES_HPP */
You can’t perform that action at this time.
0 commit comments