[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
Wed Oct 23 15:18:22 PDT 2024
https://github.com/broxigarchen updated https://github.com/llvm/llvm-project/pull/112731
>From 1d7ae3ed8142918e96e6a83ae9b4fa205f82ff02 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/3] 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 | 10 +++-
llvm/utils/update_mc_test_checks.py | 55 +++++++++++++++----
3 files changed, 57 insertions(+), 13 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 0a0ad51d15e056..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
+// 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/update_mc_test_checks.py b/llvm/utils/update_mc_test_checks.py
index f9f8cfdea418d0..f600eb2843e7eb 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, 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)
+ else:
+ raise Exception("Command '{}' return non-zero value".format(cmd))
+
# Fix line endings to unix CR style.
return out.decode().replace("\r\n", "\n")
@@ -97,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():
@@ -151,11 +171,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 +213,7 @@ def main():
(
check_prefixes,
mc_tool,
+ prefix_not,
mc_cmd_args,
triple_in_cmd,
march_in_cmd,
@@ -204,6 +230,7 @@ def main():
for (
prefixes,
mc_tool,
+ prefix_not,
mc_args,
triple_in_cmd,
march_in_cmd,
@@ -222,6 +249,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,
@@ -278,6 +306,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
@@ -294,9 +325,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.append(gen_prefix.rstrip("\n"))
>From e26ab3758dde5d195e6d9a0f221e4faec78798e9 Mon Sep 17 00:00:00 2001
From: guochen2 <guochen2 at amd.com>
Date: Fri, 18 Oct 2024 12:31:06 -0400
Subject: [PATCH 2/3] replace check_output to run
---
llvm/utils/update_mc_test_checks.py | 36 ++++++++++++++---------------
1 file changed, 17 insertions(+), 19 deletions(-)
diff --git a/llvm/utils/update_mc_test_checks.py b/llvm/utils/update_mc_test_checks.py
index f600eb2843e7eb..d05b2e4054d35e 100755
--- a/llvm/utils/update_mc_test_checks.py
+++ b/llvm/utils/update_mc_test_checks.py
@@ -22,7 +22,7 @@
COMMENT = {"asm": "//", "dasm": "#"}
-def invoke_tool(exe, prefix_not, 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:
@@ -32,18 +32,13 @@ def invoke_tool(exe, prefix_not, cmd_args, testline, verbose=False):
if verbose:
print("Command: ", cmd)
- # 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)
- else:
- raise Exception("Command '{}' return non-zero value".format(cmd))
+ 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")
@@ -173,10 +168,13 @@ def main():
filecheck_cmd = commands[-1]
# special handling for negating exit status
- prefix_not = ""
- mc_cmd_args = mc_cmd.split(" ")
+ # 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":
- prefix_not = mc_cmd_args[0]
+ checkRC = False
mc_tool = mc_cmd_args[1]
mc_cmd = mc_cmd[len(mc_cmd_args[0]) :].strip()
else:
@@ -213,7 +211,7 @@ def main():
(
check_prefixes,
mc_tool,
- prefix_not,
+ checkRC,
mc_cmd_args,
triple_in_cmd,
march_in_cmd,
@@ -230,7 +228,7 @@ def main():
for (
prefixes,
mc_tool,
- prefix_not,
+ checkRC,
mc_args,
triple_in_cmd,
march_in_cmd,
@@ -249,7 +247,7 @@ def main():
# get output for each testline
out = invoke_tool(
ti.args.llvm_mc_binary or mc_tool,
- prefix_not,
+ checkRC,
mc_args,
line,
verbose=ti.args.verbose,
>From 5de06e283b1965cc2aba56ecd54969440277a551 Mon Sep 17 00:00:00 2001
From: Brox Chen <guochen2 at amd.com>
Date: Wed, 23 Oct 2024 18:18:13 -0400
Subject: [PATCH 3/3] add a comment message
---
llvm/utils/update_mc_test_checks.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/llvm/utils/update_mc_test_checks.py b/llvm/utils/update_mc_test_checks.py
index d05b2e4054d35e..dc32a32ac3042e 100755
--- a/llvm/utils/update_mc_test_checks.py
+++ b/llvm/utils/update_mc_test_checks.py
@@ -13,6 +13,8 @@
import subprocess
import re
+# llvm-mc is the only mc-like in the LLVM tree but downstream forks can add
+# additional ones here if they have them.
mc_LIKE_TOOLS = [
"llvm-mc",
]
More information about the llvm-commits
mailing list