From 8c0e401da78d16eeabcf022763b48832fe62b1ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Bossu?= Date: Thu, 8 Dec 2022 21:50:02 +0100 Subject: [PATCH] utils/update_mir_test_checks.py: support UTC_ARGS As a reminder, UTC_ARGS is used by lit test cases to specify which arguments need to be passed to update_XXXX_test_checks.py to be auto-updated properly. The support is achieved by relying on common.itertests, which is what other test updaters use to iterate over test files. This commit also changes how the --llc-binary option is saved in args. It used to be saved as "llc", but it is here changed to the standard "llc_binary" to make use of an existing ignore mechanism for specific arguments. Without that change, the option would not be ignored and would appear in UTC_ARGS. This would be different from what e.g. update_llc_test_checks does. As update_mir_test_checks.py now supports UTC_ARGS, it became important to ensure the option is ignored. Differential Revision: https://reviews.llvm.org/D135580 --- .../Inputs/print-stack.mir.expected | 2 +- .../update_mir_test_checks/print-stack.test | 7 ++++- llvm/utils/update_mir_test_checks.py | 30 +++++-------------- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/print-stack.mir.expected b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/print-stack.mir.expected index ef54766d78107..1cef5dec49a90 100644 --- a/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/print-stack.mir.expected +++ b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/print-stack.mir.expected @@ -1,4 +1,4 @@ -# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py +# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --print-fixed-stack # RUN: llc -mtriple=x86_64-linux-gnu -run-pass=none -o - %s | FileCheck %s # Note that this file isn't a test in itself (Inputs/ is excluded from lit's diff --git a/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/print-stack.test b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/print-stack.test index 9e828fd33697d..13c16f9ad6067 100644 --- a/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/print-stack.test +++ b/llvm/test/tools/UpdateTestChecks/update_mir_test_checks/print-stack.test @@ -2,6 +2,11 @@ ## Check that update_mir_test_checks handles --print-fixed-stack properly. ## Verify with --print-fixed-stack, the proper CHECK lines for fixedStack are -## generated. +## generated, and UTC_ARGS is written in the header comment. # RUN: cp -f %S/Inputs/print-stack-first.mir %t.mir && %update_mir_test_checks %t.mir --print-fixed-stack # RUN: diff -u %S/Inputs/print-stack.mir.expected %t.mir + +## Check that re-running without --print-fixed-stack does not change the +## CHECK lines, because of UTC_ARGS. +# RUN: %update_mir_test_checks %t.mir +# RUN: diff -u %S/Inputs/print-stack.mir.expected %t.mir diff --git a/llvm/utils/update_mir_test_checks.py b/llvm/utils/update_mir_test_checks.py index 58b193d2bd484..21f3f779b0932 100755 --- a/llvm/utils/update_mir_test_checks.py +++ b/llvm/utils/update_mir_test_checks.py @@ -322,22 +322,10 @@ def should_add_line_to_output(input_line, prefix_set): return True -def update_test_file(args, test): +def update_test_file(args, test, autogenerated_note): with open(test) as fd: input_lines = [l.rstrip() for l in fd] - script_name = os.path.basename(__file__) - first_line = input_lines[0] if input_lines else "" - if 'autogenerated' in first_line and script_name not in first_line: - common.warn("Skipping test which wasn't autogenerated by " + - script_name + ": " + test) - return - - if args.update_only: - if not first_line or 'autogenerated' not in first_line: - common.warn("Skipping test which isn't autogenerated: " + test) - return - triple_in_ir = find_triple_in_ir(input_lines, args.verbose) run_lines = common.find_run_lines(test, input_lines) run_list = build_run_list(test, run_lines, args.verbose) @@ -352,7 +340,7 @@ def update_test_file(args, test): log('Extracted LLC cmd: llc {}'.format(llc_args), args.verbose) log('Extracted FileCheck prefixes: {}'.format(prefixes), args.verbose) - raw_tool_output = args.llc(llc_args, test) + raw_tool_output = args.llc_binary(llc_args, test) if not triple_in_cmd and not triple_in_ir: common.warn('No triple found: skipping file', test_file=test) return @@ -366,9 +354,6 @@ def update_test_file(args, test): prefix_set = set([prefix for run in run_list for prefix in run.prefixes]) log('Rewriting FileCheck prefixes: {}'.format(prefix_set), args.verbose) - comment_char = '#' if test.endswith('.mir') else ';' - autogenerated_note = ('{} NOTE: Assertions have been autogenerated by ' - 'utils/{}'.format(comment_char, script_name)) output_lines = [] output_lines.append(autogenerated_note) @@ -450,19 +435,20 @@ def update_test_file(args, test): def main(): parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawTextHelpFormatter) - parser.add_argument('--llc-binary', dest='llc', default='llc', type=LLC, + parser.add_argument('--llc-binary', default='llc', type=LLC, help='The "llc" binary to generate the test case with') parser.add_argument('--print-fixed-stack', action='store_true', help='Add check lines for fixedStack') parser.add_argument('tests', nargs='+') args = common.parse_commandline_args(parser) - test_paths = [test for pattern in args.tests for test in glob.glob(pattern)] - for test in test_paths: + script_name = os.path.basename(__file__) + for ti in common.itertests(args.tests, parser, + script_name='utils/' + script_name): try: - update_test_file(args, test) + update_test_file(ti.args, ti.path, ti.test_autogenerated_note) except Exception: - common.warn('Error processing file', test_file=test) + common.warn('Error processing file', test_file=ti.path) raise