2017-11-14 21:40:11 +03:00
/ *
* Shared unit tests between XI and XM .
* * /
using System ;
2019-02-06 12:27:55 +03:00
using System.Collections.Generic ;
2017-11-14 21:40:11 +03:00
using System.IO ;
2019-02-06 12:27:55 +03:00
using System.Linq ;
2017-11-24 18:52:58 +03:00
using System.Xml ;
2017-11-28 18:43:27 +03:00
using System.Text ;
2017-11-14 21:40:11 +03:00
using NUnit.Framework ;
2019-02-06 12:27:55 +03:00
using Xamarin ;
2022-11-17 15:04:59 +03:00
namespace Xamarin.Tests {
2017-11-14 21:40:11 +03:00
[TestFixture]
2022-11-17 15:04:59 +03:00
public class ProductTests {
2017-11-14 21:40:11 +03:00
[Test]
public void MonoVersion ( )
{
// Verify that the mono version is in the Versions.plist, and that it's a parsable version number.
2017-11-24 18:52:58 +03:00
var settings = new XmlReaderSettings ( ) {
XmlResolver = null ,
DtdProcessing = DtdProcessing . Parse
} ;
2017-11-14 21:40:11 +03:00
var plist = Path . Combine ( Configuration . SdkRoot , "Versions.plist" ) ;
2017-11-24 18:52:58 +03:00
var xml = new XmlDocument ( ) ;
2017-11-28 18:43:27 +03:00
using ( var sr = new StreamReader ( plist , Encoding . UTF8 , true ) )
2017-11-24 18:52:58 +03:00
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" ) ;
}
2017-11-14 21:40:11 +03:00
}
2019-02-06 12:27:55 +03:00
[Test]
2019-03-01 10:00:53 +03:00
[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)]
2019-02-13 05:18:37 +03:00
public void MinOSVersion ( Profile profile , MachO . LoadCommands load_command , MachO . Platform platform , bool device = false )
2019-02-06 12:27:55 +03:00
{
2022-09-22 08:33:42 +03:00
Configuration . IgnoreIfIgnoredPlatform ( profile . AsPlatform ( ) ) ;
2019-02-06 17:24:08 +03:00
if ( device )
2019-02-07 10:32:59 +03:00
Configuration . AssertDeviceAvailable ( ) ;
2019-02-06 17:24:08 +03:00
2019-03-01 10:00:53 +03:00
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" ;
}
) ;
2019-02-06 12:27:55 +03:00
var failed = new List < string > ( ) ;
2019-03-01 10:00:53 +03:00
foreach ( var machoFile in machoFiles ) {
var fatfile = MachO . Read ( machoFile ) ;
2019-02-06 12:27:55 +03:00
foreach ( var slice in fatfile ) {
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 */ )
2019-09-09 10:34:11 +03:00
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 ;
2019-02-06 12:27:55 +03:00
var any_load_command = false ;
foreach ( var lc in slice . load_commands ) {
2019-02-13 05:18:37 +03:00
Version lc_min_version ;
2019-02-06 12:27:55 +03:00
var mincmd = lc as MinCommand ;
2022-11-17 15:04:59 +03:00
if ( mincmd ! = null ) {
2019-02-13 05:18:37 +03:00
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 ;
2019-02-06 12:27:55 +03:00
2019-03-01 10:02:37 +03:00
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 ;
}
2022-11-17 15:04:59 +03:00
Assert . That ( buildver . Platform , Is . EqualTo ( platform ) . Or . EqualTo ( alternativePlatform ) , $"Unexpected build version command in {machoFile} ({slice.Filename})" ) ;
2019-02-13 05:18:37 +03:00
lc_min_version = buildver . MinOS ;
}
2019-02-06 12:27:55 +03:00
Version version ;
Version alternate_version = null ;
2019-02-13 05:18:37 +03:00
Version mono_native_compat_version ;
2021-03-25 00:34:30 +03:00
Version alternate_mono_native_compat_version = null ;
2019-02-13 05:18:37 +03:00
Version mono_native_unified_version ;
2019-05-10 09:22:11 +03:00
Version alternate_mono_native_unified_version = null ;
2019-02-06 12:27:55 +03:00
switch ( load_command ) {
case MachO . LoadCommands . MinMacOSX :
version = SdkVersions . MinOSXVersion ;
Xamarin.Mac native Apple Silicon targetting support (#10115)
* Add support for Xamarin.Mac arm64
* Add compile product definition task
Xamarin.Mac can be provided with a ProductDefinition file for the generated pkg. Normally, providing a product definition was optional. However, with Apple Silicon, we have an extra issue : `productbuild` needs to know what architectures your package target. If not provided with them, it will guess to the best of its abilities. However, on Catalina and lower, the guess is x86_64, even if you have an arm64 slice. To fix this, we add a new task to compile the product definition and use this file to create the pkg. If you provide your own Product Definition, we can check and warn if the architectures don't match what we expect. If the file doesn't exist or there is no architecture, we set it ourselves based on our target architectures.
* Don't reference dynamic objC_send on arm64
When building in debug, we currently try to link dynamic objC_send symbols when targeting a 64-bit architecture. However, this is actually only defined on Intel architectures, not on arm64, so we end up failing because we're referring symbols that don't exist. Rework the `GetRequiredSymbols` to take an abi, and tag those symbols to only be valid on i386/x86_64, so they don't get referred at all when building on arm64, but still get referred in x86_64.
* Fix improper delete/move with already existing directories
* Fix stret requirement for Xamarin.Mac in arm64.
The generator supposes that we're running in x64 mode, refactor to take into account the possibility of running in arm64.
* Implement OS version generation in Product.plist, based on MinimumSystemVersion of the app
* Re-generalize some mmp registrar rules
`Microsoft.macOS.registrar` was missed by the current rule set
* Fix mmp tests
* Set E7072 as not translated
Tests were failing otherwise
* Rename Xamarin.Mac lib/x86_64 folder to 64bits (currently all targeted archs are the same)
* Fix style issues
* Fix `ToLower` usage for invariant usage
* Fix xtro-sharpie test
2021-03-18 04:48:02 +03:00
if ( slice . Architecture = = MachO . Architectures . ARM64 ) {
alternate_version = new Version ( 11 , 0 , 0 ) ;
}
2019-02-13 05:18:37 +03:00
mono_native_compat_version = SdkVersions . MinOSXVersion ;
mono_native_unified_version = new Version ( 10 , 12 , 0 ) ;
2019-02-06 12:27:55 +03:00
break ;
case MachO . LoadCommands . MiniPhoneOS :
version = SdkVersions . MiniOSVersion ;
2019-03-01 10:00:53 +03:00
if ( slice . IsDynamicLibrary & & device ) {
2019-02-06 12:27:55 +03:00
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).
2019-03-01 10:00:53 +03:00
} else if ( slice . Architecture = = MachO . Architectures . ARM64 ) {
alternate_version = new Version ( 7 , 0 , 0 ) ; // our arm64 slices has min iOS 7.0.
2019-06-19 08:20:02 +03:00
} else if ( slice . IsDynamicLibrary & & ! device ) {
version = new Version ( 8 , 0 , 0 ) ;
2020-02-14 22:20:55 +03:00
alternate_version = new Version ( 7 , 0 , 0 ) ;
2019-02-06 12:27:55 +03:00
}
2019-05-24 02:36:29 +03:00
mono_native_compat_version = version ;
2019-02-13 05:18:37 +03:00
mono_native_unified_version = new Version ( 10 , 0 , 0 ) ;
2021-03-25 00:34:30 +03:00
alternate_mono_native_compat_version = new Version ( 7 , 0 , 0 ) ; // Xcode 12.4 built binaries
2019-02-06 12:27:55 +03:00
break ;
case MachO . LoadCommands . MintvOS :
version = SdkVersions . MinTVOSVersion ;
2019-05-24 02:36:29 +03:00
mono_native_compat_version = version ;
2019-02-13 05:18:37 +03:00
mono_native_unified_version = new Version ( 10 , 0 , 0 ) ;
2019-02-06 12:27:55 +03:00
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
2019-02-13 05:18:37 +03:00
mono_native_compat_version = SdkVersions . MinWatchOSVersion ;
mono_native_unified_version = new Version ( 5 , 0 , 0 ) ;
2019-05-10 09:22:11 +03:00
if ( device )
alternate_mono_native_unified_version = new Version ( 5 , 1 , 0 ) ; // armv7k has 5.0, arm64_32 has 5.1
2019-02-06 12:27:55 +03:00
break ;
default :
throw new NotImplementedException ( load_command . ToString ( ) ) ;
}
2019-02-13 05:18:37 +03:00
version = version . WithBuild ( ) ;
mono_native_compat_version = mono_native_compat_version . WithBuild ( ) ;
mono_native_unified_version = mono_native_unified_version . WithBuild ( ) ;
2019-02-06 12:27:55 +03:00
if ( alternate_version = = null )
alternate_version = version ;
2019-05-10 09:22:11 +03:00
if ( alternate_mono_native_unified_version = = null )
alternate_mono_native_unified_version = mono_native_unified_version ;
2021-03-25 00:34:30 +03:00
if ( alternate_mono_native_compat_version = = null )
alternate_mono_native_compat_version = mono_native_compat_version ;
2019-02-06 12:27:55 +03:00
2019-03-01 10:02:37 +03:00
switch ( Path . GetFileName ( machoFile ) ) {
2019-02-13 05:18:37 +03:00
case "libmono-native-compat.dylib" :
2019-03-01 10:02:37 +03:00
case "libmono-native-compat.a" :
2021-03-25 00:34:30 +03:00
if ( mono_native_compat_version ! = lc_min_version & & alternate_mono_native_compat_version ! = lc_min_version )
2019-03-01 10:02:37 +03:00
failed . Add ( $"Unexpected minOS version (expected {mono_native_compat_version}, found {lc_min_version}) in {machoFile} ({slice.Filename})." ) ;
2019-02-13 05:18:37 +03:00
break ;
case "libmono-native-unified.dylib" :
2019-03-01 10:02:37 +03:00
case "libmono-native-unified.a" :
2019-05-10 09:22:11 +03:00
if ( mono_native_unified_version ! = lc_min_version & & alternate_mono_native_unified_version ! = lc_min_version )
2019-03-01 10:02:37 +03:00
failed . Add ( $"Unexpected minOS version (expected {mono_native_unified_version}, found {lc_min_version}) in {machoFile} ({slice.Filename})." ) ;
2019-02-13 05:18:37 +03:00
break ;
default :
if ( version ! = lc_min_version & & alternate_version ! = lc_min_version )
2019-03-01 10:02:37 +03:00
failed . Add ( $"Unexpected minOS version (expected {version}, alternatively {alternate_version}, found {lc_min_version}) in {machoFile} ({slice.Filename})." ) ;
2019-02-13 05:18:37 +03:00
break ;
}
2019-02-06 12:27:55 +03:00
any_load_command = true ;
}
if ( ! any_load_command )
2019-03-01 10:00:53 +03:00
failed . Add ( $"No minOS version found in {machoFile}." ) ;
2019-02-06 12:27:55 +03:00
}
}
CollectionAssert . IsEmpty ( failed , "Failures" ) ;
}
2017-11-14 21:40:11 +03:00
}
2019-02-13 05:18:37 +03:00
2022-11-17 15:04:59 +03:00
static class VersionExtensions {
public static Version WithBuild ( this Version version )
{
return new Version ( version . Major , version . Minor , version . Build < 0 ? 0 : version . Build ) ;
}
2019-02-13 05:18:37 +03:00
}
2017-11-14 21:40:11 +03:00
}