[monotouch-test] Ignore a few tests in non-ARM64 simulators. (#13487)

* [monotouch-test] Ignore a few tests in non-ARM64 simulators.

Some tests fail when running on an M1, but in a x64_86 mode, so just ignore
those unless we're running on ARM64 (this will currently exclude them on
x86_64 hardware too, but that'll eventually not be a problem anymore when
there's no more x86_64 hardware, and just checking for ARM64 is easier than
checking for x86_64 mode on an ARM64 CPU).

* Make more legacy projects unsafe.
This commit is contained in:
Rolf Bjarne Kvinge 2021-12-07 21:10:39 +01:00 коммит произвёл GitHub
Родитель aff9d1902c
Коммит 39bdae2b7f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
13 изменённых файлов: 78 добавлений и 0 удалений

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

@ -154,6 +154,16 @@ partial class TestRuntime
#endif #endif
} }
public static void AssertIfSimulatorThenARM64 ()
{
#if !__MACOS__
if (ObjCRuntime.Runtime.Arch != Arch.SIMULATOR)
return;
if (!IsARM64)
NUnit.Framework.Assert.Ignore ("This test does not run simulators that aren't ARM64 simulators.");
#endif
}
public static void AssertNotSimulator () public static void AssertNotSimulator ()
{ {
#if !__MACOS__ #if !__MACOS__
@ -1248,6 +1258,37 @@ partial class TestRuntime
return !(Type.GetType ("System.__Canon") is null); return !(Type.GetType ("System.__Canon") is null);
} }
} }
enum NXByteOrder /* unspecified in header, means most likely int */ {
Unknown,
LittleEndian,
BigEndian,
}
[StructLayout (LayoutKind.Sequential)]
struct NXArchInfo {
IntPtr name; // const char *
public int CpuType; // cpu_type_t -> integer_t -> int
public int CpuSubType; // cpu_subtype_t -> integer_t -> int
public NXByteOrder ByteOrder;
IntPtr description; // const char *
public string Name {
get { return Marshal.PtrToStringUTF8 (name)!; }
}
public string Description {
get { return Marshal.PtrToStringUTF8 (description)!; }
}
}
[DllImport (Constants.libSystemLibrary)]
static unsafe extern NXArchInfo* NXGetLocalArchInfo ();
public unsafe static bool IsARM64 {
get { return NXGetLocalArchInfo ()->Name.StartsWith ("arm64"); }
}
} }
#if NET #if NET

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

@ -16,6 +16,7 @@
<DefineConstants></DefineConstants> <DefineConstants></DefineConstants>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle> <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>

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

@ -16,6 +16,7 @@
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle> <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<RootTestsDirectory>..\..</RootTestsDirectory> <RootTestsDirectory>..\..</RootTestsDirectory>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
<DebugSymbols>True</DebugSymbols> <DebugSymbols>True</DebugSymbols>

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

@ -13,8 +13,10 @@
<TargetFrameworkIdentifier>Xamarin.iOS</TargetFrameworkIdentifier> <TargetFrameworkIdentifier>Xamarin.iOS</TargetFrameworkIdentifier>
<IntermediateOutputPath>obj\$(Platform)\$(Configuration)-unified</IntermediateOutputPath> <IntermediateOutputPath>obj\$(Platform)\$(Configuration)-unified</IntermediateOutputPath>
<DefineConstants></DefineConstants> <DefineConstants></DefineConstants>
<LangVersion>latest</LangVersion>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle> <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<RootTestsDirectory>..\..\..</RootTestsDirectory> <RootTestsDirectory>..\..\..</RootTestsDirectory>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
<DebugSymbols>True</DebugSymbols> <DebugSymbols>True</DebugSymbols>

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

@ -16,6 +16,7 @@
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle> <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<RootTestsDirectory>..\..\..</RootTestsDirectory> <RootTestsDirectory>..\..\..</RootTestsDirectory>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
<DebugSymbols>True</DebugSymbols> <DebugSymbols>True</DebugSymbols>

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

@ -13,8 +13,10 @@
<TargetFrameworkIdentifier>Xamarin.iOS</TargetFrameworkIdentifier> <TargetFrameworkIdentifier>Xamarin.iOS</TargetFrameworkIdentifier>
<IntermediateOutputPath>obj\$(Platform)\$(Configuration)-unified</IntermediateOutputPath> <IntermediateOutputPath>obj\$(Platform)\$(Configuration)-unified</IntermediateOutputPath>
<DefineConstants></DefineConstants> <DefineConstants></DefineConstants>
<LangVersion>latest</LangVersion>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle> <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<RootTestsDirectory>..\..\..</RootTestsDirectory> <RootTestsDirectory>..\..\..</RootTestsDirectory>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
<DebugSymbols>True</DebugSymbols> <DebugSymbols>True</DebugSymbols>

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

@ -16,6 +16,7 @@
<DefineConstants></DefineConstants> <DefineConstants></DefineConstants>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle> <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>

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

@ -13,6 +13,7 @@
<MonoMacResourcePrefix>Resources</MonoMacResourcePrefix> <MonoMacResourcePrefix>Resources</MonoMacResourcePrefix>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle> <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>

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

@ -13,6 +13,7 @@
<MonoMacResourcePrefix>Resources</MonoMacResourcePrefix> <MonoMacResourcePrefix>Resources</MonoMacResourcePrefix>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle> <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>

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

@ -136,6 +136,9 @@ namespace MonoTouchFixtures.Foundation {
if (!TestRuntime.CheckXcodeVersion (5, 0)) if (!TestRuntime.CheckXcodeVersion (5, 0))
Assert.Inconclusive ("Requires iOS7 or later"); Assert.Inconclusive ("Requires iOS7 or later");
// The AppStoreReceiptUrl property may or may not return anything useful on the simulator, so run this only on device.
TestRuntime.AssertDevice ();
// on iOS8 device this now ends with "/StoreKit/sandboxReceipt" // on iOS8 device this now ends with "/StoreKit/sandboxReceipt"
// instead of "/StokeKit/receipt" // instead of "/StokeKit/receipt"
Assert.That (main.AppStoreReceiptUrl.AbsoluteString, Does.EndWith ("eceipt"), "AppStoreReceiptUrl"); Assert.That (main.AppStoreReceiptUrl.AbsoluteString, Does.EndWith ("eceipt"), "AppStoreReceiptUrl");

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

@ -120,24 +120,40 @@ namespace MonoTouchFixtures.MobileCoreServices {
[Test] [Test]
public void GetPreferredTag () public void GetPreferredTag ()
{ {
// This test may fail in the simulator, if the architecture of the simulator isn't the native one (say running x86_64 on an M1 machine),
// so just skip this test for the simulator.
TestRuntime.AssertIfSimulatorThenARM64 ();
Assert.NotNull (UTType.GetPreferredTag (UTType.PDF, UTType.TagClassFilenameExtension), "GetPreferredTag"); Assert.NotNull (UTType.GetPreferredTag (UTType.PDF, UTType.TagClassFilenameExtension), "GetPreferredTag");
} }
[Test] [Test]
public void GetDeclaration () public void GetDeclaration ()
{ {
// This test may fail in the simulator, if the architecture of the simulator isn't the native one (say running x86_64 on an M1 machine),
// so just skip this test for the simulator.
TestRuntime.AssertIfSimulatorThenARM64 ();
Assert.NotNull (UTType.GetDeclaration (UTType.PDF)); Assert.NotNull (UTType.GetDeclaration (UTType.PDF));
} }
[Test] [Test]
public void GetDeclaringBundleURL () public void GetDeclaringBundleURL ()
{ {
// This test may fail in the simulator, if the architecture of the simulator isn't the native one (say running x86_64 on an M1 machine),
// so just skip this test for the simulator.
TestRuntime.AssertIfSimulatorThenARM64 ();
Assert.NotNull (UTType.GetDeclaringBundleURL (UTType.PDF)); Assert.NotNull (UTType.GetDeclaringBundleURL (UTType.PDF));
} }
[Test] [Test]
public void CreatePreferredIdentifier () public void CreatePreferredIdentifier ()
{ {
// This test may fail in the simulator, if the architecture of the simulator isn't the native one (say running x86_64 on an M1 machine),
// so just skip this test for the simulator.
TestRuntime.AssertIfSimulatorThenARM64 ();
string[] extensions = new [] { ".html", ".css", ".jpg", ".js", ".otf" }; string[] extensions = new [] { ".html", ".css", ".jpg", ".js", ".otf" };
// random failure reported in #36708 (on some iPad2 only) // random failure reported in #36708 (on some iPad2 only)
for (int i=0; i < 100; i++) { for (int i=0; i < 100; i++) {

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

@ -99,6 +99,10 @@ namespace MonoTouchFixtures.UIKit {
[Test] [Test]
public void Save () public void Save ()
{ {
// This test may fail in the simulator, if the architecture of the simulator isn't the native one (say running x86_64 on an M1 machine),
// so just skip this test for the simulator.
TestRuntime.AssertIfSimulatorThenARM64 ();
using (NSUrl url = NSUrl.FromFilename (GetFileName ())) { using (NSUrl url = NSUrl.FromFilename (GetFileName ())) {
doc = new MyDocument (url); doc = new MyDocument (url);
doc.Save (url, UIDocumentSaveOperation.ForCreating, OperationHandler); doc.Save (url, UIDocumentSaveOperation.ForCreating, OperationHandler);

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

@ -19,6 +19,10 @@ namespace MonoTouchFixtures.UniformTypeIdentifiers {
[Test] [Test]
public void Archive () public void Archive ()
{ {
// This test may fail in the simulator, if the architecture of the simulator isn't the native one (say running x86_64 on an M1 machine),
// so just skip this test for the simulator.
TestRuntime.AssertIfSimulatorThenARM64 ();
var a = UTTypes.Archive; var a = UTTypes.Archive;
Assert.False (a.Dynamic, "Dynamic"); Assert.False (a.Dynamic, "Dynamic");
var z = UTTypes.Zip; var z = UTTypes.Zip;