[tests] Port link sdk to .NET. (#9509)

And fix all the test failures, so that the Debug configuration is green.
This commit is contained in:
Rolf Bjarne Kvinge 2020-08-26 18:38:13 +02:00 коммит произвёл GitHub
Родитель 6a1e8acbb0 09e3631cb1
Коммит 87395b4ef1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
12 изменённых файлов: 203 добавлений и 5 удалений

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

@ -13,6 +13,9 @@ namespace LinkSdk {
[TestFixture]
// we want the test to be availble if we use the linker
[Preserve (AllMembers = true)]
#if NET
[Ignore ("Type converters are linked away: https://github.com/mono/linker/issues/1451")]
#endif
public class CommonLinkSdkTest {
[Test]

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

@ -469,6 +469,9 @@ namespace LinkSdk.Aot {
}
[Test]
#if NET
[Ignore ("MulticastDelegate.BeginInvoke isn't supported in .NET (https://github.com/dotnet/runtime/issues/16312)")]
#endif
public void Bug5354 ()
{
Action<string> testAction = (string s) => { s.ToString (); };

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

@ -16,6 +16,9 @@ namespace LinkSdk {
return Task.Run (async () => await (new HttpClient ()).GetStringAsync (NetworkResources.MicrosoftUrl));
}
#if NET
[Ignore ("System.EntryPointNotFoundException: AppleCryptoNative_SecKeychainItemCopyKeychain")] // https://github.com/dotnet/runtime/issues/36897
#endif
[Test]
public void Bug12221 ()
{

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

@ -148,6 +148,9 @@ namespace LinkSdk.Serialization {
}
}
#if NET
[Ignore ("https://github.com/mono/linker/issues/1454")]
#endif
[Test]
// http://bugzilla.xamarin.com/show_bug.cgi?id=1820
// note: this also test the linker (5.1+) ability not to remove 'unused' XML setters and .ctors used for serialization

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

@ -23,6 +23,9 @@ namespace LinkSdk {
[Preserve (AllMembers = true)]
public class CryptoTest {
#if NET
[Ignore ("https://github.com/dotnet/runtime/issues/36897")]
#endif
[Test]
public void AesCreate ()
{
@ -35,6 +38,9 @@ namespace LinkSdk {
static int trust_validation_callback;
#if NET
[Ignore ("System.EntryPointNotFoundException: AppleCryptoNative_SecKeychainItemCopyKeychain")] // https://github.com/dotnet/runtime/issues/36897
#endif
[Test]
public void TrustUsingNewCallback ()
{
@ -64,6 +70,9 @@ namespace LinkSdk {
}
}
#if NET
[Ignore ("System.EntryPointNotFoundException: AppleCryptoNative_SecKeychainItemCopyKeychain")] // https://github.com/dotnet/runtime/issues/36897
#endif
[Test]
public void SSL_IP_5706 ()
{
@ -88,6 +97,9 @@ namespace LinkSdk {
static int sne_validation_callback;
#if NET
[Ignore ("System.EntryPointNotFoundException: AppleCryptoNative_SecKeychainItemCopyKeychain")] // https://github.com/dotnet/runtime/issues/36897
#endif
[Test]
public void TLS1_ServerNameExtension ()
{
@ -133,6 +145,9 @@ namespace LinkSdk {
}
}
#if NET
[Ignore ("System.EntryPointNotFoundException: AppleCryptoNative_SecKeychainCreate")] // https://github.com/dotnet/runtime/issues/36897
#endif
[Test]
public void Chain ()
{
@ -213,6 +228,10 @@ namespace LinkSdk {
0x58, 0x62, 0x42, 0x43, 0x35, 0x37, 0x77, 0x3D, 0x3D, 0x0D, 0x0A, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x45, 0x4E, 0x44, 0x20,
0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x0D, 0x0A, };
#if NET
[Ignore ("System.EntryPointNotFoundException : AppleCryptoNative_SecCopyErrorMessageString")] // https://github.com/dotnet/runtime/issues/36897
#endif
[Test]
public void Sha256 ()
{

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

@ -75,6 +75,9 @@ namespace LinkSdk {
}
}
#if NET
[Ignore ("https://github.com/dotnet/runtime/issues/41355")]
#endif
[Test]
public void LackOfCapget ()
{

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

@ -29,14 +29,18 @@ namespace LinkSdk {
[Test]
public void Corlib ()
{
Type t = Type.GetType ("System.Security.PermissionSet, mscorlib");
Type t = Type.GetType ("System.Security.PermissionSet, " + typeof (int).Assembly.GetName ().Name);
Assert.NotNull (t, "System.Security.PermissionSet");
}
[Test]
public void System ()
{
#if NET
Type t = Type.GetType ("System.Net.Mime.ContentType, System.Net.Mail");
#else
Type t = Type.GetType ("System.Net.Mime.ContentType, System");
#endif
Assert.NotNull (t, "System.Net.Mime.ContentType");
// we asked for ParseValue to be preserved
Assert.NotNull (t.GetMethod ("ParseValue", BindingFlags.Instance | BindingFlags.NonPublic), "Parse");

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

@ -18,7 +18,9 @@ using System.Security.Permissions;
using System.Security.Principal;
using System.Threading;
using System.Xml;
#if !NET
using Mono.Data.Sqlite;
#endif
using MonoTouch;
#if !__TVOS__ && !__WATCHOS__
using AddressBook;
@ -79,6 +81,7 @@ namespace LinkSdk {
// the above should not throw System.Runtime.Serialization.SerializationException
}
#if !NET // This test requires Mono.Data.SqliteConnection, which .NET 5+ doesn't have
[Test]
// http://bugzilla.xamarin.com/show_bug.cgi?id=233
public void Bug233_MonoPInvokeCallback ()
@ -89,6 +92,7 @@ namespace LinkSdk {
// the above should not crash
c.Close ();
}
#endif
[Test]
// http://bugzilla.xamarin.com/show_bug.cgi?id=234
@ -226,6 +230,7 @@ namespace LinkSdk {
}
}
#if !NET // This test requires System.ServiceModel.dll, which .NET 5+ doesn't have
[Test]
// http://bugzilla.xamarin.com/show_bug.cgi?id=1415
public void Bug1415_Linker_DataMember ()
@ -268,7 +273,9 @@ namespace LinkSdk {
Assert.True (stack_trace, "StackTrace");
Assert.True (type, "Type");
}
#endif // !NET
#if !NET // This test requires System.ServiceModel.dll, which .NET 5+ doesn't have
[Test]
// http://bugzilla.xamarin.com/show_bug.cgi?id=1415
// not really part of the bug - but part of the same fix
@ -285,6 +292,7 @@ namespace LinkSdk {
// should be null if application is linked (won't be if "Don't link" is used)
#endif // !__WATCHOS__
}
#endif // !NET
[Test]
// http://bugzilla.xamarin.com/show_bug.cgi?id=1443
@ -386,6 +394,7 @@ namespace LinkSdk {
}
}
#if !NET // This test requires Mono.Data.SqliteConnection, which .NET 5+ doesn't have
[Test]
// http://stackoverflow.com/questions/8602726/cant-open-sqlite-database-in-read-only-mode
public void Sqlite_ReadOnly ()
@ -395,6 +404,7 @@ namespace LinkSdk {
// the above should not throw a 'misuse' exception
c.Close ();
}
#endif
[Test]
public void AsQueryable_3028 ()
@ -405,6 +415,7 @@ namespace LinkSdk {
}
#if !__WATCHOS__
#if !NET // OpenTK-1.0.dll is not supported yet
[Test]
public void OpenTk_3049 ()
{
@ -430,6 +441,7 @@ namespace LinkSdk {
core = GetTypeHelper ("OpenTK.Graphics.ES20.GL/Core, " + OpenTKAssembly, false);
Assert.NotNull (core, "ES20/Core");
}
#endif // !NET
#endif // !__WATCHOS__
[Test]
@ -622,6 +634,9 @@ namespace LinkSdk {
Assert.NotNull (NetworkInterface.GetAllNetworkInterfaces ());
}
#if NET
[Ignore ("System.EntryPointNotFoundException: AppleCryptoNative_SecKeychainItemCopyKeychain")] // https://github.com/dotnet/runtime/issues/36897
#endif
[Test]
public void WebClient_SSL_Leak ()
{
@ -678,7 +693,7 @@ namespace LinkSdk {
public void Pointer_5200 ()
{
// ensure the linker did not remove the type, which is used by the runtime
Assert.NotNull (GetTypeHelper ("System.Reflection.Pointer, mscorlib"));
Assert.NotNull (GetTypeHelper ("System.Reflection.Pointer, " + typeof (int).Assembly.GetName ().Name));
}
[Test]
@ -720,11 +735,13 @@ namespace LinkSdk {
Assert.IsFalse (Attribute.IsDefined (GetType (), typeof(SerializableAttribute)));
}
#if !NET // This test requires System.Runtime.Remoting.dll, which .NET 5+ doesn't have
[Test]
public void LinkedAway ()
{
Assert.Throws<NotSupportedException> (() => new System.Runtime.Remoting.RemotingException ());
}
#endif // !NET
[Test]
public void ArrayClear_11184 ()
@ -785,7 +802,12 @@ namespace LinkSdk {
var mem = System.Diagnostics.Process.GetCurrentProcess ().PrivateMemorySize64;
// the above used a mach call that iOS samdbox did *not* allow (sandbox) on device
// but has been fixed (different call) for the same PID
#if NET
// It's not entirely clear, but it appears this is not implemented, and won't be, for mobile platforms: https://github.com/dotnet/runtime/issues/28990
Assert.That (mem, Is.EqualTo (0), "PrivateMemorySize64");
#else
Assert.That (mem, Is.Not.EqualTo (0), "PrivateMemorySize64");
#endif
}
string TestFolder (Environment.SpecialFolder folder, bool supported = true, bool exists = true, bool readOnly = false)
@ -880,8 +902,10 @@ namespace LinkSdk {
Assert.That (path, Is.EqualTo ("/usr/share"), "path - CommonApplicationData");
// and the simulator is more lax
#if !NET // https://github.com/dotnet/runtime/issues/41383
path = TestFolder (Environment.SpecialFolder.ProgramFiles, readOnly: device);
Assert.That (path, Is.EqualTo ("/Applications"), "path - ProgramFiles");
#endif
path = TestFolder (Environment.SpecialFolder.UserProfile, readOnly: device);
var bundlePath = NSBundle.MainBundle.BundlePath;
@ -987,7 +1011,11 @@ namespace LinkSdk {
[Test]
public void MonoRuntime34671 ()
{
#if NET
Assert.Null (GetTypeHelper ("Mono.Runtime"), "Mono.Runtime");
#else
Assert.NotNull (GetTypeHelper ("Mono.Runtime"), "Mono.Runtime");
#endif
}
[Test]
@ -998,6 +1026,7 @@ namespace LinkSdk {
}
#if !__WATCHOS__
#if !NET // This test requires Mono.Security.dll, which .NET 5+ doesn't have
[Test]
public void TlsProvider_Apple ()
{
@ -1005,6 +1034,7 @@ namespace LinkSdk {
Assert.NotNull (provider, "provider");
Assert.That (provider.ID, Is.EqualTo (new Guid ("981af8af-a3a3-419a-9f01-a518e3a17c1c")), "correct provider");
}
#endif
[Test]
public void Github5024 ()
@ -1073,6 +1103,9 @@ namespace LinkSdk {
}
#endif
#if NET
[Ignore ("https://github.com/mono/linker/issues/1453")]
#endif
[Test]
// https://github.com/xamarin/xamarin-macios/issues/6346
public void AsQueryable_Enumerable ()

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

@ -33,7 +33,7 @@ namespace LinkSdk {
Assert.False (this is ICommand, "ICommand");
HttpWebRequest hwr = new HttpWebRequest (uri);
HttpWebRequest hwr = WebRequest.CreateHttp (uri);
try {
Assert.True (hwr.SupportsCookieContainer, "SupportsCookieContainer");
}
@ -70,20 +70,30 @@ namespace LinkSdk {
{
AddressHeaderCollection ahc = new AddressHeaderCollection ();
try {
ahc.FindAll (null, null);
ahc.FindAll ("name", "namespace");
}
catch (NotImplementedException) {
// feature is not available, but the symbol itself is needed
}
try {
FaultException.CreateFault (null, String.Empty, null);
FaultException.CreateFault (new TestFault (), String.Empty, Array.Empty<Type> ());
}
catch (NotImplementedException) {
// feature is not available, but the symbol itself is needed
}
}
class TestFault : MessageFault {
public override FaultCode Code => throw new NotImplementedException ();
public override bool HasDetail => throw new NotImplementedException ();
public override FaultReason Reason => throw new NotImplementedException ();
protected override void OnWriteDetailContents (XmlDictionaryWriter writer)
{
throw new NotImplementedException ();
}
}
[Test]
public void Xml ()
{

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

@ -0,0 +1,14 @@
<linker>
<!-- see LinkExtraDefsTest unit tests -->
<assembly fullname="System.Private.CoreLib">
<type fullname="System.Security.PermissionSet" />
</assembly>
<assembly fullname="System.Net.Mail">
<type fullname="System.Net.Mime.ContentType" >
<method name="ParseValue" />
</type>
</assembly>
<assembly fullname="Xamarin.iOS">
<type fullname="CoreBluetooth.CBUUID" preserve="field" />
</assembly>
</linker>

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

@ -0,0 +1,102 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.iOS.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RuntimeIdentifier>ios-x64</RuntimeIdentifier>
<OutputType>Exe</OutputType>
<DefineConstants>NET</DefineConstants>
<LangVersion>latest</LangVersion>
<RootNamespace>linksdk</RootNamespace>
<AssemblyName>link sdk</AssemblyName>
<MtouchLink>SdkOnly</MtouchLink>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssetTargetFallback>xamarinios10;$(AssetTargetFallback)</AssetTargetFallback>
<MtouchExtraArgs>-disable-thread-check -xml=${ProjectDir}/../extra-linker-defs.xml "--dlsym:-link sdk" -gcc_flags="-UhoItsB0rken"</MtouchExtraArgs>
</PropertyGroup>
<ItemGroup>
<Reference Include="support">
<HintPath>../../support.dll</HintPath>
</Reference>
<PackageReference Include="NUnitLite" Version="3.12.0" />
<PackageReference Include="MonoTouch.Dialog" Version="2.0.0-pre1" />
<ProjectReference Include="..\..\..\..\..\..\external\Touch.Unit\Touch.Client\dotnet\iOS\Touch.Client-iOS.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.3.20209.5" />
<PackageReference Include="System.Data.SqlClient" Version="5.0.0-alpha1.19523.8" />
<PackageReference Include="System.ServiceModel.Primitives" Version="5.0.0-preview1.20104.1" />
<ProjectReference Include="..\..\..\..\..\BundledResources\dotnet\iOS\BundledResources.csproj" />
<ProjectReference Include="..\..\..\..\..\bindings-test\dotnet\iOS\bindings-test.csproj" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\Info.plist">
<LogicalName>Info.plist</LogicalName>
</None>
<None Include="..\..\extra-linker-defs.xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\Main.cs" />
<Compile Include="..\..\AppDelegate.cs" />
<Compile Include="..\..\LinkSdkRegressionTest.cs" />
<Compile Include="..\..\Bug1820Test.cs" />
<Compile Include="..\..\Bug2096Test.cs" />
<Compile Include="..\..\..\..\BaseOptimizeGeneratedCodeTest.cs" />
<Compile Include="..\..\OptimizeGeneratedCodeTest.cs" />
<Compile Include="..\..\AotBugs.cs" />
<Compile Include="..\..\CryptoTest.cs" />
<Compile Include="..\..\TaskTest.cs" />
<Compile Include="..\..\LinkExtraDefsTest.cs" />
<Compile Include="..\..\PclTest.cs" />
<Compile Include="..\..\AsyncTest.cs" />
<Compile Include="..\..\DataContractTest.cs" />
<Compile Include="..\..\CalendarTest.cs" />
<Compile Include="..\..\DllImportTest.cs" />
<Compile Include="..\..\LocaleTest.cs" />
<Compile Include="..\..\ReflectionTest.cs" />
<Compile Include="..\..\HttpClientHandlerTest.cs" />
<Compile Include="..\..\CanaryTest.cs" />
<Compile Include="..\..\..\..\..\common\TestRuntime.cs">
<Link>TestRuntime.cs</Link>
</Compile>
<Compile Include="..\..\..\..\ILReader.cs">
<Link>ILReader.cs</Link>
</Compile>
<Compile Include="..\..\..\..\CommonLinkSdkTest.cs">
<Link>CommonLinkSdkTest.cs</Link>
</Compile>
<Compile Include="..\..\..\..\CommonLinkAnyTest.cs">
<Link>CommonLinkAnyTest.cs</Link>
</Compile>
<Compile Include="..\..\BitcodeTest.cs" />
<Compile Include="..\..\..\..\..\monotouch-test\System.Net.Http\NetworkResources.cs">
<Link>NetworkResources.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="..\..\LaunchScreen.storyboard" />
</ItemGroup>
<ItemGroup>
<ImageAsset Include="..\..\Assets.xcassets\AppIcons.appiconset\Contents.json" />
<ImageAsset Include="..\..\Assets.xcassets\AppIcons.appiconset\Icon-app-60%403x.png" />
<ImageAsset Include="..\..\Assets.xcassets\AppIcons.appiconset\icon-app-57.png" />
<ImageAsset Include="..\..\Assets.xcassets\AppIcons.appiconset\icon-app-57%402x.png" />
<ImageAsset Include="..\..\Assets.xcassets\AppIcons.appiconset\icon-app-60%402x.png" />
<ImageAsset Include="..\..\Assets.xcassets\AppIcons.appiconset\icon-app-72.png" />
<ImageAsset Include="..\..\Assets.xcassets\AppIcons.appiconset\icon-app-72%402x.png" />
<ImageAsset Include="..\..\Assets.xcassets\AppIcons.appiconset\icon-app-76.png" />
<ImageAsset Include="..\..\Assets.xcassets\AppIcons.appiconset\icon-app-76%402x.png" />
<ImageAsset Include="..\..\Assets.xcassets\AppIcons.appiconset\icon-app-83.5%402x.png" />
</ItemGroup>
</Project>

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

@ -396,6 +396,7 @@ namespace Xharness {
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "dont link", "dotnet", "iOS", "dont link.csproj"))) { Configurations = new string [] { "Debug", "Release" }, IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = true, SkipiOS32Variation = true });
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link all", "link all.csproj"))) { Configurations = new string [] { "Debug", "Release" } });
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link sdk", "link sdk.csproj"))) { Configurations = new string [] { "Debug", "Release" } });
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link sdk", "dotnet", "iOS", "link sdk.csproj"))) { Configurations = new string [] { "Debug" /*, "Release" */ }, IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = true, SkipiOS32Variation = true });
foreach (var flavor in new MonoNativeFlavor [] { MonoNativeFlavor.Compat, MonoNativeFlavor.Unified }) {
var monoNativeInfo = new MonoNativeInfo (DevicePlatform.iOS, flavor, RootDirectory, Log);