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:
Simon Glass
2026-01-01 11:36:32 -07:00
parent c0dfcc8123
commit bbea921ca7

View File

@@ -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);