public void ExplictStripOption_ThirdPartyLibrary_AndWarnsIfSo(bool?strip, bool shouldStrip) { MMPTests.RunMMPTest(tmpDir => { string originalLocation = Path.Combine(Configuration.SourceRoot, "tests", "test-libraries", "libtest-fat.macos.dylib"); string newLibraryLocation = Path.Combine(tmpDir, "libTest.dylib"); File.Copy(originalLocation, newLibraryLocation); TI.UnifiedTestConfig test = CreateStripTestConfig(strip, tmpDir, $" --native-reference=\"{newLibraryLocation}\""); test.Release = true; var testResult = TI.TestUnifiedExecutable(test); var bundleDylib = Path.Combine(test.BundlePath, "Contents", "MonoBundle", "libTest.dylib"); Assert.That(bundleDylib, Does.Exist, "libTest.dylib presence in app bundle"); var architectures = MachO.GetArchitectures(bundleDylib); if (shouldStrip) { Assert.AreEqual(1, architectures.Count, "libTest.dylib should only contain 1 architecture"); Assert.AreEqual(Abi.x86_64, architectures [0], "libTest.dylib should be x86_64"); testResult.Messages.AssertWarning(2108, "libTest.dylib was stripped of architectures except x86_64 to comply with App Store restrictions. This could break existing codesigning signatures. Consider stripping the library with lipo or disabling with --optimize=-trim-architectures"); } else { Assert.AreEqual(2, architectures.Count, "libTest.dylib should contain 2+ architectures"); Assert.That(architectures, Is.EquivalentTo(new Abi [] { Abi.i386, Abi.x86_64 }), "libTest.dylib should be x86_64 + i386"); testResult.Messages.AssertWarningCount(1); // dylib ([...]/xamarin-macios/tests/mmptest/bin/Debug/tmp-test-dir/Xamarin.MMP.Tests.MMPTests.RunMMPTest47/bin/Release/UnifiedExample.app/Contents/MonoBundle/libTest.dylib) was built for newer macOS version (10.11) than being linked (10.9) } }); }
public void Unified_WithNativeReferences_InMainProjectWorks() { MMPTests.RunMMPTest(tmpDir => { // Could be any dylib not in /System const string SystemLibPath = "/Library/Frameworks/Mono.framework/Versions/Current/lib/libsqlite3.0.dylib"; TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir) { ItemGroup = CreateSingleNativeRef(SystemLibPath, "Dynamic") }; NativeReferenceTestCore(tmpDir, test, "Unified_WithNativeReferences_InMainProjectWorks - System", "libsqlite3.0.dylib", true); test.ItemGroup = CreateSingleNativeRef(Path.GetFullPath(SimpleDylibPath), "Dynamic"); NativeReferenceTestCore(tmpDir, test, "Unified_WithNativeReferences_InMainProjectWorks - Local", "SimpleClassDylib.dylib", true); test.ItemGroup = CreateSingleNativeRef(Path.GetFullPath(SimpleStaticPath), "Static"); NativeReferenceTestCore(tmpDir, test, "Unified_WithNativeReferences_InMainProjectWorks - Static", null, true); test.ItemGroup = CreateSingleNativeRef("/Library/Frameworks/iTunesLibrary.framework", "Framework"); NativeReferenceTestCore(tmpDir, test, "Unified_WithNativeReferences_InMainProjectWorks - Framework", null, true); Assert.True(Directory.Exists(Path.Combine(tmpDir, "bin/Debug/UnifiedExample.app/Contents/Frameworks/iTunesLibrary.framework"))); string binaryPath = Path.Combine(tmpDir, "bin/Debug/UnifiedExample.app/Contents/MacOS/UnifiedExample"); string otoolText = TI.RunAndAssert("/usr/bin/otool", new StringBuilder("-l " + binaryPath), "Unified_WithNativeReferences_InMainProjectWorks - rpath"); Assert.True(otoolText.Contains("path @loader_path/../Frameworks")); }); }
public void DynamicSymbolMode(string mode) { MMPTests.RunMMPTest(tmpDir => { TI.UnifiedTestConfig config = new TI.UnifiedTestConfig(tmpDir) { CSProjConfig = $"<MonoBundlingExtraArgs>--dynamic-symbol-mode={mode}</MonoBundlingExtraArgs>\n", }; var output = TI.TestUnifiedExecutable(config); var build_output = output.BuildResult.BuildOutput; switch (mode) { case "linker": case "default": Assert.That(build_output, Does.Contain("-u "), "reference.m"); Assert.That(build_output, Does.Not.Contain("reference.m"), "reference.m"); break; case "code": Assert.That(build_output, Does.Not.Contain("-u "), "reference.m"); Assert.That(build_output, Does.Contain("reference.m"), "reference.m"); break; case "ignore": Assert.That(build_output, Does.Not.Contain("-u "), "reference.m"); Assert.That(build_output, Does.Not.Contain("reference.m"), "reference.m"); break; default: throw new NotImplementedException(); } }); }
public void AllowsUnresolvableReferences() { MMPTests.RunMMPTest(tmpDir => { string [] sb; // build b.dll sb = new [] { "-target:library", $"-out:{tmpDir}/b.dll", $"{tmpDir}/b.cs" }; File.WriteAllText(Path.Combine(tmpDir, "b.cs"), "public class B { }"); TI.RunAndAssert("/Library/Frameworks/Mono.framework/Commands/csc", sb, "b"); // build a.dll sb = new [] { "-target:library", $"-out:{tmpDir}/a.dll", $"{tmpDir}/a.cs", $"-r:{tmpDir}/b.dll" }; File.WriteAllText(Path.Combine(tmpDir, "a.cs"), "public class A { public A () { System.Console.WriteLine (typeof (B)); }}"); TI.RunAndAssert("/Library/Frameworks/Mono.framework/Commands/csc", sb, "a"); File.Delete(Path.Combine(tmpDir, "b.dll")); // build project referencing a.dll TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir) { References = string.Format(" <Reference Include=\"a\" > <HintPath>{0}/a.dll</HintPath> </Reference> ", tmpDir), TestCode = "System.Console.WriteLine (typeof (A));", }; TI.GenerateAndBuildUnifiedExecutable(test); }); }
public void MM0138() { MMPTests.RunMMPTest(tmpDir => { var rv = TI.TestClassicExecutable(tmpDir, csprojConfig: "<IncludeMonoRuntime>true</IncludeMonoRuntime>", shouldFail: true); rv.Messages.AssertError(138, "Building 32-bit apps is not possible when using Xcode 10. Please migrate project to the Unified API."); rv.Messages.AssertWarningCount(0); }); }
public void ShouldStripMonoPosixHelper(bool?strip, bool debugStrips, bool releaseStrips) { MMPTests.RunMMPTest(tmpDir => { TI.UnifiedTestConfig test = CreateStripTestConfig(strip, tmpDir); StripTestCore(test, debugStrips, releaseStrips, "Contents/MonoBundle/libMonoPosixHelper.dylib", shouldWarn: false); }); }
public void MultipleDependencyChain(bool useProjectReference) { // App can depend on Lib that depends on binding lib with native reference and everything gets packaged in correctly MMPTests.RunMMPTest(tmpDir => { TI.UnifiedTestConfig binding = new TI.UnifiedTestConfig(tmpDir) { ProjectName = "MobileBinding.csproj" }; binding.ItemGroup += NativeReferenceTests.CreateSingleNativeRef(NativeReferenceTests.SimpleDylibPath, "Dynamic"); binding.APIDefinitionConfig += @"[BaseType (typeof (NSObject))] interface SimpleClass { [Export (""doIt"")] int DoIt (); }"; BindingProjectTests.SetNoEmbedding(binding); TI.GenerateBindingLibraryProject(binding); TI.BuildProject(Path.Combine(tmpDir, "MobileBinding.csproj"), true); TI.UnifiedTestConfig library = new TI.UnifiedTestConfig(tmpDir) { ProjectName = "UnifiedLibrary" }; library.TestCode = "public class MyClass { public static void Go () { var c = new ExampleBinding.SimpleClass (); c.DoIt (); } }"; if (useProjectReference) { library.References = $@"<ProjectReference Include=""MobileBinding.csproj"" />"; } else { library.References = $@"<Reference Include=""MobileBinding""><HintPath>{Path.Combine (tmpDir, "bin/Debug", "MobileBinding.dll")}</HintPath></Reference>"; } TI.GenerateUnifiedLibraryProject(library); TI.BuildProject(Path.Combine(tmpDir, "UnifiedLibrary.csproj"), true); TI.UnifiedTestConfig project = new TI.UnifiedTestConfig(tmpDir) { ProjectName = "UnifiedExample.csproj" }; project.TestCode = "MyClass.Go ();"; if (useProjectReference) { project.References = $@"<ProjectReference Include=""UnifiedLibrary.csproj"" />"; } else { project.References = $@"<Reference Include=""UnifiedLibrary""><HintPath>{Path.Combine (tmpDir, "bin/Debug", "UnifiedLibrary.dll")}</HintPath></Reference>"; } TI.GenerateUnifiedExecutableProject(project); TI.BuildProject(Path.Combine(tmpDir, "UnifiedExample.csproj"), true); }); }
public void ShouldStripMonoPosixHelper(bool?strip, bool debugStrips, bool releaseStrips) { MMPTests.RunMMPTest(tmpDir => { TI.UnifiedTestConfig test = CreateStripTestConfig(strip, tmpDir); // Mono's linker is smart enough to remove libMonoPosixHelper unless used (DeflateStream uses it) test.TestCode = "using (var ms = new System.IO.MemoryStream ()) { using (var gz = new System.IO.Compression.DeflateStream (ms, System.IO.Compression.CompressionMode.Compress)) { }}"; StripTestCore(test, debugStrips, releaseStrips, "Contents/MonoBundle/libMonoPosixHelper.dylib", shouldWarn: false); }); }
public void ShouldStripUserFramework(bool?strip, bool debugStrips, bool releaseStrips) { MMPTests.RunMMPTest(tmpDir => { var frameworkPath = FrameworkBuilder.CreateFatFramework(tmpDir); TI.UnifiedTestConfig test = CreateStripTestConfig(strip, tmpDir, $"--native-reference={frameworkPath}"); StripTestCore(test, debugStrips, releaseStrips, "Contents/Frameworks/Foo.framework/Foo", shouldWarn: true); }); }
public void Unified_SmokeTest(bool full) { MMPTests.RunMMPTest(tmpDir => { TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir) { XM45 = full }; TI.TestUnifiedExecutable(test); }); }
public void Modern_SmokeTest_LinkAll() { MMPTests.RunMMPTest(tmpDir => { TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir) { CSProjConfig = "<LinkMode>Full</LinkMode>" }; TI.TestUnifiedExecutable(test); }); }
public void ShouldNotMutateModernWithOptInFlag() { MMPTests.RunMMPTest(tmpDir => { TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir) { CSProjConfig = MigrateCSProjTag }; var buildOutput = TI.TestUnifiedExecutable(test).BuildResult; Assert.True(MatchesTFI("Xamarin.Mac", buildOutput), $"Build did not have expected TFI."); }); }
public void Classic_SmokeTest() { if (ShouldSkipClassicTest) { return; } MMPTests.RunMMPTest(tmpDir => { TI.TestClassicExecutable(tmpDir); }); }
public void LinkingAdditionalArguments_ShouldBeUsed() { MMPTests.RunMMPTest(tmpDir => { TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir) { CSProjConfig = "<MonoBundlingExtraArgs>-v -v --linkplatform</MonoBundlingExtraArgs>" }; var testResult = TI.TestUnifiedExecutable(test); Assert.IsTrue(testResult.BuildResult.BuildOutput.Contains("Selected Linking: 'Platform'"), $"Build Output did not contain expected selected linking line: {testResult}"); }); }
public void LinkingWithPartialStatic_ShouldFail() { MMPTests.RunMMPTest(tmpDir => { TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir) { CSProjConfig = "<MonoBundlingExtraArgs>--registrar:partial --linkplatform</MonoBundlingExtraArgs>" }; var testResult = TI.TestUnifiedExecutable(test, shouldFail: true); testResult.BuildResult.Messages.AssertError(2110, "Xamarin.Mac 'Partial Static' registrar does not support linking. Disable linking or use another registrar mode."); }); }
public void MM0143() { MMPTests.RunMMPTest(tmpDir => { string csprojTarget = Path.Combine(TI.FindSourceDirectory(), "ClassicExample.csproj"); string buildOutput = TI.BuildClassicProject(csprojTarget); Console.WriteLine(buildOutput); var rv = new OutputText(buildOutput, string.Empty); rv.Messages.AssertError(143, "Projects using the Classic API are not supported anymore. Please migrate the project to the Unified API."); rv.Messages.AssertWarningCount(0); }); }
public void AOT_SmokeTest(bool useProjectTags) { MMPTests.RunMMPTest(tmpDir => { TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir) { CSProjConfig = GetTestConfig(TestType.Base, useProjectTags) }; TI.TestUnifiedExecutable(test); ValidateAOTStatus(tmpDir, f => ShouldBaseFilesBeAOT(f)); }); }
public void LinkingWithPartialStatic_ShouldFail() { MMPTests.RunMMPTest(tmpDir => { TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir) { CSProjConfig = "<MonoBundlingExtraArgs>--registrar:partial --linkplatform</MonoBundlingExtraArgs>" }; string buildOutput = TI.TestUnifiedExecutable(test, shouldFail: true).BuildOutput; Assert.True(buildOutput.Contains("2110"), $"Building did not give the expected 2110 error.\n\n{buildOutput}"); }); }
public void ShouldAllowReference_ToOpenTK(bool full) { MMPTests.RunMMPTest(tmpDir => { TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir) { References = " <Reference Include=\"OpenTK\" />", TestCode = "var matrix = new OpenTK.Matrix2 ();", XM45 = full }; TI.TestUnifiedExecutable(test); }); }
public void ShouldBuildWithoutErrors_AndLinkCorrectFramework(BindingProjectType type, bool noEmbedding = false) { MMPTests.RunMMPTest(tmpDir => { var projects = GenerateTestProject(type, tmpDir); if (noEmbedding) { SetNoEmbedding(projects.Item1); } var logs = SetupAndBuildLinkedTestProjects(projects.Item1, projects.Item2, tmpDir, useProjectReference: false, setupDefaultNativeReference: noEmbedding); Assert.True(logs.Item1.Contains("csc"), "Bindings project must use csc:\n" + logs.Item1); var bgenInvocation = logs.Item1.SplitLines().First(x => x.Contains("bin/bgen")); var bgenParts = bgenInvocation.Split(new char[] { ' ' }); var mscorlib = bgenParts.First(x => x.Contains("mscorlib.dll")); var system = bgenParts.First(x => x.Contains("System.dll")); switch (type) { case BindingProjectType.Modern: case BindingProjectType.ModernNoTag: Assert.True(mscorlib.EndsWith("lib/mono/Xamarin.Mac/mscorlib.dll", StringComparison.Ordinal), "mscorlib not found in expected Modern location: " + mscorlib); Assert.True(system.EndsWith("lib/mono/Xamarin.Mac/System.dll", StringComparison.Ordinal), "system not found in expected Modern location: " + system); break; case BindingProjectType.Full: case BindingProjectType.FullTVF: case BindingProjectType.FullXamMacTag: Assert.True(mscorlib.EndsWith("lib/mono/4.5/mscorlib.dll", StringComparison.Ordinal), "mscorlib not found in expected Full location: " + mscorlib); Assert.True(system.EndsWith("lib/mono/4.5/System.dll", StringComparison.Ordinal), "system not found in expected Full location: " + system); break; default: throw new NotImplementedException(); } Assert.False(logs.Item1.Contains("CS1685"), "Binding should not contains CS1685 multiple definition warning:\n" + logs.Item1); Assert.False(logs.Item1.Contains("MSB9004"), "Binding should not contains MSB9004 warning:\n" + logs.Item1); string bindingName = RemoveCSProj(projects.Item1.ProjectName); string appName = RemoveCSProj(projects.Item2.ProjectName); string libPath = Path.Combine(tmpDir, $"bin/Debug/{appName}.app/Contents/MonoBundle/{bindingName}.dll"); Assert.True(File.Exists(libPath)); string results = TI.RunAndAssert("/Library/Frameworks/Mono.framework/Commands/monop", new [] { "--refs", "-r:" + libPath }, "monop"); string mscorlibLine = results.Split(new char[] { '\n' }).First(x => x.Contains("mscorlib")); string expectedVersion = GetExpectedBCLVersion(type); Assert.True(mscorlibLine.Contains(expectedVersion), $"{mscorlibLine} did not contain expected version {expectedVersion}"); }); }
public void UnifiedWithoutLinking_ShouldHaveManyFrameworkClangLines() { MMPTests.RunMMPTest(tmpDir => { // By default we -framework in all frameworks we bind. string [] clangParts = MMPTests.GetUnifiedProjectClangInvocation(tmpDir); AssertUnlinkedFrameworkStatus(clangParts); // Even with static registrar clangParts = MMPTests.GetUnifiedProjectClangInvocation(tmpDir, StaticRegistrarConfig); AssertUnlinkedFrameworkStatus(clangParts); }); }
public void Unified_WithNativeReferences_IgnoredWorks() { MMPTests.RunMMPTest(tmpDir => { TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir) { ItemGroup = CreateSingleNativeRef(Path.GetFullPath(SimpleDylibPath), "Dynamic"), CSProjConfig = string.Format(@"<MonoBundlingExtraArgs>--ignore-native-library=""{0}""</MonoBundlingExtraArgs>", Path.GetFullPath(SimpleDylibPath)) }; NativeReferenceTestCore(tmpDir, test, "Unified_WithNativeReferences_InMainProjectWorks - Local", null, true, true); }); }
public void ShouldNotAllowReference_ToSystemDrawing() { MMPTests.RunMMPTest(tmpDir => { TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir) { References = " <Reference Include=\"System.Drawing\" />", TestCode = "System.Drawing.RectangleF f = new System.Drawing.RectangleF ();", XM45 = true }; TI.TestUnifiedExecutable(test, shouldFail: true); }); }
public void AOT_32Bit_SmokeTest() { MMPTests.RunMMPTest(tmpDir => { TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir) { CSProjConfig = "<XamMacArch>i386</XamMacArch>" + AOTTestBaseConfig }; string buildResults = TI.TestUnifiedExecutable(test).BuildOutput; ValidateAOTStatus(tmpDir, f => ShouldBaseFilesBeAOT(f), buildResults); }); }
public void LongProfileStrings_ErrorsWhenWrongXMPassedToRightProfile() { MMPTests.RunMMPTest(tmpDir => { foreach (var targetProfile in XMTargetFrameworks) { string libPath = CreateTestExe(tmpDir); string args = GetTestMMPInvocation(tmpDir, libPath, targetProfile, false); string buildResults = TI.RunAndAssert(MMPPath, args, "mmp invoke with wrong XM", shouldFail: true); Assert.IsTrue(buildResults.Contains("1407"), "Did not contains 1407 error expected"); } }); }
public void DirectoryContainsSpaces (bool full, string arch) { if (!PlatformHelpers.CheckSystemVersion (10, 11)) return; MMPTests.RunMMPTest (tmpDir => { TI.UnifiedTestConfig test = new TI.UnifiedTestConfig (tmpDir) { CSProjConfig = $"<MonoBundlingExtraArgs>--registrar=static</MonoBundlingExtraArgs><XamMacArch>{arch}</XamMacArch>", XM45 = full }; }, "test withSpace"); }
public void DoesNotSupportLinkWith(BindingProjectType type) { MMPTests.RunMMPTest(tmpDir => { var projects = BindingProjectTests.GenerateTestProject(type, tmpDir); BindingProjectTests.SetNoEmbedding(projects.Item1); projects.Item1.LinkWithName = "SimpleClassDylib.dylib"; string libBuildLog = BindingProjectTests.SetupAndBuildBindingProject(projects.Item1, false, shouldFail: true); Assert.True(libBuildLog.Contains("Can't create a binding resource package unless there are native references in the binding project."), $"Did not fail as expected: {TI.PrintRedirectIfLong (libBuildLog)}"); }); }
public void LibrariesEmbeddedProperly(BindingProjectType type, bool useProjectReference) { MMPTests.RunMMPTest(tmpDir => { var projects = BindingProjectTests.GenerateTestProject(type, tmpDir); BindingProjectTests.SetNoEmbedding(projects.Item1); string appBuildLog = BindingProjectTests.SetupAndBuildLinkedTestProjects(projects.Item1, projects.Item2, tmpDir, useProjectReference, setupDefaultNativeReference: true).Item2; AssertNoResourceWithName(tmpDir, projects.Item1.ProjectName, "SimpleClassDylib.dylib"); AssertFileInBundle(tmpDir, type, "MonoBundle/SimpleClassDylib.dylib"); }); }
public void CleanShouldRemoveBundle() { MMPTests.RunMMPTest(tmpDir => { var projects = BindingProjectTests.GenerateTestProject(BindingProjectType.Modern, tmpDir); BindingProjectTests.SetNoEmbedding(projects.Item1); string libBuildLog = BindingProjectTests.SetupAndBuildBindingProject(projects.Item1, true); TI.CleanUnifiedProject(Path.Combine(tmpDir, projects.Item1.ProjectName)); Assert.False(Directory.Exists(Path.Combine(tmpDir, "bin/Debug/MobileBinding.resources")), "Resource bundle was not cleaned up"); }); }
public void Unified_WithStaticNativeRef_32bit() { MMPTests.RunMMPTest(tmpDir => { TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir) { CSProjConfig = "<XamMacArch>i386</XamMacArch>", References = $"<Reference Include=\"SimpleBinding_static\"><HintPath>{MobileStaticBindingPath}</HintPath></Reference>", TestCode = "System.Console.WriteLine (new Simple.SimpleClass ().DoIt ());" }; NativeReferenceTestCore(tmpDir, test, "Unified_WithStaticNativeRef_32bit", null, true, false); }); }