Skip to content

[xharness] Add TestReporter implementation to detect crashes properly.#25150

Merged
rolfbjarne merged 1 commit intomainfrom
dev/rolf/xharness-crashes-arent-successes
Apr 15, 2026
Merged

[xharness] Add TestReporter implementation to detect crashes properly.#25150
rolfbjarne merged 1 commit intomainfrom
dev/rolf/xharness-crashes-arent-successes

Conversation

@rolfbjarne
Copy link
Copy Markdown
Member

xharness regressed detecting crashing tests as crashing (dotnet/xharness@a6f9fe6),
so clone the TestReporter class and modify it to properly detect crashes and report
them as such.

xharness regressed detecting crashing tests as crashing (dotnet/xharness@a6f9fe6),
so clone the TestReporter class and modify it to properly detect crashes and report
them as such.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rolfbjarne rolfbjarne requested a review from Copilot April 14, 2026 17:27
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
2 pipeline(s) require an authorized user to comment /azp run to run.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a local ITestReporter implementation to tests/xharness to restore correct crash detection/reporting for test runs (addressing a regression in upstream xharness crash classification).

Changes:

  • Introduce TestReporter implementation used to parse results, capture crash artifacts, and generate XML failure output.
  • Add TestReporterFactory to create the reporter with the required dependencies.
  • Wire both files into tests/xharness/xharness.csproj.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.

File Description
tests/xharness/xharness.csproj Includes the new TestReporter + TestReporterFactory sources in the xharness build.
tests/xharness/TestReporterFactory.cs Factory that constructs the new reporter implementation.
tests/xharness/TestReporter.cs New reporter logic for determining success/crash/timeout and generating result artifacts.

Comment thread tests/xharness/TestReporter.cs
if (!int.TryParse (pidstr, out pid))
mainLog.WriteLine ("Could not parse pid: {0}", pidstr);
} else if (line.Contains ("Xamarin.Hosting: Launched ") && line.Contains (" with pid ")) {
var pidstr = line.Substring (line.LastIndexOf (' '));
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

GetPidFromRunLog extracts the PID using line.Substring (line.LastIndexOf (' ')), which includes the leading space before the PID. int.TryParse will then fail for lines like "... with pid 123" and the PID will remain -1, breaking the later kill/crash-detection logic. Trim the substring or start after the last space (LastIndexOf (' ') + 1).

Suggested change
var pidstr = line.Substring (line.LastIndexOf (' '));
var pidstr = line.Substring (line.LastIndexOf (' ') + 1);

Copilot uses AI. Check for mistakes.
while ((line = await logReader.ReadLineAsync ()) is not null) {
const string str = "was launched with pid '";
var idx = line.IndexOf (str, StringComparison.Ordinal);
if (idx > 0) {
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

GetPidFromMainLog only parses when idx > 0, so it will miss cases where the marker string starts at index 0. Using idx >= 0 makes PID detection more robust across different log formatting.

Suggested change
if (idx > 0) {
if (idx >= 0) {

Copilot uses AI. Check for mistakes.
var crashed = false;
if (File.Exists (listener.TestLog.FullPath)) {
WrenchLog.WriteLine ("AddFile: {0}", listener.TestLog.FullPath);
(Success, crashed, result.ResultMessage) = await TestsSucceeded (appInfo, listener.TestLog.FullPath, timedout);
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

ParseResult sets Success from TestsSucceeded whenever a test log exists. This can override an earlier process-level failure detected in Collect*Result (e.g., app crashed after writing results) and end up reporting success. Consider merging the process outcome with the parsed test outcome instead of overwriting it.

Suggested change
(Success, crashed, result.ResultMessage) = await TestsSucceeded (appInfo, listener.TestLog.FullPath, timedout);
var previousSuccess = Success;
var (parsedSuccess, parsedCrashed, parsedResultMessage) = await TestsSucceeded (appInfo, listener.TestLog.FullPath, timedout);
Success = (previousSuccess ?? true) && parsedSuccess;
crashed = parsedCrashed;
result.ResultMessage = parsedResultMessage;

Copilot uses AI. Check for mistakes.
Comment on lines +503 to +507
if (crashReason == "per-process-limit") {
result.ResultMessage = "Killed due to using too much memory (per-process-limit).";
} else {
result.ResultMessage = $"Killed by the OS ({crashReason})";
}
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

When a crashReason is found, ResultMessage is updated but the final ExecutingResult isn't recomputed. This can leave the run classified as Failed instead of Crashed even though an OS kill reason was detected. Set crashed = true (and adjust ExecutingResult) when crashReason is present.

Copilot uses AI. Check for mistakes.
}

public void Dispose ()
{
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

TestReporter.Dispose disposes crashLogs but not the CancellationTokenSource. CancellationTokenSource implements IDisposable and should be disposed to avoid leaking any underlying resources/timers if many reporters are created over time.

Suggested change
{
{
cancellationTokenSource.Dispose ();

Copilot uses AI. Check for mistakes.
Comment on lines +165 to +166
Console.WriteLine (node?.InnerXml);
Console.WriteLine (node?.SelectSingleNode ("reason")?.InnerText);
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

Avoid writing crash parsing details to stdout here (Console.WriteLine). This bypasses the harness log plumbing and can add noisy output in CI. Prefer mainLog.WriteLine (optionally behind verbosity) or remove.

Suggested change
Console.WriteLine (node?.InnerXml);
Console.WriteLine (node?.SelectSingleNode ("reason")?.InnerText);
mainLog.WriteLine (node?.InnerXml);
mainLog.WriteLine (node?.SelectSingleNode ("reason")?.InnerText);

Copilot uses AI. Check for mistakes.
Comment on lines +268 to +272
Console.WriteLine (line);
resultLine = line;
break;
} else if (line.Contains ("[FAIL]")) {
Console.WriteLine (line);
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

Avoid writing raw test output lines to stdout (Console.WriteLine) during result scanning. This can spam CI logs for large test suites; route through mainLog (possibly at verbose level) instead.

Suggested change
Console.WriteLine (line);
resultLine = line;
break;
} else if (line.Contains ("[FAIL]")) {
Console.WriteLine (line);
mainLog.WriteLine (line);
resultLine = line;
break;
} else if (line.Contains ("[FAIL]")) {
mainLog.WriteLine (line);

Copilot uses AI. Check for mistakes.
@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #c41f42e] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: c41f42eb367bc91a0fc6f47fe5eb0131984d02c8 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [CI Build #c41f42e] Build passed (Build packages) ✅

Pipeline on Agent
Hash: c41f42eb367bc91a0fc6f47fe5eb0131984d02c8 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: c41f42eb367bc91a0fc6f47fe5eb0131984d02c8 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [CI Build #c41f42e] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: c41f42eb367bc91a0fc6f47fe5eb0131984d02c8 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

🚀 [CI Build #c41f42e] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 156 tests passed 🎉

Tests counts

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 6 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 15 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 12 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ monotouch (tvOS): All 11 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: c41f42eb367bc91a0fc6f47fe5eb0131984d02c8 [PR build]

@rolfbjarne rolfbjarne merged commit 8376df7 into main Apr 15, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants