From 6fb4ca064275589d5d69973f4cf9227350bc9a75 Mon Sep 17 00:00:00 2001 From: derek-will <83545918+derek-will@users.noreply.github.com> Date: Fri, 11 Nov 2022 14:25:25 -0500 Subject: [PATCH] Added flexibility to two CAN_BCM tests where earlier kernel versions don't support the validation of bcm_timeval arguments while later releases will. --- test/SocketCANSharpTest/BcmCanSocketTests.cs | 29 ++++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/test/SocketCANSharpTest/BcmCanSocketTests.cs b/test/SocketCANSharpTest/BcmCanSocketTests.cs index d322d8e..b2a43be 100644 --- a/test/SocketCANSharpTest/BcmCanSocketTests.cs +++ b/test/SocketCANSharpTest/BcmCanSocketTests.cs @@ -300,9 +300,18 @@ public void BcmCanSocket_CreateCyclicTransmissionTask_InvalidTime_Failure_Test() InitialIntervalConfiguration = new BcmInitialIntervalConfiguration(10, new BcmTimeval(0, -1)), // invalid time PostInitialInterval = new BcmTimeval(-1, 0), // invalid time }; - SocketCanException ex = Assert.Throws(() => bcmCanSocket.CreateCyclicTransmissionTask(config, frames)); - Assert.AreEqual(SocketError.InvalidArgument, ex.SocketErrorCode); - Assert.AreEqual(22, ex.NativeErrorCode); + + try + { + // kernels prior to v5.0 won't throw - Updates to previous stable releases (i.e., v4.9.333) may throw + bcmCanSocket.CreateCyclicTransmissionTask(config, frames); + Assert.Inconclusive("Did not throw exception on invalid time configuration - This kernel does not support validation of that argument."); + } + catch (SocketCanException ex) + { + Assert.AreEqual(SocketError.InvalidArgument, ex.SocketErrorCode); + Assert.AreEqual(22, ex.NativeErrorCode); + } } } @@ -1147,9 +1156,17 @@ public void BcmCanSocket_CreateReceiveFilterSubscription_InvalidTime_Failure_Tes ReceiveMessageRateLimit = new BcmTimeval(-1, 0), // invalid time }; - SocketCanException ex = Assert.Throws(() => bcmCanSocket.CreateReceiveFilterSubscription(subscription, frames)); - Assert.AreEqual(SocketError.InvalidArgument, ex.SocketErrorCode); - Assert.AreEqual(22, ex.NativeErrorCode); + try + { + // kernels prior to v5.0 won't throw - Updates to previous stable releases (i.e., v4.9.333) may throw + bcmCanSocket.CreateReceiveFilterSubscription(subscription, frames); + Assert.Inconclusive("Did not throw exception on invalid time configuration - This kernel does not support validation of that argument."); + } + catch (SocketCanException ex) + { + Assert.AreEqual(SocketError.InvalidArgument, ex.SocketErrorCode); + Assert.AreEqual(22, ex.NativeErrorCode); + } } }