Skip to content

Commit

Permalink
Fix operational credentials fabric count attributes (#9303)
Browse files Browse the repository at this point in the history
* Fix operational credentials fabric count attributes

* make the PR independet of compressed fabric ID feature

* add test to Darwin tests as well

* remove invalid check for vendor id

* Update unit tests to check for limits

* update number of min fabrics in the test

* remove upper limit check in SupportedFabrics
  • Loading branch information
pan-apple authored and pull[bot] committed Sep 13, 2021
1 parent 828a186 commit 1632540
Show file tree
Hide file tree
Showing 8 changed files with 289 additions and 3 deletions.
18 changes: 18 additions & 0 deletions examples/chip-tool/templates/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,24 @@ class {{filename}}: public TestCommand
return;
}
{{/if}}

{{#if expectedConstraints.minValue}}
if ({{asLowerCamelCase name}} < {{expectedConstraints.minValue}})
{
ChipLogError(chipTool, "Error: {{asLowerCamelCase name}} is lower than expected. Min value is {{expectedConstraints.minValue}} but got '%d'", {{asLowerCamelCase name}});
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}
{{/if}}

{{#if expectedConstraints.maxValue}}
if ({{asLowerCamelCase name}} > {{expectedConstraints.maxValue}})
{
ChipLogError(chipTool, "Error: {{asLowerCamelCase name}} is higher than expected. Max value is {{expectedConstraints.maxValue}} but got '%d'", {{asLowerCamelCase name}});
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}
{{/if}}
{{/if}}
{{/chip_tests_item_response_parameters}}

Expand Down
2 changes: 1 addition & 1 deletion examples/chip-tool/templates/tests-commands.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

#include <commands/tests/TestCommand.h>

{{>test_cluster tests="TV_TargetNavigatorCluster, TV_AudioOutputCluster, TV_ApplicationLauncherCluster, TV_KeypadInputCluster, TV_AccountLoginCluster, TV_WakeOnLanCluster, TV_ApplicationBasicCluster, TV_MediaPlaybackCluster, TV_TvChannelCluster, TV_LowPowerCluster, TV_MediaInputCluster, TestCluster, Test_TC_OO_1_1, Test_TC_OO_2_1, Test_TC_OO_2_2, Test_TC_DM_1_1, Test_TC_DM_3_1, Test_TC_CC_3_4, Test_TC_CC_5, Test_TC_CC_6, Test_TC_CC_7, Test_TC_CC_8, Test_TC_WNCV_1_1, Test_TC_WNCV_2_1, Test_TC_BI_1_1, Test_TC_FLW_1_1, Test_TC_TM_1_1, Test_TC_OCC_1_1"}}
{{>test_cluster tests="TV_TargetNavigatorCluster, TV_AudioOutputCluster, TV_ApplicationLauncherCluster, TV_KeypadInputCluster, TV_AccountLoginCluster, TV_WakeOnLanCluster, TV_ApplicationBasicCluster, TV_MediaPlaybackCluster, TV_TvChannelCluster, TV_LowPowerCluster, TV_MediaInputCluster, TestCluster, Test_TC_OO_1_1, Test_TC_OO_2_1, Test_TC_OO_2_2, Test_TC_DM_1_1, Test_TC_DM_3_1, Test_TC_CC_3_4, Test_TC_CC_5, Test_TC_CC_6, Test_TC_CC_7, Test_TC_CC_8, Test_TC_WNCV_1_1, Test_TC_WNCV_2_1, Test_TC_BI_1_1, Test_TC_FLW_1_1, Test_TC_TM_1_1, Test_TC_OCC_1_1, OperationalCredentialsCluster"}}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ CHIP_ERROR writeFabricsIntoFabricsListAttribute()
const uint8_t * fabricLabel = pairing.GetFabricLabel();

// Skip over uninitialized fabrics
if (nodeId == kUndefinedNodeId || fabricId == kUndefinedFabricId || vendorId == kUndefinedVendorId)
if (nodeId == kUndefinedNodeId)
{
emberAfPrintln(EMBER_AF_PRINT_DEBUG,
"OpCreds: Skipping over uninitialized fabric with fabricId 0x" ChipLogFormatX64
Expand Down Expand Up @@ -158,6 +158,15 @@ CHIP_ERROR writeFabricsIntoFabricsListAttribute()
err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
}

if (err == CHIP_NO_ERROR &&
app::Clusters::OperationalCredentials::Attributes::SetSupportedFabrics(0, CHIP_CONFIG_MAX_DEVICE_ADMINS) !=
EMBER_ZCL_STATUS_SUCCESS)
{
emberAfPrintln(EMBER_AF_PRINT_DEBUG, "OpCreds: Failed to write %" PRIu8 " in supported fabrics count attribute",
CHIP_CONFIG_MAX_DEVICE_ADMINS);
err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
}

return err;
}

Expand Down
36 changes: 36 additions & 0 deletions src/app/tests/suites/OperationalCredentialsCluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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: Operational Credentials Cluster Tests

config:
cluster: "Operational Credentials"
endpoint: 0

tests:
- label: "Read number of supported fabrics"
command: "readAttribute"
attribute: "SupportedFabrics"
response:
constraints:
type: uint8
minValue: 4

- label: "Read number of commissioned fabrics"
command: "readAttribute"
attribute: "CommissionedFabrics"
response:
constraints:
type: uint8
minValue: 1
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/templates/clusters-tests.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ CHIPDevice * GetPairedDevice(uint64_t deviceId)
[self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil];
}

{{>test_cluster tests="TestCluster, Test_TC_OO_1_1, Test_TC_OO_2_1, Test_TC_OO_2_2, Test_TC_DM_1_1, Test_TC_DM_3_1, Test_TC_CC_3_4, Test_TC_CC_5, Test_TC_CC_6, Test_TC_CC_7, Test_TC_CC_8, Test_TC_WNCV_1_1, Test_TC_WNCV_2_1, Test_TC_BI_1_1, Test_TC_FLW_1_1, Test_TC_TM_1_1, Test_TC_OCC_1_1"}}
{{>test_cluster tests="TestCluster, Test_TC_OO_1_1, Test_TC_OO_2_1, Test_TC_OO_2_2, Test_TC_DM_1_1, Test_TC_DM_3_1, Test_TC_CC_3_4, Test_TC_CC_5, Test_TC_CC_6, Test_TC_CC_7, Test_TC_CC_8, Test_TC_WNCV_1_1, Test_TC_WNCV_2_1, Test_TC_BI_1_1, Test_TC_FLW_1_1, Test_TC_TM_1_1, Test_TC_OCC_1_1, OperationalCredentialsCluster"}}

{{#chip_client_clusters}}
{{#unless (isStrEqual "Test Cluster" name)}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
{{#if expectedConstraints.maxLength}}
XCTAssertLessThanOrEqual([values[@"{{#if parent.isReadAttribute}}value{{else}}{{name}}{{/if}}"] length], {{expectedConstraints.maxLength}});
{{/if}}
{{#if expectedConstraints.minValue}}
XCTAssertGreaterThanOrEqual([values[@"{{#if parent.isReadAttribute}}value{{else}}{{name}}{{/if}}"] {{asObjectiveCNumberType "" type true}}Value], {{expectedConstraints.minValue}});
{{/if}}
{{#if expectedConstraints.maxValue}}
XCTAssertLessThanOrEqual([values[@"{{#if parent.isReadAttribute}}value{{else}}{{name}}{{/if}}"] {{asObjectiveCNumberType "" type true}}Value], {{expectedConstraints.maxValue}});
{{/if}}
{{/if}}
{{/chip_tests_item_response_parameters}}
[expectation fulfill];
Expand Down
37 changes: 37 additions & 0 deletions src/darwin/Framework/CHIPTests/CHIPClustersTests.m

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

180 changes: 180 additions & 0 deletions zzz_generated/chip-tool/zap-generated/test/Commands.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1632540

Please sign in to comment.