[mmptest] Port link-uithread-1/2 to an NUnit LinkAll test. Partial fix for #4975. (#6546)

Fixes part of https://github.com/xamarin/xamarin-macios/issues/4975.
This commit is contained in:
Rolf Bjarne Kvinge 2019-07-11 01:24:21 -07:00 коммит произвёл GitHub
Родитель e0f16ffc9c
Коммит 891dfcb7d9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
9 изменённых файлов: 42 добавлений и 330 удалений

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

@ -1,4 +1,8 @@
using System;
using System.Runtime.CompilerServices;
using System.Threading;
using AppKit;
using Foundation;
using NUnit.Framework;
@ -25,5 +29,42 @@ namespace LinkAllTests
Check ("HijriCalendar", false);
Check ("ThaiBuddhistCalendar", false);
}
[Test]
public void EnsureUIThreadException ()
{
// works on main/ui thread
NSApplication.EnsureUIThread ();
ThreadPool.QueueUserWorkItem ((v) => Tester.Test ());
Assert.IsTrue (Tester.mre.WaitOne (TimeSpan.FromSeconds (10)), "Successful wait");
// The UI thread check only happens for debug builds, on release build it's linked away.
#if DEBUG
var expected_ex_thrown = true;
#else
var expected_ex_thrown = false;
#endif
Assert.AreEqual (expected_ex_thrown, Tester.exception_thrown, "Success");
}
class Tester : NSObject {
public static ManualResetEvent mre = new ManualResetEvent (false);
public static bool exception_thrown;
[CompilerGenerated]
[Export ("foo")]
public static void Test ()
{
try {
exception_thrown = false;
NSApplication.EnsureUIThread ();
} catch (AppKitThreadAccessException) {
exception_thrown = true;
} finally {
mre.Set ();
}
}
}
}
}

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

@ -32,7 +32,7 @@
<XamMacArch></XamMacArch>
<AOTMode>None</AOTMode>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<MonoBundlingExtraArgs>--optimize=all</MonoBundlingExtraArgs>
<MonoBundlingExtraArgs>--optimize=all,-remove-uithread-checks</MonoBundlingExtraArgs>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType></DebugType>

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

@ -11,8 +11,6 @@ export XamarinMacFrameworkRoot=$(MAC_DESTDIR)/Library/Frameworks/Xamarin.Mac.fra
TESTS_4_0 = \
link-uithread-1 \
link-uithread-2 \
link-safe-1 \
embedded-mono \
system-mono \

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

@ -1,20 +0,0 @@
<?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>CFBundleIdentifier</key>
<string>com.yourcompany.link-uithread-1</string>
<key>CFBundleName</key>
<string>link-uithread-1</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>10.9</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>LSUIElement</key>
<string>1</string>
</dict>
</plist>

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

@ -1,72 +0,0 @@
// Copyright 2013 Xamarin Inc. All rights reserved.
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading;
using MonoMac.Foundation;
using MonoMac.AppKit;
using MonoMac.ObjCRuntime;
// Test
// * By default a DEBUG build will have a it thread checks enabled
// * link-uithread-1 defines DEBUG (and has debug symbols)
// * link-uithread-2 does not defined DEBUG (and no debug symbol)
// * so same source, two test cases
//
// Requirement
// * Link SDK or Link All must be enabled
namespace Xamarin.Mac.Linker.Test {
class Tester : NSObject {
public static ManualResetEvent mre;
public static bool success;
[CompilerGenerated]
[Export ("foo")]
public static void Test ()
{
try {
NSApplication.EnsureUIThread ();
#if !DEBUG
success = true;
#endif
}
catch (AppKitThreadAccessException) {
#if DEBUG
success = true;
#endif
}
catch {
}
finally {
mre.Set ();
}
}
}
class UiThread {
static void Main (string[] args)
{
NSApplication.Init ();
Test.EnsureLinker (true);
// works on main/ui thread
NSApplication.EnsureUIThread ();
Tester.mre = new ManualResetEvent (false);
ThreadPool.QueueUserWorkItem ((v) => Tester.Test ());
Tester.mre.WaitOne ();
Test.Log.WriteLine ("{0}\tEnsureUIThread {1} on non-ui thread: {2}", Tester.success ? "[PASS]" : "[FAIL]",
#if DEBUG
"enabled",
#else
"disabled",
#endif
Tester.success);
Test.Terminate ();
}
}
}

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

@ -1,98 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{1F4422A4-C6B2-49B5-BB1D-6CA4676397CA}</ProjectGuid>
<ProjectTypeGuids>{42C0BBD9-55CE-4FC1-8D90-A7348ABAFB23};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Exe</OutputType>
<RootNamespace>linkuithread1</RootNamespace>
<MonoMacResourcePrefix>Resources</MonoMacResourcePrefix>
<AssemblyName>link-uithread-1</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>True</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>False</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseSGen>False</UseSGen>
<IncludeMonoRuntime>true</IncludeMonoRuntime>
<EnablePackageSigning>False</EnablePackageSigning>
<CreatePackage>False</CreatePackage>
<CodeSigningKey>Mac Developer</CodeSigningKey>
<EnableCodeSigning>False</EnableCodeSigning>
<ConsolePause>False</ConsolePause>
<PlatformTarget>x86</PlatformTarget>
<PackageSigningKey>Developer ID Installer</PackageSigningKey>
<I18n>
</I18n>
<LinkMode>Full</LinkMode>
<UseRefCounting>false</UseRefCounting>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>none</DebugType>
<Optimize>True</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LinkMode>Full</LinkMode>
<UseSGen>False</UseSGen>
<IncludeMonoRuntime>True</IncludeMonoRuntime>
<EnablePackageSigning>False</EnablePackageSigning>
<CreatePackage>True</CreatePackage>
<CodeSigningKey>Developer ID Application</CodeSigningKey>
<EnableCodeSigning>True</EnableCodeSigning>
<ConsolePause>False</ConsolePause>
<PlatformTarget>x86</PlatformTarget>
<UseRefCounting>false</UseRefCounting>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'AppStore|x86' ">
<DebugType>none</DebugType>
<Optimize>True</Optimize>
<OutputPath>bin\x86\AppStore</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LinkMode>Full</LinkMode>
<UseSGen>False</UseSGen>
<IncludeMonoRuntime>True</IncludeMonoRuntime>
<PackageSigningKey>3rd Party Mac Developer Installer</PackageSigningKey>
<ConsolePause>False</ConsolePause>
<EnableCodeSigning>True</EnableCodeSigning>
<CodeSigningKey>3rd Party Mac Developer Application</CodeSigningKey>
<CreatePackage>True</CreatePackage>
<EnablePackageSigning>True</EnablePackageSigning>
<PlatformTarget>x86</PlatformTarget>
<UseRefCounting>false</UseRefCounting>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="XamMac">
<HintPath>..\..\..\..\src\build\compat\XamMac.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\" />
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Mono\MonoMac\v0.0\Mono.MonoMac.targets" />
<ItemGroup>
<InterfaceDefinition Include="..\common\MainMenu.xib">
<Link>MainMenu.xib</Link>
</InterfaceDefinition>
</ItemGroup>
<ItemGroup>
<Compile Include="..\common\Test.cs">
<Link>Test.cs</Link>
</Compile>
<Compile Include="LinkUiThread.cs" />
</ItemGroup>
</Project>

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

@ -1,20 +0,0 @@
<?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>CFBundleIdentifier</key>
<string>com.yourcompany.link-uithread-2</string>
<key>CFBundleName</key>
<string>link-uithread-2</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>10.9</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>LSUIElement</key>
<string>1</string>
</dict>
</plist>

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

@ -1,101 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{26909B1A-21F0-484A-9DD0-EE5F612FB91B}</ProjectGuid>
<ProjectTypeGuids>{42C0BBD9-55CE-4FC1-8D90-A7348ABAFB23};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Exe</OutputType>
<RootNamespace>linkuithread2</RootNamespace>
<MonoMacResourcePrefix>Resources</MonoMacResourcePrefix>
<AssemblyName>link-uithread-2</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugType>none</DebugType>
<Optimize>True</Optimize>
<OutputPath>bin\Debug</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseSGen>False</UseSGen>
<IncludeMonoRuntime>true</IncludeMonoRuntime>
<EnablePackageSigning>False</EnablePackageSigning>
<CreatePackage>False</CreatePackage>
<CodeSigningKey>Mac Developer</CodeSigningKey>
<EnableCodeSigning>False</EnableCodeSigning>
<ConsolePause>False</ConsolePause>
<PlatformTarget>x86</PlatformTarget>
<PackageSigningKey>Developer ID Installer</PackageSigningKey>
<I18n>
</I18n>
<LinkMode>Full</LinkMode>
<UseRefCounting>false</UseRefCounting>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>none</DebugType>
<Optimize>True</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LinkMode>Full</LinkMode>
<UseSGen>False</UseSGen>
<IncludeMonoRuntime>True</IncludeMonoRuntime>
<EnablePackageSigning>False</EnablePackageSigning>
<CreatePackage>True</CreatePackage>
<CodeSigningKey>Developer ID Application</CodeSigningKey>
<EnableCodeSigning>True</EnableCodeSigning>
<ConsolePause>False</ConsolePause>
<PlatformTarget>x86</PlatformTarget>
<PackageSigningKey>Developer ID Installer</PackageSigningKey>
<I18n>
</I18n>
<UseRefCounting>false</UseRefCounting>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'AppStore|x86' ">
<DebugType>none</DebugType>
<Optimize>True</Optimize>
<OutputPath>bin\x86\AppStore</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LinkMode>Full</LinkMode>
<UseSGen>False</UseSGen>
<IncludeMonoRuntime>True</IncludeMonoRuntime>
<PackageSigningKey>3rd Party Mac Developer Installer</PackageSigningKey>
<ConsolePause>False</ConsolePause>
<EnableCodeSigning>True</EnableCodeSigning>
<CodeSigningKey>3rd Party Mac Developer Application</CodeSigningKey>
<CreatePackage>True</CreatePackage>
<EnablePackageSigning>True</EnablePackageSigning>
<PlatformTarget>x86</PlatformTarget>
<UseRefCounting>false</UseRefCounting>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="XamMac">
<HintPath>..\..\..\..\src\build\compat\XamMac.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\" />
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Mac\v0.0\Xamarin.Mac.targets" />
<ItemGroup>
<Compile Include="..\common\Test.cs">
<Link>Test.cs</Link>
</Compile>
<Compile Include="..\link-uithread-1\LinkUiThread.cs">
<Link>LinkUiThread.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="..\common\MainMenu.xib">
<Link>MainMenu.xib</Link>
</InterfaceDefinition>
</ItemGroup>
</Project>

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

@ -17,10 +17,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "link-keep-resources-2", "li
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "link-preserve-assembly", "link-preserve-assembly\link-preserve-assembly.csproj", "{39DD1BD5-1204-4D9E-A460-3A532DB3A797}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "link-uithread-1", "link-uithread-1\link-uithread-1.csproj", "{1F4422A4-C6B2-49B5-BB1D-6CA4676397CA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "link-uithread-2", "link-uithread-2\link-uithread-2.csproj", "{26909B1A-21F0-484A-9DD0-EE5F612FB91B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "link-xml-serialization", "link-xml-serialization\link-xml-serialization.csproj", "{6223332F-517A-43D0-9BCC-037645A24E97}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "link-remove-attributes-1", "link-remove-attributes-1\link-remove-attributes-1.csproj", "{F977D041-B0A5-49DE-815E-B210DBE140A5}"
@ -62,18 +58,6 @@ Global
{148DC17B-B29F-48A7-97CD-EECE26015B25}.Debug|x86.Build.0 = Debug|x86
{148DC17B-B29F-48A7-97CD-EECE26015B25}.Release|x86.ActiveCfg = Release|x86
{148DC17B-B29F-48A7-97CD-EECE26015B25}.Release|x86.Build.0 = Release|x86
{1F4422A4-C6B2-49B5-BB1D-6CA4676397CA}.AppStore|x86.ActiveCfg = AppStore|x86
{1F4422A4-C6B2-49B5-BB1D-6CA4676397CA}.AppStore|x86.Build.0 = AppStore|x86
{1F4422A4-C6B2-49B5-BB1D-6CA4676397CA}.Debug|x86.ActiveCfg = Debug|x86
{1F4422A4-C6B2-49B5-BB1D-6CA4676397CA}.Debug|x86.Build.0 = Debug|x86
{1F4422A4-C6B2-49B5-BB1D-6CA4676397CA}.Release|x86.ActiveCfg = Release|x86
{1F4422A4-C6B2-49B5-BB1D-6CA4676397CA}.Release|x86.Build.0 = Release|x86
{26909B1A-21F0-484A-9DD0-EE5F612FB91B}.AppStore|x86.ActiveCfg = AppStore|x86
{26909B1A-21F0-484A-9DD0-EE5F612FB91B}.AppStore|x86.Build.0 = AppStore|x86
{26909B1A-21F0-484A-9DD0-EE5F612FB91B}.Debug|x86.ActiveCfg = Debug|x86
{26909B1A-21F0-484A-9DD0-EE5F612FB91B}.Debug|x86.Build.0 = Debug|x86
{26909B1A-21F0-484A-9DD0-EE5F612FB91B}.Release|x86.ActiveCfg = Release|x86
{26909B1A-21F0-484A-9DD0-EE5F612FB91B}.Release|x86.Build.0 = Release|x86
{359E3AA4-A0E2-41A5-A5C5-03D322B71FE4}.AppStore|x86.ActiveCfg = AppStore|x86
{359E3AA4-A0E2-41A5-A5C5-03D322B71FE4}.AppStore|x86.Build.0 = AppStore|x86
{359E3AA4-A0E2-41A5-A5C5-03D322B71FE4}.Debug|x86.ActiveCfg = Debug|x86