test: Add functions to find the amount of allocated memory
[oweals/u-boot.git] / test / ut.c
index fa0f02d6d94ee179e3f07dae60fabb5babc6c1cb..265da4a0d89a8d05fa50e39751c32e6b52ed1119 100644 (file)
--- a/test/ut.c
+++ b/test/ut.c
@@ -1,12 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Simple unit test library
  *
  * Copyright (c) 2013 Google, Inc
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
+#include <malloc.h>
 #include <test/test.h>
 #include <test/ut.h>
 
@@ -33,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;
+}
+