Skip to content

Commit 09c5389

Browse files
Merge pull request #875 from staniewzki/base-alloc-coverity
Add test for `umfPoolMallocUsableSize` to improve coverage of `base_alloc_global.c`
2 parents 3d0fe19 + da98ba9 commit 09c5389

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>
@@ -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 */

0 commit comments

Comments
 (0)