Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RISC-V] Fix System.Net.Sockets.Tests on Qemu #104094

Merged
merged 10 commits into from
Jul 24, 2024
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// 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;
using System.Collections;

namespace System
{
Expand Down Expand Up @@ -30,6 +32,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 +305,21 @@ private static bool IsDistroAndVersionOrHigher(Predicate<string> distroPredicate
return false;
}

private static bool IsQemu()
{
if (IsLinux)
{
foreach (DictionaryEntry entry in Environment.GetEnvironmentVariables())
{
if (((String)entry.Key).ToUpper() == "DOTNET_RUNNING_UNDER_QEMU")
{
return true;
}
}
}
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))
{
// On Qemu we omit one test case due to: https://gitlab.com/qemu-project/qemu/-/issues/2410
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))
{
// On Qemu we omit one test case due to: https://gitlab.com/qemu-project/qemu/-/issues/2410
if (!PlatformDetection.IsNotQemuLinux && invalidatingAction == 1)
{
return;
}
switch (invalidatingAction)
{
case 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void Socket_KeepAlive_Interval_And_Time()
}
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotQemuLinux))] // Skip on Qemu due to https://gitlab.com/qemu-project/qemu/-/issues/2390
public void Socket_Get_KeepAlive_Time_AsByteArray_OptionLengthZero_Failure()
{
using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
Expand All @@ -144,6 +144,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.IsNotQemuLinux && (buffer == null || buffer.Length == 0))
{
// Skip on Qemu due to https://gitlab.com/qemu-project/qemu/-/issues/2390
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 @@ -15,6 +15,7 @@ namespace System.Net.Sockets.Tests
public partial class SocketOptionNameTest
{
private static bool SocketsReuseUnicastPortSupport => Capability.SocketsReuseUnicastPortSupport().HasValue;
private static bool SupportedOnPlatform = PlatformDetection.IsNotWindowsNanoNorServerCore && PlatformDetection.IsNotQemuLinux;

[ConditionalFact(nameof(SocketsReuseUnicastPortSupport))]
public void ReuseUnicastPort_CreateSocketGetOption()
Expand Down Expand Up @@ -50,7 +51,7 @@ public void ReuseUnicastPort_CreateSocketSetOption()
}
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotQemuLinux))]
public void MulticastOption_CreateSocketSetGetOption_GroupAndInterfaceIndex_SetSucceeds_GetThrows()
{
int interfaceIndex = 0;
Expand All @@ -64,7 +65,7 @@ public void MulticastOption_CreateSocketSetGetOption_GroupAndInterfaceIndex_SetS
}
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoNorServerCore))] // Skip on Nano: https://github.com/dotnet/runtime/issues/26286
[ConditionalFact(nameof(SupportedOnPlatform))] // Skip on Nano: https://github.com/dotnet/runtime/issues/26286 and Qemu
public async Task MulticastInterface_Set_AnyInterface_Succeeds()
{
// On all platforms, index 0 means "any interface"
Expand Down Expand Up @@ -120,7 +121,7 @@ public void MulticastInterface_Set_InvalidIndex_Throws()
}
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoNorServerCore))] // Skip on Nano: https://github.com/dotnet/runtime/issues/26286
[ConditionalFact(nameof(SupportedOnPlatform))] // Skip on Nano: https://github.com/dotnet/runtime/issues/26286 and Qemu
[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)]
public async Task MulticastInterface_Set_IPv6_AnyInterface_Succeeds()
Expand Down