Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[controller] reset Device state for usage in accessories #9386

Merged
merged 2 commits into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/controller/CHIPDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ void Device::OperationalCertProvisioned()

Persist();
CloseSession();
mState = ConnectionState::NotConnected;
}

CHIP_ERROR Device::WarmupCASESession()
Expand Down
8 changes: 8 additions & 0 deletions src/controller/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@ chip_test_suite("tests") {

test_sources = [ "TestCommissionableNodeController.cpp" ]

if (chip_device_platform == "linux" || chip_device_platform == "Darwin") {
test_sources += [ "TestDevice.cpp" ]
}

cflags = [ "-Wconversion" ]

public_deps = [
"${chip_root}/src/controller",
"${nlunit_test_root}:nlunit-test",
]

if (chip_device_platform == "linux" || chip_device_platform == "Darwin") {
public_deps += [ "${chip_root}/src/controller/data_model" ]
}
}
109 changes: 109 additions & 0 deletions src/controller/tests/TestDevice.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
*
* Copyright (c) 2021 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <ble/BleLayer.h>
#include <controller/CHIPDevice.h>
#include <inet/IPAddress.h>
#include <inet/InetLayer.h>
#include <lib/support/CHIPMem.h>
#include <lib/support/UnitTestRegistration.h>
#include <nlunit-test.h>
#include <protocols/secure_channel/MessageCounterManager.h>
#include <protocols/secure_channel/SessionIDAllocator.h>
#include <transport/SecureSessionMgr.h>
#include <transport/TransportMgr.h>
#include <transport/raw/PeerAddress.h>
#include <transport/raw/UDP.h>

using namespace chip;
using namespace chip::Transport;
using namespace chip::Controller;
using namespace chip::Messaging;

namespace {

using TestTransportMgr = TransportMgr<Transport::UDP>;

void TestDevice_EstablishSessionDirectly(nlTestSuite * inSuite, void * inContext)
{
Platform::MemoryInit();
DeviceTransportMgr transportMgr;
SecureSessionMgr sessionMgr;
ExchangeManager exchangeMgr;
Inet::InetLayer inetLayer;
System::Layer systemLayer;
Ble::BleLayer blelayer;
FabricTable fabrics;
secure_channel::MessageCounterManager messageCounterManager;
SessionIDAllocator idAllocator;

systemLayer.Init();
inetLayer.Init(systemLayer, nullptr);
transportMgr.Init(
UdpListenParameters(&inetLayer).SetAddressType(Inet::IPAddressType::kIPAddressType_IPv4).SetListenPort(CHIP_PORT)
#if INET_CONFIG_ENABLE_IPV4
,
UdpListenParameters(&inetLayer).SetAddressType(Inet::kIPAddressType_IPv4).SetListenPort(CHIP_PORT)
#endif
#if CONFIG_NETWORK_LAYER_BLE
,
BleListenParameters(&blelayer)
#endif
);
sessionMgr.Init(&systemLayer, &transportMgr, &fabrics, &messageCounterManager);
exchangeMgr.Init(&sessionMgr);
messageCounterManager.Init(&exchangeMgr);

ControllerDeviceInitParams params = {
.transportMgr = &transportMgr,
.sessionMgr = &sessionMgr,
.exchangeMgr = &exchangeMgr,
.inetLayer = &inetLayer,
.storageDelegate = nullptr,
.idAllocator = &idAllocator,
.fabricsTable = &fabrics,
};
Device device;
NodeId mockNodeId = 1;
FabricIndex mockFabricIndex = 1;
Inet::IPAddress mockAddr;
Inet::IPAddress::FromString("127.0.0.1", mockAddr);
PeerAddress addr = PeerAddress::UDP(mockAddr, CHIP_PORT);
device.Init(params, CHIP_PORT, mockNodeId, addr, mockFabricIndex);

device.OperationalCertProvisioned();
NL_TEST_ASSERT(inSuite, device.EstablishConnectivity(nullptr, nullptr) == CHIP_NO_ERROR);
}

// clang-format off
const nlTest sTests[] =
{
NL_TEST_DEF("TestDevice_EstablishSessionDirectly", TestDevice_EstablishSessionDirectly),
NL_TEST_SENTINEL()
};
// clang-format on

} // namespace

int TestDevice()
{
nlTestSuite theSuite = { "Device", &sTests[0], NULL, NULL };
nlTestRunner(&theSuite, nullptr);
return nlTestRunnerStats(&theSuite);
}

CHIP_REGISTER_TEST_SUITE(TestDevice)