xamarin-macios/tests/common/ProductTests.cs

193 строки
7.9 KiB
C#
Исходник Обычный вид История

/*
* Shared unit tests between XI and XM.
**/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using System.Text;
using NUnit.Framework;
using Xamarin;
namespace Xamarin.Tests
{
[TestFixture]
public class ProductTests
{
[Test]
public void MonoVersion ()
{
// Verify that the mono version is in the Versions.plist, and that it's a parsable version number.
var settings = new XmlReaderSettings () {
XmlResolver = null,
DtdProcessing = DtdProcessing.Parse
};
var plist = Path.Combine (Configuration.SdkRoot, "Versions.plist");
var xml = new XmlDocument ();
using (var sr = new StreamReader (plist, Encoding.UTF8, true))
using (var reader = XmlReader.Create (sr, settings)) {
xml.Load (reader);
var version = xml.SelectSingleNode ("//dict/key[text()='MonoVersion']")?.NextSibling?.InnerText;
Assert.DoesNotThrow (() => Version.Parse (version), "version");
}
}
[Test]
[TestCase (Profile.macOSSystem, MachO.LoadCommands.MinMacOSX, MachO.Platform.MacOS)]
[TestCase (Profile.macOSFull, MachO.LoadCommands.MinMacOSX, MachO.Platform.MacOS)]
[TestCase (Profile.macOSMobile, MachO.LoadCommands.MinMacOSX, MachO.Platform.MacOS)]
[TestCase (Profile.iOS, MachO.LoadCommands.MiniPhoneOS, MachO.Platform.IOSSimulator, false)]
[TestCase (Profile.iOS, MachO.LoadCommands.MiniPhoneOS, MachO.Platform.IOS, true)]
[TestCase (Profile.watchOS, MachO.LoadCommands.MinwatchOS, MachO.Platform.WatchOSSimulator, false)]
[TestCase (Profile.watchOS, MachO.LoadCommands.MinwatchOS, MachO.Platform.WatchOS, true)]
[TestCase (Profile.tvOS, MachO.LoadCommands.MintvOS, MachO.Platform.TvOSSimulator, false)]
[TestCase (Profile.tvOS, MachO.LoadCommands.MintvOS, MachO.Platform.TvOS, true)]
public void MinOSVersion (Profile profile, MachO.LoadCommands load_command, MachO.Platform platform, bool device = false)
{
if (device)
Configuration.AssertDeviceAvailable ();
var machoFiles = Directory.GetFiles (Configuration.GetSdkPath (profile, device), "*", SearchOption.AllDirectories)
.Where ((v) => {
if (v.Contains ("dylib.dSYM/Contents/Resources/DWARF")) {
// Don't include *.dylib from inside .dSYMs.
return false;
} else if (v.Contains ("libxammac-classic") || v.Contains ("libxammac-system-classic")) {
// We don't care about XM Classic, those are binary dependencies.
return false;
}
var ext = Path.GetExtension (v);
return ext == ".a" || ext == ".dylib";
}
);
var failed = new List<string> ();
foreach (var machoFile in machoFiles) {
var fatfile = MachO.Read (machoFile);
foreach (var slice in fatfile) {
Drop the Xcode 9.4 dependency. (#7044) * Drop the Xcode 9.4 dependency. Also bump mono to get the removal of the mac32 binaries. New commits in mono/mono: * mono/mono@70d69030534 [2019-08] [merp] Use a separate program as the hang supervisor. (#16900) * mono/mono@4bff2b6370b [offsets-tool] Install clang into the user-specific python directory. * mono/mono@81894ec8cad Implement WriteCore and ReadCore in DeflateStream * mono/mono@bfbf823ca11 [ci] Remove more XCODE32_DIR usages (#16964) * mono/mono@ce01b20a4d4 Add net_4.8.xml to EXTRA_DIST and bump binary-reference-assemblies again * mono/mono@7a587d7fa61 Add .NET 4.8 reference assemblies (#16912) * mono/mono@35e454a8f6a [sdks] Remove the mac32 build. (#16936) * mono/mono@75eb342f532 [2019-08] [System] Make FileSystemWatcher backend non-static (#16926) * mono/mono@5881981f790 [2019-08] [mini] Add missing membars when initializing rgctx entries (#16909) * mono/mono@6290b6cd6e3 Temporarily disable embedded ppdb data decompression (#16911) * mono/mono@a0e7f9eaf2e [2019-08] [arm64_32] make "Debug Mode" work on Watch series 4 with --interpreter (#16886) * mono/mono@6275840a7f8 Rename bundle identifier for the various Mono.frameworks we create for Xamarin.iOS. Fixes xamarin/xamarin-macios#7005. (#16901) * mono/mono@25f60932839 [corlib] Fix building nunit-lite twice (#16895) * mono/mono@7ec17ba1be9 [2019-08] [android sdk] Add aprofutil tool (#16884) * mono/mono@f755f3b5391 [metadata] Fix leaks when handling a few attributes (#16850) * mono/mono@5f9a2db39b0 [2019-08] Fix infrequent hangs in test-runner. (#16854) * mono/mono@f31f5ea1f1b [2019-08] [threads] do not convert NULL thread name (#16828) * mono/mono@20308e6f874 [aot] Do not wrap tool_prefix path when calling strip (#16820) * mono/mono@cecda47c489 [aprofutil] Add -p and -f options * mono/mono@824cc12ac3f Bump to mono/corefx@e79cf5b * mono/mono@b77dc06a7e7 [aprofutil] Install the tool correctly (#16112) * mono/mono@1848d78d60f [aotprof-tool] Initial import of AOT profiler tool (#15384) * mono/mono@da0086e3042 [2019-08] Add RenamedEvent* to FSW sources from CoreFX (#16756) * mono/mono@0297b21b030 [msbuild][roslyn] Bump msbuild and roslyn to pull in new versions (#16768) * mono/mono@40631e3b9e3 [2019-08] [aot] move method_addresses to data.rel.so section to avoid text relocations (#16751) * mono/mono@68b77674e20 Vtable [i] can be null so this should be check before use it. Fixes #16712 * mono/mono@4a0b4f41ede [mini] publish global patches after JitInfo has been added * mono/mono@7a1f63fde68 [debugger][android] It was not initialising seq_points on MonoCompile on Android, so when was compiling dynamic methods, seq_points wasn't created and we got the assert when try to single step. Diff: https://github.com/mono/mono/compare/29b1ac19c961b959a09097dbc0fe4cd567cc5298..70d690305348cb30cf620db0679ba1173dc7adb0 * [tests] Add a fat macOS dylib for testing purposes. Add a binary version of a fat macOS dylib (because we can't create one when we need it since we can't create 32-bit slice anymore). It was created like this (in tests/test-libraries): $ cat test.m int theUltimateAnswer () { return 42; } $ /Applications/Xcode94.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang test.m -olibtest.i386.dylib -shared -isysroot /Applications/Xcode94.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -framework Foundation -framework CoreLocation -lz -arch i386 $ lipo -create libtest.i386.dylib .libs/macos/libtest.dylib -output libtest-fat.dylib * [tests] Adjust XM tests to XM not having fat dylibs anymore. * [tests] Adjust product tests to some libraries not being fat anymore. * One more test fix.
2019-09-24 14:40:18 +03:00
if (slice.IsDynamicLibrary && slice.Architecture == MachO.Architectures.x86_64 && slice.Parent != null && slice.Parent.size < 10240 /* this is the dummy x86_64 slice to appease Apple's notarization tooling */)
continue;
[tests] Fix tests after a modification to our dummy x86-64 slice in our shipping libraries. Fixes xamarin/maccore#2026. (#7241) Previously we only had a single dynamic library that was used as the dummy slice, but there may be a static library instead. So teach the tests about that static library. Fixes these test failures: 1) Failed : Xamarin.Tests.ProductTests.MinOSVersion(iOS,MiniPhoneOS,IOS,True) Unexpected build version command in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/SDKs/MonoTouch.iphoneos.sdk/usr/lib/libmono-profiler-log.a (x86-64-slice.o) Expected: IOS or 0 But was: MacOS at Xamarin.Tests.ProductTests.MinOSVersion (Xamarin.Tests.Profile profile, Xamarin.MachO+LoadCommands load_command, Xamarin.MachO+Platform platform, System.Boolean device) [0x00000] in <a0c772db19e5407bb3edc34b20e04476>:0 2) Failed : Xamarin.Tests.ProductTests.MinOSVersion(watchOS,MinwatchOS,WatchOS,True) Unexpected build version command in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/SDKs/Xamarin.WatchOS.sdk/usr/lib/libmono-profiler-log.a (x86-64-slice.o) Expected: WatchOS or 0 But was: MacOS at Xamarin.Tests.ProductTests.MinOSVersion (Xamarin.Tests.Profile profile, Xamarin.MachO+LoadCommands load_command, Xamarin.MachO+Platform platform, System.Boolean device) [0x00000] in <a0c772db19e5407bb3edc34b20e04476>:0 3) Failed : Xamarin.Tests.ProductTests.MinOSVersion(tvOS,MintvOS,TvOS,True) Unexpected build version command in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/SDKs/Xamarin.AppleTVOS.sdk/usr/lib/libmono-profiler-log.a (x86-64-slice.o) Expected: TvOS or 0 But was: MacOS at Xamarin.Tests.ProductTests.MinOSVersion (Xamarin.Tests.Profile profile, Xamarin.MachO+LoadCommands load_command, Xamarin.MachO+Platform platform, System.Boolean device) [0x00000] in <a0c772db19e5407bb3edc34b20e04476>:0 Fixes https://github.com/xamarin/maccore/issues/2026.
2019-10-17 08:25:47 +03:00
else if (!slice.IsDynamicLibrary && slice.Architecture == MachO.Architectures.x86_64 && slice.Filename == "x86-64-slice.o" /* a static version of the x86_64 dummy slice */)
continue;
var any_load_command = false;
foreach (var lc in slice.load_commands) {
Version lc_min_version;
var mincmd = lc as MinCommand;
if (mincmd != null){
Assert.AreEqual (load_command, mincmd.Command, "Unexpected min load command");
lc_min_version = mincmd.Version;
} else {
// starting from iOS SDK 12 the LC_BUILD_VERSION is used instead
var buildver = lc as BuildVersionCommand;
if (buildver == null)
continue;
var alternativePlatform = (MachO.Platform) 0;
switch (platform) {
case MachO.Platform.IOSSimulator:
alternativePlatform = MachO.Platform.IOS;
break;
case MachO.Platform.TvOSSimulator:
alternativePlatform = MachO.Platform.TvOS;
break;
case MachO.Platform.WatchOSSimulator:
alternativePlatform = MachO.Platform.WatchOS;
break;
}
Assert.That (buildver.Platform, Is.EqualTo (platform).Or.EqualTo (alternativePlatform) , $"Unexpected build version command in {machoFile} ({slice.Filename})");
lc_min_version = buildver.MinOS;
}
Version version;
Version alternate_version = null;
Version mono_native_compat_version;
Version mono_native_unified_version;
Version alternate_mono_native_unified_version = null;
switch (load_command) {
case MachO.LoadCommands.MinMacOSX:
version = SdkVersions.MinOSXVersion;
mono_native_compat_version = SdkVersions.MinOSXVersion;
mono_native_unified_version = new Version (10, 12, 0);
break;
case MachO.LoadCommands.MiniPhoneOS:
version = SdkVersions.MiniOSVersion;
if (slice.IsDynamicLibrary && device) {
if (version.Major < 7)
version = new Version (7, 0, 0); // dylibs are supported starting with iOS 7.
alternate_version = new Version (8, 0, 0); // some iOS dylibs also have min OS 8.0 (if they're used as frameworks as well).
} else if (slice.Architecture == MachO.Architectures.ARM64) {
alternate_version = new Version (7, 0, 0); // our arm64 slices has min iOS 7.0.
} else if (slice.IsDynamicLibrary && !device) {
version = new Version (8, 0, 0);
alternate_version = new Version (7, 0, 0);
}
mono_native_compat_version = version;
mono_native_unified_version = new Version (10, 0, 0);
break;
case MachO.LoadCommands.MintvOS:
version = SdkVersions.MinTVOSVersion;
mono_native_compat_version = version;
mono_native_unified_version = new Version (10, 0, 0);
break;
case MachO.LoadCommands.MinwatchOS:
version = SdkVersions.MinWatchOSVersion;
Bump to mono:2019-06 (#6196) * Use the commonly used casing for `MSBuildSDKsPath` property Handle "incorrectly" cased msbuild property names msbuild property names are case insensitive. While generating the custom app.config, in `SetToolsetProperty(..)` we try to update the property if it already exists. But the name lookup was case sensitive, thus causing the lookup to fail, resulting in two entries for the same property name differing only in case. Eg. `MSBuildSDKsPath` vs `MSBuildSdksPath`. * [mtouch] Whitelist new Brotli native symbols in Xamarin.Tests.Misc.PublicSymbols test * [mtouch] Better assert in NoLLVMFailuresInWatchOS() test We'd list the "LLVM failed" messages before even though the AOT might've crashed and the list is meaningless. Assert the exit code before that. * [mtouch] Use new LLVM even for 32bit targets See https://github.com/mono/mono/issues/14841 and https://github.com/mono/mono/issues/9621 * [mtouch] Work around slow LLVM in "don't link" test See https://github.com/mono/mono/issues/14843 * Remove useless conditional * Remove LLVM36 from Makefile * [watch4] set right min version for arm64_32 based watch devices (#6307) Fixes the confusion around `libmono-native*` (see for example https://github.com/xamarin/xamarin-macios/commit/ce5ba1e41d526eddd9b61f68fae22a747831e9f2#commitcomment-33834491 ) when building with `MONO_BUILD_FROM_SOURCE=1`. * reflect watchos64_32_version_min change from mono sdk * Move mono hash info to mk/mono.mk so that existing scripts work. * Add Makefile dependency on mono.mk where necessary With https://github.com/xamarin/xamarin-macios/commit/3e7bc29adec8dff3558c284a3050f2db36ea3cf2 the Mono hash was moved from Make.config to mono.mk. We need to add a Makefile dependency on this file wherever Make.config was used to track a Mono dependency. * [tests] Copy mk/mono.mk to the XM test package. * [tests] Update minOS version test after consolidating min watchOS versions everywhere. Fixes this mtouch and mmptest failure: 1) Failed : Xamarin.Tests.ProductTests.MinOSVersion(watchOS,MinwatchOS,WatchOSSimulator,False) Failures Expected: <empty> But was: < "Unexpected minOS version (expected 2.0.0, alternatively 2.0.0, found 5.1.0) in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/SDKs/Xamarin.WatchSimulator.sdk/usr/lib/libxamarin-debug.a (mono-runtime-debug.arm64_32.o).", "Unexpected minOS version (expected 2.0.0, alternatively 2.0.0, found 5.1.0) in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/SDKs/Xamarin.WatchSimulator.sdk/usr/lib/libxamarin-debug.a (bindings-debug.arm64_32.o).", "Unexpected minOS version (expected 2.0.0, alternatively 2.0.0, found 5.1.0) in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/SDKs/Xamarin.WatchSimulator.sdk/usr/lib/libxamarin-debug.a (bindings-generated-debug.arm64_32.o).", "Unexpected minOS version (expected 2.0.0, alternatively 2.0.0, found 5.1.0) in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/SDKs/Xamarin.WatchSimulator.sdk/usr/lib/libxamarin-debug.a (shared-debug.arm64_32.o).", "Unexpected minOS version (expected 2.0.0, alternatively 2.0.0, found 5.1.0) in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/SDKs/Xamarin.WatchSimulator.sdk/usr/lib/libxamarin-debug.a (runtime-debug.arm64_32.o).", "Unexpected minOS version (expected 2.0.0, alternatively 2.0.0, found 5.1.0) in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/SDKs/Xamarin.WatchSimulator.sdk/usr/lib/libxamarin-debug.a (trampolines-debug.arm64_32.o).", "Unexpected minOS version (expected 2.0.0, alternatively 2.0.0, found 5.1.0) in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/SDKs/Xamarin.WatchSimulator.sdk/usr/lib/libxamarin-debug.a (trampolines-invoke-debug.arm64_32.o).", "Unexpected minOS version (expected 2.0.0, alternatively 2.0.0, found 5.1.0) in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/SDKs/Xamarin.WatchSimulator.sdk/usr/lib/libxamarin-debug.a (xamarin-support-debug.arm64_32.o).", "Unexpected minOS version (expected 2.0.0, alternatively 2.0.0, found 5.1.0) in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/SDKs/Xamarin.WatchSimulator.sdk/usr/lib/libxamarin-debug.a (nsstring-localization-debug.arm64_32.o).", "Unexpected minOS version (expected 2.0.0, alternatively 2.0.0, found 5.1.0) in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/SDKs/Xamarin.WatchSimulator.sdk/usr/lib/libxamarin-debug.a (trampolines-varargs-debug.arm64_32.o)."... > * [mmp] Fix make clean target It needs an -r to remove directories: ``` rm: bin: is a directory rm: obj: is a directory ``` * Add new xamarin_timezone_get_local_name() to a few more places
2019-07-16 18:24:00 +03:00
alternate_version = new Version (5, 1, 0); // arm64_32 has min OS 5.1
mono_native_compat_version = SdkVersions.MinWatchOSVersion;
mono_native_unified_version = new Version (5, 0, 0);
if (device)
alternate_mono_native_unified_version = new Version (5, 1, 0); // armv7k has 5.0, arm64_32 has 5.1
break;
default:
throw new NotImplementedException (load_command.ToString ());
}
version = version.WithBuild ();
mono_native_compat_version = mono_native_compat_version.WithBuild ();
mono_native_unified_version = mono_native_unified_version.WithBuild ();
if (alternate_version == null)
alternate_version = version;
if (alternate_mono_native_unified_version == null)
alternate_mono_native_unified_version = mono_native_unified_version;
switch (Path.GetFileName (machoFile)) {
case "libmono-native-compat.dylib":
case "libmono-native-compat.a":
if (mono_native_compat_version != lc_min_version)
failed.Add ($"Unexpected minOS version (expected {mono_native_compat_version}, found {lc_min_version}) in {machoFile} ({slice.Filename}).");
break;
case "libmono-native-unified.dylib":
case "libmono-native-unified.a":
if (mono_native_unified_version != lc_min_version && alternate_mono_native_unified_version != lc_min_version)
failed.Add ($"Unexpected minOS version (expected {mono_native_unified_version}, found {lc_min_version}) in {machoFile} ({slice.Filename}).");
break;
default:
if (version != lc_min_version && alternate_version != lc_min_version)
failed.Add ($"Unexpected minOS version (expected {version}, alternatively {alternate_version}, found {lc_min_version}) in {machoFile} ({slice.Filename}).");
break;
}
any_load_command = true;
}
if (!any_load_command)
failed.Add ($"No minOS version found in {machoFile}.");
}
}
CollectionAssert.IsEmpty (failed, "Failures");
}
}
static class VersionExtensions
{
public static Version WithBuild (this Version version)
{
return new Version (version.Major, version.Minor, version.Build < 0 ? 0 : version.Build);
}
}
}