diff options
author | Alexander Köplinger <alex.koeplinger@outlook.com> | 2016-01-27 00:06:56 +0300 |
---|---|---|
committer | Alexander Köplinger <alex.koeplinger@outlook.com> | 2016-01-27 00:06:56 +0300 |
commit | 229f1532943e8d2ca048638d6a38cf499fe5c7a3 (patch) | |
tree | 1b14899d24150d15ed1574c72c799cc15eeb1a42 | |
parent | a8b276ed8c76125cdd282bb5bdefe89d3a51f579 (diff) | |
parent | 343fc2253d2e7041cdb966224561bd1a63f5573c (diff) |
Merge pull request #2517 from steffen-kiess/posix-socket-osx-test
[Mono.Posix] Fix the SocketTest.ControlMsg() test on OSX
-rw-r--r-- | mcs/class/Mono.Posix/Test/Mono.Unix.Native/SocketTest.cs | 88 |
1 files changed, 62 insertions, 26 deletions
diff --git a/mcs/class/Mono.Posix/Test/Mono.Unix.Native/SocketTest.cs b/mcs/class/Mono.Posix/Test/Mono.Unix.Native/SocketTest.cs index 0e3dae15ff3..3ec10f916ce 100644 --- a/mcs/class/Mono.Posix/Test/Mono.Unix.Native/SocketTest.cs +++ b/mcs/class/Mono.Posix/Test/Mono.Unix.Native/SocketTest.cs @@ -731,35 +731,57 @@ namespace MonoTests.Mono.Unix.Native }); } - [Test] - [Category ("NotOnMac")] - public unsafe void ControlMsg () + public unsafe void ControlMsg (bool useMultipleControlMessages) { // Create two socket pairs and send inner_so1 and inner_so2 over the other socket pair using SCM_RIGHTS WithSocketPair ((inner_so1, inner_so2) => { WithSocketPair ((so1, so2) => { - // Create two SCM_RIGHTS control messages - var cmsg = new byte[2 * Syscall.CMSG_SPACE (sizeof (int))]; - var hdr = new Cmsghdr { - cmsg_len = (long) Syscall.CMSG_LEN (sizeof (int)), - cmsg_level = UnixSocketProtocol.SOL_SOCKET, - cmsg_type = UnixSocketControlMessage.SCM_RIGHTS, - }; - var msghdr1 = new Msghdr { - msg_control = cmsg, - msg_controllen = cmsg.Length, - }; - long offset = 0; - hdr.WriteToBuffer (msghdr1, offset); - var dataOffset = Syscall.CMSG_DATA (msghdr1, offset); - fixed (byte* ptr = msghdr1.msg_control) { - ((int*) (ptr + dataOffset))[0] = inner_so1; - } - offset = (long) Syscall.CMSG_SPACE (sizeof (int)); - hdr.WriteToBuffer (msghdr1, offset); - dataOffset = Syscall.CMSG_DATA (msghdr1, offset); - fixed (byte* ptr = msghdr1.msg_control) { - ((int*) (ptr + dataOffset))[0] = inner_so2; + byte[] cmsg; + Msghdr msghdr1; + long offset; + if (useMultipleControlMessages) { + // Create two SCM_RIGHTS control messages + cmsg = new byte[2 * Syscall.CMSG_SPACE (sizeof (int))]; + var hdr = new Cmsghdr { + cmsg_len = (long) Syscall.CMSG_LEN (sizeof (int)), + cmsg_level = UnixSocketProtocol.SOL_SOCKET, + cmsg_type = UnixSocketControlMessage.SCM_RIGHTS, + }; + msghdr1 = new Msghdr { + msg_control = cmsg, + msg_controllen = cmsg.Length, + }; + offset = 0; + hdr.WriteToBuffer (msghdr1, offset); + var dataOffset = Syscall.CMSG_DATA (msghdr1, offset); + fixed (byte* ptr = msghdr1.msg_control) { + ((int*) (ptr + dataOffset))[0] = inner_so1; + } + offset = (long) Syscall.CMSG_SPACE (sizeof (int)); + hdr.WriteToBuffer (msghdr1, offset); + dataOffset = Syscall.CMSG_DATA (msghdr1, offset); + fixed (byte* ptr = msghdr1.msg_control) { + ((int*) (ptr + dataOffset))[0] = inner_so2; + } + } else { + // Create one SCM_RIGHTS control message + cmsg = new byte[Syscall.CMSG_SPACE (2 * sizeof (int))]; + var hdr = new Cmsghdr { + cmsg_len = (long) Syscall.CMSG_LEN (2 * sizeof (int)), + cmsg_level = UnixSocketProtocol.SOL_SOCKET, + cmsg_type = UnixSocketControlMessage.SCM_RIGHTS, + }; + msghdr1 = new Msghdr { + msg_control = cmsg, + msg_controllen = cmsg.Length, + }; + offset = 0; + hdr.WriteToBuffer (msghdr1, offset); + var dataOffset = Syscall.CMSG_DATA (msghdr1, offset); + fixed (byte* ptr = msghdr1.msg_control) { + ((int*) (ptr + dataOffset))[0] = inner_so1; + ((int*) (ptr + dataOffset))[1] = inner_so2; + } } long ret; @@ -799,7 +821,8 @@ namespace MonoTests.Mono.Unix.Native if (ret < 0) UnixMarshal.ThrowExceptionForLastError (); - Assert.IsTrue ((msghdr2.msg_flags & MessageFlags.MSG_CTRUNC) != 0); // Control message has been truncated + if (useMultipleControlMessages) // This assertion fails on OSX for some reason + Assert.IsTrue ((msghdr2.msg_flags & MessageFlags.MSG_CTRUNC) != 0); // Control message has been truncated Assert.AreEqual (buffer1.Length, ret); for (int i = 0; i < buffer1.Length; i++) @@ -883,6 +906,19 @@ namespace MonoTests.Mono.Unix.Native }); }); } + + [Test] + public unsafe void ControlMsgOneCmsg () + { + ControlMsg (useMultipleControlMessages: false); + } + + [Test] + [Category ("NotOnMac")] + public unsafe void ControlMsgMultipleCMsgs () + { + ControlMsg (useMultipleControlMessages: true); + } } } |