From cf2fbddb8366b64c6c00474a7f652f3149a011d7 Mon Sep 17 00:00:00 2001 From: Junior Martinez Date: Tue, 15 Aug 2023 12:57:31 -0400 Subject: [PATCH 1/5] Add unit tests for the ICD Manager --- src/app/icd/ICDManager.cpp | 7 +- src/app/icd/ICDManager.h | 6 + src/app/tests/TestICDManager.cpp | 199 ++++++++++++++++++++++++++++++- 3 files changed, 204 insertions(+), 8 deletions(-) diff --git a/src/app/icd/ICDManager.cpp b/src/app/icd/ICDManager.cpp index e3787f2ddc747a..287d0dd11a385a 100644 --- a/src/app/icd/ICDManager.cpp +++ b/src/app/icd/ICDManager.cpp @@ -75,9 +75,12 @@ void ICDManager::Shutdown() bool ICDManager::SupportsCheckInProtocol() { - bool success; - uint32_t featureMap; + bool success = false; + uint32_t featureMap = 0; + // Can't use attribute accessors/Attributes::FeatureMap::Get in unit tests +#ifndef CONFIG_BUILD_FOR_HOST_UNIT_TEST success = (Attributes::FeatureMap::Get(kRootEndpointId, &featureMap) == EMBER_ZCL_STATUS_SUCCESS); +#endif return success ? ((featureMap & to_underlying(Feature::kCheckInProtocolSupport)) != 0) : false; } diff --git a/src/app/icd/ICDManager.h b/src/app/icd/ICDManager.h index e5406f14615837..6e9890240c5eee 100644 --- a/src/app/icd/ICDManager.h +++ b/src/app/icd/ICDManager.h @@ -26,6 +26,10 @@ namespace chip { namespace app { +// Forward declaration of TestICDManager to allow it to be friend with ICDManager +// Used in unit tests +class TestICDManager; + /** * @brief ICD Manager is responsible of processing the events and triggering the correct action for an ICD */ @@ -67,6 +71,8 @@ class ICDManager static System::Clock::Milliseconds32 GetFastPollingInterval() { return kFastPollingInterval; } protected: + friend class TestICDManager; + static void OnIdleModeDone(System::Layer * aLayer, void * appState); static void OnActiveModeDone(System::Layer * aLayer, void * appState); diff --git a/src/app/tests/TestICDManager.cpp b/src/app/tests/TestICDManager.cpp index 6fdaeedf45a73f..57a5282d381592 100644 --- a/src/app/tests/TestICDManager.cpp +++ b/src/app/tests/TestICDManager.cpp @@ -15,17 +15,204 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include +#include +#include +#include #include #include +#include -int TestICDManager() +#include +#include +#include + +using namespace chip; +using namespace chip::app; +using namespace chip::System; + +namespace { + +class TestICDStateObserver : public app::ICDStateObserver +{ +public: + void OnEnterActiveMode() {} +}; + +TestICDStateObserver mICDStateObserver; +static Clock::Internal::MockClock gMockClock; +static Clock::ClockBase * gRealClock; + +class TestContext : public Test::AppContext +{ +public: + static int Initialize(void * context) + { + gRealClock = &SystemClock(); + Clock::Internal::SetSystemClockForTesting(&gMockClock); + + if (chip::DeviceLayer::PlatformMgr().InitChipStack() != CHIP_NO_ERROR) + return FAILURE; + + if (AppContext::Initialize(context) != SUCCESS) + return FAILURE; + + auto * ctx = static_cast(context); + + if (ctx->mEventCounter.Init(0) != CHIP_NO_ERROR) + { + return FAILURE; + } + + ctx->mICDManager.Init(&ctx->testStorage, &ctx->GetFabricTable(), &mICDStateObserver); + return SUCCESS; + } + + static int Finalize(void * context) + { + auto * ctx = static_cast(context); + ctx->mICDManager.Shutdown(); + app::EventManagement::DestroyEventManagement(); + chip::System::Clock::Internal::SetSystemClockForTesting(gRealClock); + + chip::DeviceLayer::PlatformMgr().Shutdown(); + if (AppContext::Finalize(context) != SUCCESS) + return FAILURE; + + return SUCCESS; + } + + app::ICDManager mICDManager; + +private: + TestPersistentStorageDelegate testStorage; + MonotonicallyIncreasingCounter mEventCounter; +}; + +} // namespace + +namespace chip { +namespace app { +class TestICDManager +{ +public: + /* + * Advance the test Mock clock time by the amout passed in argument + * and then force the SystemLayer Timer event loop. It will check for any expired timer, + * and invoke their callbacks if there are any. + * + * @param time_ms: Value in milliseconds. + */ + static void AdvanceClockAndRunEventLoop(uint32_t time_ms) + { + LayerSocketsLoop & layer = static_cast(DeviceLayer::SystemLayer()); + gMockClock.AdvanceMonotonic(System::Clock::Timeout(time_ms)); + + layer.PrepareEvents(); + layer.WaitForEvents(); + layer.HandleEvents(); + } + + static void TestICDModeIntervals(nlTestSuite * aSuite, void * aContext) + { + TestContext * ctx = static_cast(aContext); + Clock::ClockBase * const savedClock = &SystemClock(); + + // After the init we should be in active mode + NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); + AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeInterval() + 1); + + // Active mode interval expired, ICDManager transitioned to the IdleMode. + NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode); + AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetIdleModeInterval() + 1); + // Idle mode interval expired, ICDManager transitioned to the ActiveMode. + NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); + + // Events updating the Operation to Active mode can extend the current active mode time by 1 Active mode threshold. + // Kick an active Threshold just before the end of the Active interval and validate that the active mode is extended. + AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeInterval() - 1); + ctx->mICDManager.UpdateOperationState(ICDManager::OperationalState::ActiveMode); + + AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeThreshold() / 2); + ctx->mICDManager.UpdateOperationState(ICDManager::OperationalState::ActiveMode); + AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeThreshold()); + NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode); + + Clock::Internal::SetSystemClockForTesting(savedClock); + } + + static void TestKeepActivemodeRequests(nlTestSuite * aSuite, void * aContext) + { + TestContext * ctx = static_cast(aContext); + + Clock::ClockBase * const savedClock = &SystemClock(); + // Setting a requirement will transition the ICD to active mode. + ctx->mICDManager.SetKeepActiveModeRequirements(ICDManager::KeepActiveFlags::kCommissioningWindowOpen, true); + NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); + // Advance time so active mode interval expires. + AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeInterval()); + // Requirement flag still set. We stay in active mode + NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); + + // Remove requirement. we should directly transition to idle mode. + ctx->mICDManager.SetKeepActiveModeRequirements(ICDManager::KeepActiveFlags::kCommissioningWindowOpen, false); + NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode); + + ctx->mICDManager.SetKeepActiveModeRequirements(ICDManager::KeepActiveFlags::kFailSafeArmed, true); + // Requirement will transition us to active mode. + NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); + + // Advance time, but by less than the active mode interval and remove the requirement. + // We should stay in active mode. + AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeInterval() / 2); + ctx->mICDManager.SetKeepActiveModeRequirements(ICDManager::KeepActiveFlags::kFailSafeArmed, false); + NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); + + // Advance time again, The activemode interval is completed. + AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeInterval()); + NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode); + + // Set two requirements + ctx->mICDManager.SetKeepActiveModeRequirements(ICDManager::KeepActiveFlags::kExpectingMsgResponse, true); + ctx->mICDManager.SetKeepActiveModeRequirements(ICDManager::KeepActiveFlags::kAwaitingMsgAck, true); + NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); + // advance time so the active mode interval expires. + AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeInterval()); + // A requirement flag is still set. We stay in active mode. + NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); + + // remove 1 requirement. Active mode is maintained + ctx->mICDManager.SetKeepActiveModeRequirements(ICDManager::KeepActiveFlags::kExpectingMsgResponse, false); + NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); + // remove the last requirement + ctx->mICDManager.SetKeepActiveModeRequirements(ICDManager::KeepActiveFlags::kAwaitingMsgAck, false); + NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode); + + Clock::Internal::SetSystemClockForTesting(savedClock); + } +}; + +} // namespace app +} // namespace chip + +namespace { +/** + * Test Suite. It lists all the test functions. + */ +// clang-format off +static const nlTest sTests[] = { - static nlTest sTests[] = { NL_TEST_SENTINEL() }; + NL_TEST_DEF("TestICDModeIntervals", TestICDManager::TestICDModeIntervals), + NL_TEST_DEF("TestKeepActivemodeRequests", TestICDManager::TestKeepActivemodeRequests), + NL_TEST_SENTINEL() +}; - nlTestSuite cmSuite = { "TestICDManager", &sTests[0], nullptr, nullptr }; +nlTestSuite cmSuite = { "TestICDManager", &sTests[0], TestContext::Initialize, TestContext::Finalize }; +} // namespace - nlTestRunner(&cmSuite, nullptr); - return (nlTestRunnerStats(&cmSuite)); +int TestSuiteICDManager() +{ + return ExecuteTestsWithContext(&cmSuite); } -CHIP_REGISTER_TEST_SUITE(TestICDManager) +CHIP_REGISTER_TEST_SUITE(TestSuiteICDManager) From d8b8bda3a8fba9c594c2af5ce3e80e413c07d04f Mon Sep 17 00:00:00 2001 From: Junior Martinez Date: Thu, 17 Aug 2023 12:08:28 -0400 Subject: [PATCH 2/5] Address comment, try to fix test for ESP and IOT SDK --- src/app/tests/TestICDManager.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/app/tests/TestICDManager.cpp b/src/app/tests/TestICDManager.cpp index 57a5282d381592..5ef23a9fe4230e 100644 --- a/src/app/tests/TestICDManager.cpp +++ b/src/app/tests/TestICDManager.cpp @@ -105,12 +105,20 @@ class TestICDManager */ static void AdvanceClockAndRunEventLoop(uint32_t time_ms) { - LayerSocketsLoop & layer = static_cast(DeviceLayer::SystemLayer()); gMockClock.AdvanceMonotonic(System::Clock::Timeout(time_ms)); +#if CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK + LayerSocketsLoop & layer = static_cast(DeviceLayer::SystemLayer()); layer.PrepareEvents(); layer.WaitForEvents(); layer.HandleEvents(); +#else + LayerImplFreeRTOS & layer = static_cast(DeviceLayer::SystemLayer()); + if (layer.IsInitialized()) + { + layer.HandlePlatformTimer(); + } +#endif } static void TestICDModeIntervals(nlTestSuite * aSuite, void * aContext) @@ -132,9 +140,8 @@ class TestICDManager // Kick an active Threshold just before the end of the Active interval and validate that the active mode is extended. AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeInterval() - 1); ctx->mICDManager.UpdateOperationState(ICDManager::OperationalState::ActiveMode); - AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeThreshold() / 2); - ctx->mICDManager.UpdateOperationState(ICDManager::OperationalState::ActiveMode); + NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeThreshold()); NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode); @@ -150,7 +157,7 @@ class TestICDManager ctx->mICDManager.SetKeepActiveModeRequirements(ICDManager::KeepActiveFlags::kCommissioningWindowOpen, true); NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); // Advance time so active mode interval expires. - AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeInterval()); + AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeInterval() + 1); // Requirement flag still set. We stay in active mode NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); @@ -169,7 +176,7 @@ class TestICDManager NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); // Advance time again, The activemode interval is completed. - AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeInterval()); + AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeInterval() + 1); NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode); // Set two requirements @@ -177,7 +184,7 @@ class TestICDManager ctx->mICDManager.SetKeepActiveModeRequirements(ICDManager::KeepActiveFlags::kAwaitingMsgAck, true); NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); // advance time so the active mode interval expires. - AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeInterval()); + AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeInterval() + 1); // A requirement flag is still set. We stay in active mode. NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); From 623f232cf5c96bda40ba3702d02817515486505b Mon Sep 17 00:00:00 2001 From: Junior Martinez Date: Mon, 21 Aug 2023 12:47:42 -0400 Subject: [PATCH 3/5] Use GetIOContext().DriveIO() to run event loop. Set the systemLayer for test to be the IOContext one --- src/app/tests/TestICDManager.cpp | 60 ++++++++++++++------------------ 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/src/app/tests/TestICDManager.cpp b/src/app/tests/TestICDManager.cpp index 5ef23a9fe4230e..81a2b19de903dd 100644 --- a/src/app/tests/TestICDManager.cpp +++ b/src/app/tests/TestICDManager.cpp @@ -48,16 +48,14 @@ class TestContext : public Test::AppContext public: static int Initialize(void * context) { - gRealClock = &SystemClock(); - Clock::Internal::SetSystemClockForTesting(&gMockClock); - - if (chip::DeviceLayer::PlatformMgr().InitChipStack() != CHIP_NO_ERROR) - return FAILURE; - if (AppContext::Initialize(context) != SUCCESS) return FAILURE; auto * ctx = static_cast(context); + DeviceLayer::SetSystemLayerForTesting(&ctx->GetSystemLayer()); + + gRealClock = &SystemClock(); + Clock::Internal::SetSystemClockForTesting(&gMockClock); if (ctx->mEventCounter.Init(0) != CHIP_NO_ERROR) { @@ -73,9 +71,9 @@ class TestContext : public Test::AppContext auto * ctx = static_cast(context); ctx->mICDManager.Shutdown(); app::EventManagement::DestroyEventManagement(); - chip::System::Clock::Internal::SetSystemClockForTesting(gRealClock); + System::Clock::Internal::SetSystemClockForTesting(gRealClock); + DeviceLayer::SetSystemLayerForTesting(nullptr); - chip::DeviceLayer::PlatformMgr().Shutdown(); if (AppContext::Finalize(context) != SUCCESS) return FAILURE; @@ -103,22 +101,10 @@ class TestICDManager * * @param time_ms: Value in milliseconds. */ - static void AdvanceClockAndRunEventLoop(uint32_t time_ms) + static void AdvanceClockAndRunEventLoop(TestContext * ctx, uint32_t time_ms) { gMockClock.AdvanceMonotonic(System::Clock::Timeout(time_ms)); -#if CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK - LayerSocketsLoop & layer = static_cast(DeviceLayer::SystemLayer()); - - layer.PrepareEvents(); - layer.WaitForEvents(); - layer.HandleEvents(); -#else - LayerImplFreeRTOS & layer = static_cast(DeviceLayer::SystemLayer()); - if (layer.IsInitialized()) - { - layer.HandlePlatformTimer(); - } -#endif + ctx->GetIOContext().DriveIO(); } static void TestICDModeIntervals(nlTestSuite * aSuite, void * aContext) @@ -128,21 +114,20 @@ class TestICDManager // After the init we should be in active mode NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); - AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeInterval() + 1); - + AdvanceClockAndRunEventLoop(ctx, IcdManagementServer::GetInstance().GetActiveModeInterval() + 1); // Active mode interval expired, ICDManager transitioned to the IdleMode. NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode); - AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetIdleModeInterval() + 1); + AdvanceClockAndRunEventLoop(ctx, IcdManagementServer::GetInstance().GetIdleModeInterval() + 1); // Idle mode interval expired, ICDManager transitioned to the ActiveMode. NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); // Events updating the Operation to Active mode can extend the current active mode time by 1 Active mode threshold. // Kick an active Threshold just before the end of the Active interval and validate that the active mode is extended. - AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeInterval() - 1); + AdvanceClockAndRunEventLoop(ctx, IcdManagementServer::GetInstance().GetActiveModeInterval() - 1); ctx->mICDManager.UpdateOperationState(ICDManager::OperationalState::ActiveMode); - AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeThreshold() / 2); + AdvanceClockAndRunEventLoop(ctx, IcdManagementServer::GetInstance().GetActiveModeThreshold() / 2); NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); - AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeThreshold()); + AdvanceClockAndRunEventLoop(ctx, IcdManagementServer::GetInstance().GetActiveModeThreshold()); NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode); Clock::Internal::SetSystemClockForTesting(savedClock); @@ -157,7 +142,7 @@ class TestICDManager ctx->mICDManager.SetKeepActiveModeRequirements(ICDManager::KeepActiveFlags::kCommissioningWindowOpen, true); NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); // Advance time so active mode interval expires. - AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeInterval() + 1); + AdvanceClockAndRunEventLoop(ctx, IcdManagementServer::GetInstance().GetActiveModeInterval() + 1); // Requirement flag still set. We stay in active mode NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); @@ -171,12 +156,12 @@ class TestICDManager // Advance time, but by less than the active mode interval and remove the requirement. // We should stay in active mode. - AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeInterval() / 2); + AdvanceClockAndRunEventLoop(ctx, IcdManagementServer::GetInstance().GetActiveModeInterval() / 2); ctx->mICDManager.SetKeepActiveModeRequirements(ICDManager::KeepActiveFlags::kFailSafeArmed, false); NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); // Advance time again, The activemode interval is completed. - AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeInterval() + 1); + AdvanceClockAndRunEventLoop(ctx, IcdManagementServer::GetInstance().GetActiveModeInterval() + 1); NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode); // Set two requirements @@ -184,7 +169,7 @@ class TestICDManager ctx->mICDManager.SetKeepActiveModeRequirements(ICDManager::KeepActiveFlags::kAwaitingMsgAck, true); NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); // advance time so the active mode interval expires. - AdvanceClockAndRunEventLoop(IcdManagementServer::GetInstance().GetActiveModeInterval() + 1); + AdvanceClockAndRunEventLoop(ctx, IcdManagementServer::GetInstance().GetActiveModeInterval() + 1); // A requirement flag is still set. We stay in active mode. NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); @@ -213,8 +198,17 @@ static const nlTest sTests[] = NL_TEST_DEF("TestKeepActivemodeRequests", TestICDManager::TestKeepActivemodeRequests), NL_TEST_SENTINEL() }; +// clang-format on -nlTestSuite cmSuite = { "TestICDManager", &sTests[0], TestContext::Initialize, TestContext::Finalize }; +// clang-format off +nlTestSuite cmSuite = +{ + "TestICDManager", + &sTests[0], + TestContext::Initialize, + TestContext::Finalize +}; +// clang-format on } // namespace int TestSuiteICDManager() From 3862ccbb808467d849926275ac50f85ae9e6aca4 Mon Sep 17 00:00:00 2001 From: Junior Martinez Date: Mon, 21 Aug 2023 13:03:12 -0400 Subject: [PATCH 4/5] Clean up --- src/app/tests/TestICDManager.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/app/tests/TestICDManager.cpp b/src/app/tests/TestICDManager.cpp index 81a2b19de903dd..f825449e028e0a 100644 --- a/src/app/tests/TestICDManager.cpp +++ b/src/app/tests/TestICDManager.cpp @@ -109,8 +109,7 @@ class TestICDManager static void TestICDModeIntervals(nlTestSuite * aSuite, void * aContext) { - TestContext * ctx = static_cast(aContext); - Clock::ClockBase * const savedClock = &SystemClock(); + TestContext * ctx = static_cast(aContext); // After the init we should be in active mode NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); @@ -129,15 +128,12 @@ class TestICDManager NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); AdvanceClockAndRunEventLoop(ctx, IcdManagementServer::GetInstance().GetActiveModeThreshold()); NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode); - - Clock::Internal::SetSystemClockForTesting(savedClock); } static void TestKeepActivemodeRequests(nlTestSuite * aSuite, void * aContext) { TestContext * ctx = static_cast(aContext); - Clock::ClockBase * const savedClock = &SystemClock(); // Setting a requirement will transition the ICD to active mode. ctx->mICDManager.SetKeepActiveModeRequirements(ICDManager::KeepActiveFlags::kCommissioningWindowOpen, true); NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); @@ -179,8 +175,6 @@ class TestICDManager // remove the last requirement ctx->mICDManager.SetKeepActiveModeRequirements(ICDManager::KeepActiveFlags::kAwaitingMsgAck, false); NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode); - - Clock::Internal::SetSystemClockForTesting(savedClock); } }; From b0a6248ff89de37d513ad6be53686288b0aa7952 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 21 Aug 2023 17:03:34 +0000 Subject: [PATCH 5/5] Restyled by whitespace --- src/app/tests/TestICDManager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/tests/TestICDManager.cpp b/src/app/tests/TestICDManager.cpp index f825449e028e0a..81739aea43ceb4 100644 --- a/src/app/tests/TestICDManager.cpp +++ b/src/app/tests/TestICDManager.cpp @@ -195,9 +195,9 @@ static const nlTest sTests[] = // clang-format on // clang-format off -nlTestSuite cmSuite = -{ - "TestICDManager", +nlTestSuite cmSuite = +{ + "TestICDManager", &sTests[0], TestContext::Initialize, TestContext::Finalize