Skip to content

Commit 94da685

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

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/poolFixtures.hpp

Lines changed: 21 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,24 @@ TEST_P(umfPoolTest, allocMaxSize) {
456457
ASSERT_EQ(ptr, nullptr);
457458
}
458459

460+
TEST_P(umfPoolTest, mallocUsableSize) {
461+
#ifdef __SANITIZE_ADDRESS__
462+
GTEST_SKIP()
463+
<< "This test is invalid with AddressSanitizer instrumentation";
464+
#endif
465+
466+
for (size_t allocSize : {32, 48, 1024, 8192}) {
467+
char *ptr = static_cast<char *>(umfPoolMalloc(pool.get(), allocSize));
468+
size_t result = umfPoolMallocUsableSize(pool.get(), ptr);
469+
ASSERT_TRUE(result == 0 || result >= allocSize);
470+
471+
// Make sure we can write to this memory
472+
for (size_t i = 0; i < result; i++) {
473+
ptr[i] = 123;
474+
}
475+
476+
umfPoolFree(pool.get(), ptr);
477+
}
478+
}
479+
459480
#endif /* UMF_TEST_POOL_FIXTURES_HPP */

0 commit comments

Comments
 (0)