diff options
author | Alex Richardson <Alexander.Richardson@cl.cam.ac.uk> | 2020-07-07 16:38:28 +0100 |
---|---|---|
committer | Alex Richardson <Alexander.Richardson@cl.cam.ac.uk> | 2020-07-08 10:59:28 +0100 |
commit | aae413462fae16c481df31ff23b951c5df494a60 (patch) | |
tree | 8a5f9b32f8bee2024cc36ef266ffd4f29d774609 /llvm/utils/UpdateTestChecks/common.py | |
parent | fb75451775f83c04d53e4e94bb4bd298ea9a882f (diff) | |
download | llvm-aae413462fae16c481df31ff23b951c5df494a60.zip llvm-aae413462fae16c481df31ff23b951c5df494a60.tar.gz llvm-aae413462fae16c481df31ff23b951c5df494a60.tar.bz2 |
[UpdateTestChecks] Move more update_test_checks.py logic to common.py
I intend to reuse this to add UTC_ARGS support for update_llc_test_checks.py
and update_cc_test_checks.py in D78478.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D78618
Diffstat (limited to 'llvm/utils/UpdateTestChecks/common.py')
-rw-r--r-- | llvm/utils/UpdateTestChecks/common.py | 81 |
1 files changed, 78 insertions, 3 deletions
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py index 9abb8d79..7b4a9b3 100644 --- a/llvm/utils/UpdateTestChecks/common.py +++ b/llvm/utils/UpdateTestChecks/common.py @@ -1,9 +1,10 @@ from __future__ import print_function + +import copy +import glob import re -import string import subprocess import sys -import copy if sys.version_info[0] > 2: class string: @@ -21,11 +22,85 @@ def parse_commandline_args(parser): help='Show verbose output') parser.add_argument('-u', '--update-only', action='store_true', help='Only update test if it was already autogened') + parser.add_argument('--force-update', action='store_true', + help='Update test even if it was autogened by a different script') + parser.add_argument('--enable', action='store_true', dest='enabled', default=True, + help='Activate CHECK line generation from this point forward') + parser.add_argument('--disable', action='store_false', dest='enabled', + help='Deactivate CHECK line generation from this point forward') args = parser.parse_args() global _verbose _verbose = args.verbose return args + +class InputLineInfo(object): + def __init__(self, line, line_number, args, argv): + self.line = line + self.line_number = line_number + self.args = args + self.argv = argv + + +class TestInfo(object): + def __init__(self, test, parser, script_name, input_lines, args, argv, + comment_prefix): + self.parser = parser + self.path = test + self.args = args + self.argv = argv + self.input_lines = input_lines + self.run_lines = find_run_lines(test, self.input_lines) + self.comment_prefix = comment_prefix + if self.comment_prefix is None: + if self.path.endswith('.mir'): + self.comment_prefix = '#' + else: + self.comment_prefix = ';' + self.autogenerated_note_prefix = self.comment_prefix + ' ' + UTC_ADVERT + self.test_autogenerated_note = self.autogenerated_note_prefix + script_name + self.test_autogenerated_note += get_autogennote_suffix(parser, self.args) + + def iterlines(self, output_lines): + output_lines.append(self.test_autogenerated_note) + for line_num, input_line in enumerate(self.input_lines): + # Discard any previous script advertising. + if input_line.startswith(self.autogenerated_note_prefix): + continue + self.args, self.argv = check_for_command(input_line, self.parser, + self.args, self.argv) + if not self.args.enabled: + output_lines.append(input_line) + continue + yield InputLineInfo(input_line, line_num, self.args, self.argv) + + +def itertests(test_patterns, parser, script_name, comment_prefix=None): + for pattern in test_patterns: + # On Windows we must expand the patterns ourselves. + tests_list = glob.glob(pattern) + if not tests_list: + warn("Test file pattern '%s' was not found. Ignoring it." % (pattern,)) + continue + for test in tests_list: + with open(test) as f: + input_lines = [l.rstrip() for l in f] + args = parser.parse_args() + argv = sys.argv[:] + first_line = input_lines[0] if input_lines else "" + if UTC_ADVERT in first_line: + if script_name not in first_line and not args.force_update: + warn("Skipping test which wasn't autogenerated by " + script_name, test) + continue + args, argv = check_for_command(first_line, parser, args, argv) + elif args.update_only: + assert UTC_ADVERT not in first_line + warn("Skipping test which isn't autogenerated: " + test) + continue + yield TestInfo(test, parser, script_name, input_lines, args, argv, + comment_prefix) + + def should_add_line_to_output(input_line, prefix_set): # Skip any blank comment lines in the IR. if input_line.strip() == ';': @@ -57,7 +132,6 @@ def invoke_tool(exe, cmd_args, ir): return stdout.replace('\r\n', '\n') ##### LLVM IR parser - RUN_LINE_RE = re.compile(r'^\s*(?://|[;#])\s*RUN:\s*(.*)$') CHECK_PREFIX_RE = re.compile(r'--?check-prefix(?:es)?[= ](\S+)') PREFIX_RE = re.compile('^[a-zA-Z0-9_-]+$') @@ -65,6 +139,7 @@ CHECK_RE = re.compile(r'^\s*(?://|[;#])\s*([^:]+?)(?:-NEXT|-NOT|-DAG|-LABEL|-SAM UTC_ARGS_KEY = 'UTC_ARGS:' UTC_ARGS_CMD = re.compile(r'.*' + UTC_ARGS_KEY + '\s*(?P<cmd>.*)\s*$') +UTC_ADVERT = 'NOTE: Assertions have been autogenerated by ' OPT_FUNCTION_RE = re.compile( r'^\s*define\s+(?:internal\s+)?[^@]*@(?P<func>[\w.-]+?)\s*' |