From 9b8c367b6520d10224521526e281586aac3ade5b Mon Sep 17 00:00:00 2001 From: Doru Gucea Date: Fri, 13 Sep 2024 18:54:52 +0300 Subject: [PATCH] [lit icd] add DSLS Test Event trigger Signed-off-by: Doru Gucea --- src/app/icd/server/ICDManager.cpp | 10 ++++ src/app/icd/server/tests/TestICDManager.cpp | 58 +++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/src/app/icd/server/ICDManager.cpp b/src/app/icd/server/ICDManager.cpp index 561db2d6f5ac29..3e89af1e1613a5 100644 --- a/src/app/icd/server/ICDManager.cpp +++ b/src/app/icd/server/ICDManager.cpp @@ -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 @@ -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; diff --git a/src/app/icd/server/tests/TestICDManager.cpp b/src/app/icd/server/tests/TestICDManager.cpp index df5c2e4970c579..f6f999c1a36bca 100644 --- a/src/app/icd/server/tests/TestICDManager.cpp +++ b/src/app/icd/server/tests/TestICDManager.cpp @@ -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