Skip to content

Commit

Permalink
WASM: Fix System.IO.MemoryMappedFiles tests (dotnet#39355)
Browse files Browse the repository at this point in the history
  • Loading branch information
akoeplinger authored Jul 15, 2020
1 parent 7f34be5 commit 46ca4d7
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public static partial class PlatformDetection
public static bool IsNotFedoraOrRedHatFamily => !IsFedora && !IsRedHatFamily;
public static bool IsNotDebian10 => !IsDebian10;

public static bool IsSuperUser => !IsWindows ?
public static bool IsSuperUser => IsBrowser ? false : (!IsWindows ?
libc.geteuid() == 0 :
throw new PlatformNotSupportedException();
throw new PlatformNotSupportedException());

public static Version OpenSslVersion => !IsOSXLike && !IsWindows ?
GetOpenSslVersion() :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ public void FileInUse_CreateFromFile_FailsWithExistingReadWriteMap()
/// Test exceptional behavior when trying to create a map for a non-shared file that's currently in use.
/// </summary>
[Fact]
[PlatformSpecific(~TestPlatforms.Browser)] // the emscripten implementation ignores FileShare.None
public void FileInUse_CreateFromFile_FailsWithExistingNoShareFile()
{
// Already opened with a FileStream
Expand Down Expand Up @@ -696,13 +697,13 @@ private void WriteToReadOnlyFile(MemoryMappedFileAccess access, bool succeeds)
public void WriteToReadOnlyFile_ReadWrite(MemoryMappedFileAccess access)
{
WriteToReadOnlyFile(access, access == MemoryMappedFileAccess.Read ||
(!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && geteuid() == 0));
(!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && PlatformDetection.IsSuperUser));
}

[Fact]
public void WriteToReadOnlyFile_CopyOnWrite()
{
WriteToReadOnlyFile(MemoryMappedFileAccess.CopyOnWrite, (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && geteuid() == 0));
WriteToReadOnlyFile(MemoryMappedFileAccess.CopyOnWrite, (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && PlatformDetection.IsSuperUser));
}

/// <summary>
Expand Down Expand Up @@ -768,6 +769,7 @@ public void LeaveOpenRespected_OutstandingViews(bool leaveOpen)
/// Test to validate we can create multiple maps from the same FileStream.
/// </summary>
[Fact]
[PlatformSpecific(~TestPlatforms.Browser)] // the emscripten implementation doesn't share data
public void MultipleMapsForTheSameFileStream()
{
const int Capacity = 4096;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public abstract partial class MemoryMappedFilesTestBase : FileCleanupTestBase
/// <summary>Gets the system's page size.</summary>
protected static Lazy<int> s_pageSize = new Lazy<int>(() =>
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Browser))
return Environment.SystemPageSize;

int pageSize;
const int _SC_PAGESIZE_FreeBSD = 47;
const int _SC_PAGESIZE_Linux = 30;
Expand All @@ -31,9 +34,6 @@ public abstract partial class MemoryMappedFilesTestBase : FileCleanupTestBase
[DllImport("libc", SetLastError = true)]
private static extern int sysconf(int name);

[DllImport("libc", SetLastError = true)]
protected static extern int geteuid();

/// <summary>Asserts that the handle's inheritability matches the specified value.</summary>
protected static void AssertInheritability(SafeHandle handle, HandleInheritability inheritability)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ public void FlushSupportedOnBothReadAndWriteAccessors(MemoryMappedFileAccess acc
/// Test to validate that multiple accessors over the same map share data appropriately.
/// </summary>
[Fact]
[PlatformSpecific(~TestPlatforms.Browser)] // the emscripten implementation doesn't share data
public void ViewsShareData()
{
const int MapLength = 256;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ public void FlushSupportedOnBothReadAndWriteAccessors(MemoryMappedFileAccess acc
/// Test to validate that multiple accessors over the same map share data appropriately.
/// </summary>
[Fact]
[PlatformSpecific(~TestPlatforms.Browser)] // the emscripten implementation doesn't share data
public void ViewsShareData()
{
const int MapLength = 256;
Expand Down
1 change: 0 additions & 1 deletion src/libraries/tests.proj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Globalization.Extensions\tests\System.Globalization.Extensions.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Globalization\tests\System.Globalization.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.IO.FileSystem\tests\System.IO.FileSystem.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.IO.MemoryMappedFiles\tests\System.IO.MemoryMappedFiles.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.IO.Packaging\tests\System.IO.Packaging.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Linq.Expressions\tests\System.Linq.Expressions.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Linq.Parallel\tests\System.Linq.Parallel.Tests.csproj" />
Expand Down

0 comments on commit 46ca4d7

Please sign in to comment.