From 9a0f65d3d3b27f8732ae9dfe4c8254dafd31d57c Mon Sep 17 00:00:00 2001 From: Catherine Lee Date: Wed, 12 Mar 2025 15:40:06 +0000 Subject: [PATCH] [TD] test_cpp_extensions_aot_ninja corresponds to things in test/cpp_extensions (#148992) Manually map test_cpp_extensions_aot_ninja to files in test/cpp_extensions since test_cpp_extensions_aot_ninja isn't an actual file you can edit, but a wrapper for files in test/cpp_extensions. Idk if this is a good idea, feels very manual. Maybe it would be better to classify this the same as any other TD failure where TD simply can't figure out the tests it needs to run Pull Request resolved: https://github.com/pytorch/pytorch/pull/148992 Approved by: https://github.com/malfet, https://github.com/seemethere, https://github.com/janeyx99 --- .../heuristics/edited_by_pr.py | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/tools/testing/target_determination/heuristics/edited_by_pr.py b/tools/testing/target_determination/heuristics/edited_by_pr.py index b2123536521..cc4641d85ec 100644 --- a/tools/testing/target_determination/heuristics/edited_by_pr.py +++ b/tools/testing/target_determination/heuristics/edited_by_pr.py @@ -1,5 +1,6 @@ from __future__ import annotations +import re from typing import Any from warnings import warn @@ -14,6 +15,18 @@ from tools.testing.target_determination.heuristics.utils import ( from tools.testing.test_run import TestRun +# Some files run tests in other test files, so we map them to each other here. +# This is a map from file that runs the test to regex that matches the file that +# contains the test. Test file with path test/a/b.py should of the form a/b. +# Regexes should be based on repo root. +ADDITIONAL_MAPPINGS = { + # Not files that are tracked by git but rather functions defined in + # run_test.py that generate test files which run tests in test/cpp_extensions. + "test_cpp_extensions_aot_ninja": [r"test\/cpp_extensions.*"], + "test_cpp_extensions_aot_no_ninja": [r"test\/cpp_extensions.*"], +} + + class EditedByPR(HeuristicInterface): def __init__(self, **kwargs: dict[str, Any]) -> None: super().__init__(**kwargs) @@ -28,9 +41,16 @@ class EditedByPR(HeuristicInterface): def _get_modified_tests() -> set[str]: try: changed_files = query_changed_files() + should_run = python_test_file_to_test_name(set(changed_files)) + for test_file, regexes in ADDITIONAL_MAPPINGS.items(): + if any( + re.search(regex, changed_file) is not None + for regex in regexes + for changed_file in changed_files + ): + should_run.add(test_file) + return should_run except Exception as e: warn(f"Can't query changed test files due to {e}") # If unable to get changed files from git, quit without doing any sorting - return set() - - return python_test_file_to_test_name(set(changed_files)) + return set()