Add counters to track the number of calls to malloc(), free(), and realloc(). These are displayed by the 'malloc info' command and accessible via malloc_get_info(). Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com>
35 lines
890 B
C
35 lines
890 B
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* Test for 'malloc' command
|
|
*
|
|
* Copyright 2025 Canonical Ltd
|
|
* Written by Simon Glass <simon.glass@canonical.com>
|
|
*/
|
|
|
|
#include <malloc.h>
|
|
#include <dm/test.h>
|
|
#include <test/cmd.h>
|
|
#include <test/ut.h>
|
|
|
|
/* Test 'malloc info' command */
|
|
static int cmd_test_malloc_info(struct unit_test_state *uts)
|
|
{
|
|
struct malloc_info info;
|
|
|
|
ut_assertok(malloc_get_info(&info));
|
|
ut_assert(info.total_bytes >= CONFIG_SYS_MALLOC_LEN);
|
|
ut_assert(info.in_use_bytes < info.total_bytes);
|
|
ut_assert(info.malloc_count > 0);
|
|
|
|
ut_assertok(run_command("malloc info", 0));
|
|
ut_assert_nextlinen("total bytes = ");
|
|
ut_assert_nextlinen("in use bytes = ");
|
|
ut_assert_nextlinen("malloc count = ");
|
|
ut_assert_nextlinen("free count = ");
|
|
ut_assert_nextlinen("realloc count = ");
|
|
ut_assert_console_end();
|
|
|
|
return 0;
|
|
}
|
|
CMD_TEST(cmd_test_malloc_info, UTF_CONSOLE);
|