fix sockets tests on FreeBSD (dotnet/corefx#42518)
authorTomas Weinfurt <tweinfurt@yahoo.com>
Sun, 10 Nov 2019 04:45:23 +0000 (20:45 -0800)
committerGitHub <noreply@github.com>
Sun, 10 Nov 2019 04:45:23 +0000 (20:45 -0800)
Commit migrated from https://github.com/dotnet/corefx/commit/bc115700c3ece60acd6b8dbe4b0bdb8f6f80c756

src/libraries/Native/Unix/Common/pal_config.h.in
src/libraries/Native/Unix/System.Native/pal_networking.c
src/libraries/Native/Unix/configure.cmake
src/libraries/System.Net.Sockets/tests/FunctionalTests/Connect.cs
src/libraries/System.Net.Sockets/tests/FunctionalTests/DualModeSocketTest.cs
src/libraries/System.Net.Sockets/tests/FunctionalTests/SendReceive.cs
src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketOptionNameTest.cs
src/libraries/System.Net.Sockets/tests/FunctionalTests/UdpClientTest.cs

index 66dc206..e4507c0 100644 (file)
@@ -49,6 +49,7 @@
 #cmakedefine01 HAVE_KQUEUE
 #cmakedefine01 HAVE_SENDFILE_4
 #cmakedefine01 HAVE_SENDFILE_6
+#cmakedefine01 HAVE_SENDFILE_7
 #cmakedefine01 HAVE_CLONEFILE
 #cmakedefine01 HAVE_GETNAMEINFO_SIGNED_FLAGS
 #cmakedefine01 HAVE_GETPEEREID
index 60aac3a..9b1cd7b 100644 (file)
@@ -2821,12 +2821,16 @@ int32_t SystemNative_SendFile(intptr_t out_fd, intptr_t in_fd, int64_t offset, i
     *sent = 0;
     return SystemNative_ConvertErrorPlatformToPal(errno);
 
-#elif HAVE_SENDFILE_6
+#elif HAVE_SENDFILE_6 || HAVE_SENDFILE_7
     *sent = 0;
     while (1) // in case we need to retry for an EINTR
     {
         off_t len = count;
+#if HAVE_SENDFILE_7
+        ssize_t res = sendfile(infd, outfd, (off_t)offset, (size_t)count, NULL, &len, 0);
+#else
         ssize_t res = sendfile(infd, outfd, (off_t)offset, &len, NULL, 0);
+#endif
         assert(len >= 0);
 
         // If the call succeeded, store the number of bytes sent, and return.  We add
index e3026cf..139102a 100644 (file)
@@ -359,6 +359,16 @@ check_c_source_compiles(
     "
     HAVE_SENDFILE_6)
 
+check_c_source_compiles(
+    "
+    #include <stdlib.h>
+    #include <sys/types.h>
+    #include <sys/socket.h>
+    #include <sys/uio.h>
+    int main(void) { int i = sendfile(0, 0, 0, 0, NULL, NULL, 0); return 0; }
+    "
+    HAVE_SENDFILE_7)
+
 check_symbol_exists(
     clonefile
     "sys/clonefile.h"
index fe19cb8..4dd8385 100644 (file)
@@ -88,7 +88,7 @@ namespace System.Net.Sockets.Tests
         }
 
         [Fact]
-        [PlatformSpecific(~TestPlatforms.OSX)] // Not supported on OSX.
+        [PlatformSpecific(~(TestPlatforms.OSX | TestPlatforms.FreeBSD))] // Not supported on BSD like OSes.
         public async Task ConnectGetsCanceledByDispose()
         {
             bool usesApm = UsesApm ||
index 0db74be..a40a641 100644 (file)
@@ -2419,6 +2419,11 @@ namespace System.Net.Sockets.Tests
             {
                 Assert.True(socket.DualMode);
             }
+            else if (RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD))
+            {
+                // This is not valid check on FreeBSD.
+                // Accepted socket is never DualMode and cannot be changed.
+            }
             else
             {
                 Assert.True((listenOn != IPAddress.IPv6Any && !listenOn.IsIPv4MappedToIPv6) || socket.DualMode);
index 3f39b82..999b0cc 100644 (file)
@@ -766,7 +766,7 @@ namespace System.Net.Sockets.Tests
         }
 
         [Fact]
-        [PlatformSpecific(~TestPlatforms.OSX)] // SendBufferSize, ReceiveBufferSize = 0 not supported on OSX.
+        [PlatformSpecific(~(TestPlatforms.OSX | TestPlatforms.FreeBSD))] // SendBufferSize, ReceiveBufferSize = 0 not supported on BSD like stacks.
         public async Task SendRecv_NoBuffering_Success()
         {
             if (UsesSync) return;
index 71aadd2..89eeac3 100644 (file)
@@ -129,7 +129,7 @@ namespace System.Net.Sockets.Tests
         }
 
         [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] // Skip on Nano: dotnet/corefx #29929
-        [PlatformSpecific(~TestPlatforms.OSX)]
+        [PlatformSpecific(~(TestPlatforms.OSX | TestPlatforms.FreeBSD))]
         public async Task MulticastInterface_Set_IPv6_AnyInterface_Succeeds()
         {
             if (PlatformDetection.IsRedHatFamily7)
@@ -244,6 +244,7 @@ namespace System.Net.Sockets.Tests
         [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // In WSL, the connect() call fails immediately.
         [InlineData(false)]
         [InlineData(true)]
+        [PlatformSpecific(~TestPlatforms.FreeBSD)] // on FreeBSD Connect may or may not fail immediately based on timing.
         public void FailedConnect_GetSocketOption_SocketOptionNameError(bool simpleGet)
         {
             using (var client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) { Blocking = false })
index d0c374e..dae8dff 100644 (file)
@@ -256,7 +256,7 @@ namespace System.Net.Sockets.Tests
             }
         }
 
-        [PlatformSpecific(~TestPlatforms.OSX)] // macOS doesn't have an equivalent of DontFragment
+        [PlatformSpecific(~(TestPlatforms.OSX | TestPlatforms.FreeBSD))] // BSD like doesn't have an equivalent of DontFragment
         [Fact]
         public void DontFragment_Roundtrips()
         {