[llvm] added a script to update llvm-mc test file (PR #107246)
Alexander Richardson via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 16 09:55:46 PDT 2024
================
@@ -0,0 +1,349 @@
+#!/usr/bin/env python3
+"""
+A test update script. This script is a utility to update LLVM 'llvm-mc' based test cases with new FileCheck patterns.
+"""
+
+from __future__ import print_function
+
+import argparse
+import os # Used to advertise this file's name ("autogenerated_note").
+
+from UpdateTestChecks import common
+
+import subprocess
+import re
+
+mc_LIKE_TOOLS = [
+ "llvm-mc",
+ "not llvm-mc",
+]
+
+ERROR_RE = re.compile(r"(warning|error): .*")
+ERROR_CHECK_RE = re.compile(r"# COM: .*")
+OUTPUT_SKIPPED_RE = re.compile(r"(.text)")
+COMMENT = {"asm": "//", "dasm": "#"}
+
+
+def invoke_tool(exe, cmd_args, testline, verbose=False):
+ if isinstance(cmd_args, list):
+ args = [applySubstitutions(a, substitutions) for a in cmd_args]
+ else:
+ args = cmd_args
+
+ cmd = 'echo "' + testline + '" | ' + exe + " " + args
+ if verbose:
+ print("Command: ", cmd)
+ out = subprocess.check_output(cmd, shell=True)
+ # Fix line endings to unix CR style.
+ return out.decode().replace("\r\n", "\n")
+
+
+# create tests line-by-line, here we just filter out the check lines and comments
+# and treat all others as tests
+def isTestLine(input_line, mc_mode):
+ # Skip comment lines
+ if input_line.strip(" \t\r").startswith(COMMENT[mc_mode]):
+ return False
+ elif input_line.strip(" \t\r") == "":
+ return False
+ # skip any CHECK lines.
+ elif common.CHECK_RE.match(input_line):
+ return False
+ return True
+
+
+def hasErr(err):
+ if err is None or len(err) == 0:
+ return False
+ if ERROR_RE.search(err):
+ return True
+ return False
+
+
+def getErrString(err):
+ if err is None or len(err) == 0:
+ return ""
+
+ lines = err.split("\n")
+ # take the first match
+ for line in lines:
----------------
arichardson wrote:
```suggestion
# take the first match
for line in err.splitlines():
```
https://github.com/llvm/llvm-project/pull/107246
More information about the llvm-commits
mailing list