public void BuildingSameSolutionTwice_ShouldNotRunACToolTwice() { RunMMPTest(tmpDir => { TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir) { AssetIcons = true }; string project = TI.GenerateUnifiedExecutableProject(test); string buildOutput = TI.BuildProject(project); Assert.True(buildOutput.Contains("actool execution started with arguments"), $"Initial build should run actool"); buildOutput = TI.BuildProject(project); Assert.False(buildOutput.Contains("actool execution started with arguments"), $"Second build should not run actool"); TI.RunAndAssert("touch", new [] { Path.Combine(tmpDir, "Assets.xcassets/AppIcon.appiconset/[email protected]") }, "touch icon"); buildOutput = TI.BuildProject(project); Assert.True(buildOutput.Contains("actool execution started with arguments"), $"Build after touching icon must run actool"); }); }
public void Unified_HelloWorld_ShouldHaveNoWarnings(bool release, bool full) { RunMMPTest(tmpDir => { TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir); test.Release = release; test.XM45 = full; var rv = TI.TestUnifiedExecutable(test); Console.WriteLine(rv.BuildResult); if (full && release) { rv.Messages.AssertWarning(5220, "Skipping framework 'QTKit'. It is prohibited (rejected) by the Mac App Store"); // We get the MM5220 twice in the output, once from mmp and once from msbuild repeating what mmp said, so we can't assert that there's exactly 1 warning. // Instead assert that we get no warning but MM5220. Assert.IsFalse(rv.Messages.Messages.Any((v) => v.Number != 5220), "No warnings except MM5220"); } else { rv.Messages.AssertWarningCount(0); } }); }
public void Unified_WithNativeReferences_InMainProjectWorks() { 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 = string.Format(NativeReferenceTemplate, SystemLibPath, "Dynamic") }; NativeReferenceTestCore(tmpDir, test, "Unified_WithNativeReferences_InMainProjectWorks - System", "libsqlite3.0.dylib", true); test.ItemGroup = string.Format(NativeReferenceTemplate, Path.GetFullPath(SimpleDylibPath), "Dynamic"); NativeReferenceTestCore(tmpDir, test, "Unified_WithNativeReferences_InMainProjectWorks - Local", "SimpleClassDylib.dylib", true); test.ItemGroup = string.Format(NativeReferenceTemplate, Path.GetFullPath(SimpleStaticPath), "Static"); NativeReferenceTestCore(tmpDir, test, "Unified_WithNativeReferences_InMainProjectWorks - Static", null, true); test.ItemGroup = string.Format(NativeReferenceTemplate, "/Library/Frameworks/iTunesLibrary.framework", "Framework"); NativeReferenceTestCore(tmpDir, test, "Unified_WithNativeReferences_InMainProjectWorks - Framework", null, true); }); }
public void HybridAOT_WithManualStrippingOfAllLibs_SmokeTest(bool useProjectTags) { MMPTests.RunMMPTest(tmpDir => { TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir) { CSProjConfig = GetTestConfig(TestType.Hybrid, useProjectTags) }; string buildResults = TI.TestUnifiedExecutable(test).BuildOutput; foreach (var file in GetOutputDirInfo(tmpDir).EnumerateFiles()) { if (IsFileManagedCode(file)) { TI.RunAndAssert("/Library/Frameworks/Mono.framework/Commands/mono-cil-strip", file.ToString(), "Manually strip IL"); } } ValidateAOTStatus(tmpDir, IsFileManagedCode, buildResults); TI.RunEXEAndVerifyGUID(tmpDir, test.guid, GetOutputAppPath(tmpDir)); }); }
public void AOT_32Bit_SmokeTest() { RunMMPTest(tmpDir => { TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir) { CSProjConfig = "<XamMacArch>i386</XamMacArch><MonoBundlingExtraArgs>--aot=core,-Xamarin.Mac.dll</MonoBundlingExtraArgs>" }; string buildResults = TI.TestUnifiedExecutable(test).BuildOutput; var dirInfo = new DirectoryInfo(Path.Combine(tmpDir, "bin/Debug/UnifiedExample.app/Contents/MonoBundle/")); foreach (var file in dirInfo.EnumerateFiles()) { string extension = file.Extension.ToLowerInvariant(); if (extension == ".exe" || extension == ".dll") { bool shouldBeAOT = (file.Name == "System.dll" || file.Name == "mscorlib.dll"); Assert.AreEqual(shouldBeAOT, File.Exists(file.FullName + ".dylib"), "{0} should {1} be AOT.\n{2}", file.FullName, shouldBeAOT ? "" : "not", buildResults); } } }); }
public void MM0135() { var oldXcode = Xamarin.Tests.Configuration.xcode94_root; if (!Directory.Exists(oldXcode)) { Assert.Ignore("This test requires Xcode 9.4 (or updated to a newer one that still warns MM0135)."); } if (PlatformHelpers.CheckSystemVersion(10, 15)) { Assert.Ignore("This test requires Xcode 9.4, which doesn't work on macOS 10.15+"); } MMPTests.RunMMPTest(tmpDir => { TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir); var output = TI.TestUnifiedExecutable(test, environment: new Dictionary <string, string> { { "MD_APPLE_SDK_ROOT", Path.GetDirectoryName(Path.GetDirectoryName(oldXcode)) } }); output.Messages.AssertWarningPattern(135, $"Did not link system framework"); }); }
public void HardenedRuntimeCodesignOption() { // https://github.com/xamarin/xamarin-macios/issues/5653 if (TI.InJenkins) { Assert.Ignore("Requires macOS entitlements on bots."); } RunMMPTest(tmpDir => { TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir) { CSProjConfig = "<EnableCodeSigning>true</EnableCodeSigning>" }; Func <OutputText, string> findCodesign = o => o.BuildOutput.SplitLines().Last(x => x.Contains("Tool /usr/bin/codesign execution started with arguments")); var baseOutput = TI.TestUnifiedExecutable(test); string baseCodesign = findCodesign(baseOutput); Assert.False(baseCodesign.Contains("-o runtime"), "Base codesign"); test.CSProjConfig += "<UseHardenedRuntime>true</UseHardenedRuntime><CodeSignEntitlements>Entitlements.plist</CodeSignEntitlements>"; const string entitlementText = @"<?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>com.apple.security.cs.allow-jit</key> <true/> </dict> </plist>"; File.WriteAllText(Path.Combine(tmpDir, "Entitlements.plist"), entitlementText); var hardenedOutput = TI.TestUnifiedExecutable(test); string hardenedCodesign = findCodesign(hardenedOutput); Assert.True(hardenedCodesign.Contains("-o runtime"), "Hardened codesign"); }); }
public void FilePathCollisionShouldNotFailBuild() { RunMMPTest(tmpDir => { var libraryDirectory = tmpDir + "/UnifiedExample/"; var libraryName = "UnifiedLibrary"; Directory.CreateDirectory(libraryDirectory); TI.UnifiedTestConfig libConfig = new TI.UnifiedTestConfig(libraryDirectory) { ProjectName = libraryName }; string csprojTarget = TI.GenerateUnifiedLibraryProject(libConfig); TI.BuildProject(csprojTarget); string referenceCode = string.Format(@"<Reference Include=""UnifiedLibrary""><HintPath>{0}</HintPath></Reference>", Path.Combine(libraryDirectory, "bin/Debug/", $"{libraryName}.dll")); TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir) { References = referenceCode }; TI.TestUnifiedExecutable(test); }); }
public void Unified_FailedBuild_ShouldRequireAnotherBuildNotSkipMMP() { RunMMPTest(tmpDir => { foreach (bool xm45 in new bool [] { false, true }) { // First build with a Non-existant file to force us to error inside mmp test TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir) { CSProjConfig = "<MonoBundlingExtraArgs>--resource=Foo.bar</MonoBundlingExtraArgs>", XM45 = xm45 }; TI.GenerateAndBuildUnifiedExecutable(test, shouldFail: true); // Next, build again without the error MonoBundlingExtraArgs test.CSProjConfig = ""; TI.GenerateUnifiedExecutableProject(test); // And try again. // If we fail, we'll likley fail with "did not generate an exe" before returning but let's check anyway string secondBuildOutput = TI.BuildProject(Path.Combine(tmpDir, TI.GetUnifiedExecutableProjectName(test)), true); Assert.IsTrue(!secondBuildOutput.Contains("Skipping target \"_CompileToNative"), "Did not skip"); Assert.IsTrue(secondBuildOutput.Contains("Building target \"_CompileToNative\" completely"), "Did need to build"); } }); }
public void Unified32BitWithXMRequiringLibrary_ShouldReferenceCorrectXM_AndNotCrash() { RunMMPTest(tmpDir => { TI.UnifiedTestConfig libConfig = new TI.UnifiedTestConfig(tmpDir) { ProjectName = "UnifiedLibrary", TestCode = "namespace Library { public static class Foo { public static void Bar () { var v = new Foundation.NSObject (); } } }" }; string csprojTarget = TI.GenerateUnifiedLibraryProject(libConfig); TI.BuildProject(csprojTarget, isUnified: true); string referenceCode = string.Format(@"<Reference Include=""UnifiedLibrary""><HintPath>{0}</HintPath></Reference>", Path.Combine(tmpDir, "bin/Debug/UnifiedLibrary.dll")); TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir) { CSProjConfig = @"<PlatformTarget>x86</PlatformTarget><XamMacArch>i386</XamMacArch>", ReferencesBeforePlatform = referenceCode, TestCode = "Library.Foo.Bar ();" }; TI.TestUnifiedExecutable(test); }); }
public void SystemMono_SmokeTest() { if (TI.FindMonoVersion() < new Version("4.3")) { return; } RunMMPTest(tmpDir => { TI.UnifiedTestConfig test = new TI.UnifiedTestConfig(tmpDir); TI.TestSystemMonoExecutable(test); test.SystemMonoVersion = "4.5"; TI.TestSystemMonoExecutable(test); test.SystemMonoVersion = "4.5.1"; TI.TestSystemMonoExecutable(test); test.SystemMonoVersion = "4.6"; TI.TestSystemMonoExecutable(test); test.SystemMonoVersion = "4.6.1"; TI.TestSystemMonoExecutable(test); }); }
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 testOutput = TI.TestUnifiedExecutable(test); string buildOutput = testOutput.BuildOutput; Assert.AreEqual(shouldStrip, DidAnyLipoStrip(buildOutput), "lipo usage did not match expectations"); if (shouldStrip) { testOutput.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 { testOutput.Messages.AssertWarningCount(0); } }); }
static void MonoPosixTestCore(string tmpDir, TI.UnifiedTestConfig test) { TI.TestUnifiedExecutable(test, shouldFail: false); Assert.IsTrue(File.Exists(Path.Combine(tmpDir, "bin/Debug/XM45Example.app/Contents/MonoBundle/libMonoPosixHelper.dylib")), String.Format("Does {0}/bin/Debug/XM45Example.app/Contents/MonoBundle/libMonoPosixHelper.dylib to exist?", tmpDir)); }
internal static Tuple <string, string> SetupAndBuildLinkedTestProjects(TI.UnifiedTestConfig binding, TI.UnifiedTestConfig project, string tmpDir, bool useProjectReference, bool setupDefaultNativeReference) { string bindingBuildLog = SetupAndBuildBindingProject(binding, setupDefaultNativeReference); string bindingName = RemoveCSProj(binding.ProjectName); if (useProjectReference) { project.References = $@"<ProjectReference Include=""{bindingName}.csproj"" />"; } else { project.References = $@"<Reference Include=""{bindingName}""><HintPath>{Path.Combine (tmpDir, "bin/Debug", bindingName + ".dll")}</HintPath></Reference>"; } project.TestCode = "System.Console.WriteLine (typeof (ExampleBinding.UnifiedWithDepNativeRefLibTestClass));"; string appBuildLog = TI.TestUnifiedExecutable(project).BuildOutput; return(new Tuple <string, string> (bindingBuildLog, appBuildLog)); }
internal static void SetNoEmbedding(TI.UnifiedTestConfig project) { project.CSProjConfig = "<NoBindingEmbedding>true</NoBindingEmbedding>"; }
static Tuple <string, string> BuildLinkedTestProjects(TI.UnifiedTestConfig binding, TI.UnifiedTestConfig project, string tmpDir) { binding.ItemGroup = NativeReferenceTests.CreateSingleNativeRef(Path.GetFullPath(NativeReferenceTests.SimpleDylibPath), "Dynamic"); binding.StructsAndEnumsConfig = "public class UnifiedWithDepNativeRefLibTestClass {}"; string projectPath = TI.GenerateBindingLibraryProject(binding); string bindingBuildLog = TI.BuildProject(projectPath, true); string bindingName = RemoveCSProj(binding.ProjectName); project.References = string.Format(@"<Reference Include=""{0}""><HintPath>{1}</HintPath></Reference>", bindingName, Path.Combine(tmpDir, "bin/Debug", bindingName + ".dll")); project.TestCode = "System.Console.WriteLine (typeof (ExampleBinding.UnifiedWithDepNativeRefLibTestClass));"; string appBuildLog = TI.TestUnifiedExecutable(project).BuildOutput; return(new Tuple <string, string> (bindingBuildLog, appBuildLog)); }