Skip to content

Commit

Permalink
[lit icd] add DSLS Test Event trigger
Browse files Browse the repository at this point in the history
Signed-off-by: Doru Gucea <[email protected]>
  • Loading branch information
doru91 committed Sep 13, 2024
1 parent 118375a commit c2e4499
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/app/icd/server/ICDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ enum class ICDTestEventTriggerEvent : uint64_t
kInvalidateHalfCounterValues = 0x0046'0000'00000003,
kInvalidateAllCounterValues = 0x0046'0000'00000004,
kForceMaximumCheckInBackOffState = 0x0046'0000'00000005,
kDSLSForceSitMode = 0x0046'0000'00000006,
kDSLSWithdrawSitMode = 0x0046'0000'00000007,
};
} // namespace

Expand Down Expand Up @@ -712,6 +714,14 @@ CHIP_ERROR ICDManager::HandleEventTrigger(uint64_t eventTrigger)
err = mICDCheckInBackOffStrategy->ForceMaximumCheckInBackoff();
break;
#endif // CHIP_CONFIG_ENABLE_ICD_CIP
#if CHIP_CONFIG_ENABLE_ICD_DSLS
case ICDTestEventTriggerEvent::kDSLSForceSitMode:
OnSITModeRequest();
break;
case ICDTestEventTriggerEvent::kDSLSWithdrawSitMode:
OnSITModeRequestWithdrawal();
break;
#endif // CHIP_CONFIG_ENABLE_ICD_DSLS
default:
err = CHIP_ERROR_INVALID_ARGUMENT;
break;
Expand Down
58 changes: 58 additions & 0 deletions src/app/icd/server/tests/TestICDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,64 @@ TEST_F(TestICDManager, TestICDMStayActive)
EXPECT_EQ(stayActivePromisedMs, 20000UL);
}

#if CHIP_CONFIG_ENABLE_ICD_DSLS
/**
* @brief Test verifies the logic of the ICDManager related to DSLS (Dynamic SIT LIT Support)
*/
TEST_F(TestICDManager, TestICDMDSLS)
{
typedef ICDListener::ICDManagementEvents ICDMEvent;
ICDNotifier notifier = ICDNotifier::GetInstance();

// Set FeatureMap
// Configures CIP, UAT, LITS and DSLS to 1
mICDManager.SetTestFeatureMapValue(0x0F);

// Check ICDManager starts in SIT mode if no entries are present
EXPECT_EQ(ICDConfigurationData::GetInstance().GetICDMode(), ICDConfigurationData::ICDMode::SIT);

// Create table with one fabric
ICDMonitoringTable table1(testStorage, kTestFabricIndex1, kMaxTestClients, &(mKeystore));

// Add an entry to the fabric
ICDMonitoringEntry entry1(&(mKeystore));
entry1.checkInNodeID = kClientNodeId11;
entry1.monitoredSubject = kClientNodeId12;
EXPECT_EQ(CHIP_NO_ERROR, entry1.SetKey(ByteSpan(kKeyBuffer1a)));
EXPECT_EQ(CHIP_NO_ERROR, table1.Set(0, entry1));

// Trigger register event after first entry was added
notifier.NotifyICDManagementEvent(ICDMEvent::kTableUpdated);

// Check ICDManager is now in the LIT operating mode
EXPECT_EQ(ICDConfigurationData::GetInstance().GetICDMode(), ICDConfigurationData::ICDMode::LIT);

// Simulate SIT Mode Request - device must switch to SIT mode even if there is a client registered
notifier.NotifySITModeRequestNotification();

// Check ICDManager is now in the SIT operating mode
EXPECT_EQ(ICDConfigurationData::GetInstance().GetICDMode(), ICDConfigurationData::ICDMode::SIT);

// Advance time so active mode interval expires.
AdvanceClockAndRunEventLoop(ICDConfigurationData::GetInstance().GetActiveModeDuration() + 1_ms32);

// Check ICDManager is still in the SIT operating mode
EXPECT_EQ(ICDConfigurationData::GetInstance().GetICDMode(), ICDConfigurationData::ICDMode::SIT);

// Withdraw SIT mode
notifier.NotifySITModeRequestWithdrawal();

// Check ICDManager is now in the LIT operating mode
EXPECT_EQ(ICDConfigurationData::GetInstance().GetICDMode(), ICDConfigurationData::ICDMode::LIT);

// Advance time so active mode interval expires.
AdvanceClockAndRunEventLoop(ICDConfigurationData::GetInstance().GetActiveModeDuration() + 1_ms32);

// Check ICDManager is still in the LIT operating mode
EXPECT_EQ(ICDConfigurationData::GetInstance().GetICDMode(), ICDConfigurationData::ICDMode::LIT);
}
#endif // CHIP_CONFIG_ENABLE_ICD_DSLS

#if CHIP_CONFIG_ENABLE_ICD_CIP
#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
#if CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
Expand Down

0 comments on commit c2e4499

Please sign in to comment.