Skip to content

Commit

Permalink
Added Protocol Support Condition Check on some Epoll tests and an Ioc…
Browse files Browse the repository at this point in the history
…tl test - Progress on #57
  • Loading branch information
derek-will committed Nov 11, 2022
1 parent 54f60fe commit 838499a
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 0 deletions.
162 changes: 162 additions & 0 deletions test/SocketCANSharpTest/EpollTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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<CanNetworkInterface> collection = CanNetworkInterface.GetAllInterfaces(true);
Assert.IsNotNull(collection);
Assert.GreaterOrEqual(collection.Count(), 1);
Expand Down Expand Up @@ -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<CanNetworkInterface> collection = CanNetworkInterface.GetAllInterfaces(true);
Assert.IsNotNull(collection);
Assert.GreaterOrEqual(collection.Count(), 1);
Expand Down Expand Up @@ -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<CanNetworkInterface> collection = CanNetworkInterface.GetAllInterfaces(true);
Assert.IsNotNull(collection);
Assert.GreaterOrEqual(collection.Count(), 1);
Expand Down Expand Up @@ -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<CanNetworkInterface> collection = CanNetworkInterface.GetAllInterfaces(true);
Assert.IsNotNull(collection);
Assert.GreaterOrEqual(collection.Count(), 1);
Expand Down
4 changes: 4 additions & 0 deletions test/SocketCANSharpTest/IoctlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 838499a

Please sign in to comment.