From 9251b38bd58921df21ebcf67d84a539e39b74d5c Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Sun, 21 Jul 2024 17:21:16 -0500 Subject: [PATCH] Fix iOS log exports (#23334) * Fix ios Device Logging * - fix up device test logging a bit more * Update ui-tests-steps.yml * Update ui-tests-steps.yml * Update ios.cake * Update ui-tests-steps.yml * Update maui-templates.yml * Update maui-templates.yml --- eng/devices/ios.cake | 50 +++++++++++++++++++-- eng/pipelines/common/device-tests-steps.yml | 14 +----- eng/pipelines/common/device-tests.yml | 2 +- eng/pipelines/common/maui-templates.yml | 15 +------ eng/pipelines/common/ui-tests-steps.yml | 8 ++-- 5 files changed, 55 insertions(+), 34 deletions(-) diff --git a/eng/devices/ios.cake b/eng/devices/ios.cake index 9e9871fcc5ae..e65fa2e09ee5 100644 --- a/eng/devices/ios.cake +++ b/eng/devices/ios.cake @@ -44,7 +44,7 @@ var dotnetToolPath = GetDotnetToolPath(); Setup(context => { LogSetupInfo(dotnetToolPath); - PerformCleanupIfNeeded(deviceCleanupEnabled); + PerformCleanupIfNeeded(deviceCleanupEnabled, false); // Device or simulator setup if (testDevice.Contains("device")) @@ -58,7 +58,7 @@ Setup(context => } }); -Teardown(context => PerformCleanupIfNeeded(deviceCleanupEnabled)); +Teardown(context => PerformCleanupIfNeeded(deviceCleanupEnabled, true)); Task("Cleanup"); @@ -307,15 +307,59 @@ void ExecuteCGLegacyUITests(string project, string appProject, string device, st // Helper methods -void PerformCleanupIfNeeded(bool cleanupEnabled) +void PerformCleanupIfNeeded(bool cleanupEnabled, bool createDeviceLogs) { if (cleanupEnabled) { + var logDirectory = GetLogDirectory(); Information("Cleaning up..."); Information("Deleting XHarness simulator if exists..."); var sims = ListAppleSimulators().Where(s => s.Name.Contains("XHarness")).ToArray(); foreach (var sim in sims) { + if(createDeviceLogs) + { + try + { + var homeDirectory = Environment.GetEnvironmentVariable("HOME"); + Information("Diagnostics Reports"); + StartProcess("zip", new ProcessSettings { + Arguments = new ProcessArgumentBuilder() + .Append("-9r") + .AppendQuoted($"{logDirectory}/DiagnosticReports_{sim.UDID}.zip") + .AppendQuoted($"{homeDirectory}/Library/Logs/DiagnosticReports/"), + RedirectStandardOutput = false + }); + + Information("CoreSimulator"); + StartProcess("zip", new ProcessSettings { + Arguments = new ProcessArgumentBuilder() + .Append("-9r") + .AppendQuoted($"{logDirectory}/CoreSimulator_{sim.UDID}.zip") + .AppendQuoted($"{homeDirectory}/Library/Logs/CoreSimulator/{sim.UDID}"), + RedirectStandardOutput = false + }); + + StartProcess("xcrun", $"simctl spawn {sim.UDID} log collect --output {homeDirectory}/{sim.UDID}_log.logarchive"); + + StartProcess("zip", new ProcessSettings { + Arguments = new ProcessArgumentBuilder() + .Append("-9r") + .AppendQuoted($"{logDirectory}/{sim.UDID}_log.logarchive.zip") + .AppendQuoted($"{homeDirectory}/{sim.UDID}_log.logarchive"), + RedirectStandardOutput = false + }); + + var screenshotPath = $"{testResultsPath}/{sim.UDID}_screenshot.png"; + StartProcess("xcrun", $"simctl io {sim.UDID} screenshot {screenshotPath}"); + } + catch(Exception ex) + { + Information($"Failed to collect logs for simulator {sim.Name} ({sim.UDID}): {ex.Message}"); + Information($"Command Executed: simctl spawn {sim.UDID} log collect --output {logDirectory}/{sim.UDID}_log.logarchive"); + } + } + Information($"Deleting XHarness simulator {sim.Name} ({sim.UDID})..."); StartProcess("xcrun", $"simctl shutdown {sim.UDID}"); ExecuteWithRetries(() => StartProcess("xcrun", $"simctl delete {sim.UDID}"), 3); diff --git a/eng/pipelines/common/device-tests-steps.yml b/eng/pipelines/common/device-tests-steps.yml index f597e308e244..a9ac50cdeecb 100644 --- a/eng/pipelines/common/device-tests-steps.yml +++ b/eng/pipelines/common/device-tests-steps.yml @@ -79,14 +79,6 @@ steps: Write-Host "##vso[task.setvariable variable=Platform.Name]${platformName}" displayName: 'Set Platform.Name' - - ${{ if eq(parameters.platform, 'ios')}}: - - bash: | - if [ -f "$HOME/Library/Logs/CoreSimulator/*" ]; then rm -r $HOME/Library/Logs/CoreSimulator/*; fi - if [ -f "$HOME/Library/Logs/DiagnosticReports/*" ]; then rm -r $HOME/Library/Logs/DiagnosticReports/*; fi - displayName: Delete Old Simulator Logs - condition: always() - continueOnError: true - - ${{ if eq(parameters.platform, 'windows')}}: - pwsh: | $errorPath = "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" @@ -113,10 +105,8 @@ steps: - ${{ if eq(parameters.platform, 'ios')}}: - bash: | - suffix=$(date +%Y%m%d%H%M%S) - zip -9r "$(LogDirectory)/CoreSimulatorLog_${suffix}.zip" "$HOME/Library/Logs/CoreSimulator/" - zip -9r "$(LogDirectory)/DiagnosticReports_${suffix}.zip" "$HOME/Library/Logs/DiagnosticReports/" - displayName: Zip Simulator Logs + pwsh ./build.ps1 --target=Cleanup -Script eng/devices/${{ parameters.platform }}.cake ---results="$(TestResultsDirectory)" ${{ parameters.cakeArgs }} + displayName: Cleanup and Create Simulator Logs if Test Run Failed To condition: always() continueOnError: true diff --git a/eng/pipelines/common/device-tests.yml b/eng/pipelines/common/device-tests.yml index b9c562368761..f4a6b8b18eee 100644 --- a/eng/pipelines/common/device-tests.yml +++ b/eng/pipelines/common/device-tests.yml @@ -72,7 +72,7 @@ stages: clean: all displayName: "iOS tests" pool: ${{ parameters.iosPool }} - timeoutInMinutes: 140 + timeoutInMinutes: 45 strategy: matrix: # create all the variables used for the matrix diff --git a/eng/pipelines/common/maui-templates.yml b/eng/pipelines/common/maui-templates.yml index 29d0e06fd6ee..645f1154fa52 100644 --- a/eng/pipelines/common/maui-templates.yml +++ b/eng/pipelines/common/maui-templates.yml @@ -170,14 +170,6 @@ jobs: DOTNET_TOKEN: $(dotnetbuilds-internal-container-read-token) PRIVATE_BUILD: $(PrivateBuild) - - ${{ if eq(RunPlatform.testName, 'RunOniOS') }}: - - bash: | - if [ -f "$HOME/Library/Logs/CoreSimulator/*" ]; then rm -r $HOME/Library/Logs/CoreSimulator/*; fi - if [ -f "$HOME/Library/Logs/DiagnosticReports/*" ]; then rm -r $HOME/Library/Logs/DiagnosticReports/*; fi - displayName: Delete Old Simulator Logs - condition: always() - continueOnError: true - # - script: dotnet tool update Microsoft.DotNet.XHarness.CLI --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json --version "9.0.0-prerelease*" -g # displayName: install xharness @@ -200,11 +192,8 @@ jobs: IOS_TEST_DEVICE: ios-simulator-64_17.2 - ${{ if eq(RunPlatform.testName, 'RunOniOS') }}: - - bash: | - suffix=$(date +%Y%m%d%H%M%S) - zip -9r "$(LogDirectory)/CoreSimulatorLog_${suffix}.zip" "$HOME/Library/Logs/CoreSimulator/" - zip -9r "$(LogDirectory)/DiagnosticReports_${suffix}.zip" "$HOME/Library/Logs/DiagnosticReports/" - displayName: Zip Simulator Logs + - pwsh: ./build.ps1 --target=Cleanup -Script eng/devices/ios.cake ---results="$(TestResultsDirectory)" ${{ parameters.cakeArgs }} + displayName: Cleanup and Create Simulator Logs if Test Run Failed To condition: always() continueOnError: true diff --git a/eng/pipelines/common/ui-tests-steps.yml b/eng/pipelines/common/ui-tests-steps.yml index 7835b347a9ca..86ab2bd5c7c3 100644 --- a/eng/pipelines/common/ui-tests-steps.yml +++ b/eng/pipelines/common/ui-tests-steps.yml @@ -99,7 +99,7 @@ steps: $command += " --test-filter ""$testFilter""" } - Invoke-Expression $command + Invoke-Expression $command displayName: $(Agent.JobName) ${{ if ne(parameters.platform, 'android')}}: retryCountOnTaskFailure: 1 @@ -107,10 +107,8 @@ steps: APPIUM_HOME: $(APPIUM_HOME) - bash: | - suffix=$(date +%Y%m%d%H%M%S) - zip -9r "$(LogDirectory)/CoreSimulatorLog_${suffix}.zip" "$HOME/Library/Logs/CoreSimulator/" - zip -9r "$(LogDirectory)/DiagnosticReports_${suffix}.zip" "$HOME/Library/Logs/DiagnosticReports/" - displayName: Zip Simulator Logs + pwsh ./build.ps1 --target=Cleanup -Script eng/devices/${{ parameters.platform }}.cake ---results="$(TestResultsDirectory)" ${{ parameters.cakeArgs }} + displayName: Cleanup and Create Simulator Logs if Test Run Failed To condition: ${{ eq(parameters.platform, 'ios') }} continueOnError: true