[llvm] [AMDGPU][test] fix the error case in update_mc_test_check script (PR #112731)

Ivan Kosarev via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 18 04:06:27 PDT 2024


================
@@ -32,7 +31,20 @@ def invoke_tool(exe, cmd_args, testline, verbose=False):
     cmd = 'echo "' + testline + '" | ' + exe + " " + args
     if verbose:
         print("Command: ", cmd)
-    out = subprocess.check_output(cmd, shell=True)
+
+    # if not is used in runline, the command might or might not
+    # return non-zero code on a single line run
+    try:
+        out = subprocess.check_output(cmd, shell=True, stderr=subprocess.DEVNULL)
+    except:
+        if prefix_not:
+            cmd = 'echo "' + testline + '" | ' + "not " + exe + " " + args
+            if verbose:
+                print("Command: ", cmd)
+            out = subprocess.check_output(cmd, shell=True, stderr=subprocess.DEVNULL)
----------------
kosarev wrote:

This invokes the same thing again with `not`, but we already have the output from the first run? The docs reads:

https://docs.python.org/3/library/subprocess.html#subprocess.check_output
> If the return code was non-zero it raises a [CalledProcessError](https://docs.python.org/3/library/subprocess.html#subprocess.CalledProcessError). The [CalledProcessError](https://docs.python.org/3/library/subprocess.html#subprocess.CalledProcessError) object will have the return code in the [returncode](https://docs.python.org/3/library/subprocess.html#subprocess.CalledProcessError.returncode) attribute and any output in the [output](https://docs.python.org/3/library/subprocess.html#subprocess.CalledProcessError.output) attribute.

https://github.com/llvm/llvm-project/pull/112731


More information about the llvm-commits mailing list