Skip to content

Commit 1f297d4

Browse files
committed
[nrf toup] Test Fail-Safe Marker
Test if: * Marker is stored during AddNOC. * Marker is not stored during UpdateNOC. * Marker is cleared During DisarmFailSafe and after timer expiry. Signed-off-by: Adrian Gielniewski <adrian.gielniewski@nordicsemi.no>
1 parent de383dd commit 1f297d4

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

src/app/tests/TestFailSafeContext.cpp

+54-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <lib/core/StringBuilderAdapters.h>
3535
#include <lib/support/CHIPMem.h>
3636
#include <lib/support/CodeUtils.h>
37+
#include <lib/support/DefaultStorageKeyAllocator.h>
3738
#include <lib/support/TestPersistentStorageDelegate.h>
3839
#include <platform/CHIPDeviceLayer.h>
3940

@@ -77,12 +78,14 @@ TEST_F(TestFailSafeContext, TestFailSafeContext_ArmFailSafe)
7778
EXPECT_EQ(failSafeContext.GetFabricIndex(), kTestAccessingFabricIndex1);
7879
EXPECT_TRUE(failSafeContext.IsFailSafeArmed(kTestAccessingFabricIndex1));
7980
EXPECT_FALSE(failSafeContext.IsFailSafeArmed(kTestAccessingFabricIndex2));
81+
EXPECT_FALSE(testStorage.SyncDoesKeyExist(DefaultStorageKeyAllocator::FailSafeMarkerKey().KeyName()));
8082

8183
failSafeContext.DisarmFailSafe();
8284
EXPECT_FALSE(failSafeContext.IsFailSafeArmed());
85+
EXPECT_FALSE(testStorage.SyncDoesKeyExist(DefaultStorageKeyAllocator::FailSafeMarkerKey().KeyName()));
8386
}
8487

85-
TEST_F(TestFailSafeContext, TestFailSafeContext_NocCommandInvoked)
88+
TEST_F(TestFailSafeContext, TestFailSafeContext_AddNocCommandInvoked)
8689
{
8790
chip::TestPersistentStorageDelegate testStorage;
8891
chip::app::FailSafeContext failSafeContext;
@@ -91,17 +94,67 @@ TEST_F(TestFailSafeContext, TestFailSafeContext_NocCommandInvoked)
9194

9295
EXPECT_EQ(failSafeContext.ArmFailSafe(kTestAccessingFabricIndex1, System::Clock::Seconds16(1)), CHIP_NO_ERROR);
9396
EXPECT_EQ(failSafeContext.GetFabricIndex(), kTestAccessingFabricIndex1);
97+
EXPECT_FALSE(testStorage.SyncDoesKeyExist(DefaultStorageKeyAllocator::FailSafeMarkerKey().KeyName()));
98+
99+
failSafeContext.SetAddNocCommandStarted(kTestAccessingFabricIndex2);
100+
EXPECT_EQ(failSafeContext.GetFabricIndex(), kTestAccessingFabricIndex2);
101+
EXPECT_TRUE(testStorage.SyncDoesKeyExist(DefaultStorageKeyAllocator::FailSafeMarkerKey().KeyName()));
94102

95103
failSafeContext.SetAddNocCommandInvoked(kTestAccessingFabricIndex2);
96104
EXPECT_TRUE(failSafeContext.NocCommandHasBeenInvoked());
97105
EXPECT_TRUE(failSafeContext.AddNocCommandHasBeenInvoked());
98106
EXPECT_EQ(failSafeContext.GetFabricIndex(), kTestAccessingFabricIndex2);
99107

108+
failSafeContext.DisarmFailSafe();
109+
EXPECT_FALSE(testStorage.SyncDoesKeyExist(DefaultStorageKeyAllocator::FailSafeMarkerKey().KeyName()));
110+
}
111+
112+
TEST_F(TestFailSafeContext, TestFailSafeContext_UpdateNocCommandInvoked)
113+
{
114+
chip::TestPersistentStorageDelegate testStorage;
115+
chip::app::FailSafeContext failSafeContext;
116+
117+
failSafeContext.Init({ &testStorage });
118+
119+
EXPECT_EQ(failSafeContext.ArmFailSafe(kTestAccessingFabricIndex1, System::Clock::Seconds16(1)), CHIP_NO_ERROR);
120+
EXPECT_EQ(failSafeContext.GetFabricIndex(), kTestAccessingFabricIndex1);
121+
EXPECT_FALSE(testStorage.SyncDoesKeyExist(DefaultStorageKeyAllocator::FailSafeMarkerKey().KeyName()));
122+
100123
failSafeContext.SetUpdateNocCommandInvoked();
101124
EXPECT_TRUE(failSafeContext.NocCommandHasBeenInvoked());
102125
EXPECT_TRUE(failSafeContext.UpdateNocCommandHasBeenInvoked());
126+
EXPECT_FALSE(testStorage.SyncDoesKeyExist(DefaultStorageKeyAllocator::FailSafeMarkerKey().KeyName()));
103127

104128
failSafeContext.DisarmFailSafe();
129+
EXPECT_FALSE(testStorage.SyncDoesKeyExist(DefaultStorageKeyAllocator::FailSafeMarkerKey().KeyName()));
130+
}
131+
132+
TEST_F(TestFailSafeContext, TestFailSafeContext_NocCommandInvokedTimerExpiry)
133+
{
134+
chip::TestPersistentStorageDelegate testStorage;
135+
chip::app::FailSafeContext failSafeContext;
136+
137+
failSafeContext.Init({ &testStorage });
138+
139+
EXPECT_EQ(failSafeContext.ArmFailSafe(kTestAccessingFabricIndex1, System::Clock::Seconds16(1)), CHIP_NO_ERROR);
140+
EXPECT_EQ(failSafeContext.GetFabricIndex(), kTestAccessingFabricIndex1);
141+
EXPECT_FALSE(testStorage.SyncDoesKeyExist(DefaultStorageKeyAllocator::FailSafeMarkerKey().KeyName()));
142+
143+
failSafeContext.SetAddNocCommandStarted(kTestAccessingFabricIndex2);
144+
EXPECT_EQ(failSafeContext.GetFabricIndex(), kTestAccessingFabricIndex2);
145+
EXPECT_TRUE(testStorage.SyncDoesKeyExist(DefaultStorageKeyAllocator::FailSafeMarkerKey().KeyName()));
146+
147+
failSafeContext.SetAddNocCommandInvoked(kTestAccessingFabricIndex2);
148+
EXPECT_TRUE(failSafeContext.NocCommandHasBeenInvoked());
149+
EXPECT_TRUE(failSafeContext.AddNocCommandHasBeenInvoked());
150+
EXPECT_EQ(failSafeContext.GetFabricIndex(), kTestAccessingFabricIndex2);
151+
152+
failSafeContext.ForceFailSafeTimerExpiry();
153+
154+
PlatformMgr().ScheduleWork([](intptr_t) -> void { PlatformMgr().StopEventLoopTask(); }, (intptr_t) nullptr);
155+
PlatformMgr().RunEventLoop();
156+
157+
EXPECT_FALSE(testStorage.SyncDoesKeyExist(DefaultStorageKeyAllocator::FailSafeMarkerKey().KeyName()));
105158
}
106159

107160
} // namespace

0 commit comments

Comments
 (0)