Skip to content

Commit da98ba9

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

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/poolFixtures.hpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
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 */

0 commit comments

Comments
 (0)