From 838499add354f33df0e096e894dded35dabf1330 Mon Sep 17 00:00:00 2001 From: derek-will <83545918+derek-will@users.noreply.github.com> Date: Fri, 11 Nov 2022 13:31:32 -0500 Subject: [PATCH] Added Protocol Support Condition Check on some Epoll tests and an Ioctl test - Progress on #57 --- test/SocketCANSharpTest/EpollTests.cs | 162 ++++++++++++++++++++++++++ test/SocketCANSharpTest/IoctlTests.cs | 4 + 2 files changed, 166 insertions(+) diff --git a/test/SocketCANSharpTest/EpollTests.cs b/test/SocketCANSharpTest/EpollTests.cs index 8ebd9d7..5dfef74 100644 --- a/test/SocketCANSharpTest/EpollTests.cs +++ b/test/SocketCANSharpTest/EpollTests.cs @@ -601,6 +601,15 @@ public void Epoll_Dispose_Test() [Test] public void Epoll_Add_Test() { + // Precondition Check + using (var socketHandle = LibcNativeMethods.Socket(SocketCanConstants.PF_CAN, SocketType.Dgram, SocketCanProtocolType.CAN_ISOTP)) + { + if (socketHandle.IsInvalid) + { + Assume.That(LibcNativeMethods.Errno, Is.Not.EqualTo(93) & Is.Not.EqualTo(22)); // If EPROTONOSUPPORT, then this protocol is not supported on this platform and no futher testing applies. If EINVAL, then Protocol Type is not being recognized as valid. + } + } + using (var epoll = new Epoll()) { Assert.IsFalse(epoll.SafeHandle.IsClosed); @@ -624,6 +633,15 @@ public void Epoll_Add_Test() [Test] public void Epoll_Add_Twice_Failure_Test() { + // Precondition Check + using (var socketHandle = LibcNativeMethods.Socket(SocketCanConstants.PF_CAN, SocketType.Dgram, SocketCanProtocolType.CAN_ISOTP)) + { + if (socketHandle.IsInvalid) + { + Assume.That(LibcNativeMethods.Errno, Is.Not.EqualTo(93) & Is.Not.EqualTo(22)); // If EPROTONOSUPPORT, then this protocol is not supported on this platform and no futher testing applies. If EINVAL, then Protocol Type is not being recognized as valid. + } + } + using (var epoll = new Epoll()) { Assert.IsFalse(epoll.SafeHandle.IsClosed); @@ -650,6 +668,15 @@ public void Epoll_Add_Twice_Failure_Test() [Test] public void Epoll_Add_Null_SafeFileDescriptorHandle_Failure_Test() { + // Precondition Check + using (var socketHandle = LibcNativeMethods.Socket(SocketCanConstants.PF_CAN, SocketType.Dgram, SocketCanProtocolType.CAN_ISOTP)) + { + if (socketHandle.IsInvalid) + { + Assume.That(LibcNativeMethods.Errno, Is.Not.EqualTo(93) & Is.Not.EqualTo(22)); // If EPROTONOSUPPORT, then this protocol is not supported on this platform and no futher testing applies. If EINVAL, then Protocol Type is not being recognized as valid. + } + } + using (var epoll = new Epoll()) { Assert.IsFalse(epoll.SafeHandle.IsClosed); @@ -673,6 +700,15 @@ public void Epoll_Add_Null_SafeFileDescriptorHandle_Failure_Test() [Test] public void Epoll_Add_Invalid_Event_With_EPOLLEXCLUSIVE_Failure_Test() { + // Precondition Check + using (var socketHandle = LibcNativeMethods.Socket(SocketCanConstants.PF_CAN, SocketType.Dgram, SocketCanProtocolType.CAN_ISOTP)) + { + if (socketHandle.IsInvalid) + { + Assume.That(LibcNativeMethods.Errno, Is.Not.EqualTo(93) & Is.Not.EqualTo(22)); // If EPROTONOSUPPORT, then this protocol is not supported on this platform and no futher testing applies. If EINVAL, then Protocol Type is not being recognized as valid. + } + } + using (var epoll = new Epoll()) { Assert.IsFalse(epoll.SafeHandle.IsClosed); @@ -698,6 +734,15 @@ public void Epoll_Add_Invalid_Event_With_EPOLLEXCLUSIVE_Failure_Test() [Test] public void Epoll_Add_ObjectDisposedException_Failure_Test() { + // Precondition Check + using (var socketHandle = LibcNativeMethods.Socket(SocketCanConstants.PF_CAN, SocketType.Dgram, SocketCanProtocolType.CAN_ISOTP)) + { + if (socketHandle.IsInvalid) + { + Assume.That(LibcNativeMethods.Errno, Is.Not.EqualTo(93) & Is.Not.EqualTo(22)); // If EPROTONOSUPPORT, then this protocol is not supported on this platform and no futher testing applies. If EINVAL, then Protocol Type is not being recognized as valid. + } + } + using (var epoll = new Epoll()) { Assert.IsFalse(epoll.SafeHandle.IsClosed); @@ -722,6 +767,15 @@ public void Epoll_Add_ObjectDisposedException_Failure_Test() [Test] public void Epoll_Remove_Test() { + // Precondition Check + using (var socketHandle = LibcNativeMethods.Socket(SocketCanConstants.PF_CAN, SocketType.Dgram, SocketCanProtocolType.CAN_ISOTP)) + { + if (socketHandle.IsInvalid) + { + Assume.That(LibcNativeMethods.Errno, Is.Not.EqualTo(93) & Is.Not.EqualTo(22)); // If EPROTONOSUPPORT, then this protocol is not supported on this platform and no futher testing applies. If EINVAL, then Protocol Type is not being recognized as valid. + } + } + using (var epoll = new Epoll()) { Assert.IsFalse(epoll.SafeHandle.IsClosed); @@ -746,6 +800,15 @@ public void Epoll_Remove_Test() [Test] public void Epoll_Remove_Not_Added_Failure_Test() { + // Precondition Check + using (var socketHandle = LibcNativeMethods.Socket(SocketCanConstants.PF_CAN, SocketType.Dgram, SocketCanProtocolType.CAN_ISOTP)) + { + if (socketHandle.IsInvalid) + { + Assume.That(LibcNativeMethods.Errno, Is.Not.EqualTo(93) & Is.Not.EqualTo(22)); // If EPROTONOSUPPORT, then this protocol is not supported on this platform and no futher testing applies. If EINVAL, then Protocol Type is not being recognized as valid. + } + } + using (var epoll = new Epoll()) { Assert.IsFalse(epoll.SafeHandle.IsClosed); @@ -771,6 +834,15 @@ public void Epoll_Remove_Not_Added_Failure_Test() [Test] public void Epoll_Remove_Null_SafeFileDescriptorHandle_Failure_Test() { + // Precondition Check + using (var socketHandle = LibcNativeMethods.Socket(SocketCanConstants.PF_CAN, SocketType.Dgram, SocketCanProtocolType.CAN_ISOTP)) + { + if (socketHandle.IsInvalid) + { + Assume.That(LibcNativeMethods.Errno, Is.Not.EqualTo(93) & Is.Not.EqualTo(22)); // If EPROTONOSUPPORT, then this protocol is not supported on this platform and no futher testing applies. If EINVAL, then Protocol Type is not being recognized as valid. + } + } + using (var epoll = new Epoll()) { Assert.IsFalse(epoll.SafeHandle.IsClosed); @@ -795,6 +867,15 @@ public void Epoll_Remove_Null_SafeFileDescriptorHandle_Failure_Test() [Test] public void Epoll_Remove_ObjectDisposedException_Failure_Test() { + // Precondition Check + using (var socketHandle = LibcNativeMethods.Socket(SocketCanConstants.PF_CAN, SocketType.Dgram, SocketCanProtocolType.CAN_ISOTP)) + { + if (socketHandle.IsInvalid) + { + Assume.That(LibcNativeMethods.Errno, Is.Not.EqualTo(93) & Is.Not.EqualTo(22)); // If EPROTONOSUPPORT, then this protocol is not supported on this platform and no futher testing applies. If EINVAL, then Protocol Type is not being recognized as valid. + } + } + using (var epoll = new Epoll()) { Assert.IsFalse(epoll.SafeHandle.IsClosed); @@ -820,6 +901,15 @@ public void Epoll_Remove_ObjectDisposedException_Failure_Test() [Test] public void Epoll_Modify_Test() { + // Precondition Check + using (var socketHandle = LibcNativeMethods.Socket(SocketCanConstants.PF_CAN, SocketType.Dgram, SocketCanProtocolType.CAN_ISOTP)) + { + if (socketHandle.IsInvalid) + { + Assume.That(LibcNativeMethods.Errno, Is.Not.EqualTo(93) & Is.Not.EqualTo(22)); // If EPROTONOSUPPORT, then this protocol is not supported on this platform and no futher testing applies. If EINVAL, then Protocol Type is not being recognized as valid. + } + } + using (var epoll = new Epoll()) { Assert.IsFalse(epoll.SafeHandle.IsClosed); @@ -846,6 +936,15 @@ public void Epoll_Modify_Test() [Test] public void Epoll_Modify_Include_EPOLLEXCLUSIVE_Failure_Test() { + // Precondition Check + using (var socketHandle = LibcNativeMethods.Socket(SocketCanConstants.PF_CAN, SocketType.Dgram, SocketCanProtocolType.CAN_ISOTP)) + { + if (socketHandle.IsInvalid) + { + Assume.That(LibcNativeMethods.Errno, Is.Not.EqualTo(93) & Is.Not.EqualTo(22)); // If EPROTONOSUPPORT, then this protocol is not supported on this platform and no futher testing applies. If EINVAL, then Protocol Type is not being recognized as valid. + } + } + using (var epoll = new Epoll()) { Assert.IsFalse(epoll.SafeHandle.IsClosed); @@ -874,6 +973,15 @@ public void Epoll_Modify_Include_EPOLLEXCLUSIVE_Failure_Test() [Test] public void Epoll_Modify_Not_Added_Failure_Test() { + // Precondition Check + using (var socketHandle = LibcNativeMethods.Socket(SocketCanConstants.PF_CAN, SocketType.Dgram, SocketCanProtocolType.CAN_ISOTP)) + { + if (socketHandle.IsInvalid) + { + Assume.That(LibcNativeMethods.Errno, Is.Not.EqualTo(93) & Is.Not.EqualTo(22)); // If EPROTONOSUPPORT, then this protocol is not supported on this platform and no futher testing applies. If EINVAL, then Protocol Type is not being recognized as valid. + } + } + using (var epoll = new Epoll()) { Assert.IsFalse(epoll.SafeHandle.IsClosed); @@ -901,6 +1009,15 @@ public void Epoll_Modify_Not_Added_Failure_Test() [Test] public void Epoll_Modify_Null_SafeFileDescriptorHandle_Failure_Test() { + // Precondition Check + using (var socketHandle = LibcNativeMethods.Socket(SocketCanConstants.PF_CAN, SocketType.Dgram, SocketCanProtocolType.CAN_ISOTP)) + { + if (socketHandle.IsInvalid) + { + Assume.That(LibcNativeMethods.Errno, Is.Not.EqualTo(93) & Is.Not.EqualTo(22)); // If EPROTONOSUPPORT, then this protocol is not supported on this platform and no futher testing applies. If EINVAL, then Protocol Type is not being recognized as valid. + } + } + using (var epoll = new Epoll()) { Assert.IsFalse(epoll.SafeHandle.IsClosed); @@ -927,6 +1044,15 @@ public void Epoll_Modify_Null_SafeFileDescriptorHandle_Failure_Test() [Test] public void Epoll_Modify_ObjectDisposedException_Failure_Test() { + // Precondition Check + using (var socketHandle = LibcNativeMethods.Socket(SocketCanConstants.PF_CAN, SocketType.Dgram, SocketCanProtocolType.CAN_ISOTP)) + { + if (socketHandle.IsInvalid) + { + Assume.That(LibcNativeMethods.Errno, Is.Not.EqualTo(93) & Is.Not.EqualTo(22)); // If EPROTONOSUPPORT, then this protocol is not supported on this platform and no futher testing applies. If EINVAL, then Protocol Type is not being recognized as valid. + } + } + using (var epoll = new Epoll()) { Assert.IsFalse(epoll.SafeHandle.IsClosed); @@ -955,6 +1081,15 @@ public void Epoll_Modify_ObjectDisposedException_Failure_Test() [Test] public void Epoll_Wait_Test() { + // Precondition Check + using (var socketHandle = LibcNativeMethods.Socket(SocketCanConstants.PF_CAN, SocketType.Dgram, SocketCanProtocolType.CAN_ISOTP)) + { + if (socketHandle.IsInvalid) + { + Assume.That(LibcNativeMethods.Errno, Is.Not.EqualTo(93) & Is.Not.EqualTo(22)); // If EPROTONOSUPPORT, then this protocol is not supported on this platform and no futher testing applies. If EINVAL, then Protocol Type is not being recognized as valid. + } + } + IEnumerable collection = CanNetworkInterface.GetAllInterfaces(true); Assert.IsNotNull(collection); Assert.GreaterOrEqual(collection.Count(), 1); @@ -1003,6 +1138,15 @@ public void Epoll_Wait_Test() [Test] public void Epoll_Wait_ObjectDisposedException_Failure_Test() { + // Precondition Check + using (var socketHandle = LibcNativeMethods.Socket(SocketCanConstants.PF_CAN, SocketType.Dgram, SocketCanProtocolType.CAN_ISOTP)) + { + if (socketHandle.IsInvalid) + { + Assume.That(LibcNativeMethods.Errno, Is.Not.EqualTo(93) & Is.Not.EqualTo(22)); // If EPROTONOSUPPORT, then this protocol is not supported on this platform and no futher testing applies. If EINVAL, then Protocol Type is not being recognized as valid. + } + } + IEnumerable collection = CanNetworkInterface.GetAllInterfaces(true); Assert.IsNotNull(collection); Assert.GreaterOrEqual(collection.Count(), 1); @@ -1043,6 +1187,15 @@ public void Epoll_Wait_ObjectDisposedException_Failure_Test() [Test] public void Epoll_Wait_ArgumentOutOfRangeException_Failure_Test() { + // Precondition Check + using (var socketHandle = LibcNativeMethods.Socket(SocketCanConstants.PF_CAN, SocketType.Dgram, SocketCanProtocolType.CAN_ISOTP)) + { + if (socketHandle.IsInvalid) + { + Assume.That(LibcNativeMethods.Errno, Is.Not.EqualTo(93) & Is.Not.EqualTo(22)); // If EPROTONOSUPPORT, then this protocol is not supported on this platform and no futher testing applies. If EINVAL, then Protocol Type is not being recognized as valid. + } + } + IEnumerable collection = CanNetworkInterface.GetAllInterfaces(true); Assert.IsNotNull(collection); Assert.GreaterOrEqual(collection.Count(), 1); @@ -1083,6 +1236,15 @@ public void Epoll_Wait_ArgumentOutOfRangeException_Failure_Test() [Test] public void Epoll_Wait_Timeout_Test() { + // Precondition Check + using (var socketHandle = LibcNativeMethods.Socket(SocketCanConstants.PF_CAN, SocketType.Dgram, SocketCanProtocolType.CAN_ISOTP)) + { + if (socketHandle.IsInvalid) + { + Assume.That(LibcNativeMethods.Errno, Is.Not.EqualTo(93) & Is.Not.EqualTo(22)); // If EPROTONOSUPPORT, then this protocol is not supported on this platform and no futher testing applies. If EINVAL, then Protocol Type is not being recognized as valid. + } + } + IEnumerable collection = CanNetworkInterface.GetAllInterfaces(true); Assert.IsNotNull(collection); Assert.GreaterOrEqual(collection.Count(), 1); diff --git a/test/SocketCANSharpTest/IoctlTests.cs b/test/SocketCANSharpTest/IoctlTests.cs index 0eb6077..790bfc9 100644 --- a/test/SocketCANSharpTest/IoctlTests.cs +++ b/test/SocketCANSharpTest/IoctlTests.cs @@ -107,6 +107,10 @@ public void GetInterfaceIndex_vcan0_MaximumTransmisisonUnit_ISOTP_Test() { using (SafeFileDescriptorHandle socketHandle = LibcNativeMethods.Socket(SocketCanConstants.PF_CAN, SocketType.Dgram, SocketCanProtocolType.CAN_ISOTP)) { + if (socketHandle.IsInvalid) + { + Assume.That(LibcNativeMethods.Errno, Is.Not.EqualTo(93) & Is.Not.EqualTo(22)); // If EPROTONOSUPPORT, then this protocol is not supported on this platform and no futher testing applies. If EINVAL, then Protocol Type is not being recognized as valid. + } Assert.IsFalse(socketHandle.IsInvalid); var ifr = new IfreqMtu("vcan0");