Common main() function for op tests. This handles the common argparse setup, rebuild logic, and generate/compare/run action handling that is shared across all op tests. Args: test_factory: A callable that takes parsed args (argparse.Namespace) and returns an Op
(
test_factory,
description: str,
add_args_fn=None,
)
| 1055 | |
| 1056 | |
| 1057 | def run_op_test_main( |
| 1058 | test_factory, |
| 1059 | description: str, |
| 1060 | add_args_fn=None, |
| 1061 | ): |
| 1062 | """ |
| 1063 | Common main() function for op tests. |
| 1064 | |
| 1065 | This handles the common argparse setup, rebuild logic, and generate/compare/run |
| 1066 | action handling that is shared across all op tests. |
| 1067 | |
| 1068 | Args: |
| 1069 | test_factory: A callable that takes parsed args (argparse.Namespace) and |
| 1070 | returns an OpTestCase instance. |
| 1071 | description: Description for the argparse help message. |
| 1072 | add_args_fn: Optional callable that takes a parser and adds test-specific |
| 1073 | arguments. Signature: add_args_fn(parser) -> None |
| 1074 | """ |
| 1075 | import argparse |
| 1076 | import sys |
| 1077 | |
| 1078 | parser = argparse.ArgumentParser(description=description) |
| 1079 | parser.add_argument( |
| 1080 | "action", |
| 1081 | choices=["generate", "compare", "run"], |
| 1082 | help="Action to perform: generate (create test files), compare (compare outputs), run (full test)", |
| 1083 | ) |
| 1084 | parser.add_argument("--verbose", "-v", action="store_true", help="Verbose output") |
| 1085 | parser.add_argument( |
| 1086 | "--rebuild", |
| 1087 | action="store_true", |
| 1088 | help="Rebuild the C++ test runner before running", |
| 1089 | ) |
| 1090 | |
| 1091 | # Add test-specific arguments |
| 1092 | if add_args_fn is not None: |
| 1093 | add_args_fn(parser) |
| 1094 | |
| 1095 | args = parser.parse_args() |
| 1096 | |
| 1097 | # Rebuild if requested |
| 1098 | if args.rebuild: |
| 1099 | if not rebuild_op_test_runner(verbose=args.verbose): |
| 1100 | sys.exit(1) |
| 1101 | |
| 1102 | # Create test case from factory |
| 1103 | test = test_factory(args) |
| 1104 | |
| 1105 | if args.action == "generate": |
| 1106 | pte_path, input_path, expected_path = test.generate_test_files( |
| 1107 | verbose=args.verbose |
| 1108 | ) |
| 1109 | print("\nGenerated files:") |
| 1110 | print(f" PTE: {pte_path}") |
| 1111 | print(f" Input: {input_path}") |
| 1112 | print(f" Expected: {expected_path}") |
| 1113 | print_mlx_graph_summary(pte_path) |
| 1114 |
nothing calls this directly
no test coverage detected