Skip to content

Commit

Permalink
Fixed SystemTimer.h
Browse files Browse the repository at this point in the history
  • Loading branch information
mbknust committed Sep 21, 2023
1 parent 5a9b657 commit 120cfb1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
4 changes: 0 additions & 4 deletions src/app/InteractionModelEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <app/AppBuildConfig.h>
#include <app/MessageDef/AttributeReportIBs.h>
#include <app/MessageDef/ReportDataMessage.h>
#include <gtest/gtest.h>
#include <lib/core/CHIPCore.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/DLLUtil.h>
Expand Down Expand Up @@ -378,9 +377,6 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
friend class reporting::Engine;
friend class TestCommandInteraction;
friend class TestInteractionModelEngine;
FRIEND_TEST(TestInteractionModelEngine, TestAttributePathParamsPushRelease);
FRIEND_TEST(TestInteractionModelEngine, TestRemoveDuplicateConcreteAttribute);
FRIEND_TEST(TestInteractionModelEngine, TestSubscriptionResumptionTimer);
using Status = Protocols::InteractionModel::Status;

void OnDone(CommandHandler & apCommandObj) override;
Expand Down
17 changes: 13 additions & 4 deletions src/app/tests/TestInteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ namespace app {
class TestInteractionModelEngine : public ::testing::Test
{
public:
static int GetAttributePathListLength(ObjectList<AttributePathParams> * apattributePathParamsList);
static void SetUpTestSuite() { TestContext::Initialize(&ctx); }
static void TearDownTestSuite() { TestContext::Finalize(&ctx); }
static TestContext ctx;

static void TestAttributePathParamsPushRelease();
static void TestRemoveDuplicateConcreteAttribute();
static void TestSubscriptionResumptionTimer();

static int GetAttributePathListLength(ObjectList<AttributePathParams> * apattributePathParamsList);
};

TestContext TestInteractionModelEngine::ctx;
Expand All @@ -67,7 +72,11 @@ int TestInteractionModelEngine::GetAttributePathListLength(ObjectList<AttributeP
return length;
}

TEST_F(TestInteractionModelEngine, TestAttributePathParamsPushRelease)
#define STATIC_TEST(test_fixture, test_name) \
TEST_F(test_fixture, test_name) { test_fixture::test_name(); } \
void test_fixture::test_name()

STATIC_TEST(TestInteractionModelEngine, TestAttributePathParamsPushRelease)
{
CHIP_ERROR err = CHIP_NO_ERROR;
err = InteractionModelEngine::GetInstance()->Init(&ctx.GetExchangeManager(), &ctx.GetFabricTable(),
Expand Down Expand Up @@ -101,7 +110,7 @@ TEST_F(TestInteractionModelEngine, TestAttributePathParamsPushRelease)
EXPECT_TRUE(GetAttributePathListLength(attributePathParamsList) == 0);
}

TEST_F(TestInteractionModelEngine, TestRemoveDuplicateConcreteAttribute)
STATIC_TEST(TestInteractionModelEngine, TestRemoveDuplicateConcreteAttribute)
{
CHIP_ERROR err = CHIP_NO_ERROR;
err = InteractionModelEngine::GetInstance()->Init(&ctx.GetExchangeManager(), &ctx.GetFabricTable(),
Expand Down Expand Up @@ -225,7 +234,7 @@ TEST_F(TestInteractionModelEngine, TestRemoveDuplicateConcreteAttribute)
}

#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
TEST_F(TestInteractionModelEngine, TestSubscriptionResumptionTimer)
STATIC_TEST(TestInteractionModelEngine, TestSubscriptionResumptionTimer)
{
CHIP_ERROR err = CHIP_NO_ERROR;
err = InteractionModelEngine::GetInstance()->Init(&ctx.GetExchangeManager(), &ctx.GetFabricTable(),
Expand Down
7 changes: 2 additions & 5 deletions src/system/SystemTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
#include <system/SystemLayer.h>
#include <system/SystemStats.h>

#include <gtest/gtest.h>

#if CHIP_SYSTEM_CONFIG_USE_DISPATCH
#include <dispatch/dispatch.h>
#endif
Expand All @@ -46,7 +44,7 @@ namespace chip {
namespace System {

class Layer;
class TestTimer;
class TestSystemTimer;

/**
* Basic Timer information: time and callback.
Expand Down Expand Up @@ -239,9 +237,8 @@ class TimerPool
callback.Invoke();
}

FRIEND_TEST(TestSystemTimer, CheckTimerPool);

private:
friend class TestSystemTimer;
ObjectPool<Timer, CHIP_SYSTEM_CONFIG_NUM_TIMERS> mTimerPool;
};

Expand Down
27 changes: 13 additions & 14 deletions src/system/tests/TestSystemTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
using chip::ErrorStr;
using namespace chip::System;

namespace chip {
namespace System {

template <class LayerImpl, typename Enable = void>
class LayerEvents
{
Expand Down Expand Up @@ -136,10 +139,16 @@ class TestSystemTimer : public ::testing::Test
static void SetUpTestSuite() { TestSetup(&ctx); }
static void TearDownTestSuite() { TestTeardown(&ctx); }
static TestContext ctx;

static void CheckTimerPool();
};

TestContext TestSystemTimer::ctx;

#define STATIC_TEST(test_fixture, test_name) \
TEST_F(test_fixture, test_name) { test_fixture::test_name(); } \
void test_fixture::test_name()

class ScopedGlobalTestContext
{
public:
Expand Down Expand Up @@ -335,10 +344,6 @@ TEST_F(TestSystemTimer, CheckCancellation)
Clock::Internal::SetSystemClockForTesting(savedClock);
}

namespace {

namespace CancelTimerTest {

// A bit lower than maximum system timers just in case, for systems that
// have some form of limit
constexpr unsigned kCancelTimerCount = CHIP_SYSTEM_CONFIG_NUM_TIMERS - 4;
Expand Down Expand Up @@ -433,14 +438,8 @@ TEST_F(TestSystemTimer, Test)
Clock::Internal::SetSystemClockForTesting(savedClock);
}

} // namespace CancelTimerTest
} // namespace

// Test the implementation helper classes TimerPool, TimerList, and TimerData.
namespace chip {
namespace System {

TEST_F(TestSystemTimer, CheckTimerPool)
STATIC_TEST(TestSystemTimer, CheckTimerPool)
{
TestContext & testContext = TestSystemTimer::ctx;
Layer & systemLayer = *testContext.mLayer;
Expand Down Expand Up @@ -576,9 +575,6 @@ TEST_F(TestSystemTimer, CheckTimerPool)
EXPECT_TRUE(SYSTEM_STATS_TEST_HIGH_WATER_MARK(Stats::kSystemLayer_NumTimers, 4));
}

} // namespace System
} // namespace chip

TEST_F(TestSystemTimer, ExtendTimerToTest)
{
if (!LayerEvents<LayerImpl>::HasServiceEvents())
Expand Down Expand Up @@ -754,3 +750,6 @@ static int TestTeardown(void * aContext)
::chip::Platform::MemoryShutdown();
return (SUCCESS);
}

} // namespace System
} // namespace chip

0 comments on commit 120cfb1

Please sign in to comment.