[tests] Add a .NET/macOS version of monotouch-test. (#10672)

* [tests] Add a .NET/macOS version of monotouch-test.

I made a macOS version of monotouch-test instead of a .NET version of xammac tests,
so that one day we might have only one test suite for all our API tests.

* Add a project file for .NET/macOS
* Fix some code to handle the fact that we're called 'monotouchtest' on macOS (but
  only on .NET).
* Ignore exception marshalling tests, those aren't working yet.

* [xharness] Add support for .NET/macOS and add a macOS version of monotouch-test to our tests

* [dotnet-linker] Skip libSystem.Net.Security.Native and libSystem.Native when collecting native methods to preserve for .NET/macOS.
This commit is contained in:
Rolf Bjarne Kvinge 2021-02-24 16:07:04 +01:00 коммит произвёл GitHub
Родитель f29592e7cf
Коммит 538fd86172
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
13 изменённых файлов: 301 добавлений и 10 удалений

Просмотреть файл

@ -15,7 +15,7 @@ namespace MonoTouchFixtures.CoreFoundation {
public class BundleTest {
#if __WATCHOS__
const string ExpectedAppName = "monotouchtest.appex";
#elif MONOMAC
#elif MONOMAC && !NET
const string ExpectedAppName = "xammac_tests.app";
#else
const string ExpectedAppName = "monotouchtest.app";
@ -84,7 +84,7 @@ namespace MonoTouchFixtures.CoreFoundation {
var main = CFBundle.GetMain ();
#if __WATCHOS__
var expectedBundleId = "com.xamarin.monotouch-test_watch.watchkitapp.watchkitextension";
#elif MONOMAC
#elif MONOMAC && !NET
var expectedBundleId = "com.xamarin.xammac_tests";
#else
var expectedBundleId = "com.xamarin.monotouch-test";
@ -104,9 +104,9 @@ namespace MonoTouchFixtures.CoreFoundation {
public void TestExecutableUrl ()
{
var main = CFBundle.GetMain ();
#if MONOMAC
#if MONOMAC && !NET
var executableRelativePath = Path.Combine (ExpectedAppName, "Contents", "MacOS", "xammac_tests");
#elif __MACCATALYST__
#elif __MACCATALYST__ || __MACOS__
var executableRelativePath = Path.Combine (ExpectedAppName, "Contents", "MacOS", "monotouchtest");
#else
var executableRelativePath = Path.Combine (ExpectedAppName, "monotouchtest");

Просмотреть файл

@ -45,7 +45,7 @@ namespace MonoTouchFixtures.NetworkExtension {
var HasLocalizedDescription = TestRuntime.CheckSystemVersion (PlatformName.MacOSX, 10, 11);
#endif
if (HasLocalizedDescription) {
#if MONOMAC
#if MONOMAC && !NET
Assert.AreEqual ("xammac_tests", shared.LocalizedDescription, "LocalizedDescription");
#else
Assert.AreEqual ("MonoTouchTest", shared.LocalizedDescription, "LocalizedDescription");

Просмотреть файл

@ -95,6 +95,11 @@ namespace MonoTouchFixtures.ObjCRuntime {
#if !DEBUG && !__WATCHOS__
Assert.Ignore ("This test only works in debug mode in the simulator.");
#endif
#if NET && (__MACOS__ || __MACCATALYST__)
Assert.Ignore ("Exception marshalling hasn't been completely implemented on macOS/Mac Catalyst yet, due to removal of the dllmap support");
#endif
InstallHandlers ();
try {
@ -144,6 +149,10 @@ namespace MonoTouchFixtures.ObjCRuntime {
#endif
var hasDebugger = global::System.Diagnostics.Debugger.IsAttached;
#if NET && (__MACOS__ || __MACCATALYST__)
Assert.Ignore ("Exception marshalling hasn't been completely implemented on macOS/Mac Catalyst yet, due to removal of the dllmap support");
#endif
InstallHandlers ();
try {
using (var e = new ManagedExceptionTest ()) {

Просмотреть файл

@ -27,7 +27,7 @@ namespace MonoTouchFixtures.Security {
#endif
public void Add_Certificate ()
{
#if MONOMAC
#if MONOMAC && !NET
Stream certStream = typeof (KeyChainTest).Assembly.GetManifestResourceStream ("xammac_tests.Security.openssl_crt.der");
#else
Stream certStream = typeof(KeyChainTest).Assembly.GetManifestResourceStream ("monotouchtest.Security.openssl_crt.der");

Просмотреть файл

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>MonoTouchTest</string>
<key>CFBundleIdentifier</key>
<string>com.xamarin.monotouch-test</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>10.9</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>LSUIElement</key>
<string>1</string>
<key>CFBundleName</key>
<string>MonoTouchTest</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>CFBundlePackageType</key>
<string>APPL</string>
</dict>
</plist>

Просмотреть файл

@ -0,0 +1,222 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-macos</TargetFramework>
<RuntimeIdentifier>osx-x64</RuntimeIdentifier>
<OutputType>Exe</OutputType>
<DefineConstants>NET</DefineConstants>
<LangVersion>latest</LangVersion>
<RootNamespace>monotouchtest</RootNamespace>
<AssemblyName>monotouchtest</AssemblyName>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\..\..\product.snk</AssemblyOriginatorKeyFile>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<CodesignEntitlements Condition="'$(Platform)' == 'iPhoneSimulator'">..\..\Entitlements.plist</CodesignEntitlements>
<DefineConstants>$(DefineConstants);MONOMAC;XAMMAC_TESTS</DefineConstants>
<DefineConstants Condition="'$(Configuration)' == 'Debug'">$(DefineConstants);DEBUG;DYNAMIC_REGISTRAR</DefineConstants>
<RootTestsDirectory>..\..\..</RootTestsDirectory>
<MonoBundlingExtraArgs>--marshal-objectivec-exceptions:disable</MonoBundlingExtraArgs>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnitLite" Version="3.12.0" />
<!-- <PackageReference Include="MonoTouch.Dialog" Version="2.0.0-pre1" /> -->
<ProjectReference Include="..\..\..\..\external\Touch.Unit\Touch.Client\dotnet\macOS\Touch.Client-macOS.dotnet.csproj" />
<!-- MonoTouch.Dialog references System.Json, which isn't shipped with .NET5, so reference the NuGet instead -->
<PackageReference Include="System.Json" Version="4.7.1" />
<!-- The linker resolves some assembly references too eagerly, and fails when it can't find them, so work around this by referencing the missing assemblies-->
<!-- ref: https://github.com/mono/linker/issues/1139 -->
<PackageReference Include="System.Security.Permissions" Version="5.0.0-preview.2.20160.6" />
<PackageReference Include="System.Threading.AccessControl" Version="5.0.0-preview.2.20160.6" />
<PackageReference Include="System.CodeDom" Version="5.0.0-preview.2.20160.6" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0-preview.2.20160.6" />
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="5.0.0-preview.2.20160.6" />
<PackageReference Include="System.Diagnostics.EventLog" Version="5.0.0-preview.2.20160.6" />
<PackageReference Include="System.IO.Ports" Version="5.0.0-preview.2.20160.6" />
<PackageReference Include="System.Data.SqlClient" Version="5.0.0-alpha1.19523.8" />
</ItemGroup>
<ItemGroup>
<None Include="Info.plist">
<LogicalName>Info.plist</LogicalName>
</None>
<None Include="..\..\Entitlements.plist" />
<None Include="..\..\app.config" />
<None Include="..\..\EmptyNib.xib" />
<LinkDescription Include="$(RootTestsDirectory)\monotouch-test\dotnet\extra-linker-defs.xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\**\*.cs" Exclude="$(DefaultItemExcludes);..\..\obj\**;..\..\dotnet\**">
<Link>%(RecursiveDir)%(Filename).cs</Link>
</Compile>
<Compile Include="..\..\..\..\tests\test-libraries\TrampolineTest.generated.cs" />
<Compile Include="..\..\..\..\tests\test-libraries\RegistrarTest.generated.cs" />
<Compile Include="..\..\..\api-shared\ObjCRuntime\RegistrarTest.cs">
<Link>shared\ObjCRuntime\RegistrarTest.cs</Link>
</Compile>
<Compile Include="..\..\..\api-shared\CoreFoundation\CFNotificationCenterTest.cs">
<Link>CoreFoundation\CFNotificationCenterTest.cs</Link>
</Compile>
<Compile Include="..\..\..\common\TestRuntime.cs">
<Link>TestRuntime.cs</Link>
</Compile>
<Compile Include="..\..\..\common\mac\TestRuntime.macos.cs">
<Link>TestRuntime.macos.cs</Link>
</Compile>
<Compile Include="..\..\..\common\ConditionalCompilation.cs">
<Link>ConditionalCompilation.cs</Link>
</Compile>
<Compile Include="..\..\..\common\Extensions.cs">
<Link>Extensions.cs</Link>
</Compile>
<Compile Include="..\..\..\common\PlatformInfo.cs">
<Link>PlatformInfo.cs</Link>
</Compile>
<Compile Include="..\..\..\common\mac\MacMain.cs">
<Link>MacMain.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<Content Include="..\..\AudioToolbox\1.caf">
<Link>AudioToolbox\1.caf</Link>
</Content>
<Content Include="..\..\Tamarin.pdf">
<Link>Tamarin.pdf</Link>
</Content>
<Content Include="..\..\basn3p08.png">
<Link>basn3p08.png</Link>
</Content>
<Content Include="..\..\BoardingPass.pkpass">
<Link>BoardingPass.pkpass</Link>
</Content>
<Content Include="..\..\Hand.wav">
<Link>Hand.wav</Link>
</Content>
<Content Include="..\..\Pacifico.ttf">
<Link>Pacifico.ttf</Link>
</Content>
<Content Include="..\..\LL-171A-B-B797E457-16AB-C708-1E0F-32C19DBD47B5.icc">
<Link>LL-171A-B-B797E457-16AB-C708-1E0F-32C19DBD47B5.icc</Link>
</Content>
<Content Include="..\..\drum01.mp3">
<Link>drum01.mp3</Link>
</Content>
<Content Include="..\..\Model3.arobject">
<Link>Model3.arobject</Link>
</Content>
<Content Include="..\..\access-denied.html">
<Link>access-denied.html</Link>
</Content>
<Content Include="..\..\access-granted.html">
<Link>access-granted.html</Link>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\EmbeddedResources\dotnet\macOS\EmbeddedResources.csproj" />
<ProjectReference Include="..\..\..\..\tests\bindings-test\dotnet\macOS\bindings-test.csproj" />
<ProjectReference Include="..\..\..\fsharplibrary\dotnet\macOS\fsharplibrary.fsproj" />
</ItemGroup>
<ItemGroup>
<BundleResource Include="..\..\CoreImage\Xam.png">
<Link>CoreImage\Xam.png</Link>
</BundleResource>
<BundleResource Include="..\..\Resources\xamarin0.png">
<Link>Resources\xamarin0.png</Link>
</BundleResource>
<BundleResource Include="..\..\Resources\xamarin1.png">
<Link>Resources\xamarin1.png</Link>
</BundleResource>
<BundleResource Include="..\..\Resources\xamarin2.png">
<Link>Resources\xamarin2.png</Link>
</BundleResource>
<BundleResource Include="..\..\xamvideotest.mp4">
<Link>xamvideotest.mp4</Link>
</BundleResource>
<BundleResource Include="..\..\CoreImage\xamarinmonkey.heic">
<Link>CoreImage\xamarinmonkey.heic</Link>
</BundleResource>
<BundleResource Include="..\..\Resources\Base.lproj\Localizable.strings">
<Link>Resources\Base.lproj\Localizable.strings</Link>
</BundleResource>
<BundleResource Include="..\..\Resources\metal-sample.metal">
<Link>Resources\metal-sample.metal</Link>
</BundleResource>
<BundleResource Include="..\..\Resources\fragmentShader.metal">
<Link>Resources\fragmentShader.metal</Link>
</BundleResource>
<BundleResource Include="..\..\uncompressed.txt">
<Link>uncompressed.txt</Link>
</BundleResource>
<BundleResource Include="..\..\compressed_lze">
<Link>compressed_lze</Link>
</BundleResource>
<BundleResource Include="..\..\compressed_lz4">
<Link>compressed_lz4</Link>
</BundleResource>
<BundleResource Include="..\..\compressed_lzma">
<Link>compressed_lzma</Link>
</BundleResource>
<BundleResource Include="..\..\compressed_zip">
<Link>compressed_zip</Link>
</BundleResource>
<BundleResource Include="..\..\example.pac">
<Link>example.pac</Link>
</BundleResource>
<BundleResource Include="..\..\Resources\square.gif">
<Link>Resources\square.gif</Link>
</BundleResource>
</ItemGroup>
<ItemGroup>
<Metal Include="..\..\Resources\metal-sample.metal" Condition="'$(_SdkIsSimulator)' != 'true'">
<Link>Resources\metal-sample.metal</Link>
</Metal>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\..\Security\openssl_crt.der">
<LogicalName>monotouchtest.Security.openssl_crt.der</LogicalName>
</EmbeddedResource>
</ItemGroup>
<PropertyGroup>
<TestLibrariesDirectory>..\..\..\..\tests\test-libraries</TestLibrariesDirectory>
</PropertyGroup>
<ItemGroup>
<GeneratedTestInput Include="$(TestLibrariesDirectory)\*.m" />
<GeneratedTestInput Include="$(TestLibrariesDirectory)\*.h" />
<GeneratedTestInput Include="$(TestLibrariesDirectory)\*.cs" />
<GeneratedTestInput Include="$(TestLibrariesDirectory)\Makefile" />
<GeneratedTestOutput Include="$(TestLibrariesDirectory)\TrampolineTest.generated.cs" />
<GeneratedTestOutput Include="$(TestLibrariesDirectory)\RegistrarTest.generated.cs" />
<CustomMetalSmeltingInput Include="..\..\Resources\fragmentShader.metal" />
</ItemGroup>
<Target Name="ComputeMetalOutputPath" DependsOnTargets="_GenerateBundleName;_DetectSdkLocations">
<PropertyGroup>
<MetalBundleSubDirectory Condition="'$(_PlatformName)' == 'macOS' Or '$(_PlatformName)' == 'MacCatalyst'">Contents/Resources/</MetalBundleSubDirectory>
</PropertyGroup>
</Target>
<Target Name="CustomMetalSmelting" Inputs="@(CustomMetalSmeltingInput)" Outputs="$(_AppBundlePath)\$(MetalBundleSubDirectory)fragmentShader.metallib" Condition="'$(_SdkIsSimulator)' != 'true'" DependsOnTargets="_GenerateBundleName;_DetectSdkLocations;ComputeMetalOutputPath" BeforeTargets="BeforeBuild">
<PropertyGroup>
<_SmeltingSdk Condition="'$(_PlatformName)' == 'iOS'">iphoneos</_SmeltingSdk>
<_SmeltingSdk Condition="'$(_PlatformName)' == 'tvOS'">appletvos</_SmeltingSdk>
<_SmeltingSdk Condition="'$(_PlatformName)' == 'macOS'">macosx</_SmeltingSdk>
<_SmeltingMinOS Condition="'$(_PlatformName)' == 'iOS'">-mios-version-min=11.0</_SmeltingMinOS>
<_SmeltingMinOS Condition="'$(_PlatformName)' == 'tvOS'">-mtvos-version-min=11.0</_SmeltingMinOS>
<_SmeltingMinOS Condition="'$(_PlatformName)' == 'macOS'">-mmacos-version-min=10.13</_SmeltingMinOS>
</PropertyGroup>
<MakeDir Directories="$(IntermediateOutputPath)/$(MetalBundleSubDirectory);$(AppBundleDir)/$(MetalBundleSubDirectory)" />
<Exec Command="xcrun -sdk $(_SmeltingSdk) metal -c @(CustomMetalSmeltingInput) -o $(IntermediateOutputPath)$(MetalBundleSubDirectory)\fragmentShader.air $(_SmeltingMinOS)" EnvironmentVariables="DEVELOPER_DIR=$(_SdkDevPath)" />
<Exec Command="xcrun -sdk $(_SmeltingSdk) metallib $(IntermediateOutputPath)/$(MetalBundleSubDirectory)fragmentShader.air -o $(AppBundleDir)/$(MetalBundleSubDirectory)fragmentShader.metallib" EnvironmentVariables="DEVELOPER_DIR=$(_SdkDevPath)" />
</Target>
<Target Name="BuildTestLibraries" Inputs="@(GeneratedTestInput)" Outputs="@(GeneratedTestOutput)" BeforeTargets="BeforeBuild" >
<Exec Command="make -j8 -C $(TestLibrariesDirectory)" />
</Target>
<Import Project="$(RootTestsDirectory)\nunit.framework.targets" />
</Project>

Просмотреть файл

@ -34,14 +34,18 @@ namespace Xharness {
public async Task<string> LocateAppBundle (XmlDocument projectFile, string projectFilePath, TestTarget target, string buildConfiguration)
{
var platform = target.IsSimulator () ? "iPhoneSimulator" : "iPhone";
string platform = string.Empty;
if (target != TestTarget.None)
platform = target.IsSimulator () ? "iPhoneSimulator" : "iPhone";
if (projectFile.IsDotNetProject ()) {
var properties = new Dictionary<string, string> {
{ "Configuration", buildConfiguration },
{ "Platform", platform },
};
if (!string.IsNullOrEmpty (platform))
properties ["Platform"] = platform;
return await GetPropertyByMSBuildEvaluationAsync (projectFile, projectFilePath, "OutputPath", "_GenerateBundleName", properties);
} else {
return projectFile.GetOutputPath (platform, buildConfiguration).Replace ('\\', Path.DirectorySeparatorChar);

Просмотреть файл

@ -289,6 +289,12 @@ namespace Xharness {
});
}
MacTestProjects.Add (new MacTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "monotouch-test", "dotnet", "macOS", "monotouch-test.csproj"))) {
Name = "monotouch-test",
IsDotNetProject = true,
TargetFrameworkFlavors = MacFlavors.DotNet,
});
foreach (var flavor in new MonoNativeFlavor [] { MonoNativeFlavor.Compat, MonoNativeFlavor.Unified }) {
var monoNativeInfo = new MonoNativeInfo (DevicePlatform.macOS, flavor, RootDirectory, Log);
var macTestProject = new MacTestProject (monoNativeInfo.ProjectPath, targetFrameworkFlavor: MacFlavors.Modern | MacFlavors.Full) {

Просмотреть файл

@ -76,7 +76,12 @@ namespace Xharness.Jenkins.TestTasks {
} else {
var project = new XmlDocument ();
project.LoadWithoutNetworkAccess (ProjectFile);
var outputPath = project.GetOutputPath (BuildTask.ProjectPlatform, BuildTask.ProjectConfiguration).Replace ('\\', '/');
string outputPath;
if (TestProject?.IsDotNetProject == true) {
outputPath = await Harness.AppBundleLocator.LocateAppBundle (project, ProjectFile, TestTarget.None, BuildTask.ProjectConfiguration);
} else {
outputPath = project.GetOutputPath (BuildTask.ProjectPlatform, BuildTask.ProjectConfiguration).Replace ('\\', '/');
}
var assemblyName = project.GetAssemblyName ();
Path = System.IO.Path.Combine (System.IO.Path.GetDirectoryName (ProjectFile), outputPath, assemblyName + ".app", "Contents", "MacOS", assemblyName);
}

Просмотреть файл

@ -13,7 +13,7 @@ namespace Xharness.Jenkins.TestTasks {
get {
switch (Platform) {
case TestPlatform.Mac:
return "Mac";
return TestProject?.IsDotNetProject == true ? "Mac [dotnet]" : "Mac";
case TestPlatform.Mac_Modern:
return "Mac Modern";
case TestPlatform.Mac_Full:

Просмотреть файл

@ -12,6 +12,7 @@ namespace Xharness {
MacFlavors.Full => TestPlatform.Mac_Full,
MacFlavors.Modern => TestPlatform.Mac_Modern,
MacFlavors.System => TestPlatform.Mac_System,
MacFlavors.DotNet => TestPlatform.Mac,
_ => throw new NotImplementedException (flavor.ToString ()),
};
}

Просмотреть файл

@ -7,6 +7,7 @@ namespace Xharness {
Full = 2, // Xamarin.Mac/Full app
System = 4, // Xamarin.Mac/System app
Console = 8, // Console executable
DotNet = 16,
}
public class MacTestProject : TestProject {
@ -17,6 +18,9 @@ namespace Xharness {
public override bool GenerateVariations {
get {
if (IsDotNetProject)
return false;
// If a bitwise combination of flavors, then we're generating variations
return TargetFrameworkFlavors != MacFlavors.Modern && TargetFrameworkFlavors != MacFlavors.Full && TargetFrameworkFlavors != MacFlavors.System && TargetFrameworkFlavors != MacFlavors.Console;
}

Просмотреть файл

@ -131,9 +131,22 @@ namespace Xamarin.Linker.Steps
Driver.Log (4, "Did not add native reference to {0} in {1} referenced by {2} in {3}.", pinfo.EntryPoint, pinfo.Module.Name, method.FullName, method.Module.Name);
break; // tvOS does not ship with System.Net.Security.Native due to https://github.com/dotnet/runtime/issues/45535
}
if (DerivedLinkContext.App.Platform == ApplePlatform.MacOSX) {
Driver.Log (4, "Did not add native reference to {0} in {1} referenced by {2} in {3}.", pinfo.EntryPoint, pinfo.Module.Name, method.FullName, method.Module.Name);
break; // The macOS version of the BCL has several references to native methods supposedly in libSystem.Net.Security.Native that aren't there, so skip it.
}
goto case "System.Native";
#endif
case "System.Native":
#if NET
if (DerivedLinkContext.App.Platform == ApplePlatform.MacOSX) {
Driver.Log (4, "Did not add native reference to {0} in {1} referenced by {2} in {3}.", pinfo.EntryPoint, pinfo.Module.Name, method.FullName, method.Module.Name);
break; // The macOS version of the BCL has several references to native methods supposedly in libSystem.Native that aren't there, so skip it.
}
goto case "System.Security.Cryptography.Native.Apple";
#endif
case "System.Security.Cryptography.Native.Apple":
Driver.Log (4, "Adding native reference to {0} in {1} because it's referenced by {2} in {3}.", pinfo.EntryPoint, pinfo.Module.Name, method.FullName, method.Module.Name);
DerivedLinkContext.RequireMonoNative = true;