[Concept,04/27] test: trace: Remove stale trace file before saving

Message ID 20260119204130.3972647-5-sjg@u-boot.org
State New
Headers
Series Expo debugging and textedit improvements (part E) |

Commit Message

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

The sandbox filesystem's host save command does not truncate existing
files. If a previous test run created a larger trace file, the extra
data remains when a smaller trace is written, causing proftool to fail
with "Cannot read trace file" when it tries to read past the actual
data.

Fix this by removing any existing trace file before saving.

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

 test/py/tests/test_trace.py | 2 ++
 1 file changed, 2 insertions(+)
  

Patch

diff --git a/test/py/tests/test_trace.py b/test/py/tests/test_trace.py
index fcdcbe2c6db..0bddf408833 100644
--- a/test/py/tests/test_trace.py
+++ b/test/py/tests/test_trace.py
@@ -65,6 +65,8 @@  def collect_trace(ubman):
     out = ubman.run_command(f'trace calls {addr:x} {size:x}')
     print(out)
     fname = os.path.join(TMPDIR, 'trace')
+    if os.path.exists(fname):
+        os.unlink(fname)
     out = ubman.run_command(
         'host save hostfs - %x %s ${profoffset}' % (addr, fname))
     return fname, int(dm_f_time[0])