[Concept,25/26] test: pxe: Add memory-leak check to files-API test

Message ID 20260110202906.187370-26-sjg@u-boot.org
State New
Headers
Series boot: pxe: Add three-phase API and fix memory leaks |

Commit Message

Simon Glass Jan. 10, 2026, 8:28 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Add a check for memory leaks in the callback-free files API test. This
ensures that pxe_cleanup() properly frees all allocated memory.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 test/boot/pxe.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
  

Patch

diff --git a/test/boot/pxe.c b/test/boot/pxe.c
index 80779b86aad..f4a124eafda 100644
--- a/test/boot/pxe.c
+++ b/test/boot/pxe.c
@@ -12,6 +12,7 @@ 
  *
  */
 
+#include <blk.h>
 #include <dm.h>
 #include <env.h>
 #include <fdt_support.h>
@@ -1358,6 +1359,7 @@  static int pxe_test_files_api_norun(struct unit_test_state *uts)
 	struct pxe_file *filep;
 	ulong addr = PXE_LOAD_ADDR;
 	ulong file_addr;
+	ulong start_mem;
 	ulong size;
 	char *buf;
 	uint i;
@@ -1368,6 +1370,9 @@  static int pxe_test_files_api_norun(struct unit_test_state *uts)
 	/* Bind the filesystem image */
 	ut_assertok(run_commandf("host bind 0 %s", fs_image));
 
+	blkcache_free();
+	start_mem = ut_check_delta(0);
+
 	/* Load the config file first */
 	ut_assertok(load_file(cfg_path, addr, &size));
 
@@ -1479,8 +1484,10 @@  static int pxe_test_files_api_norun(struct unit_test_state *uts)
 	ut_asserteq_mem("ramdisk", buf, 7);
 	unmap_sysmem(buf);
 
-	/* Clean up */
+	/* Clean up and check for memory leaks */
 	pxe_cleanup(ctx);
+	blkcache_free();
+	ut_assertok(ut_check_delta(start_mem));
 
 	return 0;
 }