[PULL 7/8] tracetool-test: add QEMU_TEST_KEEP_SCRATCH=1 support

Stefan Hajnoczi posted 8 patches 2 weeks, 6 days ago
Maintainers: John Snow <jsnow@redhat.com>, Cleber Rosa <crosa@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>, Mads Ynddal <mads@ynddal.dk>
There is a newer version of this series
[PULL 7/8] tracetool-test: add QEMU_TEST_KEEP_SCRATCH=1 support
Posted by Stefan Hajnoczi 2 weeks, 6 days ago
It can be useful to preserve the temporary files generated by the test
for manual inspection or diffing against expected output.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-id: 20251118183915.177192-1-stefanha@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 tests/tracetool/tracetool-test.py | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/tests/tracetool/tracetool-test.py b/tests/tracetool/tracetool-test.py
index 30006a9919..10e362a407 100755
--- a/tests/tracetool/tracetool-test.py
+++ b/tests/tracetool/tracetool-test.py
@@ -9,6 +9,9 @@
 import tempfile
 
 
+DELETE_TEMPFILE = not os.getenv("QEMU_TEST_KEEP_SCRATCH", False)
+
+
 def get_formats(backend):
     formats = [
         "c",
@@ -49,7 +52,8 @@ def test_tracetool_one(tracetool, backend, fmt, src_dir, build_dir):
         check_call(args, cwd=build_dir)
         actual = actual_file.read_text()
     finally:
-        actual_file.unlink()
+        if DELETE_TEMPFILE:
+            actual_file.unlink()
 
     if os.getenv("QEMU_TEST_REGENERATE", False):
         print(f"# regenerate {expect_file}")
@@ -84,14 +88,25 @@ def test_tracetool(tracetool, backend, source_dir, build_dir):
             except Exception as e:
                 print(f"# {e}")
                 fail = True
+
+                if DELETE_TEMPFILE:
+                    tempfile_hint = (
+                        "QEMU_TEST_KEEP_SCRATCH=1 to preserve test output "
+                        + "files"
+                    )
+                else:
+                    tempfile_hint = f"check test output files in {build_dir}"
+
                 hint = (
                     " (set QEMU_TEST_REGENERATE=1 to recreate reference "
-                    + "output if tracetool generator was intentionally changed)"
+                    + "output if tracetool generator was intentionally "
+                    + "changed or " + tempfile_hint + ")"
                 )
             finally:
                 print(f"{status} {num} - {backend}.{fmt}{hint}")
     finally:
-        build_events.unlink()
+        if DELETE_TEMPFILE:
+            build_events.unlink()
 
     return fail
 
@@ -102,7 +117,8 @@ def test_tracetool(tracetool, backend, source_dir, build_dir):
         print("syntax: {argv0} TRACE-TOOL BACKEND SRC-DIR BUILD-DIR", file=sys.stderr)
         sys.exit(1)
 
-    with tempfile.TemporaryDirectory(prefix=sys.argv[4]) as tmpdir:
+    with tempfile.TemporaryDirectory(prefix=sys.argv[4],
+                                     delete=DELETE_TEMPFILE) as tmpdir:
         fail = test_tracetool(sys.argv[1], sys.argv[2], sys.argv[3], tmpdir)
         if fail:
             sys.exit(1)
-- 
2.52.0
Re: [PULL 7/8] tracetool-test: add QEMU_TEST_KEEP_SCRATCH=1 support
Posted by Daniel P. Berrangé 2 weeks, 6 days ago
On Mon, Jan 19, 2026 at 02:08:22PM -0500, Stefan Hajnoczi wrote:
> It can be useful to preserve the temporary files generated by the test
> for manual inspection or diffing against expected output.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> Message-id: 20251118183915.177192-1-stefanha@redhat.com
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>

Double S-o-B and no 3rd party R-b, but have this one...

  Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

> ---
>  tests/tracetool/tracetool-test.py | 24 ++++++++++++++++++++----
>  1 file changed, 20 insertions(+), 4 deletions(-)


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|