[UpdateTestChecks] Update tests option
Summary:
Port of new feature introduced https://reviews.llvm.org/D65610 to other update scripts.
- update_*_checks.py: add an alias -u for --update-only
- port --update-only to other update_*_test_checks.py scripts
- update script aborts if the test file was generated by another update_*_test_checks.py utility
Reviewers: lebedev.ri, RKSimon, MaskRay, reames, gbedwell
Reviewed By: MaskRay
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65793
llvm-svn: 368174
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index 336ccb9..ecb3a0f 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -72,6 +72,17 @@
SCRUB_LOOP_COMMENT_RE = re.compile(
r'# =>This Inner Loop Header:.*|# in Loop:.*', flags=re.M)
+
+def error(msg, test_file=None):
+ if test_file:
+ msg = '{}: {}'.format(msg, test_file)
+ print('ERROR: {}'.format(msg), file=sys.stderr)
+
+def warn(msg, test_file=None):
+ if test_file:
+ msg = '{}: {}'.format(msg, test_file)
+ print('WARNING: {}'.format(msg), file=sys.stderr)
+
def scrub_body(body):
# Scrub runs of whitespace out of the assembly, but leave the leading
# whitespace in place.
@@ -108,7 +119,7 @@
if 'analysis' in m.groupdict():
analysis = m.group('analysis')
if analysis.lower() != 'cost model analysis':
- print('WARNING: Unsupported analysis mode: %r!' % (analysis,), file=sys.stderr)
+ warn('Unsupported analysis mode: %r!' % (analysis,))
if func.startswith('stress'):
# We only use the last line of the function body for stress tests.
scrubbed_body = '\n'.join(scrubbed_body.splitlines()[-1:])
@@ -123,8 +134,7 @@
continue
else:
if prefix == prefixes[-1]:
- print('WARNING: Found conflicting asm under the '
- 'same prefix: %r!' % (prefix,), file=sys.stderr)
+ warn('Found conflicting asm under the same prefix: %r!' % (prefix,))
else:
func_dict[prefix][func] = None
continue
@@ -272,8 +282,8 @@
hint = ""
if ',' in prefix:
hint = " Did you mean '--check-prefixes=" + prefix + "'?"
- print(("WARNING: Supplied prefix '%s' is invalid. Prefix must contain only alphanumeric characters, hyphens and underscores." + hint) %
- (prefix), file=sys.stderr)
+ warn(("Supplied prefix '%s' is invalid. Prefix must contain only alphanumeric characters, hyphens and underscores." + hint) %
+ (prefix))
def verify_filecheck_prefixes(fc_cmd):
@@ -287,5 +297,4 @@
for prefix in prefixes:
check_prefix(prefix)
if prefixes.count(prefix) > 1:
- print("WARNING: Supplied prefix '%s' is not unique in the prefix list." %
- (prefix,), file=sys.stderr)
+ warn("Supplied prefix '%s' is not unique in the prefix list." % (prefix,))