Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Work around known issues in "Ubuntu on Windows" #11574

Merged
merged 5 commits into from
Sep 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Common/src/Interop/Linux/procfs/Interop.ProcFsStat.cs
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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this commented out? If it's necessary, could you add a comment explaining and linking to whatever the associated issue # is?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this; I thought I'd already added a comment here. Fixed.

return b;
}

Expand Down
26 changes: 26 additions & 0 deletions src/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"))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the chance that some Linux distribution will contain WSL as a substring in its /proc/version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure...WSL sounds like an uncommon sequence of characters to me, but that's hard to predict. We could maybe do a little more rigorous parsing here, but I'm not sure it's worth the additional risk of getting things wrong. The worst-case scenario is that we stop running some tests on a distro where they should run, but at least there's a chance that whoever is porting to that distro will notice, since xunit prints messages about tests that were skipped conditionally.

{
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
4 changes: 2 additions & 2 deletions src/System.Diagnostics.Process/tests/ProcessTests.cs
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
2 changes: 1 addition & 1 deletion src/System.Diagnostics.Process/tests/ProcessThreadTests.cs
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