Skip to content

Commit

Permalink
X
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Baulig committed Oct 29, 2018
1 parent cfbcf6c commit 947524d
Show file tree
Hide file tree
Showing 19 changed files with 239 additions and 78 deletions.
1 change: 0 additions & 1 deletion tests/mono-native/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
mono-native-compat.csproj
extra-linker-defs-*.xml
34 changes: 34 additions & 0 deletions tests/mono-native/NativePlatformConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using NUnit.Framework;
using Mono;

namespace Mono.Native.Tests
{
[TestFixture]
public class NativePlatformConfig
{
static bool ShouldUseCompat {
get {
#if MONO_NATIVE_COMPAT
return true;
#elif MONO_NATIVE_UNIFIED
return false;
#else
Assert.Fail ("Missing `MONO_NATIVE_COMPAT` or `MONO_NATIVE_UNIFIED`");
throw new NotImplementedException ();
#endif
}
}
[Test]
public void PlatformType ()
{
var type = MonoNativePlatform.GetPlatformType ();
Assert.That ((int)type, Is.GreaterThan (0), "platform type");

Console.Error.WriteLine ($"NATIVE PLATFORM TYPE: {type}");

var usingCompat = (type & MonoNativePlatformType.MONO_NATIVE_PLATFORM_TYPE_COMPAT) != 0;
Assert.AreEqual (ShouldUseCompat, usingCompat, "using compatibility layer");
}
}
}
41 changes: 27 additions & 14 deletions tests/mono-native/NativePlatformTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,53 @@ namespace Mono.Native.Tests
public class NativePlatformTest
{
[Test]
public void Test ()
public void PlatformType ()
{
var type = MonoNativePlatform.GetPlatformType ();
Assert.That ((int)type, Is.GreaterThan (0), "platform type");

Console.Error.WriteLine ($"NATIVE PLATFORM TYPE: {type}");

// var usingCompat = (type & MonoNativePlatformType.MONO_NATIVE_PLATFORM_TYPE_COMPAT) != 0;
// Assert.AreEqual (MonoNativeConfig.UsingCompat, usingCompat, "using compatibility layer");
}

[Test]
public void TestInitialize ()
{
MonoNativePlatform.Initialize ();
var initialized = MonoNativePlatform.IsInitialized ();
Assert.IsTrue (initialized, "MonoNativePlatform.IsInitialized()");
}

[Test]
public void MartinTest ()
public void TestReflectionInitialize ()
{
MonoNativePlatform.Initialize ();

var asm = typeof (string).Assembly;
var type = asm.GetType ("Mono.MonoNativePlatform");
Console.Error.WriteLine ($"TEST: {type}");
Assert.IsNotNull (type, "MonoNativePlatform");

var method = type.GetMethod ("Initialize", BindingFlags.Static | BindingFlags.Public);
Assert.IsNotNull (method, "MonoNativePlatform.Initialize");

var method2 = type.GetMethod ("IsInitialized", BindingFlags.Static | BindingFlags.Public);
Assert.IsNotNull (method2, "MonoNativePlatform.IsInitialized");

method.Invoke (null, null);
Console.Error.WriteLine ($"CALLED INITIALIZE!");

var method2 = type.GetMethod ("Test", BindingFlags.Static | BindingFlags.Public);
method2.Invoke (null, null);
var result = (bool)method2.Invoke (null, null);
Assert.IsTrue (result, "MonoNativePlatform.IsInitialized()");
}

[Test]
public void TestInternalCounter ()
{
MonoNativePlatform.Initialize ();

var asm = typeof (string).Assembly;
var type = asm.GetType ("Mono.MonoNativePlatform");
Assert.IsNotNull (type, "MonoNativePlatform");

var method = type.GetMethod ("TestInternalCounter", BindingFlags.Static | BindingFlags.NonPublic);
Assert.IsNotNull (method, "MonoNativePlatform.TestInternalCounter");
var result = method.Invoke (null, null);

Console.Error.WriteLine ($"CALLED TEST!");
Assert.That (result, Is.GreaterThan (0), "MonoNativePlatform.TestInternalCounter()");
}
}
}
7 changes: 7 additions & 0 deletions tests/mono-native/extra-linker-defs-today.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<linker>
<assembly fullname="mscorlib">
<type fullname="Mono.MonoNativePlatform" preserve="all" />
<type fullname="Mono.MonoNativePlatformType" preserve="all" />
</assembly>
</linker>
7 changes: 7 additions & 0 deletions tests/mono-native/extra-linker-defs-tvos.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<linker>
<assembly fullname="mscorlib">
<type fullname="Mono.MonoNativePlatform" preserve="all" />
<type fullname="Mono.MonoNativePlatformType" preserve="all" />
</assembly>
</linker>
7 changes: 7 additions & 0 deletions tests/mono-native/extra-linker-defs-watchos.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<linker>
<assembly fullname="mscorlib">
<type fullname="Mono.MonoNativePlatform" preserve="all" />
<type fullname="Mono.MonoNativePlatformType" preserve="all" />
</assembly>
</linker>
5 changes: 4 additions & 1 deletion tests/mono-native/mono-native.csproj.template
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,16 @@
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AppDelegate.cs" />
<Compile Include="NativePlatformTest.cs" />
<Compile Include="NativePlatformConfig.cs" />
<Compile Include="..\..\external\mono\mcs\class\corlib\Mono\MonoNativePlatform.cs">
<Link>MonoNativePlatform.cs</Link>
</Compile>
<Compile Include="..\..\external\mono\mcs\class\corlib\Mono\MonoNativePlatformType.cs">
<Link>MonoNativePlatformType.cs</Link>
</Compile>
<Compile Include="..\..\external\mono\mcs\class\corlib\Test\Mono\NativePlatformTest.cs">
<Link>NativePlatformTest.cs</Link>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
</Project>
2 changes: 2 additions & 0 deletions tests/xharness/AppRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ public async Task<int> RunAsync ()
args.Append (" -setenv=NUNIT_AUTOEXIT=true");
args.Append (" -argument=-app-arg:-enablenetwork");
args.Append (" -setenv=NUNIT_ENABLE_NETWORK=true");
args.Append (" -setenv=MONO_LOG_LEVEL=debug");
args.Append (" -setenv=MONO_LOG_MASK=dll,asm");
// detect if we are using a jenkins bot.
var useXmlOutput = Harness.InJenkins;
if (useXmlOutput) {
Expand Down
3 changes: 3 additions & 0 deletions tests/xharness/Harness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,9 @@ void ConfigureIOS ()

foreach (var proj in IOSTestProjects) {
var file = proj.Path;
if (proj.MonoNativeInfo != null)
file = proj.MonoNativeInfo.TemplatePath;

if (!File.Exists (file))
throw new FileNotFoundException (file);

Expand Down
22 changes: 22 additions & 0 deletions tests/xharness/Jenkins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ IEnumerable<RunSimulatorTask> CreateRunSimulatorTaskAsync (XBuildTask buildTask)
targets = new AppRunnerTarget [] { AppRunnerTarget.Simulator_iOS32, AppRunnerTarget.Simulator_iOS64 };
platforms = new TestPlatform [] { TestPlatform.iOS_Unified32, TestPlatform.iOS_Unified64 };
break;
case TestPlatform.iOS_TodayExtension64:
targets = new AppRunnerTarget[] { AppRunnerTarget.Simulator_iOS64 };
platforms = new TestPlatform[] { TestPlatform.iOS_TodayExtension64 };
break;
default:
throw new NotImplementedException ();
}
Expand Down Expand Up @@ -204,6 +208,22 @@ IEnumerable<TestData> GetTestData (RunTestTask test)
yield return new TestData { Variation = "Release (all optimizations)", MTouchExtraArgs = "--registrar:static --optimize:all", Debug = false, Profiling = false, LinkMode = "Full", Defines = "OPTIMIZEALL" };
yield return new TestData { Variation = "Debug (all optimizations)", MTouchExtraArgs = "--registrar:static --optimize:all,-remove-uithread-checks", Debug = true, Profiling = false, LinkMode = "Full", Defines = "OPTIMIZEALL", Ignored = !IncludeAll };
break;
case "mono-native-compat":
case "mono-native-unified":
yield return new TestData { Variation = "AssemblyBuildTarget: dylib (debug)", MTouchExtraArgs = "--assembly-build-target=@all=dynamiclibrary", Debug = true, Profiling = false };
yield return new TestData { Variation = "AssemblyBuildTarget: SDK framework (debug)", MTouchExtraArgs = "--assembly-build-target=@sdk=framework=Xamarin.Sdk --assembly-build-target=@all=staticobject", Debug = true, Profiling = false };

yield return new TestData { Variation = "AssemblyBuildTarget: dylib (debug, profiling)", MTouchExtraArgs = "--assembly-build-target=@all=dynamiclibrary", Debug = true, Profiling = true };
yield return new TestData { Variation = "AssemblyBuildTarget: SDK framework (debug, profiling)", MTouchExtraArgs = "--assembly-build-target=@sdk=framework=Xamarin.Sdk --assembly-build-target=@all=staticobject", Debug = true, Profiling = true };

yield return new TestData { Variation = "AssemblyBuildTarget: SDK framework (release)", MTouchExtraArgs = "--assembly-build-target=@sdk=framework=Xamarin.Sdk --assembly-build-target=@all=staticobject", Debug = false, Profiling = false };

yield return new TestData { Variation = "Release", MTouchExtraArgs = "", Debug = false, Profiling = false };
yield return new TestData { Variation = "Release (all optimizations)", MTouchExtraArgs = "--registrar:static --optimize:all", Debug = false, Profiling = false, LinkMode = "Full", Defines = "OPTIMIZEALL" };

yield return new TestData { Variation = "Debug (static registrar)", MTouchExtraArgs = "--registrar:static", Debug = true, Profiling = false };
yield return new TestData { Variation = "Debug (all optimizations)", MTouchExtraArgs = "--registrar:static --optimize:all", Debug = true, Profiling = false, LinkMode = "Full", Defines = "OPTIMIZEALL" };
break;
}
break;
case "AnyCPU":
Expand Down Expand Up @@ -330,6 +350,8 @@ IEnumerable<TestTask> CreateRunSimulatorTasks ()
var ps = new List<Tuple<TestProject, TestPlatform, bool>> ();
if (!project.SkipiOSVariation)
ps.Add (new Tuple<TestProject, TestPlatform, bool> (project, TestPlatform.iOS_Unified, ignored || !IncludeiOS));
if (project.MonoNativeInfo != null)
ps.Add (new Tuple<TestProject, TestPlatform, bool> (project, TestPlatform.iOS_TodayExtension64, ignored || !IncludeiOS));
if (!project.SkiptvOSVariation)
ps.Add (new Tuple<TestProject, TestPlatform, bool> (project.AsTvOSProject (), TestPlatform.tvOS, ignored || !IncludetvOS));
if (!project.SkipwatchOSVariation)
Expand Down
55 changes: 22 additions & 33 deletions tests/xharness/MonoNativeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,53 +50,42 @@ public MonoNativeInfo (Harness harness, MonoNativeFlavor flavor)
public string ProjectPath => Path.Combine (Harness.RootDirectory, "mono-native", ProjectName + ".csproj");
public string TemplatePath => Path.Combine (Harness.RootDirectory, "mono-native", "mono-native.csproj.template");

public string GetMinimumOSVersion ()
public void Convert ()
{
if (Harness.Mac)
throw new NotImplementedException ();
switch (Flavor) {
case MonoNativeFlavor.Compat:
return "9.0";
case MonoNativeFlavor.Unified:
return "10.0";
default:
throw new Exception (string.Format ("Unknown MonoNativeFlavor: {0}", Flavor));
}
}
var inputProject = new XmlDocument ();

var xml = File.ReadAllText (TemplatePath);
inputProject.LoadXmlWithoutNetworkAccess (xml);
inputProject.SetOutputPath ("bin\\$(Platform)\\$(Configuration)" + FlavorSuffix);
inputProject.SetIntermediateOutputPath ("obj\\$(Platform)\\$(Configuration)" + FlavorSuffix);
inputProject.SetAssemblyName (inputProject.GetAssemblyName () + FlavorSuffix);

public string GetMinimumWatchOSVersion ()
{
switch (Flavor) {
case MonoNativeFlavor.Compat:
return "2.0";
inputProject.AddAdditionalDefines ("MONO_NATIVE_COMPAT");
break;
case MonoNativeFlavor.Unified:
return "4.0";
inputProject.AddAdditionalDefines ("MONO_NATIVE_UNIFIED");
break;
default:
throw new Exception (string.Format ("Unknown MonoNativeFlavor: {0}", Flavor));
throw new Exception ($"Unknown MonoNativeFlavor: {Flavor}");
}

// Harness.Save (inputProject, ProjectPath);
}

public void Convert ()
public void AddProjectDefines (XmlDocument project)
{
var inputProject = new XmlDocument ();

var xml = File.ReadAllText (TemplatePath);
inputProject.LoadXmlWithoutNetworkAccess (xml);

switch (Flavor) {
case MonoNativeFlavor.Compat:
// inputProject.SetTargetFrameworkIdentifier ("Xamarin.Mac");
// inputProject.SetTargetFrameworkVersion ("v2.0");
// inputProject.RemoveNode ("UseXamMacFullFramework");
// inputProject.AddAdditionalDefines ("MOBILE;XAMMAC");
// inputProject.AddReference ("Mono.Security");
project.AddAdditionalDefines ("MONO_NATIVE_COMPAT");
break;
case MonoNativeFlavor.Unified:
project.AddAdditionalDefines ("MONO_NATIVE_UNIFIED");
break;
default:
throw new Exception ($"Unknown MonoNativeFlavor: {Flavor}");
}
inputProject.SetOutputPath ("bin\\$(Platform)\\$(Configuration)" + FlavorSuffix);
inputProject.SetIntermediateOutputPath ("obj\\$(Platform)\\$(Configuration)" + FlavorSuffix);
inputProject.SetAssemblyName (inputProject.GetAssemblyName () + FlavorSuffix);

Harness.Save (inputProject, ProjectPath);
}
}
}
26 changes: 22 additions & 4 deletions tests/xharness/TVOSTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ public override string Suffix {
}
}

public override string ExtraLinkerDefsSuffix {
get {
return "-tvos";
}
}

protected override string BindingsProjectTypeGuids {
get {
return "{4A1ED743-3331-459B-915A-4B17C7B6DBB6}";
Expand Down Expand Up @@ -62,11 +68,18 @@ protected override void CalculateName ()
Name = Name + MonoNativeInfo.FlavorSuffix;
}

protected override string GetMinimumOSVersion(string templateMinimumOSVersion)
protected override string GetMinimumOSVersion (string templateMinimumOSVersion)
{
if (MonoNativeInfo != null)
return MonoNativeInfo.GetMinimumOSVersion ();
return "9.0";
if (MonoNativeInfo == null)
return "9.0";
switch (MonoNativeInfo.Flavor) {
case MonoNativeFlavor.Compat:
return "9.0";
case MonoNativeFlavor.Unified:
return "10.0";
default:
throw new Exception ($"Unknown MonoNativeFlavor: {MonoNativeInfo.Flavor}");
}
}

protected override int[] UIDeviceFamily {
Expand Down Expand Up @@ -99,6 +112,11 @@ protected override void ProcessProject ()
{
base.ProcessProject ();

if (MonoNativeInfo != null) {
MonoNativeInfo.AddProjectDefines (inputProject);
inputProject.AddAdditionalDefines ("MONO_NATIVE_TV");
}

var srcDirectory = Path.Combine (Harness.RootDirectory, "..", "src");

string project_guid;
Expand Down
3 changes: 2 additions & 1 deletion tests/xharness/Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public abstract class Target
public virtual string Suffix { get { throw new NotImplementedException (); } }
public virtual string MakefileWhereSuffix { get { return string.Empty; } }
public virtual string ProjectFileSuffix { get { return Suffix; } }
public virtual string ExtraLinkerDefsSuffix { get { return Suffix; } }
protected virtual string ProjectTypeGuids { get { throw new NotImplementedException (); } }
protected virtual string BindingsProjectTypeGuids { get { throw new NotImplementedException (); } }
protected virtual string TargetFrameworkIdentifier { get { throw new NotImplementedException (); } }
Expand Down Expand Up @@ -113,7 +114,7 @@ protected void CreateExecutableProject ()
} else {
inputProject.FixArchitectures (SimulatorArchitectures, DeviceArchitectures);
inputProject.FixInfoPListInclude (Suffix);
inputProject.SetExtraLinkerDefs ("extra-linker-defs" + Suffix + ".xml");
inputProject.SetExtraLinkerDefs ("extra-linker-defs" + ExtraLinkerDefsSuffix + ".xml");
}
Harness.Save (inputProject, ProjectPath);

Expand Down
Loading

0 comments on commit 947524d

Please sign in to comment.