Skip to content

Commit d479e9b

Browse files
committed
Make test setup functions terminate on error
1 parent 9ff29ed commit d479e9b

18 files changed

+109
-145
lines changed

src/app/tests/AppTestContext.cpp

+14-18
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,13 @@ chip::Access::AccessControl gPermissiveAccessControl;
3838
namespace chip {
3939
namespace Test {
4040

41-
CHIP_ERROR AppContext::SetUpTestSuite()
41+
void AppContext::SetUpTestSuite()
4242
{
4343
CHIP_ERROR err = CHIP_NO_ERROR;
44-
VerifyOrExit((err = LoopbackMessagingContext::SetUpTestSuite()) == CHIP_NO_ERROR,
45-
ChipLogError(AppServer, "SetUpTestSuite lo messaging context failed: %" CHIP_ERROR_FORMAT, err.Format()));
46-
VerifyOrExit((err = chip::DeviceLayer::PlatformMgr().InitChipStack()) == CHIP_NO_ERROR,
47-
ChipLogError(AppServer, "Init CHIP stack failed: %" CHIP_ERROR_FORMAT, err.Format()));
48-
exit:
49-
return err;
44+
LoopbackMessagingContext::SetUpTestSuite();
45+
// TODO: use ASSERT_EQ, once transition to pw_unit_test is complete
46+
VerifyOrDieWithMsg(chip::DeviceLayer::PlatformMgr().InitChipStack() == CHIP_NO_ERROR, AppServer,
47+
"Init CHIP stack failed: %" CHIP_ERROR_FORMAT, err.Format());
5048
}
5149

5250
void AppContext::TearDownTestSuite()
@@ -55,20 +53,18 @@ void AppContext::TearDownTestSuite()
5553
LoopbackMessagingContext::TearDownTestSuite();
5654
}
5755

58-
CHIP_ERROR AppContext::SetUp()
56+
void AppContext::SetUp()
5957
{
6058
CHIP_ERROR err = CHIP_NO_ERROR;
61-
VerifyOrExit((err = LoopbackMessagingContext::SetUp()) == CHIP_NO_ERROR,
62-
ChipLogError(AppServer, "SetUp lo messaging context failed: %" CHIP_ERROR_FORMAT, err.Format()));
63-
VerifyOrExit((err = app::InteractionModelEngine::GetInstance()->Init(
64-
&GetExchangeManager(), &GetFabricTable(), app::reporting::GetDefaultReportScheduler())) == CHIP_NO_ERROR,
65-
ChipLogError(AppServer, "Init InteractionModelEngine failed: %" CHIP_ERROR_FORMAT, err.Format()));
59+
LoopbackMessagingContext::SetUp();
60+
// TODO: use ASSERT_EQ, once transition to pw_unit_test is complete
61+
VerifyOrDieWithMsg(app::InteractionModelEngine::GetInstance()->Init(
62+
&GetExchangeManager(), &GetFabricTable(), app::reporting::GetDefaultReportScheduler()) == CHIP_NO_ERROR,
63+
AppServer, "Init InteractionModelEngine failed: %" CHIP_ERROR_FORMAT, err.Format());
6664
Access::SetAccessControl(gPermissiveAccessControl);
67-
VerifyOrExit((err = Access::GetAccessControl().Init(chip::Access::Examples::GetPermissiveAccessControlDelegate(),
68-
gDeviceTypeResolver)) == CHIP_NO_ERROR,
69-
ChipLogError(AppServer, "Init AccessControl failed: %" CHIP_ERROR_FORMAT, err.Format()));
70-
exit:
71-
return err;
65+
VerifyOrDieWithMsg(Access::GetAccessControl().Init(chip::Access::Examples::GetPermissiveAccessControlDelegate(),
66+
gDeviceTypeResolver) == CHIP_NO_ERROR,
67+
AppServer, "Init AccessControl failed: %" CHIP_ERROR_FORMAT, err.Format());
7268
}
7369

7470
void AppContext::TearDown()

src/app/tests/AppTestContext.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ class AppContext : public LoopbackMessagingContext
2828
{
2929
public:
3030
// Performs shared setup for all tests in the test suite
31-
CHIP_ERROR SetUpTestSuite() override;
31+
void SetUpTestSuite() override;
3232
// Performs shared teardown for all tests in the test suite
3333
void TearDownTestSuite() override;
3434
// Performs setup for each individual test in the test suite
35-
CHIP_ERROR SetUp() override;
35+
void SetUp() override;
3636
// Performs teardown for each individual test in the test suite
3737
void TearDown() override;
3838
};

src/app/tests/TestAclAttribute.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,11 @@ class TestAccessContext : public chip::Test::AppContext
8181
{
8282
public:
8383
// Performs setup for each individual test in the test suite
84-
CHIP_ERROR SetUp() override
84+
void SetUp() override
8585
{
86-
ReturnErrorOnFailure(chip::Test::AppContext::SetUp());
86+
chip::Test::AppContext::SetUp();
8787
Access::GetAccessControl().Finish();
8888
Access::GetAccessControl().Init(GetTestAccessControlDelegate(), gDeviceTypeResolver);
89-
return CHIP_NO_ERROR;
9089
}
9190
};
9291

src/app/tests/TestAclEvent.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -86,27 +86,25 @@ class TestContext : public chip::Test::AppContext
8686
{
8787
public:
8888
// Performs setup for each individual test in the test suite
89-
CHIP_ERROR SetUp() override
89+
void SetUp() override
9090
{
9191
const chip::app::LogStorageResources logStorageResources[] = {
9292
{ &gDebugEventBuffer[0], sizeof(gDebugEventBuffer), chip::app::PriorityLevel::Debug },
9393
{ &gInfoEventBuffer[0], sizeof(gInfoEventBuffer), chip::app::PriorityLevel::Info },
9494
{ &gCritEventBuffer[0], sizeof(gCritEventBuffer), chip::app::PriorityLevel::Critical },
9595
};
9696

97-
ReturnErrorOnFailure(chip::Test::AppContext::SetUp());
97+
chip::Test::AppContext::SetUp();
9898

9999
CHIP_ERROR err = CHIP_NO_ERROR;
100-
VerifyOrExit((err = mEventCounter.Init(0)) == CHIP_NO_ERROR,
101-
ChipLogError(AppServer, "Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format()));
100+
// TODO: use ASSERT_EQ, once transition to pw_unit_test is complete
101+
VerifyOrDieWithMsg((err = mEventCounter.Init(0)) == CHIP_NO_ERROR, AppServer,
102+
"Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format());
102103
chip::app::EventManagement::CreateEventManagement(&GetExchangeManager(), ArraySize(logStorageResources),
103104
gCircularEventBuffer, logStorageResources, &mEventCounter);
104105

105106
Access::GetAccessControl().Finish();
106107
Access::GetAccessControl().Init(GetTestAccessControlDelegate(), gDeviceTypeResolver);
107-
108-
exit:
109-
return err;
110108
}
111109

112110
// Performs teardown for each individual test in the test suite

src/app/tests/TestEventLogging.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,22 @@ class TestContext : public chip::Test::AppContext
6464
{
6565
public:
6666
// Performs setup for each individual test in the test suite
67-
CHIP_ERROR SetUp() override
67+
void SetUp() override
6868
{
6969
const chip::app::LogStorageResources logStorageResources[] = {
7070
{ &gDebugEventBuffer[0], sizeof(gDebugEventBuffer), chip::app::PriorityLevel::Debug },
7171
{ &gInfoEventBuffer[0], sizeof(gInfoEventBuffer), chip::app::PriorityLevel::Info },
7272
{ &gCritEventBuffer[0], sizeof(gCritEventBuffer), chip::app::PriorityLevel::Critical },
7373
};
7474

75-
ReturnErrorOnFailure(chip::Test::AppContext::SetUp());
75+
chip::Test::AppContext::SetUp();
7676

7777
CHIP_ERROR err = CHIP_NO_ERROR;
78-
VerifyOrExit((err = mEventCounter.Init(0)) == CHIP_NO_ERROR,
79-
ChipLogError(AppServer, "Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format()));
78+
// TODO: use ASSERT_EQ, once transition to pw_unit_test is complete
79+
VerifyOrDieWithMsg((err = mEventCounter.Init(0)) == CHIP_NO_ERROR, AppServer,
80+
"Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format());
8081
chip::app::EventManagement::CreateEventManagement(&GetExchangeManager(), ArraySize(logStorageResources),
8182
gCircularEventBuffer, logStorageResources, &mEventCounter);
82-
83-
exit:
84-
return err;
8583
}
8684

8785
// Performs teardown for each individual test in the test suite

src/app/tests/TestEventLoggingNoUTCTime.cpp

+7-10
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,10 @@ class TestContext : public chip::Test::AppContext
8484
{
8585
public:
8686
// Performs shared setup for all tests in the test suite
87-
CHIP_ERROR SetUpTestSuite() override
87+
void SetUpTestSuite() override
8888
{
89-
ReturnErrorOnFailure(chip::Test::AppContext::SetUpTestSuite());
89+
chip::Test::AppContext::SetUpTestSuite();
9090
mClock.Emplace(chip::System::SystemClock());
91-
return CHIP_NO_ERROR;
9291
}
9392

9493
// Performs shared teardown for all tests in the test suite
@@ -99,24 +98,22 @@ class TestContext : public chip::Test::AppContext
9998
}
10099

101100
// Performs setup for each individual test in the test suite
102-
CHIP_ERROR SetUp() override
101+
void SetUp() override
103102
{
104103
const chip::app::LogStorageResources logStorageResources[] = {
105104
{ &gDebugEventBuffer[0], sizeof(gDebugEventBuffer), chip::app::PriorityLevel::Debug },
106105
{ &gInfoEventBuffer[0], sizeof(gInfoEventBuffer), chip::app::PriorityLevel::Info },
107106
{ &gCritEventBuffer[0], sizeof(gCritEventBuffer), chip::app::PriorityLevel::Critical },
108107
};
109108

110-
ReturnErrorOnFailure(chip::Test::AppContext::SetUp());
109+
chip::Test::AppContext::SetUp();
111110

112111
CHIP_ERROR err = CHIP_NO_ERROR;
113-
VerifyOrExit((err = mEventCounter.Init(0)) == CHIP_NO_ERROR,
114-
ChipLogError(AppServer, "Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format()));
112+
// TODO: use ASSERT_EQ, once transition to pw_unit_test is complete
113+
VerifyOrDieWithMsg((err = mEventCounter.Init(0)) == CHIP_NO_ERROR, AppServer,
114+
"Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format());
115115
chip::app::EventManagement::CreateEventManagement(&GetExchangeManager(), ArraySize(logStorageResources),
116116
gCircularEventBuffer, logStorageResources, &mEventCounter);
117-
118-
exit:
119-
return err;
120117
}
121118

122119
// Performs teardown for each individual test in the test suite

src/app/tests/TestEventOverflow.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,22 @@ class TestContext : public chip::Test::AppContext
5656
{
5757
public:
5858
// Performs setup for each individual test in the test suite
59-
CHIP_ERROR SetUp() override
59+
void SetUp() override
6060
{
6161
const chip::app::LogStorageResources logStorageResources[] = {
6262
{ &gDebugEventBuffer[0], sizeof(gDebugEventBuffer), chip::app::PriorityLevel::Debug },
6363
{ &gInfoEventBuffer[0], sizeof(gInfoEventBuffer), chip::app::PriorityLevel::Info },
6464
{ &gCritEventBuffer[0], sizeof(gCritEventBuffer), chip::app::PriorityLevel::Critical },
6565
};
6666

67-
ReturnErrorOnFailure(chip::Test::AppContext::SetUp());
67+
chip::Test::AppContext::SetUp();
6868

6969
CHIP_ERROR err = CHIP_NO_ERROR;
70-
VerifyOrExit((err = mEventCounter.Init(0)) == CHIP_NO_ERROR,
71-
ChipLogError(AppServer, "Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format()));
70+
// TODO: use ASSERT_EQ, once transition to pw_unit_test is complete
71+
VerifyOrDieWithMsg((err = mEventCounter.Init(0)) == CHIP_NO_ERROR, AppServer,
72+
"Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format());
7273
chip::app::EventManagement::CreateEventManagement(&GetExchangeManager(), ArraySize(logStorageResources),
7374
gCircularEventBuffer, logStorageResources, &mEventCounter);
74-
75-
exit:
76-
return err;
7775
}
7876

7977
// Performs teardown for each individual test in the test suite

src/app/tests/TestFabricScopedEventLogging.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,22 @@ class TestContext : public chip::Test::AppContext
6464
{
6565
public:
6666
// Performs setup for each individual test in the test suite
67-
CHIP_ERROR SetUp() override
67+
void SetUp() override
6868
{
6969
const chip::app::LogStorageResources logStorageResources[] = {
7070
{ &gDebugEventBuffer[0], sizeof(gDebugEventBuffer), chip::app::PriorityLevel::Debug },
7171
{ &gInfoEventBuffer[0], sizeof(gInfoEventBuffer), chip::app::PriorityLevel::Info },
7272
{ &gCritEventBuffer[0], sizeof(gCritEventBuffer), chip::app::PriorityLevel::Critical },
7373
};
7474

75-
ReturnErrorOnFailure(chip::Test::AppContext::SetUp());
75+
chip::Test::AppContext::SetUp();
7676

7777
CHIP_ERROR err = CHIP_NO_ERROR;
78-
VerifyOrExit((err = mEventCounter.Init(0)) == CHIP_NO_ERROR,
79-
ChipLogError(AppServer, "Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format()));
78+
// TODO: use ASSERT_EQ, once transition to pw_unit_test is complete
79+
VerifyOrDieWithMsg((err = mEventCounter.Init(0)) == CHIP_NO_ERROR, AppServer,
80+
"Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format());
8081
chip::app::EventManagement::CreateEventManagement(&GetExchangeManager(), ArraySize(logStorageResources),
8182
gCircularEventBuffer, logStorageResources, &mEventCounter);
82-
83-
exit:
84-
return err;
8583
}
8684

8785
// Performs teardown for each individual test in the test suite

src/app/tests/TestICDManager.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ class TestContext : public chip::Test::AppContext
121121
{
122122
public:
123123
// Performs shared setup for all tests in the test suite
124-
CHIP_ERROR SetUpTestSuite() override
124+
void SetUpTestSuite() override
125125
{
126-
ReturnErrorOnFailure(chip::Test::AppContext::SetUpTestSuite());
126+
chip::Test::AppContext::SetUpTestSuite();
127127
DeviceLayer::SetSystemLayerForTesting(&GetSystemLayer());
128128
mRealClock = &chip::System::SystemClock();
129129
System::Clock::Internal::SetSystemClockForTesting(&mMockClock);
@@ -139,13 +139,12 @@ class TestContext : public chip::Test::AppContext
139139
}
140140

141141
// Performs setup for each individual test in the test suite
142-
CHIP_ERROR SetUp() override
142+
void SetUp() override
143143
{
144-
ReturnErrorOnFailure(chip::Test::AppContext::SetUp());
144+
chip::Test::AppContext::SetUp();
145145
mICDStateObserver.ResetAll();
146146
mICDManager.RegisterObserver(&mICDStateObserver);
147147
mICDManager.Init(&testStorage, &GetFabricTable(), &mKeystore, &GetExchangeManager(), &mSubInfoProvider);
148-
return CHIP_NO_ERROR;
149148
}
150149

151150
// Performs teardown for each individual test in the test suite

src/app/tests/TestReadInteraction.cpp

+8-14
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ class TestContext : public chip::Test::AppContext
7979
{
8080
public:
8181
// Performs shared setup for all tests in the test suite
82-
CHIP_ERROR SetUpTestSuite() override
82+
void SetUpTestSuite() override
8383
{
84-
ReturnErrorOnFailure(chip::Test::AppContext::SetUpTestSuite());
84+
chip::Test::AppContext::SetUpTestSuite();
8585
gRealClock = &chip::System::SystemClock();
8686
chip::System::Clock::Internal::SetSystemClockForTesting(&gMockClock);
8787

@@ -94,8 +94,6 @@ class TestContext : public chip::Test::AppContext
9494
{
9595
gReportScheduler = chip::app::reporting::GetDefaultReportScheduler();
9696
}
97-
98-
return CHIP_NO_ERROR;
9997
}
10098

10199
static int nlTestSetUpTestSuite_Sync(void * context)
@@ -112,24 +110,20 @@ class TestContext : public chip::Test::AppContext
112110
}
113111

114112
// Performs setup for each individual test in the test suite
115-
CHIP_ERROR SetUp() override
113+
void SetUp() override
116114
{
117115
const chip::app::LogStorageResources logStorageResources[] = {
118116
{ &gDebugEventBuffer[0], sizeof(gDebugEventBuffer), chip::app::PriorityLevel::Debug },
119117
{ &gInfoEventBuffer[0], sizeof(gInfoEventBuffer), chip::app::PriorityLevel::Info },
120118
{ &gCritEventBuffer[0], sizeof(gCritEventBuffer), chip::app::PriorityLevel::Critical },
121119
};
122120

123-
ReturnErrorOnFailure(chip::Test::AppContext::SetUp());
121+
chip::Test::AppContext::SetUp();
124122

125-
CHIP_ERROR err = CHIP_NO_ERROR;
126-
VerifyOrExit((err = mEventCounter.Init(0)) == CHIP_NO_ERROR,
127-
ChipLogError(AppServer, "Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format()));
123+
// TODO: change to ASSERT_EQ, once transition to pw_unit_test is complete
124+
VerifyOrDie(mEventCounter.Init(0) == CHIP_NO_ERROR);
128125
chip::app::EventManagement::CreateEventManagement(&GetExchangeManager(), ArraySize(logStorageResources),
129126
gCircularEventBuffer, logStorageResources, &mEventCounter);
130-
131-
exit:
132-
return err;
133127
}
134128

135129
// Performs teardown for each individual test in the test suite
@@ -4244,7 +4238,7 @@ void TestReadInteraction::TestSubscribeClientReceiveUnsolicitedInvalidReportMess
42444238

42454239
ctx.GetLoopback().mSentMessageCount = 0;
42464240
auto exchange = InteractionModelEngine::GetInstance()->GetExchangeManager()->NewContext(
4247-
delegate.mpReadHandler->mSessionHandle.Get().Value(), delegate.mpReadHandler);
4241+
delegate.mpReadHandler->mSessionHandle.Get().Value(), delegate.mpReadHandler);
42484242
delegate.mpReadHandler->mExchangeCtx.Grab(exchange);
42494243
err = delegate.mpReadHandler->mExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::ReportData, std::move(msgBuf),
42504244
Messaging::SendMessageFlags::kExpectResponse);
@@ -4413,7 +4407,7 @@ void TestReadInteraction::TestSubscribeClientReceiveUnsolicitedReportMessageWith
44134407

44144408
ctx.GetLoopback().mSentMessageCount = 0;
44154409
auto exchange = InteractionModelEngine::GetInstance()->GetExchangeManager()->NewContext(
4416-
delegate.mpReadHandler->mSessionHandle.Get().Value(), delegate.mpReadHandler);
4410+
delegate.mpReadHandler->mSessionHandle.Get().Value(), delegate.mpReadHandler);
44174411
delegate.mpReadHandler->mExchangeCtx.Grab(exchange);
44184412
err = delegate.mpReadHandler->mExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::ReportData, std::move(msgBuf),
44194413
Messaging::SendMessageFlags::kExpectResponse);

src/app/tests/TestWriteInteraction.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,21 @@ class TestContext : public chip::Test::AppContext
5555
{
5656
public:
5757
// Performs setup for each individual test in the test suite
58-
CHIP_ERROR SetUp() override
58+
void SetUp() override
5959
{
60-
ReturnErrorOnFailure(chip::Test::AppContext::SetUp());
60+
chip::Test::AppContext::SetUp();
6161

6262
gTestStorage.ClearStorage();
6363
gGroupsProvider.SetStorageDelegate(&gTestStorage);
6464
gGroupsProvider.SetSessionKeystore(&gSessionKeystore);
65-
ReturnErrorOnFailure(gGroupsProvider.Init());
65+
// TODO: use ASSERT_EQ, once transition to pw_unit_test is complete
66+
VerifyOrDie(gGroupsProvider.Init() == CHIP_NO_ERROR);
6667
chip::Credentials::SetGroupDataProvider(&gGroupsProvider);
6768

6869
uint8_t buf[sizeof(chip::CompressedFabricId)];
6970
chip::MutableByteSpan span(buf);
70-
ReturnErrorOnFailure(GetBobFabric()->GetCompressedFabricIdBytes(span));
71-
ReturnErrorOnFailure(chip::GroupTesting::InitData(&gGroupsProvider, GetBobFabricIndex(), span));
72-
73-
return CHIP_NO_ERROR;
71+
VerifyOrDie(GetBobFabric()->GetCompressedFabricIdBytes(span) == CHIP_NO_ERROR);
72+
VerifyOrDie(chip::GroupTesting::InitData(&gGroupsProvider, GetBobFabricIndex(), span) == CHIP_NO_ERROR);
7473
}
7574

7675
// Performs teardown for each individual test in the test suite

0 commit comments

Comments
 (0)