From 0372393312a71429333e1cc2794ebe103dcedb93 Mon Sep 17 00:00:00 2001 From: Wystan Schmidt Date: Tue, 2 Nov 2021 13:42:38 -0500 Subject: [PATCH] Add test TC EMR 1_1 (#11239) * Add Test_TC_EMR_1_1.yaml and update templates * Update generated tests --- examples/chip-tool/templates/tests.js | 5 + .../suites/certification/Test_TC_EMR_1_1.yaml | 42 +++++ src/darwin/Framework/CHIP/templates/tests.js | 5 + .../Framework/CHIPTests/CHIPClustersTests.m | 65 ++++++++ .../chip-tool/zap-generated/test/Commands.h | 146 ++++++++++++++++++ 5 files changed, 263 insertions(+) create mode 100644 src/app/tests/suites/certification/Test_TC_EMR_1_1.yaml diff --git a/examples/chip-tool/templates/tests.js b/examples/chip-tool/templates/tests.js index 5cc5f973cdb492..127cb1eb515890 100644 --- a/examples/chip-tool/templates/tests.js +++ b/examples/chip-tool/templates/tests.js @@ -49,6 +49,10 @@ function getTests() 'Test_TC_DM_3_1', ]; + const ElectricalMeasurement = [ + 'Test_TC_EMR_1_1', + ]; + const FlowMeasurement = [ 'Test_TC_FLW_1_1', 'Test_TC_FLW_2_1', @@ -161,6 +165,7 @@ function getTests() BinaryInput, // ColorControl, // DeviceManagement, // + ElectricalMeasurement, // FlowMeasurement, // LevelControl, // MediaControl, // diff --git a/src/app/tests/suites/certification/Test_TC_EMR_1_1.yaml b/src/app/tests/suites/certification/Test_TC_EMR_1_1.yaml new file mode 100644 index 00000000000000..84183517b32b73 --- /dev/null +++ b/src/app/tests/suites/certification/Test_TC_EMR_1_1.yaml @@ -0,0 +1,42 @@ +# 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. + +name: 13.1.1. [TC-EMR-1.1] Global attributes with server as DUT + +config: + cluster: "Electrical Measurement" + endpoint: 1 + +tests: + - label: "read the global attribute: ClusterRevision" + command: "readAttribute" + attribute: "ClusterRevision" + response: + value: 3 + + - label: + "write the default values to mandatory global attribute: + ClusterRevision" + command: "writeAttribute" + attribute: "ClusterRevision" + arguments: + value: 1 + response: + error: 1 + + - label: "reads back global attribute: ClusterRevision" + command: "readAttribute" + attribute: "ClusterRevision" + response: + value: 3 diff --git a/src/darwin/Framework/CHIP/templates/tests.js b/src/darwin/Framework/CHIP/templates/tests.js index 56a55753964de0..f9078254f4d382 100644 --- a/src/darwin/Framework/CHIP/templates/tests.js +++ b/src/darwin/Framework/CHIP/templates/tests.js @@ -49,6 +49,10 @@ function getTests() 'Test_TC_DM_3_1', ]; + const ElectricalMeasurement = [ + 'Test_TC_EMR_1_1', + ]; + const FlowMeasurement = [ 'Test_TC_FLW_1_1', 'Test_TC_FLW_2_1', @@ -145,6 +149,7 @@ function getTests() BinaryInput, // ColorControl, // DeviceManagement, // + ElectricalMeasurement, // FlowMeasurement, // LevelControl, // MediaControl, // diff --git a/src/darwin/Framework/CHIPTests/CHIPClustersTests.m b/src/darwin/Framework/CHIPTests/CHIPClustersTests.m index e66a6bd1f16628..270ece582b8c95 100644 --- a/src/darwin/Framework/CHIPTests/CHIPClustersTests.m +++ b/src/darwin/Framework/CHIPTests/CHIPClustersTests.m @@ -6451,6 +6451,71 @@ - (void)testSendClusterTest_TC_DM_1_1_000017_ReadAttribute [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; } +- (void)testSendClusterTest_TC_EMR_1_1_000000_ReadAttribute +{ + XCTestExpectation * expectation = [self expectationWithDescription:@"read the global attribute: ClusterRevision"]; + + CHIPDevice * device = GetConnectedDevice(); + dispatch_queue_t queue = dispatch_get_main_queue(); + CHIPTestElectricalMeasurement * cluster = [[CHIPTestElectricalMeasurement alloc] initWithDevice:device endpoint:1 queue:queue]; + XCTAssertNotNil(cluster); + + [cluster readAttributeClusterRevisionWithResponseHandler:^(NSError * err, NSDictionary * values) { + NSLog(@"read the global attribute: ClusterRevision Error: %@", err); + + XCTAssertEqual(err.code, 0); + + XCTAssertEqual([values[@"value"] unsignedShortValue], 3U); + + [expectation fulfill]; + }]; + + [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; +} +- (void)testSendClusterTest_TC_EMR_1_1_000001_WriteAttribute +{ + XCTestExpectation * expectation = + [self expectationWithDescription:@"write the default values to mandatory global attribute: ClusterRevision"]; + + CHIPDevice * device = GetConnectedDevice(); + dispatch_queue_t queue = dispatch_get_main_queue(); + CHIPTestElectricalMeasurement * cluster = [[CHIPTestElectricalMeasurement alloc] initWithDevice:device endpoint:1 queue:queue]; + XCTAssertNotNil(cluster); + + uint16_t clusterRevisionArgument = 1U; + [cluster + writeAttributeClusterRevisionWithValue:clusterRevisionArgument + responseHandler:^(NSError * err, NSDictionary * values) { + NSLog(@"write the default values to mandatory global attribute: ClusterRevision Error: %@", err); + + XCTAssertEqual(err.code, 1); + [expectation fulfill]; + }]; + + [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; +} +- (void)testSendClusterTest_TC_EMR_1_1_000002_ReadAttribute +{ + XCTestExpectation * expectation = [self expectationWithDescription:@"reads back global attribute: ClusterRevision"]; + + CHIPDevice * device = GetConnectedDevice(); + dispatch_queue_t queue = dispatch_get_main_queue(); + CHIPTestElectricalMeasurement * cluster = [[CHIPTestElectricalMeasurement alloc] initWithDevice:device endpoint:1 queue:queue]; + XCTAssertNotNil(cluster); + + [cluster readAttributeClusterRevisionWithResponseHandler:^(NSError * err, NSDictionary * values) { + NSLog(@"reads back global attribute: ClusterRevision Error: %@", err); + + XCTAssertEqual(err.code, 0); + + XCTAssertEqual([values[@"value"] unsignedShortValue], 3U); + + [expectation fulfill]; + }]; + + [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; +} + - (void)testSendClusterTest_TC_FLW_1_1_000000_WriteAttribute { XCTestExpectation * expectation = diff --git a/zzz_generated/chip-tool/zap-generated/test/Commands.h b/zzz_generated/chip-tool/zap-generated/test/Commands.h index e09d19191c791f..dabc0b8bf4d653 100644 --- a/zzz_generated/chip-tool/zap-generated/test/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/test/Commands.h @@ -10309,6 +10309,151 @@ class Test_TC_DM_3_1 : public TestCommand // }; +class Test_TC_EMR_1_1 : public TestCommand +{ +public: + Test_TC_EMR_1_1() : TestCommand("Test_TC_EMR_1_1"), mTestIndex(0) {} + + /////////// TestCommand Interface ///////// + void NextTest() override + { + CHIP_ERROR err = CHIP_NO_ERROR; + + if (0 == mTestIndex) + { + ChipLogProgress(chipTool, " **** Test Start: Test_TC_EMR_1_1\n"); + } + + if (mTestCount == mTestIndex) + { + ChipLogProgress(chipTool, " **** Test Complete: Test_TC_EMR_1_1\n"); + SetCommandExitStatus(CHIP_NO_ERROR); + return; + } + + Wait(); + + // Ensure we increment mTestIndex before we start running the relevant + // command. That way if we lose the timeslice after we send the message + // but before our function call returns, we won't end up with an + // incorrect mTestIndex value observed when we get the response. + switch (mTestIndex++) + { + case 0: + ChipLogProgress(chipTool, " ***** Test Step 0 : read the global attribute: ClusterRevision\n"); + err = TestReadTheGlobalAttributeClusterRevision_0(); + break; + case 1: + ChipLogProgress(chipTool, + " ***** Test Step 1 : write the default values to mandatory global attribute: ClusterRevision\n"); + err = TestWriteTheDefaultValuesToMandatoryGlobalAttributeClusterRevision_1(); + break; + case 2: + ChipLogProgress(chipTool, " ***** Test Step 2 : reads back global attribute: ClusterRevision\n"); + err = TestReadsBackGlobalAttributeClusterRevision_2(); + break; + } + + if (CHIP_NO_ERROR != err) + { + ChipLogError(chipTool, " ***** Test Failure: %s\n", chip::ErrorStr(err)); + SetCommandExitStatus(err); + } + } + +private: + std::atomic_uint16_t mTestIndex; + const uint16_t mTestCount = 3; + + chip::Callback::Callback mOnFailureCallback_0{ OnFailureCallback_0, this }; + chip::Callback::Callback mOnSuccessCallback_0{ OnSuccessCallback_0, this }; + chip::Callback::Callback mOnFailureCallback_1{ OnFailureCallback_1, this }; + chip::Callback::Callback mOnSuccessCallback_1{ OnSuccessCallback_1, this }; + chip::Callback::Callback mOnFailureCallback_2{ OnFailureCallback_2, this }; + chip::Callback::Callback mOnSuccessCallback_2{ OnSuccessCallback_2, this }; + + static void OnFailureCallback_0(void * context, uint8_t status) + { + (static_cast(context))->OnFailureResponse_0(status); + } + + static void OnSuccessCallback_0(void * context, uint16_t clusterRevision) + { + (static_cast(context))->OnSuccessResponse_0(clusterRevision); + } + + static void OnFailureCallback_1(void * context, uint8_t status) + { + (static_cast(context))->OnFailureResponse_1(status); + } + + static void OnSuccessCallback_1(void * context, uint16_t clusterRevision) + { + (static_cast(context))->OnSuccessResponse_1(clusterRevision); + } + + static void OnFailureCallback_2(void * context, uint8_t status) + { + (static_cast(context))->OnFailureResponse_2(status); + } + + static void OnSuccessCallback_2(void * context, uint16_t clusterRevision) + { + (static_cast(context))->OnSuccessResponse_2(clusterRevision); + } + + // + // Tests methods + // + + CHIP_ERROR TestReadTheGlobalAttributeClusterRevision_0() + { + chip::Controller::ElectricalMeasurementClusterTest cluster; + cluster.Associate(mDevice, 1); + + return cluster.ReadAttributeClusterRevision(mOnSuccessCallback_0.Cancel(), mOnFailureCallback_0.Cancel()); + } + + void OnFailureResponse_0(uint8_t status) { ThrowFailureResponse(); } + + void OnSuccessResponse_0(uint16_t clusterRevision) + { + VerifyOrReturn(CheckValue("clusterRevision", clusterRevision, 3U)); + NextTest(); + } + + CHIP_ERROR TestWriteTheDefaultValuesToMandatoryGlobalAttributeClusterRevision_1() + { + chip::Controller::ElectricalMeasurementClusterTest cluster; + cluster.Associate(mDevice, 1); + + uint16_t clusterRevisionArgument = 1U; + + return cluster.WriteAttributeClusterRevision(mOnSuccessCallback_1.Cancel(), mOnFailureCallback_1.Cancel(), + clusterRevisionArgument); + } + + void OnFailureResponse_1(uint8_t status) { NextTest(); } + + void OnSuccessResponse_1(uint16_t clusterRevision) { ThrowSuccessResponse(); } + + CHIP_ERROR TestReadsBackGlobalAttributeClusterRevision_2() + { + chip::Controller::ElectricalMeasurementClusterTest cluster; + cluster.Associate(mDevice, 1); + + return cluster.ReadAttributeClusterRevision(mOnSuccessCallback_2.Cancel(), mOnFailureCallback_2.Cancel()); + } + + void OnFailureResponse_2(uint8_t status) { ThrowFailureResponse(); } + + void OnSuccessResponse_2(uint16_t clusterRevision) + { + VerifyOrReturn(CheckValue("clusterRevision", clusterRevision, 3U)); + NextTest(); + } +}; + class Test_TC_FLW_1_1 : public TestCommand { public: @@ -24658,6 +24803,7 @@ void registerCommandsTests(Commands & commands) make_unique(), make_unique(), make_unique(), + make_unique(), make_unique(), make_unique(), make_unique(),