Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,8 @@ private CancellationTokenSource CaptureLogStream(string appName, bool useSimctl,
}
else
{
// For MacCatalyst, the test output log does not propagate to the main log.
// Hence, we duplicate the log to the main console log to simplify the UX of failure investigation.
IFileBackedLog aggregatedAppOutputLog = Log.CreateReadableAggregatedLog(_mainLog, log);
_processManager
.ExecuteCommandAsync("log", logArgs, _mainLog, aggregatedAppOutputLog, aggregatedAppOutputLog, TimeSpan.FromDays(1), cancellationToken: streamCancellation)
.ExecuteCommandAsync("log", logArgs, _mainLog, log, log, TimeSpan.FromDays(1), cancellationToken: streamCancellation)
.DoNotAwait();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,12 @@ private async Task RunDeviceTests(
// We need to check for MT1111 (which means that mlaunch won't wait for the app to exit)
IFileBackedLog aggregatedLog = Log.CreateReadableAggregatedLog(_mainLog, testReporter.CallbackLog);

// The app output log is not directly accessible.
// Hence, we duplicate the log to the main console log to simplify the UX of failure investigation.
IFileBackedLog aggregatedAppOutputLog = Log.CreateReadableAggregatedLog(_mainLog, appOutputLog);

var result = await RunAndWatchForAppSignal(() => _processManager.ExecuteCommandAsync(
mlaunchArguments,
aggregatedLog,
aggregatedAppOutputLog,
aggregatedAppOutputLog,
appOutputLog,
appOutputLog,
timeout,
envVars,
cancellationToken: cancellationToken));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ private async Task<ExitCode> ExecuteApp(
skippedTestClasses: classMethodFilters?.ToArray(),
cancellationToken: cancellationToken);

if (!target.Platform.IsSimulator()) // Simulator app logs are already included in the main log
{
// Copy system and application logs to the main log for better failure investigation.
CopyLogsToMainLog();
}

return ParseResult(testResult, resultMessage, appTester.ListenerConnected);
}

Expand Down Expand Up @@ -278,6 +284,9 @@ private async Task<ExitCode> ExecuteMacCatalystApp(
skippedTestClasses: classMethodFilters?.ToArray(),
cancellationToken: cancellationToken);

// Copy system and application logs to the main log for better failure investigation.
CopyLogsToMainLog();

return ParseResult(testResult, resultMessage, appTester.ListenerConnected);
}

Expand Down Expand Up @@ -364,4 +373,42 @@ ExitCode LogProblem(string message, ExitCode defaultExitCode)
return ExitCode.GENERAL_FAILURE;
}
}

/// <summary>
/// Copy system and application logs to the main log for better failure investigation.
/// </summary>
private void CopyLogsToMainLog()
{
var logs = _logs.Where(log => log.Description == LogType.SystemLog.ToString() || log.Description == LogType.ApplicationLog.ToString()).ToList();

foreach (var log in logs)
{
_mainLog.WriteLine($"==================== {log.Description} ====================");
_mainLog.WriteLine($"Log file: {log.FullPath}");

try
{
// Read and append log content to the main log
string logContent;
using (var reader = log.GetReader())
{
while (!reader.EndOfStream)
{
logContent = reader.ReadLine()!;
if (logContent != null)
{
_mainLog.WriteLine(logContent);
}
}
}
}
catch (Exception ex)
{
_mainLog.WriteLine($"Failed to read {log.Description}: {ex.Message}");
}

_mainLog.WriteLine($"==================== End of {log.Description} ====================");
_mainLog.WriteLine(string.Empty);
}
}
}
Loading