From 236997298d5717d6797af35665d46a5d195c15c3 Mon Sep 17 00:00:00 2001 From: Jakub Latusek Date: Fri, 24 May 2024 11:53:50 +0200 Subject: [PATCH] Break the dependency between tests that use MessagingContext (#33588) * Fix dependency between tests * Restyled by clang-format --------- Co-authored-by: Restyled.io --- src/messaging/tests/MessagingContext.cpp | 4 +--- src/messaging/tests/MessagingContext.h | 4 ++-- src/protocols/secure_channel/tests/TestCASESession.cpp | 8 +++++++- src/protocols/secure_channel/tests/TestPASESession.cpp | 9 +++++++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/messaging/tests/MessagingContext.cpp b/src/messaging/tests/MessagingContext.cpp index 61565da1cd4ac0..909bc90f443575 100644 --- a/src/messaging/tests/MessagingContext.cpp +++ b/src/messaging/tests/MessagingContext.cpp @@ -58,7 +58,7 @@ CHIP_ERROR MessagingContext::Init(TransportMgrBase * transport, IOContext * ioCo ReturnErrorOnFailure(mExchangeManager.Init(&mSessionManager)); ReturnErrorOnFailure(mMessageCounterManager.Init(&mExchangeManager)); - if (sInitializeNodes) + if (mInitializeNodes) { ReturnErrorOnFailure(CreateAliceFabric()); ReturnErrorOnFailure(CreateBobFabric()); @@ -112,8 +112,6 @@ using namespace System::Clock::Literals; constexpr chip::System::Clock::Timeout MessagingContext::kResponsiveIdleRetransTimeout; constexpr chip::System::Clock::Timeout MessagingContext::kResponsiveActiveRetransTimeout; -bool MessagingContext::sInitializeNodes = true; - void MessagingContext::SetMRPMode(MRPMode mode) { if (mode == MRPMode::kDefault) diff --git a/src/messaging/tests/MessagingContext.h b/src/messaging/tests/MessagingContext.h index bd9b0b981926e6..51525f967d1475 100644 --- a/src/messaging/tests/MessagingContext.h +++ b/src/messaging/tests/MessagingContext.h @@ -101,7 +101,7 @@ class MessagingContext : public PlatformMemoryUser ~MessagingContext() { VerifyOrDie(mInitialized == false); } // Whether Alice and Bob are initialized, must be called before Init - static void ConfigInitializeNodes(bool initializeNodes) { sInitializeNodes = initializeNodes; } + void ConfigInitializeNodes(bool initializeNodes) { mInitializeNodes = initializeNodes; } /// Initialize the underlying layers and test suite pointer CHIP_ERROR Init(TransportMgrBase * transport, IOContext * io); @@ -178,7 +178,7 @@ class MessagingContext : public PlatformMemoryUser System::Layer & GetSystemLayer() { return mIOContext->GetSystemLayer(); } private: - static bool sInitializeNodes; + bool mInitializeNodes = true; bool mInitialized; FabricTable mFabricTable; diff --git a/src/protocols/secure_channel/tests/TestCASESession.cpp b/src/protocols/secure_channel/tests/TestCASESession.cpp index 5fc6a37f72f4ab..68d6ddd177eeb8 100644 --- a/src/protocols/secure_channel/tests/TestCASESession.cpp +++ b/src/protocols/secure_channel/tests/TestCASESession.cpp @@ -64,6 +64,13 @@ class TestContext : public Test::LoopbackMessagingContext static void SetUpTestSuite(); // Performs shared teardown for all tests in the test suite static void TearDownTestSuite(); + + virtual void SetUp() override + { + ConfigInitializeNodes(false); + chip::Test::LoopbackMessagingContext::SetUp(); + } + virtual void TearDown() override { chip::Test::LoopbackMessagingContext::TearDown(); } }; void ServiceEvents(TestContext & ctx) @@ -329,7 +336,6 @@ CHIP_ERROR InitCredentialSets() void TestContext::SetUpTestSuite() { - ConfigInitializeNodes(false); CHIP_ERROR err = CHIP_NO_ERROR; LoopbackMessagingContext::SetUpTestSuite(); // TODO: use ASSERT_EQ, once transition to pw_unit_test is complete diff --git a/src/protocols/secure_channel/tests/TestPASESession.cpp b/src/protocols/secure_channel/tests/TestPASESession.cpp index d610b304cec481..896f721579334d 100644 --- a/src/protocols/secure_channel/tests/TestPASESession.cpp +++ b/src/protocols/secure_channel/tests/TestPASESession.cpp @@ -89,11 +89,16 @@ class TestContext : public chip::Test::LoopbackMessagingContext { public: // Performs shared setup for all tests in the test suite - static void SetUpTestSuite() + static void SetUpTestSuite() { chip::Test::LoopbackMessagingContext::SetUpTestSuite(); } + static void TearDownTestSuite() { chip::Test::LoopbackMessagingContext::TearDownTestSuite(); } + + void SetUp() override { ConfigInitializeNodes(false); - chip::Test::LoopbackMessagingContext::SetUpTestSuite(); + chip::Test::LoopbackMessagingContext::SetUp(); } + + void TearDown() override { chip::Test::LoopbackMessagingContext::TearDown(); } }; class PASETestLoopbackTransportDelegate : public Test::LoopbackTransportDelegate