From 3fe1e47b0362f1b1dcf499ce65aea8c1c3c4a187 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Tue, 1 Jun 2021 14:42:47 +0200 Subject: [PATCH] Remove WSL checks and platform detection WSL1 isn't a supported build or execution environment for dotnet/runtime. Because of that removing the checks and platform detection for it as that code path isn't necessary for WSL2 anymore as it contains a fully featured kernel which behaves just a like a usual Linux distro. Fixes https://github.com/dotnet/runtime/issues/18258 --- .../Net/Http/HttpClientHandlerTest.Proxy.cs | 2 +- .../System/Net/Http/HttpClientHandlerTest.cs | 2 +- .../System/PlatformDetection.Windows.cs | 24 ------------------- .../tests/ProcessTests.Unix.cs | 13 ++-------- .../tests/DriveInfo.Unix.Tests.cs | 2 +- .../tests/HttpResponseStreamTests.cs | 4 ++-- .../FunctionalTests/IPGlobalPropertiesTest.cs | 10 ++++---- .../NetworkInterfaceBasicTest.cs | 4 ++-- .../NetworkInterfaceIPv4Statistics.cs | 2 +- .../Tests/AsyncReaderLateInitTests.cs | 2 +- .../tests/Encoder/EncoderConvert2.cs | 6 ++--- 11 files changed, 19 insertions(+), 52 deletions(-) diff --git a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Proxy.cs b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Proxy.cs index c4beb328d6ea8d..22a98d68cf182e 100644 --- a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Proxy.cs +++ b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Proxy.cs @@ -306,7 +306,7 @@ public async Task AuthenticatedProxyTunnelRequest_PostAsyncWithNoCreds_Throws() } } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // [ActiveIssue("https://github.com/dotnet/runtime/issues/18258")] + [Fact] public async Task Proxy_SslProxyUnsupported_Throws() { using (HttpClientHandler handler = CreateHttpClientHandler()) diff --git a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.cs b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.cs index 2d49eded82fa52..f5b6a02c51b2ae 100644 --- a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.cs +++ b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.cs @@ -1815,7 +1815,7 @@ await LoopbackServerFactory.CreateServerAsync(async (server, rootUrl) => } #endregion - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsSubsystemForLinux), nameof(PlatformDetection.IsNotBrowserDomSupported))] // [ActiveIssue("https://github.com/dotnet/runtime/issues/18258")] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowserDomSupported))] public async Task GetAsync_InvalidUrl_ExpectedExceptionThrown() { string invalidUri = $"http://nosuchhost.invalid"; diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Windows.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Windows.cs index 4253f7785f8051..078f29be48e685 100644 --- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Windows.cs +++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Windows.cs @@ -103,30 +103,6 @@ public static bool IsWindowsHomeEdition } } - public static bool IsWindowsSubsystemForLinux => m_isWindowsSubsystemForLinux.Value; - public static bool IsNotWindowsSubsystemForLinux => !IsWindowsSubsystemForLinux; - - private static Lazy m_isWindowsSubsystemForLinux = new Lazy(GetIsWindowsSubsystemForLinux); - private static bool GetIsWindowsSubsystemForLinux() - { - // https://github.com/Microsoft/BashOnWindows/issues/423#issuecomment-221627364 - if (IsLinux) - { - const string versionFile = "/proc/version"; - if (File.Exists(versionFile)) - { - string s = File.ReadAllText(versionFile); - - if (s.Contains("Microsoft") || s.Contains("WSL")) - { - return true; - } - } - } - - return false; - } - private static string GetWindowsInstallationType() { string key = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion"; diff --git a/src/libraries/System.Diagnostics.Process/tests/ProcessTests.Unix.cs b/src/libraries/System.Diagnostics.Process/tests/ProcessTests.Unix.cs index fe3c26b1e8592c..a4ff703332afce 100644 --- a/src/libraries/System.Diagnostics.Process/tests/ProcessTests.Unix.cs +++ b/src/libraries/System.Diagnostics.Process/tests/ProcessTests.Unix.cs @@ -453,21 +453,12 @@ public void TestBasePriorityOnUnix() ProcessPriorityClass originalPriority = _process.PriorityClass; Assert.Equal(ProcessPriorityClass.Normal, originalPriority); - - // https://github.com/dotnet/runtime/issues/24426 -- returns "-19" and not "19" - if (!PlatformDetection.IsWindowsSubsystemForLinux) - { - SetAndCheckBasePriority(ProcessPriorityClass.Idle, 19); - } + SetAndCheckBasePriority(ProcessPriorityClass.Idle, 19); try { SetAndCheckBasePriority(ProcessPriorityClass.Normal, 0); - // https://github.com/dotnet/runtime/issues/24426 -- returns "11" and not "-11" - if (!PlatformDetection.IsWindowsSubsystemForLinux) - { - SetAndCheckBasePriority(ProcessPriorityClass.High, -11); - } + SetAndCheckBasePriority(ProcessPriorityClass.High, -11); _process.PriorityClass = originalPriority; } catch (Win32Exception ex) diff --git a/src/libraries/System.IO.FileSystem.DriveInfo/tests/DriveInfo.Unix.Tests.cs b/src/libraries/System.IO.FileSystem.DriveInfo/tests/DriveInfo.Unix.Tests.cs index 9244ddff9e68e9..c922752d447572 100644 --- a/src/libraries/System.IO.FileSystem.DriveInfo/tests/DriveInfo.Unix.Tests.cs +++ b/src/libraries/System.IO.FileSystem.DriveInfo/tests/DriveInfo.Unix.Tests.cs @@ -59,7 +59,7 @@ public void PropertiesOfInvalidDrive() Assert.Equal(invalidDriveName, invalidDrive.VolumeLabel); // VolumeLabel is equivalent to Name on Unix } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/dotnet/runtime/issues/18487 + [Fact] [PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Android)] public void PropertiesOfValidDrive() { diff --git a/src/libraries/System.Net.HttpListener/tests/HttpResponseStreamTests.cs b/src/libraries/System.Net.HttpListener/tests/HttpResponseStreamTests.cs index 21cfaac305a019..4170efafa4ce7e 100644 --- a/src/libraries/System.Net.HttpListener/tests/HttpResponseStreamTests.cs +++ b/src/libraries/System.Net.HttpListener/tests/HttpResponseStreamTests.cs @@ -454,7 +454,7 @@ public async Task Write_HeadersToClosedConnectionSynchronously_ThrowsHttpListene } } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // [ActiveIssue("https://github.com/dotnet/runtime/issues/18258")] + [Theory] [InlineData(true)] [InlineData(false)] [ActiveIssue("https://github.com/dotnet/runtime/issues/21022", platforms: TestPlatforms.Windows)] // Indeterminate failure - socket not always fully disconnected. @@ -494,7 +494,7 @@ public async Task Write_ContentToClosedConnectionAsynchronously_ThrowsHttpListen } } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // [ActiveIssue("https://github.com/dotnet/runtime/issues/18258")] + [Theory] [InlineData(true)] [InlineData(false)] [ActiveIssue("https://github.com/dotnet/runtime/issues/21022", platforms: TestPlatforms.Windows)] // Indeterminate failure - socket not always fully disconnected. diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/IPGlobalPropertiesTest.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/IPGlobalPropertiesTest.cs index 62ba2328c65b77..860e64f216edbe 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/IPGlobalPropertiesTest.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/IPGlobalPropertiesTest.cs @@ -25,7 +25,7 @@ public IPGlobalPropertiesTest(ITestOutputHelper output) _log = output; } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // [ActiveIssue("https://github.com/dotnet/runtime/issues/18258")] + [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/36890", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public void IPGlobalProperties_AccessAllMethods_NoErrors() { @@ -50,7 +50,7 @@ public void IPGlobalProperties_AccessAllMethods_NoErrors() Assert.NotNull(gp.GetUdpIPv6Statistics()); } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // [ActiveIssue("https://github.com/dotnet/runtime/issues/18258")] + [Theory] [MemberData(nameof(Loopbacks))] [ActiveIssue("https://github.com/dotnet/runtime/issues/36890", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public void IPGlobalProperties_TcpListeners_Succeed(IPAddress address) @@ -76,7 +76,7 @@ public void IPGlobalProperties_TcpListeners_Succeed(IPAddress address) } } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // [ActiveIssue("https://github.com/dotnet/runtime/issues/18258")] + [Theory] [ActiveIssue("https://github.com/dotnet/runtime/issues/34690", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)] [ActiveIssue("https://github.com/dotnet/runtime/issues/36890", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] [MemberData(nameof(Loopbacks))] @@ -108,7 +108,7 @@ public async Task IPGlobalProperties_TcpActiveConnections_Succeed(IPAddress addr } } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // [ActiveIssue("https://github.com/dotnet/runtime/issues/18258")] + [Fact] public void IPGlobalProperties_TcpActiveConnections_NotListening() { TcpConnectionInformation[] tcpCconnections = IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections(); @@ -118,7 +118,7 @@ public void IPGlobalProperties_TcpActiveConnections_NotListening() } } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // [ActiveIssue("https://github.com/dotnet/runtime/issues/18258")] + [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/50567", TestPlatforms.Android)] public async Task GetUnicastAddresses_NotEmpty() { diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceBasicTest.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceBasicTest.cs index 7554f679deccd9..3455f06297d793 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceBasicTest.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceBasicTest.cs @@ -222,7 +222,7 @@ public void BasicTest_GetIPInterfaceStatistics_Success() } } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/dotnet/runtime/issues/20029 and https://github.com/Microsoft/WSL/issues/3561 + [Fact] [PlatformSpecific(TestPlatforms.Linux)] // Some APIs are not supported on Linux public void BasicTest_GetIPInterfaceStatistics_Success_Linux() { @@ -271,7 +271,7 @@ public void BasicTest_GetIPInterfaceStatistics_Success_Bsd() } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/dotnet/runtime/issues/20029 and https://github.com/Microsoft/WSL/issues/3561 + [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/50567", TestPlatforms.Android)] [ActiveIssue("https://github.com/dotnet/runtime/issues/36890", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public void BasicTest_GetIsNetworkAvailable_Success() diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceIPv4Statistics.cs b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceIPv4Statistics.cs index 48fa49a9872826..52aceb0d3f9c14 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceIPv4Statistics.cs +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceIPv4Statistics.cs @@ -44,7 +44,7 @@ public void BasicTest_GetIPv4InterfaceStatistics_Success() } } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/dotnet/runtime/issues/20029 and https://github.com/Microsoft/WSL/issues/3561 + [Fact] [PlatformSpecific(TestPlatforms.Linux)] // Some APIs are not supported on Windows and OSX public void BasicTest_GetIPv4InterfaceStatistics_Success_Linux() { diff --git a/src/libraries/System.Private.Xml/tests/XmlReader/Tests/AsyncReaderLateInitTests.cs b/src/libraries/System.Private.Xml/tests/XmlReader/Tests/AsyncReaderLateInitTests.cs index 482014481e8fb4..eeb087178f0248 100644 --- a/src/libraries/System.Private.Xml/tests/XmlReader/Tests/AsyncReaderLateInitTests.cs +++ b/src/libraries/System.Private.Xml/tests/XmlReader/Tests/AsyncReaderLateInitTests.cs @@ -86,7 +86,7 @@ public static void ReadAfterInitializationWithUriOnAsyncReaderTrows() } } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsSubsystemForLinux), nameof(PlatformDetection.IsThreadingSupported))] // [ActiveIssue("https://github.com/dotnet/runtime/issues/18258")] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public static void InitializationWithUriOnNonAsyncReaderThrows() { Assert.Throws(() => XmlReader.Create("http://test.test/test.html", new XmlReaderSettings() { Async = false })); diff --git a/src/libraries/System.Text.Encoding/tests/Encoder/EncoderConvert2.cs b/src/libraries/System.Text.Encoding/tests/Encoder/EncoderConvert2.cs index e8797dc0273cef..17e64168f4e923 100644 --- a/src/libraries/System.Text.Encoding/tests/Encoder/EncoderConvert2.cs +++ b/src/libraries/System.Text.Encoding/tests/Encoder/EncoderConvert2.cs @@ -208,7 +208,7 @@ public void EncoderASCIIConvertUnicodeCharArrayPartial() } // Call Convert to convert partial of a Unicode character array with UTF8 encoder - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // [ActiveIssue("https://github.com/dotnet/runtime/issues/18258")] + [Fact] public void EncoderUTF8ConvertUnicodeCharArrayPartial() { char[] chars = "\uD83D\uDE01Test".ToCharArray(); @@ -228,7 +228,7 @@ public void EncoderUTF8ConvertUnicodeCharArrayPartial() } // Call Convert to convert partial of a ASCII+Unicode character array with ASCII encoder - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // [ActiveIssue("https://github.com/dotnet/runtime/issues/18258")] + [Fact] public void EncoderASCIIConvertMixedASCIIUnicodeCharArrayPartial() { char[] chars = "T\uD83D\uDE01est".ToCharArray(); @@ -250,7 +250,7 @@ public void EncoderASCIIConvertMixedASCIIUnicodeCharArrayPartial() } // Call Convert to convert partial of a ASCII+Unicode character array with UTF8 encoder - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // [ActiveIssue("https://github.com/dotnet/runtime/issues/18258")] + [Fact] public void EncoderUTF8ConvertMixedASCIIUnicodeCharArrayPartial() { char[] chars = "T\uD83D\uDE01est".ToCharArray();