Skip to content

Commit

Permalink
Remove WSL checks and platform detection
Browse files Browse the repository at this point in the history
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 dotnet#18258
  • Loading branch information
ViktorHofer committed Jun 1, 2021
1 parent 85fde05 commit 3fe1e47
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,30 +103,6 @@ public static bool IsWindowsHomeEdition
}
}

public static bool IsWindowsSubsystemForLinux => m_isWindowsSubsystemForLinux.Value;
public static bool IsNotWindowsSubsystemForLinux => !IsWindowsSubsystemForLinux;

private static Lazy<bool> m_isWindowsSubsystemForLinux = new Lazy<bool>(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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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)
Expand All @@ -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))]
Expand Down Expand Up @@ -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();
Expand All @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<System.Net.Http.HttpRequestException>(() => XmlReader.Create("http://test.test/test.html", new XmlReaderSettings() { Async = false }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 3fe1e47

Please sign in to comment.