diff --git a/test/address_claim_tests.cpp b/test/address_claim_tests.cpp index e6ce2dee3..e8a5eaa3d 100644 --- a/test/address_claim_tests.cpp +++ b/test/address_claim_tests.cpp @@ -60,7 +60,27 @@ TEST_F(AddressClaimTest, AddressClaim_PartneredClaim) const isobus::NAMEFilter filterFirst(NAME::NAMEParameters::FunctionCode, static_cast(NAME::Function::CabClimateControl)); auto secondPartneredFirstEcu = CANNetworkManager::CANNetwork.create_partnered_control_function(1, { filterFirst }); - time_source.update_for_ms(500); + constexpr std::uint32_t maximumWaitTime_ms = 1500; + constexpr std::uint32_t pollingPeriod_ms = 10; + + for (std::uint32_t elapsedTime_ms = 0; + elapsedTime_ms < maximumWaitTime_ms; + elapsedTime_ms += pollingPeriod_ms) + { + time_source.update_for_ms(pollingPeriod_ms); + CANNetworkManager::CANNetwork.update(); + + if (firstInternalECU->get_address_valid() && + secondInternalECU2->get_address_valid() && + firstPartneredSecondECU->get_address_valid() && + secondPartneredFirstEcu->get_address_valid()) + { + break; + } + + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } + EXPECT_TRUE(firstInternalECU->get_address_valid()); EXPECT_TRUE(secondInternalECU2->get_address_valid()); EXPECT_TRUE(firstPartneredSecondECU->get_address_valid()); diff --git a/test/isb_tests.cpp b/test/isb_tests.cpp index 2d4a1489b..6d1b535ad 100644 --- a/test/isb_tests.cpp +++ b/test/isb_tests.cpp @@ -3,6 +3,7 @@ #include "isobus/hardware_integration/can_hardware_interface.hpp" #include "isobus/hardware_integration/virtual_can_plugin.hpp" #include "isobus/isobus/can_network_manager.hpp" +#include "isobus/isobus/can_stack_logger.hpp" #include "isobus/isobus/isobus_shortcut_button_interface.hpp" #include "isobus/utility/system_timing.hpp" @@ -76,6 +77,21 @@ TEST_F(IsobusShortcutButtonTest, ShortcutButtonRxTests) EXPECT_EQ(ShortcutButtonInterface::StopAllImplementOperationsState::PermitAllImplementsToOperationOn, interfaceUnderTest.get_state()); // Send increased, incorrect transition count + // Set up test logger to verify ERROR log is emitted when transitioning to StopImplementOperations + class TestLogger : public isobus::CANStackLogger + { + public: + isobus::CANStackLogger::LoggingLevel lastLogLevel = isobus::CANStackLogger::LoggingLevel::Info; + void sink_CAN_stack_log(isobus::CANStackLogger::LoggingLevel level, const std::string &) override + { + lastLogLevel = level; + } + }; + TestLogger testLogger; + auto originalLogLevel = isobus::CANStackLogger::get_log_level(); + isobus::CANStackLogger::set_log_level(isobus::CANStackLogger::LoggingLevel::Debug); + isobus::CANStackLogger::set_can_stack_logger_sink(&testLogger); + testFrame.identifier = 0x18FD0274; testFrame.data[0] = 0xFF; testFrame.data[1] = 0xFF; @@ -89,6 +105,12 @@ TEST_F(IsobusShortcutButtonTest, ShortcutButtonRxTests) CANNetworkManager::CANNetwork.update(); EXPECT_EQ(ShortcutButtonInterface::StopAllImplementOperationsState::StopImplementOperations, interfaceUnderTest.get_state()); + // Verify ERROR log was emitted (mutant would log INFO instead) + EXPECT_EQ(isobus::CANStackLogger::LoggingLevel::Error, testLogger.lastLogLevel); + + isobus::CANStackLogger::set_can_stack_logger_sink(nullptr); + isobus::CANStackLogger::set_log_level(originalLogLevel); + // Test reset of state as counter is back to normal testFrame.identifier = 0x18FD0274; testFrame.data[0] = 0xFF; @@ -228,11 +250,29 @@ TEST_F(IsobusShortcutButtonTest, ShortcutButtonTxTests) interfaceUnderTest.initialize(); EXPECT_EQ(ShortcutButtonInterface::StopAllImplementOperationsState::PermitAllImplementsToOperationOn, interfaceUnderTest.get_state()); + // Set up test logger to verify ERROR log is emitted when setting StopImplementOperations + class TestLogger : public isobus::CANStackLogger + { + public: + isobus::CANStackLogger::LoggingLevel lastLogLevel = isobus::CANStackLogger::LoggingLevel::Info; + void sink_CAN_stack_log(isobus::CANStackLogger::LoggingLevel level, const std::string &) override + { + lastLogLevel = level; + } + }; + TestLogger testLogger; + auto originalLogLevel = isobus::CANStackLogger::get_log_level(); + isobus::CANStackLogger::set_log_level(isobus::CANStackLogger::LoggingLevel::Debug); + isobus::CANStackLogger::set_can_stack_logger_sink(&testLogger); + interfaceUnderTest.set_stop_all_implement_operations_state(ShortcutButtonInterface::StopAllImplementOperationsState::StopImplementOperations); interfaceUnderTest.update(); time_source.update_for_ms(5); EXPECT_TRUE(serverPlugin.read_frame(testFrame)); + // Verify ERROR log was emitted (mutant would log INFO instead) + EXPECT_EQ(isobus::CANStackLogger::LoggingLevel::Error, testLogger.lastLogLevel); + ASSERT_TRUE(testFrame.isExtendedFrame); ASSERT_EQ(testFrame.dataLength, 8); EXPECT_EQ(CANIdentifier(testFrame.identifier).get_parameter_group_number(), 0xFD02); @@ -247,6 +287,20 @@ TEST_F(IsobusShortcutButtonTest, ShortcutButtonTxTests) EXPECT_EQ(ShortcutButtonInterface::StopAllImplementOperationsState::StopImplementOperations, interfaceUnderTest.get_state()); + // Trigger a second transmission by changing state to Permit + interfaceUnderTest.set_stop_all_implement_operations_state(ShortcutButtonInterface::StopAllImplementOperationsState::PermitAllImplementsToOperationOn); + interfaceUnderTest.update(); + time_source.update_for_ms(5); + + ASSERT_TRUE(serverPlugin.read_frame(testFrame)); + + EXPECT_EQ(testFrame.data[6], 0x01); + EXPECT_EQ(testFrame.data[7], 0xFD); + EXPECT_EQ(ShortcutButtonInterface::StopAllImplementOperationsState::PermitAllImplementsToOperationOn, interfaceUnderTest.get_state()); + + isobus::CANStackLogger::set_can_stack_logger_sink(nullptr); + isobus::CANStackLogger::set_log_level(originalLogLevel); + CANHardwareInterface::stop(); CANNetworkManager::CANNetwork.deactivate_control_function(internalECU); }