MCPcopy Create free account
hub / github.com/pytorch/executorch / run_test

Method run_test

backends/mlx/test/test_utils.py:978–1054  ·  view source on GitHub ↗

Run the full test: generate files, run C++, compare outputs. Args: verbose: Whether to print verbose output. timeout: Timeout in seconds. None means use self.timeout. Returns: True if test passed, False otherwise.

(self, verbose: bool = False, timeout: Optional[int] = None)

Source from the content-addressed store, hash-verified

976 return compare_outputs(expected, actual, rtol=rtol, atol=atol)
977
978 def run_test(self, verbose: bool = False, timeout: Optional[int] = None) -> bool:
979 """
980 Run the full test: generate files, run C++, compare outputs.
981
982 Args:
983 verbose: Whether to print verbose output.
984 timeout: Timeout in seconds. None means use self.timeout.
985
986 Returns:
987 True if test passed, False otherwise.
988 """
989 if timeout is None:
990 timeout = self.timeout
991
992 print(f"\n{'='*60}")
993 print(f"Running test: {self.name}")
994 print(f"{'='*60}\n")
995
996 # Generate test files
997 print("Step 1: Generating test files...")
998 pte_path, input_path, expected_path = self.generate_test_files(verbose=verbose)
999
1000 # Print MLX graph summary
1001 print_mlx_graph_summary(pte_path)
1002
1003 # Verify expected number of MLX delegate segments
1004 print("\nStep 2: Verifying MLX delegation...")
1005 actual_segments = count_mlx_delegate_segments(pte_path)
1006 print(f" Expected MLX segments: {self.expected_mlx_segments}")
1007 print(f" Actual MLX segments: {actual_segments}")
1008
1009 if actual_segments != self.expected_mlx_segments:
1010 print("✗ FAILED: MLX delegation mismatch!")
1011 print(
1012 f" Expected {self.expected_mlx_segments} segment(s), but found {actual_segments}"
1013 )
1014 return False
1015 print("✓ MLX delegation verified")
1016
1017 # Verify expected node counts if specified
1018 if self.expected_node_counts is not None:
1019 print("\n Verifying serialized node counts...")
1020 actual_counts = get_mlx_node_counts(pte_path)
1021 for node_name, expected_count in self.expected_node_counts.items():
1022 actual_count = actual_counts.get(node_name, 0)
1023 if actual_count != expected_count:
1024 print(f"✗ FAILED: Node count mismatch for {node_name}!")
1025 print(f" Expected {expected_count}, got {actual_count}")
1026 print(f" All node counts: {actual_counts}")
1027 return False
1028 print(f" ✓ {node_name}: {actual_count}")
1029 print(" ✓ All node counts verified")
1030
1031 # Run C++ binary
1032 print("\nStep 3: Running C++ binary...")
1033 actual_path = self.get_test_dir() / "actual_output.bin"
1034 if not run_cpp_test_runner(
1035 pte_path, input_path, actual_path, verbose=verbose, timeout=timeout

Callers 4

_run_single_testFunction · 0.45
run_tests_sequentialFunction · 0.45
run_op_test_mainFunction · 0.45

Calls 9

generate_test_filesMethod · 0.95
get_test_dirMethod · 0.95
compare_with_actualMethod · 0.95
print_mlx_graph_summaryFunction · 0.85
get_mlx_node_countsFunction · 0.85
run_cpp_test_runnerFunction · 0.85
itemsMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected