Skip to content

Commit

Permalink
Work around known issues in "Ubuntu on Windows" (dotnet/corefx#11574)
Browse files Browse the repository at this point in the history
The latest Windows 10 preview builds contain enough functionality in Ubuntu/Bash on Windows (a.k.a. Windows Subsystem for Linux, or WSL) that .NET Core mostly works now. With the fix for dotnet/corefx#11058, we can even build/test the CoreFx tree in this environment. Currently there are a few test failures; I've been working on identifying the causes of these, and filing bugs in the appropriate repos. 
This change implements workarounds for all of the current known issues in the "inner loop" tests. Mostly, I've just conditionally disabled tests when running in the WSL environment. 
There is still an issue, under investigation, causing non-deterministic failures in the System.Net.Http tests (Microsoft/BashOnWindowsdotnet/corefx#1068). And I haven't tried OuterLoop runs of anything but the networking tests. 

Commit migrated from dotnet/corefx@d9aa92f
  • Loading branch information
Eric Eilebrecht authored Sep 10, 2016
1 parent be9d4be commit be96f80
Show file tree
Hide file tree
Showing 69 changed files with 392 additions and 258 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ internal static bool TryReadStatFile(int pid, out ParsedStat result, ReusableTex
internal static bool TryReadStatFile(int pid, int tid, out ParsedStat result, ReusableTextReader reusableReader)
{
bool b = TryParseStatFile(GetStatFilePathForThread(pid, tid), out result, reusableReader);
Debug.Assert(!b || result.pid == tid, "Expected thread ID from stat file to match supplied tid");
//
// This assert currently fails in the Windows Subsystem For Linux. See https://github.com/Microsoft/BashOnWindows/issues/967.
//
//Debug.Assert(!b || result.pid == tid, "Expected thread ID from stat file to match supplied tid");
return b;
}

Expand Down
26 changes: 26 additions & 0 deletions src/libraries/Common/tests/System/PlatformDetection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,32 @@ public static class PlatformDetection

public static int WindowsVersion { get; } = GetWindowsVersion();

private static Lazy<bool> m_isWindowsSubsystemForLinux = new Lazy<bool>(GetIsWindowsSubsystemForLinux);

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

private static bool GetIsWindowsSubsystemForLinux()
{
// https://github.com/Microsoft/BashOnWindows/issues/423#issuecomment-221627364

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
const string versionFile = "/proc/version";
if (File.Exists(versionFile))
{
var s = File.ReadAllText(versionFile);

if (s.Contains("Microsoft") || s.Contains("WSL"))
{
return true;
}
}
}

return false;
}

public static bool IsDebian8 { get; } = IsDistroAndVersion("debian", "8");
public static bool IsUbuntu1510 { get; } = IsDistroAndVersion("ubuntu", "15.10");
public static bool IsUbuntu1604 { get; } = IsDistroAndVersion("ubuntu", "16.04");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public void TestProcessorTime()
Assert.InRange(processorTimeAtHalfSpin, processorTimeBeforeSpin, Process.GetCurrentProcess().TotalProcessorTime.TotalSeconds);
}

[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/974
public void TestProcessStartTime()
{
TimeSpan allowedWindow = TimeSpan.FromSeconds(3);
Expand All @@ -417,7 +417,7 @@ public void TestProcessStartTime()
}
}

[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/968
[PlatformSpecific(~PlatformID.OSX)] // getting/setting affinity not supported on OSX
public void TestProcessorAffinity()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void TestStartTimeProperty_OSX()
}
}

[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/974
[PlatformSpecific(~PlatformID.OSX)] // OSX throws PNSE from StartTime
public async Task TestStartTimeProperty()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ namespace ManagedTests.DynamicCSharp.Conformance.dynamic.context.operate.genclas

public class Test
{
[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/513
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1734,7 +1734,7 @@ namespace ManagedTests.DynamicCSharp.Conformance.dynamic.context.operate.regclas

public class Test
{
[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/513
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.basic.array

public class Program
{
[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/513
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using Xunit;

namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.returnType.covariant.indexer001.indexer001
Expand Down Expand Up @@ -3421,7 +3422,7 @@ public override bool Equals(object o)

public class Test
{
[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/513
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using Xunit;

namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.statements.checked001.checked001
Expand All @@ -24,7 +25,7 @@ public int GetMaxInt()

public class Test
{
[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/513
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand Down Expand Up @@ -81,7 +82,7 @@ public int GetMaxInt

public class Test
{
[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/513
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand Down Expand Up @@ -124,7 +125,7 @@ namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.statements.

public class Test
{
[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/513
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand Down Expand Up @@ -168,7 +169,7 @@ namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.statements.

public class Test
{
[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/513
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand Down Expand Up @@ -212,7 +213,7 @@ namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.statements.

public class Test
{
[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/513
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand Down Expand Up @@ -491,7 +492,7 @@ namespace ManagedTests.DynamicCSharp.Conformance.dynamic.dynamicType.statements.

public class Test
{
[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/513
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand Down Expand Up @@ -1763,7 +1764,7 @@ public int GetMaxInt()

public class Test
{
[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/513
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand Down Expand Up @@ -1813,7 +1814,7 @@ public int GetMaxInt()

public class Test
{
[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/513
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@
<Compile Include="Dynamic.Variance\Conformance.dynamic.Variance.expr.cs" />
<Compile Include="Dynamic.Variance\Conformance.dynamic.Variance.implem.cs" />
<Compile Include="ErrorVerifier.cs" />
<Compile Include="$(CommonTestPath)\System\PlatformDetection.cs">
<Link>Common\System\PlatformDetection.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\pkg\System.Dynamic.Runtime.pkgproj">
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
}

[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/dotnet/corefx/issues/11570
[PlatformSpecific(PlatformID.AnyUnix)]
public void PropertiesOfValidDrive()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<ItemGroup>
<Compile Include="DriveInfo.Unix.Tests.cs" />
<Compile Include="DriveInfo.Windows.Tests.cs" />
<Compile Include="$(CommonTestPath)\System\PlatformDetection.cs">
<Link>Common\System\PlatformDetection.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="project.json" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace System.IO.Tests
{
public class Directory_Changed_Tests : FileSystemWatcherTest
{
[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/216
public void FileSystemWatcher_Directory_Changed_LastWrite()
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))
Expand All @@ -23,7 +23,7 @@ public void FileSystemWatcher_Directory_Changed_LastWrite()
}
}

[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/216
public void FileSystemWatcher_Directory_Changed_WatchedFolder()
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))
Expand All @@ -36,7 +36,7 @@ public void FileSystemWatcher_Directory_Changed_WatchedFolder()
}
}

[Theory]
[ConditionalTheory(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/216
[InlineData(false)]
[InlineData(true)]
public void FileSystemWatcher_Directory_Changed_Nested(bool includeSubdirectories)
Expand All @@ -58,7 +58,7 @@ public void FileSystemWatcher_Directory_Changed_Nested(bool includeSubdirectorie
}
}

[ConditionalFact(nameof(CanCreateSymbolicLinks))]
[ConditionalFact(nameof(CanCreateSymbolicLinks), nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/216
public void FileSystemWatcher_Directory_Changed_SymLink()
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace System.IO.Tests
{
public class Directory_Create_Tests : FileSystemWatcherTest
{
[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/216
public void FileSystemWatcher_Directory_Create()
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))
Expand All @@ -25,7 +25,7 @@ public void FileSystemWatcher_Directory_Create()
}
}

[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/216
public void FileSystemWatcher_Directory_Create_InNestedDirectory()
{
using (var dir = new TempDirectory(GetTestFilePath()))
Expand All @@ -44,7 +44,7 @@ public void FileSystemWatcher_Directory_Create_InNestedDirectory()
}
}

[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/216
[OuterLoop]
public void FileSystemWatcher_Directory_Create_DeepDirectoryStructure()
{
Expand All @@ -64,7 +64,7 @@ public void FileSystemWatcher_Directory_Create_DeepDirectoryStructure()
}
}

[ConditionalFact(nameof(CanCreateSymbolicLinks))]
[ConditionalFact(nameof(CanCreateSymbolicLinks), nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/216
public void FileSystemWatcher_Directory_Create_SymLink()
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace System.IO.Tests
{
public class Directory_Delete_Tests : FileSystemWatcherTest
{
[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/216
public void FileSystemWatcher_Directory_Delete()
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))
Expand All @@ -27,7 +27,7 @@ public void FileSystemWatcher_Directory_Delete()
}
}

[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/216
public void FileSystemWatcher_Directory_Delete_InNestedDirectory()
{
using (var dir = new TempDirectory(GetTestFilePath()))
Expand All @@ -47,7 +47,7 @@ public void FileSystemWatcher_Directory_Delete_InNestedDirectory()
}
}

[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/216
[OuterLoop]
public void FileSystemWatcher_Directory_Delete_DeepDirectoryStructure()
{
Expand All @@ -68,7 +68,7 @@ public void FileSystemWatcher_Directory_Delete_DeepDirectoryStructure()
}
}

[ConditionalFact(nameof(CanCreateSymbolicLinks))]
[ConditionalFact(nameof(CanCreateSymbolicLinks), nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/216
public void FileSystemWatcher_Directory_Delete_SymLink()
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void Directory_Move_To_Same_Directory()
DirectoryMove_SameDirectory(WatcherChangeTypes.Renamed);
}

[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/216
public void Directory_Move_From_Watched_To_Unwatched()
{
DirectoryMove_FromWatchedToUnwatched(WatcherChangeTypes.Deleted);
Expand All @@ -35,21 +35,21 @@ public void Unix_Directory_Move_To_Different_Watched_Directory()
DirectoryMove_DifferentWatchedDirectory(0);
}

[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/216
public void Directory_Move_From_Unwatched_To_Watched()
{
DirectoryMove_FromUnwatchedToWatched(WatcherChangeTypes.Created);
}

[Theory]
[ConditionalTheory(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/216
[InlineData(false)]
[InlineData(true)]
public void Directory_Move_In_Nested_Directory(bool includeSubdirectories)
{
DirectoryMove_NestedDirectory(includeSubdirectories ? WatcherChangeTypes.Renamed : 0, includeSubdirectories);
}

[Fact]
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/216
public void Directory_Move_With_Set_NotifyFilter()
{
DirectoryMove_WithNotifyFilter(WatcherChangeTypes.Renamed);
Expand Down
Loading

0 comments on commit be96f80

Please sign in to comment.