Skip to content

Commit 8c0e401

Browse files
gbossunhaehnle
authored andcommitted
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
1 parent b1a9584 commit 8c0e401

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

llvm/test/tools/UpdateTestChecks/update_mir_test_checks/Inputs/print-stack.mir.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --print-fixed-stack
22
# RUN: llc -mtriple=x86_64-linux-gnu -run-pass=none -o - %s | FileCheck %s
33

44
# Note that this file isn't a test in itself (Inputs/ is excluded from lit's

llvm/test/tools/UpdateTestChecks/update_mir_test_checks/print-stack.test

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
## Check that update_mir_test_checks handles --print-fixed-stack properly.
33

44
## Verify with --print-fixed-stack, the proper CHECK lines for fixedStack are
5-
## generated.
5+
## generated, and UTC_ARGS is written in the header comment.
66
# RUN: cp -f %S/Inputs/print-stack-first.mir %t.mir && %update_mir_test_checks %t.mir --print-fixed-stack
77
# RUN: diff -u %S/Inputs/print-stack.mir.expected %t.mir
8+
9+
## Check that re-running without --print-fixed-stack does not change the
10+
## CHECK lines, because of UTC_ARGS.
11+
# RUN: %update_mir_test_checks %t.mir
12+
# RUN: diff -u %S/Inputs/print-stack.mir.expected %t.mir

llvm/utils/update_mir_test_checks.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -322,22 +322,10 @@ def should_add_line_to_output(input_line, prefix_set):
322322
return True
323323

324324

325-
def update_test_file(args, test):
325+
def update_test_file(args, test, autogenerated_note):
326326
with open(test) as fd:
327327
input_lines = [l.rstrip() for l in fd]
328328

329-
script_name = os.path.basename(__file__)
330-
first_line = input_lines[0] if input_lines else ""
331-
if 'autogenerated' in first_line and script_name not in first_line:
332-
common.warn("Skipping test which wasn't autogenerated by " +
333-
script_name + ": " + test)
334-
return
335-
336-
if args.update_only:
337-
if not first_line or 'autogenerated' not in first_line:
338-
common.warn("Skipping test which isn't autogenerated: " + test)
339-
return
340-
341329
triple_in_ir = find_triple_in_ir(input_lines, args.verbose)
342330
run_lines = common.find_run_lines(test, input_lines)
343331
run_list = build_run_list(test, run_lines, args.verbose)
@@ -352,7 +340,7 @@ def update_test_file(args, test):
352340
log('Extracted LLC cmd: llc {}'.format(llc_args), args.verbose)
353341
log('Extracted FileCheck prefixes: {}'.format(prefixes), args.verbose)
354342

355-
raw_tool_output = args.llc(llc_args, test)
343+
raw_tool_output = args.llc_binary(llc_args, test)
356344
if not triple_in_cmd and not triple_in_ir:
357345
common.warn('No triple found: skipping file', test_file=test)
358346
return
@@ -366,9 +354,6 @@ def update_test_file(args, test):
366354
prefix_set = set([prefix for run in run_list for prefix in run.prefixes])
367355
log('Rewriting FileCheck prefixes: {}'.format(prefix_set), args.verbose)
368356

369-
comment_char = '#' if test.endswith('.mir') else ';'
370-
autogenerated_note = ('{} NOTE: Assertions have been autogenerated by '
371-
'utils/{}'.format(comment_char, script_name))
372357
output_lines = []
373358
output_lines.append(autogenerated_note)
374359

@@ -450,19 +435,20 @@ def update_test_file(args, test):
450435
def main():
451436
parser = argparse.ArgumentParser(
452437
description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
453-
parser.add_argument('--llc-binary', dest='llc', default='llc', type=LLC,
438+
parser.add_argument('--llc-binary', default='llc', type=LLC,
454439
help='The "llc" binary to generate the test case with')
455440
parser.add_argument('--print-fixed-stack', action='store_true',
456441
help='Add check lines for fixedStack')
457442
parser.add_argument('tests', nargs='+')
458443
args = common.parse_commandline_args(parser)
459444

460-
test_paths = [test for pattern in args.tests for test in glob.glob(pattern)]
461-
for test in test_paths:
445+
script_name = os.path.basename(__file__)
446+
for ti in common.itertests(args.tests, parser,
447+
script_name='utils/' + script_name):
462448
try:
463-
update_test_file(args, test)
449+
update_test_file(ti.args, ti.path, ti.test_autogenerated_note)
464450
except Exception:
465-
common.warn('Error processing file', test_file=test)
451+
common.warn('Error processing file', test_file=ti.path)
466452
raise
467453

468454

0 commit comments

Comments
 (0)