Skip to content

Commit 891d511

Browse files
[UpdateTestChecks][llvm-mca] Use common.itertests in update_mca_test_checks (llvm#67477)
common.itertests has useful functionality such as skipping test case if it starts with UTC_AVOID comment string. It also does some of the functionality, such as skipping test file pattern if not found, that was duplicated by update_mca_test_checks. This patch uses this function to take advantage of extra behavior and remove duplication.
1 parent 7d6c3a2 commit 891d511

File tree

1 file changed

+41
-43
lines changed

1 file changed

+41
-43
lines changed

llvm/utils/update_mca_test_checks.py

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def _showwarning(message, category, filename, lineno, file=None, line=None):
5252
file.write(warnings.formatwarning(message, category, filename, lineno, line))
5353

5454

55-
def _parse_args():
55+
def _get_parser():
5656
parser = argparse.ArgumentParser(description=__doc__)
5757
parser.add_argument("-w", action="store_true", help="suppress warnings")
5858
parser.add_argument(
@@ -65,18 +65,7 @@ def _parse_args():
6565
help="the binary to use to generate the test case " "(default: llvm-mca)",
6666
)
6767
parser.add_argument("tests", metavar="<test-path>", nargs="+")
68-
args = common.parse_commandline_args(parser)
69-
70-
_configure_warnings(args)
71-
72-
if not args.llvm_mca_binary:
73-
raise Error("--llvm-mca-binary value cannot be empty string")
74-
75-
if "llvm-mca" not in os.path.basename(args.llvm_mca_binary):
76-
_warn("unexpected binary name: {}".format(args.llvm_mca_binary))
77-
78-
return args
79-
68+
return parser
8069

8170
def _get_run_infos(run_lines, args):
8271
run_infos = []
@@ -546,39 +535,48 @@ def _write_output(
546535
f.writelines(["{}\n".format(l).encode("utf-8") for l in output_lines])
547536

548537

538+
def update_test_file(args, test_path, autogenerated_note):
539+
sys.stderr.write("Test: {}\n".format(test_path))
540+
541+
# Call this per test. By default each warning will only be written once
542+
# per source location. Reset the warning filter so that now each warning
543+
# will be written once per source location per test.
544+
_configure_warnings(args)
545+
546+
with open(test_path) as f:
547+
input_lines = [l.rstrip() for l in f]
548+
549+
run_lines = common.find_run_lines(test_path, input_lines)
550+
run_infos = _get_run_infos(run_lines, args)
551+
common_prefix, prefix_pad = _get_useful_prefix_info(run_infos)
552+
block_infos = _get_block_infos(run_infos, test_path, args, common_prefix)
553+
_write_output(
554+
test_path,
555+
input_lines,
556+
run_infos,
557+
block_infos,
558+
args,
559+
common_prefix,
560+
prefix_pad,
561+
)
562+
549563
def main():
550-
args = _parse_args()
551-
test_paths = [test for pattern in args.tests for test in glob.glob(pattern)]
552-
for test_path in test_paths:
553-
sys.stderr.write("Test: {}\n".format(test_path))
554-
555-
# Call this per test. By default each warning will only be written once
556-
# per source location. Reset the warning filter so that now each warning
557-
# will be written once per source location per test.
558-
_configure_warnings(args)
559-
560-
if not os.path.isfile(test_path):
561-
raise Error("could not find test file: {}".format(test_path))
562-
563-
with open(test_path) as f:
564-
input_lines = [l.rstrip() for l in f]
565-
566-
run_lines = common.find_run_lines(test_path, input_lines)
567-
run_infos = _get_run_infos(run_lines, args)
568-
common_prefix, prefix_pad = _get_useful_prefix_info(run_infos)
569-
block_infos = _get_block_infos(run_infos, test_path, args, common_prefix)
570-
_write_output(
571-
test_path,
572-
input_lines,
573-
run_infos,
574-
block_infos,
575-
args,
576-
common_prefix,
577-
prefix_pad,
578-
)
564+
script_name = "utils/" + os.path.basename(__file__)
565+
parser = _get_parser()
566+
args = common.parse_commandline_args(parser)
567+
if not args.llvm_mca_binary:
568+
raise Error("--llvm-mca-binary value cannot be empty string")
579569

580-
return 0
570+
if "llvm-mca" not in os.path.basename(args.llvm_mca_binary):
571+
_warn("unexpected binary name: {}".format(args.llvm_mca_binary))
581572

573+
for ti in common.itertests(args.tests, parser, script_name=script_name):
574+
try:
575+
update_test_file(ti.args, ti.path, ti.test_autogenerated_note)
576+
except Exception:
577+
common.warn("Error processing file", test_file=ti.path)
578+
raise
579+
return 0
582580

583581
if __name__ == "__main__":
584582
try:

0 commit comments

Comments
 (0)