qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Mads Ynddal <mads@ynddal.dk>,
	berrange@redhat.com, Stefan Hajnoczi <stefanha@redhat.com>
Subject: [PATCH] tracetool-test: add QEMU_TEST_KEEP_SCRATCH=1 support
Date: Tue, 18 Nov 2025 13:39:15 -0500	[thread overview]
Message-ID: <20251118183915.177192-1-stefanha@redhat.com> (raw)

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>
---
 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 786083ad7f..5a0c6a869c 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.51.1



                 reply	other threads:[~2025-11-18 18:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251118183915.177192-1-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=berrange@redhat.com \
    --cc=mads@ynddal.dk \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).