From 135891251d12d846457a30f006e66d151e61a8b6 Mon Sep 17 00:00:00 2001 From: Wystan Schmidt Date: Sat, 6 Nov 2021 22:07:01 -0600 Subject: [PATCH] Adding BooleanState Yaml test cases and update (#11517) * Adding BooleanState Yaml test cases and update generated tests * Restyled by prettier-yaml Co-authored-by: Restyled.io --- examples/chip-tool/templates/tests.js | 6 + .../certification/Test_TC_BOOL_1_1.yaml | 42 +++ .../certification/Test_TC_BOOL_2_1.yaml | 48 +++ src/darwin/Framework/CHIP/templates/tests.js | 6 + .../Framework/CHIPTests/CHIPClustersTests.m | 150 +++++++++ .../chip-tool/zap-generated/test/Commands.h | 316 ++++++++++++++++++ 6 files changed, 568 insertions(+) create mode 100644 src/app/tests/suites/certification/Test_TC_BOOL_1_1.yaml create mode 100644 src/app/tests/suites/certification/Test_TC_BOOL_2_1.yaml diff --git a/examples/chip-tool/templates/tests.js b/examples/chip-tool/templates/tests.js index 6761bcf000c358..5003ad980ca36a 100644 --- a/examples/chip-tool/templates/tests.js +++ b/examples/chip-tool/templates/tests.js @@ -22,6 +22,11 @@ function getTests() 'Test_TC_BI_2_1', ]; + const BooleanState = [ + 'Test_TC_BOOL_1_1', + 'Test_TC_BOOL_2_1', + ]; + const ColorControl = [ 'Test_TC_CC_1_1', 'Test_TC_CC_2_1', @@ -182,6 +187,7 @@ function getTests() const tests = [ BinaryInput, // + BooleanState, // ColorControl, // DeviceManagement, // ElectricalMeasurement, // diff --git a/src/app/tests/suites/certification/Test_TC_BOOL_1_1.yaml b/src/app/tests/suites/certification/Test_TC_BOOL_1_1.yaml new file mode 100644 index 00000000000000..e8f9a9bec501ea --- /dev/null +++ b/src/app/tests/suites/certification/Test_TC_BOOL_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: 60.1.1. [TC-BOOL-1.1] Global attributes with server as DUT + +config: + cluster: "Boolean State" + endpoint: 1 + +tests: + - label: "read the global attribute: ClusterRevision" + command: "readAttribute" + attribute: "ClusterRevision" + response: + value: 1 + + - 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: 1 diff --git a/src/app/tests/suites/certification/Test_TC_BOOL_2_1.yaml b/src/app/tests/suites/certification/Test_TC_BOOL_2_1.yaml new file mode 100644 index 00000000000000..69a46931581529 --- /dev/null +++ b/src/app/tests/suites/certification/Test_TC_BOOL_2_1.yaml @@ -0,0 +1,48 @@ +# 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: 60.2.1. [TC-BOOL-2.1] Attributes with server as DUT + +config: + cluster: "Boolean State" + endpoint: 1 + +tests: + - label: "Read mandatory non-global attribute: StateValue" + command: "readAttribute" + attribute: "StateValue" + response: + value: 0 + + - label: "Read mandatory non-global attribute constraints: StateValue" + command: "readAttribute" + attribute: "StateValue" + response: + constraints: + type: bool + + - label: + "Write the default value to mandatory non-global attribute: StateValue" + command: "writeAttribute" + attribute: "StateValue" + arguments: + value: 1 + response: + error: 1 + + - label: "Reads back the mandatory non-global attribute: StateValue" + command: "readAttribute" + attribute: "StateValue" + response: + value: 0 diff --git a/src/darwin/Framework/CHIP/templates/tests.js b/src/darwin/Framework/CHIP/templates/tests.js index a9e45da0fd3711..d0e73c1180f70b 100644 --- a/src/darwin/Framework/CHIP/templates/tests.js +++ b/src/darwin/Framework/CHIP/templates/tests.js @@ -22,6 +22,11 @@ function getTests() 'Test_TC_BI_2_1', ]; + const BooleanState = [ + 'Test_TC_BOOL_1_1', + 'Test_TC_BOOL_2_1', + ]; + const ColorControl = [ 'Test_TC_CC_1_1', 'Test_TC_CC_2_1', @@ -166,6 +171,7 @@ function getTests() const tests = [ BinaryInput, // + BooleanState, // ColorControl, // DeviceManagement, // ElectricalMeasurement, // diff --git a/src/darwin/Framework/CHIPTests/CHIPClustersTests.m b/src/darwin/Framework/CHIPTests/CHIPClustersTests.m index dd1f9115475224..b8fd559dd8641a 100644 --- a/src/darwin/Framework/CHIPTests/CHIPClustersTests.m +++ b/src/darwin/Framework/CHIPTests/CHIPClustersTests.m @@ -488,6 +488,156 @@ - (void)testSendClusterTest_TC_BI_2_1_000010_ReadAttribute [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; } +- (void)testSendClusterTest_TC_BOOL_1_1_000000_ReadAttribute +{ + XCTestExpectation * expectation = [self expectationWithDescription:@"read the global attribute: ClusterRevision"]; + + CHIPDevice * device = GetConnectedDevice(); + dispatch_queue_t queue = dispatch_get_main_queue(); + CHIPTestBooleanState * cluster = [[CHIPTestBooleanState 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], 1U); + + [expectation fulfill]; + }]; + + [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; +} +- (void)testSendClusterTest_TC_BOOL_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(); + CHIPTestBooleanState * cluster = [[CHIPTestBooleanState 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_BOOL_1_1_000002_ReadAttribute +{ + XCTestExpectation * expectation = [self expectationWithDescription:@"reads back global attribute: ClusterRevision"]; + + CHIPDevice * device = GetConnectedDevice(); + dispatch_queue_t queue = dispatch_get_main_queue(); + CHIPTestBooleanState * cluster = [[CHIPTestBooleanState 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], 1U); + + [expectation fulfill]; + }]; + + [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; +} + +- (void)testSendClusterTest_TC_BOOL_2_1_000000_ReadAttribute +{ + XCTestExpectation * expectation = [self expectationWithDescription:@"Read mandatory non-global attribute: StateValue"]; + + CHIPDevice * device = GetConnectedDevice(); + dispatch_queue_t queue = dispatch_get_main_queue(); + CHIPTestBooleanState * cluster = [[CHIPTestBooleanState alloc] initWithDevice:device endpoint:1 queue:queue]; + XCTAssertNotNil(cluster); + + [cluster readAttributeStateValueWithResponseHandler:^(NSError * err, NSDictionary * values) { + NSLog(@"Read mandatory non-global attribute: StateValue Error: %@", err); + + XCTAssertEqual(err.code, 0); + + XCTAssertEqual([values[@"value"] boolValue], 0); + + [expectation fulfill]; + }]; + + [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; +} +- (void)testSendClusterTest_TC_BOOL_2_1_000001_ReadAttribute +{ + XCTestExpectation * expectation = + [self expectationWithDescription:@"Read mandatory non-global attribute constraints: StateValue"]; + + CHIPDevice * device = GetConnectedDevice(); + dispatch_queue_t queue = dispatch_get_main_queue(); + CHIPTestBooleanState * cluster = [[CHIPTestBooleanState alloc] initWithDevice:device endpoint:1 queue:queue]; + XCTAssertNotNil(cluster); + + [cluster readAttributeStateValueWithResponseHandler:^(NSError * err, NSDictionary * values) { + NSLog(@"Read mandatory non-global attribute constraints: StateValue Error: %@", err); + + XCTAssertEqual(err.code, 0); + + [expectation fulfill]; + }]; + + [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; +} +- (void)testSendClusterTest_TC_BOOL_2_1_000002_WriteAttribute +{ + XCTestExpectation * expectation = + [self expectationWithDescription:@"Write the default value to mandatory non-global attribute: StateValue"]; + + CHIPDevice * device = GetConnectedDevice(); + dispatch_queue_t queue = dispatch_get_main_queue(); + CHIPTestBooleanState * cluster = [[CHIPTestBooleanState alloc] initWithDevice:device endpoint:1 queue:queue]; + XCTAssertNotNil(cluster); + + bool stateValueArgument = 1; + [cluster writeAttributeStateValueWithValue:stateValueArgument + responseHandler:^(NSError * err, NSDictionary * values) { + NSLog(@"Write the default value to mandatory non-global attribute: StateValue Error: %@", err); + + XCTAssertEqual(err.code, 1); + [expectation fulfill]; + }]; + + [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; +} +- (void)testSendClusterTest_TC_BOOL_2_1_000003_ReadAttribute +{ + XCTestExpectation * expectation = + [self expectationWithDescription:@"Reads back the mandatory non-global attribute: StateValue"]; + + CHIPDevice * device = GetConnectedDevice(); + dispatch_queue_t queue = dispatch_get_main_queue(); + CHIPTestBooleanState * cluster = [[CHIPTestBooleanState alloc] initWithDevice:device endpoint:1 queue:queue]; + XCTAssertNotNil(cluster); + + [cluster readAttributeStateValueWithResponseHandler:^(NSError * err, NSDictionary * values) { + NSLog(@"Reads back the mandatory non-global attribute: StateValue Error: %@", err); + + XCTAssertEqual(err.code, 0); + + XCTAssertEqual([values[@"value"] boolValue], 0); + + [expectation fulfill]; + }]; + + [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; +} + - (void)testSendClusterTest_TC_CC_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 64f5774eb13181..1d624d64a8849d 100644 --- a/zzz_generated/chip-tool/zap-generated/test/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/test/Commands.h @@ -552,6 +552,320 @@ class Test_TC_BI_2_1 : public TestCommand } }; +class Test_TC_BOOL_1_1 : public TestCommand +{ +public: + Test_TC_BOOL_1_1() : TestCommand("Test_TC_BOOL_1_1"), mTestIndex(0) {} + + /////////// TestCommand Interface ///////// + void NextTest() override + { + CHIP_ERROR err = CHIP_NO_ERROR; + + if (0 == mTestIndex) + { + ChipLogProgress(chipTool, " **** Test Start: Test_TC_BOOL_1_1\n"); + } + + if (mTestCount == mTestIndex) + { + ChipLogProgress(chipTool, " **** Test Complete: Test_TC_BOOL_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_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, EmberAfStatus status) + { + (static_cast(context))->OnFailureResponse_1(chip::to_underlying(status)); + } + + static void OnSuccessCallback_1(void * context) { (static_cast(context))->OnSuccessResponse_1(); } + + 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::BooleanStateClusterTest 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, 1U)); + NextTest(); + } + + CHIP_ERROR TestWriteTheDefaultValuesToMandatoryGlobalAttributeClusterRevision_1() + { + chip::Controller::BooleanStateClusterTest cluster; + cluster.Associate(mDevice, 1); + + uint16_t clusterRevisionArgument; + clusterRevisionArgument = 1U; + + return cluster.WriteAttribute( + clusterRevisionArgument, this, OnSuccessCallback_1, OnFailureCallback_1); + } + + void OnFailureResponse_1(uint8_t status) { NextTest(); } + + void OnSuccessResponse_1() { ThrowSuccessResponse(); } + + CHIP_ERROR TestReadsBackGlobalAttributeClusterRevision_2() + { + chip::Controller::BooleanStateClusterTest 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, 1U)); + NextTest(); + } +}; + +class Test_TC_BOOL_2_1 : public TestCommand +{ +public: + Test_TC_BOOL_2_1() : TestCommand("Test_TC_BOOL_2_1"), mTestIndex(0) {} + + /////////// TestCommand Interface ///////// + void NextTest() override + { + CHIP_ERROR err = CHIP_NO_ERROR; + + if (0 == mTestIndex) + { + ChipLogProgress(chipTool, " **** Test Start: Test_TC_BOOL_2_1\n"); + } + + if (mTestCount == mTestIndex) + { + ChipLogProgress(chipTool, " **** Test Complete: Test_TC_BOOL_2_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 mandatory non-global attribute: StateValue\n"); + err = TestReadMandatoryNonGlobalAttributeStateValue_0(); + break; + case 1: + ChipLogProgress(chipTool, " ***** Test Step 1 : Read mandatory non-global attribute constraints: StateValue\n"); + err = TestReadMandatoryNonGlobalAttributeConstraintsStateValue_1(); + break; + case 2: + ChipLogProgress(chipTool, + " ***** Test Step 2 : Write the default value to mandatory non-global attribute: StateValue\n"); + err = TestWriteTheDefaultValueToMandatoryNonGlobalAttributeStateValue_2(); + break; + case 3: + ChipLogProgress(chipTool, " ***** Test Step 3 : Reads back the mandatory non-global attribute: StateValue\n"); + err = TestReadsBackTheMandatoryNonGlobalAttributeStateValue_3(); + 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 = 4; + + 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_3{ OnFailureCallback_3, this }; + chip::Callback::Callback mOnSuccessCallback_3{ OnSuccessCallback_3, this }; + + static void OnFailureCallback_0(void * context, uint8_t status) + { + (static_cast(context))->OnFailureResponse_0(status); + } + + static void OnSuccessCallback_0(void * context, bool stateValue) + { + (static_cast(context))->OnSuccessResponse_0(stateValue); + } + + static void OnFailureCallback_1(void * context, uint8_t status) + { + (static_cast(context))->OnFailureResponse_1(status); + } + + static void OnSuccessCallback_1(void * context, bool stateValue) + { + (static_cast(context))->OnSuccessResponse_1(stateValue); + } + + static void OnFailureCallback_2(void * context, EmberAfStatus status) + { + (static_cast(context))->OnFailureResponse_2(chip::to_underlying(status)); + } + + static void OnSuccessCallback_2(void * context) { (static_cast(context))->OnSuccessResponse_2(); } + + static void OnFailureCallback_3(void * context, uint8_t status) + { + (static_cast(context))->OnFailureResponse_3(status); + } + + static void OnSuccessCallback_3(void * context, bool stateValue) + { + (static_cast(context))->OnSuccessResponse_3(stateValue); + } + + // + // Tests methods + // + + CHIP_ERROR TestReadMandatoryNonGlobalAttributeStateValue_0() + { + chip::Controller::BooleanStateClusterTest cluster; + cluster.Associate(mDevice, 1); + + return cluster.ReadAttributeStateValue(mOnSuccessCallback_0.Cancel(), mOnFailureCallback_0.Cancel()); + } + + void OnFailureResponse_0(uint8_t status) { ThrowFailureResponse(); } + + void OnSuccessResponse_0(bool stateValue) + { + VerifyOrReturn(CheckValue("stateValue", stateValue, 0)); + NextTest(); + } + + CHIP_ERROR TestReadMandatoryNonGlobalAttributeConstraintsStateValue_1() + { + chip::Controller::BooleanStateClusterTest cluster; + cluster.Associate(mDevice, 1); + + return cluster.ReadAttributeStateValue(mOnSuccessCallback_1.Cancel(), mOnFailureCallback_1.Cancel()); + } + + void OnFailureResponse_1(uint8_t status) { ThrowFailureResponse(); } + + void OnSuccessResponse_1(bool stateValue) + { + VerifyOrReturn(CheckConstraintType("stateValue", "", "bool")); + NextTest(); + } + + CHIP_ERROR TestWriteTheDefaultValueToMandatoryNonGlobalAttributeStateValue_2() + { + chip::Controller::BooleanStateClusterTest cluster; + cluster.Associate(mDevice, 1); + + bool stateValueArgument; + stateValueArgument = 1; + + return cluster.WriteAttribute( + stateValueArgument, this, OnSuccessCallback_2, OnFailureCallback_2); + } + + void OnFailureResponse_2(uint8_t status) { NextTest(); } + + void OnSuccessResponse_2() { ThrowSuccessResponse(); } + + CHIP_ERROR TestReadsBackTheMandatoryNonGlobalAttributeStateValue_3() + { + chip::Controller::BooleanStateClusterTest cluster; + cluster.Associate(mDevice, 1); + + return cluster.ReadAttributeStateValue(mOnSuccessCallback_3.Cancel(), mOnFailureCallback_3.Cancel()); + } + + void OnFailureResponse_3(uint8_t status) { ThrowFailureResponse(); } + + void OnSuccessResponse_3(bool stateValue) + { + VerifyOrReturn(CheckValue("stateValue", stateValue, 0)); + NextTest(); + } +}; + class Test_TC_CC_1_1 : public TestCommand { public: @@ -27727,6 +28041,8 @@ void registerCommandsTests(Commands & commands) commands_list clusterCommands = { make_unique(), make_unique(), + make_unique(), + make_unique(), make_unique(), make_unique(), make_unique(),