[PATCH] tests/tracetool: Honor the Python interpreter that "configure" detected

Thomas Huth posted 1 patch 3 weeks, 2 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260114092358.22961-1-thuth@redhat.com
Maintainers: Stefan Hajnoczi <stefanha@redhat.com>, Mads Ynddal <mads@ynddal.dk>
There is a newer version of this series
tests/tracetool/meson.build       | 3 +++
tests/tracetool/tracetool-test.py | 4 +++-
2 files changed, 6 insertions(+), 1 deletion(-)
[PATCH] tests/tracetool: Honor the Python interpreter that "configure" detected
Posted by Thomas Huth 3 weeks, 2 days ago
From: Thomas Huth <thuth@redhat.com>

The tracetool tests currently fail if the host installation does not
have a "python3" binary (and you compiled QEMU by selecting a different
one during the "configure" step). This happens because tracetool-test.py
executes scripts/tracetool.py directly, so that this script is run via
its shebang line.
To fix the issue, pass the right Python interpreter to tracetool-test.py
via the PYTHON environment variable and use that to run the tracetool.py
script.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/tracetool/meson.build       | 3 +++
 tests/tracetool/tracetool-test.py | 4 +++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/tests/tracetool/meson.build b/tests/tracetool/meson.build
index 09bbaaa86bf..7ff8ada7b23 100644
--- a/tests/tracetool/meson.build
+++ b/tests/tracetool/meson.build
@@ -15,6 +15,8 @@ backends = [
 
 # The tracetool-test.py program has portability problems on Windows.
 if host_machine.system() != 'windows'
+    test_env = environment()
+    test_env.set('PYTHON', python.full_path())
     foreach backend: backends
         test(backend,
              python,
@@ -23,6 +25,7 @@ if host_machine.system() != 'windows'
                     backend,
                     meson.current_source_dir(),
                     meson.current_build_dir()],
+             env: test_env,
              suite: ['tracetool'])
     endforeach
 endif
diff --git a/tests/tracetool/tracetool-test.py b/tests/tracetool/tracetool-test.py
index 30006a99190..9e62a81d4c3 100755
--- a/tests/tracetool/tracetool-test.py
+++ b/tests/tracetool/tracetool-test.py
@@ -36,7 +36,9 @@ def test_tracetool_one(tracetool, backend, fmt, src_dir, build_dir):
     actual_file = Path(build_dir, rel_filename)
     expect_file = Path(src_dir, rel_filename)
 
-    args = [tracetool, f"--format={fmt}", f"--backends={backend}", "--group=testsuite"]
+    python = os.environ.get("PYTHON", "python3")
+    args = [python, tracetool, f"--format={fmt}", f"--backends={backend}",
+            "--group=testsuite"]
 
     if fmt.find("stap") != -1:
         args += ["--binary=qemu", "--probe-prefix=qemu"]
-- 
2.52.0
Re: [PATCH] tests/tracetool: Honor the Python interpreter that "configure" detected
Posted by Paolo Bonzini 3 weeks, 2 days ago
On 1/14/26 10:23, Thomas Huth wrote:
> From: Thomas Huth <thuth@redhat.com>
> 
> The tracetool tests currently fail if the host installation does not
> have a "python3" binary (and you compiled QEMU by selecting a different
> one during the "configure" step). This happens because tracetool-test.py
> executes scripts/tracetool.py directly, so that this script is run via
> its shebang line.
> To fix the issue, pass the right Python interpreter to tracetool-test.py
> via the PYTHON environment variable and use that to run the tracetool.py
> script.
> 
> -    args = [tracetool, f"--format={fmt}", f"--backends={backend}", "--group=testsuite"]
> +    python = os.environ.get("PYTHON", "python3")
> +    args = [python, tracetool, f"--format={fmt}", f"--backends={backend}",
> +            "--group=testsuite"]
>   
>       if fmt.find("stap") != -1:
>           args += ["--binary=qemu", "--probe-prefix=qemu"]

What about just

diff --git a/tests/tracetool/tracetool-test.py b/tests/tracetool/tracetool-test.py
index 30006a99190..efc518a6b1e 100755
--- a/tests/tracetool/tracetool-test.py
+++ b/tests/tracetool/tracetool-test.py
@@ -36,7 +36,7 @@ def test_tracetool_one(tracetool, backend, fmt, src_dir, build_dir):
      actual_file = Path(build_dir, rel_filename)
      expect_file = Path(src_dir, rel_filename)
  
-    args = [tracetool, f"--format={fmt}", f"--backends={backend}", "--group=testsuite"]
+    args = [sys.executable, tracetool, f"--format={fmt}", f"--backends={backend}", "--group=testsuite"]
  
      if fmt.find("stap") != -1:
          args += ["--binary=qemu", "--probe-prefix=qemu"]

(only the second half of the commit message needs changing).

Even if you keep using PYTHON, which makes sense, I would change the
default to sys.executable.

Paolo
Re: [PATCH] tests/tracetool: Honor the Python interpreter that "configure" detected
Posted by Thomas Huth 3 weeks, 2 days ago
On 14/01/2026 10.29, Paolo Bonzini wrote:
> On 1/14/26 10:23, Thomas Huth wrote:
>> From: Thomas Huth <thuth@redhat.com>
>>
>> The tracetool tests currently fail if the host installation does not
>> have a "python3" binary (and you compiled QEMU by selecting a different
>> one during the "configure" step). This happens because tracetool-test.py
>> executes scripts/tracetool.py directly, so that this script is run via
>> its shebang line.
>> To fix the issue, pass the right Python interpreter to tracetool-test.py
>> via the PYTHON environment variable and use that to run the tracetool.py
>> script.
>>
>> -    args = [tracetool, f"--format={fmt}", f"--backends={backend}", "-- 
>> group=testsuite"]
>> +    python = os.environ.get("PYTHON", "python3")
>> +    args = [python, tracetool, f"--format={fmt}", f"--backends={backend}",
>> +            "--group=testsuite"]
>>       if fmt.find("stap") != -1:
>>           args += ["--binary=qemu", "--probe-prefix=qemu"]
> 
> What about just
> 
> diff --git a/tests/tracetool/tracetool-test.py b/tests/tracetool/tracetool- 
> test.py
> index 30006a99190..efc518a6b1e 100755
> --- a/tests/tracetool/tracetool-test.py
> +++ b/tests/tracetool/tracetool-test.py
> @@ -36,7 +36,7 @@ def test_tracetool_one(tracetool, backend, fmt, src_dir, 
> build_dir):
>       actual_file = Path(build_dir, rel_filename)
>       expect_file = Path(src_dir, rel_filename)
> 
> -    args = [tracetool, f"--format={fmt}", f"--backends={backend}", "-- 
> group=testsuite"]
> +    args = [sys.executable, tracetool, f"--format={fmt}", f"-- 
> backends={backend}", "--group=testsuite"]
> 
>       if fmt.find("stap") != -1:
>           args += ["--binary=qemu", "--probe-prefix=qemu"]
> 
> (only the second half of the commit message needs changing).
> 
> Even if you keep using PYTHON, which makes sense, I would change the
> default to sys.executable.

Fine for me, too! ... Stefan, do you have any preferences?

  Thomas


Re: [PATCH] tests/tracetool: Honor the Python interpreter that "configure" detected
Posted by Stefan Hajnoczi 3 weeks, 2 days ago
On Wed, Jan 14, 2026 at 4:52 AM Thomas Huth <thuth@redhat.com> wrote:
>
> On 14/01/2026 10.29, Paolo Bonzini wrote:
> > On 1/14/26 10:23, Thomas Huth wrote:
> >> From: Thomas Huth <thuth@redhat.com>
> >>
> >> The tracetool tests currently fail if the host installation does not
> >> have a "python3" binary (and you compiled QEMU by selecting a different
> >> one during the "configure" step). This happens because tracetool-test.py
> >> executes scripts/tracetool.py directly, so that this script is run via
> >> its shebang line.
> >> To fix the issue, pass the right Python interpreter to tracetool-test.py
> >> via the PYTHON environment variable and use that to run the tracetool.py
> >> script.
> >>
> >> -    args = [tracetool, f"--format={fmt}", f"--backends={backend}", "--
> >> group=testsuite"]
> >> +    python = os.environ.get("PYTHON", "python3")
> >> +    args = [python, tracetool, f"--format={fmt}", f"--backends={backend}",
> >> +            "--group=testsuite"]
> >>       if fmt.find("stap") != -1:
> >>           args += ["--binary=qemu", "--probe-prefix=qemu"]
> >
> > What about just
> >
> > diff --git a/tests/tracetool/tracetool-test.py b/tests/tracetool/tracetool-
> > test.py
> > index 30006a99190..efc518a6b1e 100755
> > --- a/tests/tracetool/tracetool-test.py
> > +++ b/tests/tracetool/tracetool-test.py
> > @@ -36,7 +36,7 @@ def test_tracetool_one(tracetool, backend, fmt, src_dir,
> > build_dir):
> >       actual_file = Path(build_dir, rel_filename)
> >       expect_file = Path(src_dir, rel_filename)
> >
> > -    args = [tracetool, f"--format={fmt}", f"--backends={backend}", "--
> > group=testsuite"]
> > +    args = [sys.executable, tracetool, f"--format={fmt}", f"--
> > backends={backend}", "--group=testsuite"]
> >
> >       if fmt.find("stap") != -1:
> >           args += ["--binary=qemu", "--probe-prefix=qemu"]
> >
> > (only the second half of the commit message needs changing).
> >
> > Even if you keep using PYTHON, which makes sense, I would change the
> > default to sys.executable.
>
> Fine for me, too! ... Stefan, do you have any preferences?

I like the minimal patch with just sys.executable and no PYTHON
environment variable.

Thanks,
Stefan