Skip to content

Commit

Permalink
Address comment, try to fix test for ESP and IOT SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartinez-silabs committed Aug 17, 2023
1 parent 5bf71ea commit 25dfa2e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/app/tests/TestICDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,20 @@ class TestICDManager
*/
static void AdvanceClockAndRunEventLoop(uint32_t time_ms)
{
LayerSocketsLoop & layer = static_cast<LayerSocketsLoop &>(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<LayerSocketsLoop &>(DeviceLayer::SystemLayer());

layer.PrepareEvents();
layer.WaitForEvents();
layer.HandleEvents();
#else
LayerImplFreeRTOS & layer = static_cast<LayerImplFreeRTOS &>(DeviceLayer::SystemLayer());
if (layer.IsInitialized())
{
layer.HandlePlatformTimer();
}
#endif
}

static void TestICDModeIntervals(nlTestSuite * aSuite, void * aContext)
Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -169,15 +176,15 @@ 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
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());
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);

Expand Down

0 comments on commit 25dfa2e

Please sign in to comment.