diff --git a/eng/devices/ios.cake b/eng/devices/ios.cake index 9e9871fcc5ae..cc963be8d501 100644 --- a/eng/devices/ios.cake +++ b/eng/devices/ios.cake @@ -311,11 +311,43 @@ void PerformCleanupIfNeeded(bool cleanupEnabled) { 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) { + 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 {logDirectory}/{sim.UDID}_log.logarchive"); + 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 4400dd2c92e2..de5654fede38 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,19 +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 - condition: always() - continueOnError: true - - - - ${{ if eq(parameters.platform, 'ios')}}: - - bash: | - zip -9r "$(LogDirectory)/CoreSimulatorLog.zip" "$HOME/Library/Logs/CoreSimulator/" - zip -9r "$(LogDirectory)/DiagnosticReports.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 1f44dd41e485..9efa8320a12f 100644 --- a/eng/pipelines/common/device-tests.yml +++ b/eng/pipelines/common/device-tests.yml @@ -71,7 +71,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 505af0f9c797..d62c84e0efa1 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 @@ -201,10 +193,8 @@ jobs: - ${{ 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/${{ 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/ui-tests-steps.yml b/eng/pipelines/common/ui-tests-steps.yml index 9e28c5579b6e..06c55928dff5 100644 --- a/eng/pipelines/common/ui-tests-steps.yml +++ b/eng/pipelines/common/ui-tests-steps.yml @@ -74,6 +74,8 @@ steps: } Invoke-Expression $command + + - pwsh: ./build.ps1 -Script eng/devices/${{ parameters.platform }}.cake --target=uitest --project="${{ parameters.path }}" --appproject="${{ parameters.app }}" --device="${{ parameters.device }}" --apiversion="${{ parameters.version }}" --configuration="${{ parameters.configuration }}" --results="$(TestResultsDirectory)" --binlog="$(LogDirectory)" ${{ parameters.cakeArgs }} --verbosity=diagnostic --runtimevariant="${{ parameters.runtimeVariant }}" displayName: $(Agent.JobName) ${{ if ne(parameters.platform, 'android')}}: retryCountOnTaskFailure: 1 @@ -81,10 +83,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