Skip to content

Commit

Permalink
Fix returned error for ICDNotifier subscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartinez-silabs committed Oct 6, 2023
1 parent a83360c commit 0f212f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/app/icd/ICDNotifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ ICDNotifier::~ICDNotifier()

CHIP_ERROR ICDNotifier::Subscribe(ICDSubscriber * subscriber)
{
CHIP_ERROR err = CHIP_NO_ERROR;
CHIP_ERROR err = CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
for (auto & sub : mSubscribers)
{
if (sub == nullptr)
{
sub = subscriber;
err = CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
err = CHIP_NO_ERROR;
break;
}
}
Expand Down
18 changes: 10 additions & 8 deletions src/app/tests/TestICDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,47 +135,49 @@ class TestICDManager
static void TestKeepActivemodeRequests(nlTestSuite * aSuite, void * aContext)
{
TestContext * ctx = static_cast<TestContext *>(aContext);
typedef ICDSubscriber::KeepActiveFlags ActiveFlag;
ICDNotifier notifier = ICDNotifier::GetInstance();

// Setting a requirement will transition the ICD to active mode.
ICDNotifier::GetInstance().BroadcastActiveRequestNotification(ICDSubscriber::KeepActiveFlags::kCommissioningWindowOpen);
notifier.BroadcastActiveRequestNotification(ActiveFlag::kCommissioningWindowOpen);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);
// Advance time so active mode interval expires.
AdvanceClockAndRunEventLoop(ctx, IcdManagementServer::GetInstance().GetActiveModeIntervalMs() + 1);
// 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.
ICDNotifier::GetInstance().BroadcastActiveRequestWithdrawal(ICDSubscriber::KeepActiveFlags::kCommissioningWindowOpen);
notifier.BroadcastActiveRequestWithdrawal(ActiveFlag::kCommissioningWindowOpen);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);

ICDNotifier::GetInstance().BroadcastActiveRequestNotification(ICDSubscriber::KeepActiveFlags::kFailSafeArmed);
notifier.BroadcastActiveRequestNotification(ActiveFlag::kFailSafeArmed);
// 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(ctx, IcdManagementServer::GetInstance().GetActiveModeIntervalMs() / 2);
ICDNotifier::GetInstance().BroadcastActiveRequestWithdrawal(ICDSubscriber::KeepActiveFlags::kFailSafeArmed);
notifier.BroadcastActiveRequestWithdrawal(ActiveFlag::kFailSafeArmed);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);

// Advance time again, The activemode interval is completed.
AdvanceClockAndRunEventLoop(ctx, IcdManagementServer::GetInstance().GetActiveModeIntervalMs() + 1);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);

// Set two requirements
ICDNotifier::GetInstance().BroadcastActiveRequestNotification(ICDSubscriber::KeepActiveFlags::kFailSafeArmed);
ICDNotifier::GetInstance().BroadcastActiveRequestNotification(ICDSubscriber::KeepActiveFlags::kExchangeContextOpen);
notifier.BroadcastActiveRequestNotification(ActiveFlag::kFailSafeArmed);
notifier.BroadcastActiveRequestNotification(ActiveFlag::kExchangeContextOpen);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);
// advance time so the active mode interval expires.
AdvanceClockAndRunEventLoop(ctx, IcdManagementServer::GetInstance().GetActiveModeIntervalMs() + 1);
// 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
ICDNotifier::GetInstance().BroadcastActiveRequestWithdrawal(ICDSubscriber::KeepActiveFlags::kFailSafeArmed);
notifier.BroadcastActiveRequestWithdrawal(ActiveFlag::kFailSafeArmed);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);
// remove the last requirement
ICDNotifier::GetInstance().BroadcastActiveRequestWithdrawal(ICDSubscriber::KeepActiveFlags::kExchangeContextOpen);
notifier.BroadcastActiveRequestWithdrawal(ActiveFlag::kExchangeContextOpen);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
}
};
Expand Down

0 comments on commit 0f212f7

Please sign in to comment.