From 5e9ac5bdf77b22901026b001fd28b3886d6a9fb0 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 20 Aug 2024 11:52:18 +0200 Subject: [PATCH] test(build_system): print failed command and output when test fails --- .../test_build_system_helpers/idf_utils.py | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/tools/test_build_system/test_build_system_helpers/idf_utils.py b/tools/test_build_system/test_build_system_helpers/idf_utils.py index 638789535e..2e7de87601 100644 --- a/tools/test_build_system/test_build_system_helpers/idf_utils.py +++ b/tools/test_build_system/test_build_system_helpers/idf_utils.py @@ -90,10 +90,17 @@ def run_idf_py(*args: str, ] cmd += args # type: ignore logging.debug('running {} in {}'.format(' '.join(cmd), workdir)) - return subprocess.run( - cmd, env=env, cwd=workdir, - check=check, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - text=True, encoding='utf-8', errors='backslashreplace', input=input_str) + try: + return subprocess.run( + cmd, env=env, cwd=workdir, + check=check, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + text=True, encoding='utf-8', errors='backslashreplace', input=input_str) + except subprocess.CalledProcessError as e: + logging.error('The following idf.py command has failed: {}'.format(' '.join(cmd))) + logging.error('Working directory: {}'.format(workdir)) + logging.error('Stdout: {}'.format(e.stdout)) + logging.error('Stderr: {}'.format(e.stderr)) + raise def run_cmake(*cmake_args: str, @@ -120,10 +127,17 @@ def run_cmake(*cmake_args: str, cmd = ['cmake'] + list(cmake_args) logging.debug('running {} in {}'.format(' '.join(cmd), build_dir)) - return subprocess.run( - cmd, env=env, cwd=build_dir, - check=check, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - text=True, encoding='utf-8', errors='backslashreplace') + try: + return subprocess.run( + cmd, env=env, cwd=build_dir, + check=check, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + text=True, encoding='utf-8', errors='backslashreplace') + except subprocess.CalledProcessError as e: + logging.error('The following cmake command has failed: {}'.format(' '.join(cmd))) + logging.error('Working directory: {}'.format(workdir)) + logging.error('Stdout: {}'.format(e.stdout)) + logging.error('Stderr: {}'.format(e.stderr)) + raise def run_cmake_and_build(*cmake_args: str, env: typing.Optional[EnvDict] = None) -> None: