From: Simon Glass <simon.glass@canonical.com> 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> --- test/common/malloc.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/test/common/malloc.c b/test/common/malloc.c index 9fdc1789645..436aac503be 100644 --- a/test/common/malloc.c +++ b/test/common/malloc.c @@ -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); -- 2.43.0