[tests] Re-use tools/common/MachO.cs in mtouch/mmp tests.

This commit is contained in:
Rolf Bjarne Kvinge 2019-02-06 09:54:54 +01:00
Родитель db44b386ae
Коммит 2ae43112b8
7 изменённых файлов: 67 добавлений и 102 удалений

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

@ -35,7 +35,7 @@ using ObjCRuntime;
using Mono.Cecil.Cil;
#endif
#if MMP || MMP_TEST || MTOUCH
#if MMP || MMP_TEST || MTOUCH || MTOUCH_TESTS
namespace Xamarin.Bundler {
#else
namespace ObjCRuntime {

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

@ -1,77 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
namespace Xamarin.Tests
{
public static class MachO
{
public static List<string> GetArchitectures (string file)
{
var result = new List<string> ();
using (var fs = File.OpenRead (file)) {
using (var reader = new BinaryReader (fs)) {
int magic = reader.ReadInt32 ();
switch ((uint) magic) {
case 0xCAFEBABE: // little-endian fat binary
throw new NotImplementedException ("little endian fat binary");
case 0xBEBAFECA:
int architectures = System.Net.IPAddress.NetworkToHostOrder (reader.ReadInt32 ());
for (int i = 0; i < architectures; i++) {
result.Add (GetArch (System.Net.IPAddress.NetworkToHostOrder (reader.ReadInt32 ()), System.Net.IPAddress.NetworkToHostOrder (reader.ReadInt32 ())));
// skip to next entry
reader.ReadInt32 (); // offset
reader.ReadInt32 (); // size
reader.ReadInt32 (); // align
}
break;
case 0xFEEDFACE: // little-endian mach-o header
case 0xFEEDFACF: // little-endian 64-big mach-o header
result.Add (GetArch (reader.ReadInt32 (), reader.ReadInt32 ()));
break;
case 0xCFFAEDFE:
case 0xCEFAEDFE:
result.Add (GetArch (System.Net.IPAddress.NetworkToHostOrder (reader.ReadInt32 ()), System.Net.IPAddress.NetworkToHostOrder (reader.ReadInt32 ())));
break;
default:
throw new Exception (string.Format ("File '{0}' is neither a Universal binary nor a Mach-O binary (magic: 0x{1})", file, magic.ToString ("x")));
}
}
}
return result;
}
static string GetArch (int cputype, int cpusubtype)
{
const int ABI64 = 0x01000000;
const int X86 = 7;
const int ARM = 12;
switch (cputype) {
case ARM : // arm
switch (cpusubtype) {
case 6: return "armv6";
case 9: return "armv7";
case 11: return "armv7s";
default:
return "unknown arm variation: " + cpusubtype.ToString ();
}
case ARM | ABI64:
switch (cpusubtype) {
case 0:
return "arm64";
default:
return "unknown arm/64 variation: " + cpusubtype.ToString ();
}
case X86: // x86
return "i386";
case X86 | ABI64: // x64
return "x86_64";
}
return string.Format ("unknown: {0}/{1}", cputype, cpusubtype);
}
}
}

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

@ -97,9 +97,6 @@
<Link>BundlerTool.cs</Link>
</Compile>
<Compile Include="src\CodeStrippingTests.cs" />
<Compile Include="..\common\MachO.cs">
<Link>MachO.cs</Link>
</Compile>
<Compile Include="..\..\tools\common\StringUtils.cs">
<Link>StringUtils.cs</Link>
</Compile>

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

@ -29,14 +29,14 @@ namespace Xamarin.MMP.Tests
void AssertStrip (string libPath, bool shouldStrip)
{
var archsFound = Xamarin.Tests.MachO.GetArchitectures (libPath);
var archsFound = MachO.GetArchitectures (libPath);
if (shouldStrip) {
Assert.AreEqual (1, archsFound.Count, "Did not contain one archs");
Assert.True (archsFound.Contains ("x86_64"), "Did not contain x86_64");
Assert.True (archsFound.Contains (Abi.x86_64), "Did not contain x86_64");
} else {
Assert.AreEqual (2, archsFound.Count, "Did not contain two archs");
Assert.True (archsFound.Contains ("i386"), "Did not contain i386");
Assert.True (archsFound.Contains ("x86_64"), "Did not contain x86_64");
Assert.True (archsFound.Contains (Abi.i386), "Did not contain i386");
Assert.True (archsFound.Contains (Abi.x86_64), "Did not contain x86_64");
}
}

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

@ -2245,13 +2245,13 @@ public class B
mtouch.AssertExecute (MTouchAction.BuildDev);
var bin = mtouch.NativeExecutablePath;
VerifyArchitectures (bin, "arm7s/64", "armv7", "arm64");
VerifyArchitectures (bin, "arm7s/64", "ARMv7", "ARM64");
foreach (var dylib in Directory.GetFileSystemEntries (mtouch.AppPath, "*.dylib")) {
if (Path.GetFileName (dylib).StartsWith ("libmono", StringComparison.Ordinal))
continue;
if (Path.GetFileName (dylib).StartsWith ("libxamarin", StringComparison.Ordinal))
continue;
VerifyArchitectures (dylib, dylib + ": arm7s/64", "armv7", "arm64");
VerifyArchitectures (dylib, dylib + ": arm7s/64", "ARMv7", "ARM64");
}
}
}
@ -2298,14 +2298,14 @@ public class B
}
[Test]
[TestCase (Target.Dev, "armv7", "10.3")]
[TestCase (Target.Dev, "armv7s", "10.3")]
[TestCase (Target.Dev, "armv7,armv7s", "10.3")]
[TestCase (Target.Dev, "arm64", null)]
[TestCase (Target.Dev, "arm64+llvm", null)]
[TestCase (Target.Dev, "armv7,arm64", "10.3")]
[TestCase (Target.Dev, "armv7s,arm64", "10.3")]
[TestCase (Target.Dev, "armv7,armv7s,arm64", "10.3")]
[TestCase (Target.Dev, "ARMv7", "10.3")]
[TestCase (Target.Dev, "ARMv7s", "10.3")]
[TestCase (Target.Dev, "ARMv7,ARMv7s", "10.3")]
[TestCase (Target.Dev, "ARM64", null)]
[TestCase (Target.Dev, "ARM64+llvm", null)]
[TestCase (Target.Dev, "ARMv7,ARM64", "10.3")]
[TestCase (Target.Dev, "ARMv7s,ARM64", "10.3")]
[TestCase (Target.Dev, "ARMv7,ARMv7s,ARM64", "10.3")]
[TestCase (Target.Sim, "i386", "10.3")]
[TestCase (Target.Sim, "x86_64", null)]
public void Architectures_Unified (Target target, string abi, string deployment_target)
@ -2314,7 +2314,7 @@ public class B
mtouch.Profile = Profile.iOS;
mtouch.CreateTemporaryApp ();
mtouch.Abi = abi;
mtouch.Abi = abi.ToLower ();
mtouch.TargetVer = deployment_target;
var bin = Path.Combine (mtouch.AppPath, Path.GetFileNameWithoutExtension (mtouch.RootAssembly));
@ -2381,7 +2381,7 @@ public class B
var bin = Path.Combine (mtouch.AppPath, Path.GetFileNameWithoutExtension (mtouch.RootAssembly));
Assert.AreEqual (0, mtouch.Execute (target == Target.Dev ? MTouchAction.BuildDev : MTouchAction.BuildSim), "build");
VerifyArchitectures (bin, "arch", target == Target.Dev ? "arm64" : "x86_64");
VerifyArchitectures (bin, "arch", target == Target.Dev ? "ARM64" : "x86_64");
}
}
@ -2423,7 +2423,7 @@ public class B
var mono_framework = Path.Combine (app.AppPath, "Frameworks", "Mono.framework", "Mono");
Assert.That (mono_framework, Does.Exist, "mono framework existence");
// Verify that mtouch removed armv7s from the framework.
Assert.That (MachO.GetArchitectures (mono_framework), Is.EquivalentTo (new [] { "armv7", "arm64" }), "mono framework architectures");
Assert.That (MachO.GetArchitectures (mono_framework).Select ((v) => v.ToString ()), Is.EquivalentTo (new [] { "ARMv7", "ARM64" }), "mono framework architectures");
}
}
}
@ -4223,7 +4223,7 @@ public class TestApp {
static void VerifyArchitectures (string file, string message, params string[] expected)
{
var actual = MachO.GetArchitectures (file).ToArray ();
var actual = MachO.GetArchitectures (file).Select ((v) => v.ToString ()).ToArray ();
Array.Sort (expected);
Array.Sort (actual);

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

@ -0,0 +1,41 @@
// Copyright 2011-2012, Xamarin Inc. All rights reserved,
using System;
using System.Collections.Generic;
namespace MonoTouch {
public class RuntimeException : Exception {
public RuntimeException (string message, params object [] args)
: base (string.Format (message, args))
{
}
public RuntimeException (int code, string message, params object [] args) :
this (code, false, message, args)
{
}
public RuntimeException (int code, bool error, string message, params object [] args) :
this (code, error, null, message, args)
{
}
public RuntimeException (int code, bool error, Exception innerException, string message, params object [] args) :
base (String.Format (message, args), innerException)
{
Code = code;
Error = error;
}
public int Code { get; private set; }
public bool Error { get; private set; }
// http://blogs.msdn.com/b/msbuild/archive/2006/11/03/msbuild-visual-studio-aware-error-messages-and-message-formats.aspx
public override string ToString ()
{
return String.Format ("{0} MT{1:0000}: {2}",
Error ? "error" : "warning", Code, Message);
}
}
}

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

@ -69,9 +69,6 @@
<Compile Include="..\common\BundlerTool.cs">
<Link>BundlerTool.cs</Link>
</Compile>
<Compile Include="..\common\MachO.cs">
<Link>MachO.cs</Link>
</Compile>
<Compile Include="ToolTasksBinPathTest.cs" />
<Compile Include="..\..\msbuild\Xamarin.Mac.Tasks\Tasks\Metal.cs">
<Link>Metal.cs</Link>
@ -79,6 +76,13 @@
<Compile Include="..\..\msbuild\Xamarin.Mac.Tasks\Tasks\MetalLib.cs">
<Link>MetalLib.cs</Link>
</Compile>
<Compile Include="..\..\tools\common\MachO.cs">
<Link>MachO.cs</Link>
</Compile>
<Compile Include="..\..\src\ObjCRuntime\ErrorHelper.cs">
<Link>ErrorHelper.cs</Link>
</Compile>
<Compile Include="RuntimeException.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />