Skip to content

Commit

Permalink
Adding RunEventLoop to testcases in TestCommissioningWindowManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Alami-Amine committed Jun 10, 2024
1 parent 453ea0c commit bcc0c4e
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions src/app/tests/TestCommissioningWindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ void TearDownTask(intptr_t context)
chip::Server::GetInstance().Shutdown();
}

static void StopEventLoop(intptr_t context)
{
chip::DeviceLayer::PlatformMgr().StopEventLoopTask();
}

class TestCommissioningWindowManager : public ::testing::Test
{
public:
Expand All @@ -117,16 +122,17 @@ class TestCommissioningWindowManager : public ::testing::Test
ASSERT_EQ(chip::Server::GetInstance().Init(initParams), CHIP_NO_ERROR);

Server::GetInstance().GetCommissioningWindowManager().CloseCommissioningWindow();
chip::DeviceLayer::PlatformMgr().StartEventLoopTask();
}
static void TearDownTestSuite()
{

// TODO: The platform memory was intentionally left not deinitialized so that minimal mdns can destruct
chip::DeviceLayer::PlatformMgr().ScheduleWork(TearDownTask, 0);
sleep(kTestTaskWaitSeconds);
chip::DeviceLayer::PlatformMgr().ScheduleWork(StopEventLoop);

chip::DeviceLayer::PlatformMgr().RunEventLoop();

chip::DeviceLayer::PlatformMgr().StopEventLoopTask();
// chip::DeviceLayer::PlatformMgr().StopEventLoopTask();
chip::DeviceLayer::PlatformMgr().Shutdown();

auto & mdnsAdvertiser = chip::Dnssd::ServiceAdvertiser::Instance();
Expand Down Expand Up @@ -175,8 +181,15 @@ void CheckCommissioningWindowManagerBasicWindowOpenCloseTask(intptr_t context)

TEST_F(TestCommissioningWindowManager, TestCheckCommissioningWindowManagerBasicWindowOpenClose)
{

// chip::DeviceLayer::PlatformMgr().ScheduleWork([](intptr_t) {
// CheckCommissioningWindowManagerBasicWindowOpenCloseTask;
// StopEventLoop;
// });

chip::DeviceLayer::PlatformMgr().ScheduleWork(CheckCommissioningWindowManagerBasicWindowOpenCloseTask);
sleep(kTestTaskWaitSeconds);
chip::DeviceLayer::PlatformMgr().ScheduleWork(StopEventLoop);
chip::DeviceLayer::PlatformMgr().RunEventLoop();
}

void CheckCommissioningWindowManagerBasicWindowOpenCloseFromClusterTask(intptr_t context)
Expand Down Expand Up @@ -222,7 +235,10 @@ void CheckCommissioningWindowManagerBasicWindowOpenCloseFromClusterTask(intptr_t
TEST_F(TestCommissioningWindowManager, TestCheckCommissioningWindowManagerBasicWindowOpenCloseFromCluster)
{
chip::DeviceLayer::PlatformMgr().ScheduleWork(CheckCommissioningWindowManagerBasicWindowOpenCloseFromClusterTask);
sleep(kTestTaskWaitSeconds);
chip::DeviceLayer::PlatformMgr().ScheduleWork(StopEventLoop);
chip::DeviceLayer::PlatformMgr().RunEventLoop();

// sleep(kTestTaskWaitSeconds);
}

void CheckCommissioningWindowManagerWindowClosedTask(chip::System::Layer *, void *)
Expand Down Expand Up @@ -265,7 +281,10 @@ void CheckCommissioningWindowManagerWindowTimeoutTask(intptr_t context)
TEST_F(TestCommissioningWindowManager, TestCheckCommissioningWindowManagerWindowTimeout)
{
chip::DeviceLayer::PlatformMgr().ScheduleWork(CheckCommissioningWindowManagerWindowTimeoutTask);
sleep(kTestTaskWaitSeconds);
chip::DeviceLayer::PlatformMgr().ScheduleWork(StopEventLoop);
chip::DeviceLayer::PlatformMgr().RunEventLoop();

// sleep(kTestTaskWaitSeconds);
}

void SimulateFailedSessionEstablishmentTask(chip::System::Layer *, void *)
Expand Down Expand Up @@ -319,6 +338,9 @@ void CheckCommissioningWindowManagerWindowTimeoutWithSessionEstablishmentErrorsT
TEST_F(TestCommissioningWindowManager, CheckCommissioningWindowManagerWindowTimeoutWithSessionEstablishmentErrors)
{
chip::DeviceLayer::PlatformMgr().ScheduleWork(CheckCommissioningWindowManagerWindowTimeoutWithSessionEstablishmentErrorsTask);
chip::DeviceLayer::PlatformMgr().ScheduleWork(StopEventLoop);
chip::DeviceLayer::PlatformMgr().RunEventLoop();

sleep(kTestTaskWaitSeconds);
}

Expand Down Expand Up @@ -376,7 +398,11 @@ void CheckCommissioningWindowManagerEnhancedWindowTask(intptr_t context)
TEST_F(TestCommissioningWindowManager, TestCheckCommissioningWindowManagerEnhancedWindow)
{
chip::DeviceLayer::PlatformMgr().ScheduleWork(CheckCommissioningWindowManagerEnhancedWindowTask);
sleep(kTestTaskWaitSeconds);

chip::DeviceLayer::PlatformMgr().ScheduleWork(StopEventLoop);
chip::DeviceLayer::PlatformMgr().RunEventLoop();

// sleep(kTestTaskWaitSeconds);
}

} // namespace

0 comments on commit bcc0c4e

Please sign in to comment.