Skip to content

Commit

Permalink
Fix ios Device Logging
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWeen committed Jul 5, 2024
1 parent 7785fea commit 0354908
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 38 deletions.
32 changes: 32 additions & 0 deletions eng/devices/ios.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 2 additions & 21 deletions eng/pipelines/common/device-tests-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion eng/pipelines/common/device-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 2 additions & 12 deletions eng/pipelines/common/maui-templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions eng/pipelines/common/ui-tests-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ 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
env:
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
Expand Down

0 comments on commit 0354908

Please sign in to comment.