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

Brox Chen via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 29 10:58:20 PDT 2024


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

>From 9ced142a1607141e84d9841432541b9de22e2577 Mon Sep 17 00:00:00 2001
From: guochen2 <guochen2 at amd.com>
Date: Thu, 17 Oct 2024 11:30:02 -0400
Subject: [PATCH 1/2] fix an issue in update_mc_script that the error case is
 not handle properly

---
 .../Inputs/amdgpu_asm_err.s                   |  5 +-
 .../Inputs/amdgpu_asm_err.s.expected          | 12 +++--
 llvm/utils/UpdateTestChecks/common.py         |  1 +
 llvm/utils/update_mc_test_checks.py           | 53 +++++++++++++++----
 4 files changed, 57 insertions(+), 14 deletions(-)

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..76f8e7880d836e 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,6 @@
-// RUN: not llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
+// RUN: not llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECKA %s
+// RUN: not llvm-mc -triple=amdgcn %s 2>&1 | FileCheck --check-prefixes=CHECKB %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 ca287fc2d63209..c34e30d9152873 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
@@ -1,5 +1,11 @@
-// NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py
-// RUN: not llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
+; NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py
+// RUN: not llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECKA %s
+// RUN: not llvm-mc -triple=amdgcn %s 2>&1 | FileCheck --check-prefixes=CHECKB %s
 
 v_bfrev_b32 v5, v299
-// CHECK: :[[@LINE-1]]:17: error: register index is out of range
+// CHECKA: :[[@LINE-1]]:17: error: register index is out of range
+// CHECKB: :[[@LINE-2]]:17: error: register index is out of range
+
+v_bfrev_b32 v5, v1
+// CHECKA: v_bfrev_b32_e32 v5, v1                  ; encoding: [0x01,0x71,0x0a,0x7e]
+// CHECKB: v_bfrev_b32_e32 v5, v1
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index cdfa8978566fb4..b108a21dbc52b8 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -2470,6 +2470,7 @@ def get_autogennote_suffix(parser, args):
             "verbose",
             "force_update",
             "reset_variable_names",
+            "llvm_mc_binary",
         ):
             continue
         value = getattr(args, action.dest)
diff --git a/llvm/utils/update_mc_test_checks.py b/llvm/utils/update_mc_test_checks.py
index 55ed6c82d4877e..32ae3cd0a5d5f2 100755
--- a/llvm/utils/update_mc_test_checks.py
+++ b/llvm/utils/update_mc_test_checks.py
@@ -16,7 +16,6 @@
 
 mc_LIKE_TOOLS = [
     "llvm-mc",
-    "not llvm-mc",
 ]
 ERROR_RE = re.compile(r":\d+: (warning|error): .*")
 ERROR_CHECK_RE = re.compile(r"# COM: .*")
@@ -24,7 +23,7 @@
 COMMENT = {"asm": "//", "dasm": "#"}
 
 
-def invoke_tool(exe, cmd_args, testline, verbose=False):
+def invoke_tool(exe, checkRC, cmd_args, testline, verbose=False):
     if isinstance(cmd_args, list):
         args = [applySubstitutions(a, substitutions) for a in cmd_args]
     else:
@@ -33,7 +32,15 @@ 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)
+
+    out = subprocess.run(
+        cmd,
+        shell=True,
+        check=checkRC,
+        stdout=subprocess.PIPE,
+        stderr=subprocess.DEVNULL,
+    ).stdout
+
     # Fix line endings to unix CR style.
     return out.decode().replace("\r\n", "\n")
 
@@ -102,8 +109,16 @@ def getStdCheckLine(prefix, output, mc_mode):
     return o
 
 
-def getErrCheckLine(prefix, output, mc_mode):
-    return COMMENT[mc_mode] + " " + prefix + ": " + ":[[@LINE-1]]" + output + "\n"
+def getErrCheckLine(prefix, output, mc_mode, line_offset=1):
+    return (
+        COMMENT[mc_mode]
+        + " "
+        + prefix
+        + ": "
+        + ":[[@LINE-{}]]".format(line_offset)
+        + output
+        + "\n"
+    )
 
 
 def main():
@@ -174,11 +189,19 @@ 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]
+            # if not is used in runline, disable rc check, since
+            # the command might or might not
+            # return non-zero code on a single line run
+            checkRC = True
+            mc_cmd_args = mc_cmd.strip().split()
+            if mc_cmd_args[0] == "not":
+                checkRC = False
+                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)
@@ -211,6 +234,7 @@ def main():
                 (
                     check_prefixes,
                     mc_tool,
+                    checkRC,
                     mc_cmd_args,
                     triple_in_cmd,
                     march_in_cmd,
@@ -231,6 +255,7 @@ def main():
         for (
             prefixes,
             mc_tool,
+            checkRC,
             mc_args,
             triple_in_cmd,
             march_in_cmd,
@@ -249,6 +274,7 @@ def main():
                 # get output for each testline
                 out = invoke_tool(
                     ti.args.llvm_mc_binary or mc_tool,
+                    checkRC,
                     mc_args,
                     line,
                     verbose=ti.args.verbose,
@@ -305,6 +331,9 @@ def main():
             # each run_id can only be used once
             gen_prefix = ""
             used_runid = set()
+
+            # line number diff between generated prefix and testline
+            line_offset = 1
             for prefix, tup in p_dict_sorted.items():
                 o, run_ids = tup
 
@@ -321,9 +350,13 @@ def main():
                     used_prefixes.add(prefix)
 
                     if hasErr(o):
-                        gen_prefix += getErrCheckLine(prefix, o, mc_mode)
+                        newline = getErrCheckLine(prefix, o, mc_mode, line_offset)
                     else:
-                        gen_prefix += getStdCheckLine(prefix, o, mc_mode)
+                        newline = getStdCheckLine(prefix, o, mc_mode)
+
+                    if newline:
+                        gen_prefix += newline
+                        line_offset += 1
 
             generated_prefixes[input_line] = gen_prefix.rstrip("\n")
 

>From 2cd440c5df74407e59282a5ce4b9a672b43a0c27 Mon Sep 17 00:00:00 2001
From: Brox Chen <guochen2 at amd.com>
Date: Tue, 29 Oct 2024 10:44:54 -0400
Subject: [PATCH 2/2] use check_rc

---
 llvm/utils/update_mc_test_checks.py | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/llvm/utils/update_mc_test_checks.py b/llvm/utils/update_mc_test_checks.py
index 32ae3cd0a5d5f2..c8a40b37088ae4 100755
--- a/llvm/utils/update_mc_test_checks.py
+++ b/llvm/utils/update_mc_test_checks.py
@@ -23,7 +23,7 @@
 COMMENT = {"asm": "//", "dasm": "#"}
 
 
-def invoke_tool(exe, checkRC, cmd_args, testline, verbose=False):
+def invoke_tool(exe, check_rc, cmd_args, testline, verbose=False):
     if isinstance(cmd_args, list):
         args = [applySubstitutions(a, substitutions) for a in cmd_args]
     else:
@@ -36,7 +36,7 @@ def invoke_tool(exe, checkRC, cmd_args, testline, verbose=False):
     out = subprocess.run(
         cmd,
         shell=True,
-        check=checkRC,
+        check=check_rc,
         stdout=subprocess.PIPE,
         stderr=subprocess.DEVNULL,
     ).stdout
@@ -194,10 +194,10 @@ def main():
             # if not is used in runline, disable rc check, since
             # the command might or might not
             # return non-zero code on a single line run
-            checkRC = True
+            check_rc = True
             mc_cmd_args = mc_cmd.strip().split()
             if mc_cmd_args[0] == "not":
-                checkRC = False
+                check_rc = False
                 mc_tool = mc_cmd_args[1]
                 mc_cmd = mc_cmd[len(mc_cmd_args[0]) :].strip()
             else:
@@ -234,7 +234,7 @@ def main():
                 (
                     check_prefixes,
                     mc_tool,
-                    checkRC,
+                    check_rc,
                     mc_cmd_args,
                     triple_in_cmd,
                     march_in_cmd,
@@ -255,7 +255,7 @@ def main():
         for (
             prefixes,
             mc_tool,
-            checkRC,
+            check_rc,
             mc_args,
             triple_in_cmd,
             march_in_cmd,
@@ -274,7 +274,7 @@ def main():
                 # get output for each testline
                 out = invoke_tool(
                     ti.args.llvm_mc_binary or mc_tool,
-                    checkRC,
+                    check_rc,
                     mc_args,
                     line,
                     verbose=ti.args.verbose,



More information about the llvm-commits mailing list