Skip to content
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

[tests] Run a few more tests remotely from Windows. #21867

Merged
merged 11 commits into from
Mar 6, 2025
2 changes: 1 addition & 1 deletion msbuild/Xamarin.Shared/Xamarin.Shared.targets
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);_IncludeBindingResourcesInNuGetPackage</TargetsForTfmSpecificContentInPackage>
</PropertyGroup>
<Target Name="_IncludeBindingResourcesInNuGetPackage"
Condition="'$(IsMacEnabled)' == 'true' And '$(IncludeBuildOutput)' != 'false'"
Condition="'$(IncludeBuildOutput)' != 'false'"
>
<PropertyGroup>
<_HasOldStyleBindingItems Condition="@(ObjcBindingNativeLibrary->Count()) > 0">true</_HasOldStyleBindingItems>
Expand Down
127 changes: 117 additions & 10 deletions tests/dotnet/UnitTests/PackTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,35 @@ public class PackTest : TestBaseClass {
[TestCase (ApplePlatform.TVOS)]
[TestCase (ApplePlatform.MacOSX)]
public void BindingOldStyle (ApplePlatform platform)
{
BindingOldStyleImpl (platform);
}

[Test]
[TestCase (ApplePlatform.iOS)]
[Category ("RemoteWindows")]
public void BindingOldStyleOnRemoteWindows (ApplePlatform platform)
{
BindingOldStyleImpl (platform, AddRemoteProperties ());
}

void BindingOldStyleImpl (ApplePlatform platform, Dictionary<string, string>? properties = null)
{
var project = "BindingOldStyle";
Configuration.IgnoreIfIgnoredPlatform (platform);

var project_path = GetProjectPath (project, platform: platform);
Clean (project_path);

var tmpdir = Cache.CreateTemporaryDirectory ();
string tmpdir;
if (Configuration.IsBuildingRemotely) {
tmpdir = Path.Combine ("bin", "tmp-dir");
} else {
tmpdir = Cache.CreateTemporaryDirectory ();
}
var outputPath = Path.Combine (tmpdir, "OutputPath");
var intermediateOutputPath = Path.Combine (tmpdir, "IntermediateOutputPath");
var properties = GetDefaultProperties ();
properties = GetDefaultProperties (extraProperties: properties);
properties ["OutputPath"] = outputPath + Path.DirectorySeparatorChar;
properties ["IntermediateOutputPath"] = intermediateOutputPath + Path.DirectorySeparatorChar;

Expand Down Expand Up @@ -98,6 +116,19 @@ public void BindingFrameworksProject (ApplePlatform platform, bool noBindingEmbe
[TestCase (ApplePlatform.MacOSX, true)]
[TestCase (ApplePlatform.MacOSX, false)]
public void BindingXcFrameworksProject (ApplePlatform platform, bool noBindingEmbedding)
{
BindingXcFrameworksProjectImpl (platform, noBindingEmbedding);
}

[Category ("RemoteWindows")]
[TestCase (ApplePlatform.iOS, true)]
[TestCase (ApplePlatform.iOS, false)]
public void BindingXcFrameworksProjectOnRemoteWindows (ApplePlatform platform, bool noBindingEmbedding)
{
BindingXcFrameworksProjectImpl (platform, noBindingEmbedding, AddRemoteProperties ());
}

void BindingXcFrameworksProjectImpl (ApplePlatform platform, bool noBindingEmbedding, Dictionary<string, string>? properties = null)
{
var project = "bindings-xcframework-test";
var assemblyName = "bindings-framework-test";
Expand All @@ -113,30 +144,94 @@ public void BindingXcFrameworksProject (ApplePlatform platform, bool noBindingEm
var project_path = Path.Combine (Configuration.RootPath, "tests", project, "dotnet", platform.AsString (), $"{project}.csproj");
Clean (project_path);

var tmpdir = Cache.CreateTemporaryDirectory ();
string tmpdir;
if (Configuration.IsBuildingRemotely) {
tmpdir = Path.Combine ("bin", "tmp-dir");
} else {
tmpdir = Cache.CreateTemporaryDirectory ();
}
var outputPath = Path.Combine (tmpdir, "OutputPath");
var intermediateOutputPath = Path.Combine (tmpdir, "IntermediateOutputPath");
var properties = GetDefaultProperties ();
properties = GetDefaultProperties (extraProperties: properties);
properties ["OutputPath"] = outputPath + Path.DirectorySeparatorChar;
properties ["IntermediateOutputPath"] = intermediateOutputPath + Path.DirectorySeparatorChar;
properties ["NoBindingEmbedding"] = noBindingEmbedding ? "true" : "false";

DotNet.AssertPack (project_path, properties, msbuildParallelism: false);

var nupkg = Path.Combine (outputPath, assemblyName + ".1.0.0.nupkg");
string nupkg;
if (Configuration.IsBuildingRemotely) {
nupkg = Path.Combine (Path.GetDirectoryName (project_path)!, outputPath, assemblyName + ".1.0.0.nupkg");
} else {
nupkg = Path.Combine (outputPath, assemblyName + ".1.0.0.nupkg");
}
Assert.That (nupkg, Does.Exist, "nupkg existence");

var archive = ZipFile.OpenRead (nupkg);
using var archive = ZipFile.OpenRead (nupkg);
var files = archive.Entries.Select (v => v.FullName).ToHashSet ();
var tfm = platform.ToFrameworkWithPlatformVersion (isExecutable: false);
Assert.That (archive.Entries.Count, Is.EqualTo (noBindingEmbedding ? 6 : 5), $"nupkg file count - {nupkg}");
int archiveCount;
if (noBindingEmbedding) {
if (Configuration.IsBuildingRemotely) {
// When building remotely, the xcframework is originally on Windows. This means any symlinks won't be symlinks anymore,
// and the xcframework isn't compressed into a zip file before storing in the nupkg. This also means the nupkg won't
// work on macOS/Mac Catalyst (because those are the frameworks with symlinks), but this doesn't seem like a big issue
// at the moment (never heard of a customer running into this), so for now we can probably just ignore this scenario.
// A possibility for the future, would be to detect this and show warning/error telling people to build from macOS
// instead of remotely.
archiveCount = 39;
} else {
archiveCount = 6;
}
} else {
archiveCount = 5;
}
Assert.That (archive.Entries.Count, Is.EqualTo (archiveCount), $"nupkg file count - {nupkg}:\n\t{string.Join ("\n\t", archive.Entries.Select (v => v.FullName))}");
Assert.That (files, Does.Contain (assemblyName + ".nuspec"), "nuspec");
Assert.That (files, Does.Contain ("_rels/.rels"), ".rels");
Assert.That (files, Does.Contain ("[Content_Types].xml"), "[Content_Types].xml");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.dll"), $"{assemblyName}.dll");
Assert.That (files, Has.Some.Matches<string> (v => v.StartsWith ("package/services/metadata/core-properties/", StringComparison.Ordinal) && v.EndsWith (".psmdcp", StringComparison.Ordinal)), "psmdcp");
if (noBindingEmbedding) {
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources.zip"), $"{assemblyName}.resources.zip");
if (Configuration.IsBuildingRemotely) {
Assert.That (files, Does.Not.Contain ($"lib/{tfm}/{assemblyName}.resources.zip"), $"{assemblyName}.resources.zip");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/manifest"), $"{assemblyName}.resources/manifest");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XStaticArTest.xcframework/Info.plist"), $"{assemblyName}.resources/XStaticArTest.xcframework/Info.plist");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XStaticArTest.xcframework/ios-arm64/XStaticArTest.framework/XStaticArTest"), $"{assemblyName}.resources/XStaticArTest.xcframework/ios-arm64/XStaticArTest.framework/XStaticArTest");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XStaticArTest.xcframework/ios-arm64_x86_64-maccatalyst/XStaticArTest.framework/XStaticArTest"), $"{assemblyName}.resources/XStaticArTest.xcframework/ios-arm64_x86_64-maccatalyst/XStaticArTest.framework/XStaticArTest");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XStaticArTest.xcframework/ios-arm64_x86_64-simulator/XStaticArTest.framework/XStaticArTest"), $"{assemblyName}.resources/XStaticArTest.xcframework/ios-arm64_x86_64-simulator/XStaticArTest.framework/XStaticArTest");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XStaticArTest.xcframework/macos-arm64_x86_64/XStaticArTest.framework/XStaticArTest"), $"{assemblyName}.resources/XStaticArTest.xcframework/macos-arm64_x86_64/XStaticArTest.framework/XStaticArTest");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XStaticArTest.xcframework/tvos-arm64/XStaticArTest.framework/XStaticArTest"), $"{assemblyName}.resources/XStaticArTest.xcframework/tvos-arm64/XStaticArTest.framework/XStaticArTest");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XStaticArTest.xcframework/tvos-arm64_x86_64-simulator/XStaticArTest.framework/XStaticArTest"), $"{assemblyName}.resources/XStaticArTest.xcframework/tvos-arm64_x86_64-simulator/XStaticArTest.framework/XStaticArTest");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XStaticObjectTest.xcframework/Info.plist"), $"{assemblyName}.resources/XStaticObjectTest.xcframework/Info.plist");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XStaticObjectTest.xcframework/ios-arm64/XStaticObjectTest.framework/XStaticObjectTest"), $"{assemblyName}.resources/XStaticObjectTest.xcframework/ios-arm64/XStaticObjectTest.framework/XStaticObjectTest");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XStaticObjectTest.xcframework/ios-arm64_x86_64-maccatalyst/XStaticObjectTest.framework/XStaticObjectTest"), $"{assemblyName}.resources/XStaticObjectTest.xcframework/ios-arm64_x86_64-maccatalyst/XStaticObjectTest.framework/XStaticObjectTest");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XStaticObjectTest.xcframework/ios-arm64_x86_64-simulator/XStaticObjectTest.framework/XStaticObjectTest"), $"{assemblyName}.resources/XStaticObjectTest.xcframework/ios-arm64_x86_64-simulator/XStaticObjectTest.framework/XStaticObjectTest");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XStaticObjectTest.xcframework/macos-arm64_x86_64/XStaticObjectTest.framework/XStaticObjectTest"), $"{assemblyName}.resources/XStaticObjectTest.xcframework/macos-arm64_x86_64/XStaticObjectTest.framework/XStaticObjectTest");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XStaticObjectTest.xcframework/tvos-arm64/XStaticObjectTest.framework/XStaticObjectTest"), $"{assemblyName}.resources/XStaticObjectTest.xcframework/tvos-arm64/XStaticObjectTest.framework/XStaticObjectTest");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XStaticObjectTest.xcframework/tvos-arm64_x86_64-simulator/XStaticObjectTest.framework/XStaticObjectTest"), $"{assemblyName}.resources/XStaticObjectTest.xcframework/tvos-arm64_x86_64-simulator/XStaticObjectTest.framework/XStaticObjectTest");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XTest.xcframework/Info.plist"), $"{assemblyName}.resources/XTest.xcframework/Info.plist");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XTest.xcframework/ios-arm64/XTest.framework/Info.plist"), $"{assemblyName}.resources/XTest.xcframework/ios-arm64/XTest.framework/Info.plist");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XTest.xcframework/ios-arm64/XTest.framework/XTest"), $"{assemblyName}.resources/XTest.xcframework/ios-arm64/XTest.framework/XTest");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XTest.xcframework/ios-arm64_x86_64-maccatalyst/XTest.framework/Resources"), $"{assemblyName}.resources/XTest.xcframework/ios-arm64_x86_64-maccatalyst/XTest.framework/Resources");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XTest.xcframework/ios-arm64_x86_64-maccatalyst/XTest.framework/XTest"), $"{assemblyName}.resources/XTest.xcframework/ios-arm64_x86_64-maccatalyst/XTest.framework/XTest");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XTest.xcframework/ios-arm64_x86_64-maccatalyst/XTest.framework/Versions/A/Resources/Info.plist"), $"{assemblyName}.resources/XTest.xcframework/ios-arm64_x86_64-maccatalyst/XTest.framework/Versions/A/Resources/Info.plist");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XTest.xcframework/ios-arm64_x86_64-maccatalyst/XTest.framework/Versions/A/XTest"), $"{assemblyName}.resources/XTest.xcframework/ios-arm64_x86_64-maccatalyst/XTest.framework/Versions/A/XTest");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XTest.xcframework/ios-arm64_x86_64-maccatalyst/XTest.framework/Versions/Current"), $"{assemblyName}.resources/XTest.xcframework/ios-arm64_x86_64-maccatalyst/XTest.framework/Versions/Current");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XTest.xcframework/ios-arm64_x86_64-simulator/XTest.framework/Info.plist"), $"{assemblyName}.resources/XTest.xcframework/ios-arm64_x86_64-simulator/XTest.framework/Info.plist");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XTest.xcframework/ios-arm64_x86_64-simulator/XTest.framework/XTest"), $"{assemblyName}.resources/XTest.xcframework/ios-arm64_x86_64-simulator/XTest.framework/XTest");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XTest.xcframework/macos-arm64_x86_64/XTest.framework/Resources"), $"{assemblyName}.resources/XTest.xcframework/macos-arm64_x86_64/XTest.framework/Resources");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XTest.xcframework/macos-arm64_x86_64/XTest.framework/XTest"), $"{assemblyName}.resources/XTest.xcframework/macos-arm64_x86_64/XTest.framework/XTest");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XTest.xcframework/macos-arm64_x86_64/XTest.framework/Versions/A/Resources/Info.plist"), $"{assemblyName}.resources/XTest.xcframework/macos-arm64_x86_64/XTest.framework/Versions/A/Resources/Info.plist");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XTest.xcframework/macos-arm64_x86_64/XTest.framework/Versions/A/XTest"), $"{assemblyName}.resources/XTest.xcframework/macos-arm64_x86_64/XTest.framework/Versions/A/XTest");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XTest.xcframework/macos-arm64_x86_64/XTest.framework/Versions/Current"), $"{assemblyName}.resources/XTest.xcframework/macos-arm64_x86_64/XTest.framework/Versions/Current");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XTest.xcframework/tvos-arm64/XTest.framework/Info.plist"), $"{assemblyName}.resources/XTest.xcframework/tvos-arm64/XTest.framework/Info.plist");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XTest.xcframework/tvos-arm64/XTest.framework/XTest"), $"{assemblyName}.resources/XTest.xcframework/tvos-arm64/XTest.framework/XTest");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XTest.xcframework/tvos-arm64_x86_64-simulator/XTest.framework/Info.plist"), $"{assemblyName}.resources/XTest.xcframework/tvos-arm64_x86_64-simulator/XTest.framework/Info.plist");
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources/XTest.xcframework/tvos-arm64_x86_64-simulator/XTest.framework/XTest"), $"{assemblyName}.resources/XTest.xcframework/tvos-arm64_x86_64-simulator/XTest.framework/XTest");
} else {
Assert.That (files, Does.Contain ($"lib/{tfm}/{assemblyName}.resources.zip"), $"{assemblyName}.resources.zip");
}
}
}

Expand Down Expand Up @@ -249,14 +344,26 @@ public void BindingCompressedXcFrameworksProject (ApplePlatform platform, bool c
[TestCase (ApplePlatform.TVOS)]
[TestCase (ApplePlatform.MacOSX)]
public void LibraryProject (ApplePlatform platform)
{
LibraryProjectImpl (platform);
}

[TestCase (ApplePlatform.iOS)]
[Category ("RemoteWindows")]
public void LibraryProjectOnRemoteWindows (ApplePlatform platform)
{
LibraryProjectImpl (platform, AddRemoteProperties ());
}

void LibraryProjectImpl (ApplePlatform platform, Dictionary<string, string>? properties = null)
{
var project = "MyClassLibrary";
var configuration = "Release";
Configuration.IgnoreIfIgnoredPlatform (platform);

var project_path = GetProjectPath (project, runtimeIdentifiers: string.Empty, platform: platform, out var appPath, configuration: configuration);
var project_path = GetProjectPath (project, platform: platform);
Clean (project_path);
var properties = GetDefaultProperties ();
properties = GetDefaultProperties (extraProperties: properties);

DotNet.AssertPack (project_path, properties);

Expand Down
4 changes: 3 additions & 1 deletion tests/dotnet/UnitTests/TestBaseClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ protected static Dictionary<string, string> GetDefaultProperties (string? runtim
return rv;
}

protected static void AddRemoteProperties (Dictionary<string, string> properties)
protected static Dictionary<string, string> AddRemoteProperties (Dictionary<string, string>? properties = null)
{
properties ??= new Dictionary<string, string> ();
properties ["ServerAddress"] = Environment.GetEnvironmentVariable ("MAC_AGENT_IP") ?? string.Empty;
properties ["ServerUser"] = Environment.GetEnvironmentVariable ("MAC_AGENT_USER") ?? string.Empty;
properties ["ServerPassword"] = Environment.GetEnvironmentVariable ("XMA_PASSWORD") ?? string.Empty;
if (!string.IsNullOrEmpty (properties ["ServerUser"]))
properties ["ContinueOnDisconnected"] = "false";
return properties;
}

protected static void SetRuntimeIdentifiers (Dictionary<string, string> properties, string runtimeIdentifiers)
Expand Down