3 * Copyright (c) 2020 Project CHIP Authors
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 * This file implements a unit test suite for the Platform Manager
31 #include <nlunit-test.h>
32 #include <support/CHIPMem.h>
33 #include <support/CodeUtils.h>
34 #include <support/UnitTestRegistration.h>
36 #include <platform/CHIPDeviceLayer.h>
39 using namespace chip::Logging;
40 using namespace chip::Inet;
41 using namespace chip::DeviceLayer;
43 // =================================
45 // =================================
47 static void TestPlatformMgr_Init(nlTestSuite * inSuite, void * inContext)
49 CHIP_ERROR err = PlatformMgr().InitChipStack();
50 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
53 static void TestPlatformMgr_StartEventLoopTask(nlTestSuite * inSuite, void * inContext)
55 CHIP_ERROR err = PlatformMgr().StartEventLoopTask();
56 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
59 static void TestPlatformMgr_TryLockChipStack(nlTestSuite * inSuite, void * inContext)
61 bool locked = PlatformMgr().TryLockChipStack();
63 PlatformMgr().UnlockChipStack();
66 static int sEventRecieved = 0;
68 void DeviceEventHandler(const ChipDeviceEvent * event, intptr_t arg)
70 // NL_TEST_ASSERT(inSuite, arg == 12345);
74 static void TestPlatformMgr_AddEventHandler(nlTestSuite * inSuite, void * inContext)
78 error = PlatformMgr().AddEventHandler(DeviceEventHandler, 12345);
79 NL_TEST_ASSERT(inSuite, error == CHIP_NO_ERROR);
82 while (sEventRecieved == 0)
86 NL_TEST_ASSERT(inSuite, sEventRecieved > 0);
91 * Test Suite. It lists all the test functions.
93 static const nlTest sTests[] = {
95 NL_TEST_DEF("Test PlatformMgr::Init", TestPlatformMgr_Init),
96 NL_TEST_DEF("Test PlatformMgr::StartEventLoopTask", TestPlatformMgr_StartEventLoopTask),
97 NL_TEST_DEF("Test PlatformMgr::TryLockChipStack", TestPlatformMgr_TryLockChipStack),
98 NL_TEST_DEF("Test PlatformMgr::AddEventHandler", TestPlatformMgr_AddEventHandler),
104 * Set up the test suite.
106 int TestPlatformMgr_Setup(void * inContext)
108 CHIP_ERROR error = chip::Platform::MemoryInit();
109 if (error != CHIP_NO_ERROR)
115 * Tear down the test suite.
117 int TestPlatformMgr_Teardown(void * inContext)
119 chip::Platform::MemoryShutdown();
123 int TestPlatformMgr()
125 nlTestSuite theSuite = { "PlatformMgr tests", &sTests[0], TestPlatformMgr_Setup, TestPlatformMgr_Teardown };
127 // Run test suit againt one context.
128 nlTestRunner(&theSuite, nullptr);
129 return nlTestRunnerStats(&theSuite);
132 CHIP_REGISTER_TEST_SUITE(TestPlatformMgr);