[llvm] [AMDGPU][test] fix the "not" issue in update_mc_test_check script (PR #112731)

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 17 08:37:01 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-amdgpu

Author: Brox Chen (broxigarchen)

<details>
<summary>Changes</summary>

update_mc_test_check script handle the error test( runline with "not") wrong in two cases:

1. when user select "--llvm-mc-binary" with a path, the script does not add "not" on top of the "--llvm-mc-binary" and thus getting non-zero exit code and failed.
2. When there are multiple testlines in the file while only not all testlines are expected to fail, the script need to check if the "not" is needed or not when it execute llvm-mc line by line. Otherwise the script will fail on testline which is passing.

This patch solve these two issues

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


3 Files Affected:

- (modified) llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_err.s (+2) 
- (modified) llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_err.s.expected (+3) 
- (modified) llvm/utils/update_mc_test_checks.py (+26-6) 


``````````diff
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_err.s b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_err.s
index 489bd1801d864a..b8a21f9e0162a1 100644
--- a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_err.s
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_err.s
@@ -1,3 +1,5 @@
 // RUN: not llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
 
 v_bfrev_b32 v5, v299
+
+v_bfrev_b32 v5, v1
diff --git a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_err.s.expected b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_err.s.expected
index 0a0ad51d15e056..8cb098477ae3ae 100644
--- a/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_err.s.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_mc_test_checks/Inputs/amdgpu_asm_err.s.expected
@@ -3,3 +3,6 @@
 
 v_bfrev_b32 v5, v299
 // CHECK: :[[@LINE-1]]:17: error: register index is out of range
+
+v_bfrev_b32 v5, v1
+// CHECK: v_bfrev_b32_e32 v5, v1                  ; encoding: [0x01,0x71,0x0a,0x7e]
diff --git a/llvm/utils/update_mc_test_checks.py b/llvm/utils/update_mc_test_checks.py
index f9f8cfdea418d0..cf6f8879daffcf 100755
--- a/llvm/utils/update_mc_test_checks.py
+++ b/llvm/utils/update_mc_test_checks.py
@@ -15,7 +15,6 @@
 
 mc_LIKE_TOOLS = [
     "llvm-mc",
-    "not llvm-mc",
 ]
 ERROR_RE = re.compile(r":\d+: (warning|error): .*")
 ERROR_CHECK_RE = re.compile(r"# COM: .*")
@@ -23,7 +22,7 @@
 COMMENT = {"asm": "//", "dasm": "#"}
 
 
-def invoke_tool(exe, cmd_args, testline, verbose=False):
+def invoke_tool(exe, prefix_not, cmd_args, testline, verbose=False):
     if isinstance(cmd_args, list):
         args = [applySubstitutions(a, substitutions) for a in cmd_args]
     else:
@@ -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)
+    except:
+        if prefix_not:
+            cmd = 'echo "' + testline + '" | ' + "not " + exe + " " + args
+            if verbose:
+                print("Command: ", cmd)
+            out = subprocess.check_output(cmd, shell=True)
+        else:
+            raise Exception("Command '{}' return non-zero value".format(cmd))
+
     # Fix line endings to unix CR style.
     return out.decode().replace("\r\n", "\n")
 
@@ -151,11 +163,16 @@ def main():
             assert len(commands) >= 2
             mc_cmd = " | ".join(commands[:-1])
             filecheck_cmd = commands[-1]
-            mc_tool = mc_cmd.split(" ")[0]
 
             # special handling for negating exit status
-            if mc_tool == "not":
-                mc_tool = mc_tool + " " + mc_cmd.split(" ")[1]
+            prefix_not = ""
+            mc_cmd_args = mc_cmd.split(" ")
+            if mc_cmd_args[0] == "not":
+                prefix_not = mc_cmd_args[0]
+                mc_tool = mc_cmd_args[1]
+                mc_cmd = mc_cmd[len(mc_cmd_args[0]) :].strip()
+            else:
+                mc_tool = mc_cmd_args[0]
 
             triple_in_cmd = None
             m = common.TRIPLE_ARG_RE.search(mc_cmd)
@@ -188,6 +205,7 @@ def main():
                 (
                     check_prefixes,
                     mc_tool,
+                    prefix_not,
                     mc_cmd_args,
                     triple_in_cmd,
                     march_in_cmd,
@@ -204,6 +222,7 @@ def main():
         for (
             prefixes,
             mc_tool,
+            prefix_not,
             mc_args,
             triple_in_cmd,
             march_in_cmd,
@@ -222,6 +241,7 @@ def main():
                 # get output for each testline
                 out = invoke_tool(
                     ti.args.llvm_mc_binary or mc_tool,
+                    prefix_not,
                     mc_args,
                     line,
                     verbose=ti.args.verbose,

``````````

</details>


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


More information about the llvm-commits mailing list