[Buildroot] [PATCH 01/11] support/testing/infra: improve run_cmd_on_host() to show stdout/stderr
Thomas Petazzoni
thomas.petazzoni at bootlin.com
Sat Oct 18 19:42:59 UTC 2025
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>
---
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
--
2.51.0
More information about the buildroot
mailing list