diff --git a/src/Microsoft.DotNet.Helix/Sdk/CreateXHarnessAppleWorkItems.cs b/src/Microsoft.DotNet.Helix/Sdk/CreateXHarnessAppleWorkItems.cs index a3effada738..1145d896658 100644 --- a/src/Microsoft.DotNet.Helix/Sdk/CreateXHarnessAppleWorkItems.cs +++ b/src/Microsoft.DotNet.Helix/Sdk/CreateXHarnessAppleWorkItems.cs @@ -23,6 +23,7 @@ public static class MetadataNames public const string Targets = "Targets"; public const string LaunchTimeout = "LaunchTimeout"; public const string IncludesTestRunner = "IncludesTestRunner"; + public const string ResetSimulator = "ResetSimulator"; } private const string EntryPointScript = "xharness-helix-job.apple.sh"; @@ -135,6 +136,15 @@ private async Task PrepareWorkItem( Log.LogWarning("The ExpectedExitCode property is ignored in the `apple test` scenario"); } + bool resetSimulator = false; + if (appBundleItem.TryGetMetadata(MetadataNames.ResetSimulator, out string resetSimulatorRunnerProp)) + { + if (resetSimulatorRunnerProp.ToLowerInvariant() == "true") + { + resetSimulator = true; + } + } + if (customCommands == null) { // In case user didn't specify custom commands, we use our default one @@ -146,13 +156,14 @@ private async Task PrepareWorkItem( (includesTestRunner ? $"--launch-timeout \"$launch_timeout\" " : $"--expected-exit-code $expected_exit_code ") + + (resetSimulator ? $"--reset-simulator " : string.Empty) + "--xcode \"$xcode_path\" " + "-v " + (!string.IsNullOrEmpty(AppArguments) ? "-- " + AppArguments : string.Empty); } string appName = fileSystem.GetFileName(appBundleItem.ItemSpec); - string helixCommand = GetHelixCommand(appName, targets, testTimeout, launchTimeout, includesTestRunner, expectedExitCode); + string helixCommand = GetHelixCommand(appName, targets, testTimeout, launchTimeout, includesTestRunner, expectedExitCode, resetSimulator); string payloadArchivePath = await CreateZipArchiveOfFolder(zipArchiveManager, fileSystem, appFolderPath, customCommands); Log.LogMessage($"Creating work item with properties Identity: {workItemName}, Payload: {appFolderPath}, Command: {helixCommand}"); @@ -166,13 +177,22 @@ private async Task PrepareWorkItem( }); } - private string GetHelixCommand(string appName, string targets, TimeSpan testTimeout, TimeSpan launchTimeout, bool includesTestRunner, int expectedExitCode) => + private string GetHelixCommand( + string appName, + string targets, + TimeSpan testTimeout, + TimeSpan launchTimeout, + bool includesTestRunner, + int expectedExitCode, + bool resetSimulator) + => $"chmod +x {EntryPointScript} && ./{EntryPointScript} " + $"--app \"{appName}\" " + $"--targets \"{targets}\" " + $"--timeout \"{testTimeout}\" " + $"--launch-timeout \"{launchTimeout}\" " + (includesTestRunner ? "--includes-test-runner " : string.Empty) + + (resetSimulator ? "--reset-simulator" : string.Empty) + $"--expected-exit-code \"{expectedExitCode}\" " + (!string.IsNullOrEmpty(XcodeVersion) ? $" --xcode-version \"{XcodeVersion}\"" : string.Empty) + (!string.IsNullOrEmpty(AppArguments) ? $" --app-arguments \"{AppArguments}\"" : string.Empty); diff --git a/src/Microsoft.DotNet.Helix/Sdk/tools/xharness-runner/Readme.md b/src/Microsoft.DotNet.Helix/Sdk/tools/xharness-runner/Readme.md index e9b6459f8c9..38f94eab3d7 100644 --- a/src/Microsoft.DotNet.Helix/Sdk/tools/xharness-runner/Readme.md +++ b/src/Microsoft.DotNet.Helix/Sdk/tools/xharness-runner/Readme.md @@ -67,7 +67,7 @@ To execute .app bundles, declare one or more `XHarnessAppBundleToTest` items: The `` metadata is a required configuration that tells XHarness which kind of device/Simulator to target. Use the XHarness CLI help command to find more (see the `--targets` option). -You can also specify some metadata that will help you configure the run better: +You can also specify some additional metadata that will help you configure the run better: ```xml @@ -89,6 +89,10 @@ You can also specify some metadata that will help you configure the run better: false + + + + true ``` @@ -128,7 +132,7 @@ To execute .apks, declare one or more `XHarnessApkToTest` items: ``` -You can also specify some metadata that will help you configure the run better: +You can also specify some additional metadata that will help you configure the run better: ```xml diff --git a/src/Microsoft.DotNet.Helix/Sdk/tools/xharness-runner/xharness-runner.apple.sh b/src/Microsoft.DotNet.Helix/Sdk/tools/xharness-runner/xharness-runner.apple.sh index c8795fb47bd..58264b2ed74 100644 --- a/src/Microsoft.DotNet.Helix/Sdk/tools/xharness-runner/xharness-runner.apple.sh +++ b/src/Microsoft.DotNet.Helix/Sdk/tools/xharness-runner/xharness-runner.apple.sh @@ -16,6 +16,7 @@ xcode_version='' app_arguments='' expected_exit_code=0 includes_test_runner=false +reset_simulator=false while [[ $# -gt 0 ]]; do opt="$(echo "$1" | tr "[:upper:]" "[:lower:]")" @@ -59,6 +60,9 @@ while [[ $# -gt 0 ]]; do --includes-test-runner) includes_test_runner=true ;; + --reset-simulator) + reset_simulator=true + ;; esac shift done