From 0f67ef28f86a9aa935857a38f5cc1d47aae073d1 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Sat, 29 Jun 2019 21:53:19 +0200 Subject: [PATCH] Make CoreFx.Private.TestUtilites RID-agnostic (dotnet/corefx#36207) * Make CoreFx.Private.TestUtilites RID-agnostic * Add version checks for other distros https://github.com/dotnet/corefx/commit/dotnet/corefx@4f0d10773ccbb4849b869b6a0a73d5938f1804bd Porting fix over into PlatformDetection. * Build test lib in advance for VS support * Disable pretest in AllConfigurations Commit migrated from https://github.com/dotnet/corefx/commit/d3d144fad9b600a0fc1ca6fc7d65c247fddd9f04 --- .../Configurations.props | 2 +- .../CoreFx.Private.TestUtilities.csproj | 83 +++++ .../Interop/Interop.Libraries.cs | 13 + .../System/AdminHelpers.cs} | 30 +- .../System/AssertExtensions.cs | 0 .../System/Buffers/BoundedMemory.Creation.cs | 12 + .../System/Buffers/BoundedMemory.Unix.cs | 3 +- .../System/Buffers/BoundedMemory.Windows.cs | 2 +- .../System/Buffers/BoundedMemory.cs | 0 .../System/Buffers/PoisonPagePlacement.cs | 0 .../System/IO/FileCleanupTestBase.cs | 0 .../System/PlatformDetection.Unix.cs | 321 ++++++++++---------- .../System/PlatformDetection.Windows.cs | 275 ++++++++--------- .../System/PlatformDetection.cs | 181 +++++++---- .../System/RetryHelper.cs | 4 +- .../System/TestEnvironment.cs | 0 .../Common/tests/StaticTestGenerator/Program.cs | 1 - .../AlgorithmImplementations/RSA/EncryptDecrypt.cs | 3 +- .../AlgorithmImplementations/RSA/SignVerify.cs | 12 +- .../CoreFx.Private.TestUtilities.sln | 53 ---- .../Directory.Build.props | 12 - .../pkg/CoreFx.Private.TestUtilities.pkgproj | 17 -- .../ref/CoreFx.Private.TestUtilities.cs | 167 ----------- .../ref/CoreFx.Private.TestUtilities.csproj | 21 -- .../ref/CoreFx.Private.TestUtilities.netcoreapp.cs | 30 -- .../src/Configurations.props | 13 - .../src/CoreFx.Private.TestUtilities.csproj | 130 -------- .../Resources/CoreFx.Private.TestUtilities.rd.xml | 7 - .../src/System/AdminHelpers.Unix.cs | 24 -- .../src/System/AdminHelpers.cs | 33 -- .../src/System/Net/PlatformDetection.Networking.cs | 14 - .../src/System/PlatformApis.Unix.cs | 268 ----------------- .../src/System/PlatformDetection.NetFx.cs | 65 ---- .../System/PlatformDetection.NonNetFx.Windows.cs | 15 - .../src/System/TheoryExtensions.cs | 39 --- .../tests/AssertExtensionTests.cs | 334 --------------------- .../tests/ConditionalAttributeTests.cs | 66 ---- .../tests/Configurations.props | 8 - .../CoreFx.Private.TestUtilities.Tests.csproj | 14 - .../tests/TheoryExtensionTests.cs | 56 ---- src/libraries/Directory.Build.props | 12 +- .../tests/ProcessTestBase.Uap.cs | 3 +- .../System/DirectoryServices/SortOptionTests.cs | 15 +- .../tests/Directory/CreateDirectory.cs | 1 + .../System.IO.FileSystem/tests/FileSystemTest.cs | 1 + .../tests/System.Linq.Expressions.Tests.csproj | 1 - .../tests/FunctionalTests/HttpProtocolTests.cs | 1 + .../System.Net.Http.Functional.Tests.csproj | 3 - .../FunctionalTests/UriRelativeResolutionTest.cs | 13 +- .../tests/BinaryFormatterTestData.cs | 2 +- .../tests/BinaryFormatterTests.cs | 2 +- .../tests/PlatformExtensions.cs | 46 +-- .../tests/RsaCngTests.cs | 6 +- .../tests/EnvelopedCms/DecryptTests.cs | 17 +- .../DecryptTestsUsingCertWithPrivateKey.cs | 2 +- .../tests/EnvelopedCms/EdgeCasesTests.cs | 8 +- .../tests/EnvelopedCms/StateTests.cs | 8 +- .../tests/Samples/SigningVerifyingX509Cert.cs | 5 +- src/libraries/build.proj | 3 - src/libraries/dirs.proj | 2 +- .../packageIndex.json | 7 - src/libraries/pkg/descriptions.json | 5 - src/libraries/pkg/test/testPackages.proj | 1 - src/libraries/pretest.builds | 29 -- src/libraries/pretest.proj | 46 +++ 65 files changed, 638 insertions(+), 1929 deletions(-) rename src/libraries/{CoreFx.Private.TestUtilities/ref => Common/tests/CoreFx.Private.TestUtilities}/Configurations.props (88%) create mode 100644 src/libraries/Common/tests/CoreFx.Private.TestUtilities/CoreFx.Private.TestUtilities.csproj create mode 100644 src/libraries/Common/tests/CoreFx.Private.TestUtilities/Interop/Interop.Libraries.cs rename src/libraries/{CoreFx.Private.TestUtilities/src/System/AdminHelpers.Windows.cs => Common/tests/CoreFx.Private.TestUtilities/System/AdminHelpers.cs} (62%) rename src/libraries/{CoreFx.Private.TestUtilities/src => Common/tests/CoreFx.Private.TestUtilities}/System/AssertExtensions.cs (100%) rename src/libraries/{CoreFx.Private.TestUtilities/src => Common/tests/CoreFx.Private.TestUtilities}/System/Buffers/BoundedMemory.Creation.cs (88%) rename src/libraries/{CoreFx.Private.TestUtilities/src => Common/tests/CoreFx.Private.TestUtilities}/System/Buffers/BoundedMemory.Unix.cs (93%) rename src/libraries/{CoreFx.Private.TestUtilities/src => Common/tests/CoreFx.Private.TestUtilities}/System/Buffers/BoundedMemory.Windows.cs (99%) rename src/libraries/{CoreFx.Private.TestUtilities/src => Common/tests/CoreFx.Private.TestUtilities}/System/Buffers/BoundedMemory.cs (100%) rename src/libraries/{CoreFx.Private.TestUtilities/src => Common/tests/CoreFx.Private.TestUtilities}/System/Buffers/PoisonPagePlacement.cs (100%) rename src/libraries/{CoreFx.Private.TestUtilities/src => Common/tests/CoreFx.Private.TestUtilities}/System/IO/FileCleanupTestBase.cs (100%) rename src/libraries/{CoreFx.Private.TestUtilities/src => Common/tests/CoreFx.Private.TestUtilities}/System/PlatformDetection.Unix.cs (66%) rename src/libraries/{CoreFx.Private.TestUtilities/src => Common/tests/CoreFx.Private.TestUtilities}/System/PlatformDetection.Windows.cs (64%) rename src/libraries/{CoreFx.Private.TestUtilities/src => Common/tests/CoreFx.Private.TestUtilities}/System/PlatformDetection.cs (58%) rename src/libraries/{CoreFx.Private.TestUtilities/src => Common/tests/CoreFx.Private.TestUtilities}/System/RetryHelper.cs (98%) rename src/libraries/{CoreFx.Private.TestUtilities/src => Common/tests/CoreFx.Private.TestUtilities}/System/TestEnvironment.cs (100%) delete mode 100644 src/libraries/CoreFx.Private.TestUtilities/CoreFx.Private.TestUtilities.sln delete mode 100644 src/libraries/CoreFx.Private.TestUtilities/Directory.Build.props delete mode 100644 src/libraries/CoreFx.Private.TestUtilities/pkg/CoreFx.Private.TestUtilities.pkgproj delete mode 100644 src/libraries/CoreFx.Private.TestUtilities/ref/CoreFx.Private.TestUtilities.cs delete mode 100644 src/libraries/CoreFx.Private.TestUtilities/ref/CoreFx.Private.TestUtilities.csproj delete mode 100644 src/libraries/CoreFx.Private.TestUtilities/ref/CoreFx.Private.TestUtilities.netcoreapp.cs delete mode 100644 src/libraries/CoreFx.Private.TestUtilities/src/Configurations.props delete mode 100644 src/libraries/CoreFx.Private.TestUtilities/src/CoreFx.Private.TestUtilities.csproj delete mode 100644 src/libraries/CoreFx.Private.TestUtilities/src/Resources/CoreFx.Private.TestUtilities.rd.xml delete mode 100644 src/libraries/CoreFx.Private.TestUtilities/src/System/AdminHelpers.Unix.cs delete mode 100644 src/libraries/CoreFx.Private.TestUtilities/src/System/AdminHelpers.cs delete mode 100644 src/libraries/CoreFx.Private.TestUtilities/src/System/Net/PlatformDetection.Networking.cs delete mode 100644 src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformApis.Unix.cs delete mode 100644 src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.NetFx.cs delete mode 100644 src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.NonNetFx.Windows.cs delete mode 100644 src/libraries/CoreFx.Private.TestUtilities/src/System/TheoryExtensions.cs delete mode 100644 src/libraries/CoreFx.Private.TestUtilities/tests/AssertExtensionTests.cs delete mode 100644 src/libraries/CoreFx.Private.TestUtilities/tests/ConditionalAttributeTests.cs delete mode 100644 src/libraries/CoreFx.Private.TestUtilities/tests/Configurations.props delete mode 100644 src/libraries/CoreFx.Private.TestUtilities/tests/CoreFx.Private.TestUtilities.Tests.csproj delete mode 100644 src/libraries/CoreFx.Private.TestUtilities/tests/TheoryExtensionTests.cs delete mode 100644 src/libraries/pretest.builds create mode 100644 src/libraries/pretest.proj diff --git a/src/libraries/CoreFx.Private.TestUtilities/ref/Configurations.props b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/Configurations.props similarity index 88% rename from src/libraries/CoreFx.Private.TestUtilities/ref/Configurations.props rename to src/libraries/Common/tests/CoreFx.Private.TestUtilities/Configurations.props index ca0a1fd..ca41626 100644 --- a/src/libraries/CoreFx.Private.TestUtilities/ref/Configurations.props +++ b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/Configurations.props @@ -2,7 +2,7 @@ netcoreapp; - netstandard; + netfx; uap; diff --git a/src/libraries/Common/tests/CoreFx.Private.TestUtilities/CoreFx.Private.TestUtilities.csproj b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/CoreFx.Private.TestUtilities.csproj new file mode 100644 index 0000000..c50951d --- /dev/null +++ b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/CoreFx.Private.TestUtilities.csproj @@ -0,0 +1,83 @@ + + + {EBDB0247-CA43-4226-B7A1-8FEF21061D09} + true + $(NoWarn);CS1573 + + netcoreapp-Debug;netcoreapp-Release;netstandard-Debug;netstandard-Release + + + + + + + + + + + + + + + + + + + + + + + + Common\Interop\Windows\Kernel32\Interop.GetCurrentProcess_IntPtr.cs + + + Common\Interop\Windows\NtDll\Interop.RTL_OSVERSIONINFOEX.cs + + + Common\Interop\Windows\NtDll\Interop.RtlGetVersion.cs + + + Common\Interop\Windows\Advapi32\Interop.OpenProcessToken_SafeAccessTokenHandle.cs + + + Common\Interop\Windows\Interop.Libraries.cs + + + Common\CoreLib\Interop\Windows\Kernel32\Interop.CloseHandle.cs + + + Common\Interop\Windows\Advapi32\Interop.TOKEN_INFORMATION_CLASS.cs + + + Common\Interop\Windows\Advapi32\Interop.GetTokenInformation_void.cs + + + Common\Interop\Windows\Advapi32\Interop.TOKEN_ELEVATION.cs + + + Common\CoreLib\Interop\Windows\Interop.BOOL.cs + + + + + + Common\Interop\Unix\System.Security.Cryptography.Native\Interop.OpenSslVersion.cs + + + Common\Interop\Unix\Interop.GetEUid.cs + + + + + + + + + + diff --git a/src/libraries/Common/tests/CoreFx.Private.TestUtilities/Interop/Interop.Libraries.cs b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/Interop/Interop.Libraries.cs new file mode 100644 index 0000000..e1501f9 --- /dev/null +++ b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/Interop/Interop.Libraries.cs @@ -0,0 +1,13 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +internal static partial class Interop +{ + internal static partial class Libraries + { + // Shims + public const string CryptoNative = "System.Security.Cryptography.Native.OpenSsl"; + public const string SystemNative = "System.Native"; + } +} diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/System/AdminHelpers.Windows.cs b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/AdminHelpers.cs similarity index 62% rename from src/libraries/CoreFx.Private.TestUtilities/src/System/AdminHelpers.Windows.cs rename to src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/AdminHelpers.cs index 64173a9..56cdf0c 100644 --- a/src/libraries/CoreFx.Private.TestUtilities/src/System/AdminHelpers.Windows.cs +++ b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/AdminHelpers.cs @@ -3,19 +3,44 @@ // See the LICENSE file in the project root for more information. using System.ComponentModel; +using System.Diagnostics; using System.Runtime.InteropServices; using System.Security.Principal; using Microsoft.Win32.SafeHandles; +using Xunit; namespace System { - public static partial class AdminHelpers + public static class AdminHelpers { /// - /// Returns true if the current process is elevated (in Windows). + /// Runs the given command as sudo (for Unix). /// + /// The command line to run as sudo + /// Returns the process exit code (0 typically means it is successful) + public static int RunAsSudo(string commandLine) + { + ProcessStartInfo startInfo = new ProcessStartInfo() + { + FileName = "sudo", + Arguments = commandLine + }; + + using (Process process = Process.Start(startInfo)) + { + Assert.True(process.WaitForExit(30000)); + return process.ExitCode; + } + } + public unsafe static bool IsProcessElevated() { + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + uint userId = Interop.Sys.GetEUid(); + return(userId == 0); + } + IntPtr processHandle = Interop.Kernel32.GetCurrentProcess(); SafeAccessTokenHandle token; if (!Interop.Advapi32.OpenProcessToken(processHandle, TokenAccessLevels.Read, out token)) @@ -39,6 +64,5 @@ namespace System return elevation.TokenIsElevated != Interop.BOOL.FALSE; } } - } } diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/System/AssertExtensions.cs b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/AssertExtensions.cs similarity index 100% rename from src/libraries/CoreFx.Private.TestUtilities/src/System/AssertExtensions.cs rename to src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/AssertExtensions.cs diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/System/Buffers/BoundedMemory.Creation.cs b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/Buffers/BoundedMemory.Creation.cs similarity index 88% rename from src/libraries/CoreFx.Private.TestUtilities/src/System/Buffers/BoundedMemory.Creation.cs rename to src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/Buffers/BoundedMemory.Creation.cs index 22a7d14..a31af0e 100644 --- a/src/libraries/CoreFx.Private.TestUtilities/src/System/Buffers/BoundedMemory.Creation.cs +++ b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/Buffers/BoundedMemory.Creation.cs @@ -76,5 +76,17 @@ namespace System.Buffers buffer[i] = (byte)random.Next(); } } + + private static BoundedMemory AllocateWithoutDataPopulation(int elementCount, PoisonPagePlacement placement) where T : unmanaged + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return AllocateWithoutDataPopulationWindows(elementCount, placement); + } + else + { + return AllocateWithoutDataPopulationUnix(elementCount, placement); + } + } } } diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/System/Buffers/BoundedMemory.Unix.cs b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/Buffers/BoundedMemory.Unix.cs similarity index 93% rename from src/libraries/CoreFx.Private.TestUtilities/src/System/Buffers/BoundedMemory.Unix.cs rename to src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/Buffers/BoundedMemory.Unix.cs index aa9d87a..11049e8 100644 --- a/src/libraries/CoreFx.Private.TestUtilities/src/System/Buffers/BoundedMemory.Unix.cs +++ b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/Buffers/BoundedMemory.Unix.cs @@ -6,10 +6,9 @@ namespace System.Buffers { public static partial class BoundedMemory { - private static UnixImplementation AllocateWithoutDataPopulation(int elementCount, PoisonPagePlacement placement) where T : unmanaged + private static UnixImplementation AllocateWithoutDataPopulationUnix(int elementCount, PoisonPagePlacement placement) where T : unmanaged { // On non-Windows platforms, we don't yet have support for changing the permissions of individual pages. - return new UnixImplementation(elementCount); } diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/System/Buffers/BoundedMemory.Windows.cs b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/Buffers/BoundedMemory.Windows.cs similarity index 99% rename from src/libraries/CoreFx.Private.TestUtilities/src/System/Buffers/BoundedMemory.Windows.cs rename to src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/Buffers/BoundedMemory.Windows.cs index d60df68..5de8ebe 100644 --- a/src/libraries/CoreFx.Private.TestUtilities/src/System/Buffers/BoundedMemory.Windows.cs +++ b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/Buffers/BoundedMemory.Windows.cs @@ -13,7 +13,7 @@ namespace System.Buffers { private static readonly int SystemPageSize = Environment.SystemPageSize; - private static WindowsImplementation AllocateWithoutDataPopulation(int elementCount, PoisonPagePlacement placement) where T : unmanaged + private static WindowsImplementation AllocateWithoutDataPopulationWindows(int elementCount, PoisonPagePlacement placement) where T : unmanaged { long cb, totalBytesToAllocate; checked diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/System/Buffers/BoundedMemory.cs b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/Buffers/BoundedMemory.cs similarity index 100% rename from src/libraries/CoreFx.Private.TestUtilities/src/System/Buffers/BoundedMemory.cs rename to src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/Buffers/BoundedMemory.cs diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/System/Buffers/PoisonPagePlacement.cs b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/Buffers/PoisonPagePlacement.cs similarity index 100% rename from src/libraries/CoreFx.Private.TestUtilities/src/System/Buffers/PoisonPagePlacement.cs rename to src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/Buffers/PoisonPagePlacement.cs diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/System/IO/FileCleanupTestBase.cs b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/IO/FileCleanupTestBase.cs similarity index 100% rename from src/libraries/CoreFx.Private.TestUtilities/src/System/IO/FileCleanupTestBase.cs rename to src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/IO/FileCleanupTestBase.cs diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.Unix.cs b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/PlatformDetection.Unix.cs similarity index 66% rename from src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.Unix.cs rename to src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/PlatformDetection.Unix.cs index bbcf9f5..19d5627 100644 --- a/src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.Unix.cs +++ b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/PlatformDetection.Unix.cs @@ -4,35 +4,27 @@ using System.Diagnostics; using System.IO; -using System.Xml.Linq; using System.Runtime.InteropServices; using System.Text; +using System.Xml.Linq; using Xunit; namespace System { public static partial class PlatformDetection { - public static bool IsWindowsIoTCore => false; - public static bool IsWindowsHomeEdition => false; - public static bool IsWindows => false; - public static bool IsWindows7 => false; - public static bool IsWindows8x => false; - public static bool IsWindows8xOrLater => false; - public static bool IsWindows10Version1607OrGreater => false; - public static bool IsWindows10Version1703OrGreater => false; - public static bool IsWindows10Version1709OrGreater => false; - public static bool IsWindows10Version1803OrGreater => false; - public static bool IsWindows10Version1903OrGreater => false; - public static bool IsNotOneCoreUAP => true; - public static bool IsInAppContainer => false; - public static int WindowsVersion => -1; + // + // Do not use the " { get; } = " pattern here. Having all the initialization happen in the type initializer + // means that one exception anywhere means all tests using PlatformDetection fail. If you feel a value is worth latching, + // do it in a way that failures don't cascade. + // + private static bool IsLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); public static bool IsCentos6 => IsDistroAndVersion("centos", 6); - public static bool IsAlpine => IsDistroAndVersion("alpine"); public static bool IsOpenSUSE => IsDistroAndVersion("opensuse"); public static bool IsUbuntu => IsDistroAndVersion("ubuntu"); public static bool IsDebian => IsDistroAndVersion("debian"); + public static bool IsAlpine => IsDistroAndVersion("alpine"); public static bool IsDebian8 => IsDistroAndVersion("debian", 8); public static bool IsUbuntu1404 => IsDistroAndVersion("ubuntu", 14, 4); public static bool IsUbuntu1604 => IsDistroAndVersion("ubuntu", 16, 4); @@ -43,10 +35,18 @@ namespace System public static bool IsUbuntu1810OrHigher => IsDistroAndVersionOrHigher("ubuntu", 18, 10); public static bool IsTizen => IsDistroAndVersion("tizen"); public static bool IsFedora => IsDistroAndVersion("fedora"); - public static bool IsWindowsNanoServer => false; - public static bool IsWindowsServerCore => false; - public static bool IsWindowsAndElevated => false; - + + // OSX family + public static bool IsOSX => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); + public static bool IsNotOSX => !IsOSX; + public static Version OSXVersion => IsOSX ? + ToVersion(Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystemVersion) : + throw new PlatformNotSupportedException(); + private static Lazy m_osxProductVersion = new Lazy(GetOSXProductVersion); + public static bool IsMacOsHighSierraOrHigher => IsOSX && (m_osxProductVersion.Value.Major > 10 || (m_osxProductVersion.Value.Major == 10 && m_osxProductVersion.Value.Minor >= 13)); + public static bool IsNotMacOsHighSierraOrHigher => !IsMacOsHighSierraOrHigher; + public static bool IsMacOsMojaveOrHigher => IsOSX && (m_osxProductVersion.Value.Major > 10 || (m_osxProductVersion.Value.Major == 10 && m_osxProductVersion.Value.Minor >= 14)); + // RedHat family covers RedHat and CentOS public static bool IsRedHatFamily => IsRedHatFamilyAndVersion(); public static bool IsNotRedHatFamily => !IsRedHatFamily; @@ -55,47 +55,16 @@ namespace System public static bool IsRedHatFamily7 => IsRedHatFamilyAndVersion(7); public static bool IsNotFedoraOrRedHatFamily => !IsFedora && !IsRedHatFamily; - public static bool TargetsNetFx452OrLower => false; - public static bool IsNetfx462OrNewer => false; - public static bool IsNetfx470OrNewer => false; - public static bool IsNetfx471OrNewer => false; - public static bool IsNetfx472OrNewer => false; - - public static bool SupportsSsl3 => (PlatformDetection.IsOSX || (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && PlatformDetection.OpenSslVersion < new Version(1, 0, 2) && !PlatformDetection.IsDebian)); - - public static bool IsDrawingSupported { get; } = - RuntimeInformation.IsOSPlatform(OSPlatform.OSX) -#if netcoreapp20 - ? dlopen("libgdiplus.dylib", RTLD_LAZY) != IntPtr.Zero - : dlopen("libgdiplus.so", RTLD_LAZY) != IntPtr.Zero || dlopen("libgdiplus.so.0", RTLD_LAZY) != IntPtr.Zero; - - [DllImport("libdl")] - private static extern IntPtr dlopen(string libName, int flags); - private const int RTLD_LAZY = 0x001; -#else // use managed NativeLibrary API from .NET Core 3 onwards - ? NativeLibrary.TryLoad("libgdiplus.dylib", out _) - : NativeLibrary.TryLoad("libgdiplus.so", out _) || NativeLibrary.TryLoad("libgdiplus.so.0", out _); -#endif - - public static bool IsInContainer => RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && File.Exists("/.dockerenv"); - - public static bool IsSoundPlaySupported { get; } = false; - - public static Version OSXVersion { get; } = ToVersion(PlatformApis.GetOSVersion()); + private static Lazy m_icuVersion = new Lazy(GetICUVersion); + public static Version ICUVersion => m_icuVersion.Value; - public static Version OpenSslVersion => !RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? GetOpenSslVersion() : throw new PlatformNotSupportedException(); + public static bool IsSuperUser => !IsWindows ? + libc.geteuid() == 0 : + throw new PlatformNotSupportedException(); - public static string GetDistroVersionString() - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - { - return "OSX Version=" + s_osxProductVersion.ToString(); - } - - var (name, version) = GetDistroInfo(); - - return "Distro=" + name + " VersionId=" + version; - } + public static Version OpenSslVersion => !IsOSX && !IsWindows ? + GetOpenSslVersion() : + throw new PlatformNotSupportedException(); /// /// If gnulibc is available, returns the release, such as "stable". @@ -105,9 +74,14 @@ namespace System { get { + if (IsWindows) + { + return "glibc_not_found"; + } + try { - return Marshal.PtrToStringUTF8(gnu_get_libc_release()); + return Marshal.PtrToStringAnsi(libc.gnu_get_libc_release()); } catch (Exception e) when (e is DllNotFoundException || e is EntryPointNotFoundException) { @@ -124,9 +98,14 @@ namespace System { get { + if (IsWindows) + { + return "glibc_not_found"; + } + try { - return Marshal.PtrToStringUTF8(gnu_get_libc_version()); + return Marshal.PtrToStringAnsi(libc.gnu_get_libc_version()); } catch (Exception e) when (e is DllNotFoundException || e is EntryPointNotFoundException) { @@ -135,28 +114,105 @@ namespace System } } - private static readonly Version s_osxProductVersion = GetOSXProductVersion(); + private static Version GetICUVersion() + { + if (IsWindows) + { + return new Version(0, 0, 0, 0); + } + else + { + int ver = libc.GlobalizationNative_GetICUVersion(); + return new Version( ver & 0xFF, + (ver >> 8) & 0xFF, + (ver >> 16) & 0xFF, + ver >> 24); + } + } - public static bool IsMacOsHighSierraOrHigher { get; } = - IsOSX && (s_osxProductVersion.Major > 10 || (s_osxProductVersion.Major == 10 && s_osxProductVersion.Minor >= 13)); + private static Version GetOSXProductVersion() + { + if (IsOSX) + { + try + { + // + // + // ProductBuildVersion + // 17A330h + // ProductCopyright + // 1983-2017 Apple Inc. + // ProductName + // Mac OS X + // ProductUserVisibleVersion + // 10.13 + // ProductVersion + // 10.13 + // + // - public static bool IsMacOsMojaveOrHigher { get; } = - IsOSX && (s_osxProductVersion.Major > 10 || (s_osxProductVersion.Major == 10 && s_osxProductVersion.Minor >= 14)); + XElement dict = XDocument.Load("/System/Library/CoreServices/SystemVersion.plist").Root.Element("dict"); + if (dict != null) + { + foreach (XElement key in dict.Elements("key")) + { + if ("ProductVersion".Equals(key.Value)) + { + XElement stringElement = key.NextNode as XElement; + if (stringElement != null && stringElement.Name.LocalName.Equals("string")) + { + string versionString = stringElement.Value; + if (versionString != null) + { + return Version.Parse(versionString); + } + } + } + } + } + } + catch + { + } + } - private static readonly Version s_icuVersion = GetICUVersion(); - public static Version ICUVersion => s_icuVersion; + // In case of exception, couldn't get the version or non osx + return new Version(0, 0, 0); + } - private static Version GetICUVersion() + private static Version s_opensslVersion; + private static Version GetOpenSslVersion() { - int ver = GlobalizationNative_GetICUVersion(); - return new Version( ver & 0xFF, - (ver >> 8) & 0xFF, - (ver >> 16) & 0xFF, - ver >> 24); + if (s_opensslVersion == null) + { + // OpenSSL version numbers are encoded as + // 0xMNNFFPPS: major (one nybble), minor (one byte, unaligned), + // "fix" (one byte, unaligned), patch (one byte, unaligned), status (one nybble) + // + // e.g. 1.0.2a final is 0x1000201F + // + // Currently they don't exceed 29-bit values, but we use long here to account + // for the expanded range on their 64-bit C-long return value. + long versionNumber = Interop.OpenSsl.OpenSslVersionNumber(); + int major = (int)((versionNumber >> 28) & 0xF); + int minor = (int)((versionNumber >> 20) & 0xFF); + int fix = (int)((versionNumber >> 12) & 0xFF); + + s_opensslVersion = new Version(major, minor, fix); + } + + return s_opensslVersion; } - static Version ToVersion(string versionString) + private static Version ToVersion(string versionString) { + // In some distros/versions we cannot discover the distro version; return something valid. + // Pick a high version number, since this seems to happen on newer distros. + if (string.IsNullOrEmpty(versionString)) + { + versionString = new Version(Int32.MaxValue, Int32.MaxValue).ToString(); + } + try { if (versionString.IndexOf('.') != -1) @@ -172,8 +228,11 @@ namespace System } } - private static (string name, Version version) GetDistroInfo() => - (PlatformApis.GetOSName(), ToVersion(PlatformApis.GetOSVersion())); + private static DistroInfo GetDistroInfo() => new DistroInfo() + { + Id = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystem, + VersionId = ToVersion(Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystemVersion) + }; private static bool IsRedHatFamilyAndVersion(int major = -1, int minor = -1, int build = -1, int revision = -1) { @@ -210,10 +269,10 @@ namespace System private static bool IsDistroAndVersion(Predicate distroPredicate, int major = -1, int minor = -1, int build = -1, int revision = -1) { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + if (IsLinux) { - var (name, version) = GetDistroInfo(); - if (distroPredicate(name) && VersionEquivalentTo(major, minor, build, revision, version)) + DistroInfo v = GetDistroInfo(); + if (distroPredicate(v.Id) && VersionEquivalentTo(major, minor, build, revision, v.VersionId)) { return true; } @@ -224,10 +283,10 @@ namespace System private static bool IsDistroAndVersionOrHigher(Predicate distroPredicate, int major = -1, int minor = -1, int build = -1, int revision = -1) { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + if (IsLinux) { - var (name, version) = GetDistroInfo(); - if (distroPredicate(name) && VersionEquivalentToOrHigher(major, minor, build, revision, version)) + DistroInfo v = GetDistroInfo(); + if (distroPredicate(v.Id) && VersionEquivalentToOrHigher(major, minor, build, revision, v.VersionId)) { return true; } @@ -255,95 +314,25 @@ namespace System (actualVersionId.Revision == revision)))))))); } - private static Version GetOSXProductVersion() + private struct DistroInfo { - try - { - if (IsOSX) - { - // - // - // ProductBuildVersion - // 17A330h - // ProductCopyright - // 1983-2017 Apple Inc. - // ProductName - // Mac OS X - // ProductUserVisibleVersion - // 10.13 - // ProductVersion - // 10.13 - // - // - - XElement dict = XDocument.Load("/System/Library/CoreServices/SystemVersion.plist").Root.Element("dict"); - if (dict != null) - { - foreach (XElement key in dict.Elements("key")) - { - if ("ProductVersion".Equals(key.Value)) - { - XElement stringElement = key.NextNode as XElement; - if (stringElement != null && stringElement.Name.LocalName.Equals("string")) - { - string versionString = stringElement.Value; - if (versionString != null) - { - return Version.Parse(versionString); - } - } - } - } - } - } - } - catch - { - } - - // In case of exception or couldn't get the version - return new Version(0, 0, 0); + public string Id { get; set; } + public Version VersionId { get; set; } } - private static Version s_opensslVersion; - private static Version GetOpenSslVersion() + private static class libc { - if (s_opensslVersion == null) - { - // OpenSSL version numbers are encoded as - // 0xMNNFFPPS: major (one nybble), minor (one byte, unaligned), - // "fix" (one byte, unaligned), patch (one byte, unaligned), status (one nybble) - // - // e.g. 1.0.2a final is 0x1000201F - // - // Currently they don't exceed 29-bit values, but we use long here to account - // for the expanded range on their 64-bit C-long return value. - long versionNumber = Interop.OpenSsl.OpenSslVersionNumber(); - int major = (int)((versionNumber >> 28) & 0xF); - int minor = (int)((versionNumber >> 20) & 0xFF); - int fix = (int)((versionNumber >> 12) & 0xFF); + [DllImport("libc", SetLastError = true)] + public static extern unsafe uint geteuid(); - s_opensslVersion = new Version(major, minor, fix); - } - - return s_opensslVersion; - } + [DllImport("libc", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr gnu_get_libc_release(); - [DllImport("libc", SetLastError = true)] - private static extern int sysctlbyname(string ctlName, byte[] oldp, ref IntPtr oldpLen, byte[] newp, IntPtr newpLen); + [DllImport("libc", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr gnu_get_libc_version(); - [DllImport("libc", SetLastError = true)] - internal static extern unsafe uint geteuid(); - - [DllImport("libc", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr gnu_get_libc_release(); - - [DllImport("libc", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr gnu_get_libc_version(); - - [DllImport("System.Globalization.Native", SetLastError = true)] - private static extern int GlobalizationNative_GetICUVersion(); - - public static bool IsSuperUser => geteuid() == 0; + [DllImport("System.Globalization.Native", SetLastError = true)] + public static extern int GlobalizationNative_GetICUVersion(); + } } } diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.Windows.cs b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/PlatformDetection.Windows.cs similarity index 64% rename from src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.Windows.cs rename to src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/PlatformDetection.Windows.cs index d7f9ce8..5b1ac03 100644 --- a/src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.Windows.cs +++ b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/PlatformDetection.Windows.cs @@ -2,82 +2,78 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Win32; using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; +using System.Runtime.Versioning; using System.Security; using System.Text; +using Microsoft.Win32; using Xunit; namespace System { public static partial class PlatformDetection { - public static Version OSXVersion => throw new PlatformNotSupportedException(); - public static Version OpenSslVersion => throw new PlatformNotSupportedException(); - public static bool IsDrawingSupported => IsNotWindowsNanoServer && IsNotWindowsServerCore && !IsUap; - public static bool IsSoundPlaySupported => IsNotWindowsNanoServer; - public static bool IsSuperUser => throw new PlatformNotSupportedException(); - public static bool IsCentos6 => false; - public static bool IsOpenSUSE => false; - public static bool IsUbuntu => false; - public static bool IsDebian => false; - public static bool IsAlpine => false; - public static bool IsDebian8 => false; - public static bool IsUbuntu1404 => false; - public static bool IsUbuntu1604 => false; - public static bool IsUbuntu1704 => false; - public static bool IsUbuntu1710 => false; - public static bool IsUbuntu1710OrHigher => false; - public static bool IsUbuntu1804 => false; - public static bool IsUbuntu1810OrHigher => false; - public static bool IsTizen => false; - public static bool IsNotFedoraOrRedHatFamily => true; - public static bool IsFedora => false; - public static bool IsWindowsNanoServer => (IsNotWindowsIoTCore && GetInstallationType().Equals("Nano Server", StringComparison.OrdinalIgnoreCase)); - public static bool IsWindowsServerCore => GetInstallationType().Equals("Server Core", StringComparison.OrdinalIgnoreCase); - public static int WindowsVersion => (int)GetWindowsVersion(); - public static bool IsMacOsHighSierraOrHigher { get; } = false; - public static bool IsMacOsMojaveOrHigher { get; } = false; - public static Version ICUVersion => new Version(0, 0, 0, 0); - public static bool IsRedHatFamily => false; - public static bool IsNotRedHatFamily => true; - public static bool IsRedHatFamily6 => false; - public static bool IsRedHatFamily7 => false; - public static bool IsNotRedHatFamily6 => true; - public static bool IsInContainer => !String.IsNullOrEmpty(GetContainerType()); - - public static bool SupportsSsl3 => GetSsl3Support(); + // + // Do not use the " { get; } = " pattern here. Having all the initialization happen in the type initializer + // means that one exception anywhere means all tests using PlatformDetection fail. If you feel a value is worth latching, + // do it in a way that failures don't cascade. + // + + public static bool IsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + public static bool IsUap => IsInAppContainer; + public static bool IsFullFramework => RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework", StringComparison.OrdinalIgnoreCase); + public static bool HasWindowsShell => IsWindows && IsNotWindowsServerCore && IsNotWindowsNanoServer && IsNotWindowsIoTCore; + public static bool IsWindows7 => IsWindows && GetWindowsVersion() == 6 && GetWindowsMinorVersion() == 1; + public static bool IsWindows8x => IsWindows && GetWindowsVersion() == 6 && (GetWindowsMinorVersion() == 2 || GetWindowsMinorVersion() == 3); + public static bool IsWindows8xOrLater => IsWindows && new Version((int)GetWindowsVersion(), (int)GetWindowsMinorVersion()) >= new Version(6, 2); + public static bool IsWindowsNanoServer => IsWindows && (IsNotWindowsIoTCore && GetWindowsInstallationType().Equals("Nano Server", StringComparison.OrdinalIgnoreCase)); + public static bool IsWindowsServerCore => IsWindows && GetWindowsInstallationType().Equals("Server Core", StringComparison.OrdinalIgnoreCase); + public static int WindowsVersion => IsWindows ? (int)GetWindowsVersion() : -1; + public static bool IsNotWindows8x => !IsWindows8x; + public static bool IsNotWindowsNanoServer => !IsWindowsNanoServer; + public static bool IsNotWindowsServerCore => !IsWindowsServerCore; + public static bool IsNotWindowsIoTCore => !IsWindowsIoTCore; + public static bool IsNotWindowsHomeEdition => !IsWindowsHomeEdition; + public static bool IsNotInAppContainer => !IsInAppContainer; + public static bool IsWinRTSupported => IsWindows && !IsWindows7; + public static bool IsNotWinRTSupported => !IsWinRTSupported; + public static bool IsSoundPlaySupported => IsWindows && IsNotWindowsNanoServer; // >= Windows 10 Anniversary Update - public static bool IsWindows10Version1607OrGreater => + public static bool IsWindows10Version1607OrGreater => IsWindows && GetWindowsVersion() == 10 && GetWindowsMinorVersion() == 0 && GetWindowsBuildNumber() >= 14393; // >= Windows 10 Creators Update - public static bool IsWindows10Version1703OrGreater => + public static bool IsWindows10Version1703OrGreater => IsWindows && GetWindowsVersion() == 10 && GetWindowsMinorVersion() == 0 && GetWindowsBuildNumber() >= 15063; // >= Windows 10 Fall Creators Update - public static bool IsWindows10Version1709OrGreater => + public static bool IsWindows10Version1709OrGreater => IsWindows && GetWindowsVersion() == 10 && GetWindowsMinorVersion() == 0 && GetWindowsBuildNumber() >= 16299; // >= Windows 10 April 2018 Update - public static bool IsWindows10Version1803OrGreater => + public static bool IsWindows10Version1803OrGreater => IsWindows && GetWindowsVersion() == 10 && GetWindowsMinorVersion() == 0 && GetWindowsBuildNumber() >= 17134; // >= Windows 10 May 2019 Update (19H1) - public static bool IsWindows10Version1903OrGreater => + public static bool IsWindows10Version1903OrGreater => IsWindows && GetWindowsVersion() == 10 && GetWindowsMinorVersion() == 0 && GetWindowsBuildNumber() >= 18362; // Windows OneCoreUAP SKU doesn't have httpapi.dll - public static bool IsNotOneCoreUAP => + public static bool IsNotOneCoreUAP => !IsWindows || File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "System32", "httpapi.dll")); public static bool IsWindowsIoTCore { get { + if (!IsWindows) + { + return false; + } + int productType = GetWindowsProductType(); if ((productType == PRODUCT_IOTUAPCOMMERCIAL) || (productType == PRODUCT_IOTUAP)) @@ -92,6 +88,11 @@ namespace System { get { + if (!IsWindows) + { + return false; + } + int productType = GetWindowsProductType(); switch (productType) { @@ -110,18 +111,92 @@ namespace System } } - public static bool IsWindows => true; - public static bool IsWindows7 => GetWindowsVersion() == 6 && GetWindowsMinorVersion() == 1; - public static bool IsWindows8x => GetWindowsVersion() == 6 && (GetWindowsMinorVersion() == 2 || GetWindowsMinorVersion() == 3); - public static bool IsWindows8xOrLater => new Version((int)GetWindowsVersion(), (int)GetWindowsMinorVersion()) >= new Version(6, 2); + public static bool IsWindowsSubsystemForLinux => m_isWindowsSubsystemForLinux.Value; + public static bool IsNotWindowsSubsystemForLinux => !IsWindowsSubsystemForLinux; - public static string LibcRelease => "glibc_not_found"; - public static string LibcVersion => "glibc_not_found"; + private static Lazy m_isWindowsSubsystemForLinux = new Lazy(GetIsWindowsSubsystemForLinux); + private static bool GetIsWindowsSubsystemForLinux() + { + // https://github.com/Microsoft/BashOnWindows/issues/423#issuecomment-221627364 + if (IsLinux) + { + const string versionFile = "/proc/version"; + if (File.Exists(versionFile)) + { + string s = File.ReadAllText(versionFile); - public static string GetDistroVersionString() { return "WindowsProductType=" + GetWindowsProductType() + " WindowsInstallationType=" + GetInstallationType(); } + if (s.Contains("Microsoft") || s.Contains("WSL")) + { + return true; + } + } + } - private static int s_isInAppContainer = -1; + return false; + } + + private static string GetWindowsInstallationType() + { + string key = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion"; + string value = ""; + + try + { + value = (string)Registry.GetValue(key, "InstallationType", defaultValue: ""); + } + catch (Exception e) when (e is SecurityException || e is InvalidCastException || e is PlatformNotSupportedException /* UAP */) + { + } + + return value; + } + + private static int GetWindowsProductType() + { + Assert.True(GetProductInfo(Environment.OSVersion.Version.Major, Environment.OSVersion.Version.Minor, 0, 0, out int productType)); + return productType; + } + private const int PRODUCT_IOTUAP = 0x0000007B; + private const int PRODUCT_IOTUAPCOMMERCIAL = 0x00000083; + private const int PRODUCT_CORE = 0x00000065; + private const int PRODUCT_CORE_COUNTRYSPECIFIC = 0x00000063; + private const int PRODUCT_CORE_N = 0x00000062; + private const int PRODUCT_CORE_SINGLELANGUAGE = 0x00000064; + private const int PRODUCT_HOME_BASIC = 0x00000002; + private const int PRODUCT_HOME_BASIC_N = 0x00000005; + private const int PRODUCT_HOME_PREMIUM = 0x00000003; + private const int PRODUCT_HOME_PREMIUM_N = 0x0000001A; + + [DllImport("kernel32.dll", SetLastError = false)] + private static extern bool GetProductInfo( + int dwOSMajorVersion, + int dwOSMinorVersion, + int dwSpMajorVersion, + int dwSpMinorVersion, + out int pdwReturnedProductType + ); + + [DllImport("kernel32.dll", ExactSpelling = true)] + private static extern int GetCurrentApplicationUserModelId(ref uint applicationUserModelIdLength, byte[] applicationUserModelId); + + internal static uint GetWindowsVersion() + { + Assert.Equal(0, Interop.NtDll.RtlGetVersionEx(out Interop.NtDll.RTL_OSVERSIONINFOEX osvi)); + return osvi.dwMajorVersion; + } + internal static uint GetWindowsMinorVersion() + { + Assert.Equal(0, Interop.NtDll.RtlGetVersionEx(out Interop.NtDll.RTL_OSVERSIONINFOEX osvi)); + return osvi.dwMinorVersion; + } + internal static uint GetWindowsBuildNumber() + { + Assert.Equal(0, Interop.NtDll.RtlGetVersionEx(out Interop.NtDll.RTL_OSVERSIONINFOEX osvi)); + return osvi.dwBuildNumber; + } + + private static int s_isInAppContainer = -1; public static bool IsInAppContainer { // This actually checks whether code is running in a modern app. @@ -181,7 +256,6 @@ namespace System } private static int s_isWindowsElevated = -1; - public static bool IsWindowsAndElevated { get @@ -200,104 +274,5 @@ namespace System return s_isWindowsElevated == 1; } } - - private static string GetInstallationType() - { - string key = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion"; - string value = ""; - - try - { - value = (string)Registry.GetValue(key, "InstallationType", defaultValue: ""); - } - catch (Exception e) when (e is SecurityException || e is InvalidCastException || e is PlatformNotSupportedException /* UAP */) - { - } - - return value; - } - - private static bool GetSsl3Support() - { - string clientKey = @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 3.0\Client"; - string serverKey = @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 3.0\Server"; - bool enabled = true; - - // This may change in future but for now, missing key means protocol is enabled. - try - { - if ((int)Registry.GetValue(clientKey, "Enabled", 1) == 0 || (int)Registry.GetValue(serverKey, "Enabled", 1) == 0) - { - enabled = false; - } - } - catch (Exception e) when (e is SecurityException || e is InvalidCastException || e is NullReferenceException) - { - } - - return enabled; - } - - private static int GetWindowsProductType() - { - Assert.True(GetProductInfo(Environment.OSVersion.Version.Major, Environment.OSVersion.Version.Minor, 0, 0, out int productType)); - return productType; - } - - private static string GetContainerType() - { - string key = @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control"; - string value = ""; - - try - { - value = (string)Registry.GetValue(key, "ContainerType", defaultValue: ""); - } - catch - { - } - - return value; - } - - private const int PRODUCT_IOTUAP = 0x0000007B; - private const int PRODUCT_IOTUAPCOMMERCIAL = 0x00000083; - private const int PRODUCT_CORE = 0x00000065; - private const int PRODUCT_CORE_COUNTRYSPECIFIC = 0x00000063; - private const int PRODUCT_CORE_N = 0x00000062; - private const int PRODUCT_CORE_SINGLELANGUAGE = 0x00000064; - private const int PRODUCT_HOME_BASIC = 0x00000002; - private const int PRODUCT_HOME_BASIC_N = 0x00000005; - private const int PRODUCT_HOME_PREMIUM = 0x00000003; - private const int PRODUCT_HOME_PREMIUM_N = 0x0000001A; - - [DllImport("kernel32.dll", SetLastError = false)] - private static extern bool GetProductInfo( - int dwOSMajorVersion, - int dwOSMinorVersion, - int dwSpMajorVersion, - int dwSpMinorVersion, - out int pdwReturnedProductType - ); - - - [DllImport("kernel32.dll", ExactSpelling = true)] - private static extern int GetCurrentApplicationUserModelId(ref uint applicationUserModelIdLength, byte[] applicationUserModelId); - - internal static uint GetWindowsVersion() - { - Assert.Equal(0, Interop.NtDll.RtlGetVersionEx(out Interop.NtDll.RTL_OSVERSIONINFOEX osvi)); - return osvi.dwMajorVersion; - } - internal static uint GetWindowsMinorVersion() - { - Assert.Equal(0, Interop.NtDll.RtlGetVersionEx(out Interop.NtDll.RTL_OSVERSIONINFOEX osvi)); - return osvi.dwMinorVersion; - } - internal static uint GetWindowsBuildNumber() - { - Assert.Equal(0, Interop.NtDll.RtlGetVersionEx(out Interop.NtDll.RTL_OSVERSIONINFOEX osvi)); - return osvi.dwBuildNumber; - } } } diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.cs b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/PlatformDetection.cs similarity index 58% rename from src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.cs rename to src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/PlatformDetection.cs index 2b2776c..722b826 100644 --- a/src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.cs +++ b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/PlatformDetection.cs @@ -4,9 +4,11 @@ using System.Diagnostics; using System.IO; +using System.Security; using System.Runtime.InteropServices; using System.Text; using System.Runtime.CompilerServices; +using Microsoft.Win32; using Xunit; namespace System @@ -19,20 +21,11 @@ namespace System // do it in a way that failures don't cascade. // - public static bool HasWindowsShell => IsWindows && IsNotWindowsServerCore && IsNotWindowsNanoServer && IsNotWindowsIoTCore; - public static bool IsUap => IsInAppContainer; - public static bool IsFullFramework => RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework", StringComparison.OrdinalIgnoreCase); public static bool IsNetCore => RuntimeInformation.FrameworkDescription.StartsWith(".NET Core", StringComparison.OrdinalIgnoreCase); public static bool IsMonoRuntime => Type.GetType("Mono.RuntimeStructs") != null; - public static bool IsOSX => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); - public static bool IsNotOSX => !IsOSX; public static bool IsFreeBSD => RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")); public static bool IsNetBSD => RuntimeInformation.IsOSPlatform(OSPlatform.Create("NETBSD")); - public static bool IsNotWindows8x => !IsWindows8x; - public static bool IsNotWindowsNanoServer => !IsWindowsNanoServer; - public static bool IsNotWindowsServerCore => !IsWindowsServerCore; - public static bool IsNotWindowsIoTCore => !IsWindowsIoTCore; - public static bool IsNotWindowsHomeEdition => !IsWindowsHomeEdition; + public static bool IsArmProcess => RuntimeInformation.ProcessArchitecture == Architecture.Arm; public static bool IsNotArmProcess => !IsArmProcess; public static bool IsArm64Process => RuntimeInformation.ProcessArchitecture == Architecture.Arm64; @@ -43,49 +36,83 @@ namespace System public static bool IsArgIteratorNotSupported => !IsArgIteratorSupported; public static bool Is32BitProcess => IntPtr.Size == 4; - public static bool IsNotInAppContainer => !IsInAppContainer; - public static bool IsWinRTSupported => IsWindows && !IsWindows7; - public static bool IsNotWinRTSupported => !IsWinRTSupported; - public static bool IsNotMacOsHighSierraOrHigher => !IsMacOsHighSierraOrHigher; + // Windows 10 Insider Preview Build 16215 introduced the necessary APIs for the UAP version of + // ClientWebSocket.ReceiveAsync to consume partial message data as it arrives, without having to wait + // for "end of message" to be signaled. + public static bool ClientWebSocketPartialMessagesSupported => !IsUap || IsWindows10Version1709OrGreater; - public static bool IsDomainJoinedMachine => !Environment.MachineName.Equals(Environment.UserDomainName, StringComparison.OrdinalIgnoreCase); + public static bool IsDrawingSupported + { + get + { +#if netcoreapp + if (IsWindows) + { +#endif + return IsNotWindowsNanoServer && IsNotWindowsServerCore && !IsUap; +#if netcoreapp + } + else if (IsOSX) + { + return NativeLibrary.TryLoad("libgdiplus.dylib", out _); + } + else + { + return NativeLibrary.TryLoad("libgdiplus.so", out _) || NativeLibrary.TryLoad("libgdiplus.so.0", out _); + } +#endif + } + } - // Windows - Schannel supports alpn from win8.1/2012 R2 and higher. - // Linux - OpenSsl supports alpn from openssl 1.0.2 and higher. - // OSX - SecureTransport doesn't expose alpn APIs. #30492 - public static bool SupportsAlpn => (IsWindows && !IsWindows7) || - ((!IsOSX && !IsWindows) && - (OpenSslVersion.Major >= 1 && (OpenSslVersion.Minor >= 1 || OpenSslVersion.Build >= 2))); - public static bool SupportsClientAlpn => SupportsAlpn || (IsOSX && PlatformDetection.OSXVersion > new Version(10, 12)); - // OpenSSL 1.1.1 and above. - public static bool SupportsTls13 => !IsWindows && !IsOSX && (OpenSslVersion.CompareTo(new Version(1,1,1)) >= 0); + public static bool IsInContainer => GetIsInContainer(); + public static bool SupportsSsl3 => GetSsl3Support(); + public static bool IsReflectionEmitSupported = true; + public static bool IsInvokingStaticConstructorsSupported => true; + + // System.Security.Cryptography.Xml.XmlDsigXsltTransform.GetOutput() relies on XslCompiledTransform which relies + // heavily on Reflection.Emit + public static bool IsXmlDsigXsltTransformSupported => !PlatformDetection.IsUap; - private static Lazy m_isWindowsSubsystemForLinux = new Lazy(GetIsWindowsSubsystemForLinux); + public static bool IsPreciseGcSupported => !IsMonoRuntime; - public static bool IsWindowsSubsystemForLinux => m_isWindowsSubsystemForLinux.Value; - public static bool IsNotWindowsSubsystemForLinux => !IsWindowsSubsystemForLinux; + public static bool IsNotIntMaxValueArrayIndexSupported => s_largeArrayIsNotSupported.Value; - private static bool GetIsWindowsSubsystemForLinux() + private static volatile Tuple s_lazyNonZeroLowerBoundArraySupported; + public static bool IsNonZeroLowerBoundArraySupported { - // https://github.com/Microsoft/BashOnWindows/issues/423#issuecomment-221627364 - - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + get { - const string versionFile = "/proc/version"; - if (File.Exists(versionFile)) + if (s_lazyNonZeroLowerBoundArraySupported == null) { - string s = File.ReadAllText(versionFile); - - if (s.Contains("Microsoft") || s.Contains("WSL")) + bool nonZeroLowerBoundArraysSupported = false; + try + { + Array.CreateInstance(typeof(int), new int[] { 5 }, new int[] { 5 }); + nonZeroLowerBoundArraysSupported = true; + } + catch (PlatformNotSupportedException) { - return true; } + s_lazyNonZeroLowerBoundArraySupported = Tuple.Create(nonZeroLowerBoundArraysSupported); } + return s_lazyNonZeroLowerBoundArraySupported.Item1; } - - return false; } + public static bool IsDomainJoinedMachine => !Environment.MachineName.Equals(Environment.UserDomainName, StringComparison.OrdinalIgnoreCase); + + // Windows - Schannel supports alpn from win8.1/2012 R2 and higher. + // Linux - OpenSsl supports alpn from openssl 1.0.2 and higher. + // OSX - SecureTransport doesn't expose alpn APIs. #30492 + public static bool SupportsAlpn => (IsWindows && !IsWindows7) || + ((!IsOSX && !IsWindows) && + (OpenSslVersion.Major >= 1 && (OpenSslVersion.Minor >= 1 || OpenSslVersion.Build >= 2))); + + public static bool SupportsClientAlpn => SupportsAlpn || (IsOSX && PlatformDetection.OSXVersion > new Version(10, 12)); + + // OpenSSL 1.1.1 and above. + public static bool SupportsTls13 => !IsWindows && !IsOSX && (OpenSslVersion.CompareTo(new Version(1,1,1)) >= 0); + private static Lazy s_largeArrayIsNotSupported = new Lazy(IsLargeArrayNotSupported); [MethodImpl(MethodImplOptions.NoOptimization)] @@ -102,39 +129,69 @@ namespace System } } - public static bool IsNotIntMaxValueArrayIndexSupported => s_largeArrayIsNotSupported.Value; + public static string GetDistroVersionString() + { + if (IsWindows) + { + return "WindowsProductType=" + GetWindowsProductType() + " WindowsInstallationType=" + GetWindowsInstallationType(); + } + else if (IsOSX) + { + return "OSX Version=" + m_osxProductVersion.Value.ToString(); + } + else + { + DistroInfo v = GetDistroInfo(); - public static bool IsNonZeroLowerBoundArraySupported + return $"Distro={v.Id} VersionId={v.VersionId}"; + } + } + + private static bool GetIsInContainer() { - get + if (IsWindows) { - if (s_lazyNonZeroLowerBoundArraySupported == null) + string key = @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control"; + string value = ""; + + try { - bool nonZeroLowerBoundArraysSupported = false; - try - { - Array.CreateInstance(typeof(int), new int[] { 5 }, new int[] { 5 }); - nonZeroLowerBoundArraysSupported = true; - } - catch (PlatformNotSupportedException) - { - } - s_lazyNonZeroLowerBoundArraySupported = Tuple.Create(nonZeroLowerBoundArraysSupported); + value = (string)Registry.GetValue(key, "ContainerType", defaultValue: ""); } - return s_lazyNonZeroLowerBoundArraySupported.Item1; + catch + { + } + + return !string.IsNullOrEmpty(value); } - } - private static volatile Tuple s_lazyNonZeroLowerBoundArraySupported; + return (IsLinux && File.Exists("/.dockerenv")); + } - public static bool IsReflectionEmitSupported = true; + private static bool GetSsl3Support() + { + if (IsWindows) + { + string clientKey = @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 3.0\Client"; + string serverKey = @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 3.0\Server"; + bool enabled = true; - public static bool IsInvokingStaticConstructorsSupported => true; + // This may change in future but for now, missing key means protocol is enabled. + try + { + if ((int)Registry.GetValue(clientKey, "Enabled", 1) == 0 || (int)Registry.GetValue(serverKey, "Enabled", 1) == 0) + { + enabled = false; + } + } + catch (Exception e) when (e is SecurityException || e is InvalidCastException || e is NullReferenceException) + { + } - // System.Security.Cryptography.Xml.XmlDsigXsltTransform.GetOutput() relies on XslCompiledTransform which relies - // heavily on Reflection.Emit - public static bool IsXmlDsigXsltTransformSupported => !PlatformDetection.IsUap; + return enabled; + } - public static bool IsPreciseGcSupported => !IsMonoRuntime; + return (IsOSX || (IsLinux && OpenSslVersion < new Version(1, 0, 2) && !IsDebian)); + } } } diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/System/RetryHelper.cs b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/RetryHelper.cs similarity index 98% rename from src/libraries/CoreFx.Private.TestUtilities/src/System/RetryHelper.cs rename to src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/RetryHelper.cs index 0308f11..92244c8 100644 --- a/src/libraries/CoreFx.Private.TestUtilities/src/System/RetryHelper.cs +++ b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/RetryHelper.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -88,4 +88,4 @@ namespace System } } } -} +} \ No newline at end of file diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/System/TestEnvironment.cs b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/TestEnvironment.cs similarity index 100% rename from src/libraries/CoreFx.Private.TestUtilities/src/System/TestEnvironment.cs rename to src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/TestEnvironment.cs diff --git a/src/libraries/Common/tests/StaticTestGenerator/Program.cs b/src/libraries/Common/tests/StaticTestGenerator/Program.cs index c1d31b1..48066a9 100644 --- a/src/libraries/Common/tests/StaticTestGenerator/Program.cs +++ b/src/libraries/Common/tests/StaticTestGenerator/Program.cs @@ -1129,7 +1129,6 @@ public static class Test #HelperAssemblyLocation#xunit.core.dll #HelperAssemblyLocation#xunit.assert.dll #HelperAssemblyLocation#xunit.abstractions.dll - #HelperAssemblyLocation#CoreFx.Private.TestUtilities.dll #HelperAssemblyLocation#System.Runtime.CompilerServices.Unsafe.dll #HelperAssemblyLocation#Microsoft.DotNet.XUnitExtensions.dll #TestAssemblyLocation# diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/EncryptDecrypt.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/EncryptDecrypt.cs index 01ed1a3..a0076ae 100644 --- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/EncryptDecrypt.cs +++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/EncryptDecrypt.cs @@ -28,7 +28,6 @@ namespace System.Security.Cryptography.Rsa.Tests public abstract class EncryptDecrypt { public static bool SupportsSha2Oaep => RSAFactory.SupportsSha2Oaep; - private static bool EphemeralKeysAreExportable => !PlatformDetection.IsFullFramework || PlatformDetection.IsNetfx462OrNewer; protected abstract byte[] Encrypt(RSA rsa, byte[] data, RSAEncryptionPadding padding); protected abstract byte[] Decrypt(RSA rsa, byte[] data, RSAEncryptionPadding padding); @@ -602,7 +601,7 @@ namespace System.Security.Cryptography.Rsa.Tests } } - [ConditionalFact(nameof(EphemeralKeysAreExportable))] + [Fact] public void RsaDecryptAfterExport() { byte[] output; diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/SignVerify.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/SignVerify.cs index 882911f..792b72d 100644 --- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/SignVerify.cs +++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/SignVerify.cs @@ -40,8 +40,6 @@ namespace System.Security.Cryptography.Rsa.Tests public abstract class SignVerify { public static bool SupportsPss => RSAFactory.SupportsPss; - public static bool BadKeyFormatDoesntThrow => !PlatformDetection.IsFullFramework || PlatformDetection.IsNetfx462OrNewer; - public static bool InvalidKeySizeDoesntThrow => !PlatformDetection.IsFullFramework || PlatformDetection.IsNetfx462OrNewer; protected abstract byte[] SignData(RSA rsa, byte[] data, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding); protected abstract byte[] SignHash(RSA rsa, byte[] hash, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding); @@ -143,7 +141,7 @@ namespace System.Security.Cryptography.Rsa.Tests } } - [ConditionalFact(nameof(InvalidKeySizeDoesntThrow))] + [Fact] public void ExpectedSignature_SHA1_384() { byte[] expectedSignature = @@ -174,7 +172,7 @@ namespace System.Security.Cryptography.Rsa.Tests } } - [ConditionalFact(nameof(InvalidKeySizeDoesntThrow))] + [Fact] public void ExpectedSignature_SHA1_1032() { byte[] expectedSignature = @@ -346,7 +344,7 @@ namespace System.Security.Cryptography.Rsa.Tests Assert.Equal(expectedSignature, signature); } - [ConditionalFact(nameof(InvalidKeySizeDoesntThrow))] + [Fact] public void VerifySignature_SHA1_384() { byte[] signature = @@ -362,7 +360,7 @@ namespace System.Security.Cryptography.Rsa.Tests VerifySignature(signature, TestData.HelloBytes, "SHA1", TestData.RSA384Parameters); } - [ConditionalFact(nameof(InvalidKeySizeDoesntThrow))] + [Fact] public void VerifySignature_SHA1_1032() { byte[] signature = @@ -558,7 +556,7 @@ namespace System.Security.Cryptography.Rsa.Tests } } - [ConditionalFact(nameof(BadKeyFormatDoesntThrow))] + [Fact] public void NegativeVerify_BadKeysize() { byte[] signature; diff --git a/src/libraries/CoreFx.Private.TestUtilities/CoreFx.Private.TestUtilities.sln b/src/libraries/CoreFx.Private.TestUtilities/CoreFx.Private.TestUtilities.sln deleted file mode 100644 index 2a0725b..0000000 --- a/src/libraries/CoreFx.Private.TestUtilities/CoreFx.Private.TestUtilities.sln +++ /dev/null @@ -1,53 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27213.1 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoreFx.Private.TestUtilities.Tests", "tests\CoreFx.Private.TestUtilities.Tests.csproj", "{5E0DB390-A45E-41BE-8304-B840327FE597}" - ProjectSection(ProjectDependencies) = postProject - {EBDB0247-CA43-4226-B7A1-8FEF21061D09} = {EBDB0247-CA43-4226-B7A1-8FEF21061D09} - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoreFx.Private.TestUtilities", "src\CoreFx.Private.TestUtilities.csproj", "{EBDB0247-CA43-4226-B7A1-8FEF21061D09}" - ProjectSection(ProjectDependencies) = postProject - {E2E59C98-998F-9965-991D-99411166AF6F} = {E2E59C98-998F-9965-991D-99411166AF6F} - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoreFx.Private.TestUtilities", "ref\CoreFx.Private.TestUtilities.csproj", "{E2E59C98-998F-9965-991D-99411166AF6F}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{1A2F9F4A-A032-433E-B914-ADD5992BB178}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E107E9C1-E893-4E87-987E-04EF0DCEAEFD}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{2E666815-2EDB-464B-9DF6-380BF4789AD4}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {5E0DB390-A45E-41BE-8304-B840327FE597}.Debug|Any CPU.ActiveCfg = netcoreapp-Debug|Any CPU - {5E0DB390-A45E-41BE-8304-B840327FE597}.Debug|Any CPU.Build.0 = netcoreapp-Debug|Any CPU - {5E0DB390-A45E-41BE-8304-B840327FE597}.Release|Any CPU.ActiveCfg = netcoreapp-Release|Any CPU - {5E0DB390-A45E-41BE-8304-B840327FE597}.Release|Any CPU.Build.0 = netcoreapp-Release|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.Debug|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Debug|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.Debug|Any CPU.Build.0 = netcoreapp-Windows_NT-Debug|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.Release|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Release|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.Release|Any CPU.Build.0 = netcoreapp-Windows_NT-Release|Any CPU - {E2E59C98-998F-9965-991D-99411166AF6F}.Debug|Any CPU.ActiveCfg = netcoreapp-Debug|Any CPU - {E2E59C98-998F-9965-991D-99411166AF6F}.Debug|Any CPU.Build.0 = netcoreapp-Debug|Any CPU - {E2E59C98-998F-9965-991D-99411166AF6F}.Release|Any CPU.ActiveCfg = netcoreapp-Release|Any CPU - {E2E59C98-998F-9965-991D-99411166AF6F}.Release|Any CPU.Build.0 = netcoreapp-Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {5E0DB390-A45E-41BE-8304-B840327FE597} = {1A2F9F4A-A032-433E-B914-ADD5992BB178} - {EBDB0247-CA43-4226-B7A1-8FEF21061D09} = {E107E9C1-E893-4E87-987E-04EF0DCEAEFD} - {E2E59C98-998F-9965-991D-99411166AF6F} = {2E666815-2EDB-464B-9DF6-380BF4789AD4} - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {6EDCA7D5-885F-44E6-9098-1396FD41C96E} - EndGlobalSection -EndGlobal diff --git a/src/libraries/CoreFx.Private.TestUtilities/Directory.Build.props b/src/libraries/CoreFx.Private.TestUtilities/Directory.Build.props deleted file mode 100644 index e9e1de5..0000000 --- a/src/libraries/CoreFx.Private.TestUtilities/Directory.Build.props +++ /dev/null @@ -1,12 +0,0 @@ - - - true - - - - 1.0.1.0 - Open - - true - - diff --git a/src/libraries/CoreFx.Private.TestUtilities/pkg/CoreFx.Private.TestUtilities.pkgproj b/src/libraries/CoreFx.Private.TestUtilities/pkg/CoreFx.Private.TestUtilities.pkgproj deleted file mode 100644 index 791dee1..0000000 --- a/src/libraries/CoreFx.Private.TestUtilities/pkg/CoreFx.Private.TestUtilities.pkgproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - - uap10.0.16299;netcoreapp2.0;net461;$(AllXamarinFrameworks) - - - uap10.0.16299;netcoreapp2.0;net461;$(AllXamarinFrameworks) - - - - - true - - - diff --git a/src/libraries/CoreFx.Private.TestUtilities/ref/CoreFx.Private.TestUtilities.cs b/src/libraries/CoreFx.Private.TestUtilities/ref/CoreFx.Private.TestUtilities.cs deleted file mode 100644 index 35489eb..0000000 --- a/src/libraries/CoreFx.Private.TestUtilities/ref/CoreFx.Private.TestUtilities.cs +++ /dev/null @@ -1,167 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. -// ------------------------------------------------------------------------------ -// Changes to this file must follow the http://aka.ms/api-review process. -// ------------------------------------------------------------------------------ - -namespace System -{ - public static partial class AdminHelpers - { - public static bool IsProcessElevated() { throw null; } - public static int RunAsSudo(string commandLine) { throw null; } - } - public static partial class AssertExtensions - { - public static void Contains(string value, string substring) { } - public static void Equal(T[] expected, T[] actual) where T : System.IEquatable { } - public static void Equal(System.Collections.Generic.HashSet expected, System.Collections.Generic.HashSet actual) { } - public static void GreaterThanOrEqualTo(T actual, T greaterThanOrEqualTo, string userMessage = null) where T : System.IComparable { } - public static void GreaterThan(T actual, T greaterThan, string userMessage = null) where T : System.IComparable { } - public static void LessThanOrEqualTo(T actual, T lessThanOrEqualTo, string userMessage = null) where T : System.IComparable { } - public static void LessThan(T actual, T lessThan, string userMessage = null) where T : System.IComparable { } - public static System.Exception Throws(System.Type netCoreExceptionType, System.Type netFxExceptionType, System.Action action) { throw null; } - public static void ThrowsAny(System.Type firstExceptionType, System.Type secondExceptionType, System.Action action) { } - public static void ThrowsAny(System.Action action) where TFirstExceptionType : System.Exception where TSecondExceptionType : System.Exception { } - public static void ThrowsAny(System.Action action) where TFirstExceptionType : System.Exception where TSecondExceptionType : System.Exception where TThirdExceptionType : System.Exception { } - public static System.Threading.Tasks.Task ThrowsAsync(string paramName, System.Func testCode) where T : System.ArgumentException { throw null; } - public static void ThrowsIf(bool condition, System.Action action) where T : System.Exception { } - public static T Throws(System.Action action) where T : System.Exception { throw null; } - public static void Throws(System.Action action, string message) where T : System.Exception { } - public static T Throws(string paramName, System.Action action) where T : System.ArgumentException { throw null; } - public static T Throws(string paramName, System.Func testCode) where T : System.ArgumentException { throw null; } - public static void Throws(string netCoreParamName, string netFxParamName, System.Action action) where T : System.ArgumentException { } - public static void Throws(string netCoreParamName, string netFxParamName, System.Func testCode) where T : System.ArgumentException { } - public static System.Exception Throws(System.Action action) where TNetCoreExceptionType : System.Exception where TNetFxExceptionType : System.Exception { throw null; } - public static void Throws(string paramName, System.Action action) where TNetCoreExceptionType : System.ArgumentException where TNetFxExceptionType : System.Exception { } - public static void Throws(string netCoreParamName, string netFxParamName, System.Action action) where TNetCoreExceptionType : System.ArgumentException where TNetFxExceptionType : System.ArgumentException { } - } - public static partial class PlatformDetection - { - public static bool IsReflectionEmitSupported; - public static bool ClientWebSocketPartialMessagesSupported { get { throw null; } } - public static bool HasWindowsShell { get { throw null; } } - public static System.Version ICUVersion { get { throw null; } } - public static bool Is32BitProcess { get { throw null; } } - public static bool IsAlpine { get { throw null; } } - public static bool IsArgIteratorNotSupported { get { throw null; } } - public static bool IsArgIteratorSupported { get { throw null; } } - public static bool IsArm64Process { get { throw null; } } - public static bool IsArmOrArm64Process { get { throw null; } } - public static bool IsArmProcess { get { throw null; } } - public static bool IsCentos6 { get { throw null; } } - public static bool IsDebian { get { throw null; } } - public static bool IsDebian8 { get { throw null; } } - public static bool IsDomainJoinedMachine { get { throw null; } } - public static bool IsDrawingSupported { get { throw null; } } - public static bool IsFedora { get { throw null; } } - public static bool IsFreeBSD { get { throw null; } } - public static bool IsFullFramework { get { throw null; } } - public static bool IsInAppContainer { get { throw null; } } - public static bool IsInContainer { get { throw null; } } - public static bool IsInvokingStaticConstructorsSupported { get { throw null; } } - public static bool IsMacOsHighSierraOrHigher { get { throw null; } } - public static bool IsMacOsMojaveOrHigher { get { throw null; } } - public static bool IsMonoRuntime { get { throw null; } } - public static bool IsNetBSD { get { throw null; } } - public static bool IsNetCore { get { throw null; } } - public static bool IsNetfx462OrNewer { get { throw null; } } - public static bool IsNetfx470OrNewer { get { throw null; } } - public static bool IsNetfx471OrNewer { get { throw null; } } - public static bool IsNetfx472OrNewer { get { throw null; } } - public static bool IsNonZeroLowerBoundArraySupported { get { throw null; } } - public static bool IsNotArm64Process { get { throw null; } } - public static bool IsNotArmNorArm64Process { get { throw null; } } - public static bool IsNotArmProcess { get { throw null; } } - public static bool IsNotFedoraOrRedHatFamily { get { throw null; } } - public static bool IsNotInAppContainer { get { throw null; } } - public static bool IsNotIntMaxValueArrayIndexSupported { get { throw null; } } - public static bool IsNotMacOsHighSierraOrHigher { get { throw null; } } - public static bool IsNotOneCoreUAP { get { throw null; } } - public static bool IsNotOSX { get { throw null; } } - public static bool IsNotRedHatFamily { get { throw null; } } - public static bool IsNotRedHatFamily6 { get { throw null; } } - public static bool IsNotWindows8x { get { throw null; } } - public static bool IsNotWindowsHomeEdition { get { throw null; } } - public static bool IsNotWindowsIoTCore { get { throw null; } } - public static bool IsNotWindowsNanoServer { get { throw null; } } - public static bool IsNotWindowsServerCore { get { throw null; } } - public static bool IsNotWindowsSubsystemForLinux { get { throw null; } } - public static bool IsNotWinRTSupported { get { throw null; } } - public static bool IsOpenSUSE { get { throw null; } } - public static bool IsOSX { get { throw null; } } - public static bool IsPreciseGcSupported { get { throw null; } } - public static bool IsRedHatFamily { get { throw null; } } - public static bool IsRedHatFamily6 { get { throw null; } } - public static bool IsRedHatFamily7 { get { throw null; } } - public static bool IsSoundPlaySupported { get { throw null; } } - public static bool IsSuperUser { get { throw null; } } - public static bool IsTizen { get { throw null; } } - public static bool IsUap { get { throw null; } } - public static bool IsUbuntu { get { throw null; } } - public static bool IsUbuntu1404 { get { throw null; } } - public static bool IsUbuntu1604 { get { throw null; } } - public static bool IsUbuntu1704 { get { throw null; } } - public static bool IsUbuntu1710 { get { throw null; } } - public static bool IsUbuntu1710OrHigher { get { throw null; } } - public static bool IsUbuntu1804 { get { throw null; } } - public static bool IsUbuntu1810OrHigher { get { throw null; } } - public static bool IsWindows { get { throw null; } } - public static bool IsWindows10Version1607OrGreater { get { throw null; } } - public static bool IsWindows10Version1703OrGreater { get { throw null; } } - public static bool IsWindows10Version1709OrGreater { get { throw null; } } - public static bool IsWindows10Version1803OrGreater { get { throw null; } } - public static bool IsWindows10Version1903OrGreater { get { throw null; } } - public static bool IsWindows7 { get { throw null; } } - public static bool IsWindows8x { get { throw null; } } - public static bool IsWindows8xOrLater { get { throw null; } } - public static bool IsWindowsAndElevated { get { throw null; } } - public static bool IsWindowsHomeEdition { get { throw null; } } - public static bool IsWindowsIoTCore { get { throw null; } } - public static bool IsWindowsNanoServer { get { throw null; } } - public static bool IsWindowsServerCore { get { throw null; } } - public static bool IsWindowsSubsystemForLinux { get { throw null; } } - public static bool IsWinRTSupported { get { throw null; } } - public static bool IsXmlDsigXsltTransformSupported { get { throw null; } } - public static string LibcRelease { get { throw null; } } - public static string LibcVersion { get { throw null; } } - public static System.Version OpenSslVersion { get { throw null; } } - public static System.Version OSXVersion { get { throw null; } } - public static bool SupportsAlpn { get { throw null; } } - public static bool SupportsClientAlpn { get { throw null; } } - public static bool SupportsSsl3 { get { throw null; } } - public static bool SupportsTls13 { get { throw null; } } - public static bool TargetsNetFx452OrLower { get { throw null; } } - public static int WindowsVersion { get { throw null; } } - public static string GetDistroVersionString() { throw null; } - } - public static partial class RetryHelper - { - public static void Execute(System.Action test, int maxAttempts = 5, System.Func backoffFunc = null) { } - public static System.Threading.Tasks.Task ExecuteAsync(Func test, int maxAttempts = 5, System.Func backoffFunc = null) { throw null; } - } - public static partial class TestEnvironment - { - public static bool IsStressModeEnabled { get { throw null; } } - } - public static partial class TheoryExtensions - { - [System.CLSCompliantAttribute(false)] - public static Xunit.TheoryData ToTheoryData(this System.Collections.Generic.IEnumerable data) { throw null; } - } -} -namespace System.IO -{ - public abstract partial class FileCleanupTestBase : System.IDisposable - { - protected FileCleanupTestBase() { } - protected static bool IsProcessElevated { get { throw null; } } - protected string TestDirectory { get { throw null; } } - public void Dispose() { } - protected virtual void Dispose(bool disposing) { } - ~FileCleanupTestBase() { } - protected string GetTestFileName(int? index = default(int?), [System.Runtime.CompilerServices.CallerMemberNameAttribute]string memberName = null, [System.Runtime.CompilerServices.CallerLineNumberAttribute]int lineNumber = 0) { throw null; } - protected string GetTestFilePath(int? index = default(int?), [System.Runtime.CompilerServices.CallerMemberNameAttribute]string memberName = null, [System.Runtime.CompilerServices.CallerLineNumberAttribute]int lineNumber = 0) { throw null; } - } -} diff --git a/src/libraries/CoreFx.Private.TestUtilities/ref/CoreFx.Private.TestUtilities.csproj b/src/libraries/CoreFx.Private.TestUtilities/ref/CoreFx.Private.TestUtilities.csproj deleted file mode 100644 index 3998c01..0000000 --- a/src/libraries/CoreFx.Private.TestUtilities/ref/CoreFx.Private.TestUtilities.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - {E2E59C98-998F-9965-991D-99411166AF6F} - false - netcoreapp-Debug;netcoreapp-Release;netstandard-Debug;netstandard-Release;uap-Debug;uap-Release - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/libraries/CoreFx.Private.TestUtilities/ref/CoreFx.Private.TestUtilities.netcoreapp.cs b/src/libraries/CoreFx.Private.TestUtilities/ref/CoreFx.Private.TestUtilities.netcoreapp.cs deleted file mode 100644 index ed68ba1..0000000 --- a/src/libraries/CoreFx.Private.TestUtilities/ref/CoreFx.Private.TestUtilities.netcoreapp.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. -// ------------------------------------------------------------------------------ -// Changes to this file must follow the http://aka.ms/api-review process. -// ------------------------------------------------------------------------------ - -namespace System.Buffers -{ - public static partial class BoundedMemory - { - public static System.Buffers.BoundedMemory Allocate(int elementCount, System.Buffers.PoisonPagePlacement placement = System.Buffers.PoisonPagePlacement.After) where T : unmanaged { throw null; } - public static System.Buffers.BoundedMemory AllocateFromExistingData(System.ReadOnlySpan data, System.Buffers.PoisonPagePlacement placement = System.Buffers.PoisonPagePlacement.After) where T : unmanaged { throw null; } - public static System.Buffers.BoundedMemory AllocateFromExistingData(T[] data, System.Buffers.PoisonPagePlacement placement = System.Buffers.PoisonPagePlacement.After) where T : unmanaged { throw null; } - } - public abstract partial class BoundedMemory : IDisposable where T : unmanaged - { - public abstract bool IsReadonly { get; } - public abstract System.Memory Memory { get; } - public abstract System.Span Span { get; } - public abstract void Dispose(); - public abstract void MakeReadonly(); - public abstract void MakeWriteable(); - } - public enum PoisonPagePlacement - { - After = 0, - Before = 1, - } -} diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/Configurations.props b/src/libraries/CoreFx.Private.TestUtilities/src/Configurations.props deleted file mode 100644 index bae9d9f..0000000 --- a/src/libraries/CoreFx.Private.TestUtilities/src/Configurations.props +++ /dev/null @@ -1,13 +0,0 @@ - - - - netstandard; - uap-Windows_NT; - netfx-Windows_NT; - netcoreapp-Windows_NT; - netcoreapp-Unix; - netcoreapp2.0-Windows_NT; - netcoreapp2.0-Unix; - - - diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/CoreFx.Private.TestUtilities.csproj b/src/libraries/CoreFx.Private.TestUtilities/src/CoreFx.Private.TestUtilities.csproj deleted file mode 100644 index 0f831be..0000000 --- a/src/libraries/CoreFx.Private.TestUtilities/src/CoreFx.Private.TestUtilities.csproj +++ /dev/null @@ -1,130 +0,0 @@ - - - CoreFx.Private.TestUtilities - {EBDB0247-CA43-4226-B7A1-8FEF21061D09} - false - false - true - $(NoWarn);CS1573 - false - false - $(NoWarn);CS3021 - true - Test Utilities are not supported on this platform - netcoreapp-Unix-Debug;netcoreapp-Unix-Release;netcoreapp-Windows_NT-Debug;netcoreapp-Windows_NT-Release;netcoreapp2.0-Unix-Debug;netcoreapp2.0-Unix-Release;netcoreapp2.0-Windows_NT-Debug;netcoreapp2.0-Windows_NT-Release;netfx-Windows_NT-Debug;netfx-Windows_NT-Release;netstandard-Debug;netstandard-Release;uap-Windows_NT-Debug;uap-Windows_NT-Release - - - - - - - - - - - - - - Common\CoreLib\System\PasteArguments.cs - - - - - - - - - - - - - Common\Interop\Windows\Kernel32\Interop.GetCurrentProcess_IntPtr.cs - - - Common\CoreLib\System\PasteArguments.Windows.cs - - - Common\Interop\Windows\NtDll\Interop.RTL_OSVERSIONINFOEX.cs - - - Common\Interop\Windows\NtDll\Interop.RtlGetVersion.cs - - - Common\Interop\Windows\Advapi32\Interop.OpenProcessToken_SafeAccessTokenHandle.cs - - - Common\Interop\Windows\Interop.Libraries.cs - - - Common\CoreLib\Interop\Windows\Kernel32\Interop.CloseHandle.cs - - - Common\Interop\Windows\Advapi32\Interop.TOKEN_INFORMATION_CLASS.cs - - - Common\Interop\Windows\Advapi32\Interop.GetTokenInformation_void.cs - - - Common\Interop\Windows\Advapi32\Interop.TOKEN_ELEVATION.cs - - - Common\CoreLib\Interop\Windows\Interop.BOOL.cs - - - - - - Common\Interop\Unix\System.Security.Cryptography.Native\Interop.OpenSslVersion.cs - - - Common\CoreLib\System\PasteArguments.Unix.cs - - - - Common\Interop\Unix\Interop.GetEUid.cs - - - Common\Interop\Unix\Interop.Libraries.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/Resources/CoreFx.Private.TestUtilities.rd.xml b/src/libraries/CoreFx.Private.TestUtilities/src/Resources/CoreFx.Private.TestUtilities.rd.xml deleted file mode 100644 index e19b454..0000000 --- a/src/libraries/CoreFx.Private.TestUtilities/src/Resources/CoreFx.Private.TestUtilities.rd.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/System/AdminHelpers.Unix.cs b/src/libraries/CoreFx.Private.TestUtilities/src/System/AdminHelpers.Unix.cs deleted file mode 100644 index dd20faa..0000000 --- a/src/libraries/CoreFx.Private.TestUtilities/src/System/AdminHelpers.Unix.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace System -{ - /// - /// Returns true if the current process is elevated (in Unix). - /// - public static partial class AdminHelpers - { - public unsafe static bool IsProcessElevated() - { - uint userId = Interop.Sys.GetEUid(); - return(userId == 0); - } - } -} diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/System/AdminHelpers.cs b/src/libraries/CoreFx.Private.TestUtilities/src/System/AdminHelpers.cs deleted file mode 100644 index 526e6bd..0000000 --- a/src/libraries/CoreFx.Private.TestUtilities/src/System/AdminHelpers.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Diagnostics; -using Xunit; - -namespace System -{ - public static partial class AdminHelpers - { - /// - /// Runs the given command as sudo (for Unix). - /// - /// The command line to run as sudo - /// Returns the process exit code (0 typically means it is successful) - public static int RunAsSudo(string commandLine) - { - ProcessStartInfo startInfo = new ProcessStartInfo() - { - FileName = "sudo", - Arguments = commandLine - }; - - using (Process process = Process.Start(startInfo)) - { - Assert.True(process.WaitForExit(30000)); - return process.ExitCode; - } - } - - } -} diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/System/Net/PlatformDetection.Networking.cs b/src/libraries/CoreFx.Private.TestUtilities/src/System/Net/PlatformDetection.Networking.cs deleted file mode 100644 index 0aa9faf..0000000 --- a/src/libraries/CoreFx.Private.TestUtilities/src/System/Net/PlatformDetection.Networking.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace System -{ - public static partial class PlatformDetection - { - // Windows 10 Insider Preview Build 16215 introduced the necessary APIs for the UAP version of - // ClientWebSocket.ReceiveAsync to consume partial message data as it arrives, without having to wait - // for "end of message" to be signaled. - public static bool ClientWebSocketPartialMessagesSupported => !IsUap || IsWindows10Version1709OrGreater; - } -} diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformApis.Unix.cs b/src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformApis.Unix.cs deleted file mode 100644 index 84b8d2d..0000000 --- a/src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformApis.Unix.cs +++ /dev/null @@ -1,268 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.IO; -using System.Runtime.InteropServices; - -namespace System -{ - internal static class PlatformApis - { - private enum Platform - { - Unknown = 0, - Linux = 2, - Darwin = 3, - FreeBSD = 4 - } - - private static partial class NativeMethods - { - public static class Darwin - { - private const int CTL_KERN = 1; - private const int KERN_OSRELEASE = 2; - - public unsafe static string GetKernelRelease() - { - const uint BUFFER_LENGTH = 32; - - var name = stackalloc int[2]; - name[0] = CTL_KERN; - name[1] = KERN_OSRELEASE; - - var buf = stackalloc byte[(int)BUFFER_LENGTH]; - var len = stackalloc uint[1]; - *len = BUFFER_LENGTH; - - try - { - // If the buffer isn't big enough, it seems sysctl still returns 0 and just sets len to the - // necessary buffer size. This appears to be contrary to the man page, but it's easy to detect - // by simply checking len against the buffer length. - if (sysctl(name, 2, buf, len, IntPtr.Zero, 0) == 0 && *len < BUFFER_LENGTH) - { - return Marshal.PtrToStringAnsi((IntPtr)buf, (int)*len); - } - } - catch (Exception ex) - { - throw new PlatformNotSupportedException("Error reading Darwin Kernel Version", ex); - } - throw new PlatformNotSupportedException("Unknown error reading Darwin Kernel Version"); - } - - [DllImport("libc")] - private unsafe static extern int sysctl( - int* name, - uint namelen, - byte* oldp, - uint* oldlenp, - IntPtr newp, - uint newlen); - } - } - - private class DistroInfo - { - public string Id; - public string VersionId; - } - - private static readonly Lazy _platform = new Lazy(DetermineOSPlatform); - private static readonly Lazy _distroInfo = new Lazy(LoadDistroInfo); - - public static string GetOSName() - { - switch (GetOSPlatform()) - { - case Platform.Linux: - return GetDistroId() ?? "Linux"; - case Platform.Darwin: - return "Mac OS X"; - case Platform.FreeBSD: - return "FreeBSD"; - default: - return "Unknown"; - } - } - - public static string GetOSVersion() - { - switch (GetOSPlatform()) - { - case Platform.Linux: - return GetDistroVersionId() ?? string.Empty; - case Platform.Darwin: - return GetDarwinVersion() ?? string.Empty; - case Platform.FreeBSD: - return GetFreeBSDVersion() ?? string.Empty; - default: - return string.Empty; - } - } - - private static string GetDarwinVersion() - { - Version version; - var kernelRelease = NativeMethods.Darwin.GetKernelRelease(); - if (!Version.TryParse(kernelRelease, out version) || version.Major < 5) - { - // 10.0 covers all versions prior to Darwin 5 - // Similarly, if the version is not a valid version number, but we have still detected that it is Darwin, we just assume - // it is OS X 10.0 - return "10.0"; - } - else - { - // Mac OS X 10.1 mapped to Darwin 5.x, and the mapping continues that way - // So just subtract 4 from the Darwin version. - // https://en.wikipedia.org/wiki/Darwin_%28operating_system%29 - return $"10.{version.Major - 4}"; - } - } - - private static string GetFreeBSDVersion() - { - // This is same as sysctl kern.version - // FreeBSD 11.0-RELEASE-p1 FreeBSD 11.0-RELEASE-p1 #0 r306420: Thu Sep 29 01:43:23 UTC 2016 root@releng2.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC - // What we want is major release as minor releases should be compatible. - String version = RuntimeInformation.OSDescription; - try - { - // second token up to first dot - return RuntimeInformation.OSDescription.Split()[1].Split('.')[0]; - } - catch - { - } - return string.Empty; - } - - private static Platform GetOSPlatform() - { - return _platform.Value; - } - - private static string GetDistroId() - { - return _distroInfo.Value?.Id; - } - - private static string GetDistroVersionId() - { - return _distroInfo.Value?.VersionId; - } - - private static DistroInfo LoadDistroInfo() - { - DistroInfo result = null; - - // Sample os-release file: - // NAME="Ubuntu" - // VERSION = "14.04.3 LTS, Trusty Tahr" - // ID = ubuntu - // ID_LIKE = debian - // PRETTY_NAME = "Ubuntu 14.04.3 LTS" - // VERSION_ID = "14.04" - // HOME_URL = "http://www.ubuntu.com/" - // SUPPORT_URL = "http://help.ubuntu.com/" - // BUG_REPORT_URL = "http://bugs.launchpad.net/ubuntu/" - // We use ID and VERSION_ID - - if (File.Exists("/etc/os-release")) - { - var lines = File.ReadAllLines("/etc/os-release"); - result = new DistroInfo(); - foreach (var line in lines) - { - if (line.StartsWith("ID=", StringComparison.Ordinal)) - { - result.Id = line.Substring(3).Trim('"', '\''); - } - else if (line.StartsWith("VERSION_ID=", StringComparison.Ordinal)) - { - result.VersionId = line.Substring(11).Trim('"', '\''); - } - } - } - else if (File.Exists("/etc/redhat-release")) - { - var lines = File.ReadAllLines("/etc/redhat-release"); - - if (lines.Length >= 1) - { - string line = lines[0]; - if (line.StartsWith("Red Hat Enterprise Linux Server release 6.") || - line.StartsWith("CentOS release 6.")) - { - result = new DistroInfo(); - result.Id = "rhel"; - result.VersionId = "6"; - } - } - } - // possibly should fall back to /usr/lib/os-release here - - if (result != null) - { - result = NormalizeDistroInfo(result); - } - - return result; - } - - // For some distros, we don't want to use the full version from VERSION_ID. One example is - // Red Hat Enterprise Linux, which includes a minor version in their VERSION_ID but minor - // versions are backwards compatable. - // - // In this case, we'll normalized RIDs like 'rhel.7.2' and 'rhel.7.3' to a generic - // 'rhel.7'. This brings RHEL in line with other distros like CentOS or Debian which - // don't put minor version numbers in their VERSION_ID fields because all minor versions - // are backwards compatible. - private static DistroInfo NormalizeDistroInfo(DistroInfo distroInfo) - { - // Handle if VersionId is null by just setting the index to -1. - int lastVersionNumberSeparatorIndex = distroInfo.VersionId?.IndexOf('.') ?? -1; - - if (lastVersionNumberSeparatorIndex != -1 && distroInfo.Id == "alpine") - { - // For Alpine, the version reported has three components, so we need to find the second version separator - lastVersionNumberSeparatorIndex = distroInfo.VersionId.IndexOf('.', lastVersionNumberSeparatorIndex + 1); - } - - if (lastVersionNumberSeparatorIndex != -1 && (distroInfo.Id == "rhel" || distroInfo.Id == "alpine")) - { - distroInfo.VersionId = distroInfo.VersionId.Substring(0, lastVersionNumberSeparatorIndex); - } - - // In some distros/versions we cannot discover the distro version; return something valid. - // Pick a high version number, since this seems to happen on newer distros. - if (string.IsNullOrEmpty(distroInfo.VersionId)) - { - distroInfo.VersionId = new Version(Int32.MaxValue, Int32.MaxValue).ToString(); - } - - return distroInfo; - } - - private static Platform DetermineOSPlatform() - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - return Platform.Linux; - } - if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - { - return Platform.Darwin; - } - if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD"))) - { - return Platform.FreeBSD; - } - - return Platform.Unknown; - } - } -} diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.NetFx.cs b/src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.NetFx.cs deleted file mode 100644 index 9e633f1..0000000 --- a/src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.NetFx.cs +++ /dev/null @@ -1,65 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using Xunit; -using Microsoft.Win32; -using System.Runtime.Versioning; - -namespace System -{ - public static partial class PlatformDetection - { - private static string FrameworkName => AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName; - private static Version TargetVersion => string.IsNullOrEmpty(FrameworkName) ? new Version(4, 5, 0, 0) : new FrameworkName(FrameworkName).Version; - - // The current full framework xunit runner is targeting 4.5.2 so we expect TargetsNetFx452OrLower to be true. - // When we update xunit runner in the future which may target recent framework version, TargetsNetFx452OrLower can start return - // false but we don't expect any code change though. - public static bool TargetsNetFx452OrLower => TargetVersion.CompareTo(new Version(4, 5, 3, 0)) < 0; - - public static bool IsNetfx462OrNewer => GetFrameworkVersion() >= new Version(4, 6, 2); - - public static bool IsNetfx470OrNewer => GetFrameworkVersion() >= new Version(4, 7, 0); - - public static bool IsNetfx471OrNewer => GetFrameworkVersion() >= new Version(4, 7, 1); - - public static bool IsNetfx472OrNewer => GetFrameworkVersion() >= new Version(4, 7, 2); - - // To get the framework version we can do it throught the registry key and getting the Release value under the .NET Framework key. - // the mapping to each version can be found in: https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed - // everytime we ship a new version this method should be updated to include the new framework version. - private static Version GetFrameworkVersion() - { - using (RegistryKey ndpKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full")) - { - if (ndpKey != null) - { - int value = (int)(ndpKey.GetValue("Release") ?? 0); - if (value >= 461808) - return new Version(4, 7, 2); - if (value >= 461308) - return new Version(4, 7, 1); - if (value >= 460798) - return new Version(4, 7, 0); - if (value >= 394802) - return new Version(4, 6, 2); - if (value >= 394254) - return new Version(4, 6, 1); - if (value >= 393295) - return new Version(4, 6, 0); - if (value >= 379893) - return new Version(4, 5, 2); - if (value >= 378675) - return new Version(4, 5, 1); - if (value >= 378389) - return new Version(4, 5, 0); - - throw new NotSupportedException($"No 4.5 or later framework version detected, framework key value: {value}"); - } - - throw new NotSupportedException(@"No registry key found under 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' to determine running framework version"); - } - } - } -} diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.NonNetFx.Windows.cs b/src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.NonNetFx.Windows.cs deleted file mode 100644 index 9e446da..0000000 --- a/src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.NonNetFx.Windows.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace System -{ - public static partial class PlatformDetection - { - public static bool TargetsNetFx452OrLower => false; - public static bool IsNetfx462OrNewer => false; - public static bool IsNetfx470OrNewer => false; - public static bool IsNetfx471OrNewer => false; - public static bool IsNetfx472OrNewer => false; - } -} diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/System/TheoryExtensions.cs b/src/libraries/CoreFx.Private.TestUtilities/src/System/TheoryExtensions.cs deleted file mode 100644 index 30fda49..0000000 --- a/src/libraries/CoreFx.Private.TestUtilities/src/System/TheoryExtensions.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace System -{ - public static class TheoryExtensions - { - /// - /// Converts an IEnumerable into an Xunit theory compatible enumerable. - /// - public static TheoryData ToTheoryData(this IEnumerable data) - { - // Returning TheoryData rather than IEnumerable directly should - // encourage discover and usage of TheoryData classes for more - // complicated theories. Slightly easier to type as well. - return new TheoryDataAdapter(data.Select(d => new object[] { d })); - } - - private class TheoryDataAdapter : TheoryData, IEnumerable - { - private IEnumerable _data; - - public TheoryDataAdapter(IEnumerable data) - { - _data = data; - } - - public new IEnumerator GetEnumerator() => _data.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - } - } -} diff --git a/src/libraries/CoreFx.Private.TestUtilities/tests/AssertExtensionTests.cs b/src/libraries/CoreFx.Private.TestUtilities/tests/AssertExtensionTests.cs deleted file mode 100644 index 94be320..0000000 --- a/src/libraries/CoreFx.Private.TestUtilities/tests/AssertExtensionTests.cs +++ /dev/null @@ -1,334 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Xunit; -using Xunit.Sdk; - -namespace CoreFx.Private.TestUtilities.Tests -{ - public class AssertExtensionTests - { - private const string Null = ""; - - public class OneException : Exception { } - - public class TwoException : Exception { } - - public class ThreeException : Exception { } - - public class NotMyException : Exception { } - - [Fact] - public void ThrowsAny_Two_ThrowsExpected() - { - Action throwExpected = () => { throw new OneException(); }; - try - { - AssertExtensions.ThrowsAny(throwExpected); - } - catch (Exception e) - { - Assert.False(true, $"Should not have thrown for first, threw {e}"); - } - - throwExpected = () => { throw new TwoException(); }; - try - { - AssertExtensions.ThrowsAny(throwExpected); - } - catch (Exception e) - { - Assert.False(true, $"Should not have thrown for second, threw {e}"); - } - } - - [Fact] - public void ThrowsAny_Two_ThrowsUnexpected() - { - Action throwUnexpected = () => { throw new NotMyException(); }; - try - { - AssertExtensions.ThrowsAny(throwUnexpected); - } - catch (XunitException e) - { - Assert.Equal( - "Expected one of: (CoreFx.Private.TestUtilities.Tests.AssertExtensionTests+OneException, CoreFx.Private.TestUtilities.Tests.AssertExtensionTests+TwoException) -> Actual: (CoreFx.Private.TestUtilities.Tests.AssertExtensionTests+NotMyException)", - e.Message); - return; - } - - Assert.False(true, "Should have thrown"); - } - - [Fact] - public void ThrowsAny_Two_DoesNotThrow() - { - Action doNothing = () => { }; - try - { - AssertExtensions.ThrowsAny(doNothing); - } - catch (XunitException e) - { - Assert.Equal( - "Expected one of: (CoreFx.Private.TestUtilities.Tests.AssertExtensionTests+OneException, CoreFx.Private.TestUtilities.Tests.AssertExtensionTests+TwoException) -> Actual: No exception thrown", - e.Message); - return; - } - - Assert.False(true, "Should have thrown"); - } - - - [Fact] - public void ThrowsAny_Three_ThrowsExpected() - { - Action throwExpected = () => { throw new ThreeException(); }; - try - { - AssertExtensions.ThrowsAny(throwExpected); - } - catch (Exception e) - { - Assert.False(true, $"Should not have thrown for first, threw {e}"); - } - } - - [Fact] - public void ThrowsAny_Three_ThrowsUnexpected() - { - Action throwUnexpected = () => { throw new NotMyException(); }; - try - { - AssertExtensions.ThrowsAny(throwUnexpected); - } - catch (XunitException) - { - // We're ok - return; - } - - Assert.False(true, "Should have thrown"); - } - - [Fact] - public void ThrowsAny_Three_DoesNotThrow() - { - Action doNothing = () => { }; - try - { - AssertExtensions.ThrowsAny(doNothing); - } - catch (XunitException) - { - // We're ok - return; - } - - Assert.False(true, "Should have thrown"); - } - - [Theory, - InlineData(0, 0, false), - InlineData(1, 1, false), - InlineData(0, 1, false), - InlineData(0, -1, true), - InlineData(-1, 0, false), - InlineData(1, 0, true), - InlineData(1, -1, true), - InlineData(-1, 1, false) - ] - public void GreaterThan_ValueType(int actual, int greaterThan, bool expected) - { - try - { - AssertExtensions.GreaterThan(actual, greaterThan); - Assert.True(expected, $"{actual} > {greaterThan} should have failed the assertion."); - } - catch (XunitException) - { - Assert.False(expected, $"{actual} > {greaterThan} should *not* have failed the assertion."); - } - } - - [Theory, - // Null is always less than anything other than null - InlineData("", null, true), - InlineData(null, null, false), - InlineData(null, "", false), - InlineData("b", "b", false), - InlineData("b", "c", false), - InlineData("b", "a", true), - InlineData("a", "b", false), - InlineData("c", "b", true), - InlineData("c", "a", true), - InlineData("a", "c", false) - ] - public void GreaterThan_ReferenceType(string actual, string greaterThan, bool expected) - { - try - { - AssertExtensions.GreaterThan(actual, greaterThan); - Assert.True(expected, $"{actual ?? Null} > {greaterThan ?? Null} should have failed the assertion."); - } - catch (XunitException) - { - Assert.False(expected, $"{actual ?? Null} > {greaterThan ?? Null} should *not* have failed the assertion."); - } - } - - [Theory, - InlineData(0, 0, false), - InlineData(1, 1, false), - InlineData(0, 1, true), - InlineData(0, -1, false), - InlineData(-1, 0, true), - InlineData(1, 0, false), - InlineData(1, -1, false), - InlineData(-1, 1, true) - ] - public void LessThan_ValueType(int actual, int lessThan, bool expected) - { - try - { - AssertExtensions.LessThan(actual, lessThan); - Assert.True(expected, $"{actual} < {lessThan} should have failed the assertion."); - } - catch (XunitException) - { - Assert.False(expected, $"{actual} < {lessThan} should *not* have failed the assertion."); - } - } - - [Theory, - // Null is always less than anything other than null - InlineData("", null, false), - InlineData(null, null, false), - InlineData(null, "", true), - InlineData("b", "b", false), - InlineData("b", "c", true), - InlineData("b", "a", false), - InlineData("a", "b", true), - InlineData("c", "b", false), - InlineData("c", "a", false), - InlineData("a", "c", true) - ] - public void LessThan_ReferenceType(string actual, string lessThan, bool expected) - { - try - { - AssertExtensions.LessThan(actual, lessThan); - Assert.True(expected, $"'{actual ?? Null}' < '{lessThan ?? Null}' should have failed the assertion."); - } - catch (XunitException) - { - Assert.False(expected, $"'{actual ?? Null}' < '{lessThan ?? Null}' should *not* have failed the assertion."); - } - } - - [Theory, - InlineData(0, 0, true), - InlineData(1, 1, true), - InlineData(0, 1, false), - InlineData(0, -1, true), - InlineData(-1, 0, false), - InlineData(1, 0, true), - InlineData(1, -1, true), - InlineData(-1, 1, false) - ] - public void GreaterThanOrEqualTo_ValueType(int actual, int greaterThanOrEqualTo, bool expected) - { - try - { - AssertExtensions.GreaterThanOrEqualTo(actual, greaterThanOrEqualTo); - Assert.True(expected, $"{actual} >= {greaterThanOrEqualTo} should have failed the assertion."); - } - catch (XunitException) - { - Assert.False(expected, $"{actual} >= {greaterThanOrEqualTo} should *not* have failed the assertion."); - } - } - - [Theory, - // Null is always less than anything other than null - InlineData("", null, true), - InlineData(null, null, true), - InlineData(null, "", false), - InlineData("b", "b", true), - InlineData("b", "c", false), - InlineData("b", "a", true), - InlineData("a", "b", false), - InlineData("c", "b", true), - InlineData("c", "a", true), - InlineData("a", "c", false) - ] - public void GreaterThanOrEqualTo_ReferenceType(string actual, string greaterThanOrEqualTo, bool expected) - { - try - { - AssertExtensions.GreaterThanOrEqualTo(actual, greaterThanOrEqualTo); - Assert.True(expected, $"'{actual ?? Null}' >= '{greaterThanOrEqualTo ?? Null}' should have failed the assertion."); - } - catch (XunitException) - { - Assert.False(expected, $"'{actual ?? Null}' >= '{greaterThanOrEqualTo ?? Null}' should *not* have failed the assertion."); - } - } - - [Theory, - InlineData(0, 0, true), - InlineData(1, 1, true), - InlineData(0, 1, true), - InlineData(0, -1, false), - InlineData(-1, 0, true), - InlineData(1, 0, false), - InlineData(1, -1, false), - InlineData(-1, 1, true) - ] - public void LessThanOrEqualTo_ValueType(int actual, int lessThanOrEqualTo, bool expected) - { - try - { - AssertExtensions.LessThanOrEqualTo(actual, lessThanOrEqualTo); - Assert.True(expected, $"{actual} <= {lessThanOrEqualTo} should have failed the assertion."); - } - catch (XunitException) - { - Assert.False(expected, $"{actual} <= {lessThanOrEqualTo} should *not* have failed the assertion."); - } - } - - [Theory, - // Null is always less than anything other than null - InlineData("", null, false), - InlineData(null, null, true), - InlineData(null, "", true), - InlineData("b", "b", true), - InlineData("b", "c", true), - InlineData("b", "a", false), - InlineData("a", "b", true), - InlineData("c", "b", false), - InlineData("c", "a", false), - InlineData("a", "c", true) - ] - public void LessThanOrEqualTo_ReferenceType(string actual, string lessThanOrEqualTo, bool expected) - { - try - { - AssertExtensions.LessThanOrEqualTo(actual, lessThanOrEqualTo); - Assert.True(expected, $"'{actual ?? Null}' >= '{lessThanOrEqualTo ?? Null}' should have failed the assertion."); - } - catch (XunitException) - { - Assert.False(expected, $"'{actual ?? Null}' >= '{lessThanOrEqualTo ?? Null}' should *not* have failed the assertion."); - } - } - } -} diff --git a/src/libraries/CoreFx.Private.TestUtilities/tests/ConditionalAttributeTests.cs b/src/libraries/CoreFx.Private.TestUtilities/tests/ConditionalAttributeTests.cs deleted file mode 100644 index 5cee77a..0000000 --- a/src/libraries/CoreFx.Private.TestUtilities/tests/ConditionalAttributeTests.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; -using Xunit.Abstractions; -using Xunit.Sdk; - -namespace CoreFx.Private.TestUtilities.Tests -{ - [TestCaseOrderer("CoreFx.Private.TestUtilities.Tests.AlphabeticalOrderer", "CoreFx.Private.TestUtilities.Tests")] - public class ConditionalAttributeTests - { - // The tests under this class are to validate that ConditionalFact and ConditionalAttribute tests are being executed correctly - // In the past we have had cases where infrastructure changes broke this feature and tests where not running in certain framework. - // This test class is test order dependent so do not rename the tests. - // If new tests need to be added, follow the same naming pattern ConditionalAttribute{LetterToOrderTest} and then add a Validate{TestName}. - - private static bool s_conditionalFactExecuted; - private static int s_conditionalTheoryCount; - - public static bool AlwaysTrue => true; - - [ConditionalFact(nameof(AlwaysTrue))] - public void ConditionalAttributeA() - { - s_conditionalFactExecuted = true; - } - - [ConditionalTheory(nameof(AlwaysTrue))] - [InlineData(1)] - [InlineData(2)] - [InlineData(3)] - public void ConditionalAttributeB(int _) - { - s_conditionalTheoryCount++; - } - - [Fact] - public void ValidateConditionalFact() - { - Assert.True(s_conditionalFactExecuted); - } - - [Fact] - public void ValidateConditionalTheory() - { - Assert.Equal(3, s_conditionalTheoryCount); - } - } - - // We need this TestCaseOrderer in order to guarantee that the ConditionalAttributeTests are always executed in the same order. - public class AlphabeticalOrderer : ITestCaseOrderer - { - public IEnumerable OrderTestCases(IEnumerable testCases) - where TTestCase : ITestCase - { - List result = testCases.ToList(); - result.Sort((x, y) => StringComparer.Ordinal.Compare(x.TestMethod.Method.Name, y.TestMethod.Method.Name)); - return result; - } - } -} diff --git a/src/libraries/CoreFx.Private.TestUtilities/tests/Configurations.props b/src/libraries/CoreFx.Private.TestUtilities/tests/Configurations.props deleted file mode 100644 index acf56fa..0000000 --- a/src/libraries/CoreFx.Private.TestUtilities/tests/Configurations.props +++ /dev/null @@ -1,8 +0,0 @@ - - - - netcoreapp; - uap; - - - \ No newline at end of file diff --git a/src/libraries/CoreFx.Private.TestUtilities/tests/CoreFx.Private.TestUtilities.Tests.csproj b/src/libraries/CoreFx.Private.TestUtilities/tests/CoreFx.Private.TestUtilities.Tests.csproj deleted file mode 100644 index 19a0a1a..0000000 --- a/src/libraries/CoreFx.Private.TestUtilities/tests/CoreFx.Private.TestUtilities.Tests.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - {5E0DB390-A45E-41BE-8304-B840327FE597} - netcoreapp-Debug;netcoreapp-Release;uap-Debug;uap-Release - - - CoreFx.Private.TestUtilities.Tests - - - - - - - \ No newline at end of file diff --git a/src/libraries/CoreFx.Private.TestUtilities/tests/TheoryExtensionTests.cs b/src/libraries/CoreFx.Private.TestUtilities/tests/TheoryExtensionTests.cs deleted file mode 100644 index 35a303e..0000000 --- a/src/libraries/CoreFx.Private.TestUtilities/tests/TheoryExtensionTests.cs +++ /dev/null @@ -1,56 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Collections.Generic; -using Xunit; - -namespace CoreFx.Private.TestUtilities.Tests -{ - public class TheoryExtensionTests : IClassFixture - { - public class TheoryDataFixture : IDisposable - { - private static List s_receivedTheoryData = new List(); - - public void AddValue(string value) - { - s_receivedTheoryData.Add(value); - } - - public void Dispose() - { - Assert.Equal(3, s_receivedTheoryData.Count); - Assert.Equal(new string[] { "one", "two", "three" }, s_receivedTheoryData); - } - } - - private TheoryDataFixture _fixture; - - public TheoryExtensionTests(TheoryDataFixture fixture) - { - _fixture = fixture; - } - - [Theory, - MemberData(nameof(ToTheoryDataData))] - public void ToTheoryData_Basic(string data) - { - _fixture.AddValue(data); - } - - public static TheoryData ToTheoryDataData - { - get - { - List data = new List - { - "one", "two", "three" - }; - - return data.ToTheoryData(); - } - } - } -} diff --git a/src/libraries/Directory.Build.props b/src/libraries/Directory.Build.props index 03bec28..a09b26d 100644 --- a/src/libraries/Directory.Build.props +++ b/src/libraries/Directory.Build.props @@ -13,6 +13,10 @@ $(MSBuildThisFileDirectory)CodeAnalysis.ruleset + + + + @@ -45,13 +49,5 @@ true - - - - - \ No newline at end of file diff --git a/src/libraries/System.Diagnostics.Process/tests/ProcessTestBase.Uap.cs b/src/libraries/System.Diagnostics.Process/tests/ProcessTestBase.Uap.cs index b8f32f93..b88cd3a 100644 --- a/src/libraries/System.Diagnostics.Process/tests/ProcessTestBase.Uap.cs +++ b/src/libraries/System.Diagnostics.Process/tests/ProcessTestBase.Uap.cs @@ -11,8 +11,7 @@ namespace System.Diagnostics.Tests { partial class ProcessTestBase { - protected const string NetfxRunnerName = "cmd"; - protected static readonly string RunnerName = $"{NetfxRunnerName}.exe"; + protected static readonly string RunnerName = "cmd.exe"; protected Process CreateProcessLong() { diff --git a/src/libraries/System.DirectoryServices/tests/System/DirectoryServices/SortOptionTests.cs b/src/libraries/System.DirectoryServices/tests/System/DirectoryServices/SortOptionTests.cs index 67d4472..49cc3ee 100644 --- a/src/libraries/System.DirectoryServices/tests/System/DirectoryServices/SortOptionTests.cs +++ b/src/libraries/System.DirectoryServices/tests/System/DirectoryServices/SortOptionTests.cs @@ -25,11 +25,7 @@ namespace System.DirectoryServices.Tests { var sortOption = new SortOption(propertyName, direction); Assert.Equal(propertyName, sortOption.PropertyName); - - if (PlatformDetection.TargetsNetFx452OrLower) - Assert.Equal(SortDirection.Ascending, sortOption.Direction); - else - Assert.Equal(direction, sortOption.Direction); + Assert.Equal(direction, sortOption.Direction); } [Fact] @@ -43,14 +39,7 @@ namespace System.DirectoryServices.Tests [InlineData(SortDirection.Descending + 1)] public void Ctor_InvalidDirection_ThrowsInvalidEnumArgumentException(SortDirection direction) { - if (PlatformDetection.TargetsNetFx452OrLower) - { - SortOption so = new SortOption("propertyName", direction); - Assert.Equal("propertyName", so.PropertyName); - Assert.Equal(SortDirection.Ascending, so.Direction); - } - else - AssertExtensions.Throws("value", () => new SortOption("propertyName", direction)); + AssertExtensions.Throws("value", () => new SortOption("propertyName", direction)); } } } diff --git a/src/libraries/System.IO.FileSystem/tests/Directory/CreateDirectory.cs b/src/libraries/System.IO.FileSystem/tests/Directory/CreateDirectory.cs index 4d27fd7..61f7bf8 100644 --- a/src/libraries/System.IO.FileSystem/tests/Directory/CreateDirectory.cs +++ b/src/libraries/System.IO.FileSystem/tests/Directory/CreateDirectory.cs @@ -4,6 +4,7 @@ using System.Linq; using Microsoft.DotNet.RemoteExecutor; +using Microsoft.DotNet.XUnitExtensions; using Xunit; namespace System.IO.Tests diff --git a/src/libraries/System.IO.FileSystem/tests/FileSystemTest.cs b/src/libraries/System.IO.FileSystem/tests/FileSystemTest.cs index 1e9e23b..f8e73d9 100644 --- a/src/libraries/System.IO.FileSystem/tests/FileSystemTest.cs +++ b/src/libraries/System.IO.FileSystem/tests/FileSystemTest.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; +using Microsoft.DotNet.XUnitExtensions; using Xunit; namespace System.IO.Tests diff --git a/src/libraries/System.Linq.Expressions/tests/System.Linq.Expressions.Tests.csproj b/src/libraries/System.Linq.Expressions/tests/System.Linq.Expressions.Tests.csproj index 3f0cc48..36f640e 100644 --- a/src/libraries/System.Linq.Expressions/tests/System.Linq.Expressions.Tests.csproj +++ b/src/libraries/System.Linq.Expressions/tests/System.Linq.Expressions.Tests.csproj @@ -17,7 +17,6 @@ - diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpProtocolTests.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpProtocolTests.cs index 0873d91..b2a1516 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpProtocolTests.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpProtocolTests.cs @@ -7,6 +7,7 @@ using System.IO; using System.Net.Test.Common; using System.Threading; using System.Threading.Tasks; +using Microsoft.DotNet.XUnitExtensions; using Xunit; using Xunit.Abstractions; diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj index 2ad9f79..ada60a5 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj @@ -179,9 +179,6 @@ - - - SelectedSitesTest.txt diff --git a/src/libraries/System.Private.Uri/tests/FunctionalTests/UriRelativeResolutionTest.cs b/src/libraries/System.Private.Uri/tests/FunctionalTests/UriRelativeResolutionTest.cs index 3573446..d20fa54 100644 --- a/src/libraries/System.Private.Uri/tests/FunctionalTests/UriRelativeResolutionTest.cs +++ b/src/libraries/System.Private.Uri/tests/FunctionalTests/UriRelativeResolutionTest.cs @@ -22,9 +22,6 @@ namespace System.PrivateUri.Tests private const string FullBaseUriGetLeftPart_Authority = "http://user:psw@host:9090"; private const string FullBaseUriGetLeftPart_Query = "http://user:psw@host:9090/path1/path2/path3/fileA?query"; - // A few of these tests depend on bugfixes made in .NET Framework 4.7.2 and must be skipped on older versions. - public static bool IsNetCoreOrIsNetfx472OrLater => !PlatformDetection.IsFullFramework || PlatformDetection.IsNetfx472OrNewer; - [Fact] public void Uri_Relative_BaseVsAbsolute_ReturnsFullAbsolute() { @@ -138,7 +135,7 @@ namespace System.PrivateUri.Tests Assert.Equal(expectedResult, resolved.ToString()); } - [ConditionalFact(nameof(IsNetCoreOrIsNetfx472OrLater))] + [Fact] public void Uri_Relative_SimplePartialPathWithUnknownScheme_Unicode_ReturnsPartialPathWithScheme() { string schemeAndRelative = "scheme:\u011E"; @@ -148,7 +145,7 @@ namespace System.PrivateUri.Tests Assert.Equal(expectedResult, resolved.ToString()); } - [ConditionalFact(nameof(IsNetCoreOrIsNetfx472OrLater))] + [Fact] public void Uri_Relative_SimplePartialPathWithScheme_Unicode_ReturnsPartialPathWithScheme() { string schemeAndRelative = "http:\u00C7"; @@ -158,7 +155,7 @@ namespace System.PrivateUri.Tests Assert.Equal(expectedResult, resolved.ToString()); } - [ConditionalFact(nameof(IsNetCoreOrIsNetfx472OrLater))] + [Fact] public void Uri_Relative_RightToLeft() { var loremIpsumArabic = "\u0643\u0644 \u0627\u0644\u0649 \u0627\u0644\u0639\u0627\u0644\u0645"; @@ -170,7 +167,7 @@ namespace System.PrivateUri.Tests Assert.Equal(expectedResult, resolved.ToString()); } - [ConditionalFact(nameof(IsNetCoreOrIsNetfx472OrLater))] + [Fact] public void Uri_Relative_Unicode_Glitchy() { var glitchy = "4\u0308\u0311\u031A\u030B\u0352\u034A\u030D\u036C\u036C\u036B\u0344\u0312\u0322\u0334\u0328\u0319\u0323\u0359\u0317\u0324\u0319\u032D\u0331\u0319\u031F\u0331\u0330\u0347\u0353\u0318\u032F\u032C\u03162\u0303\u0313\u031A\u0368\u036E\u0368\u0301\u0367\u0368\u0306\u0305\u0350\u036A\u036F\u0307\u0328\u035F\u0321\u0361\u0320\u032F\u032B\u034E\u0326\u033B"; @@ -182,7 +179,7 @@ namespace System.PrivateUri.Tests Assert.Equal(expectedResult, resolved.ToString()); } - [ConditionalFact(nameof(IsNetCoreOrIsNetfx472OrLater))] + [Fact] public void Uri_Unicode_Format_Character_Combinations_Scheme() { var combinations = CartesianProductAll(_ => CharUnicodeInfo.GetUnicodeCategory(_) == UnicodeCategory.Format && !UriHelper.IsIriDisallowedBidi(_)); diff --git a/src/libraries/System.Runtime.Serialization.Formatters/tests/BinaryFormatterTestData.cs b/src/libraries/System.Runtime.Serialization.Formatters/tests/BinaryFormatterTestData.cs index 8762675..e570b9d 100644 --- a/src/libraries/System.Runtime.Serialization.Formatters/tests/BinaryFormatterTestData.cs +++ b/src/libraries/System.Runtime.Serialization.Formatters/tests/BinaryFormatterTestData.cs @@ -211,7 +211,7 @@ namespace System.Runtime.Serialization.Formatters.Tests yield return new object[] { PopulateException(imageFormatLimitationException), new TypeSerializableValue[] { new TypeSerializableValue("AAEAAAD/////AQAAAAAAAAAMAgAAAF1TeXN0ZW0uUmVmbGVjdGlvbi5NZXRhZGF0YSwgVmVyc2lvbj0xLjQuNC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAADlTeXN0ZW0uUmVmbGVjdGlvbi5NZXRhZGF0YS5JbWFnZUZvcm1hdExpbWl0YXRpb25FeGNlcHRpb24MAAAACUNsYXNzTmFtZQdNZXNzYWdlBERhdGEOSW5uZXJFeGNlcHRpb24HSGVscFVSTBBTdGFja1RyYWNlU3RyaW5nFlJlbW90ZVN0YWNrVHJhY2VTdHJpbmcQUmVtb3RlU3RhY2tJbmRleA9FeGNlcHRpb25NZXRob2QHSFJlc3VsdAZTb3VyY2UNV2F0c29uQnVja2V0cwEBAwMBAQEAAQABBylTeXN0ZW0uQ29sbGVjdGlvbnMuTGlzdERpY3Rpb25hcnlJbnRlcm5hbBBTeXN0ZW0uRXhjZXB0aW9uCAgCAgAAAAYDAAAAOVN5c3RlbS5SZWZsZWN0aW9uLk1ldGFkYXRhLkltYWdlRm9ybWF0TGltaXRhdGlvbkV4Y2VwdGlvbgYEAAAAB21lc3NhZ2UJBQAAAAkGAAAABgcAAAAZaHR0cDovL21zZG4ubWljcm9zb2Z0LmNvbQYIAAAAFFN0YWNrVHJhY2Ugc3RyaW5nLi4uBgkAAAAbUmVtb3RlIFN0YWNrVHJhY2Ugc3RyaW5nLi4uAAAAAAroAwAABgoAAAAXRXhjZXB0aW9uX0NsYXNzX1NhbXBsZXMKBAUAAAApU3lzdGVtLkNvbGxlY3Rpb25zLkxpc3REaWN0aW9uYXJ5SW50ZXJuYWwDAAAABGhlYWQHdmVyc2lvbgVjb3VudAMAADhTeXN0ZW0uQ29sbGVjdGlvbnMuTGlzdERpY3Rpb25hcnlJbnRlcm5hbCtEaWN0aW9uYXJ5Tm9kZQgICQsAAAACAAAAAgAAAAQGAAAAEFN5c3RlbS5FeGNlcHRpb24MAAAACUNsYXNzTmFtZQdNZXNzYWdlBERhdGEOSW5uZXJFeGNlcHRpb24HSGVscFVSTBBTdGFja1RyYWNlU3RyaW5nFlJlbW90ZVN0YWNrVHJhY2VTdHJpbmcQUmVtb3RlU3RhY2tJbmRleA9FeGNlcHRpb25NZXRob2QHSFJlc3VsdAZTb3VyY2UNV2F0c29uQnVja2V0cwEBAwMBAQEAAQABBylTeXN0ZW0uQ29sbGVjdGlvbnMuTGlzdERpY3Rpb25hcnlJbnRlcm5hbBBTeXN0ZW0uRXhjZXB0aW9uCAgCBgwAAAAQU3lzdGVtLkV4Y2VwdGlvbgkEAAAACQ4AAAAJDwAAAAkHAAAACQgAAAAJCQAAAAAAAAAK6AMAAAkKAAAACgQLAAAAOFN5c3RlbS5Db2xsZWN0aW9ucy5MaXN0RGljdGlvbmFyeUludGVybmFsK0RpY3Rpb25hcnlOb2RlAwAAAANrZXkFdmFsdWUEbmV4dAICAzhTeXN0ZW0uQ29sbGVjdGlvbnMuTGlzdERpY3Rpb25hcnlJbnRlcm5hbCtEaWN0aW9uYXJ5Tm9kZQYUAAAABnNlY3JldAgBAQkVAAAAAQ4AAAAFAAAACRYAAAACAAAAAgAAAAEPAAAABgAAAAkMAAAABhgAAAAXSW5uZXIgZXhjZXB0aW9uIG1lc3NhZ2UKCgoKCgAAAAAKABUTgAoKARUAAAALAAAACAgBAAAABhkAAAADb25lCgEWAAAACwAAAAkUAAAACAEBCRsAAAABGwAAAAsAAAAICAEAAAAJGQAAAAoL", TargetFrameworkMoniker.netcoreapp20), new TypeSerializableValue("AAEAAAD/////AQAAAAAAAAAMAgAAAF1TeXN0ZW0uUmVmbGVjdGlvbi5NZXRhZGF0YSwgVmVyc2lvbj0xLjQuNC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAADlTeXN0ZW0uUmVmbGVjdGlvbi5NZXRhZGF0YS5JbWFnZUZvcm1hdExpbWl0YXRpb25FeGNlcHRpb24MAAAACUNsYXNzTmFtZQdNZXNzYWdlBERhdGEOSW5uZXJFeGNlcHRpb24HSGVscFVSTBBTdGFja1RyYWNlU3RyaW5nFlJlbW90ZVN0YWNrVHJhY2VTdHJpbmcQUmVtb3RlU3RhY2tJbmRleA9FeGNlcHRpb25NZXRob2QHSFJlc3VsdAZTb3VyY2UNV2F0c29uQnVja2V0cwEBAwMBAQEAAQABBylTeXN0ZW0uQ29sbGVjdGlvbnMuTGlzdERpY3Rpb25hcnlJbnRlcm5hbBBTeXN0ZW0uRXhjZXB0aW9uCAgCAgAAAAYDAAAAOVN5c3RlbS5SZWZsZWN0aW9uLk1ldGFkYXRhLkltYWdlRm9ybWF0TGltaXRhdGlvbkV4Y2VwdGlvbgYEAAAAB21lc3NhZ2UJBQAAAAkGAAAABgcAAAAZaHR0cDovL21zZG4ubWljcm9zb2Z0LmNvbQYIAAAAFFN0YWNrVHJhY2Ugc3RyaW5nLi4uBgkAAAAbUmVtb3RlIFN0YWNrVHJhY2Ugc3RyaW5nLi4uAAAAAAroAwAABgoAAAAXRXhjZXB0aW9uX0NsYXNzX1NhbXBsZXMKBAUAAAApU3lzdGVtLkNvbGxlY3Rpb25zLkxpc3REaWN0aW9uYXJ5SW50ZXJuYWwDAAAABGhlYWQHdmVyc2lvbgVjb3VudAMAADhTeXN0ZW0uQ29sbGVjdGlvbnMuTGlzdERpY3Rpb25hcnlJbnRlcm5hbCtEaWN0aW9uYXJ5Tm9kZQgICQsAAAACAAAAAgAAAAQGAAAAEFN5c3RlbS5FeGNlcHRpb24MAAAACUNsYXNzTmFtZQdNZXNzYWdlBERhdGEOSW5uZXJFeGNlcHRpb24HSGVscFVSTBBTdGFja1RyYWNlU3RyaW5nFlJlbW90ZVN0YWNrVHJhY2VTdHJpbmcQUmVtb3RlU3RhY2tJbmRleA9FeGNlcHRpb25NZXRob2QHSFJlc3VsdAZTb3VyY2UNV2F0c29uQnVja2V0cwEBAwMBAQEAAQABBylTeXN0ZW0uQ29sbGVjdGlvbnMuTGlzdERpY3Rpb25hcnlJbnRlcm5hbBBTeXN0ZW0uRXhjZXB0aW9uCAgCBgwAAAAQU3lzdGVtLkV4Y2VwdGlvbgkEAAAACQ4AAAAJDwAAAAkHAAAACQgAAAAJCQAAAAAAAAAK6AMAAAkKAAAACgQLAAAAOFN5c3RlbS5Db2xsZWN0aW9ucy5MaXN0RGljdGlvbmFyeUludGVybmFsK0RpY3Rpb25hcnlOb2RlAwAAAANrZXkFdmFsdWUEbmV4dAICAzhTeXN0ZW0uQ29sbGVjdGlvbnMuTGlzdERpY3Rpb25hcnlJbnRlcm5hbCtEaWN0aW9uYXJ5Tm9kZQYUAAAABnNlY3JldAgBAQkVAAAAAQ4AAAAFAAAACRYAAAACAAAAAgAAAAEPAAAABgAAAAkMAAAABhgAAAAXSW5uZXIgZXhjZXB0aW9uIG1lc3NhZ2UKCgoKCgAAAAAKABUTgAoKARUAAAALAAAACAgBAAAABhkAAAADb25lCgEWAAAACwAAAAkUAAAACAEBCRsAAAABGwAAAAsAAAAICAEAAAAJGQAAAAoL", TargetFrameworkMoniker.netfx461) } }; // EventLog is not supported in non Windows. - if (PlatformDetection.IsWindows && !PlatformDetection.IsNetfx462OrNewer && !PlatformDetection.IsUap) + if (PlatformDetection.IsWindows && PlatformDetection.IsNetCore && !PlatformDetection.IsUap) { var channelClosedException = new ChannelClosedException("message", exception); yield return new object[] { PopulateException(channelClosedException), new TypeSerializableValue[] { new TypeSerializableValue("AAEAAAD/////AQAAAAAAAAAMAgAAAFxTeXN0ZW0uVGhyZWFkaW5nLkNoYW5uZWxzLCBWZXJzaW9uPTQuMC4xLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49Y2M3YjEzZmZjZDJkZGQ1MQUBAAAAMFN5c3RlbS5UaHJlYWRpbmcuQ2hhbm5lbHMuQ2hhbm5lbENsb3NlZEV4Y2VwdGlvbgwAAAAJQ2xhc3NOYW1lB01lc3NhZ2UERGF0YQ5Jbm5lckV4Y2VwdGlvbgdIZWxwVVJMEFN0YWNrVHJhY2VTdHJpbmcWUmVtb3RlU3RhY2tUcmFjZVN0cmluZxBSZW1vdGVTdGFja0luZGV4D0V4Y2VwdGlvbk1ldGhvZAdIUmVzdWx0BlNvdXJjZQ1XYXRzb25CdWNrZXRzAQEDAwEBAQABAAEHKVN5c3RlbS5Db2xsZWN0aW9ucy5MaXN0RGljdGlvbmFyeUludGVybmFsEFN5c3RlbS5FeGNlcHRpb24ICAICAAAABgMAAAAwU3lzdGVtLlRocmVhZGluZy5DaGFubmVscy5DaGFubmVsQ2xvc2VkRXhjZXB0aW9uBgQAAAAHbWVzc2FnZQkFAAAACQYAAAAGBwAAABlodHRwOi8vbXNkbi5taWNyb3NvZnQuY29tBggAAAAUU3RhY2tUcmFjZSBzdHJpbmcuLi4GCQAAABtSZW1vdGUgU3RhY2tUcmFjZSBzdHJpbmcuLi4AAAAACugDAAAGCgAAABdFeGNlcHRpb25fQ2xhc3NfU2FtcGxlcwoEBQAAAClTeXN0ZW0uQ29sbGVjdGlvbnMuTGlzdERpY3Rpb25hcnlJbnRlcm5hbAMAAAAEaGVhZAd2ZXJzaW9uBWNvdW50AwAAOFN5c3RlbS5Db2xsZWN0aW9ucy5MaXN0RGljdGlvbmFyeUludGVybmFsK0RpY3Rpb25hcnlOb2RlCAgJCwAAAAIAAAACAAAABAYAAAAQU3lzdGVtLkV4Y2VwdGlvbgwAAAAJQ2xhc3NOYW1lB01lc3NhZ2UERGF0YQ5Jbm5lckV4Y2VwdGlvbgdIZWxwVVJMEFN0YWNrVHJhY2VTdHJpbmcWUmVtb3RlU3RhY2tUcmFjZVN0cmluZxBSZW1vdGVTdGFja0luZGV4D0V4Y2VwdGlvbk1ldGhvZAdIUmVzdWx0BlNvdXJjZQ1XYXRzb25CdWNrZXRzAQEDAwEBAQABAAEHKVN5c3RlbS5Db2xsZWN0aW9ucy5MaXN0RGljdGlvbmFyeUludGVybmFsEFN5c3RlbS5FeGNlcHRpb24ICAIGDAAAABBTeXN0ZW0uRXhjZXB0aW9uCQQAAAAJDgAAAAkPAAAACQcAAAAJCAAAAAkJAAAAAAAAAAroAwAACQoAAAAKBAsAAAA4U3lzdGVtLkNvbGxlY3Rpb25zLkxpc3REaWN0aW9uYXJ5SW50ZXJuYWwrRGljdGlvbmFyeU5vZGUDAAAAA2tleQV2YWx1ZQRuZXh0AgIDOFN5c3RlbS5Db2xsZWN0aW9ucy5MaXN0RGljdGlvbmFyeUludGVybmFsK0RpY3Rpb25hcnlOb2RlBhQAAAAGc2VjcmV0CAEBCRUAAAABDgAAAAUAAAAJFgAAAAIAAAACAAAAAQ8AAAAGAAAACQwAAAAGGAAAABdJbm5lciBleGNlcHRpb24gbWVzc2FnZQoKCgoKAAAAAAoAFROACgoBFQAAAAsAAAAICAEAAAAGGQAAAANvbmUKARYAAAALAAAACRQAAAAIAQEJGwAAAAEbAAAACwAAAAgIAQAAAAkZAAAACgs=", TargetFrameworkMoniker.netcoreapp20) } }; diff --git a/src/libraries/System.Runtime.Serialization.Formatters/tests/BinaryFormatterTests.cs b/src/libraries/System.Runtime.Serialization.Formatters/tests/BinaryFormatterTests.cs index 01cd406..05dfed5 100644 --- a/src/libraries/System.Runtime.Serialization.Formatters/tests/BinaryFormatterTests.cs +++ b/src/libraries/System.Runtime.Serialization.Formatters/tests/BinaryFormatterTests.cs @@ -112,7 +112,7 @@ namespace System.Runtime.Serialization.Formatters.Tests var tmpList = new List(blobs); tmpList.RemoveAt(1); - int index = tmpList.FindIndex(b => b.Platform.IsNetfxPlatform()); + int index = tmpList.FindIndex(b => b.Platform.ToString().StartsWith("netfx")); if (index >= 0) tmpList.RemoveAt(index); diff --git a/src/libraries/System.Runtime.Serialization.Formatters/tests/PlatformExtensions.cs b/src/libraries/System.Runtime.Serialization.Formatters/tests/PlatformExtensions.cs index 2af75a4..6fc965d 100644 --- a/src/libraries/System.Runtime.Serialization.Formatters/tests/PlatformExtensions.cs +++ b/src/libraries/System.Runtime.Serialization.Formatters/tests/PlatformExtensions.cs @@ -11,15 +11,12 @@ namespace System.Runtime.Serialization.Formatters.Tests { internal static class PlatformExtensions { - public static bool IsNetfxPlatform(this TargetFrameworkMoniker targetFrameworkMoniker) + private static bool IsNetFxPatchedVersion(int build) { - switch (targetFrameworkMoniker) + string versionRaw = RuntimeInformation.FrameworkDescription.Replace(".NET Framework", "").Trim(); + if (Version.TryParse(versionRaw, out Version version)) { - case TargetFrameworkMoniker.netfx461: - case TargetFrameworkMoniker.netfx471: - case TargetFrameworkMoniker.netfx472: - case TargetFrameworkMoniker.netfx472_3260: - return true; + return version.Build >= build; } return false; @@ -27,17 +24,6 @@ namespace System.Runtime.Serialization.Formatters.Tests public static int GetPlatformIndex(this TypeSerializableValue[] blobs) { - bool IsNetFxPatchedVersion(int build) - { - string versionRaw = RuntimeInformation.FrameworkDescription.Replace(".NET Framework", "").Trim(); - if (Version.TryParse(versionRaw, out Version version)) - { - return version.Build >= build; - } - - return false; - } - List blobList = blobs.ToList(); int index; @@ -45,7 +31,7 @@ namespace System.Runtime.Serialization.Formatters.Tests if (PlatformDetection.IsFullFramework) { // Check if a specialized blob for >=netfx472 build 3260 is present and return if found. - if (PlatformDetection.IsNetfx472OrNewer && IsNetFxPatchedVersion(3260)) + if (IsNetFxPatchedVersion(3260)) { index = blobList.FindIndex(b => b.Platform == TargetFrameworkMoniker.netfx472_3260); @@ -53,23 +39,13 @@ namespace System.Runtime.Serialization.Formatters.Tests return index; } - // Check if a specialized blob for >=netfx472 is present and return if found. - if (PlatformDetection.IsNetfx472OrNewer) - { - index = blobList.FindIndex(b => b.Platform == TargetFrameworkMoniker.netfx472); - - if (index >= 0) - return index; - } - - // Check if a specialized blob for >=netfx471 is present and return if found. - if (PlatformDetection.IsNetfx471OrNewer) - { - index = blobList.FindIndex(b => b.Platform == TargetFrameworkMoniker.netfx471); + index = blobList.FindIndex(b => b.Platform == TargetFrameworkMoniker.netfx472); + if (index >= 0) + return index; - if (index >= 0) - return index; - } + index = blobList.FindIndex(b => b.Platform == TargetFrameworkMoniker.netfx471); + if (index >= 0) + return index; // If no newer blob for >=netfx471 is present use existing one. // If no netfx blob is present then -1 will be returned. diff --git a/src/libraries/System.Security.Cryptography.Cng/tests/RsaCngTests.cs b/src/libraries/System.Security.Cryptography.Cng/tests/RsaCngTests.cs index 8750e20..84c1855 100644 --- a/src/libraries/System.Security.Cryptography.Cng/tests/RsaCngTests.cs +++ b/src/libraries/System.Security.Cryptography.Cng/tests/RsaCngTests.cs @@ -16,8 +16,6 @@ namespace System.Security.Cryptography.Cng.Tests { public static class RsaCngTests { - public static bool KeySizeTrustsOSValue => !PlatformDetection.IsFullFramework || PlatformDetection.IsNetfx462OrNewer; - [Fact] public static void SignVerifyHashRoundTrip() { @@ -79,7 +77,7 @@ namespace System.Security.Cryptography.Cng.Tests } } - [ConditionalFact(nameof(KeySizeTrustsOSValue))] + [Fact] public static void RSACng_Ctor_UnusualKeysize_384() { const int ExpectedKeySize = 384; @@ -110,7 +108,7 @@ namespace System.Security.Cryptography.Cng.Tests } } - [ConditionalFact(nameof(KeySizeTrustsOSValue))] + [Fact] public static void RSACng_Ctor_UnusualKeysize_1032() { const int ExpectedKeySize = 1032; diff --git a/src/libraries/System.Security.Cryptography.Pkcs/tests/EnvelopedCms/DecryptTests.cs b/src/libraries/System.Security.Cryptography.Pkcs/tests/EnvelopedCms/DecryptTests.cs index c7ae3bc..842c26b 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/tests/EnvelopedCms/DecryptTests.cs +++ b/src/libraries/System.Security.Cryptography.Pkcs/tests/EnvelopedCms/DecryptTests.cs @@ -15,7 +15,6 @@ namespace System.Security.Cryptography.Pkcs.EnvelopedCmsTests.Tests public abstract partial class DecryptTests { private bool _useExplicitPrivateKey; - public static bool SupportsCngCertificates { get; } = (!PlatformDetection.IsFullFramework || PlatformDetection.IsNetfx462OrNewer); public static bool SupportsIndefiniteLengthEncoding { get; } = !PlatformDetection.IsFullFramework; public DecryptTests(bool useExplicitPrivateKey) @@ -23,7 +22,7 @@ namespace System.Security.Cryptography.Pkcs.EnvelopedCmsTests.Tests _useExplicitPrivateKey = useExplicitPrivateKey; } - [ConditionalFact(nameof(SupportsCngCertificates))] + [Fact] [OuterLoop(/* Leaks key on disk if interrupted */)] public void Decrypt_IssuerAndSerial() { @@ -32,7 +31,7 @@ namespace System.Security.Cryptography.Pkcs.EnvelopedCmsTests.Tests TestSimpleDecrypt_RoundTrip(Certificates.RSAKeyTransfer1, contentInfo, Oids.Aes256, SubjectIdentifierType.IssuerAndSerialNumber); } - [ConditionalFact(nameof(SupportsCngCertificates))] + [Fact] [OuterLoop(/* Leaks key on disk if interrupted */)] public void Decrypt_Ski() { @@ -50,7 +49,7 @@ namespace System.Security.Cryptography.Pkcs.EnvelopedCmsTests.Tests TestSimpleDecrypt_RoundTrip(Certificates.RSAKeyTransferCapi1, contentInfo, Oids.Aes256, SubjectIdentifierType.IssuerAndSerialNumber); } - [ConditionalFact(nameof(SupportsCngCertificates))] + [Fact] [OuterLoop(/* Leaks key on disk if interrupted */)] public void Decrypt_256() { @@ -59,7 +58,7 @@ namespace System.Security.Cryptography.Pkcs.EnvelopedCmsTests.Tests TestSimpleDecrypt_RoundTrip(Certificates.RSASha256KeyTransfer1, contentInfo, Oids.Aes256, SubjectIdentifierType.IssuerAndSerialNumber); } - [ConditionalFact(nameof(SupportsCngCertificates))] + [Fact] [OuterLoop(/* Leaks key on disk if interrupted */)] public void Decrypt_384() { @@ -68,7 +67,7 @@ namespace System.Security.Cryptography.Pkcs.EnvelopedCmsTests.Tests TestSimpleDecrypt_RoundTrip(Certificates.RSASha384KeyTransfer1, contentInfo, Oids.Aes256, SubjectIdentifierType.IssuerAndSerialNumber); } - [ConditionalFact(nameof(SupportsCngCertificates))] + [Fact] [OuterLoop(/* Leaks key on disk if interrupted */)] public void Decrypt_512() { @@ -77,7 +76,7 @@ namespace System.Security.Cryptography.Pkcs.EnvelopedCmsTests.Tests TestSimpleDecrypt_RoundTrip(Certificates.RSASha512KeyTransfer1, contentInfo, Oids.Aes256, SubjectIdentifierType.IssuerAndSerialNumber); } - [ConditionalFact(nameof(SupportsCngCertificates))] + [Fact] [OuterLoop("Leaks key on disk if interrupted")] public void Decrypt_512_FixedValue() { @@ -98,7 +97,7 @@ namespace System.Security.Cryptography.Pkcs.EnvelopedCmsTests.Tests VerifySimpleDecrypt(message, Certificates.RSASha512KeyTransfer1, new ContentInfo(content)); } - [ConditionalFact(nameof(SupportsCngCertificates))] + [Fact] [OuterLoop("Leaks key on disk if interrupted")] public void Decrypt_512_NoData_FixedValue() { @@ -127,7 +126,7 @@ namespace System.Security.Cryptography.Pkcs.EnvelopedCmsTests.Tests VerifySimpleDecrypt(message, Certificates.RSASha512KeyTransfer1, new ContentInfo(content)); } - [ConditionalFact(nameof(SupportsCngCertificates))] + [Fact] [OuterLoop("Leaks key on disk if interrupted")] public void Decrypt_512_CekDoesNotDecrypt_FixedValue() { diff --git a/src/libraries/System.Security.Cryptography.Pkcs/tests/EnvelopedCms/DecryptTestsUsingCertWithPrivateKey.cs b/src/libraries/System.Security.Cryptography.Pkcs/tests/EnvelopedCms/DecryptTestsUsingCertWithPrivateKey.cs index e4f9010..2206bdd 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/tests/EnvelopedCms/DecryptTestsUsingCertWithPrivateKey.cs +++ b/src/libraries/System.Security.Cryptography.Pkcs/tests/EnvelopedCms/DecryptTestsUsingCertWithPrivateKey.cs @@ -14,7 +14,7 @@ namespace System.Security.Cryptography.Pkcs.EnvelopedCmsTests.Tests { public DecryptTestsUsingCertWithPrivateKey() : base(false) { } - [ConditionalFact(nameof(SupportsCngCertificates))] + [Fact] [OuterLoop(/* Leaks key on disk if interrupted */)] public static void DecryptMultipleRecipients() { diff --git a/src/libraries/System.Security.Cryptography.Pkcs/tests/EnvelopedCms/EdgeCasesTests.cs b/src/libraries/System.Security.Cryptography.Pkcs/tests/EnvelopedCms/EdgeCasesTests.cs index 8c5d480..eab6420 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/tests/EnvelopedCms/EdgeCasesTests.cs +++ b/src/libraries/System.Security.Cryptography.Pkcs/tests/EnvelopedCms/EdgeCasesTests.cs @@ -15,9 +15,7 @@ namespace System.Security.Cryptography.Pkcs.EnvelopedCmsTests.Tests { public static bool SupportsRc4 { get; } = ContentEncryptionAlgorithmTests.SupportsRc4; - public static bool SupportsCngCertificates { get; } = (!PlatformDetection.IsFullFramework || PlatformDetection.IsNetfx462OrNewer); - - [ConditionalFact(nameof(SupportsCngCertificates))] + [Fact] [OuterLoop(/* Leaks key on disk if interrupted */)] public static void ImportEdgeCase() { @@ -50,7 +48,7 @@ namespace System.Security.Cryptography.Pkcs.EnvelopedCmsTests.Tests } } - [ConditionalFact(nameof(SupportsCngCertificates))] + [Fact] [OuterLoop(/* Leaks key on disk if interrupted */)] public static void ImportEdgeCaseSki() { @@ -130,7 +128,7 @@ namespace System.Security.Cryptography.Pkcs.EnvelopedCmsTests.Tests ValidateZeroLengthContent(encodedMessage); } - [ConditionalFact(nameof(SupportsCngCertificates))] + [Fact] [OuterLoop(/* Leaks key on disk if interrupted */)] public static void ZeroLengthContent_FixedValue() { diff --git a/src/libraries/System.Security.Cryptography.Pkcs/tests/EnvelopedCms/StateTests.cs b/src/libraries/System.Security.Cryptography.Pkcs/tests/EnvelopedCms/StateTests.cs index b3e4af8..3c582a2 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/tests/EnvelopedCms/StateTests.cs +++ b/src/libraries/System.Security.Cryptography.Pkcs/tests/EnvelopedCms/StateTests.cs @@ -21,8 +21,6 @@ namespace System.Security.Cryptography.Pkcs.EnvelopedCmsTests.Tests { public static partial class StateTests { - public static bool SupportsCngCertificates { get; } = (!PlatformDetection.IsFullFramework || PlatformDetection.IsNetfx462OrNewer); - // // Exercises various edge cases when EnvelopedCms methods and properties are called out of the "expected" order. // @@ -274,7 +272,7 @@ namespace System.Security.Cryptography.Pkcs.EnvelopedCmsTests.Tests // // State 4: Called Decode() + Decrypt() // - [ConditionalTheory(nameof(SupportsCngCertificates))] + [Theory] [OuterLoop(/* Leaks key on disk if interrupted */)] [InlineData(false)] #if netcoreapp // API not supported on netfx @@ -323,7 +321,7 @@ namespace System.Security.Cryptography.Pkcs.EnvelopedCmsTests.Tests } } - [ConditionalFact(nameof(SupportsCngCertificates))] + [Fact] [OuterLoop(/* Leaks key on disk if interrupted */)] public static void PostDecrypt_RecipientInfos() { @@ -362,7 +360,7 @@ namespace System.Security.Cryptography.Pkcs.EnvelopedCmsTests.Tests } } - [ConditionalTheory(nameof(SupportsCngCertificates))] + [Theory] [OuterLoop(/* Leaks key on disk if interrupted */)] [InlineData(false)] #if netcoreapp // API not supported on netfx diff --git a/src/libraries/System.Security.Cryptography.Xml/tests/Samples/SigningVerifyingX509Cert.cs b/src/libraries/System.Security.Cryptography.Xml/tests/Samples/SigningVerifyingX509Cert.cs index 66187ac..fe174de 100644 --- a/src/libraries/System.Security.Cryptography.Xml/tests/Samples/SigningVerifyingX509Cert.cs +++ b/src/libraries/System.Security.Cryptography.Xml/tests/Samples/SigningVerifyingX509Cert.cs @@ -20,8 +20,6 @@ namespace System.Security.Cryptography.Xml.Tests some text node "; - private static bool SupportsNewRsaTypes => !PlatformDetection.IsFullFramework || PlatformDetection.IsNetfx462OrNewer; - private static void SignXml(XmlDocument doc, AsymmetricAlgorithm key) { var signedXml = new SignedXml(doc) @@ -61,8 +59,7 @@ namespace System.Security.Cryptography.Xml.Tests return signedXml.CheckSignature(certificate, verifySignatureOnly: true); } - // https://github.com/dotnet/corefx/issues/19270 - [ConditionalFact(nameof(SupportsNewRsaTypes))] + [Fact] public void SignedXmlHasCertificateVerifiableSignature() { using (X509Certificate2 x509cert = TestHelpers.GetSampleX509Certificate()) diff --git a/src/libraries/build.proj b/src/libraries/build.proj index 0711f6f..09b69e0 100644 --- a/src/libraries/build.proj +++ b/src/libraries/build.proj @@ -24,9 +24,6 @@ <_RestoreProjects Include="$(SourceDir)tests.proj" Build="false" /> - - <_RestoreProjects Include="$(SourceDir)CoreFx.Private.TestUtilities\ref\CoreFx.Private.TestUtilities.csproj" Build="false" /> - <_RestoreProjects Include="$(SourceDir)CoreFx.Private.TestUtilities\src\CoreFx.Private.TestUtilities.csproj" Build="false" /> diff --git a/src/libraries/dirs.proj b/src/libraries/dirs.proj index fbe8e15..af8d308 100644 --- a/src/libraries/dirs.proj +++ b/src/libraries/dirs.proj @@ -13,7 +13,7 @@ - + diff --git a/src/libraries/pkg/Microsoft.Private.PackageBaseline/packageIndex.json b/src/libraries/pkg/Microsoft.Private.PackageBaseline/packageIndex.json index 9fa2ca7..d7f3b35 100644 --- a/src/libraries/pkg/Microsoft.Private.PackageBaseline/packageIndex.json +++ b/src/libraries/pkg/Microsoft.Private.PackageBaseline/packageIndex.json @@ -5,13 +5,6 @@ "net45": "4.0.0.0" } }, - "CoreFx.Private.TestUtilities": { - "InboxOn": {}, - "AssemblyVersionInPackageVersion": { - "1.0.0.0": "4.5.0", - "1.0.1.0": "4.6.0" - } - }, "CustomMarshalers": { "InboxOn": { "net45": "4.0.0.0" diff --git a/src/libraries/pkg/descriptions.json b/src/libraries/pkg/descriptions.json index 79c4333..975b3d4 100644 --- a/src/libraries/pkg/descriptions.json +++ b/src/libraries/pkg/descriptions.json @@ -1,10 +1,5 @@ [ { - "Name": "CoreFx.Private.TestUtilities", - "Description": "Private package, which provides testing utility classes. The package is meant to be used when running CoreFX tests on a runtime.", - "CommonTypes": [] - }, - { "Name": "RuntimePackage", "Description": "Internal implementation package not meant for direct consumption. Please do not reference directly.", "CommonTypes": [] diff --git a/src/libraries/pkg/test/testPackages.proj b/src/libraries/pkg/test/testPackages.proj index 9955427..8a16ef9 100644 --- a/src/libraries/pkg/test/testPackages.proj +++ b/src/libraries/pkg/test/testPackages.proj @@ -3,7 +3,6 @@ - diff --git a/src/libraries/pretest.builds b/src/libraries/pretest.builds deleted file mode 100644 index c4a9e52..0000000 --- a/src/libraries/pretest.builds +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - true - - - - - - - - <_TestProjectRootDir>$(SourceDir) - <_TestProjectRootDir Condition="'$(DirectoryToBuild)'!=''">$(DirectoryToBuild) - - - - - - - - - - - - diff --git a/src/libraries/pretest.proj b/src/libraries/pretest.proj new file mode 100644 index 0000000..1ca39a3 --- /dev/null +++ b/src/libraries/pretest.proj @@ -0,0 +1,46 @@ + + + + + + true + + + + + + + + + + + <_TestProjectRootDir>$(SourceDir) + <_TestProjectRootDir Condition="'$(DirectoryToBuild)'!=''">$(DirectoryToBuild) + + + + + + + + + + + + + + + + + + + + -- 2.7.4