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 => IsQemu();
public static bool IsNotQemuLinux => !IsQemuLinux;

// OSX family
public static bool IsApplePlatform => IsOSX || IsiOS || IstvOS || IsMacCatalyst;
Expand Down Expand Up @@ -301,6 +304,15 @@ private static bool IsDistroAndVersionOrHigher(Predicate<string> distroPredicate
return false;
}

private static bool IsQemu()
{
if (IsLinux)
{
return Environment.GetEnvironmentVariable("DOTNET_RUNNING_UNDER_QEMU") != null;
}
return false;
}

private static bool VersionEquivalentTo(int major, int minor, int build, int revision, Version actualVersionId)
{
return (major == -1 || major == actualVersionId.Major)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,11 @@ public void Connect_ConnectTwice_NotSupported(int invalidatingAction)
{
using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
// Skip on Qemu due to [ActiveIssue(https://github.com/dotnet/runtime/issues/104542)]
if (PlatformDetection.IsQemuLinux && invalidatingAction == 1)
{
return;
}
switch (invalidatingAction)
{
case 0:
Expand Down Expand Up @@ -833,6 +838,11 @@ public void ConnectAsync_ConnectTwice_NotSupported(int invalidatingAction)

using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
// Skip on Qemu due to [ActiveIssue(https://github.com/dotnet/runtime/issues/104542)]
if (PlatformDetection.IsQemuLinux && invalidatingAction == 1)
{
return;
}
switch (invalidatingAction)
{
case 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,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 @@ -144,6 +145,11 @@ public void Socket_Get_KeepAlive_Time_AsByteArray_OptionLengthZero_Failure()
[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))
{
// Skip on Qemu due to [ActiveIssue(https://github.com/dotnet/runtime/issues/104545)]
return;
}
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