Faster Tests and Better Debugging: Improvements to Malloc and test/py

Developing for U-Boot often involves chasing down elusive memory leaks and waiting for long test suites to finish. A recent series of 29 patches is aimed squarely at improving the developer experience in these areas.
This series introduces powerful new malloc debugging tools, optimises the video subsystem, and significantly improves the performance of the test/py infrastructure.
Deep Dive into Malloc Debugging
Finding memory leaks in a bootloader can be painful. This series adds several features to the malloc subsystem, particularly for sandbox, to make this process more transparent.
Malloc Traffic Log
A new logging feature records every malloc, free, and realloc call into a circular buffer. This includes the pointer address, allocation size, and the caller’s backtrace.
You can control this via the new malloc log command:
=> malloc log start Malloc logging started => ... run commands that might leak ... => malloc log stop Malloc logging stopped => malloc log Malloc log: 29 entries (max 524288, total 29) Seq Type Ptr Size Caller ---- -------- ---------------- -------- ------ 0 free 16a016e0 0 free_pipe_list:2001 -parse_stream_outer:3208 -parse_file_outer:3300 1 alloc 16a01b90 20 hush_file_init:3277 -parse_file_outer:3295 -run_pipe_real:1986 ...
Each entry shows the operation type, the address and size and the caller trace, so you can figure out where it happened.
File Output for Heap Dumps
To make comparing heap states easier, new functions malloc_dump_to_file() and malloc_log_to_file() allow you to write the heap state directly to a file on the host system (when running U-Boot sandbox). This enables a simple workflow for finding leaks:
- Dump heap to
before.txt - Run your test case
- Dump heap to
after.txt - Use
difforcommon the host to identify pointers that persist.
Performance Improvements
Video and Truetype Optimization
Rendering text on the video console was identified as a performance bottleneck during testing.
- Truetype Scratch Buffer: The
stb_truetypelibrary previously performed around 5 allocations per character. We added a pre-allocated scratch buffer, drastically reducingmallocpressure. - Full-line Copy: The
video_flush_copy()function is now optimised to detect full-line damage, allowing for singlememcpycalls instead of looping pixel-by-pixel or small chunks.
Accelerating test/py
Running the full test suite can be CPU intensive. This series addresses inefficiencies in how test/py handles console output.
- VT100 Filtering: The logic to filter escape sequences was previously O(N^2). It has been optimised to filter only new data, significantly reducing overhead on verbose tests.
- CPU Usage: A tiny delay has been added before polling the console pipe to allow data to accumulate (up to 4KB). This simple change reduced CPU usage by approximately 30% during intensive output operations.
Additional Features
- Gprof Support: You can now build sandbox with
GPROF=1to generate profiling data (gmon.out) for analysis with standard GNU tools. - Runtime Mcheck Disable: A new
-Mflag allows you to disablemcheckheap protection at runtime, useful when the overhead interferes with specific timing-sensitive tests.
These changes make the U-Boot sandbox a faster, more observable environment for development!