malloc: Add 'malloc' command with 'info' subcommand

Add a command to display malloc heap statistics, showing total heap
size and memory currently in use.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
This commit is contained in:
Simon Glass
2025-11-28 08:54:29 -07:00
parent bd0f9a753c
commit cfbee94582
7 changed files with 121 additions and 0 deletions

30
test/cmd/malloc.c Normal file
View File

@@ -0,0 +1,30 @@
// 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_assertok(run_command("malloc info", 0));
ut_assert_nextlinen("total bytes = ");
ut_assert_nextlinen("in use bytes = ");
ut_assert_console_end();
return 0;
}
CMD_TEST(cmd_test_malloc_info, UTF_CONSOLE);