-
Notifications
You must be signed in to change notification settings - Fork 567
Add dotnet test integration tests for all Apple platforms
#25320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jonathanpeppers
wants to merge
12
commits into
net11.0
Choose a base branch
from
jonathanpeppers/add-mlaunch-mtp-tests
base: net11.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+114
−7
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7f41542
Add dotnet test integration tests for all Apple platforms
jonathanpeppers cc61fdc
Comment out macOS/MacCatalyst tests and fix test verb workaround
jonathanpeppers cc79797
Bump Microsoft.Tools.Mlaunch to 1.1.115
jonathanpeppers 1ba19e6
Split dotnet test into build + ComputeRunArguments + test --no-build
jonathanpeppers 8f87ffc
Remove ComputeRunArguments diagnostic step
jonathanpeppers 12bc5bb
Set UseFloatingTargetPlatformVersion in csproj for dotnet test
jonathanpeppers f529cb8
Use Execution.RunAsync directly for dotnet test step
jonathanpeppers 8cf7f27
Drop --no-build and use dotnet test directly
jonathanpeppers f0f69c7
Remove unnecessary env var overrides from dotnet test call
jonathanpeppers e90a4ab
Clear MSBuild env vars for dotnet test call
jonathanpeppers 9cce9a3
Add /bl: to dotnet test for CI diagnostics
jonathanpeppers f702ffe
Boot simulator before running dotnet test
jonathanpeppers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule Xamarin.MacDev
updated
235 files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| # Available versions can be seen here: | ||
| # https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet-eng/NuGet/Microsoft.Tools.Mlaunch/versions | ||
| MLAUNCH_NUGET_VERSION=1.1.113 | ||
| MLAUNCH_NUGET_VERSION=1.1.115 | ||
| # https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet-eng/NuGet/AppleDocReader/versions | ||
| ADR_NUGET_VERSION=1.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| using System.Text.Json; | ||
|
|
||
| using Xamarin.Tests; | ||
| using Xamarin.Utils; | ||
|
|
||
| #nullable enable | ||
|
|
||
| namespace Xamarin.Tests { | ||
| [TestFixture] | ||
| public class DotNetTestTest : TestBaseClass { | ||
| [Test] | ||
| [TestCase (ApplePlatform.iOS, "iostest")] | ||
| [TestCase (ApplePlatform.TVOS, "tvostest")] | ||
| // macOS and Mac Catalyst don't use mlaunch (they use 'open' via Desktop.targets), | ||
| // so MTP support requires a different approach for these platforms. | ||
| // [TestCase (ApplePlatform.MacCatalyst, "maccatalysttest")] | ||
| // [TestCase (ApplePlatform.MacOSX, "macostest")] | ||
| public void DotNetTest (ApplePlatform platform, string template) | ||
| { | ||
| Configuration.IgnoreIfIgnoredPlatform (platform); | ||
|
|
||
| var tmpDir = Cache.CreateTemporaryDirectory (); | ||
| var outputDir = Path.Combine (tmpDir, template); | ||
| DotNet.AssertNew (outputDir, template); | ||
| var proj = Path.Combine (outputDir, $"{template}.csproj"); | ||
|
|
||
| // dotnet test internally calls ComputeRunArguments via MSBuild API without | ||
| // forwarding /p: properties, so we must set them in the project file directly. | ||
| var csproj = File.ReadAllText (proj); | ||
| csproj = csproj.Replace ("</PropertyGroup>", " <UseFloatingTargetPlatformVersion>true</UseFloatingTargetPlatformVersion>\n </PropertyGroup>"); | ||
| File.WriteAllText (proj, csproj); | ||
|
|
||
| // Replace generated tests with a single passing test | ||
| var testFile = Path.Combine (outputDir, "Test1.cs"); | ||
| File.WriteAllText (testFile, $@"namespace {template}; | ||
|
|
||
| [TestClass] | ||
| public sealed class Test1 {{ | ||
| [TestMethod] | ||
| public void TestMethod1 () | ||
| {{ | ||
| }} | ||
| }} | ||
| "); | ||
|
|
||
| // Boot a simulator so that ComputeRunArguments can find a device | ||
| var runtimeIdentifier = GetDefaultRuntimeIdentifier (platform); | ||
| var deviceUdid = GetDeviceUdid (outputDir, runtimeIdentifier); | ||
| BootSimulator (deviceUdid); | ||
|
|
||
| // Run 'dotnet test' directly using Execution.RunAsync. | ||
| // dotnet test's MTP flow doesn't forward /p: properties to its internal | ||
| // ComputeRunArguments MSBuild API call, so properties must be in the csproj. | ||
| var env = new Dictionary<string, string?> (); | ||
| env ["MSBuildSDKsPath"] = null; | ||
| env ["MSBUILD_EXE_PATH"] = null; | ||
| var binlog = Path.Combine (outputDir, "log-test.binlog"); | ||
| var testArgs = new List<string> { "test", proj, $"/bl:{binlog}" }; | ||
| var testResult = Execution.RunAsync (DotNet.Executable, testArgs, env, Console.Out, workingDirectory: outputDir, timeout: TimeSpan.FromMinutes (10)).Result; | ||
| Assert.AreEqual (0, testResult.ExitCode, $"'dotnet test' failed with exit code {testResult.ExitCode}.\nBinlog: {binlog}\nOutput:\n{testResult.Output.MergedOutput}"); | ||
| } | ||
|
|
||
| static string GetDeviceUdid (string projectDirectory, string runtimeIdentifier) | ||
| { | ||
| var tmpdir = Cache.CreateTemporaryDirectory (); | ||
| var outputFile = Path.Combine (tmpdir, "AvailableDevices.json"); | ||
| var args = new List<string> { | ||
| "build", | ||
| "-t:ComputeAvailableDevices", | ||
| "-getItem:Devices", | ||
| $"-getResultOutputFile:{outputFile}", | ||
| $"-p:RuntimeIdentifier={runtimeIdentifier}", | ||
| }; | ||
|
|
||
| var env = new Dictionary<string, string?> (); | ||
| env ["MSBuildSDKsPath"] = null; | ||
| env ["MSBUILD_EXE_PATH"] = null; | ||
| var rv = Execution.RunAsync (DotNet.Executable, args, env, Console.Out, workingDirectory: projectDirectory, timeout: TimeSpan.FromMinutes (2)).Result; | ||
| Assert.AreEqual (0, rv.ExitCode, $"Failed to compute available devices. Output:\n{rv.Output.MergedOutput}"); | ||
|
|
||
| var output = File.ReadAllText (outputFile); | ||
| var doc = JsonDocument.Parse (output); | ||
| var devices = doc.RootElement.GetProperty ("Items").GetProperty ("Devices").EnumerateArray ().Select (e => { | ||
| var identity = e.GetProperty ("Identity").GetString ()!; | ||
| var osVersion = Version.Parse (e.GetProperty ("OSVersion").GetString ()!); | ||
| var deviceTypeIdentifier = e.GetProperty ("DeviceTypeIdentifier").GetString ()!; | ||
| return (Identity: identity, OsVersion: osVersion, DeviceTypeIdentifier: deviceTypeIdentifier); | ||
| }).OrderByDescending (d => d.OsVersion).ThenBy (d => d.DeviceTypeIdentifier).ThenBy (d => d.Identity).ToList (); | ||
|
|
||
| Assert.That (devices, Is.Not.Empty, $"No devices found. Output:\n{output}"); | ||
| return devices.First ().Identity; | ||
| } | ||
|
|
||
| static void BootSimulator (string udid) | ||
| { | ||
| var rv = Execution.RunAsync ("xcrun", new List<string> { "simctl", "boot", udid }, timeout: TimeSpan.FromMinutes (1)).Result; | ||
| // Exit code 149 means "already booted", which is fine | ||
| if (rv.ExitCode != 0 && rv.ExitCode != 149) | ||
| Assert.Fail ($"Failed to boot simulator {udid}. Exit code: {rv.ExitCode}\nOutput:\n{rv.Output.MergedOutput}"); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's failing with "Running the ComputeRunArguments target to discover run commands failed for this project. Fix the errors and warnings and run again.", so maybe a binlog would be able to reveal what's going on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latest has a
.binlognow, but it's partial (because something aborted), and I can't seem to get the error message out of it.I think the problem is something to do with having no Simulator running at all -- are these tests setup for having a simulator? Or should we test in a different place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error message is:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it locally, and this is what happens:
The simulator has to be launched before you can install apps into it.