Skip to content

Commit

Permalink
Merge branch 'master' into idm-4.2-troubleshoot
Browse files Browse the repository at this point in the history
  • Loading branch information
raul-marquez-csa authored May 22, 2024
2 parents c87de26 + b5d13a7 commit 1b265c0
Show file tree
Hide file tree
Showing 26 changed files with 1,175 additions and 1,458 deletions.
1 change: 1 addition & 0 deletions .gn
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ script_executable = "python3"

default_args = {
pw_unit_test_AUTOMATIC_RUNNER = "$dir_pigweed/targets/host/run_test"
pw_unit_test_CONFIG = "//config/pw_unit_test:define_overrides"

pw_build_PIP_CONSTRAINTS = [ "//scripts/setup/constraints.txt" ]
pw_build_PIP_REQUIREMENTS = [ "//scripts/setup/requirements.build.txt" ]
Expand Down
32 changes: 32 additions & 0 deletions config/pw_unit_test/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (c) 2024 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.

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")
import("//build_overrides/pigweed.gni")

import("${chip_root}/build/chip/tests.gni")

import("$dir_pw_build/target_types.gni")
pw_source_set("define_overrides") {
public_configs = [ ":define_options" ]
}

config("define_options") {
if (chip_fake_platform && chip_link_tests) {
defines = [ "PW_UNIT_TEST_CONFIG_MEMORY_POOL_SIZE=65536" ]
} else {
defines = [ "PW_UNIT_TEST_CONFIG_MEMORY_POOL_SIZE=16384" ]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3752,7 +3752,7 @@ cluster ActivatedCarbonFilterMonitoring = 114 {
}

/** This cluster is used to configure a boolean sensor. */
provisional cluster BooleanStateConfiguration = 128 {
cluster BooleanStateConfiguration = 128 {
revision 1;

bitmap AlarmModeBitmap : bitmap8 {
Expand Down Expand Up @@ -3810,7 +3810,7 @@ provisional cluster BooleanStateConfiguration = 128 {
}

/** This cluster is used to configure a valve. */
provisional cluster ValveConfigurationAndControl = 129 {
cluster ValveConfigurationAndControl = 129 {
revision 1;

enum StatusCodeEnum : enum8 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ limitations under the License.
<field name="GeneralFault" mask="0x1"/>
</bitmap>

<cluster apiMaturity="provisional">
<cluster>
<domain>General</domain>
<name>Boolean State Configuration</name>
<code>0x0080</code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ limitations under the License.
<item name="FailureDueToFault" value="0x02"/>
</enum>

<cluster apiMaturity="provisional">
<cluster>
<domain>HVAC</domain>
<name>Valve Configuration and Control</name>
<code>0x0081</code>
Expand Down
4 changes: 2 additions & 2 deletions src/controller/data_model/controller-clusters.matter
Original file line number Diff line number Diff line change
Expand Up @@ -3988,7 +3988,7 @@ cluster ActivatedCarbonFilterMonitoring = 114 {
}

/** This cluster is used to configure a boolean sensor. */
provisional cluster BooleanStateConfiguration = 128 {
cluster BooleanStateConfiguration = 128 {
revision 1;

bitmap AlarmModeBitmap : bitmap8 {
Expand Down Expand Up @@ -4046,7 +4046,7 @@ provisional cluster BooleanStateConfiguration = 128 {
}

/** This cluster is used to configure a valve. */
provisional cluster ValveConfigurationAndControl = 129 {
cluster ValveConfigurationAndControl = 129 {
revision 1;

enum StatusCodeEnum : enum8 {
Expand Down
101 changes: 56 additions & 45 deletions src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -881,24 +881,21 @@ - (MTRDeviceController * _Nullable)maybeInitializeOTAProvider:(MTRDeviceControll

- (void)resetOperationalAdvertising
{
if (!_advertiseOperational) {
// No need to reset anything; we are not advertising the things that
// would need to get reset.
return;
}
assertChipStackLockedByCurrentThread();

std::lock_guard lock(_controllersLock);
if (_controllers.count != 0) {
// We have a running controller. That means we likely need to reset
// operational advertising for that controller.
dispatch_async(_chipWorkQueue, ^{
// StartServer() is the only API we have for resetting DNS-SD
// advertising. It sure would be nice if there were a "restart"
// that was a no-op if the DNS-SD server was not already
// running.
app::DnssdServer::Instance().StartServer();
});
// If we're not advertising, then there's no need to reset anything.
VerifyOrReturn(_advertiseOperational);

// If there are no running controllers there will be no advertisements to reset.
{
std::lock_guard lock(_controllersLock);
VerifyOrReturn(_controllers.count > 0);
}

// StartServer() is the only API we have for resetting DNS-SD advertising.
// It sure would be nice if there were a "restart" that was a no-op if the
// DNS-SD server was not already running.
app::DnssdServer::Instance().StartServer();
}

- (void)controllerShuttingDown:(MTRDeviceController *)controller
Expand Down Expand Up @@ -1165,6 +1162,45 @@ - (MTRDeviceController * _Nullable)initializeController:(MTRDeviceController *)c
error:error];
}

- (void)setMessageReliabilityProtocolIdleRetransmitMs:(nullable NSNumber *)idleRetransmitMs
activeRetransmitMs:(nullable NSNumber *)activeRetransmitMs
activeThresholdMs:(nullable NSNumber *)activeThresholdMs
additionalRetransmitDelayMs:(nullable NSNumber *)additionalRetransmitDelayMs
{
[self _assertCurrentQueueIsNotMatterQueue];
dispatch_async(_chipWorkQueue, ^{
bool resetAdvertising;
if (idleRetransmitMs == nil && activeRetransmitMs == nil && activeThresholdMs == nil && additionalRetransmitDelayMs == nil) {
Messaging::ReliableMessageMgr::SetAdditionalMRPBackoffTime(NullOptional);
resetAdvertising = ReliableMessageProtocolConfig::SetLocalMRPConfig(NullOptional);
} else {
if (additionalRetransmitDelayMs != nil) {
System::Clock::Timeout additionalBackoff(additionalRetransmitDelayMs.unsignedLongValue);
Messaging::ReliableMessageMgr::SetAdditionalMRPBackoffTime(MakeOptional(additionalBackoff));
}

// Get current MRP parameters, then override the things we were asked to
// override.
ReliableMessageProtocolConfig mrpConfig = GetLocalMRPConfig().ValueOr(GetDefaultMRPConfig());
if (idleRetransmitMs != nil) {
mrpConfig.mIdleRetransTimeout = System::Clock::Milliseconds32(idleRetransmitMs.unsignedLongValue);
}
if (activeRetransmitMs != nil) {
mrpConfig.mActiveRetransTimeout = System::Clock::Milliseconds32(activeRetransmitMs.unsignedLongValue);
}
if (activeThresholdMs != nil) {
mrpConfig.mActiveThresholdTime = System::Clock::Milliseconds32(activeThresholdMs.unsignedLongValue);
}

resetAdvertising = ReliableMessageProtocolConfig::SetLocalMRPConfig(MakeOptional(mrpConfig));
}

if (resetAdvertising) {
[self resetOperationalAdvertising];
}
});
}

- (PersistentStorageDelegate *)storageDelegate
{
return _persistentStorageDelegate;
Expand Down Expand Up @@ -1327,33 +1363,8 @@ void MTRSetMessageReliabilityParameters(NSNumber * _Nullable idleRetransmitMs,
NSNumber * _Nullable activeThresholdMs,
NSNumber * _Nullable additionalRetransmitDelayMs)
{
bool resetAdvertising = false;
if (idleRetransmitMs == nil && activeRetransmitMs == nil && activeThresholdMs == nil && additionalRetransmitDelayMs == nil) {
Messaging::ReliableMessageMgr::SetAdditionalMRPBackoffTime(NullOptional);
resetAdvertising = ReliableMessageProtocolConfig::SetLocalMRPConfig(NullOptional);
} else {
if (additionalRetransmitDelayMs != nil) {
System::Clock::Timeout additionalBackoff(additionalRetransmitDelayMs.unsignedLongValue);
Messaging::ReliableMessageMgr::SetAdditionalMRPBackoffTime(MakeOptional(additionalBackoff));
}

// Get current MRP parameters, then override the things we were asked to
// override.
ReliableMessageProtocolConfig mrpConfig = GetLocalMRPConfig().ValueOr(GetDefaultMRPConfig());
if (idleRetransmitMs != nil) {
mrpConfig.mIdleRetransTimeout = System::Clock::Milliseconds32(idleRetransmitMs.unsignedLongValue);
}
if (activeRetransmitMs != nil) {
mrpConfig.mActiveRetransTimeout = System::Clock::Milliseconds32(activeRetransmitMs.unsignedLongValue);
}
if (activeThresholdMs != nil) {
mrpConfig.mActiveThresholdTime = System::Clock::Milliseconds32(activeThresholdMs.unsignedLongValue);
}

resetAdvertising = ReliableMessageProtocolConfig::SetLocalMRPConfig(MakeOptional(mrpConfig));
}

if (resetAdvertising) {
[[MTRDeviceControllerFactory sharedInstance] resetOperationalAdvertising];
}
[MTRDeviceControllerFactory.sharedInstance setMessageReliabilityProtocolIdleRetransmitMs:idleRetransmitMs
activeRetransmitMs:activeThresholdMs
activeThresholdMs:activeThresholdMs
additionalRetransmitDelayMs:additionalRetransmitDelayMs];
}
7 changes: 7 additions & 0 deletions src/darwin/Framework/CHIPTests/MTRControllerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -1552,4 +1552,11 @@ - (void)testControllerCATs
XCTAssertFalse([factory isRunning]);
}

- (void)testSetMRPParameters
{
// Can be called before starting the factory
XCTAssertFalse(MTRDeviceControllerFactory.sharedInstance.running);
MTRSetMessageReliabilityParameters(@2000, @2000, @2000, @2000);
}

@end
16 changes: 16 additions & 0 deletions src/darwin/Framework/CHIPTests/MTRPerControllerStorageTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -2035,6 +2035,22 @@ - (void)testControllerServer
[controllerServer shutdown];
}

- (void)testSetMRPParametersWithRunningController
{
NSError * error;
__auto_type * storageDelegate = [[MTRTestPerControllerStorage alloc] initWithControllerID:[NSUUID UUID]];
MTRDeviceController * controller = [self startControllerWithRootKeys:[[MTRTestKeys alloc] init]
operationalKeys:[[MTRTestKeys alloc] init]
fabricID:@555
nodeID:@888
storage:storageDelegate
error:&error];
XCTAssertNotNil(controller);
XCTAssertTrue(controller.running);
MTRSetMessageReliabilityParameters(@2000, @2000, @2000, @2000);
[controller shutdown];
}

static NSString * const kLocalTestUserDefaultDomain = @"org.csa-iot.matter.darwintest";
static NSString * const kLocalTestUserDefaultSubscriptionPoolSizeOverrideKey = @"subscriptionPoolSizeOverride";

Expand Down
12 changes: 6 additions & 6 deletions src/lib/core/CHIPError.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class ChipError
* The result is valid only if CanEncapsulate() is true.
*/
constexpr ChipError(Range range, ValueType value) : ChipError(range, value, /*file=*/nullptr, /*line=*/0) {}
#if __cplusplus >= 202002L
#if CHIP_CONFIG_ERROR_SOURCE && __cplusplus >= 202002L
constexpr ChipError(Range range, ValueType value, const char * file, unsigned int line,
std::source_location location = std::source_location::current()) :
mError(MakeInteger(range, (value & MakeMask(0, kValueLength)))) CHIP_INITIALIZE_ERROR_SOURCE(file, line, location)
Expand All @@ -141,7 +141,7 @@ class ChipError
constexpr ChipError(Range range, ValueType value, const char * file, unsigned int line) :
mError(MakeInteger(range, (value & MakeMask(0, kValueLength)))) CHIP_INITIALIZE_ERROR_SOURCE(file, line, /*loc=*/nullptr)
{}
#endif // __cplusplus >= 202002L
#endif // CHIP_CONFIG_ERROR_SOURCE && __cplusplus >= 202002L

/**
* Construct a CHIP_ERROR for SdkPart @a part with @a code.
Expand All @@ -150,7 +150,7 @@ class ChipError
* The macro version CHIP_SDK_ERROR checks that the numeric value is constant and well-formed.
*/
constexpr ChipError(SdkPart part, uint8_t code) : ChipError(part, code, /*file=*/nullptr, /*line=*/0) {}
#if __cplusplus >= 202002L
#if CHIP_CONFIG_ERROR_SOURCE && __cplusplus >= 202002L
constexpr ChipError(SdkPart part, uint8_t code, const char * file, unsigned int line,
std::source_location location = std::source_location::current()) :
mError(MakeInteger(part, code)) CHIP_INITIALIZE_ERROR_SOURCE(file, line, location)
Expand All @@ -159,7 +159,7 @@ class ChipError
constexpr ChipError(SdkPart part, uint8_t code, const char * file, unsigned int line) :
mError(MakeInteger(part, code)) CHIP_INITIALIZE_ERROR_SOURCE(file, line, /*loc=*/nullptr)
{}
#endif // __cplusplus >= 202002L
#endif // CHIP_CONFIG_ERROR_SOURCE && __cplusplus >= 202002L

/**
* Construct a CHIP_ERROR constant for SdkPart @a part with @a code at the current source line.
Expand All @@ -180,7 +180,7 @@ class ChipError
* This is intended to be used only in foreign function interfaces.
*/
explicit constexpr ChipError(StorageType error) : ChipError(error, /*file=*/nullptr, /*line=*/0) {}
#if __cplusplus >= 202002L
#if CHIP_CONFIG_ERROR_SOURCE && __cplusplus >= 202002L
explicit constexpr ChipError(StorageType error, const char * file, unsigned int line,
std::source_location location = std::source_location::current()) :
mError(error) CHIP_INITIALIZE_ERROR_SOURCE(file, line, location)
Expand All @@ -189,7 +189,7 @@ class ChipError
explicit constexpr ChipError(StorageType error, const char * file, unsigned int line) :
mError(error) CHIP_INITIALIZE_ERROR_SOURCE(file, line, /*loc=*/nullptr)
{}
#endif // __cplusplus >= 202002L
#endif // CHIP_CONFIG_ERROR_SOURCE && __cplusplus >= 202002L

#undef CHIP_INITIALIZE_ERROR_SOURCE

Expand Down
11 changes: 1 addition & 10 deletions src/messaging/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")
import("//build_overrides/nlunit_test.gni")

import("${chip_root}/build/chip/chip_test_suite.gni")
import("${chip_root}/src/app/icd/icd.gni")
Expand All @@ -38,15 +37,9 @@ static_library("helpers") {
"${chip_root}/src/transport",
"${chip_root}/src/transport/tests:helpers",
]

# MessagingContext exposes nl-test compatible setup/teardown functions, specifically
# they return nltest specific SUCCESS/FAILURE constants hence this dependency.
#
# Once all tests are moved to pw_unittest/gtest, this dependency should be removed
public_deps = [ "${nlunit_test_root}:nlunit-test" ]
}

chip_test_suite_using_nltest("tests") {
chip_test_suite("tests") {
output_name = "libMessagingLayerTests"

test_sources = [
Expand All @@ -73,12 +66,10 @@ chip_test_suite_using_nltest("tests") {
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/support",
"${chip_root}/src/lib/support:test_utils",
"${chip_root}/src/lib/support:testing_nlunit",
"${chip_root}/src/messaging",
"${chip_root}/src/protocols",
"${chip_root}/src/transport",
"${chip_root}/src/transport/raw/tests:helpers",
"${nlunit_test_root}:nlunit-test",
]

if (chip_enable_icd_server) {
Expand Down
4 changes: 2 additions & 2 deletions src/messaging/tests/MessagingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
#include <transport/tests/LoopbackTransportManager.h>
#include <transport/tests/UDPTransportManager.h>

#include <nlunit-test.h>

#include <vector>

namespace chip {
Expand Down Expand Up @@ -98,6 +96,8 @@ class MessagingContext : public PlatformMemoryUser
mInitialized(false), mAliceAddress(Transport::PeerAddress::UDP(GetAddress(), CHIP_PORT + 1)),
mBobAddress(Transport::PeerAddress::UDP(GetAddress(), CHIP_PORT))
{}
// TODO Replace VerifyOrDie with Pigweed assert after transition app/tests to Pigweed.
// TODO Currently src/app/icd/server/tests is using MessagingConetext as dependency.
~MessagingContext() { VerifyOrDie(mInitialized == false); }

// Whether Alice and Bob are initialized, must be called before Init
Expand Down
Loading

0 comments on commit 1b265c0

Please sign in to comment.