Skip to content
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.IO;
using System.Runtime.InteropServices;

Expand Down Expand Up @@ -30,6 +31,8 @@ public static partial class PlatformDetection

public static bool IsMonoLinuxArm64 => IsMonoRuntime && IsLinux && IsArm64Process;
public static bool IsNotMonoLinuxArm64 => !IsMonoLinuxArm64;
public static bool IsQemuLinux => IsLinux && Environment.GetEnvironmentVariable("DOTNET_RUNNING_UNDER_QEMU") != null;
public static bool IsNotQemuLinux => !IsQemuLinux;

// OSX family
public static bool IsApplePlatform => IsOSX || IsiOS || IstvOS || IsMacCatalyst;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.DotNet.XUnitExtensions;
using Xunit;

namespace System.Net.Sockets.Tests
Expand Down Expand Up @@ -792,14 +792,19 @@ await Task.WhenAll(
}
}

[Theory]
[ConditionalTheory]
[PlatformSpecific(TestPlatforms.AnyUnix)] // API throws PNSE on Unix
[InlineData(0)]
[InlineData(1)]
public void Connect_ConnectTwice_NotSupported(int invalidatingAction)
{
using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
if (PlatformDetection.IsQemuLinux && invalidatingAction == 1)
{
throw new SkipTestException("Skip on Qemu due to [ActiveIssue(https://github.com/dotnet/runtime/issues/104542)]");
}

switch (invalidatingAction)
{
case 0:
Expand All @@ -823,7 +828,7 @@ public void Connect_ConnectTwice_NotSupported(int invalidatingAction)
}
}

[Theory]
[ConditionalTheory]
[PlatformSpecific(TestPlatforms.AnyUnix)] // API throws PNSE on Unix
[InlineData(0)]
[InlineData(1)]
Expand All @@ -833,6 +838,11 @@ public void ConnectAsync_ConnectTwice_NotSupported(int invalidatingAction)

using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
if (PlatformDetection.IsQemuLinux && invalidatingAction == 1)
{
throw new SkipTestException("Skip on Qemu due to [ActiveIssue(https://github.com/dotnet/runtime/issues/104542)]");
}

switch (invalidatingAction)
{
case 0:
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.

using System.Runtime.InteropServices;
using Microsoft.DotNet.XUnitExtensions;
using Xunit;

namespace System.Net.Sockets.Tests
Expand Down Expand Up @@ -122,6 +123,7 @@ public void Socket_KeepAlive_Interval_And_Time()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/104545", typeof(PlatformDetection), nameof(PlatformDetection.IsQemuLinux))]
public void Socket_Get_KeepAlive_Time_AsByteArray_OptionLengthZero_Failure()
{
using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
Expand All @@ -138,12 +140,17 @@ public void Socket_Get_KeepAlive_Time_AsByteArray_OptionLengthZero_Failure()
}
}

[Theory]
[ConditionalTheory]
[InlineData(null)]
[InlineData(new byte[0])]
[InlineData(new byte[3] { 0, 0, 0 })]
public void Socket_Get_KeepAlive_Time_AsByteArray_BufferNullOrTooSmall_Failure(byte[] buffer)
{
if (PlatformDetection.IsQemuLinux && (buffer == null || buffer.Length == 0))
{
throw new SkipTestException("Skip on Qemu due to [ActiveIssue(https://github.com/dotnet/runtime/issues/104545)]");
}

using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
if (PlatformDetection.IsWindows)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void ReuseUnicastPort_CreateSocketSetOption()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/104547", typeof(PlatformDetection), nameof(PlatformDetection.IsQemuLinux))]
public void MulticastOption_CreateSocketSetGetOption_GroupAndInterfaceIndex_SetSucceeds_GetThrows()
{
int interfaceIndex = 0;
Expand All @@ -65,6 +66,7 @@ public void MulticastOption_CreateSocketSetGetOption_GroupAndInterfaceIndex_SetS
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoNorServerCore))] // Skip on Nano: https://github.com/dotnet/runtime/issues/26286
[ActiveIssue("https://github.com/dotnet/runtime/issues/104547", typeof(PlatformDetection), nameof(PlatformDetection.IsQemuLinux))]
public async Task MulticastInterface_Set_AnyInterface_Succeeds()
{
// On all platforms, index 0 means "any interface"
Expand Down Expand Up @@ -123,6 +125,7 @@ public void MulticastInterface_Set_InvalidIndex_Throws()
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoNorServerCore))] // Skip on Nano: https://github.com/dotnet/runtime/issues/26286
[SkipOnPlatform(TestPlatforms.OSX | TestPlatforms.FreeBSD, "Expected behavior is different on OSX or FreeBSD")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/52124", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/104547", typeof(PlatformDetection), nameof(PlatformDetection.IsQemuLinux))]
public async Task MulticastInterface_Set_IPv6_AnyInterface_Succeeds()
{
// On all platforms, index 0 means "any interface"
Expand Down