From 3c5b92c96dd93c71317f6e253c4274bb1622bad8 Mon Sep 17 00:00:00 2001 From: Maksymilian Knust Date: Mon, 6 May 2024 15:38:33 +0200 Subject: [PATCH] Make test setup functions terminate on error (#33002) * Make test setup functions terminate on error * Restyled by clang-format --------- Co-authored-by: Restyled.io --- src/app/icd/server/tests/TestICDManager.cpp | 4 +-- src/app/tests/AppTestContext.cpp | 33 +++++++++---------- src/app/tests/AppTestContext.h | 4 +-- src/app/tests/TestAclAttribute.cpp | 5 ++- src/app/tests/TestAclEvent.cpp | 12 +++---- src/app/tests/TestEventLogging.cpp | 12 +++---- src/app/tests/TestEventLoggingNoUTCTime.cpp | 17 ++++------ src/app/tests/TestEventOverflow.cpp | 12 +++---- .../tests/TestFabricScopedEventLogging.cpp | 12 +++---- src/app/tests/TestReadInteraction.cpp | 18 ++++------ src/app/tests/TestWriteInteraction.cpp | 13 ++++---- src/controller/tests/TestEventCaching.cpp | 12 +++---- src/controller/tests/TestEventChunking.cpp | 12 +++---- .../tests/TestEventNumberCaching.cpp | 12 +++---- src/messaging/tests/MessagingContext.h | 29 ++++++++-------- .../tests/TestAbortExchangesForFabric.cpp | 8 ++--- src/messaging/tests/TestExchangeMgr.cpp | 8 ++--- .../tests/TestReliableMessageProtocol.cpp | 8 ++--- .../secure_channel/tests/TestCASESession.cpp | 24 +++++++------- .../secure_channel/tests/TestPASESession.cpp | 4 +-- 20 files changed, 113 insertions(+), 146 deletions(-) diff --git a/src/app/icd/server/tests/TestICDManager.cpp b/src/app/icd/server/tests/TestICDManager.cpp index 366bcb5c9280ad..6cba8c308b4e06 100644 --- a/src/app/icd/server/tests/TestICDManager.cpp +++ b/src/app/icd/server/tests/TestICDManager.cpp @@ -163,7 +163,7 @@ class TestICDManager : public ::testing::Test ASSERT_NE(pMessagingContext, nullptr); } - ASSERT_EQ(pMessagingContext->SetUpTestSuite(), CHIP_NO_ERROR); + pMessagingContext->SetUpTestSuite(); ASSERT_EQ(chip::DeviceLayer::PlatformMgr().InitChipStack(), CHIP_NO_ERROR); DeviceLayer::SetSystemLayerForTesting(&(pMessagingContext->GetSystemLayer())); @@ -198,7 +198,7 @@ class TestICDManager : public ::testing::Test // Performs setup for each individual test in the test suite void SetUp() override { - EXPECT_EQ(pMessagingContext->SetUp(), CHIP_NO_ERROR); + pMessagingContext->SetUp(); mICDStateObserver.ResetAll(); mICDManager.RegisterObserver(&mICDStateObserver); diff --git a/src/app/tests/AppTestContext.cpp b/src/app/tests/AppTestContext.cpp index 6f22097d7d11e8..eca7a2db76c83b 100644 --- a/src/app/tests/AppTestContext.cpp +++ b/src/app/tests/AppTestContext.cpp @@ -38,15 +38,13 @@ chip::Access::AccessControl gPermissiveAccessControl; namespace chip { namespace Test { -CHIP_ERROR AppContext::SetUpTestSuite() +void AppContext::SetUpTestSuite() { CHIP_ERROR err = CHIP_NO_ERROR; - VerifyOrExit((err = LoopbackMessagingContext::SetUpTestSuite()) == CHIP_NO_ERROR, - ChipLogError(AppServer, "SetUpTestSuite lo messaging context failed: %" CHIP_ERROR_FORMAT, err.Format())); - VerifyOrExit((err = chip::DeviceLayer::PlatformMgr().InitChipStack()) == CHIP_NO_ERROR, - ChipLogError(AppServer, "Init CHIP stack failed: %" CHIP_ERROR_FORMAT, err.Format())); -exit: - return err; + LoopbackMessagingContext::SetUpTestSuite(); + // TODO: use ASSERT_EQ, once transition to pw_unit_test is complete + VerifyOrDieWithMsg((err = chip::DeviceLayer::PlatformMgr().InitChipStack()) == CHIP_NO_ERROR, AppServer, + "Init CHIP stack failed: %" CHIP_ERROR_FORMAT, err.Format()); } void AppContext::TearDownTestSuite() @@ -55,20 +53,19 @@ void AppContext::TearDownTestSuite() LoopbackMessagingContext::TearDownTestSuite(); } -CHIP_ERROR AppContext::SetUp() +void AppContext::SetUp() { CHIP_ERROR err = CHIP_NO_ERROR; - VerifyOrExit((err = LoopbackMessagingContext::SetUp()) == CHIP_NO_ERROR, - ChipLogError(AppServer, "SetUp lo messaging context failed: %" CHIP_ERROR_FORMAT, err.Format())); - VerifyOrExit((err = app::InteractionModelEngine::GetInstance()->Init( - &GetExchangeManager(), &GetFabricTable(), app::reporting::GetDefaultReportScheduler())) == CHIP_NO_ERROR, - ChipLogError(AppServer, "Init InteractionModelEngine failed: %" CHIP_ERROR_FORMAT, err.Format())); + LoopbackMessagingContext::SetUp(); + // TODO: use ASSERT_EQ, once transition to pw_unit_test is complete + VerifyOrDieWithMsg((err = app::InteractionModelEngine::GetInstance()->Init(&GetExchangeManager(), &GetFabricTable(), + app::reporting::GetDefaultReportScheduler())) == + CHIP_NO_ERROR, + AppServer, "Init InteractionModelEngine failed: %" CHIP_ERROR_FORMAT, err.Format()); Access::SetAccessControl(gPermissiveAccessControl); - VerifyOrExit((err = Access::GetAccessControl().Init(chip::Access::Examples::GetPermissiveAccessControlDelegate(), - gDeviceTypeResolver)) == CHIP_NO_ERROR, - ChipLogError(AppServer, "Init AccessControl failed: %" CHIP_ERROR_FORMAT, err.Format())); -exit: - return err; + VerifyOrDieWithMsg((err = Access::GetAccessControl().Init(chip::Access::Examples::GetPermissiveAccessControlDelegate(), + gDeviceTypeResolver)) == CHIP_NO_ERROR, + AppServer, "Init AccessControl failed: %" CHIP_ERROR_FORMAT, err.Format()); } void AppContext::TearDown() diff --git a/src/app/tests/AppTestContext.h b/src/app/tests/AppTestContext.h index 40605f237db7ab..b9945fecd3a90a 100644 --- a/src/app/tests/AppTestContext.h +++ b/src/app/tests/AppTestContext.h @@ -28,11 +28,11 @@ class AppContext : public LoopbackMessagingContext { public: // Performs shared setup for all tests in the test suite - CHIP_ERROR SetUpTestSuite() override; + void SetUpTestSuite() override; // Performs shared teardown for all tests in the test suite void TearDownTestSuite() override; // Performs setup for each individual test in the test suite - CHIP_ERROR SetUp() override; + void SetUp() override; // Performs teardown for each individual test in the test suite void TearDown() override; }; diff --git a/src/app/tests/TestAclAttribute.cpp b/src/app/tests/TestAclAttribute.cpp index da11c40a28dedf..c1bfd8acf68a73 100644 --- a/src/app/tests/TestAclAttribute.cpp +++ b/src/app/tests/TestAclAttribute.cpp @@ -81,12 +81,11 @@ class TestAccessContext : public chip::Test::AppContext { public: // Performs setup for each individual test in the test suite - CHIP_ERROR SetUp() override + void SetUp() override { - ReturnErrorOnFailure(chip::Test::AppContext::SetUp()); + chip::Test::AppContext::SetUp(); Access::GetAccessControl().Finish(); Access::GetAccessControl().Init(GetTestAccessControlDelegate(), gDeviceTypeResolver); - return CHIP_NO_ERROR; } }; diff --git a/src/app/tests/TestAclEvent.cpp b/src/app/tests/TestAclEvent.cpp index fda4a69217ccd6..f7c85e0bccaed8 100644 --- a/src/app/tests/TestAclEvent.cpp +++ b/src/app/tests/TestAclEvent.cpp @@ -86,7 +86,7 @@ class TestContext : public chip::Test::AppContext { public: // Performs setup for each individual test in the test suite - CHIP_ERROR SetUp() override + void SetUp() override { const chip::app::LogStorageResources logStorageResources[] = { { &gDebugEventBuffer[0], sizeof(gDebugEventBuffer), chip::app::PriorityLevel::Debug }, @@ -94,19 +94,17 @@ class TestContext : public chip::Test::AppContext { &gCritEventBuffer[0], sizeof(gCritEventBuffer), chip::app::PriorityLevel::Critical }, }; - ReturnErrorOnFailure(chip::Test::AppContext::SetUp()); + chip::Test::AppContext::SetUp(); CHIP_ERROR err = CHIP_NO_ERROR; - VerifyOrExit((err = mEventCounter.Init(0)) == CHIP_NO_ERROR, - ChipLogError(AppServer, "Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format())); + // TODO: use ASSERT_EQ, once transition to pw_unit_test is complete + VerifyOrDieWithMsg((err = mEventCounter.Init(0)) == CHIP_NO_ERROR, AppServer, + "Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format()); chip::app::EventManagement::CreateEventManagement(&GetExchangeManager(), ArraySize(logStorageResources), gCircularEventBuffer, logStorageResources, &mEventCounter); Access::GetAccessControl().Finish(); Access::GetAccessControl().Init(GetTestAccessControlDelegate(), gDeviceTypeResolver); - - exit: - return err; } // Performs teardown for each individual test in the test suite diff --git a/src/app/tests/TestEventLogging.cpp b/src/app/tests/TestEventLogging.cpp index baf43d6b398707..41ae31bd4295ff 100644 --- a/src/app/tests/TestEventLogging.cpp +++ b/src/app/tests/TestEventLogging.cpp @@ -64,7 +64,7 @@ class TestContext : public chip::Test::AppContext { public: // Performs setup for each individual test in the test suite - CHIP_ERROR SetUp() override + void SetUp() override { const chip::app::LogStorageResources logStorageResources[] = { { &gDebugEventBuffer[0], sizeof(gDebugEventBuffer), chip::app::PriorityLevel::Debug }, @@ -72,16 +72,14 @@ class TestContext : public chip::Test::AppContext { &gCritEventBuffer[0], sizeof(gCritEventBuffer), chip::app::PriorityLevel::Critical }, }; - ReturnErrorOnFailure(chip::Test::AppContext::SetUp()); + chip::Test::AppContext::SetUp(); CHIP_ERROR err = CHIP_NO_ERROR; - VerifyOrExit((err = mEventCounter.Init(0)) == CHIP_NO_ERROR, - ChipLogError(AppServer, "Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format())); + // TODO: use ASSERT_EQ, once transition to pw_unit_test is complete + VerifyOrDieWithMsg((err = mEventCounter.Init(0)) == CHIP_NO_ERROR, AppServer, + "Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format()); chip::app::EventManagement::CreateEventManagement(&GetExchangeManager(), ArraySize(logStorageResources), gCircularEventBuffer, logStorageResources, &mEventCounter); - - exit: - return err; } // Performs teardown for each individual test in the test suite diff --git a/src/app/tests/TestEventLoggingNoUTCTime.cpp b/src/app/tests/TestEventLoggingNoUTCTime.cpp index 8360f9a0813e98..77a8463a5f9718 100644 --- a/src/app/tests/TestEventLoggingNoUTCTime.cpp +++ b/src/app/tests/TestEventLoggingNoUTCTime.cpp @@ -84,11 +84,10 @@ class TestContext : public chip::Test::AppContext { public: // Performs shared setup for all tests in the test suite - CHIP_ERROR SetUpTestSuite() override + void SetUpTestSuite() override { - ReturnErrorOnFailure(chip::Test::AppContext::SetUpTestSuite()); + chip::Test::AppContext::SetUpTestSuite(); mClock.Emplace(chip::System::SystemClock()); - return CHIP_NO_ERROR; } // Performs shared teardown for all tests in the test suite @@ -99,7 +98,7 @@ class TestContext : public chip::Test::AppContext } // Performs setup for each individual test in the test suite - CHIP_ERROR SetUp() override + void SetUp() override { const chip::app::LogStorageResources logStorageResources[] = { { &gDebugEventBuffer[0], sizeof(gDebugEventBuffer), chip::app::PriorityLevel::Debug }, @@ -107,16 +106,14 @@ class TestContext : public chip::Test::AppContext { &gCritEventBuffer[0], sizeof(gCritEventBuffer), chip::app::PriorityLevel::Critical }, }; - ReturnErrorOnFailure(chip::Test::AppContext::SetUp()); + chip::Test::AppContext::SetUp(); CHIP_ERROR err = CHIP_NO_ERROR; - VerifyOrExit((err = mEventCounter.Init(0)) == CHIP_NO_ERROR, - ChipLogError(AppServer, "Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format())); + // TODO: use ASSERT_EQ, once transition to pw_unit_test is complete + VerifyOrDieWithMsg((err = mEventCounter.Init(0)) == CHIP_NO_ERROR, AppServer, + "Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format()); chip::app::EventManagement::CreateEventManagement(&GetExchangeManager(), ArraySize(logStorageResources), gCircularEventBuffer, logStorageResources, &mEventCounter); - - exit: - return err; } // Performs teardown for each individual test in the test suite diff --git a/src/app/tests/TestEventOverflow.cpp b/src/app/tests/TestEventOverflow.cpp index 3edc62a0445ca1..a328bec9783ef2 100644 --- a/src/app/tests/TestEventOverflow.cpp +++ b/src/app/tests/TestEventOverflow.cpp @@ -56,7 +56,7 @@ class TestContext : public chip::Test::AppContext { public: // Performs setup for each individual test in the test suite - CHIP_ERROR SetUp() override + void SetUp() override { const chip::app::LogStorageResources logStorageResources[] = { { &gDebugEventBuffer[0], sizeof(gDebugEventBuffer), chip::app::PriorityLevel::Debug }, @@ -64,16 +64,14 @@ class TestContext : public chip::Test::AppContext { &gCritEventBuffer[0], sizeof(gCritEventBuffer), chip::app::PriorityLevel::Critical }, }; - ReturnErrorOnFailure(chip::Test::AppContext::SetUp()); + chip::Test::AppContext::SetUp(); CHIP_ERROR err = CHIP_NO_ERROR; - VerifyOrExit((err = mEventCounter.Init(0)) == CHIP_NO_ERROR, - ChipLogError(AppServer, "Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format())); + // TODO: use ASSERT_EQ, once transition to pw_unit_test is complete + VerifyOrDieWithMsg((err = mEventCounter.Init(0)) == CHIP_NO_ERROR, AppServer, + "Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format()); chip::app::EventManagement::CreateEventManagement(&GetExchangeManager(), ArraySize(logStorageResources), gCircularEventBuffer, logStorageResources, &mEventCounter); - - exit: - return err; } // Performs teardown for each individual test in the test suite diff --git a/src/app/tests/TestFabricScopedEventLogging.cpp b/src/app/tests/TestFabricScopedEventLogging.cpp index d016ad5183e1c0..082aca0a2ecb7d 100644 --- a/src/app/tests/TestFabricScopedEventLogging.cpp +++ b/src/app/tests/TestFabricScopedEventLogging.cpp @@ -64,7 +64,7 @@ class TestContext : public chip::Test::AppContext { public: // Performs setup for each individual test in the test suite - CHIP_ERROR SetUp() override + void SetUp() override { const chip::app::LogStorageResources logStorageResources[] = { { &gDebugEventBuffer[0], sizeof(gDebugEventBuffer), chip::app::PriorityLevel::Debug }, @@ -72,16 +72,14 @@ class TestContext : public chip::Test::AppContext { &gCritEventBuffer[0], sizeof(gCritEventBuffer), chip::app::PriorityLevel::Critical }, }; - ReturnErrorOnFailure(chip::Test::AppContext::SetUp()); + chip::Test::AppContext::SetUp(); CHIP_ERROR err = CHIP_NO_ERROR; - VerifyOrExit((err = mEventCounter.Init(0)) == CHIP_NO_ERROR, - ChipLogError(AppServer, "Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format())); + // TODO: use ASSERT_EQ, once transition to pw_unit_test is complete + VerifyOrDieWithMsg((err = mEventCounter.Init(0)) == CHIP_NO_ERROR, AppServer, + "Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format()); chip::app::EventManagement::CreateEventManagement(&GetExchangeManager(), ArraySize(logStorageResources), gCircularEventBuffer, logStorageResources, &mEventCounter); - - exit: - return err; } // Performs teardown for each individual test in the test suite diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index 8173761b6ca83a..7e18cca7883c8f 100644 --- a/src/app/tests/TestReadInteraction.cpp +++ b/src/app/tests/TestReadInteraction.cpp @@ -79,9 +79,9 @@ class TestContext : public chip::Test::AppContext { public: // Performs shared setup for all tests in the test suite - CHIP_ERROR SetUpTestSuite() override + void SetUpTestSuite() override { - ReturnErrorOnFailure(chip::Test::AppContext::SetUpTestSuite()); + chip::Test::AppContext::SetUpTestSuite(); gRealClock = &chip::System::SystemClock(); chip::System::Clock::Internal::SetSystemClockForTesting(&gMockClock); @@ -94,8 +94,6 @@ class TestContext : public chip::Test::AppContext { gReportScheduler = chip::app::reporting::GetDefaultReportScheduler(); } - - return CHIP_NO_ERROR; } static int nlTestSetUpTestSuite_Sync(void * context) @@ -112,7 +110,7 @@ class TestContext : public chip::Test::AppContext } // Performs setup for each individual test in the test suite - CHIP_ERROR SetUp() override + void SetUp() override { const chip::app::LogStorageResources logStorageResources[] = { { &gDebugEventBuffer[0], sizeof(gDebugEventBuffer), chip::app::PriorityLevel::Debug }, @@ -120,16 +118,12 @@ class TestContext : public chip::Test::AppContext { &gCritEventBuffer[0], sizeof(gCritEventBuffer), chip::app::PriorityLevel::Critical }, }; - ReturnErrorOnFailure(chip::Test::AppContext::SetUp()); + chip::Test::AppContext::SetUp(); - CHIP_ERROR err = CHIP_NO_ERROR; - VerifyOrExit((err = mEventCounter.Init(0)) == CHIP_NO_ERROR, - ChipLogError(AppServer, "Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format())); + // TODO: change to ASSERT_EQ, once transition to pw_unit_test is complete + VerifyOrDie(mEventCounter.Init(0) == CHIP_NO_ERROR); chip::app::EventManagement::CreateEventManagement(&GetExchangeManager(), ArraySize(logStorageResources), gCircularEventBuffer, logStorageResources, &mEventCounter); - - exit: - return err; } // Performs teardown for each individual test in the test suite diff --git a/src/app/tests/TestWriteInteraction.cpp b/src/app/tests/TestWriteInteraction.cpp index ce8c49176fabdf..16647ca523829e 100644 --- a/src/app/tests/TestWriteInteraction.cpp +++ b/src/app/tests/TestWriteInteraction.cpp @@ -55,22 +55,21 @@ class TestContext : public chip::Test::AppContext { public: // Performs setup for each individual test in the test suite - CHIP_ERROR SetUp() override + void SetUp() override { - ReturnErrorOnFailure(chip::Test::AppContext::SetUp()); + chip::Test::AppContext::SetUp(); gTestStorage.ClearStorage(); gGroupsProvider.SetStorageDelegate(&gTestStorage); gGroupsProvider.SetSessionKeystore(&gSessionKeystore); - ReturnErrorOnFailure(gGroupsProvider.Init()); + // TODO: use ASSERT_EQ, once transition to pw_unit_test is complete + VerifyOrDie(gGroupsProvider.Init() == CHIP_NO_ERROR); chip::Credentials::SetGroupDataProvider(&gGroupsProvider); uint8_t buf[sizeof(chip::CompressedFabricId)]; chip::MutableByteSpan span(buf); - ReturnErrorOnFailure(GetBobFabric()->GetCompressedFabricIdBytes(span)); - ReturnErrorOnFailure(chip::GroupTesting::InitData(&gGroupsProvider, GetBobFabricIndex(), span)); - - return CHIP_NO_ERROR; + VerifyOrDie(GetBobFabric()->GetCompressedFabricIdBytes(span) == CHIP_NO_ERROR); + VerifyOrDie(chip::GroupTesting::InitData(&gGroupsProvider, GetBobFabricIndex(), span) == CHIP_NO_ERROR); } // Performs teardown for each individual test in the test suite diff --git a/src/controller/tests/TestEventCaching.cpp b/src/controller/tests/TestEventCaching.cpp index dab191cd69ae65..f69f5614592db7 100644 --- a/src/controller/tests/TestEventCaching.cpp +++ b/src/controller/tests/TestEventCaching.cpp @@ -56,7 +56,7 @@ class TestContext : public chip::Test::AppContext { public: // Performs setup for each individual test in the test suite - CHIP_ERROR SetUp() override + void SetUp() override { const chip::app::LogStorageResources logStorageResources[] = { { &gDebugEventBuffer[0], sizeof(gDebugEventBuffer), chip::app::PriorityLevel::Debug }, @@ -64,16 +64,14 @@ class TestContext : public chip::Test::AppContext { &gCritEventBuffer[0], sizeof(gCritEventBuffer), chip::app::PriorityLevel::Critical }, }; - ReturnErrorOnFailure(chip::Test::AppContext::SetUp()); + chip::Test::AppContext::SetUp(); CHIP_ERROR err = CHIP_NO_ERROR; - VerifyOrExit((err = mEventCounter.Init(0)) == CHIP_NO_ERROR, - ChipLogError(AppServer, "Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format())); + // TODO: use ASSERT_EQ, once transition to pw_unit_test is complete + VerifyOrDieWithMsg((err = mEventCounter.Init(0)) == CHIP_NO_ERROR, AppServer, + "Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format()); chip::app::EventManagement::CreateEventManagement(&GetExchangeManager(), ArraySize(logStorageResources), gCircularEventBuffer, logStorageResources, &mEventCounter); - - exit: - return err; } // Performs teardown for each individual test in the test suite diff --git a/src/controller/tests/TestEventChunking.cpp b/src/controller/tests/TestEventChunking.cpp index 0555e3ef94560b..fb2b068fcbc0a0 100644 --- a/src/controller/tests/TestEventChunking.cpp +++ b/src/controller/tests/TestEventChunking.cpp @@ -60,7 +60,7 @@ class TestContext : public chip::Test::AppContext { public: // Performs setup for each individual test in the test suite - CHIP_ERROR SetUp() override + void SetUp() override { const chip::app::LogStorageResources logStorageResources[] = { { &gDebugEventBuffer[0], sizeof(gDebugEventBuffer), chip::app::PriorityLevel::Debug }, @@ -68,16 +68,14 @@ class TestContext : public chip::Test::AppContext { &gCritEventBuffer[0], sizeof(gCritEventBuffer), chip::app::PriorityLevel::Critical }, }; - ReturnErrorOnFailure(chip::Test::AppContext::SetUp()); + chip::Test::AppContext::SetUp(); CHIP_ERROR err = CHIP_NO_ERROR; - VerifyOrExit((err = mEventCounter.Init(0)) == CHIP_NO_ERROR, - ChipLogError(AppServer, "Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format())); + // TODO: use ASSERT_EQ, once transition to pw_unit_test is complete + VerifyOrDieWithMsg((err = mEventCounter.Init(0)) == CHIP_NO_ERROR, AppServer, + "Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format()); chip::app::EventManagement::CreateEventManagement(&GetExchangeManager(), ArraySize(logStorageResources), gCircularEventBuffer, logStorageResources, &mEventCounter); - - exit: - return err; } // Performs teardown for each individual test in the test suite diff --git a/src/controller/tests/TestEventNumberCaching.cpp b/src/controller/tests/TestEventNumberCaching.cpp index a0d93290253117..01526388f4e459 100644 --- a/src/controller/tests/TestEventNumberCaching.cpp +++ b/src/controller/tests/TestEventNumberCaching.cpp @@ -53,7 +53,7 @@ class TestContext : public chip::Test::AppContext { public: // Performs setup for each individual test in the test suite - CHIP_ERROR SetUp() override + void SetUp() override { const chip::app::LogStorageResources logStorageResources[] = { { &gDebugEventBuffer[0], sizeof(gDebugEventBuffer), chip::app::PriorityLevel::Debug }, @@ -61,16 +61,14 @@ class TestContext : public chip::Test::AppContext { &gCritEventBuffer[0], sizeof(gCritEventBuffer), chip::app::PriorityLevel::Critical }, }; - ReturnErrorOnFailure(chip::Test::AppContext::SetUp()); + chip::Test::AppContext::SetUp(); CHIP_ERROR err = CHIP_NO_ERROR; - VerifyOrExit((err = mEventCounter.Init(0)) == CHIP_NO_ERROR, - ChipLogError(AppServer, "Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format())); + // TODO: use ASSERT_EQ, once transition to pw_unit_test is complete + VerifyOrDieWithMsg((err = mEventCounter.Init(0)) == CHIP_NO_ERROR, AppServer, + "Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format()); chip::app::EventManagement::CreateEventManagement(&GetExchangeManager(), ArraySize(logStorageResources), gCircularEventBuffer, logStorageResources, &mEventCounter); - - exit: - return err; } // Performs teardown for each individual test in the test suite diff --git a/src/messaging/tests/MessagingContext.h b/src/messaging/tests/MessagingContext.h index 7ae452b9678a90..9ed82de60e4d5d 100644 --- a/src/messaging/tests/MessagingContext.h +++ b/src/messaging/tests/MessagingContext.h @@ -212,15 +212,14 @@ class LoopbackMessagingContext : public LoopbackTransportManager, public Messagi virtual ~LoopbackMessagingContext() {} // Performs shared setup for all tests in the test suite - virtual CHIP_ERROR SetUpTestSuite() + virtual void SetUpTestSuite() { CHIP_ERROR err = CHIP_NO_ERROR; - VerifyOrExit((err = chip::Platform::MemoryInit()) == CHIP_NO_ERROR, - ChipLogError(AppServer, "Init CHIP memory failed: %" CHIP_ERROR_FORMAT, err.Format())); - VerifyOrExit((err = LoopbackTransportManager::Init()) == CHIP_NO_ERROR, - ChipLogError(AppServer, "Init LoopbackTransportManager failed: %" CHIP_ERROR_FORMAT, err.Format())); - exit: - return err; + // TODO: use ASSERT_EQ, once transition to pw_unit_test is complete + VerifyOrDieWithMsg((err = chip::Platform::MemoryInit()) == CHIP_NO_ERROR, AppServer, + "Init CHIP memory failed: %" CHIP_ERROR_FORMAT, err.Format()); + VerifyOrDieWithMsg((err = LoopbackTransportManager::Init()) == CHIP_NO_ERROR, AppServer, + "Init LoopbackTransportManager failed: %" CHIP_ERROR_FORMAT, err.Format()); } // Performs shared teardown for all tests in the test suite @@ -231,13 +230,11 @@ class LoopbackMessagingContext : public LoopbackTransportManager, public Messagi } // Performs setup for each individual test in the test suite - virtual CHIP_ERROR SetUp() + virtual void SetUp() { CHIP_ERROR err = CHIP_NO_ERROR; - VerifyOrExit((err = MessagingContext::Init(&GetTransportMgr(), &GetIOContext())) == CHIP_NO_ERROR, - ChipLogError(AppServer, "Init MessagingContext failed: %" CHIP_ERROR_FORMAT, err.Format())); - exit: - return err; + VerifyOrDieWithMsg((err = MessagingContext::Init(&GetTransportMgr(), &GetIOContext())) == CHIP_NO_ERROR, AppServer, + "Init MessagingContext failed: %" CHIP_ERROR_FORMAT, err.Format()); } // Performs teardown for each individual test in the test suite @@ -247,8 +244,8 @@ class LoopbackMessagingContext : public LoopbackTransportManager, public Messagi static int nlTestSetUpTestSuite(void * context) { - auto err = static_cast(context)->SetUpTestSuite(); - return err == CHIP_NO_ERROR ? SUCCESS : FAILURE; + static_cast(context)->SetUpTestSuite(); + return SUCCESS; } static int nlTestTearDownTestSuite(void * context) @@ -259,8 +256,8 @@ class LoopbackMessagingContext : public LoopbackTransportManager, public Messagi static int nlTestSetUp(void * context) { - auto err = static_cast(context)->SetUp(); - return err == CHIP_NO_ERROR ? SUCCESS : FAILURE; + static_cast(context)->SetUp(); + return SUCCESS; } static int nlTestTearDown(void * context) diff --git a/src/messaging/tests/TestAbortExchangesForFabric.cpp b/src/messaging/tests/TestAbortExchangesForFabric.cpp index 6dc5d8c2775cd3..5993a771e76bd4 100644 --- a/src/messaging/tests/TestAbortExchangesForFabric.cpp +++ b/src/messaging/tests/TestAbortExchangesForFabric.cpp @@ -51,13 +51,13 @@ using namespace chip::Protocols; struct TestContext : Test::LoopbackMessagingContext { - virtual CHIP_ERROR SetUp() + void SetUp() override { #if CHIP_CRYPTO_PSA - ReturnErrorOnFailure(psa_crypto_init() == PSA_SUCCESS ? CHIP_NO_ERROR : CHIP_ERROR_INTERNAL); + // TODO: use ASSERT_EQ, once transition to pw_unit_test is complete + VerifyOrDie(psa_crypto_init() == PSA_SUCCESS); #endif - ReturnErrorOnFailure(chip::Test::LoopbackMessagingContext::SetUp()); - return CHIP_NO_ERROR; + chip::Test::LoopbackMessagingContext::SetUp(); } }; diff --git a/src/messaging/tests/TestExchangeMgr.cpp b/src/messaging/tests/TestExchangeMgr.cpp index f85bebe455259e..cc4dbf10e5a4f4 100644 --- a/src/messaging/tests/TestExchangeMgr.cpp +++ b/src/messaging/tests/TestExchangeMgr.cpp @@ -55,13 +55,13 @@ struct TestContext : Test::LoopbackMessagingContext { // TODO Add TearDown function during changing test framework to Pigweed to make it more clear how does it work. // Currently, the TearDown function is from LoopbackMessagingContext - virtual CHIP_ERROR SetUp() + void SetUp() override { #if CHIP_CRYPTO_PSA - ReturnErrorOnFailure(psa_crypto_init() == PSA_SUCCESS ? CHIP_NO_ERROR : CHIP_ERROR_INTERNAL); + // TODO: use ASSERT_EQ, once transition to pw_unit_test is complete + VerifyOrDie(psa_crypto_init() == PSA_SUCCESS); #endif - ReturnErrorOnFailure(chip::Test::LoopbackMessagingContext::SetUp()); - return CHIP_NO_ERROR; + chip::Test::LoopbackMessagingContext::SetUp(); } }; diff --git a/src/messaging/tests/TestReliableMessageProtocol.cpp b/src/messaging/tests/TestReliableMessageProtocol.cpp index 4636193bb06378..dc70e013a55bc5 100644 --- a/src/messaging/tests/TestReliableMessageProtocol.cpp +++ b/src/messaging/tests/TestReliableMessageProtocol.cpp @@ -77,15 +77,15 @@ class TestContext : public chip::Test::LoopbackMessagingContext { public: // Performs setup for each individual test in the test suite - CHIP_ERROR SetUp() override + void SetUp() override { #if CHIP_CRYPTO_PSA - ReturnErrorOnFailure(psa_crypto_init() == PSA_SUCCESS ? CHIP_NO_ERROR : CHIP_ERROR_INTERNAL); + // TODO: use ASSERT_EQ, once transition to pw_unit_test is complete + VerifyOrDie(psa_crypto_init() == PSA_SUCCESS); #endif - ReturnErrorOnFailure(chip::Test::LoopbackMessagingContext::SetUp()); + chip::Test::LoopbackMessagingContext::SetUp(); GetSessionAliceToBob()->AsSecureSession()->SetRemoteSessionParameters(GetLocalMRPConfig().ValueOr(GetDefaultMRPConfig())); GetSessionBobToAlice()->AsSecureSession()->SetRemoteSessionParameters(GetLocalMRPConfig().ValueOr(GetDefaultMRPConfig())); - return CHIP_NO_ERROR; } }; diff --git a/src/protocols/secure_channel/tests/TestCASESession.cpp b/src/protocols/secure_channel/tests/TestCASESession.cpp index df4a2edf05ea29..1ef821f30c8b50 100644 --- a/src/protocols/secure_channel/tests/TestCASESession.cpp +++ b/src/protocols/secure_channel/tests/TestCASESession.cpp @@ -61,7 +61,7 @@ class TestContext : public Test::LoopbackMessagingContext { public: // Performs shared setup for all tests in the test suite - CHIP_ERROR SetUpTestSuite() override; + void SetUpTestSuite() override; // Performs shared teardown for all tests in the test suite void TearDownTestSuite() override; }; @@ -327,22 +327,20 @@ CHIP_ERROR InitCredentialSets() return CHIP_NO_ERROR; } -CHIP_ERROR TestContext::SetUpTestSuite() +void TestContext::SetUpTestSuite() { ConfigInitializeNodes(false); CHIP_ERROR err = CHIP_NO_ERROR; - VerifyOrExit((err = LoopbackMessagingContext::SetUpTestSuite()) == CHIP_NO_ERROR, - ChipLogError(AppServer, "SetUpTestSuite lo messaging context failed: %" CHIP_ERROR_FORMAT, err.Format())); - VerifyOrExit((err = chip::DeviceLayer::PlatformMgr().InitChipStack()) == CHIP_NO_ERROR, - ChipLogError(AppServer, "Init CHIP stack failed: %" CHIP_ERROR_FORMAT, err.Format())); - VerifyOrExit((err = InitFabricTable(gCommissionerFabrics, &gCommissionerStorageDelegate, /* opKeyStore = */ nullptr, - &gCommissionerOpCertStore)) == CHIP_NO_ERROR, - ChipLogError(AppServer, "InitFabricTable failed: %" CHIP_ERROR_FORMAT, err.Format())); - VerifyOrExit((err = InitCredentialSets()) == CHIP_NO_ERROR, - ChipLogError(AppServer, "InitCredentialSets failed: %" CHIP_ERROR_FORMAT, err.Format())); + LoopbackMessagingContext::SetUpTestSuite(); + // TODO: use ASSERT_EQ, once transition to pw_unit_test is complete + VerifyOrDieWithMsg((err = chip::DeviceLayer::PlatformMgr().InitChipStack()) == CHIP_NO_ERROR, AppServer, + "Init CHIP stack failed: %" CHIP_ERROR_FORMAT, err.Format()); + VerifyOrDieWithMsg((err = InitFabricTable(gCommissionerFabrics, &gCommissionerStorageDelegate, /* opKeyStore = */ nullptr, + &gCommissionerOpCertStore)) == CHIP_NO_ERROR, + AppServer, "InitFabricTable failed: %" CHIP_ERROR_FORMAT, err.Format()); + VerifyOrDieWithMsg((err = InitCredentialSets()) == CHIP_NO_ERROR, AppServer, "InitCredentialSets failed: %" CHIP_ERROR_FORMAT, + err.Format()); chip::DeviceLayer::SetSystemLayerForTesting(&GetSystemLayer()); -exit: - return err; } void TestContext::TearDownTestSuite() diff --git a/src/protocols/secure_channel/tests/TestPASESession.cpp b/src/protocols/secure_channel/tests/TestPASESession.cpp index 073a2afb6ae651..b25252f15b7385 100644 --- a/src/protocols/secure_channel/tests/TestPASESession.cpp +++ b/src/protocols/secure_channel/tests/TestPASESession.cpp @@ -89,10 +89,10 @@ class TestContext : public chip::Test::LoopbackMessagingContext { public: // Performs shared setup for all tests in the test suite - CHIP_ERROR SetUpTestSuite() override + void SetUpTestSuite() override { ConfigInitializeNodes(false); - return chip::Test::LoopbackMessagingContext::SetUpTestSuite(); + chip::Test::LoopbackMessagingContext::SetUpTestSuite(); } };