From 2eda6ecd9e62058634b339a09e578b9bf0572270 Mon Sep 17 00:00:00 2001 From: KonradBkd <117755498+KonradBkd@users.noreply.github.com> Date: Thu, 28 Nov 2024 13:20:25 +0100 Subject: [PATCH] dev: Use targetted messaging towards netsim (#151) * dev: Use targetted messaging towards netsim * tests: Adapt tests to netsim targetted messaging * Apply suggestions from code review --- .../services/can/SimBehaviorDetailed.cpp | 2 +- .../can/Test_CanControllerDetailedSim.cpp | 41 +++++++------ .../services/ethernet/SimBehaviorDetailed.cpp | 2 +- .../Test_EthControllerDetailedSim.cpp | 24 ++++---- .../services/flexray/FlexrayController.cpp | 2 +- .../flexray/Test_FlexrayController.cpp | 59 +++++++++++-------- SilKit/source/services/lin/LinTestUtils.hpp | 15 +++-- .../services/lin/SimBehaviorDetailed.cpp | 31 ++++++---- .../services/lin/SimBehaviorDetailed.hpp | 5 +- .../lin/Test_LinControllerDetailedSim.cpp | 18 +++--- 10 files changed, 118 insertions(+), 81 deletions(-) diff --git a/SilKit/source/services/can/SimBehaviorDetailed.cpp b/SilKit/source/services/can/SimBehaviorDetailed.cpp index 46258ca84..f1961e098 100644 --- a/SilKit/source/services/can/SimBehaviorDetailed.cpp +++ b/SilKit/source/services/can/SimBehaviorDetailed.cpp @@ -38,7 +38,7 @@ SimBehaviorDetailed::SimBehaviorDetailed(Core::IParticipantInternal* participant template void SimBehaviorDetailed::SendMsgImpl(MsgT&& msg) { - _participant->SendMsg(_parentServiceEndpoint, std::forward(msg)); + _participant->SendMsg(_parentServiceEndpoint, _simulatedLink.GetParticipantName(), std::forward(msg)); } void SimBehaviorDetailed::SendMsg(CanConfigureBaudrate&& msg) { diff --git a/SilKit/source/services/can/Test_CanControllerDetailedSim.cpp b/SilKit/source/services/can/Test_CanControllerDetailedSim.cpp index 6a6f76790..e664367bd 100644 --- a/SilKit/source/services/can/Test_CanControllerDetailedSim.cpp +++ b/SilKit/source/services/can/Test_CanControllerDetailedSim.cpp @@ -50,11 +50,12 @@ using ::SilKit::Core::Tests::DummyParticipant; class MockParticipant : public DummyParticipant { + public: - MOCK_METHOD2(SendMsg, void(const IServiceEndpoint *, const WireCanFrameEvent &)); - MOCK_METHOD2(SendMsg, void(const IServiceEndpoint *, const CanFrameTransmitEvent &)); - MOCK_METHOD2(SendMsg, void(const IServiceEndpoint *, const CanConfigureBaudrate &)); - MOCK_METHOD2(SendMsg, void(const IServiceEndpoint *, const CanSetControllerMode &)); + MOCK_METHOD(void, SendMsg, (const IServiceEndpoint *, const std::string &, const WireCanFrameEvent &), (override)); + MOCK_METHOD(void, SendMsg, (const IServiceEndpoint *, const std::string &, const CanFrameTransmitEvent &), (override)); + MOCK_METHOD(void, SendMsg, (const IServiceEndpoint *, const std::string &, const CanConfigureBaudrate &), (override)); + MOCK_METHOD(void, SendMsg, (const IServiceEndpoint *, const std::string &, const CanSetControllerMode &), (override)); }; class CanControllerCallbacks @@ -66,16 +67,18 @@ class CanControllerCallbacks MOCK_METHOD2(FrameTransmitHandler, void(ICanController *, CanFrameTransmitEvent)); }; +const std::string netsimName = "bussim"; + TEST(Test_CanControllerDetailedSim, send_can_message) { MockParticipant mockParticipant; CanController canController(&mockParticipant, {}, mockParticipant.GetTimeProvider()); - canController.SetDetailedBehavior({"bussim", "n1", "c1", 8}); + canController.SetDetailedBehavior({netsimName, "n1", "c1", 8}); canController.SetServiceDescriptor({"p1", "n1", "c1", 8}); WireCanFrameEvent testFrameEvent{}; - EXPECT_CALL(mockParticipant, SendMsg(&canController, testFrameEvent)).Times(1); + EXPECT_CALL(mockParticipant, SendMsg(&canController, netsimName, testFrameEvent)).Times(1); canController.SendFrame(ToCanFrame(testFrameEvent.frame)); } @@ -84,7 +87,7 @@ TEST(Test_CanControllerDetailedSim, receive_can_message) { using namespace std::placeholders; - ServiceDescriptor busSimAddress{"bussim", "n1", "c1", 8}; + ServiceDescriptor busSimAddress{netsimName, "n1", "c1", 8}; MockParticipant mockParticipant; CanControllerCallbacks callbackProvider; @@ -110,7 +113,7 @@ TEST(Test_CanControllerDetailedSim, start_stop_sleep_reset) MockParticipant mockParticipant; CanController canController(&mockParticipant, {}, mockParticipant.GetTimeProvider()); - canController.SetDetailedBehavior({"bussim", "n1", "c1", 8}); + canController.SetDetailedBehavior({netsimName, "n1", "c1", 8}); canController.SetServiceDescriptor({"p1", "n1", "c1", 8}); CanSetControllerMode startCommand = {{0, 0}, CanControllerState::Started}; @@ -118,10 +121,10 @@ TEST(Test_CanControllerDetailedSim, start_stop_sleep_reset) CanSetControllerMode sleepCommand = {{0, 0}, CanControllerState::Sleep}; CanSetControllerMode resetCommand = {{1, 1}, CanControllerState::Uninit}; - EXPECT_CALL(mockParticipant, SendMsg(&canController, startCommand)).Times(1); - EXPECT_CALL(mockParticipant, SendMsg(&canController, stopCommand)).Times(1); - EXPECT_CALL(mockParticipant, SendMsg(&canController, sleepCommand)).Times(1); - EXPECT_CALL(mockParticipant, SendMsg(&canController, resetCommand)).Times(1); + EXPECT_CALL(mockParticipant, SendMsg(&canController, netsimName, startCommand)).Times(1); + EXPECT_CALL(mockParticipant, SendMsg(&canController, netsimName, stopCommand)).Times(1); + EXPECT_CALL(mockParticipant, SendMsg(&canController, netsimName, sleepCommand)).Times(1); + EXPECT_CALL(mockParticipant, SendMsg(&canController, netsimName, resetCommand)).Times(1); canController.Start(); canController.Stop(); @@ -134,14 +137,14 @@ TEST(Test_CanControllerDetailedSim, set_baudrate) MockParticipant mockParticipant; CanController canController(&mockParticipant, {}, mockParticipant.GetTimeProvider()); - canController.SetDetailedBehavior({"bussim", "n1", "c1", 8}); + canController.SetDetailedBehavior({netsimName, "n1", "c1", 8}); canController.SetServiceDescriptor({"p1", "n1", "c1", 8}); CanConfigureBaudrate baudrate1 = {3000, 0, 0}; CanConfigureBaudrate baudrate2 = {3000, 500000, 0}; - EXPECT_CALL(mockParticipant, SendMsg(&canController, baudrate1)).Times(1); - EXPECT_CALL(mockParticipant, SendMsg(&canController, baudrate2)).Times(1); + EXPECT_CALL(mockParticipant, SendMsg(&canController, netsimName, baudrate1)).Times(1); + EXPECT_CALL(mockParticipant, SendMsg(&canController, netsimName, baudrate2)).Times(1); canController.SetBaudRate(baudrate1.baudRate, baudrate1.fdBaudRate, baudrate1.xlBaudRate); canController.SetBaudRate(baudrate2.baudRate, baudrate2.fdBaudRate, baudrate2.xlBaudRate); @@ -151,7 +154,7 @@ TEST(Test_CanControllerDetailedSim, receive_new_controller_state) { using namespace std::placeholders; - ServiceDescriptor busSimAddress{"bussim", "n1", "c1", 8}; + ServiceDescriptor busSimAddress{netsimName, "n1", "c1", 8}; MockParticipant mockParticipant; @@ -197,7 +200,7 @@ TEST(Test_CanControllerDetailedSim, receive_new_controller_state) TEST(Test_CanControllerDetailedSim, receive_ack) { using namespace std::placeholders; - ServiceDescriptor busSimAddress{"bussim", "n1", "c1", 8}; + ServiceDescriptor busSimAddress{netsimName, "n1", "c1", 8}; MockParticipant mockParticipant; @@ -245,7 +248,9 @@ TEST(Test_CanControllerDetailedSim, must_not_generate_ack) canController.SetServiceDescriptor(controllerAddress); WireCanFrameEvent msg{}; - EXPECT_CALL(mockParticipant, SendMsg(An(), A())).Times(0); + EXPECT_CALL(mockParticipant, + SendMsg(An(), netsimName, A())) + .Times(0); CanController canControllerFrom(&mockParticipant, {}, mockParticipant.GetTimeProvider()); canControllerFrom.SetServiceDescriptor(busSimAddress); diff --git a/SilKit/source/services/ethernet/SimBehaviorDetailed.cpp b/SilKit/source/services/ethernet/SimBehaviorDetailed.cpp index 61cc475e2..d074bc52b 100644 --- a/SilKit/source/services/ethernet/SimBehaviorDetailed.cpp +++ b/SilKit/source/services/ethernet/SimBehaviorDetailed.cpp @@ -37,7 +37,7 @@ SimBehaviorDetailed::SimBehaviorDetailed(Core::IParticipantInternal* participant template void SimBehaviorDetailed::SendMsgImpl(MsgT&& msg) { - _participant->SendMsg(_parentServiceEndpoint, std::forward(msg)); + _participant->SendMsg(_parentServiceEndpoint, _simulatedLink.GetParticipantName(), std::forward(msg)); } void SimBehaviorDetailed::SendMsg(WireEthernetFrameEvent&& msg) diff --git a/SilKit/source/services/ethernet/Test_EthControllerDetailedSim.cpp b/SilKit/source/services/ethernet/Test_EthControllerDetailedSim.cpp index 367c8e399..b7a17f733 100644 --- a/SilKit/source/services/ethernet/Test_EthControllerDetailedSim.cpp +++ b/SilKit/source/services/ethernet/Test_EthControllerDetailedSim.cpp @@ -61,10 +61,10 @@ auto AnEthMessageWith(std::chrono::nanoseconds timestamp) -> testing::Matcher(17); - EXPECT_CALL(participant, SendMsg(An(), A())).Times(0); + EXPECT_CALL(participant, + SendMsg(An(), netsimName, A())) + .Times(0); controller.ReceiveMsg(&controllerBusSim, msg); } diff --git a/SilKit/source/services/flexray/FlexrayController.cpp b/SilKit/source/services/flexray/FlexrayController.cpp index 235889f48..7dc330038 100644 --- a/SilKit/source/services/flexray/FlexrayController.cpp +++ b/SilKit/source/services/flexray/FlexrayController.cpp @@ -340,7 +340,7 @@ void FlexrayController::ReceiveMsg(const IServiceEndpoint* from, const FlexrayPo template void FlexrayController::SendMsg(MsgT&& msg) { - _participant->SendMsg(this, std::forward(msg)); + _participant->SendMsg(this, _simulatedLink.GetParticipantName(), std::forward(msg)); } //------------------------ diff --git a/SilKit/source/services/flexray/Test_FlexrayController.cpp b/SilKit/source/services/flexray/Test_FlexrayController.cpp index 8378974ac..d9f120692 100644 --- a/SilKit/source/services/flexray/Test_FlexrayController.cpp +++ b/SilKit/source/services/flexray/Test_FlexrayController.cpp @@ -145,10 +145,10 @@ auto GetDummyConfigWithValues() -> SilKit::Config::FlexrayController class MockParticipant : public DummyParticipant { public: - MOCK_METHOD2(SendMsg, void(const IServiceEndpoint *, const FlexrayHostCommand &)); - MOCK_METHOD2(SendMsg, void(const IServiceEndpoint *, const FlexrayControllerConfig &)); - MOCK_METHOD2(SendMsg, void(const IServiceEndpoint *, const FlexrayTxBufferConfigUpdate &)); - MOCK_METHOD2(SendMsg, void(const IServiceEndpoint *, const WireFlexrayTxBufferUpdate &)); + MOCK_METHOD(void, SendMsg, (const IServiceEndpoint *, const std::string&, const FlexrayHostCommand &), (override)); + MOCK_METHOD(void, SendMsg, (const IServiceEndpoint *, const std::string&, const FlexrayControllerConfig &), (override)); + MOCK_METHOD(void, SendMsg, (const IServiceEndpoint *, const std::string&, const FlexrayTxBufferConfigUpdate &), (override)); + MOCK_METHOD(void, SendMsg, (const IServiceEndpoint *, const std::string&, const WireFlexrayTxBufferUpdate &), (override)); }; class Test_FlexrayController : public testing::Test @@ -173,15 +173,20 @@ class Test_FlexrayController : public testing::Test { controller.SetServiceDescriptor(controllerAddress); controller.SetDetailedBehavior(busSimAddress); + controllerConfigured.SetServiceDescriptor(controllerConfiguredAddress); + controllerConfigured.SetDetailedBehavior(busSimAddress); + controllerBusSim.SetServiceDescriptor(busSimAddress); + referencePayload.resize(20); std::iota(referencePayload.begin(), referencePayload.end(), '\000'); - controllerBusSim.SetServiceDescriptor(busSimAddress); } protected: + const std::string netsimName = "bussim"; const ServiceDescriptor controllerAddress{"p1", "n1", "c1", 5}; - const ServiceDescriptor busSimAddress{"bussim", "n1", "c1", 5}; + const ServiceDescriptor controllerConfiguredAddress{"p2", "n1", "c1", 5}; + const ServiceDescriptor busSimAddress{netsimName, "n1", "c1", 5}; std::vector referencePayload; @@ -203,7 +208,7 @@ TEST_F(Test_FlexrayController, send_controller_config) controllerCfg.bufferConfigs.push_back(MakeValidTxBufferConfig()); - EXPECT_CALL(participant, SendMsg(&controller, controllerCfg)).Times(1); + EXPECT_CALL(participant, SendMsg(&controller, netsimName, controllerCfg)).Times(1); controller.Configure(controllerCfg); } @@ -222,7 +227,7 @@ TEST_F(Test_FlexrayController, send_controller_config_override_identical) testControllerCfg.nodeParams = MakeValidNodeParams(); testControllerCfg.bufferConfigs.push_back(MakeValidTxBufferConfig()); - EXPECT_CALL(participant, SendMsg(&controllerConfigured, configuredControllerCfg)).Times(1); + EXPECT_CALL(participant, SendMsg(&controllerConfigured, netsimName, configuredControllerCfg)).Times(1); controllerConfigured.Configure(testControllerCfg); } @@ -245,7 +250,7 @@ TEST_F(Test_FlexrayController, send_controller_config_override_cluster_params) testControllerCfg.nodeParams = MakeValidNodeParams(); testControllerCfg.bufferConfigs.push_back(MakeValidTxBufferConfig()); - EXPECT_CALL(participant, SendMsg(&controllerConfigured, configuredControllerCfg)).Times(1); + EXPECT_CALL(participant, SendMsg(&controllerConfigured, netsimName, configuredControllerCfg)).Times(1); controllerConfigured.Configure(testControllerCfg); } @@ -268,7 +273,7 @@ TEST_F(Test_FlexrayController, send_controller_config_override_node_params) testControllerCfg.clusterParams = MakeValidClusterParams(); testControllerCfg.bufferConfigs.push_back(MakeValidTxBufferConfig()); - EXPECT_CALL(participant, SendMsg(&controllerConfigured, configuredControllerCfg)).Times(1); + EXPECT_CALL(participant, SendMsg(&controllerConfigured, netsimName, configuredControllerCfg)).Times(1); controllerConfigured.Configure(testControllerCfg); } @@ -291,7 +296,7 @@ TEST_F(Test_FlexrayController, send_controller_config_override_tx_buffer) testControllerCfg.clusterParams = MakeValidClusterParams(); testControllerCfg.nodeParams = MakeValidNodeParams(); - EXPECT_CALL(participant, SendMsg(&controllerConfigured, configuredControllerCfg)).Times(1); + EXPECT_CALL(participant, SendMsg(&controllerConfigured, netsimName, configuredControllerCfg)).Times(1); controllerConfigured.Configure(testControllerCfg); } @@ -310,7 +315,7 @@ TEST_F(Test_FlexrayController, send_txbuffer_configupdate) controllerCfg.nodeParams = MakeValidNodeParams(); controllerCfg.bufferConfigs.push_back(bufferCfg); - EXPECT_CALL(participant, SendMsg(&controller, controllerCfg)).Times(1); + EXPECT_CALL(participant, SendMsg(&controller, netsimName, controllerCfg)).Times(1); controller.Configure(controllerCfg); // Reconfigure TxBuffer 0 @@ -325,7 +330,7 @@ TEST_F(Test_FlexrayController, send_txbuffer_configupdate) expectedUpdate.txBufferIndex = 0; expectedUpdate.txBufferConfig = bufferCfg; - EXPECT_CALL(participant, SendMsg(&controller, expectedUpdate)).Times(1); + EXPECT_CALL(participant, SendMsg(&controller, netsimName, expectedUpdate)).Times(1); controller.ReconfigureTxBuffer(0, bufferCfg); } @@ -336,12 +341,13 @@ TEST_F(Test_FlexrayController, throw_on_unconfigured_tx_buffer_configupdate) controllerCfg.nodeParams = MakeValidNodeParams(); controllerCfg.bufferConfigs.resize(5); - EXPECT_CALL(participant, SendMsg(&controller, controllerCfg)).Times(1); + EXPECT_CALL(participant, SendMsg(&controller, netsimName, controllerCfg)).Times(1); controller.Configure(controllerCfg); // Attempt to reconfigure TxBuffer 6, which should be out of range FlexrayTxBufferConfig bufferCfg{}; - EXPECT_CALL(participant, SendMsg(An(), A())) + EXPECT_CALL(participant, + SendMsg(An(), netsimName, A())) .Times(0); EXPECT_THROW(controller.ReconfigureTxBuffer(6, bufferCfg), SilKit::OutOfRangeError); } @@ -356,7 +362,7 @@ TEST_F(Test_FlexrayController, send_txbuffer_update) controllerCfg.nodeParams = MakeValidNodeParams(); controllerCfg.bufferConfigs.push_back(bufferCfg); - EXPECT_CALL(participant, SendMsg(&controller, controllerCfg)).Times(1); + EXPECT_CALL(participant, SendMsg(&controller, netsimName, controllerCfg)).Times(1); controller.Configure(controllerCfg); WireFlexrayTxBufferUpdate update{}; @@ -364,7 +370,7 @@ TEST_F(Test_FlexrayController, send_txbuffer_update) update.payload = referencePayload; update.payloadDataValid = true; - EXPECT_CALL(participant, SendMsg(&controller, update)).Times(1); + EXPECT_CALL(participant, SendMsg(&controller, netsimName, update)).Times(1); controller.UpdateTxBuffer(ToFlexrayTxBufferUpdate(update)); } @@ -377,40 +383,43 @@ TEST_F(Test_FlexrayController, throw_on_unconfigured_tx_buffer_update) controllerCfg.nodeParams = MakeValidNodeParams(); controllerCfg.bufferConfigs.resize(1); - EXPECT_CALL(participant, SendMsg(&controller, controllerCfg)).Times(1); + EXPECT_CALL(participant, SendMsg(&controller, netsimName, controllerCfg)).Times(1); controller.Configure(controllerCfg); FlexrayTxBufferUpdate update; update.txBufferIndex = 7; // only txBufferIdx = 0 is configured - EXPECT_CALL(participant, SendMsg(An(), A())) + EXPECT_CALL(participant, + SendMsg(An(), netsimName, A())) .Times(0); EXPECT_THROW(controller.UpdateTxBuffer(update), SilKit::OutOfRangeError); } TEST_F(Test_FlexrayController, send_run_command) { - EXPECT_CALL(participant, SendMsg(&controller, FlexrayHostCommand{FlexrayChiCommand::RUN})).Times(1); + EXPECT_CALL(participant, SendMsg(&controller, netsimName, FlexrayHostCommand{FlexrayChiCommand::RUN})).Times(1); controller.Run(); } TEST_F(Test_FlexrayController, send_deferred_halt_command) { - EXPECT_CALL(participant, SendMsg(&controller, FlexrayHostCommand{FlexrayChiCommand::DEFERRED_HALT})).Times(1); + EXPECT_CALL(participant, SendMsg(&controller, netsimName, FlexrayHostCommand{FlexrayChiCommand::DEFERRED_HALT})) + .Times(1); controller.DeferredHalt(); } TEST_F(Test_FlexrayController, send_freeze_command) { - EXPECT_CALL(participant, SendMsg(&controller, FlexrayHostCommand{FlexrayChiCommand::FREEZE})).Times(1); + EXPECT_CALL(participant, SendMsg(&controller, netsimName, FlexrayHostCommand{FlexrayChiCommand::FREEZE})).Times(1); controller.Freeze(); } TEST_F(Test_FlexrayController, send_allow_coldstart_command) { - EXPECT_CALL(participant, SendMsg(&controller, FlexrayHostCommand{FlexrayChiCommand::ALLOW_COLDSTART})).Times(1); + EXPECT_CALL(participant, SendMsg(&controller, netsimName, FlexrayHostCommand{FlexrayChiCommand::ALLOW_COLDSTART})) + .Times(1); controller.AllowColdstart(); } @@ -420,14 +429,14 @@ TEST_F(Test_FlexrayController, send_all_slots_command) FlexrayHostCommand cmd; cmd.command = FlexrayChiCommand::ALL_SLOTS; - EXPECT_CALL(participant, SendMsg(&controller, cmd)).Times(1); + EXPECT_CALL(participant, SendMsg(&controller, netsimName, cmd)).Times(1); controller.AllSlots(); } TEST_F(Test_FlexrayController, send_wakeup_command) { - EXPECT_CALL(participant, SendMsg(&controller, FlexrayHostCommand{FlexrayChiCommand::WAKEUP})).Times(1); + EXPECT_CALL(participant, SendMsg(&controller, netsimName, FlexrayHostCommand{FlexrayChiCommand::WAKEUP})).Times(1); controller.Wakeup(); } diff --git a/SilKit/source/services/lin/LinTestUtils.hpp b/SilKit/source/services/lin/LinTestUtils.hpp index 3fde544c2..127d21463 100644 --- a/SilKit/source/services/lin/LinTestUtils.hpp +++ b/SilKit/source/services/lin/LinTestUtils.hpp @@ -38,13 +38,20 @@ namespace Tests { class LinMockParticipant : public Core::Tests::DummyParticipant { public: - MOCK_METHOD(void, SendMsg, (const Core::IServiceEndpoint*, const LinSendFrameRequest&)); - MOCK_METHOD(void, SendMsg, (const Core::IServiceEndpoint*, const LinSendFrameHeaderRequest&)); - MOCK_METHOD(void, SendMsg, (const Core::IServiceEndpoint*, const LinTransmission&)); + MOCK_METHOD(void, SendMsg, (const Core::IServiceEndpoint*, const LinFrameResponseUpdate&)); MOCK_METHOD(void, SendMsg, (const Core::IServiceEndpoint*, const WireLinControllerConfig&)); MOCK_METHOD(void, SendMsg, (const Core::IServiceEndpoint*, const LinControllerStatusUpdate&)); - MOCK_METHOD(void, SendMsg, (const Core::IServiceEndpoint*, const LinWakeupPulse&)); + + MOCK_METHOD(void, SendMsg, (const Core::IServiceEndpoint*, const LinSendFrameRequest&), (override)); + MOCK_METHOD(void, SendMsg, (const Core::IServiceEndpoint*, const LinSendFrameHeaderRequest&), (override)); + MOCK_METHOD(void, SendMsg, (const Core::IServiceEndpoint*, const LinTransmission&), (override)); + MOCK_METHOD(void, SendMsg, (const Core::IServiceEndpoint*, const LinWakeupPulse&), (override)); + + MOCK_METHOD(void, SendMsg, (const Core::IServiceEndpoint*, const std::string&, const LinSendFrameRequest&), (override)); + MOCK_METHOD(void, SendMsg, (const Core::IServiceEndpoint*, const std::string&, const LinSendFrameHeaderRequest&), (override)); + MOCK_METHOD(void, SendMsg, (const Core::IServiceEndpoint*, const std::string&, const LinTransmission&), (override)); + MOCK_METHOD(void, SendMsg, (const Core::IServiceEndpoint*, const std::string&, const LinWakeupPulse&), (override)); }; inline auto MakeControllerConfig(LinControllerMode mode) -> LinControllerConfig diff --git a/SilKit/source/services/lin/SimBehaviorDetailed.cpp b/SilKit/source/services/lin/SimBehaviorDetailed.cpp index 102f76bcc..9e2f6a859 100644 --- a/SilKit/source/services/lin/SimBehaviorDetailed.cpp +++ b/SilKit/source/services/lin/SimBehaviorDetailed.cpp @@ -36,34 +36,41 @@ SimBehaviorDetailed::SimBehaviorDetailed(Core::IParticipantInternal* participant } template -void SimBehaviorDetailed::SendMsgImpl(MsgT&& msg) +void SimBehaviorDetailed::SendBroadcastMsgImpl(MsgT&& msg) { _participant->SendMsg(_parentServiceEndpoint, std::forward(msg)); } +template +void SimBehaviorDetailed::SendTargettedMsgImpl(MsgT&& msg) +{ + _participant->SendMsg(_parentServiceEndpoint, _simulatedLink.GetParticipantName(), std::forward(msg)); +} + void SimBehaviorDetailed::SendMsg(LinSendFrameRequest&& msg) { - SendMsgImpl(msg); + SendTargettedMsgImpl(msg); } void SimBehaviorDetailed::SendMsg(LinTransmission&& msg) { - SendMsgImpl(msg); + SendTargettedMsgImpl(msg); } -void SimBehaviorDetailed::SendMsg(WireLinControllerConfig&& msg) +void SimBehaviorDetailed::SendMsg(LinSendFrameHeaderRequest&& msg) { - SendMsgImpl(msg); + SendTargettedMsgImpl(msg); } -void SimBehaviorDetailed::SendMsg(LinSendFrameHeaderRequest&& msg) + +void SimBehaviorDetailed::SendMsg(WireLinControllerConfig&& msg) { - SendMsgImpl(msg); + SendBroadcastMsgImpl(msg); } void SimBehaviorDetailed::SendMsg(LinFrameResponseUpdate&& msg) { - SendMsgImpl(msg); + SendBroadcastMsgImpl(msg); } void SimBehaviorDetailed::SendMsg(LinControllerStatusUpdate&& msg) { - SendMsgImpl(msg); + SendBroadcastMsgImpl(msg); } void SimBehaviorDetailed::ProcessFrameHeaderRequest(const LinSendFrameHeaderRequest& /*header*/) @@ -78,7 +85,7 @@ void SimBehaviorDetailed::UpdateTxBuffer(const LinFrame& frame) response.frame = frame; response.responseMode = LinFrameResponseMode::TxUnconditional; responseUpdate.frameResponses.push_back(response); - SendMsgImpl(responseUpdate); + SendBroadcastMsgImpl(responseUpdate); } void SimBehaviorDetailed::GoToSleep() @@ -87,7 +94,7 @@ void SimBehaviorDetailed::GoToSleep() gotosleepFrame.frame = GoToSleepFrame(); gotosleepFrame.responseType = LinFrameResponseType::MasterResponse; - SendMsgImpl(gotosleepFrame); + SendTargettedMsgImpl(gotosleepFrame); // We signal SleepPending to the network simulator, so it will be able // to finish sleep frame transmissions before entering Sleep state. @@ -101,7 +108,7 @@ void SimBehaviorDetailed::Wakeup() { // Send without direction, netsim will distribute with correct directions LinWakeupPulse pulse{}; - SendMsgImpl(pulse); + SendTargettedMsgImpl(pulse); _parentController->WakeupInternal(); } diff --git a/SilKit/source/services/lin/SimBehaviorDetailed.hpp b/SilKit/source/services/lin/SimBehaviorDetailed.hpp index f793902ea..dcd9d319b 100644 --- a/SilKit/source/services/lin/SimBehaviorDetailed.hpp +++ b/SilKit/source/services/lin/SimBehaviorDetailed.hpp @@ -59,7 +59,10 @@ class SimBehaviorDetailed : public ISimBehavior private: template - void SendMsgImpl(MsgT&& msg); + void SendBroadcastMsgImpl(MsgT&& msg); + + template + void SendTargettedMsgImpl(MsgT&& msg); Core::IParticipantInternal* _participant{nullptr}; LinController* _parentController{nullptr}; diff --git a/SilKit/source/services/lin/Test_LinControllerDetailedSim.cpp b/SilKit/source/services/lin/Test_LinControllerDetailedSim.cpp index 5fb04aea0..189c5c6d2 100644 --- a/SilKit/source/services/lin/Test_LinControllerDetailedSim.cpp +++ b/SilKit/source/services/lin/Test_LinControllerDetailedSim.cpp @@ -76,7 +76,8 @@ class Test_LinControllerDetailedSim : public testing::Test } protected: - const ServiceDescriptor addr1_netsim{"P1", "N1", "C1", 5}; + const std::string netsimName = "bussim"; + const ServiceDescriptor addr1_netsim{netsimName, "N1", "C1", 5}; const ServiceDescriptor addr1_proxy{"P2", "N1", "C1", 5}; const ServiceDescriptor addr2_proxy{"P1", "N1", "C2", 9}; @@ -90,6 +91,7 @@ class Test_LinControllerDetailedSim : public testing::Test LinController::GoToSleepHandler goToSleepHandler; LinController::WakeupHandler wakeupHandler; SilKit::Experimental::Services::Lin::LinSlaveConfigurationHandler slaveConfigurationHandler; + }; TEST_F(Test_LinControllerDetailedSim, send_frame_unitialized) @@ -118,7 +120,7 @@ TEST_F(Test_LinControllerDetailedSim, send_frame) master.ReceiveMsg(&slave1, slaveConfig); EXPECT_CALL(participant, SendMsg(&master, A())).Times(1); - EXPECT_CALL(participant, SendMsg(&master, expectedMsg)).Times(1); + EXPECT_CALL(participant, SendMsg(&master, netsimName, expectedMsg)).Times(1); master.SendFrame(expectedMsg.frame, expectedMsg.responseType); } @@ -131,7 +133,7 @@ TEST_F(Test_LinControllerDetailedSim, send_frame_without_configured_slave_respon LinFrame frame = MakeFrame(17, LinChecksumModel::Enhanced, 4, {1, 2, 3, 4, 5, 6, 7, 8}); - EXPECT_CALL(participant, SendMsg(&master, A())).Times(0); + EXPECT_CALL(participant, SendMsg(&master, netsimName, A())).Times(0); EXPECT_CALL(callbacks, FrameStatusHandler(&master, frame, LinFrameStatus::LIN_RX_NO_RESPONSE)).Times(2); EXPECT_CALL(participant.mockTimeProvider, Now()).Times(2); master.SendFrame(frame, LinFrameResponseType::SlaveResponse); @@ -154,7 +156,7 @@ TEST_F(Test_LinControllerDetailedSim, send_frame_header) expectedMsg.id = 13; EXPECT_CALL(participant.mockTimeProvider, Now()).Times(1); - EXPECT_CALL(participant, SendMsg(&master, expectedMsg)).Times(1); + EXPECT_CALL(participant, SendMsg(&master, netsimName, expectedMsg)).Times(1); master.SendFrameHeader(expectedMsg.id); } @@ -212,7 +214,7 @@ TEST_F(Test_LinControllerDetailedSim, go_to_sleep) expectedMsg.frame = GoToSleepFrame(); expectedMsg.responseType = LinFrameResponseType::MasterResponse; - EXPECT_CALL(participant, SendMsg(&master, expectedMsg)).Times(1); + EXPECT_CALL(participant, SendMsg(&master, netsimName, expectedMsg)).Times(1); EXPECT_CALL(participant, SendMsg(&master, AControllerStatusUpdateWith(LinControllerStatus::SleepPending))).Times(1); master.GoToSleep(); @@ -225,7 +227,7 @@ TEST_F(Test_LinControllerDetailedSim, go_to_sleep_internal) auto config = MakeControllerConfig(LinControllerMode::Master); master.Init(config); - EXPECT_CALL(participant, SendMsg(&master, A())).Times(0); + EXPECT_CALL(participant, SendMsg(&master, netsimName, A())).Times(0); EXPECT_CALL(participant, SendMsg(&master, AControllerStatusUpdateWith(LinControllerStatus::Sleep))).Times(1); master.GoToSleepInternal(); @@ -277,7 +279,7 @@ TEST_F(Test_LinControllerDetailedSim, wake_up) auto config = MakeControllerConfig(LinControllerMode::Master); master.Init(config); - EXPECT_CALL(participant, SendMsg(&master, A())).Times(1); + EXPECT_CALL(participant, SendMsg(&master, netsimName, A())).Times(1); EXPECT_CALL(participant, SendMsg(&master, AControllerStatusUpdateWith(LinControllerStatus::Operational))).Times(1); master.Wakeup(); @@ -290,7 +292,7 @@ TEST_F(Test_LinControllerDetailedSim, wake_up_internal) auto config = MakeControllerConfig(LinControllerMode::Master); master.Init(config); - EXPECT_CALL(participant, SendMsg(&master, A())).Times(0); + EXPECT_CALL(participant, SendMsg(&master, netsimName, A())).Times(0); EXPECT_CALL(participant, SendMsg(&master, AControllerStatusUpdateWith(LinControllerStatus::Operational))).Times(1); master.WakeupInternal();