[Buildroot] [git commit] support/testing/infra: improve run_cmd_on_host() to show stdout/stderr
Julien Olivain
ju.o at free.fr
Thu Oct 30 20:10:33 UTC 2025
commit: https://git.buildroot.net/buildroot/commit/?id=01dc13adfb7486cb05e655d0b58f5490a0d046ea
branch: https://git.buildroot.net/buildroot/commit/?id=refs/heads/master
When run_cmd_on_host() runs a command that fails, we only get an
exception with no details to debug what happened. Let's improve that
by catching the exception, and printing the command output. This
requires redirecting stderr to stdout (instead of /dev/null) and
asking to get the output in text format.
Signed-off-by: Thomas Petazzoni <thomas.petazzoni at bootlin.com>
Signed-off-by: Julien Olivain <ju.o at free.fr>
---
support/testing/infra/__init__.py | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/support/testing/infra/__init__.py b/support/testing/infra/__init__.py
index 1f003f24c6..52308395a3 100644
--- a/support/testing/infra/__init__.py
+++ b/support/testing/infra/__init__.py
@@ -59,11 +59,20 @@ def download(dldir, filename):
def run_cmd_on_host(builddir, cmd):
"""Call subprocess.check_output and return the text output."""
- out = subprocess.check_output(cmd,
- stderr=open(os.devnull, "w"),
- cwd=builddir,
- env={"LANG": "C"},
- universal_newlines=True)
+ try:
+ out = subprocess.check_output(cmd,
+ cwd=builddir,
+ env={"LANG": "C"},
+ stderr=subprocess.STDOUT,
+ text=True,
+ universal_newlines=True)
+ except subprocess.CalledProcessError as e:
+ print(f"Command failed with return code {e.returncode}")
+ print("=== STDOUT/STDERR ===")
+ print(e.output)
+ print("=====================")
+ raise
+
return out
More information about the buildroot
mailing list