test: malloc: Account for mcheck overhead in the large test
The malloc_very_large() test fails when mcheck is enabled with large CONFIG_MCHECK_CALLER_LEN because the 64K margin does not account for the per-allocation overhead (header + canaries). Use a larger margin (256K) when mcheck is enabled to ensure the test passes regardless of the mcheck caller length setting. Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com>
This commit is contained in:
@@ -535,11 +535,21 @@ COMMON_TEST(common_test_mallinfo, 0);
|
||||
/* Test allocating a very large size */
|
||||
static int common_test_malloc_very_large(struct unit_test_state *uts)
|
||||
{
|
||||
size_t size, before;
|
||||
size_t size, before, margin;
|
||||
void *ptr;
|
||||
|
||||
before = get_alloced_size();
|
||||
size = TOTAL_MALLOC_LEN - before - SZ_64K;
|
||||
|
||||
/*
|
||||
* When mcheck is enabled, it adds overhead per allocation (header +
|
||||
* canaries). With large CONFIG_MCHECK_CALLER_LEN, this can be
|
||||
* significant. Use a larger margin to account for mcheck overhead.
|
||||
*/
|
||||
if (CONFIG_IS_ENABLED(MCHECK_HEAP_PROTECTION))
|
||||
margin = SZ_256K;
|
||||
else
|
||||
margin = SZ_64K;
|
||||
size = TOTAL_MALLOC_LEN - before - margin;
|
||||
|
||||
ptr = malloc(size);
|
||||
ut_assertnonnull(ptr);
|
||||
|
||||
Reference in New Issue
Block a user