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>
@@ -456,4 +457,26 @@ TEST_P(umfPoolTest, allocMaxSize) {
456457 ASSERT_EQ (ptr, nullptr );
457458}
458459
460+ TEST_P (umfPoolTest, mallocUsableSize) {
461+ #ifdef __SANITIZE_ADDRESS__
462+ // Sanitizer replaces malloc_usable_size implementation with its own
463+ GTEST_SKIP ()
464+ << " This test is invalid with AddressSanitizer instrumentation" ;
465+ #endif
466+
467+ for (size_t allocSize : {32 , 48 , 1024 , 8192 }) {
468+ char *ptr = static_cast <char *>(umfPoolMalloc (pool.get (), allocSize));
469+ ASSERT_NE (ptr, nullptr );
470+ size_t result = umfPoolMallocUsableSize (pool.get (), ptr);
471+ ASSERT_TRUE (result == 0 || result >= allocSize);
472+
473+ // Make sure we can write to this memory
474+ for (size_t i = 0 ; i < result; i++) {
475+ ptr[i] = 123 ;
476+ }
477+
478+ umfPoolFree (pool.get (), ptr);
479+ }
480+ }
481+
459482#endif /* UMF_TEST_POOL_FIXTURES_HPP */
You can’t perform that action at this time.
0 commit comments