diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/error_reporting.s b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/error_reporting.s new file mode 100644 index 0000000000000..9f303b19c1cd7 --- /dev/null +++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/error_reporting.s @@ -0,0 +1,3 @@ +// RUN: llvm-mc -triple=riscv64 %s | FileCheck %s + +add x1, x2, x3, x4 diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/error-reporting.test b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/error-reporting.test new file mode 100644 index 0000000000000..fca1e753762b3 --- /dev/null +++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/error-reporting.test @@ -0,0 +1,11 @@ +# REQUIRES: riscv-registered-target +## Check that update_mc_test_checks prints a useful error message with stderr when the command fails + +# RUN: cp -f %S/Inputs/error_reporting.s %t.s +# RUN: not %update_mc_test_checks %t.s 2>&1 | FileCheck %s + +# CHECK: Error running command: {{.*}}llvm-mc{{.*}} -triple=riscv64 +# CHECK: Exit code: 1 +# CHECK: Stderr: +# CHECK: error: expected +# CHECK: Error: Failed to update test diff --git a/llvm/utils/update_mc_test_checks.py b/llvm/utils/update_mc_test_checks.py index 565e1ad085dff..d60d1c2df5e0e 100755 --- a/llvm/utils/update_mc_test_checks.py +++ b/llvm/utils/update_mc_test_checks.py @@ -79,17 +79,24 @@ def invoke_tool( if verbose: print("Command: ", cmd) - out = subprocess.run( - cmd, - shell=True, - input=full_input.encode(), - check=check_rc, - stdout=subprocess.PIPE, - stderr=subprocess.DEVNULL, - ).stdout + try: + completed = subprocess.run( + cmd, + shell=True, + input=full_input.encode(), + check=check_rc, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + except subprocess.CalledProcessError as e: + sys.stderr.write(f"Error running command: {cmd}\n") + sys.stderr.write(f"Exit code: {e.returncode}\n") + if e.stderr: + sys.stderr.write(f"Stderr:\n{e.stderr.decode(errors='replace')}\n") + raise e # Fix line endings to unix CR style. - return out.decode().replace("\r\n", "\n") + return completed.stdout.decode().replace("\r\n", "\n") def isRunLine(l):