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.
18 /* TIZEN_CHIP_MODIFY */
21 #include <dbus/dbus.h>
24 #include <support/CHIPMem.h>
25 #include <support/UnitTestRegistration.h>
27 #include "platform/internal/CHIPDeviceLayerInternal.h"
29 #include "platform/PlatformManager.h"
30 #include "platform/ThreadStackManager.h"
32 #if CHIP_DEVICE_LAYER_TARGET == LINUX || CHIP_DEVICE_LAYER_TARGET == TIZEN
35 struct DBusConnectionDeleter
37 void operator()(DBusConnection * aConnection) { dbus_connection_unref(aConnection); }
40 using UniqueDBusConnection = std::unique_ptr<DBusConnection, DBusConnectionDeleter>;
43 void EventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg)
46 if (event->Type == chip::DeviceLayer::DeviceEventType::kThreadConnectivityChange)
48 if (event->ThreadConnectivityChange.Result == chip::DeviceLayer::ConnectivityChange::kConnectivity_Established)
55 int TestThreadStackManager()
57 chip::DeviceLayer::ThreadStackManagerImpl impl;
58 chip::DeviceLayer::Internal::DeviceNetworkInfo info;
59 uint16_t masterKey[16] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
61 strncpy(info.ThreadNetworkName, "CHIP-TEST", sizeof(info.ThreadNetworkName));
62 info.ThreadChannel = UINT8_MAX;
63 info.ThreadPANId = 0x3455;
64 info.FieldPresent.ThreadExtendedPANId = false;
65 info.FieldPresent.ThreadMeshPrefix = false;
66 info.FieldPresent.ThreadPSKc = false;
67 memcpy(&info.ThreadMasterKey, &masterKey, sizeof(masterKey));
69 chip::Platform::MemoryInit();
70 chip::DeviceLayer::PlatformMgrImpl().InitChipStack();
71 chip::DeviceLayer::PlatformMgrImpl().AddEventHandler(EventHandler, 0);
73 impl.InitThreadStack();
74 impl.StartThreadTask();
75 impl._SetThreadProvision(info);
76 impl._SetThreadEnabled(true);
78 printf("Start Thread task done\n");
80 chip::DeviceLayer::PlatformMgrImpl().RunEventLoop();
85 CHIP_REGISTER_TEST_SUITE(TestThreadStackManager);