Skip to content

[torchci] Report C++ tests - #200980

Closed
georgehong wants to merge 5 commits into
gh/georgehong/25/basefrom
gh/georgehong/25/head
Closed

georgehong wants to merge 5 commits into
gh/georgehong/25/basefrom
gh/georgehong/25/head

Conversation

@georgehong

@georgehong georgehong commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Summary:
Writes test run reports for C++ tests. run_test.py runs them as pytest <binary> under pytest-cpp rather than through run_tests, so it registers the report plugin itself.

Each gtest is recorded as cpp/<binary>, the name run_test.py and junit already use. Its suite and test name come from gtest's JSON test list (--gtest_list_tests --gtest_output=json, one extra launch per xdist worker) rather than from splitting the full name, since a custom typed-name generator can put a . in the suite. The declared name drops a value parameter's /<param>. Only Google Test binaries are recorded, not pytest-cpp's Boost.Test or Catch2 items. Owners for cpp/<binary> are left to a follow-up.

C++ tests run under xdist with -x, which stops before the final failure's teardown report, where the writer writes the run. Runs with a known failure are now written at session end, so the failure that stops a run is no longer missing. As in junit, a crashed gtest is failed with pytest-cpp's message; a dead xdist worker's test isn't recorded, since pytest-rerunfailures only sends a test's reports after each attempt.

Test Plan:
Added unit tests, inspection of CI, and ran C++ torch test suite as smoke test on devgpu.

Authored with the help of an AI assistant (Claude).

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/200980

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit f22e421 with merge base 47383b7 (image):
💚 Looks good so far! There are no failures yet. 💚

🟡 GREEN LIGHT - OUTDATED (earlier commit) - PR requires human review:

  • Triviality
    • New feature, not a trivial class: C++ gtest runs now emit torchci report records via _gtest_identities and report.gtest_identities
    • test/run_test.py changes the pytest args for every C++ test, adding -p torch.testing._internal.torchci.plugin and --torchci-report-prefix
  • Behavior change
    • plugin.identity now launches each gtest binary with --gtest_list_tests through subprocess.run(check=True), so the plugin runs an extra process per binary per worker
    • pytest_sessionfinish now writes any run that has failed_phase set, for Python sessions as well as C++ ones
  • Socialization
    • Report records gain language value cpp and file values cpp/<binary>, per the README.md schema table, and consumers outside this repo parse that output

reason: not_trivial
Reviewed commit: 7e3de5e (NOT the current head f22e421)

Inference job

🐛 Report a wrong verdict

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@georgehong georgehong added the topic: not user facing topic category label Oct 14, 2026
@georgehong
georgehong requested review from huydhn and jathu October 14, 2026 22:10
@georgehong georgehong added ciflow/trunk Trigger trunk jobs on your pull request ci-no-td Do not run TD on this PR labels Oct 14, 2026
[ghstack-poisoned]
georgehong added a commit that referenced this pull request Oct 14, 2026
**Summary:**
C++ tests run as `pytest <binary>` under pytest-cpp, not through run_tests, so run_test.py registers the report plugin for them. Each gtest is recorded as file `cpp/<binary>`, the name run_test.py and junit already use, with language `cpp` and the suite and test name from gtest's JSON test list (`--gtest_list_tests --gtest_output=json`), which keeps them as separate fields; a full name can't always be split on its `.`, since a custom typed-name generator can put one in the suite. The plugin lists each binary once per process itself, which costs about as much as running one of its tests, rather than setting GTEST_OUTPUT around pytest-cpp's own listing. Only pytest-cpp's Google Test items are recorded. The declared name drops a value-parameterized test's `/<param>`. As in junit, a gtest whose process crashed is `failed` with pytest-cpp's message. A test's source file isn't recorded, so owners for `cpp/<binary>` are left to a follow-up.

run_test.py runs C++ tests under xdist with `-x`, which stops right after the final failing report, before the teardown report where the writer writes the run. Runs whose failure is already known are now written at session end; without that, the attempt that stops a C++ run is missing from its report. An xdist worker that dies isn't recorded: pytest-rerunfailures sends a test's reports only after each attempt, so the controller never has the identity of the test the worker was running. junit and the log still have it.

**Test Plan:**
```
python test/torchci/test_testing.py
CPP_TESTS_DIR=<dir with a gtest binary> python test/run_test.py --cpp -i cpp/<binary> --save-torchci-reports <dir>
```
`test_xdist_maxfail` fails without the session-end flush.

Authored with the help of an AI assistant (Claude).

ghstack-source-id: 99292dc
Pull-Request: #200980
@georgehong

Copy link
Copy Markdown
Contributor Author

Part of pytorch/test-infra#9102

@georgehong
georgehong marked this pull request as ready for review October 14, 2026 23:07
@georgehong
georgehong requested a review from a team as a code owner October 14, 2026 23:07
Comment thread test/run_test.py
Comment on lines +534 to +535
if not is_cpp_test:
return [f"--save-torchci-reports={reports_dir}"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, why can't we always pass this? Empty reports?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--save-torchci-reports is used by Python test files from run_tests() from common_utils.py. In comparison, C++ passes plugin args directly to pytest. If we always pass it in, it would trigger a pytest usage error for unknown options.

Comment thread test/run_test.py Outdated
return [f"--save-torchci-reports={reports_dir}"]
# C++ tests run under pytest-cpp, not run_tests, so register the plugin here.
prefix = Path(reports_dir) / sanitize_test_filename(test_file)
plugin = "torch.testing._internal.torchci.plugin"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can get this by importing plugin and getting the module name.

from torch.testing._internal.torchci import plugin

plugin._some_method_that_gives_module_name

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion incorporated - thanks!

gtest adds an instantiation's ``Prefix/`` and a typed suite's ``/<type>`` to
the suite, and a value-parameterized test's ``/<param>`` to the test name; the
declared name drops that ``/<param>``."""
file = f"cpp/{Path(binary).stem}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do wonder, do we even need the cpp/? The "language" column already tells us that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run_test.py takes the same name, taking -i cpp/test_api, and this seems to be what our codebase currently uses throughout. C++ tests appear to go by cpp/binary: https://github.com/pytorch/pytorch/blob/main/.ci/pytorch/test.sh also has extensive usage of this with --cpp.

@huydhn

huydhn commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

@claude Review this change

@claude

claude Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Claude finished @huydhn's task in 1m 37s —— View job


I found no correctness problems in this PR. There are two small cleanups and one optional testing gap, and none of them blocks merging.

PR Review: #200980

Summary

The PR registers the torchci report plugin for C++ tests run under pytest-cpp. It names each gtest from the binary's JSON test list. It also writes out runs that already failed but whose teardown report never arrived because -x stopped the session. No REVIEW.md files apply. I found no correctness issues; the findings below are cleanups.

Code Quality

  • The plugin args are now built in two places. test/run_test.py:536-539 repeats the -p torch.testing._internal.torchci.plugin --torchci-report-prefix=<dir>/<sanitized file> list that torch/testing/_internal/common_utils.py:1629-1630 already builds for Python tests. Both copies hardcode the module string and the sanitize_test_filename prefix rule. If one changes, C++ and Python reports can silently end up with different names. Suggested fix: move this into one helper in torch/testing/_internal/torchci, for example pytest_args(reports_dir, test_file), that uses plugin.__name__, and call it from both places. This would also cover jathu's comment on run_test.py:538. run_test.py already imports sanitize_test_filename from common_utils, so the import is not a new dependency.
  • The new pytest_sessionfinish comment says the flush is for C++ tests only (torch/testing/_internal/torchci/plugin.py:232-234). The loop actually runs for every session, and get_pytest_args passes -x to Python tests too (run_test.py:1440,1452), often together with -n. So Python xdist runs get the same fix, a behavior change the Dr. CI summary also flagged. Suggested fix: reword the comment to describe the general case, i.e. xdist with -x drops the teardown report of the test that stopped the session.

Testing

  • No test covers the full gtest path. Low confidence, optional. That path is a real CppItem going through pytest_runtest_makereport, then xdist serialization of _TEST_ID, then ReportWriter, including the crashed-gtest case that the README now documents ("failed, with pytest-cpp's message"). test_gtest_item_identity builds a CppItem via object.__new__ and sets path, facade and name by hand. That checks identity(), but it depends on pytest-cpp internals and skips the writer. A small end-to-end test would pin the documented crash behavior. It could fake a gtest binary, for example a script that answers --gtest_list_tests, --gtest_output=json and --gtest_filter, and run it under -p pytest_cpp.

Recommendation

Approve. Nothing blocks merging. I'd still fix the duplicated arg construction and the misleading comment before landing.

@huydhn huydhn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@georgehong georgehong added the keep-going Don't stop on first failure, keep running tests until the end label Oct 15, 2026
[ghstack-poisoned]
georgehong added a commit that referenced this pull request Oct 15, 2026
**Summary:**
C++ tests run as `pytest <binary>` under pytest-cpp, not through run_tests, so run_test.py registers the report plugin for them. Each gtest is recorded as file `cpp/<binary>`, the name run_test.py and junit already use, with language `cpp` and the suite and test name from gtest's JSON test list (`--gtest_list_tests --gtest_output=json`), which keeps them as separate fields; a full name can't always be split on its `.`, since a custom typed-name generator can put one in the suite. The plugin lists each binary once per process itself, which costs about as much as running one of its tests, rather than setting GTEST_OUTPUT around pytest-cpp's own listing. Only pytest-cpp's Google Test items are recorded. The declared name drops a value-parameterized test's `/<param>`. As in junit, a gtest whose process crashed is `failed` with pytest-cpp's message. A test's source file isn't recorded, so owners for `cpp/<binary>` are left to a follow-up.

run_test.py runs C++ tests under xdist with `-x`, which stops right after the final failing report, before the teardown report where the writer writes the run. Runs whose failure is already known are now written at session end; without that, the attempt that stops a C++ run is missing from its report. An xdist worker that dies isn't recorded: pytest-rerunfailures sends a test's reports only after each attempt, so the controller never has the identity of the test the worker was running. junit and the log still have it.

**Test Plan:**
```
python test/torchci/test_testing.py
CPP_TESTS_DIR=<dir with a gtest binary> python test/run_test.py --cpp -i cpp/<binary> --save-torchci-reports <dir>
```
`test_xdist_maxfail` fails without the session-end flush.

Authored with the help of an AI assistant (Claude).

ghstack-source-id: 9089b90
Pull-Request: #200980
@georgehong georgehong removed keep-going Don't stop on first failure, keep running tests until the end ci-no-td Do not run TD on this PR labels Oct 15, 2026
[ghstack-poisoned]
georgehong added a commit that referenced this pull request Oct 15, 2026
**Summary:**
C++ tests run as `pytest <binary>` under pytest-cpp, not through run_tests, so run_test.py registers the report plugin for them. Each gtest is recorded as file `cpp/<binary>`, the name run_test.py and junit already use, with language `cpp` and the suite and test name from gtest's JSON test list (`--gtest_list_tests --gtest_output=json`), which keeps them as separate fields; a full name can't always be split on its `.`, since a custom typed-name generator can put one in the suite. The plugin lists each binary once per process itself, which costs about as much as running one of its tests, rather than setting GTEST_OUTPUT around pytest-cpp's own listing. Only pytest-cpp's Google Test items are recorded. The declared name drops a value-parameterized test's `/<param>`. As in junit, a gtest whose process crashed is `failed` with pytest-cpp's message. A test's source file isn't recorded, so owners for `cpp/<binary>` are left to a follow-up.

run_test.py runs C++ tests under xdist with `-x`, which stops right after the final failing report, before the teardown report where the writer writes the run. Runs whose failure is already known are now written at session end; without that, the attempt that stops a C++ run is missing from its report. An xdist worker that dies isn't recorded: pytest-rerunfailures sends a test's reports only after each attempt, so the controller never has the identity of the test the worker was running. junit and the log still have it.

**Test Plan:**
```
python test/torchci/test_testing.py
CPP_TESTS_DIR=<dir with a gtest binary> python test/run_test.py --cpp -i cpp/<binary> --save-torchci-reports <dir>
```
`test_xdist_maxfail` fails without the session-end flush.

Authored with the help of an AI assistant (Claude).

ghstack-source-id: 2a6a5da
Pull-Request: #200980
@georgehong

georgehong commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

rebase onto timeout/crash handling PR to avoid merge conflict

@georgehong

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 STARTUP failures reported, please check workflows syntax!

Details for Dev Infra team Raised by workflow job

[ghstack-poisoned]
georgehong added a commit that referenced this pull request Oct 15, 2026
**Summary:**
C++ tests run as `pytest <binary>` under pytest-cpp, not through run_tests, so run_test.py registers the report plugin for them. Each gtest is recorded as file `cpp/<binary>`, the name run_test.py and junit already use, with language `cpp` and the suite and test name from gtest's JSON test list (`--gtest_list_tests --gtest_output=json`), which keeps them as separate fields; a full name can't always be split on its `.`, since a custom typed-name generator can put one in the suite. The plugin lists each binary once per process itself, which costs about as much as running one of its tests, rather than setting GTEST_OUTPUT around pytest-cpp's own listing. Only pytest-cpp's Google Test items are recorded. The declared name drops a value-parameterized test's `/<param>`. As in junit, a gtest whose process crashed is `failed` with pytest-cpp's message. A test's source file isn't recorded, so owners for `cpp/<binary>` are left to a follow-up.

run_test.py runs C++ tests under xdist with `-x`, which stops right after the final failing report, before the teardown report where the writer writes the run. Runs whose failure is already known are now written at session end; without that, the attempt that stops a C++ run is missing from its report. An xdist worker that dies isn't recorded: pytest-rerunfailures sends a test's reports only after each attempt, so the controller never has the identity of the test the worker was running. junit and the log still have it.

**Test Plan:**
```
python test/torchci/test_testing.py
CPP_TESTS_DIR=<dir with a gtest binary> python test/run_test.py --cpp -i cpp/<binary> --save-torchci-reports <dir>
```
`test_xdist_maxfail` fails without the session-end flush.

Authored with the help of an AI assistant (Claude).

ghstack-source-id: 1b49284
Pull-Request: #200980
@georgehong

Copy link
Copy Markdown
Contributor Author

rebase to address merge error

Reason: 1 STARTUP failures reported, please check workflows syntax!

@georgehong

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: GraphQL query
query ($owner: String!, $name: String!, $number: Int!, $cs_cursor: String, $cr_cursor: String!) {
repository(name: $name, owner: $owner) {
pullRequest(number: $number) {
commits(last: 1) {
nodes {
commit {
oid
checkSuites(first: 1, after: $cs_cursor) {
nodes {
checkRuns(first: 100, after: $cr_cursor) {
nodes {
name
conclusion
detailsUrl
databaseId
title
summary
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
}
}
}
}
}
}
, args {'name': 'pytorch', 'owner': 'pytorch', 'number': 200980, 'cs_cursor': 'Y3Vyc29yOnYyOpHPAAAAGHamGFk=', 'cr_cursor': 'Y3Vyc29yOnYyOpHPAAAAGyMUa_A='} failed: [{'message': 'Something went wrong while executing your query on 2026-10-15T17:52:34Z. Please include 83C2:1E1657:18F3748:50E093D:6AD112DA when reporting this issue.'}]

Details for Dev Infra team Raised by workflow job

@georgehong

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

pytorchmergebot pushed a commit that referenced this pull request Oct 15, 2026
…trict workflows (#201097)

**Summary:**
Continue rollout. This should be passing based on #201020 already, with the exception of `periodic-strict`, so `ci-no-td` shouldn't be necessary here.

Authored with the help of an AI assistant (Claude).
Pull Request resolved: #201097
Approved by: https://github.com/jathu, https://github.com/huydhn
ghstack dependencies: #200980
pytorchmergebot pushed a commit that referenced this pull request Oct 16, 2026
✴️ iz2: When a GitHub GraphQL call fails, mergebot's "Merge failed" comment put the whole query and its variables on the **Reason** line, about 40 lines of query text (example: #200980).

Now **Reason** shows only GitHub's error message, on one line (or "(no error message)" when the errors list is empty):

> **Reason**: GitHub GraphQL query failed: Something went wrong while executing your query on 2026-10-15T17:52:34Z. Please include `83C2:…` when reporting this issue.

The variables, raw errors and query move into "Details for Dev Infra team" as fenced blocks, each size-capped to keep the comment under GitHub's 65536-char limit. The same context also stays in the job log for every `gh_graphql` caller: `gh_graphql` prints it when it raises, and `GHGraphQLError` adds it as an exception note on Python 3.11+ (mergebot runs on 3.10, where tracebacks don't show notes). `handle_exception` becomes the module-level `format_failure_comment()` so it can be tested. The details block now also appears when there is a failing merge rule but `GH_RUN_URL` is unset.

**Exposure check:** the comment and log contain nothing sensitive. The token is sent as an HTTP header and never reaches the exception. The query text is already in this repo. The variables are owner, repo name, PR number and opaque pagination cursors. The request ID is the one GitHub asks you to share.

Test plan: `python -m unittest test_trymerge test_delete_old_branches` in `.github/scripts` (Python 3.12): 159 pass, 2 skipped. `TestFailureComment` covers the short reason, empty errors, the log output and note, the collapsed details, size caps, the merge-rule case and the no-details case.
Pull Request resolved: #201104
Approved by: https://github.com/huydhn
majing921201 pushed a commit to majing921201/pytorch that referenced this pull request Nov 16, 2026
…h#201104)

✴️ iz2: When a GitHub GraphQL call fails, mergebot's "Merge failed" comment put the whole query and its variables on the **Reason** line, about 40 lines of query text (example: pytorch#200980).

Now **Reason** shows only GitHub's error message, on one line (or "(no error message)" when the errors list is empty):

> **Reason**: GitHub GraphQL query failed: Something went wrong while executing your query on 2026-10-15T17:52:34Z. Please include `83C2:…` when reporting this issue.

The variables, raw errors and query move into "Details for Dev Infra team" as fenced blocks, each size-capped to keep the comment under GitHub's 65536-char limit. The same context also stays in the job log for every `gh_graphql` caller: `gh_graphql` prints it when it raises, and `GHGraphQLError` adds it as an exception note on Python 3.11+ (mergebot runs on 3.10, where tracebacks don't show notes). `handle_exception` becomes the module-level `format_failure_comment()` so it can be tested. The details block now also appears when there is a failing merge rule but `GH_RUN_URL` is unset.

**Exposure check:** the comment and log contain nothing sensitive. The token is sent as an HTTP header and never reaches the exception. The query text is already in this repo. The variables are owner, repo name, PR number and opaque pagination cursors. The request ID is the one GitHub asks you to share.

Test plan: `python -m unittest test_trymerge test_delete_old_branches` in `.github/scripts` (Python 3.12): 159 pass, 2 skipped. `TestFailureComment` covers the short reason, empty errors, the log output and note, the collapsed details, size caps, the merge-rule case and the no-details case.
Pull Request resolved: pytorch#201104
Approved by: https://github.com/huydhn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants