diff --git a/src/installer/tests/HostActivation.Tests/DependencyResolution/ResolveComponentDependencies.cs b/src/installer/tests/HostActivation.Tests/DependencyResolution/ResolveComponentDependencies.cs index f931594ccd31a5..ccf81e7cf8760f 100644 --- a/src/installer/tests/HostActivation.Tests/DependencyResolution/ResolveComponentDependencies.cs +++ b/src/installer/tests/HostActivation.Tests/DependencyResolution/ResolveComponentDependencies.cs @@ -74,7 +74,7 @@ public void ComponentWithNoDependenciesCaseChangedOnAsm() // Rename File.Move(fileName, changeFile); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { sharedTestState.RunComponentResolutionTest(component) .Should().Pass() @@ -84,7 +84,7 @@ public void ComponentWithNoDependenciesCaseChangedOnAsm() .And.HaveStdErrContaining($"deps='{component.DepsJson}'") .And.HaveStdErrContaining($"mgd_app='{component.AppDll}'"); } - else if(RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + else if(OperatingSystem.IsMacOS()) { sharedTestState.RunComponentResolutionTest(component) .Should().Pass() @@ -131,7 +131,7 @@ public void ComponentWithNoDependenciesCaseChangedOnDepsAndAsm() File.Move(fileName, changeFile); File.Move(component.DepsJson, changeDepsFile); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { sharedTestState.RunComponentResolutionTest(component) .Should().Pass() @@ -141,7 +141,7 @@ public void ComponentWithNoDependenciesCaseChangedOnDepsAndAsm() .And.HaveStdErrContaining($"deps='{component.DepsJson}'") .And.HaveStdErrContaining($"mgd_app='{component.AppDll}'"); } - else if(RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + else if(OperatingSystem.IsMacOS()) { sharedTestState.RunComponentResolutionTest(component) .Should().Pass() @@ -189,7 +189,7 @@ public void ComponentWithNoDependenciesNoDepsCaseChangedOnAsm() // Delete deps File.Delete(component.DepsJson); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { sharedTestState.RunComponentResolutionTest(component) .Should().Pass() @@ -199,7 +199,7 @@ public void ComponentWithNoDependenciesNoDepsCaseChangedOnAsm() .And.HaveStdErrContaining($"deps='{component.DepsJson}'") .And.HaveStdErrContaining($"mgd_app='{component.AppDll}'"); } - else if(RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + else if(OperatingSystem.IsMacOS()) { sharedTestState.RunComponentResolutionTest(component) .Should().Pass() diff --git a/src/installer/tests/HostActivation.Tests/FrameworkResolution/MultipleHives.cs b/src/installer/tests/HostActivation.Tests/FrameworkResolution/MultipleHives.cs index 2b09b95c8ec95b..0a12cd2640ce9b 100644 --- a/src/installer/tests/HostActivation.Tests/FrameworkResolution/MultipleHives.cs +++ b/src/installer/tests/HostActivation.Tests/FrameworkResolution/MultipleHives.cs @@ -21,14 +21,9 @@ public MultipleHives(SharedTestState sharedState) } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // Multiple hives are only supported on Windows. public void FrameworkHiveSelection_GlobalHiveWithBetterMatch() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // Multiple hives are only supported on Windows. - return; - } - RunTest( runtimeConfig => runtimeConfig .WithFramework(MicrosoftNETCoreApp, "5.0.0")) @@ -36,14 +31,9 @@ public void FrameworkHiveSelection_GlobalHiveWithBetterMatch() } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // Multiple hives are only supported on Windows. public void FrameworkHiveSelection_MainHiveWithBetterMatch() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // Multiple hives are only supported on Windows. - return; - } - RunTest( runtimeConfig => runtimeConfig .WithFramework(MicrosoftNETCoreApp, "6.0.0")) @@ -51,14 +41,9 @@ public void FrameworkHiveSelection_MainHiveWithBetterMatch() } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // Multiple hives are only supported on Windows. public void FrameworkHiveSelection_CurrentDirectoryIsIgnored() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // Multiple hives are only supported on Windows. - return; - } - RunTest( SharedState.DotNetMainHive, SharedState.FrameworkReferenceApp, diff --git a/src/installer/tests/HostActivation.Tests/HostVersionCompatibility.cs b/src/installer/tests/HostActivation.Tests/HostVersionCompatibility.cs index d352a8bdb32f07..ba80b0c7caad29 100644 --- a/src/installer/tests/HostActivation.Tests/HostVersionCompatibility.cs +++ b/src/installer/tests/HostActivation.Tests/HostVersionCompatibility.cs @@ -138,9 +138,9 @@ private static bool IsRidSupported() { // Some current Linux RIDs are not supported in 2.0\2.1; just test for Ubuntu 16. return ( - RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || - RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || - (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && RuntimeInformation.RuntimeIdentifier == "ubuntu.16.04-x64") + OperatingSystem.IsWindows() || + OperatingSystem.IsMacOS() || + (OperatingSystem.IsLinux() && RuntimeInformation.RuntimeIdentifier == "ubuntu.16.04-x64") ); } diff --git a/src/installer/tests/HostActivation.Tests/MultilevelSDKLookup.cs b/src/installer/tests/HostActivation.Tests/MultilevelSDKLookup.cs index d3ddfa2553d731..97b3387604b623 100644 --- a/src/installer/tests/HostActivation.Tests/MultilevelSDKLookup.cs +++ b/src/installer/tests/HostActivation.Tests/MultilevelSDKLookup.cs @@ -89,14 +89,9 @@ public void Dispose() } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // Multi-level lookup is only supported on Windows. public void SdkMultilevelLookup_Global_Json_Single_Digit_Patch_Rollup() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // Multi-level lookup is only supported on Windows. - return; - } - // Set specified SDK version = 9999.3.4-global-dummy SetGlobalJsonVersion("SingleDigit-global.json"); @@ -264,14 +259,9 @@ public void SdkMultilevelLookup_Global_Json_Single_Digit_Patch_Rollup() } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // Multi-level lookup is only supported on Windows. public void SdkMultilevelLookup_Global_Json_Two_Part_Patch_Rollup() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // Multi-level lookup is only supported on Windows. - return; - } - // Set specified SDK version = 9999.3.304-global-dummy SetGlobalJsonVersion("TwoPart-global.json"); @@ -444,14 +434,9 @@ public void SdkMultilevelLookup_Global_Json_Two_Part_Patch_Rollup() } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // Multi-level lookup is only supported on Windows. public void SdkMultilevelLookup_Precedential_Order() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // Multi-level lookup is only supported on Windows. - return; - } - WriteEmptyGlobalJson(); // Add SDK versions @@ -498,6 +483,7 @@ public void SdkMultilevelLookup_Precedential_Order() } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // Multi-level lookup is only supported on Windows. public void SdkMultilevelLookup_RegistryAccess() { // The purpose of this test is to verify that the product uses correct code to access @@ -511,12 +497,6 @@ public void SdkMultilevelLookup_RegistryAccess() // different registry key, inside the HKEY_CURRENT_USER hive which is writable without admin. // Note that the test creates a unique key (based on PID) for every run, to avoid collisions between parallel running tests. - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // Multi-level lookup is only supported on Windows. - return; - } - WriteEmptyGlobalJson(); using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(DotNet.GreatestVersionHostFxrFilePath)) @@ -547,14 +527,9 @@ public void SdkMultilevelLookup_RegistryAccess() } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // Multi-level lookup is only supported on Windows. public void SdkMultilevelLookup_Must_Pick_The_Highest_Semantic_Version() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // Multi-level lookup is only supported on Windows. - return; - } - WriteEmptyGlobalJson(); // Add SDK versions diff --git a/src/installer/tests/HostActivation.Tests/MultilevelSharedFxLookup.cs b/src/installer/tests/HostActivation.Tests/MultilevelSharedFxLookup.cs index f8b4e8bfd402d6..788963fa33e49b 100644 --- a/src/installer/tests/HostActivation.Tests/MultilevelSharedFxLookup.cs +++ b/src/installer/tests/HostActivation.Tests/MultilevelSharedFxLookup.cs @@ -129,14 +129,9 @@ public void Dispose() } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // Multi-level lookup is only supported on Windows. public void SharedMultilevelFxLookup_Must_Verify_Folders_in_the_Correct_Order() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // Multi-level lookup is only supported on Windows. - return; - } - var fixture = SharedFxLookupPortableAppFixture .Copy(); @@ -246,14 +241,9 @@ public void SharedMultilevelFxLookup_Must_Verify_Folders_in_the_Correct_Order() } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // Multi-level lookup is only supported on Windows. public void SharedMultilevelFxLookup_Must_Not_Roll_Forward_If_Framework_Version_Is_Specified_Through_Argument() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // Multi-level lookup is only supported on Windows. - return; - } - var fixture = SharedFxLookupPortableAppFixture .Copy(); diff --git a/src/installer/tests/HostActivation.Tests/NativeHostApis.cs b/src/installer/tests/HostActivation.Tests/NativeHostApis.cs index a213579e5a7186..aaabf8e571bcd2 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHostApis.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHostApis.cs @@ -128,14 +128,9 @@ public SdkResolutionFixture(SharedTestState state) } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // Multi-level lookup is only supported on Windows. public void Hostfxr_get_available_sdks_with_multilevel_lookup() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // multilevel lookup is not supported on non-Windows - return; - } - var f = new SdkResolutionFixture(sharedTestState); // With multi-level lookup (windows only): get local and global sdks sorted by ascending version, @@ -322,14 +317,9 @@ public void Hostfxr_get_dotnet_environment_info_dotnet_root_only() } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // Multi-level lookup is only supported on Windows. public void Hostfxr_get_dotnet_environment_info_with_multilevel_lookup_with_dotnet_root() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // Only Windows supports multi-level lookup. - return; - } - var f = new SdkResolutionFixture(sharedTestState); string expectedSdkVersions = string.Join(';', new[] { @@ -406,14 +396,9 @@ public void Hostfxr_get_dotnet_environment_info_with_multilevel_lookup_with_dotn } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // Multi-level lookup is only supported on Windows. public void Hostfxr_get_dotnet_environment_info_with_multilevel_lookup_only() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // Only Windows supports multi-level lookup. - return; - } - var f = new SdkResolutionFixture(sharedTestState); string expectedSdkVersions = string.Join(';', new[] { @@ -558,7 +543,7 @@ public SharedTestState() .EnsureRestored() .PublishProject(); - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (!OperatingSystem.IsWindows()) { BreadcrumbLocation = Path.Combine( PortableAppWithExceptionFixture.TestProject.OutputDirectory, diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/ApplicationExecution.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/ApplicationExecution.cs index 9c0d1da0a63ea5..cec6b1030e7c7c 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/ApplicationExecution.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/ApplicationExecution.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.DotNet.Cli.Build.Framework; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -101,7 +102,7 @@ public static FluentAssertions.AndConstraint ExecuteApp public static FluentAssertions.AndConstraint ExecuteApplicationWithException(this CommandResultAssertions assertion, string hostPath, string appPath) { var constraint = assertion.ExecuteApplication(hostPath, appPath); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { return constraint.And.HaveStdOutContaining($"hostfxr_run_app threw exception: 0x{Constants.ErrorCode.COMPlusException.ToString("x")}"); } diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/Comhost.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/Comhost.cs index ff15e58b878a44..d48d8439008966 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/Comhost.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/Comhost.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using System.Collections.Generic; using System.IO; using System.Reflection.Metadata; @@ -22,17 +23,12 @@ public Comhost(SharedTestState sharedTestState) } [Theory] + [PlatformSpecific(TestPlatforms.Windows)] // COM activation is only supported on Windows [InlineData(1, true)] [InlineData(10, true)] [InlineData(10, false)] public void ActivateClass(int count, bool synchronous) { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // COM activation is only supported on Windows - return; - } - string [] args = { "comhost", synchronous ? "synchronous" : "concurrent", @@ -53,14 +49,9 @@ public void ActivateClass(int count, bool synchronous) } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // COM activation is only supported on Windows public void ActivateClass_IgnoreAppLocalHostFxr() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // COM activation is only supported on Windows - return; - } - using (var fixture = sharedState.ComLibraryFixture.Copy()) { File.WriteAllText(Path.Combine(fixture.TestProject.BuiltApp.Location, "hostfxr.dll"), string.Empty); @@ -86,14 +77,9 @@ public void ActivateClass_IgnoreAppLocalHostFxr() } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // COM activation is only supported on Windows public void ActivateClass_ValidateIErrorInfoResult() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // COM activation is only supported on Windows - return; - } - using (var fixture = sharedState.ComLibraryFixture.Copy()) { string missingRuntimeConfig = Path.Combine(fixture.TestProject.BuiltApp.Location, @@ -121,14 +107,9 @@ public void ActivateClass_ValidateIErrorInfoResult() } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // COM activation is only supported on Windows public void LoadTypeLibraries() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // COM activation is only supported on Windows - return; - } - using (var fixture = sharedState.ComLibraryFixture.Copy()) { var comHost = Path.Combine( @@ -165,7 +146,7 @@ public class SharedTestState : SharedTestStateBase public SharedTestState() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (!OperatingSystem.IsWindows()) { // COM activation is only supported on Windows return; diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/ComhostSideBySide.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/ComhostSideBySide.cs index 3732e545f4807d..623f93a8fdce5d 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/ComhostSideBySide.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/ComhostSideBySide.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using System.Collections.Generic; using System.IO; using System.Reflection.Metadata; @@ -22,14 +23,9 @@ public ComhostSideBySide(SharedTestState sharedTestState) } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // COM activation is only supported on Windows public void ActivateClass() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // COM activation is only supported on Windows - return; - } - string [] args = { "activation", sharedState.ClsidString @@ -46,14 +42,9 @@ public void ActivateClass() } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // COM activation is only supported on Windows public void LocateEmbeddedTlb() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // COM activation is only supported on Windows - return; - } - string [] args = { "typelib_lookup", sharedState.TypeLibId @@ -77,7 +68,7 @@ public class SharedTestState : Comhost.SharedTestState public SharedTestState() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (!OperatingSystem.IsWindows()) { // COM activation is only supported on Windows return; diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/GetFunctionPointer.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/GetFunctionPointer.cs index 0ac123167732b2..1f741d696e29f5 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/GetFunctionPointer.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/GetFunctionPointer.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.DotNet.Cli.Build.Framework; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -268,7 +269,7 @@ public static FluentAssertions.AndConstraint ExecuteFun public static FluentAssertions.AndConstraint ExecuteFunctionPointerWithException(this CommandResultAssertions assertion, string methodName, int functionPointerCallCount) { var constraint = assertion.ExecuteFunctionPointer(methodName, functionPointerCallCount); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { return constraint.And.HaveStdOutContaining($"{methodName} delegate threw exception: 0x{Constants.ErrorCode.COMPlusException.ToString("x")}"); } diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssemblyAndGetFunctionPointer.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssemblyAndGetFunctionPointer.cs index 53e9eeb52aec93..f329de2229c29a 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssemblyAndGetFunctionPointer.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssemblyAndGetFunctionPointer.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.DotNet.Cli.Build.Framework; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -284,7 +285,7 @@ public static FluentAssertions.AndConstraint ExecuteCom public static FluentAssertions.AndConstraint ExecuteComponentEntryPointWithException(this CommandResultAssertions assertion, string methodName, int componentCallCount) { var constraint = assertion.ExecuteComponentEntryPoint(methodName, componentCallCount); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { return constraint.And.HaveStdOutContaining($"{methodName} delegate threw exception: 0x{Constants.ErrorCode.COMPlusException.ToString("x")}"); } diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/Nethost.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/Nethost.cs index c8f5106b166637..0f18161b026827 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/Nethost.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/Nethost.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.DotNet.Cli.Build.Framework; +using System; using System.IO; using System.Runtime.InteropServices; using Xunit; @@ -178,6 +179,7 @@ public void GetHostFxrPath_HostFxrAlreadyLoaded() } [Theory] + [SkipOnPlatform(TestPlatforms.Windows, "This test targets the install_location config file which is only used on Linux and macOS.")] [InlineData("{0}", true)] [InlineData("{0}\n", true)] [InlineData("{0}\nSome other text", true)] @@ -188,12 +190,6 @@ public void GetHostFxrPath_HostFxrAlreadyLoaded() [InlineData("{0} ", false)] public void GetHostFxrPath_InstallLocationFile(string value, bool shouldPass) { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // This test targets the install_location config file which is only used on Linux and macOS. - return; - } - string installLocation = Path.Combine(sharedState.ValidInstallRoot, "dotnet"); using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(sharedState.NethostPath)) diff --git a/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs b/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs index 79ead8f05f3b07..14060b5e944bfa 100644 --- a/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs +++ b/src/installer/tests/HostActivation.Tests/PortableAppActivation.cs @@ -456,16 +456,11 @@ public void AppHost_CLI_FrameworkDependent_MissingRuntimeFramework_ErrorReported } [Theory] + [PlatformSpecific(TestPlatforms.Windows)] // GUI app host is only supported on Windows. [InlineData(true)] [InlineData(false)] public void AppHost_GUI_FrameworkDependent_MissingRuntimeFramework_ErrorReportedInDialog(bool missingHostfxr) { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // GUI app host is only supported on Windows. - return; - } - var fixture = sharedTestState.PortableAppFixture_Built .Copy(); @@ -521,13 +516,9 @@ public void AppHost_GUI_FrameworkDependent_MissingRuntimeFramework_ErrorReported } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // GUI app host is only supported on Windows. public void AppHost_GUI_NoCustomErrorWriter_FrameworkMissing_ErrorReportedInDialog() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - return; - } - var fixture = sharedTestState.PortableAppFixture_Built .Copy(); @@ -564,14 +555,9 @@ public void AppHost_GUI_NoCustomErrorWriter_FrameworkMissing_ErrorReportedInDial } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // GUI app host is only supported on Windows. public void AppHost_GUI_FrameworkDependent_DisabledGUIErrors_DialogNotShown() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // GUI app host is only supported on Windows. - return; - } - var fixture = sharedTestState.PortableAppFixture_Built .Copy(); diff --git a/src/installer/tests/HostActivation.Tests/RegisteredInstallLocationOverride.cs b/src/installer/tests/HostActivation.Tests/RegisteredInstallLocationOverride.cs index 33ce9f81c3e940..7a30c5d6fd08dc 100644 --- a/src/installer/tests/HostActivation.Tests/RegisteredInstallLocationOverride.cs +++ b/src/installer/tests/HostActivation.Tests/RegisteredInstallLocationOverride.cs @@ -25,7 +25,7 @@ public RegisteredInstallLocationOverride(string productBinaryPath) { _testOnlyProductBehavior = TestOnlyProductBehavior.Enable(productBinaryPath); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { // To test registered installs, we need a registry key which is: // - writable without admin access - so that the tests don't require admin to run @@ -63,7 +63,7 @@ public RegisteredInstallLocationOverride(string productBinaryPath) public void SetInstallLocation(string installLocation, string architecture) { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { using (RegistryKey dotnetLocationKey = key.CreateSubKey($@"Setup\InstalledVersions\{architecture}")) { @@ -78,7 +78,7 @@ public void SetInstallLocation(string installLocation, string architecture) public void Dispose() { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { parentKey.DeleteSubKeyTree(keyName, throwOnMissingSubKey: false); key.Dispose(); @@ -110,7 +110,7 @@ public static Command ApplyRegisteredInstallLocationOverride( return command; } - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { return command.EnvironmentVariable( Constants.TestOnlyEnvironmentVariables.RegistryPath, diff --git a/src/installer/tests/HostActivation.Tests/StandaloneAppActivation.cs b/src/installer/tests/HostActivation.Tests/StandaloneAppActivation.cs index 995aa5f64b9a2c..b7ec6eb9688916 100644 --- a/src/installer/tests/HostActivation.Tests/StandaloneAppActivation.cs +++ b/src/installer/tests/HostActivation.Tests/StandaloneAppActivation.cs @@ -78,7 +78,7 @@ public void Running_Publish_Output_Standalone_EXE_with_Unbound_AppHost_Fails() .Execute(fExpectedToFail: true) .ExitCode; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { exitCode.Should().Be(-2147450731); } @@ -107,7 +107,7 @@ public void Running_Publish_Output_Standalone_EXE_By_Renaming_dotnet_exe_Fails() .Execute(fExpectedToFail: true) .ExitCode; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { exitCode.Should().Be(-2147450748); } @@ -237,14 +237,9 @@ public void Running_Publish_Output_Standalone_EXE_with_Bound_AppHost_Succeeds() } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // GUI app host is only supported on Windows. public void Running_AppHost_with_GUI_No_Console() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // GUI app host is only supported on Windows. - return; - } - var fixture = sharedTestState.StandaloneAppFixture_Published .Copy(); @@ -263,14 +258,9 @@ public void Running_AppHost_with_GUI_No_Console() } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // GUI app host is only supported on Windows. public void Running_AppHost_with_GUI_Traces() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // GUI app host is only supported on Windows. - return; - } - var fixture = sharedTestState.StandaloneAppFixture_Published .Copy(); diff --git a/src/installer/tests/HostActivation.Tests/WindowsSpecificBehavior.cs b/src/installer/tests/HostActivation.Tests/WindowsSpecificBehavior.cs index 4df829ddc049e8..b97f38304f7538 100644 --- a/src/installer/tests/HostActivation.Tests/WindowsSpecificBehavior.cs +++ b/src/installer/tests/HostActivation.Tests/WindowsSpecificBehavior.cs @@ -18,14 +18,9 @@ public WindowsSpecificBehavior(SharedTestState fixture) } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // Manifests are only supported on Windows OSes. public void MuxerRunsPortableAppWithoutWindowsOsShims() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // Manifests are only supported on Windows OSes. - return; - } - TestProjectFixture portableAppFixture = sharedTestState.TestWindowsOsShimsAppFixture.Copy(); portableAppFixture.BuiltDotnet.Exec(portableAppFixture.TestProject.AppDll) @@ -37,13 +32,9 @@ public void MuxerRunsPortableAppWithoutWindowsOsShims() } [Fact] + [PlatformSpecific(TestPlatforms.Windows)] public void FrameworkDependent_DLL_LongPath_Succeeds() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - return; - } - // Long paths must also be enabled via a machine-wide setting. Only run the test if it is enabled. using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\FileSystem")) { diff --git a/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/BundleExtractToSpecificPath.cs b/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/BundleExtractToSpecificPath.cs index 33c895548b2195..4fd8156dcdc37c 100644 --- a/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/BundleExtractToSpecificPath.cs +++ b/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/BundleExtractToSpecificPath.cs @@ -76,7 +76,7 @@ private void Bundle_Extraction_To_Relative_Path_Succeeds(string relativePath, Bu // any forward slashes to the standard Windows dir separator ('\'), thus // failing to create directory trees for bundle extraction that use Unix // style dir separator in Windows. - if (relativePath == "foo/bar" && RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (relativePath == "foo/bar" && OperatingSystem.IsWindows()) return; var fixture = sharedTestState.TestFixture.Copy(); diff --git a/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/BundleLocalizedApp.cs b/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/BundleLocalizedApp.cs index c1c8fbe28d9f8c..5471ed9b444916 100644 --- a/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/BundleLocalizedApp.cs +++ b/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/BundleLocalizedApp.cs @@ -26,7 +26,7 @@ public void Bundled_Localized_App_Run_Succeeds() var fixture = sharedTestState.TestFixture.Copy(); var singleFile = BundleSelfContainedApp(fixture); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { // Set code page to output unicode characters. Command.Create("chcp 65001").Execute(); diff --git a/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/HammerServiceTest.cs b/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/HammerServiceTest.cs index 96c0c7c07baf08..d173883559f7df 100644 --- a/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/HammerServiceTest.cs +++ b/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/HammerServiceTest.cs @@ -21,16 +21,10 @@ public HammerServiceTest(SharedTestState fixture) } [Fact] + [SkipOnPlatform(TestPlatforms.Windows, "On Windows, the hammer servicing location is %ProgramFiles%\\coreservicing. Since writing to this location requires administrative privilege, we do not run the test on Windows.")] private void SingleFile_Apps_Are_Serviced() { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // On Windows, the hammer servicing location is %ProgramFiles%\coreservicing. - // Since writing to this location requires administrative privilege, we do not run the test on Windows. - // On Unix systems, the servicing location is obtained from the environment variable $CORE_SERVICING. - - return; - } + // On Unix systems, the servicing location is obtained from the environment variable $CORE_SERVICING. var fixture = sharedTestState.TestFixture.Copy(); var servicer = sharedTestState.ServiceFixture.Copy(); diff --git a/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.AppHost.Tests/AppHostUpdateTests.cs b/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.AppHost.Tests/AppHostUpdateTests.cs index 5fa06a528fc05d..fc0aedbdfbfd7d 100644 --- a/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.AppHost.Tests/AppHostUpdateTests.cs +++ b/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.AppHost.Tests/AppHostUpdateTests.cs @@ -291,7 +291,7 @@ private static class CoreFxFileStatusProvider static CoreFxFileStatusProvider() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (!OperatingSystem.IsWindows()) { try { diff --git a/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.AppHost.Tests/AppHostUsedWithSymbolicLinks.cs b/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.AppHost.Tests/AppHostUsedWithSymbolicLinks.cs index 991eff791deeef..e00441d92e0cf1 100644 --- a/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.AppHost.Tests/AppHostUsedWithSymbolicLinks.cs +++ b/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.AppHost.Tests/AppHostUsedWithSymbolicLinks.cs @@ -22,14 +22,11 @@ public AppHostUsedWithSymbolicLinks(AppHostUsedWithSymbolicLinks.SharedTestState } [Theory] + [SkipOnPlatform(TestPlatforms.Windows, "Creating symbolic links requires administrative privilege on Windows, so skip test.")] [InlineData ("a/b/SymlinkToApphost")] [InlineData ("a/SymlinkToApphost")] public void Run_apphost_behind_symlink(string symlinkRelativePath) { - // Creating symbolic links requires administrative privilege on Windows, so skip test. - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - return; - var fixture = sharedTestState.StandaloneAppFixture_Published .Copy(); @@ -48,16 +45,13 @@ public void Run_apphost_behind_symlink(string symlinkRelativePath) } [Theory] + [SkipOnPlatform(TestPlatforms.Windows, "Creating symbolic links requires administrative privilege on Windows, so skip test.")] [InlineData ("a/b/FirstSymlink", "c/d/SecondSymlink")] [InlineData ("a/b/FirstSymlink", "c/SecondSymlink")] [InlineData ("a/FirstSymlink", "c/d/SecondSymlink")] [InlineData ("a/FirstSymlink", "c/SecondSymlink")] public void Run_apphost_behind_transitive_symlinks(string firstSymlinkRelativePath, string secondSymlinkRelativePath) { - // Creating symbolic links requires administrative privilege on Windows, so skip test. - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - return; - var fixture = sharedTestState.StandaloneAppFixture_Published .Copy(); @@ -87,12 +81,9 @@ public void Run_apphost_behind_transitive_symlinks(string firstSymlinkRelativePa //[InlineData("a/SymlinkToFrameworkDependentApp")] [Fact(Skip = "Currently failing in OSX with \"No such file or directory\" when running Command.Create. " + "CI failing to use stat on symbolic links on Linux (permission denied).")] + [SkipOnPlatform(TestPlatforms.Windows, "Creating symbolic links requires administrative privilege on Windows, so skip test.")] public void Run_framework_dependent_app_behind_symlink(/*string symlinkRelativePath*/) { - // Creating symbolic links requires administrative privilege on Windows, so skip test. - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - return; - var symlinkRelativePath = string.Empty; var fixture = sharedTestState.FrameworkDependentAppFixture_Published @@ -116,12 +107,9 @@ public void Run_framework_dependent_app_behind_symlink(/*string symlinkRelativeP [Fact(Skip = "Currently failing in OSX with \"No such file or directory\" when running Command.Create. " + "CI failing to use stat on symbolic links on Linux (permission denied).")] + [SkipOnPlatform(TestPlatforms.Windows, "Creating symbolic links requires administrative privilege on Windows, so skip test.")] public void Run_framework_dependent_app_with_runtime_behind_symlink() { - // Creating symbolic links requires administrative privilege on Windows, so skip test. - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - return; - var fixture = sharedTestState.FrameworkDependentAppFixture_Published .Copy(); @@ -141,12 +129,9 @@ public void Run_framework_dependent_app_with_runtime_behind_symlink() } [Fact] + [SkipOnPlatform(TestPlatforms.Windows, "Creating symbolic links requires administrative privilege on Windows, so skip test.")] public void Put_app_directory_behind_symlink() { - // Creating symbolic links requires administrative privilege on Windows, so skip test. - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - return; - var fixture = sharedTestState.StandaloneAppFixture_Published .Copy(); @@ -165,12 +150,9 @@ public void Put_app_directory_behind_symlink() } [Fact] + [SkipOnPlatform(TestPlatforms.Windows, "Creating symbolic links requires administrative privilege on Windows, so skip test.")] public void Put_dotnet_behind_symlink() { - // Creating symbolic links requires administrative privilege on Windows, so skip test. - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - return; - var fixture = sharedTestState.StandaloneAppFixture_Published .Copy(); @@ -189,12 +171,9 @@ public void Put_dotnet_behind_symlink() } [Fact] + [SkipOnPlatform(TestPlatforms.Windows, "Creating symbolic links requires administrative privilege on Windows, so skip test.")] public void Put_app_directory_behind_symlink_and_use_dotnet() { - // Creating symbolic links requires administrative privilege on Windows, so skip test. - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - return; - var fixture = sharedTestState.StandaloneAppFixture_Published .Copy(); @@ -213,12 +192,9 @@ public void Put_app_directory_behind_symlink_and_use_dotnet() } [Fact] + [SkipOnPlatform(TestPlatforms.Windows, "Creating symbolic links requires administrative privilege on Windows, so skip test.")] public void Put_app_directory_behind_symlink_and_use_dotnet_run() { - // Creating symbolic links requires administrative privilege on Windows, so skip test. - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - return; - var fixture = sharedTestState.StandaloneAppFixture_Published .Copy(); @@ -238,14 +214,10 @@ public void Put_app_directory_behind_symlink_and_use_dotnet_run() } [Fact] + // If enabled, this tests will need to set the console code page to output unicode characters: Command.Create("chcp 65001").Execute(); + [SkipOnPlatform(TestPlatforms.Windows, "Creating symbolic links requires administrative privilege on Windows, so skip test.")] public void Put_satellite_assembly_behind_symlink() { - // Creating symbolic links requires administrative privilege on Windows, so skip test. - // If enabled, this tests will need to set the console code page to output unicode characters: - // Command.Create("chcp 65001").Execute(); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - return; - var fixture = sharedTestState.StandaloneAppFixture_Localized .Copy(); diff --git a/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.Bundle.Tests/BundlerConsistencyTests.cs b/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.Bundle.Tests/BundlerConsistencyTests.cs index d8aa3eb1edfb81..75d9e44e961ccd 100644 --- a/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.Bundle.Tests/BundlerConsistencyTests.cs +++ b/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.Bundle.Tests/BundlerConsistencyTests.cs @@ -187,7 +187,7 @@ public void TestBaseNameComputation() // work correctly in the presence of "."s in the hostName. var originalBaseName = "StandaloneApp"; var newBaseName = "Stand.Alone.App"; - var exe = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : string.Empty; + var exe = OperatingSystem.IsWindows() ? ".exe" : string.Empty; void rename(string extension) { diff --git a/src/installer/tests/TestUtils/Command.cs b/src/installer/tests/TestUtils/Command.cs index 1e300d6077ba4e..3c3e5607dde90a 100644 --- a/src/installer/tests/TestUtils/Command.cs +++ b/src/installer/tests/TestUtils/Command.cs @@ -29,7 +29,7 @@ public class Command public Process Process { get; } // Priority order of runnable suffixes to look for and run - private static readonly string[] RunnableSuffixes = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) + private static readonly string[] RunnableSuffixes = OperatingSystem.IsWindows() ? new string[] { ".exe", ".cmd", ".bat" } : new string[] { string.Empty }; @@ -102,7 +102,7 @@ private static void ResolveExecutablePath(ref string executable, ref string args private static bool ShouldUseCmd(string executable) { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { var extension = Path.GetExtension(executable); if (!string.IsNullOrEmpty(extension)) @@ -249,7 +249,7 @@ public Command WorkingDirectory(string projectDirectory) public Command WithUserProfile(string userprofile) { string userDir; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { userDir = "USERPROFILE"; } diff --git a/src/installer/tests/TestUtils/SymbolicLinking.cs b/src/installer/tests/TestUtils/SymbolicLinking.cs index 81ed64bf115d71..bf7dbf45df0c8a 100644 --- a/src/installer/tests/TestUtils/SymbolicLinking.cs +++ b/src/installer/tests/TestUtils/SymbolicLinking.cs @@ -33,7 +33,7 @@ public void Dispose() private static bool MakeSymbolicLink(string symbolicLinkName, string targetFileName, out string errorMessage) { errorMessage = string.Empty; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { if (!CreateSymbolicLink(symbolicLinkName, targetFileName, SymbolicLinkFlag.IsFile)) { diff --git a/src/libraries/Common/src/System/Security/Cryptography/DSACng.cs b/src/libraries/Common/src/System/Security/Cryptography/DSACng.cs index 508fd0c79f3a27..a89f2706a23d43 100644 --- a/src/libraries/Common/src/System/Security/Cryptography/DSACng.cs +++ b/src/libraries/Common/src/System/Security/Cryptography/DSACng.cs @@ -73,7 +73,7 @@ private void ForceSetKeySize(int newKeySize) private static bool Supports2048KeySize() { - Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); + Debug.Assert(OperatingSystem.IsWindows()); Version version = Environment.OSVersion.Version; bool isAtLeastWindows8 = version.Major > 6 || (version.Major == 6 && version.Minor >= 2); return isAtLeastWindows8; diff --git a/src/libraries/Common/tests/System/Net/Capability.Sockets.cs b/src/libraries/Common/tests/System/Net/Capability.Sockets.cs index efef8f64046e80..a28c982032ad9e 100644 --- a/src/libraries/Common/tests/System/Net/Capability.Sockets.cs +++ b/src/libraries/Common/tests/System/Net/Capability.Sockets.cs @@ -25,7 +25,7 @@ private struct RTL_OSVERSIONINFOW public static bool? SocketsReuseUnicastPortSupport() { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { RTL_OSVERSIONINFOW v = default(RTL_OSVERSIONINFOW); v.dwOSVersionInfoSize = (uint)Marshal.SizeOf(); diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/EC/EccTestBase.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/EC/EccTestBase.cs index 16a8cefd84106a..2f347469e12cb9 100644 --- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/EC/EccTestBase.cs +++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/EC/EccTestBase.cs @@ -204,7 +204,7 @@ internal static void CompareCurve(in ECCurve c1, in ECCurve c2) { Assert.True(c2.IsNamed); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || + if (OperatingSystem.IsWindows() || string.IsNullOrEmpty(c1.Oid.Value)) { Assert.Equal(c1.Oid.FriendlyName, c2.Oid.FriendlyName); diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDiffieHellman/ECDiffieHellmanTests.NistValidation.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDiffieHellman/ECDiffieHellmanTests.NistValidation.cs index 46b2187f7fa8d1..7e5d408c4c9aea 100644 --- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDiffieHellman/ECDiffieHellmanTests.NistValidation.cs +++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDiffieHellman/ECDiffieHellmanTests.NistValidation.cs @@ -185,7 +185,7 @@ private static void Verify( // represent the same curve. // // secp256r1 and secp521r1 both succeed this block, secp384r1 fails. - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { throw; } diff --git a/src/libraries/System.Net.Http/tests/StressTests/HttpStress/StressServer.cs b/src/libraries/System.Net.Http/tests/StressTests/HttpStress/StressServer.cs index 1d5dab37ecba37..6012965d2a5097 100644 --- a/src/libraries/System.Net.Http/tests/StressTests/HttpStress/StressServer.cs +++ b/src/libraries/System.Net.Http/tests/StressTests/HttpStress/StressServer.cs @@ -102,7 +102,7 @@ void ConfigureListenOptions(ListenOptions listenOptions) certReq.CertificateExtensions.Add(new X509EnhancedKeyUsageExtension(new OidCollection { new Oid("1.3.6.1.5.5.7.3.1") }, false)); certReq.CertificateExtensions.Add(new X509KeyUsageExtension(X509KeyUsageFlags.DigitalSignature, false)); X509Certificate2 cert = certReq.CreateSelfSigned(DateTimeOffset.UtcNow.AddMonths(-1), DateTimeOffset.UtcNow.AddMonths(1)); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { cert = new X509Certificate2(cert.Export(X509ContentType.Pfx)); } diff --git a/src/libraries/System.Net.Security/tests/StressTests/SslStress/SslServerBase.cs b/src/libraries/System.Net.Security/tests/StressTests/SslStress/SslServerBase.cs index 56ba32e7c0363c..f43cfb4d5b8588 100644 --- a/src/libraries/System.Net.Security/tests/StressTests/SslStress/SslServerBase.cs +++ b/src/libraries/System.Net.Security/tests/StressTests/SslStress/SslServerBase.cs @@ -158,7 +158,7 @@ protected virtual X509Certificate2 CreateSelfSignedCertificate() certReq.CertificateExtensions.Add(new X509EnhancedKeyUsageExtension(new OidCollection { new Oid("1.3.6.1.5.5.7.3.1") }, false)); certReq.CertificateExtensions.Add(new X509KeyUsageExtension(X509KeyUsageFlags.DigitalSignature, false)); X509Certificate2 cert = certReq.CreateSelfSigned(DateTimeOffset.UtcNow.AddMonths(-1), DateTimeOffset.UtcNow.AddMonths(1)); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { cert = new X509Certificate2(cert.Export(X509ContentType.Pfx)); } diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/CreateSocketTests.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/CreateSocketTests.cs index 7252fb847cdad7..334280938e0a0f 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/CreateSocketTests.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/CreateSocketTests.cs @@ -312,8 +312,8 @@ public void Ctor_SafeHandle_BasicPropertiesPropagate_Success(AddressFamily addre if (copy.IsBound) { // On Unix, we may successfully obtain an (empty) local end point, even though Bind wasn't called. - Debug.Assert(!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) // OSX gets some strange results in some cases, e.g. "@\0\0\0\0\0\0\0\0\0\0\0\0\0" for a UDS + Debug.Assert(!OperatingSystem.IsWindows()); + if (OperatingSystem.IsLinux()) // OSX gets some strange results in some cases, e.g. "@\0\0\0\0\0\0\0\0\0\0\0\0\0" for a UDS { switch (addressFamily) { diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/DualModeSocketTest.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/DualModeSocketTest.cs index 600ae16628985e..eb229d9d37e3f4 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/DualModeSocketTest.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/DualModeSocketTest.cs @@ -154,7 +154,7 @@ private void DualModeConnect_IPAddressToHost_Fails_Helper(IPAddress connectTo, I Assert.ThrowsAny(() => { DualModeConnect_IPAddressToHost_Helper(connectTo, listenOn, false); - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (!OperatingSystem.IsWindows()) { // On Unix, socket assignment is random (not incremental) and there is a small chance the // listening socket was created in another test currently running. Try the test one more time. @@ -245,7 +245,7 @@ private void DualModeConnect_IPEndPointToHost_Fails_Helper(IPAddress connectTo, Assert.ThrowsAny(() => { DualModeConnect_IPEndPointToHost_Helper(connectTo, listenOn, false); - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (!OperatingSystem.IsWindows()) { // On Unix, socket assignment is random (not incremental) and there is a small chance the // listening socket was created in another test currently running. Try the test one more time. @@ -384,7 +384,7 @@ private async Task DualModeBeginConnect_IPAddressToHost_Fails_Helper(IPAddress c SocketException e = await Assert.ThrowsAnyAsync(async () => { await DualModeBeginConnect_IPAddressToHost_Helper(connectTo, listenOn, false); - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (!OperatingSystem.IsWindows()) { // On Unix, socket assignment is random (not incremental) and there is a small chance the // listening socket was created in another test currently running. Try the test one more time. @@ -565,7 +565,7 @@ private void DualModeConnectAsync_IPEndPointToHost_Fails_Helper(IPAddress connec Assert.ThrowsAny(() => { DualModeConnectAsync_IPEndPointToHost_Helper(connectTo, listenOn, false); - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (!OperatingSystem.IsWindows()) { // On Unix, socket assignment is random (not incremental) and there is a small chance the // listening socket was created in another test currently running. Try the test one more time. @@ -1239,11 +1239,11 @@ public void Socket_SendToAsyncV4IPEndPointToV4Host_Throws() bool async = socket.SendToAsync(args); Assert.False(async); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { Assert.Equal(SocketError.Fault, args.SocketError); } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + else if (OperatingSystem.IsLinux()) { // NOTE: on Linux, this API returns ENETUNREACH instead of EFAULT: this platform // checks the family of the provided socket address before checking its size @@ -2015,7 +2015,7 @@ private void ReceiveMessageFrom_Helper(IPAddress listenOn, IPAddress connectTo, serverSocket.ReceiveTimeout = TestSettings.FailingTestTimeout; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { Assert.Throws(() => { @@ -2469,11 +2469,11 @@ private static bool GetLocalhostIsBothIPv4AndIPv6() protected static void AssertDualModeEnabled(Socket socket, IPAddress listenOn) { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { Assert.True(socket.DualMode); } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD)) + else if (OperatingSystem.IsFreeBSD()) { // This is not valid check on FreeBSD. // Accepted socket is never DualMode and cannot be changed. diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/NetworkStreamTest.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/NetworkStreamTest.cs index 05f7f9b8c1d6d2..52022c5da82164 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/NetworkStreamTest.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/NetworkStreamTest.cs @@ -414,7 +414,7 @@ await RunWithConnectedNetworkStreamsAsync(async (stream, _) => // socket is closed. On Unix, it's completed as successful once or after // the shutdown is issued, but depending on timing, if it's then closed // before that takes effect, it may also complete as aborted. - bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + bool isWindows = OperatingSystem.IsWindows(); Assert.True( (isWindows && e is IOException) || (!isWindows && (e == null || e is IOException)), diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketOptionNameTest.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketOptionNameTest.cs index a504f3957dd3b2..eccff0d22d6302 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketOptionNameTest.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketOptionNameTest.cs @@ -263,7 +263,7 @@ public void FailedConnect_GetSocketOption_SocketOptionNameError(bool simpleGet) Assert.Equal((int)SocketError.ConnectionRefused, errorCode); // Then get it again - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { // The Windows implementation doesn't clear the error code after retrieved. // https://github.com/dotnet/runtime/issues/17260 @@ -431,14 +431,14 @@ public unsafe void ReuseAddressUdp() // that allow binding the same address. int SOL_SOCKET = -1; int option = -1; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + if (OperatingSystem.IsLinux()) { // Linux: use SO_REUSEADDR to allow binding the same address. SOL_SOCKET = 1; const int SO_REUSEADDR = 2; option = SO_REUSEADDR; } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + else if (OperatingSystem.IsMacOS()) { // BSD: use SO_REUSEPORT to allow binding the same address. SOL_SOCKET = 0xffff; @@ -514,13 +514,13 @@ public void GetSetRawSocketOption_Roundtrips(AddressFamily family) int SOL_SOCKET; int SO_RCVBUF; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || - RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + if (OperatingSystem.IsWindows() || + OperatingSystem.IsMacOS()) { SOL_SOCKET = 0xffff; SO_RCVBUF = 0x1002; } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + else if (OperatingSystem.IsLinux()) { SOL_SOCKET = 1; SO_RCVBUF = 8; @@ -534,7 +534,7 @@ public void GetSetRawSocketOption_Roundtrips(AddressFamily family) { const int SetSize = 8192; int ExpectedGetSize = - RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? SetSize * 2 : // Linux kernel documented to double the size + OperatingSystem.IsLinux() ? SetSize * 2 : // Linux kernel documented to double the size SetSize; socket.SetRawSocketOption(SOL_SOCKET, SO_RCVBUF, BitConverter.GetBytes(SetSize)); diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/UnixDomainSocketTest.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/UnixDomainSocketTest.cs index 35486516aec121..da2d4d67ba39af 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/UnixDomainSocketTest.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/UnixDomainSocketTest.cs @@ -108,7 +108,7 @@ public async Task Socket_ConnectAsyncUnixDomainSocketEndPoint_NotServer() } Assert.Equal( - RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? SocketError.ConnectionRefused : SocketError.AddressNotAvailable, + OperatingSystem.IsWindows() ? SocketError.ConnectionRefused : SocketError.AddressNotAvailable, args.SocketError); } } @@ -421,7 +421,7 @@ public void UnixDomainSocketEndPoint_RemoteEndPointEqualsBindAddress(bool abstra if (abstractAddress) { // abstract socket addresses are a Linux feature. - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + if (!OperatingSystem.IsLinux()) { return; } @@ -518,7 +518,7 @@ private static bool PlatformSupportsUnixDomainSockets { get { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { try { diff --git a/src/libraries/System.Security.Cryptography.X509Certificates/tests/DynamicChainTests.cs b/src/libraries/System.Security.Cryptography.X509Certificates/tests/DynamicChainTests.cs index 1b224441a0b092..2fe04218e09d08 100644 --- a/src/libraries/System.Security.Cryptography.X509Certificates/tests/DynamicChainTests.cs +++ b/src/libraries/System.Security.Cryptography.X509Certificates/tests/DynamicChainTests.cs @@ -631,7 +631,7 @@ public static void MismatchKeyIdentifiers() chain.ChainPolicy.CustomTrustStore.Add(rootCert); chain.ChainPolicy.ExtraStore.Add(intermediateCert); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + if (OperatingSystem.IsLinux()) { Assert.False(chain.Build(endEntityCert), "chain.Build"); Assert.Equal(X509ChainStatusFlags.PartialChain, chain.AllStatusFlags()); diff --git a/src/tests/Common/CoreCLRTestLibrary/Utilities.cs b/src/tests/Common/CoreCLRTestLibrary/Utilities.cs index ffd9f00da0bda5..bd1eb1be37de73 100644 --- a/src/tests/Common/CoreCLRTestLibrary/Utilities.cs +++ b/src/tests/Common/CoreCLRTestLibrary/Utilities.cs @@ -62,9 +62,9 @@ public static bool Verbose public static bool IsArm => (RuntimeInformation.ProcessArchitecture == Architecture.Arm); public static bool IsArm64 => (RuntimeInformation.ProcessArchitecture == Architecture.Arm64); - public static bool IsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); - public static bool IsLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); - public static bool IsMacOSX => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); + public static bool IsWindows => OperatingSystem.IsWindows(); + public static bool IsLinux => OperatingSystem.IsLinux(); + public static bool IsMacOSX => OperatingSystem.IsMacOS(); public static bool IsWindows7 => IsWindows && Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 1; public static bool IsWindowsNanoServer => (!IsWindowsIoTCore && GetInstallationType().Equals("Nano Server", StringComparison.OrdinalIgnoreCase)); diff --git a/src/tests/Common/Coreclr.TestWrapper/CoreclrTestWrapperLib.cs b/src/tests/Common/Coreclr.TestWrapper/CoreclrTestWrapperLib.cs index 22c606728ac701..074eb1a2df3c99 100644 --- a/src/tests/Common/Coreclr.TestWrapper/CoreclrTestWrapperLib.cs +++ b/src/tests/Common/Coreclr.TestWrapper/CoreclrTestWrapperLib.cs @@ -78,15 +78,15 @@ internal static class ProcessExtensions public unsafe static IEnumerable GetChildren(this Process process) { var children = new List(); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { return Windows_GetChildren(process); } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + else if (OperatingSystem.IsLinux()) { return Linux_GetChildren(process); } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + else if (OperatingSystem.IsMacOS()) { return MacOS_GetChildren(process); } @@ -210,12 +210,12 @@ static bool CollectCrashDump(Process process, string path) string arguments = $"--name \"{path}\" {process.Id} --withheap"; Process createdump = new Process(); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { createdump.StartInfo.FileName = createdumpPath + ".exe"; createdump.StartInfo.Arguments = arguments; } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) { createdump.StartInfo.FileName = "sudo"; createdump.StartInfo.Arguments = $"{createdumpPath} " + arguments; @@ -305,7 +305,7 @@ public int RunTest(string executable, string outputFile, string errorFile, strin using (Process process = new Process()) { // Windows can run the executable implicitly - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { process.StartInfo.FileName = executable; } diff --git a/src/tests/CoreMangLib/system/runtime/interopservices/marshal/marshalsizeof1.cs b/src/tests/CoreMangLib/system/runtime/interopservices/marshal/marshalsizeof1.cs index b600f3d66de27c..5cd2fd3a5aeda6 100644 --- a/src/tests/CoreMangLib/system/runtime/interopservices/marshal/marshalsizeof1.cs +++ b/src/tests/CoreMangLib/system/runtime/interopservices/marshal/marshalsizeof1.cs @@ -226,7 +226,7 @@ public bool PosTest4() obj.TestDouble = TestLibrary.Generator.GetDouble(-55); int expectedSize; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || (RuntimeInformation.ProcessArchitecture != Architecture.X86)) + if (OperatingSystem.IsWindows() || (RuntimeInformation.ProcessArchitecture != Architecture.X86)) { expectedSize = 16; // sizeof(double) + sizeof(int) + padding } diff --git a/src/tests/CoreMangLib/system/runtime/interopservices/marshal/marshalsizeof2.cs b/src/tests/CoreMangLib/system/runtime/interopservices/marshal/marshalsizeof2.cs index 59bc6dbe9fb539..3b3f9c8ac35d80 100644 --- a/src/tests/CoreMangLib/system/runtime/interopservices/marshal/marshalsizeof2.cs +++ b/src/tests/CoreMangLib/system/runtime/interopservices/marshal/marshalsizeof2.cs @@ -211,7 +211,7 @@ public bool PosTest4() Type obj = typeof(TestMultiMemberStruct1); int expectedSize; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || (RuntimeInformation.ProcessArchitecture != Architecture.X86)) + if (OperatingSystem.IsWindows() || (RuntimeInformation.ProcessArchitecture != Architecture.X86)) { expectedSize = 16; // sizeof(double) + sizeof(int) + padding } diff --git a/src/tests/GC/LargeMemory/memcheck.cs b/src/tests/GC/LargeMemory/memcheck.cs index 793b941fcb4240..5fbda715390228 100644 --- a/src/tests/GC/LargeMemory/memcheck.cs +++ b/src/tests/GC/LargeMemory/memcheck.cs @@ -37,7 +37,7 @@ public static uint LimitByAvailableMemMB(uint sizeMB, uint defaultMB = 300) } private static uint? TryGetPhysicalMemMB() => - RuntimeInformation.IsOSPlatform(OSPlatform.Windows) + OperatingSystem.IsWindows() ? TryGetPhysicalMemMBWindows() : TryGetPhysicalMemMBNonWindows(); diff --git a/src/tests/Interop/COM/Reflection/Reflection.cs b/src/tests/Interop/COM/Reflection/Reflection.cs index cccb9625937caa..d850e9c5b61375 100644 --- a/src/tests/Interop/COM/Reflection/Reflection.cs +++ b/src/tests/Interop/COM/Reflection/Reflection.cs @@ -76,7 +76,7 @@ static bool ActivateCOMType() var contextMenu = (NETServer.ContextMenu)Activator.CreateInstance(typeof(NETServer.ContextMenu)); // Non-Windows should throw PlatformNotSupportedException - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (!OperatingSystem.IsWindows()) { return false; } @@ -89,11 +89,11 @@ static bool ActivateCOMType() return true; } - catch (PlatformNotSupportedException) when (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + catch (PlatformNotSupportedException) when (!OperatingSystem.IsWindows()) { return true; } - catch (COMException) when (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + catch (COMException) when (OperatingSystem.IsWindows()) { return true; } diff --git a/src/tests/Interop/DllImportAttribute/DllImportPath/DllImportPathTest.cs b/src/tests/Interop/DllImportAttribute/DllImportPath/DllImportPathTest.cs index 8a53250d4442e3..c83295d89292a4 100644 --- a/src/tests/Interop/DllImportAttribute/DllImportPath/DllImportPathTest.cs +++ b/src/tests/Interop/DllImportAttribute/DllImportPath/DllImportPathTest.cs @@ -66,7 +66,7 @@ static void TestNativeLibraryProbingOnLocalPath() GetZero_Local1(); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { GetZero_Local2(); @@ -80,7 +80,7 @@ static void TestNativeLibraryProbingOnRelativePath() { string strManaged = "Managed"; string native = " Native"; - bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + bool isWindows = OperatingSystem.IsWindows(); if (!isWindows) // We need to ensure that the subdirectory exists for off-Windows. { @@ -98,7 +98,7 @@ static void TestNativeLibraryProbingOnRelativePath() GetZero_Relative1Unix(); } - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { GetZero_Relative2(); } @@ -112,7 +112,7 @@ static void TestNativeLibraryProbingOnRelativePath() GetZero_Relative3Unix(); } - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { GetZero_Relative4(); } @@ -174,12 +174,12 @@ public static int Main(string[] args) { TestNativeLibraryProbingOnLocalPath(); TestNativeLibraryProbingOnRelativePath(); - if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) // This test fails due to a bug in OSX 10.12 combined with the weird way that HFS+ handles unicode file names + if (!OperatingSystem.IsMacOS()) // This test fails due to a bug in OSX 10.12 combined with the weird way that HFS+ handles unicode file names { TestNativeLibraryProbingUnicode(); } TestNativeLibraryProbingOnPathEnv(); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { TestNativeExeProbing(); } diff --git a/src/tests/Interop/DllImportAttribute/ExactSpelling/ExactSpellingTest.cs b/src/tests/Interop/DllImportAttribute/ExactSpelling/ExactSpellingTest.cs index 3db1b9ceeaf96c..929f2b7518765f 100644 --- a/src/tests/Interop/DllImportAttribute/ExactSpelling/ExactSpellingTest.cs +++ b/src/tests/Interop/DllImportAttribute/ExactSpelling/ExactSpellingTest.cs @@ -130,7 +130,7 @@ public static int Main(string[] args) try { ExactSpellingTrue(); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { ExactSpellingFalse_Windows(); } diff --git a/src/tests/Interop/NativeLibrary/NativeLibraryToLoad/NativeLibraryToLoad.cs b/src/tests/Interop/NativeLibrary/NativeLibraryToLoad/NativeLibraryToLoad.cs index c9ad4a09845c61..4a61c599961f5a 100644 --- a/src/tests/Interop/NativeLibrary/NativeLibraryToLoad/NativeLibraryToLoad.cs +++ b/src/tests/Interop/NativeLibrary/NativeLibraryToLoad/NativeLibraryToLoad.cs @@ -13,13 +13,13 @@ public class NativeLibraryToLoad public static string GetFileName() { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) return $"{Name}.dll"; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + if (OperatingSystem.IsLinux()) return $"lib{Name}.so"; - if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + if (OperatingSystem.IsMacOS()) return $"lib{Name}.dylib"; throw new PlatformNotSupportedException(); diff --git a/src/tests/Interop/PInvoke/Array/MarshalArrayAsField/AsByValArray/AsByValArrayTest.cs b/src/tests/Interop/PInvoke/Array/MarshalArrayAsField/AsByValArray/AsByValArrayTest.cs index 7649c8e0f0e3a6..036f282ef685f3 100644 --- a/src/tests/Interop/PInvoke/Array/MarshalArrayAsField/AsByValArray/AsByValArrayTest.cs +++ b/src/tests/Interop/PInvoke/Array/MarshalArrayAsField/AsByValArray/AsByValArrayTest.cs @@ -851,7 +851,7 @@ static void RunTest1(string report) s12.arr = InitArray(ARRAY_SIZE); Assert.IsTrue(TakeLPCSTRArraySeqStructByVal(s12, s12.arr.Length),"TakeLPCSTRArraySeqStructByVal"); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { S_BSTRArray_Seq s13 = new S_BSTRArray_Seq(); s13.arr = InitArray(ARRAY_SIZE); @@ -939,7 +939,7 @@ static void RunTest2(string report) c12.arr = InitArray(ARRAY_SIZE); Assert.IsTrue(TakeLPCSTRArraySeqClassByVal(c12, c12.arr.Length)); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { C_BSTRArray_Seq c13 = new C_BSTRArray_Seq(); c13.arr = InitArray(ARRAY_SIZE); @@ -1004,7 +1004,7 @@ static void RunTest3(string report) Assert.IsTrue(TakeLPCSTRArrayExpStructByVal(s12, s12.arr.Length)); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { S_BSTRArray_Exp c13 = new S_BSTRArray_Exp(); c13.arr = InitArray(ARRAY_SIZE); @@ -1068,7 +1068,7 @@ static void RunTest4(string report) c12.arr = InitArray(ARRAY_SIZE); Assert.IsTrue(TakeLPCSTRArrayExpClassByVal(c12, c12.arr.Length)); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { C_BSTRArray_Exp c13 = new C_BSTRArray_Exp(); c13.arr = InitArray(ARRAY_SIZE); @@ -1120,7 +1120,7 @@ static void RunTest5(string report) C_LPSTRArray_Seq retval11 = S_LPSTRArray_Ret(); Assert.IsTrue(Equals(InitArray(ARRAY_SIZE), retval11.arr)); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { C_BSTRArray_Seq retval12 = S_BSTRArray_Ret(); Assert.IsTrue(Equals(InitArray(ARRAY_SIZE), retval12.arr)); @@ -1167,7 +1167,7 @@ static void RunTest6(string report) C_LPSTRArray_Exp retval11 = S_LPSTRArray_Ret2(); Assert.IsTrue(Equals(InitArray(ARRAY_SIZE), retval11.arr)); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { C_BSTRArray_Exp retval12 = S_BSTRArray_Ret2(); Assert.IsTrue(Equals(InitArray(ARRAY_SIZE), retval12.arr)); @@ -1183,7 +1183,7 @@ static int Main(string[] args) { RunTest1("RunTest1 : Marshal array as field as ByValArray in sequential struct as parameter."); RunTest2("RunTest2 : Marshal array as field as ByValArray in sequential class as parameter."); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { RunTest3("RunTest3 : Marshal array as field as ByValArray in explicit struct as parameter."); } diff --git a/src/tests/Interop/PInvoke/Array/MarshalArrayAsField/AsLPArray/AsLPArrayTest.cs b/src/tests/Interop/PInvoke/Array/MarshalArrayAsField/AsLPArray/AsLPArrayTest.cs index 4fbd6d9658754f..70b9618e57752a 100644 --- a/src/tests/Interop/PInvoke/Array/MarshalArrayAsField/AsLPArray/AsLPArrayTest.cs +++ b/src/tests/Interop/PInvoke/Array/MarshalArrayAsField/AsLPArray/AsLPArrayTest.cs @@ -218,7 +218,7 @@ static void RunTest1(string report) s12.arr = InitArray(ARRAY_SIZE); Assert.Throws(() => TakeLPCSTRArraySeqStructByVal(s12, ARRAY_SIZE), "TakeLPCSTRArraySeqStructByVal"); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { S_BSTRArray_Seq s13 = new S_BSTRArray_Seq(); s13.arr = InitArray(ARRAY_SIZE); @@ -281,7 +281,7 @@ static void RunTest2(string report) c12.arr = InitArray(ARRAY_SIZE); Assert.Throws(() => TakeLPCSTRArraySeqClassByVal(c12, ARRAY_SIZE), "TakeLPCSTRArraySeqClassByVal"); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { C_BSTRArray_Seq c13 = new C_BSTRArray_Seq(); c13.arr = InitArray(ARRAY_SIZE); @@ -345,7 +345,7 @@ static void RunTest3(string report) s12.arr = InitArray(ARRAY_SIZE); Assert.Throws(() => TakeLPCSTRArrayExpStructByVal(s12, ARRAY_SIZE), "TakeLPCSTRArrayExpStructByVal"); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { S_BSTRArray_Exp s13 = new S_BSTRArray_Exp(); s13.arr = InitArray(ARRAY_SIZE); @@ -409,7 +409,7 @@ static void RunTest4(string report) c12.arr = InitArray(ARRAY_SIZE); Assert.Throws(() => TakeLPCSTRArrayExpClassByVal(c12, ARRAY_SIZE), "TakeLPCSTRArrayExpClassByVal"); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { C_BSTRArray_Exp c13 = new C_BSTRArray_Exp(); c13.arr = InitArray(ARRAY_SIZE); @@ -427,7 +427,7 @@ static int Main(string[] args) { RunTest1("RunTest 1 : Marshal Array In Sequential Struct As LPArray. "); RunTest2("RunTest 2 : Marshal Array In Sequential Class As LPArray. "); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { RunTest3("RunTest 3 : Marshal Array In Explicit Struct As LPArray. "); } diff --git a/src/tests/Interop/PInvoke/Array/MarshalArrayAsParam/AsDefault/AsDefaultTest.cs b/src/tests/Interop/PInvoke/Array/MarshalArrayAsParam/AsDefault/AsDefaultTest.cs index 8ae8690c03c8a7..d30ef8bf9a2e73 100644 --- a/src/tests/Interop/PInvoke/Array/MarshalArrayAsParam/AsDefault/AsDefaultTest.cs +++ b/src/tests/Interop/PInvoke/Array/MarshalArrayAsParam/AsDefault/AsDefaultTest.cs @@ -334,7 +334,7 @@ private static void TestMarshalByVal_NoAttributes() Assert.IsTrue(CStyle_Array_Bool(InitBoolArray(ARRAY_SIZE), ARRAY_SIZE), "CStyle_Array_Bool"); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { object[] oArr = InitArray(ARRAY_SIZE); // Test nesting null value scenario @@ -366,7 +366,7 @@ private static void TestMarshalByVal_In() Assert.IsTrue(CStyle_Array_LPSTR_In(strArr, ARRAY_SIZE), "CStyle_Array_LPSTR_In"); Assert.IsTrue(CStyle_Array_Struct_In(InitStructArray(ARRAY_SIZE), ARRAY_SIZE), "CStyle_Array_Struct_In"); Assert.IsTrue(CStyle_Array_Bool_In(InitBoolArray(ARRAY_SIZE), ARRAY_SIZE), "CStyle_Array_Bool_In"); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { object[] oArr = InitArray(ARRAY_SIZE); // Test nesting null value scenario @@ -461,7 +461,7 @@ private static void TestMarshalInOut_ByVal() Assert.IsTrue(CStyle_Array_Bool_InOut(boolArr, ARRAY_SIZE), "CStyle_Array_Bool_InOut"); Assert.IsTrue(Equals(boolArr, GetExpectedOutBoolArray(ARRAY_SIZE)), "CStyle_Array_Bool_InOut:Equals"); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { Console.WriteLine("CStyle_Array_Object_InOut"); object[] oArr = InitArray(ARRAY_SIZE); @@ -624,7 +624,7 @@ private static void TestMarshalOut_ByVal() Assert.IsTrue(CStyle_Array_Bool_Out(boolArr, ARRAY_SIZE), "CStyle_Array_Bool_Out"); Assert.IsTrue(Equals(boolArr, GetExpectedOutBoolArray(ARRAY_SIZE)), "CStyle_Array_Bool_Out:Equals"); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { Console.WriteLine("CStyle_Array_Object_Out"); object[] oArr = new object[ARRAY_SIZE]; diff --git a/src/tests/Interop/PInvoke/Array/MarshalArrayAsParam/AsLPArray/AsLPArrayTest.cs b/src/tests/Interop/PInvoke/Array/MarshalArrayAsParam/AsLPArray/AsLPArrayTest.cs index dfd2f88ef5386f..b152744d89cbe0 100644 --- a/src/tests/Interop/PInvoke/Array/MarshalArrayAsParam/AsLPArray/AsLPArrayTest.cs +++ b/src/tests/Interop/PInvoke/Array/MarshalArrayAsParam/AsLPArray/AsLPArrayTest.cs @@ -316,7 +316,7 @@ private static void TestMarshalByVal_NoAttributes() Assert.IsTrue(CStyle_Array_Struct(InitStructArray(ARRAY_SIZE), ARRAY_SIZE), "CStyle_Array_Struct"); Assert.IsTrue(CStyle_Array_Bool(InitBoolArray(ARRAY_SIZE), ARRAY_SIZE), "CStyle_Array_Bool"); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { object[] oArr = InitArray(ARRAY_SIZE); // Test nesting null value scenario @@ -349,7 +349,7 @@ private static void TestMarshalByVal_In() Assert.IsTrue(CStyle_Array_Struct_In(InitStructArray(ARRAY_SIZE), ARRAY_SIZE), "CStyle_Array_Struct_In"); Assert.IsTrue(CStyle_Array_Bool_In(InitBoolArray(ARRAY_SIZE), ARRAY_SIZE), "CStyle_Array_Bool_In"); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { object[] oArr = InitArray(ARRAY_SIZE); // Test nesting null value scenario @@ -556,7 +556,7 @@ private static void TestMarshalByVal_Out() Assert.IsTrue(CStyle_Array_Bool_Out(boolArr, ARRAY_SIZE), "CStyle_Array_Bool_Out"); Assert.IsTrue(Equals(boolArr, GetExpectedOutBoolArray(ARRAY_SIZE)), "CStyle_Array_Bool_Out:Equals"); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { object[] oArr = new object[ARRAY_SIZE]; Assert.IsTrue(CStyle_Array_Object_Out(oArr, ARRAY_SIZE), "CStyle_Array_Object_Out"); diff --git a/src/tests/Interop/PInvoke/AsAny/AsAnyTest.cs b/src/tests/Interop/PInvoke/AsAny/AsAnyTest.cs index c166235753dda8..71c26a8b344936 100644 --- a/src/tests/Interop/PInvoke/AsAny/AsAnyTest.cs +++ b/src/tests/Interop/PInvoke/AsAny/AsAnyTest.cs @@ -318,7 +318,7 @@ public static int Main() TestUnicodeString(); TestUnicodeStringArray(); TestUnicodeStringBuilder(); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { RunBestFitMappingTests(); } diff --git a/src/tests/Interop/PInvoke/Decimal/DecimalTest.cs b/src/tests/Interop/PInvoke/Decimal/DecimalTest.cs index fd0ea97caaa87b..e98277dd42e5f7 100644 --- a/src/tests/Interop/PInvoke/Decimal/DecimalTest.cs +++ b/src/tests/Interop/PInvoke/Decimal/DecimalTest.cs @@ -16,7 +16,7 @@ public static int Main() { RunDecimalTests(); RunLPDecimalTests(); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { RunCurrencyTests(); } diff --git a/src/tests/Interop/PInvoke/Delegate/DelegateTest.cs b/src/tests/Interop/PInvoke/Delegate/DelegateTest.cs index 0ed7d39bbc33d2..37ed43c910b4bf 100644 --- a/src/tests/Interop/PInvoke/Delegate/DelegateTest.cs +++ b/src/tests/Interop/PInvoke/Delegate/DelegateTest.cs @@ -124,7 +124,7 @@ static int Main(string[] args) try { TestFunctionPointer(); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { TestIDispatch(); } diff --git a/src/tests/Interop/PInvoke/SizeParamIndex/PInvoke/PassingByOut/PassingByOutTest.cs b/src/tests/Interop/PInvoke/SizeParamIndex/PInvoke/PassingByOut/PassingByOutTest.cs index ecb94384759661..f56c273bf1abfb 100644 --- a/src/tests/Interop/PInvoke/SizeParamIndex/PInvoke/PassingByOut/PassingByOutTest.cs +++ b/src/tests/Interop/PInvoke/SizeParamIndex/PInvoke/PassingByOut/PassingByOutTest.cs @@ -241,7 +241,7 @@ static int Main() SizeParamTypeIsUInt32(); SizeParamTypeIsLong(); SizeParamTypeIsULong(); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { SizeParamTypeIsString(); } diff --git a/src/tests/Interop/PInvoke/SizeParamIndex/PInvoke/PassingByRef/PassingByRefTest.cs b/src/tests/Interop/PInvoke/SizeParamIndex/PInvoke/PassingByRef/PassingByRefTest.cs index e86d21db3a1fc9..20e0a20236f3c8 100644 --- a/src/tests/Interop/PInvoke/SizeParamIndex/PInvoke/PassingByRef/PassingByRefTest.cs +++ b/src/tests/Interop/PInvoke/SizeParamIndex/PInvoke/PassingByRef/PassingByRefTest.cs @@ -249,7 +249,7 @@ static int Main() SizeParamTypeIsUInt32(); SizeParamTypeIsLong(); SizeParamTypeIsULong(); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { SizeParamTypeIsString(); } diff --git a/src/tests/Interop/PInvoke/SizeParamIndex/ReversePInvoke/PassingByOut/PassingByOutTest.cs b/src/tests/Interop/PInvoke/SizeParamIndex/ReversePInvoke/PassingByOut/PassingByOutTest.cs index ec8cd58971c461..bf0c46c83c4f13 100644 --- a/src/tests/Interop/PInvoke/SizeParamIndex/ReversePInvoke/PassingByOut/PassingByOutTest.cs +++ b/src/tests/Interop/PInvoke/SizeParamIndex/ReversePInvoke/PassingByOut/PassingByOutTest.cs @@ -184,7 +184,7 @@ public static void RunTestByOut() Assert.IsTrue(DoCallBack_MarshalUlongArray_AsParam_AsByOut(new DelUlongArrByOutAsCdeclCaller(TestMethodForUlongArray_AsReversePInvokeByOut_AsCdecl))); Console.WriteLine("\t\tMarshalUlongArray_AsReversePInvokeByOut_AsCdecl Passed!"); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { Console.WriteLine("\tScenario 10 : string ==> BSTR, Array_Size = 10, Return_Array_Size = 20"); Assert.IsTrue(DoCallBack_MarshalStringArray_AsParam_AsByOut(new DelStringArrByOutAsCdeclCaller(TestMethodForStringArray_AsReversePInvokeByOut_AsCdecl))); diff --git a/src/tests/Interop/PInvoke/SizeParamIndex/ReversePInvoke/PassingByRef/PassingByRefTest.cs b/src/tests/Interop/PInvoke/SizeParamIndex/ReversePInvoke/PassingByRef/PassingByRefTest.cs index c0b0e7804dda50..13b53e610b6bd1 100644 --- a/src/tests/Interop/PInvoke/SizeParamIndex/ReversePInvoke/PassingByRef/PassingByRefTest.cs +++ b/src/tests/Interop/PInvoke/SizeParamIndex/ReversePInvoke/PassingByRef/PassingByRefTest.cs @@ -167,7 +167,7 @@ public static void RunTestByRef() Console.WriteLine("\t\tMarshalSbyteArray_AsReversePInvokeByRef_AsCdecl Passed!"); // We don't support exception interop in .NET off-Windows. - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { Console.WriteLine("\tScenario 3 : short ==> SHORT, Array_Size = -1, Return_Array_Size = 20"); Assert.Throws(() => DoCallBack_MarshalShortArray_AsParam_AsByRef(new DelShortArrByRefAsCdeclCaller(TestMethodForShortArray_AsReversePInvokeByRef_AsCdecl))); @@ -199,7 +199,7 @@ public static void RunTestByRef() Assert.IsTrue(DoCallBack_MarshalUlongArray_AsParam_AsByRef(new DelUlongArrByRefAsCdeclCaller(TestMethodForUlongArray_AsReversePInvokeByRef_AsCdecl))); Console.WriteLine("\t\tMarshalUlongArray_AsReversePInvokeByRef_AsCdecl Passed!"); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { Console.WriteLine("\tScenario 10 : string ==> BSTR, Array_Size = 10, Return_Array_Size = 20"); Assert.IsTrue(DoCallBack_MarshalStringArray_AsParam_AsByRef(new DelStringArrByRefAsCdeclCaller(TestMethodForStringArray_AsReversePInvokeByRef_AsCdecl))); diff --git a/src/tests/Interop/PrimitiveMarshalling/Bool/BoolTest.cs b/src/tests/Interop/PrimitiveMarshalling/Bool/BoolTest.cs index cff9bb1fbd891a..69df2d5475a2dc 100644 --- a/src/tests/Interop/PrimitiveMarshalling/Bool/BoolTest.cs +++ b/src/tests/Interop/PrimitiveMarshalling/Bool/BoolTest.cs @@ -118,7 +118,7 @@ public static int Main(string[] args) ReportFailure("Method Marshal_As_Out[Managed Side],The parameter value is changed", boolManaged, boolValue9); } - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { TestVariantBool(); } diff --git a/src/tests/Interop/StringMarshalling/UTF8/UTF8Test.cs b/src/tests/Interop/StringMarshalling/UTF8/UTF8Test.cs index 41e394d948d915..6338b1dd866765 100644 --- a/src/tests/Interop/StringMarshalling/UTF8/UTF8Test.cs +++ b/src/tests/Interop/StringMarshalling/UTF8/UTF8Test.cs @@ -151,7 +151,7 @@ public static void TestUTF8StructMarshalling(string[] utf8Strings) utf8Struct.index = i; TestStructWithUtf8Field(utf8Struct); } - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (!OperatingSystem.IsWindows()) CompareWithUTF8Encoding(); string testString = "StructTestString\uD83D\uDE00"; diff --git a/src/tests/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/ReversePInvoke/ReversePInvokeTest_.cs b/src/tests/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/ReversePInvoke/ReversePInvokeTest_.cs index c4b1e480aadcc4..2e56b1b1cee869 100644 --- a/src/tests/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/ReversePInvoke/ReversePInvokeTest_.cs +++ b/src/tests/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/ReversePInvoke/ReversePInvokeTest_.cs @@ -1801,7 +1801,7 @@ private static void Run_TestMethod_DoCallBack_MarshalStructByVal_Cdecl() TestMethod_DoCallBack_MarshalStructByVal_Cdecl(StructID.IncludeOuterIntergerStructSequentialId); TestMethod_DoCallBack_MarshalStructByVal_Cdecl(StructID.S11Id); // Windows X86 has a long standing X86_ONLY logic that causes 3, 5,6,7 byte structure returns to behave incorrectly. - if ((RuntimeInformation.ProcessArchitecture != Architecture.X86) || !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if ((RuntimeInformation.ProcessArchitecture != Architecture.X86) || !OperatingSystem.IsWindows()) { TestMethod_DoCallBack_MarshalStructByVal_Cdecl(StructID.ByteStruct3Byte); } @@ -1824,7 +1824,7 @@ private static void Run_TestMethod_DoCallBack_MarshalStructByVal_StdCall() TestMethod_DoCallBack_MarshalStructByVal_StdCall(StructID.IncludeOuterIntergerStructSequentialId); TestMethod_DoCallBack_MarshalStructByVal_StdCall(StructID.S11Id); // Windows X86 has a long standing X86_ONLY logic that causes 3, 5,6,7 byte structure returns to behave incorrectly. - if ((RuntimeInformation.ProcessArchitecture != Architecture.X86) || !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if ((RuntimeInformation.ProcessArchitecture != Architecture.X86) || !OperatingSystem.IsWindows()) { TestMethod_DoCallBack_MarshalStructByVal_StdCall(StructID.ByteStruct3Byte); } diff --git a/src/tests/Interop/StructPacking/StructPacking.cs b/src/tests/Interop/StructPacking/StructPacking.cs index cae74be41b8a09..ec59227b21243d 100644 --- a/src/tests/Interop/StructPacking/StructPacking.cs +++ b/src/tests/Interop/StructPacking/StructPacking.cs @@ -286,7 +286,7 @@ static bool TestDouble() { bool succeeded = true; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || (RuntimeInformation.ProcessArchitecture != Architecture.X86)) + if (OperatingSystem.IsWindows() || (RuntimeInformation.ProcessArchitecture != Architecture.X86)) { succeeded &= Test>( expectedSize: 16, @@ -505,7 +505,7 @@ static bool TestInt64() { bool succeeded = true; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || (RuntimeInformation.ProcessArchitecture != Architecture.X86)) + if (OperatingSystem.IsWindows() || (RuntimeInformation.ProcessArchitecture != Architecture.X86)) { succeeded &= Test>( expectedSize: 16, @@ -918,7 +918,7 @@ static bool TestUInt64() { bool succeeded = true; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || (RuntimeInformation.ProcessArchitecture != Architecture.X86)) + if (OperatingSystem.IsWindows() || (RuntimeInformation.ProcessArchitecture != Architecture.X86)) { succeeded &= Test>( expectedSize: 16, diff --git a/src/tests/JIT/Regression/CLR-x86-JIT/V1.2-Beta1/b103058/b103058.cs b/src/tests/JIT/Regression/CLR-x86-JIT/V1.2-Beta1/b103058/b103058.cs index 18bc557a8988a2..dcd3d54e4d2504 100644 --- a/src/tests/JIT/Regression/CLR-x86-JIT/V1.2-Beta1/b103058/b103058.cs +++ b/src/tests/JIT/Regression/CLR-x86-JIT/V1.2-Beta1/b103058/b103058.cs @@ -20,7 +20,7 @@ internal unsafe class test private static unsafe bool CheckDoubleAlignment1(VT* p) { Console.WriteLine("Address {0}", (IntPtr)p); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || (RuntimeInformation.ProcessArchitecture != Architecture.X86)) + if (OperatingSystem.IsWindows() || (RuntimeInformation.ProcessArchitecture != Architecture.X86)) { if ((int)(long)p % sizeof(double) != 0) { diff --git a/src/tests/JIT/Regression/Dev11/External/dev11_239804/ShowLocallocAlignment.cs b/src/tests/JIT/Regression/Dev11/External/dev11_239804/ShowLocallocAlignment.cs index 4ab7b6c585c493..76e33b31d2585b 100644 --- a/src/tests/JIT/Regression/Dev11/External/dev11_239804/ShowLocallocAlignment.cs +++ b/src/tests/JIT/Regression/Dev11/External/dev11_239804/ShowLocallocAlignment.cs @@ -52,7 +52,7 @@ private unsafe static int RunAlignmentCheckScenario() void* ptr2; required_alignment = 16; // Default to the biggest alignment required - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && (RuntimeInformation.ProcessArchitecture == Architecture.X86)) + if (OperatingSystem.IsWindows() && (RuntimeInformation.ProcessArchitecture == Architecture.X86)) { required_alignment = 4; } diff --git a/src/tests/JIT/superpmi/superpmicollect.cs b/src/tests/JIT/superpmi/superpmicollect.cs index fc448309566c37..d00272b441ca74 100644 --- a/src/tests/JIT/superpmi/superpmicollect.cs +++ b/src/tests/JIT/superpmi/superpmicollect.cs @@ -63,9 +63,9 @@ public static void Initialize() throw new SpmiException("Illegal CORE_ROOT environment variable (" + core_root_raw + "), exception: " + ex.Message); } - IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); - IsOSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); - IsLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux); + IsWindows = OperatingSystem.IsWindows(); + IsOSX = OperatingSystem.IsMacOS(); + IsLinux = OperatingSystem.IsLinux(); if (IsWindows) { diff --git a/src/tests/Loader/AssemblyDependencyResolver/AssemblyDependencyResolverTests/NativeDependencyTests.cs b/src/tests/Loader/AssemblyDependencyResolver/AssemblyDependencyResolverTests/NativeDependencyTests.cs index 35e8bb3b8484ec..bce770fd2222ec 100644 --- a/src/tests/Loader/AssemblyDependencyResolver/AssemblyDependencyResolverTests/NativeDependencyTests.cs +++ b/src/tests/Loader/AssemblyDependencyResolver/AssemblyDependencyResolverTests/NativeDependencyTests.cs @@ -270,7 +270,7 @@ private void ValidateNativeLibraryResolutions( Path.Combine(TestBasePath, _componentAssemblyPath)); string result = resolver.ResolveUnmanagedDllToPath(lookupName); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { if (resolvesOnOSes.HasFlag(OS.Windows)) { @@ -281,7 +281,7 @@ private void ValidateNativeLibraryResolutions( Assert.Null(result); } } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + else if (OperatingSystem.IsMacOS()) { if (resolvesOnOSes.HasFlag(OS.OSX)) { diff --git a/src/tests/Loader/binding/tracing/BinderTracingTest.DefaultProbing.cs b/src/tests/Loader/binding/tracing/BinderTracingTest.DefaultProbing.cs index 3ac201a21492da..d61e46cf26eaca 100644 --- a/src/tests/Loader/binding/tracing/BinderTracingTest.DefaultProbing.cs +++ b/src/tests/Loader/binding/tracing/BinderTracingTest.DefaultProbing.cs @@ -264,12 +264,12 @@ public static BindOperation SatelliteAssembly_CultureSubdirectory_Lowercase() { FilePath = Helpers.GetProbingFilePath(ProbedPath.PathSource.SatelliteSubdirectory, assemblyName.Name, SatelliteCulture.Name, subdirectoryPath), Source = ProbedPath.PathSource.SatelliteSubdirectory, - Result = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? COR_E_FILENOTFOUND : S_OK + Result = OperatingSystem.IsLinux() ? COR_E_FILENOTFOUND : S_OK } }; // On Linux, the path with a lower-case culture name should also be probed - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + if (OperatingSystem.IsLinux()) { probedPaths.Add(new ProbedPath() { @@ -318,7 +318,7 @@ public static BindOperation SatelliteAssembly_NotFound() }; // On Linux (case-sensitive), the path with a lower-case culture name should also be probed - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + if (OperatingSystem.IsLinux()) { probedPaths.Add(new ProbedPath() { diff --git a/src/tests/baseservices/callconvs/TestCallingConventions.cs b/src/tests/baseservices/callconvs/TestCallingConventions.cs index fe42b6956108ad..6ad86cf135a51f 100644 --- a/src/tests/baseservices/callconvs/TestCallingConventions.cs +++ b/src/tests/baseservices/callconvs/TestCallingConventions.cs @@ -16,13 +16,13 @@ class NativeFunctions public static string GetFileName() { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) return $"{Name}.dll"; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + if (OperatingSystem.IsLinux()) return $"lib{Name}.so"; - if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + if (OperatingSystem.IsMacOS()) return $"lib{Name}.dylib"; throw new PlatformNotSupportedException(); diff --git a/src/tests/baseservices/typeequivalence/simple/Simple.cs b/src/tests/baseservices/typeequivalence/simple/Simple.cs index fbfb5dbdb370ed..a65866e58059fc 100644 --- a/src/tests/baseservices/typeequivalence/simple/Simple.cs +++ b/src/tests/baseservices/typeequivalence/simple/Simple.cs @@ -216,7 +216,7 @@ private static void TestGenericInterfaceEquivalence() public static int Main(string[] noArgs) { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (!OperatingSystem.IsWindows()) { return 100; } diff --git a/src/tests/ilasm/PortablePdb/IlasmPortablePdbTester.cs b/src/tests/ilasm/PortablePdb/IlasmPortablePdbTester.cs index 221e22ee4e126c..5b697d5802759a 100644 --- a/src/tests/ilasm/PortablePdb/IlasmPortablePdbTester.cs +++ b/src/tests/ilasm/PortablePdb/IlasmPortablePdbTester.cs @@ -22,7 +22,7 @@ public class IlasmPortablePdbTester : XunitBase public IlasmPortablePdbTester() { CoreRootVar = Environment.GetEnvironmentVariable(CoreRoot); - IsUnix = !RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + IsUnix = !OperatingSystem.IsWindows(); NativeExtension = IsUnix ? string.Empty : ".exe"; IlasmFile = IlasmFileName + NativeExtension; } diff --git a/src/tests/readytorun/coreroot_determinism/Program.cs b/src/tests/readytorun/coreroot_determinism/Program.cs index f836feda5d7ad5..ea537f274e439b 100644 --- a/src/tests/readytorun/coreroot_determinism/Program.cs +++ b/src/tests/readytorun/coreroot_determinism/Program.cs @@ -63,7 +63,7 @@ public static int CompareDLLs(string folder1, string folder2) return result; } - public static string OSExeSuffix(string path) => (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? path + ".exe" : path); + public static string OSExeSuffix(string path) => (OperatingSystem.IsWindows() ? path + ".exe" : path); private static void PrepareCompilationInputFolder(string coreRootFolder, string compilationInputFolder) { diff --git a/src/tests/readytorun/r2rdump/FrameworkTests/R2RDumpTester.cs b/src/tests/readytorun/r2rdump/FrameworkTests/R2RDumpTester.cs index 2d813eb31055a9..18c1f0cd217dbb 100644 --- a/src/tests/readytorun/r2rdump/FrameworkTests/R2RDumpTester.cs +++ b/src/tests/readytorun/r2rdump/FrameworkTests/R2RDumpTester.cs @@ -15,7 +15,7 @@ public class R2RDumpTester : XunitBase public static string FindExePath(string exe) { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { exe = exe + ".exe"; } @@ -40,7 +40,7 @@ public static string FindExePath(string exe) public void DumpCoreLib() { string CoreRootVar = Environment.GetEnvironmentVariable(CoreRoot); - bool IsUnix = !RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + bool IsUnix = !OperatingSystem.IsWindows(); string R2RDumpAbsolutePath = Path.Combine(CoreRootVar, R2RDumpRelativePath, R2RDumpFile); string CoreLibFile = "System.Private.CoreLib.dll"; string CoreLibAbsolutePath = Path.Combine(CoreRootVar, CoreLibFile); diff --git a/src/tests/tracing/eventpipe/common/IpcTraceTest.cs b/src/tests/tracing/eventpipe/common/IpcTraceTest.cs index 660efdf09fe6af..7a9b9fd0c19503 100644 --- a/src/tests/tracing/eventpipe/common/IpcTraceTest.cs +++ b/src/tests/tracing/eventpipe/common/IpcTraceTest.cs @@ -347,7 +347,7 @@ private int Validate() // the process that created them, so we don't need to check on that platform. static public bool EnsureCleanEnvironment() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (!OperatingSystem.IsWindows()) { Func<(IEnumerable>, List)> getPidsAndSockets = () => { diff --git a/src/tests/tracing/eventpipe/common/IpcUtils.cs b/src/tests/tracing/eventpipe/common/IpcUtils.cs index 6828254159e3b4..6f60368894d7e9 100644 --- a/src/tests/tracing/eventpipe/common/IpcUtils.cs +++ b/src/tests/tracing/eventpipe/common/IpcUtils.cs @@ -375,7 +375,7 @@ private static IpcMessage Read(Stream stream) public class ConnectionHelper { - private static string IpcRootPath { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? @"\\.\pipe\" : Path.GetTempPath(); + private static string IpcRootPath { get; } = OperatingSystem.IsWindows() ? @"\\.\pipe\" : Path.GetTempPath(); public static Stream GetStandardTransport(int processId) { try @@ -391,7 +391,7 @@ public static Stream GetStandardTransport(int processId) throw new Exception($"Process {processId} seems to be elevated."); } - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { string pipeName = $"dotnet-diagnostic-{processId}"; var namedPipe = new NamedPipeClientStream( diff --git a/src/tests/tracing/eventpipe/common/Reverse.cs b/src/tests/tracing/eventpipe/common/Reverse.cs index fd5693a6be9c35..b301cf59598f10 100644 --- a/src/tests/tracing/eventpipe/common/Reverse.cs +++ b/src/tests/tracing/eventpipe/common/Reverse.cs @@ -70,7 +70,7 @@ public class ReverseServer { public static string MakeServerAddress() { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { return "DOTNET_TRACE_TESTS_" + Path.GetRandomFileName(); } @@ -89,7 +89,7 @@ public ReverseServer(string serverAddress, int bufferSize = 16 * 1024) { _serverAddress = serverAddress; _bufferSize = bufferSize; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { _server = GetNewNamedPipeServer(); } @@ -135,7 +135,7 @@ public async Task AcceptAsync() private NamedPipeServerStream GetNewNamedPipeServer() { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { return new NamedPipeServerStream( _serverAddress, diff --git a/src/tests/tracing/eventpipe/complus_config/name_config_with_pid.cs b/src/tests/tracing/eventpipe/complus_config/name_config_with_pid.cs index 41b5421ec4c576..7cca9d64320bb4 100644 --- a/src/tests/tracing/eventpipe/complus_config/name_config_with_pid.cs +++ b/src/tests/tracing/eventpipe/complus_config/name_config_with_pid.cs @@ -32,7 +32,7 @@ static int Main(string[] args) } string corerun = Path.Combine(Environment.GetEnvironmentVariable("CORE_ROOT"), "corerun"); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) corerun = corerun + ".exe"; // Use dll directory as temp directory diff --git a/src/tests/tracing/eventpipe/processinfo/processinfo.cs b/src/tests/tracing/eventpipe/processinfo/processinfo.cs index d79e8147b739ac..ebeb602e8f014a 100644 --- a/src/tests/tracing/eventpipe/processinfo/processinfo.cs +++ b/src/tests/tracing/eventpipe/processinfo/processinfo.cs @@ -62,7 +62,7 @@ public static string NormalizeCommandLine(string cmdline) // Tests are run out of /tmp on Mac and linux, but on Mac /tmp is actually a symlink that points to /private/tmp. // This isn't represented in the output from FileInfo.FullName unfortunately, so we'll fake that completion in that case. - if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && normalizedCommandLine.StartsWith("/tmp/")) + if (OperatingSystem.IsMacOS() && normalizedCommandLine.StartsWith("/tmp/")) normalizedCommandLine = "/private" + normalizedCommandLine; return normalizedCommandLine; @@ -146,15 +146,15 @@ public static int Main(string[] args) // see eventpipeeventsource.cpp for these values string expectedOSValue = null; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { expectedOSValue = "Windows"; } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + else if (OperatingSystem.IsMacOS()) { expectedOSValue = "macOS"; } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + else if (OperatingSystem.IsLinux()) { expectedOSValue = "Linux"; }