From 8109863f535e0851b50a333d4e7fdaa2006ac019 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 29 Dec 2019 21:19:23 -0700 Subject: test: Add functions to find the amount of allocated memory The malloc() implementations provides a way of finding out the approximate amount of memory that is allocated. Add helper functions to make it easier to access this and see changes over time. This is useful for tests that want to check if memory has been allocated or freed. Signed-off-by: Simon Glass --- test/ut.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/ut.c') diff --git a/test/ut.c b/test/ut.c index 5579804..265da4a 100644 --- a/test/ut.c +++ b/test/ut.c @@ -6,6 +6,7 @@ */ #include +#include #include #include @@ -32,3 +33,16 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line, putc('\n'); uts->fail_count++; } + +ulong ut_check_free(void) +{ + struct mallinfo info = mallinfo(); + + return info.uordblks; +} + +long ut_check_delta(ulong last) +{ + return ut_check_free() - last; +} + -- cgit v1.1