Repository navigation
fix(ctest): name the signal when a test crashes instead of reporting exit code 0 - #5047
Merged
Hannia Valera (hanniavalera) merged 3 commits intoAug 25, 2026
Conversation
…exit code 0 When a CTest test is killed by a signal or times out, CTest records the cause in the "Exit Code" measurement of Test.xml (SEGFAULT, ILLEGAL, NUMERICAL, INTERRUPT, OTHER_FAULT, Timeout, BAD_COMMAND) while the companion "Exit Value" measurement is usually 0 and "Completion Status" is still "Completed". The Test Explorer only ever looked at "Exit Value", so a segfaulting test was reported as "failed with exit code 0", which reads like success and hides the actual cause. The XML parser already stored every NamedMeasurement, so the "Exit Code" value was available but never consulted. The failure message selection now lives in a small exported helper, getTestFailureMessage, which prefers the descriptive "Exit Code" status whenever it is present and is neither the ordinary "Failed" or "Completed" marker nor a plain number, and otherwise keeps the existing exit value message unchanged. A crashed test is now reported as, for example, "Test crashing_test failed with SEGFAULT (exit value 0)." The exit value is kept in the message because on Windows it carries the exception code. Add a TestResults4.xml fixture with the exact measurements CTest writes for a segfault and for an ordinary failure, and unit tests covering the parsed measurements, the new message, and the fallback to the old message when "Exit Code" is missing, "Failed", "Completed" or numeric. Fixes microsoft#5043
Hannia Valera (hanniavalera)
approved these changes
Aug 24, 2026
Hannia Valera (hanniavalera)
enabled auto-merge (squash)
August 24, 2026 21:04
snehara99
approved these changes
Aug 25, 2026
Hannia Valera (hanniavalera)
merged commit Aug 25, 2026
a692bd3
into
microsoft:main
28 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix Test Explorer reporting a signal killed test as "failed with exit code 0"
Fixes #5043
Problem
When a test is killed by a signal (segfault, illegal instruction, abort) or times out, CTest writes two measurements into
Test.xml:Exit CodeSEGFAULTFailedExit Value01(the process exit code)Completion StatusCompletedCompletedtestResultsAnalysisinsrc/ctest.tsonly readExit ValueandCompletion Status, so a crashed test was shown in the Test Explorer as:That reads like success for a process that crashed, and the one measurement that names the cause was never consulted even though
readTestResultsFilealready parses everyNamedMeasurementinto themeasurementsmap.Fix
src/ctest.ts: add a small exported helper,getTestFailureMessage(testName, output, exitValue, exitStatus), that picks the message for a failed test that has anExit Valuemeasurement. WhenExit Codeis present and is neitherFailed,Completednor a plain number, it emits a new localized string (test.failed.with.signal) naming that status. Otherwise it returns the existingtest.failed.with.exit.codemessage unchanged.testResultsAnalysisreads theExit Codemeasurement and calls the helper. The branch structure (ctestFailedvsctestErroredvsskipped) is unchanged; only the text of the message differs for the signal/timeout case.3221225477for an access violation), which is useful alongsideSEGFAULT.After the fix the same test shows:
and an ordinary failure still shows
Test failing_test failed with exit code 1.The helper is exported only so the message selection can be unit tested without constructing a
CTestDriver; the rest of the diff is kept deliberately small and stays away from the hunks touched by #5037, #5019 and #5025.Tests
test/unit-tests/TestResults4.xmlcontaining the exact measurements CTest 4.2 writes for a segfaulting test (Exit Code=SEGFAULT,Exit Value=0,Completion Status=Completed) and for an ordinary failure (Exit Code=Failed,Exit Value=1).test/unit-tests/ctest.test.ts:Test crashing_test failed with SEGFAULTand notexit code 0, while the ordinary failure still yieldsfailed with exit code 1.undefined,Failed,Completedand numericExit Codevalues (old message) andTimeout/SEGFAULT(new message).Both new tests fail on
main(getTestFailureMessagedoes not exist) and pass with this change; the 16 existing tests inctest.test.tsstill pass.Verification performed
tsc -p test.tsconfig.json(thepreteststep): clean.eslint src/ctest.ts test/unit-tests/ctest.test.ts: clean.ctest.test.tsexecuted from the compiledout/tree with mocha and a permissivevscodemodule mock (the machine used for this change could not download the VS Code Electron build thatyarn unitTestsrequires): 18 passing with the fix, 16 passing and 2 failing without it.yarn backendTests: 386 passing.unitTestsElectron suite and an end to end run against a real segfaulting CTest project were not executed here. The issue reporter's repro (crash.c+CMakeLists.txt) is the recommended manual check.Changelog
Added a Bug Fixes entry under 1.24 in
CHANGELOG.md.Notes for reviewers
Exit CodeareFailed,Completed,Timeout,SEGFAULT,ILLEGAL,INTERRUPT,NUMERICAL,BAD_COMMANDandNot Run, plus the free text exception string CTest substitutes for other faults (for exampleSubprocess abortedfor SIGABRT on Unix, orExit code 0xc0000409on Windows), which is why the check accepts any value that is notFailed,Completedor a plain number rather than matching a fixed list. Only the first two fall through to the exit value message; everything else is surfaced by name. Numeric values are also treated as a plain exit code as a guard against future CTest changes.Exit Value=0because ofFAIL_REGULAR_EXPRESSIONorWILL_FAILstill reads "failed with exit code 0" (itsExit CodeisFailed). Distinguishing that case would need a different message and is out of scope for this issue.