Skip to content

fix(ctest): name the signal when a test crashes instead of reporting exit code 0 - #5047

Merged
Hannia Valera (hanniavalera) merged 3 commits into
microsoft:mainfrom
Om-singhaI:fix/ctest-signal-exit-code
Aug 25, 2026
Merged

Hannia Valera (hanniavalera) merged 3 commits into
microsoft:mainfrom
Om-singhaI:fix/ctest-signal-exit-code

Conversation

@Om-singhaI

Copy link
Copy Markdown
Contributor

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:

Measurement Crash (segfault) Ordinary failure
Exit Code SEGFAULT Failed
Exit Value 0 1 (the process exit code)
Completion Status Completed Completed

testResultsAnalysis in src/ctest.ts only read Exit Value and Completion Status, so a crashed test was shown in the Test Explorer as:

Test crashing_test failed with exit code 0.

That reads like success for a process that crashed, and the one measurement that names the cause was never consulted even though readTestResultsFile already parses every NamedMeasurement into the measurements map.

Fix

  • src/ctest.ts: add a small exported helper, getTestFailureMessage(testName, output, exitValue, exitStatus), that picks the message for a failed test that has an Exit Value measurement. When Exit Code is present and is neither Failed, Completed nor a plain number, it emits a new localized string (test.failed.with.signal) naming that status. Otherwise it returns the existing test.failed.with.exit.code message unchanged.
  • testResultsAnalysis reads the Exit Code measurement and calls the helper. The branch structure (ctestFailed vs ctestErrored vs skipped) is unchanged; only the text of the message differs for the signal/timeout case.
  • The exit value is kept in the new message because on Windows CTest stores the exception code there (for example 3221225477 for an access violation), which is useful alongside SEGFAULT.

After the fix the same test shows:

Test crashing_test failed with SEGFAULT (exit value 0).

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

  • New fixture test/unit-tests/TestResults4.xml containing 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:
    • "Parse results for a test killed by a signal and name the signal in the failure message": asserts the measurements are parsed and that the chosen message contains Test crashing_test failed with SEGFAULT and not exit code 0, while the ordinary failure still yields failed with exit code 1.
    • "Failure message falls back to the exit value without a descriptive Exit Code": covers undefined, Failed, Completed and numeric Exit Code values (old message) and Timeout / SEGFAULT (new message).

Both new tests fail on main (getTestFailureMessage does not exist) and pass with this change; the 16 existing tests in ctest.test.ts still pass.

Verification performed

  • tsc -p test.tsconfig.json (the pretest step): clean.
  • eslint src/ctest.ts test/unit-tests/ctest.test.ts: clean.
  • ctest.test.ts executed from the compiled out/ tree with mocha and a permissive vscode module mock (the machine used for this change could not download the VS Code Electron build that yarn unitTests requires): 18 passing with the fix, 16 passing and 2 failing without it.
  • yarn backendTests: 386 passing.
  • The unitTests Electron 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

  • Values CTest can write to Exit Code are Failed, Completed, Timeout, SEGFAULT, ILLEGAL, INTERRUPT, NUMERICAL, BAD_COMMAND and Not Run, plus the free text exception string CTest substitutes for other faults (for example Subprocess aborted for SIGABRT on Unix, or Exit code 0xc0000409 on Windows), which is why the check accepts any value that is not Failed, Completed or 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.
  • A larger change that was deliberately not made: a test that fails with Exit Value=0 because of FAIL_REGULAR_EXPRESSION or WILL_FAIL still reads "failed with exit code 0" (its Exit Code is Failed). Distinguishing that case would need a different message and is out of scope for this issue.
…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
@hanniavalera
Hannia Valera (hanniavalera) merged commit a692bd3 into microsoft:main Aug 25, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants