From 10630754c74f9f97fc8365a3940ba3756c7cd13b Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Tue, 1 Feb 2022 01:20:35 +0100 Subject: [PATCH] [CI] In TC-DM-3.1 maxNetworks and networks attributes read is disabled (#14428) * [TC-DM-3.1] Network Commissioning Attributes - Query MaxNetworks is disabled * Update generated test content --- .../network-commissioning-ember.cpp | 54 ++++++++++--- .../suites/certification/Test_TC_DM_3_1.yaml | 2 - .../Framework/CHIPTests/CHIPClustersTests.m | 48 +++++++++++ .../chip-tool/zap-generated/test/Commands.h | 81 ++++++++++++++++++- 4 files changed, 173 insertions(+), 12 deletions(-) diff --git a/src/app/clusters/network-commissioning-old/network-commissioning-ember.cpp b/src/app/clusters/network-commissioning-old/network-commissioning-ember.cpp index 0fa4311bc14913..9de86f3bafef07 100644 --- a/src/app/clusters/network-commissioning-old/network-commissioning-ember.cpp +++ b/src/app/clusters/network-commissioning-old/network-commissioning-ember.cpp @@ -20,21 +20,53 @@ #include -#include -#include -#include -#include -#include #include -#include -#include +#include +#include +#include #include #include -#include +#include using namespace chip; +using namespace chip::app; using namespace chip::app::Clusters::NetworkCommissioning; +namespace { +class NetworkCommissioningAttributeAccess : public AttributeAccessInterface +{ +public: + NetworkCommissioningAttributeAccess() : AttributeAccessInterface(Optional::Missing(), Id) {} + + CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override + { + switch (aPath.mAttributeId) + { + case Attributes::MaxNetworks::Id: + return aEncoder.Encode(static_cast(0)); + case Attributes::Networks::Id: + return aEncoder.EncodeEmptyList(); + case Attributes::ScanMaxTimeSeconds::Id: + return aEncoder.Encode(static_cast(0)); + case Attributes::ConnectMaxTimeSeconds::Id: + return aEncoder.Encode(static_cast(0)); + case Attributes::InterfaceEnabled::Id: + return aEncoder.Encode(static_cast(false)); + case Attributes::LastNetworkingStatus::Id: + return aEncoder.Encode(NetworkCommissioningStatus::kSuccess); + case Attributes::LastNetworkID::Id: + return aEncoder.Encode(ByteSpan()); + case Attributes::LastConnectErrorValue::Id: + return aEncoder.Encode(Attributes::LastConnectErrorValue::TypeInfo::Type(static_cast(0))); + case Attributes::FeatureMap::Id: + return aEncoder.Encode(static_cast(0)); + default: + return CHIP_NO_ERROR; + } + } +}; +} // namespace + bool emberAfNetworkCommissioningClusterAddOrUpdateThreadNetworkCallback( app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath, const Commands::AddOrUpdateThreadNetwork::DecodableType & commandData) @@ -96,4 +128,8 @@ bool emberAfNetworkCommissioningClusterReorderNetworkCallback(app::CommandHandle return false; } -void MatterNetworkCommissioningPluginServerInitCallback() {} +NetworkCommissioningAttributeAccess gAttrAccess; +void MatterNetworkCommissioningPluginServerInitCallback() +{ + registerAttributeAccessOverride(&gAttrAccess); +} diff --git a/src/app/tests/suites/certification/Test_TC_DM_3_1.yaml b/src/app/tests/suites/certification/Test_TC_DM_3_1.yaml index 9ca7f0c184812d..e9c66ddf0bbb92 100644 --- a/src/app/tests/suites/certification/Test_TC_DM_3_1.yaml +++ b/src/app/tests/suites/certification/Test_TC_DM_3_1.yaml @@ -26,7 +26,6 @@ tests: - label: "Query MaxNetworks" command: "readAttribute" attribute: "MaxNetworks" - disabled: true optional: true response: constraints: @@ -35,7 +34,6 @@ tests: - label: "Query Networks" command: "readAttribute" attribute: "Networks" - disabled: true optional: true response: constraints: diff --git a/src/darwin/Framework/CHIPTests/CHIPClustersTests.m b/src/darwin/Framework/CHIPTests/CHIPClustersTests.m index e9bbbb602a0542..51561907bdbed4 100644 --- a/src/darwin/Framework/CHIPTests/CHIPClustersTests.m +++ b/src/darwin/Framework/CHIPTests/CHIPClustersTests.m @@ -10433,6 +10433,54 @@ - (void)testSendClusterTest_TC_DM_3_1_000000_WaitForCommissionee WaitForCommissionee(expectation, queue); [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; } +- (void)testSendClusterTest_TC_DM_3_1_000001_ReadAttribute +{ + XCTestExpectation * expectation = [self expectationWithDescription:@"Query MaxNetworks"]; + + CHIPDevice * device = GetConnectedDevice(); + dispatch_queue_t queue = dispatch_get_main_queue(); + CHIPTestNetworkCommissioning * cluster = [[CHIPTestNetworkCommissioning alloc] initWithDevice:device endpoint:0 queue:queue]; + XCTAssertNotNil(cluster); + + [cluster readAttributeMaxNetworksWithCompletionHandler:^(NSNumber * _Nullable value, NSError * _Nullable err) { + NSLog(@"Query MaxNetworks Error: %@", err); + + if (err.code == CHIPErrorCodeUnsupportedAttribute) { + [expectation fulfill]; + return; + } + + XCTAssertEqual([CHIPErrorTestUtils errorToZCLErrorCode:err], 0); + + [expectation fulfill]; + }]; + + [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; +} +- (void)testSendClusterTest_TC_DM_3_1_000002_ReadAttribute +{ + XCTestExpectation * expectation = [self expectationWithDescription:@"Query Networks"]; + + CHIPDevice * device = GetConnectedDevice(); + dispatch_queue_t queue = dispatch_get_main_queue(); + CHIPTestNetworkCommissioning * cluster = [[CHIPTestNetworkCommissioning alloc] initWithDevice:device endpoint:0 queue:queue]; + XCTAssertNotNil(cluster); + + [cluster readAttributeNetworksWithCompletionHandler:^(NSArray * _Nullable value, NSError * _Nullable err) { + NSLog(@"Query Networks Error: %@", err); + + if (err.code == CHIPErrorCodeUnsupportedAttribute) { + [expectation fulfill]; + return; + } + + XCTAssertEqual([CHIPErrorTestUtils errorToZCLErrorCode:err], 0); + + [expectation fulfill]; + }]; + + [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; +} - (void)testSendClusterTest_TC_EMR_1_1_000000_WaitForCommissionee { diff --git a/zzz_generated/chip-tool/zap-generated/test/Commands.h b/zzz_generated/chip-tool/zap-generated/test/Commands.h index e35fc59b579285..e1ab16d210a052 100644 --- a/zzz_generated/chip-tool/zap-generated/test/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/test/Commands.h @@ -17460,6 +17460,14 @@ class Test_TC_DM_3_1 : public TestCommand ChipLogProgress(chipTool, " ***** Test Step 0 : Wait for the commissioned device to be retrieved\n"); err = TestWaitForTheCommissionedDeviceToBeRetrieved_0(); break; + case 1: + ChipLogProgress(chipTool, " ***** Test Step 1 : Query MaxNetworks\n"); + err = TestQueryMaxNetworks_1(); + break; + case 2: + ChipLogProgress(chipTool, " ***** Test Step 2 : Query Networks\n"); + err = TestQueryNetworks_2(); + break; } if (CHIP_NO_ERROR != err) @@ -17471,11 +17479,34 @@ class Test_TC_DM_3_1 : public TestCommand private: std::atomic_uint16_t mTestIndex; - const uint16_t mTestCount = 1; + const uint16_t mTestCount = 3; chip::Optional mCluster; chip::Optional mEndpoint; + static void OnFailureCallback_1(void * context, CHIP_ERROR error) + { + (static_cast(context))->OnFailureResponse_1(error); + } + + static void OnSuccessCallback_1(void * context, uint8_t maxNetworks) + { + (static_cast(context))->OnSuccessResponse_1(maxNetworks); + } + + static void OnFailureCallback_2(void * context, CHIP_ERROR error) + { + (static_cast(context))->OnFailureResponse_2(error); + } + + static void OnSuccessCallback_2( + void * context, + const chip::app::DataModel::DecodableList & + networks) + { + (static_cast(context))->OnSuccessResponse_2(networks); + } + // // Tests methods // @@ -17485,6 +17516,54 @@ class Test_TC_DM_3_1 : public TestCommand SetIdentity(kIdentityAlpha); return WaitForCommissionee(); } + + CHIP_ERROR TestQueryMaxNetworks_1() + { + const chip::EndpointId endpoint = mEndpoint.HasValue() ? mEndpoint.Value() : 0; + chip::Controller::NetworkCommissioningClusterTest cluster; + cluster.Associate(mDevices[kIdentityAlpha], endpoint); + + ReturnErrorOnFailure(cluster.ReadAttribute( + this, OnSuccessCallback_1, OnFailureCallback_1)); + return CHIP_NO_ERROR; + } + + void OnFailureResponse_1(CHIP_ERROR error) + { + chip::app::StatusIB status(error); + (status.mStatus == chip::Protocols::InteractionModel::Status::UnsupportedAttribute) ? NextTest() : ThrowFailureResponse(); + } + + void OnSuccessResponse_1(uint8_t maxNetworks) + { + VerifyOrReturn(CheckConstraintType("maxNetworks", "", "uint8")); + NextTest(); + } + + CHIP_ERROR TestQueryNetworks_2() + { + const chip::EndpointId endpoint = mEndpoint.HasValue() ? mEndpoint.Value() : 0; + chip::Controller::NetworkCommissioningClusterTest cluster; + cluster.Associate(mDevices[kIdentityAlpha], endpoint); + + ReturnErrorOnFailure(cluster.ReadAttribute( + this, OnSuccessCallback_2, OnFailureCallback_2)); + return CHIP_NO_ERROR; + } + + void OnFailureResponse_2(CHIP_ERROR error) + { + chip::app::StatusIB status(error); + (status.mStatus == chip::Protocols::InteractionModel::Status::UnsupportedAttribute) ? NextTest() : ThrowFailureResponse(); + } + + void OnSuccessResponse_2( + const chip::app::DataModel::DecodableList & + networks) + { + VerifyOrReturn(CheckConstraintType("networks", "", "list")); + NextTest(); + } }; class Test_TC_DM_2_2 : public TestCommand