From 05938204e9a80db75dd88d90a948b841e6724fdf Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Mon, 13 Dec 2021 12:41:37 -0800 Subject: [PATCH] Fix TestGroupMessaging test failure --- src/app/clusters/basic/basic.cpp | 87 +++++++++++++++++++ .../tests/suites/TestBasicInformation.yaml | 4 +- src/app/tests/suites/TestGroupMessaging.yaml | 6 +- 3 files changed, 92 insertions(+), 5 deletions(-) diff --git a/src/app/clusters/basic/basic.cpp b/src/app/clusters/basic/basic.cpp index 88dcadf7de97a1..ed86e5fc289758 100644 --- a/src/app/clusters/basic/basic.cpp +++ b/src/app/clusters/basic/basic.cpp @@ -33,10 +33,96 @@ using namespace chip; using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::Clusters::Basic; +using namespace chip::app::Clusters::Basic::Attributes; using namespace chip::DeviceLayer; namespace { +class BasicAttrAccess : public AttributeAccessInterface +{ +public: + // Register for the Basic cluster on all endpoints. + BasicAttrAccess() : AttributeAccessInterface(Optional::Missing(), Basic::Id) {} + + CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; + CHIP_ERROR Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder) override; + +private: + CHIP_ERROR ReadLocation(AttributeValueEncoder & aEncoder); + CHIP_ERROR WriteLocation(AttributeValueDecoder & aDecoder); +}; + +BasicAttrAccess gAttrAccess; + +CHIP_ERROR BasicAttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) +{ + if (aPath.mClusterId != Basic::Id) + { + // We shouldn't have been called at all. + return CHIP_ERROR_INVALID_ARGUMENT; + } + + switch (aPath.mAttributeId) + { + case Location::Id: + return ReadLocation(aEncoder); + default: + break; + } + + return CHIP_NO_ERROR; +} + +CHIP_ERROR BasicAttrAccess::ReadLocation(AttributeValueEncoder & aEncoder) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + char location[DeviceLayer::ConfigurationManager::kMaxLocationLength + 1]; + size_t codeLen = 0; + + if (ConfigurationMgr().GetCountryCode(location, sizeof(location), codeLen) == CHIP_NO_ERROR) + { + if (codeLen == 0) + { + err = aEncoder.Encode(chip::CharSpan("XX", strlen("XX"))); + } + else + { + err = aEncoder.Encode(chip::CharSpan(location, strlen(location))); + } + } + else + { + err = aEncoder.Encode(chip::CharSpan("XX", strlen("XX"))); + } + + return err; +} + +CHIP_ERROR BasicAttrAccess::Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder) +{ + VerifyOrDie(aPath.mClusterId == Basic::Id); + + switch (aPath.mAttributeId) + { + case Location::Id: + return WriteLocation(aDecoder); + default: + break; + } + + return CHIP_NO_ERROR; +} + +CHIP_ERROR BasicAttrAccess::WriteLocation(AttributeValueDecoder & aDecoder) +{ + chip::CharSpan location; + + ReturnErrorOnFailure(aDecoder.Decode(location)); + + return DeviceLayer::ConfigurationMgr().StoreCountryCode(location.data(), location.size()); +} + class PlatformMgrDelegate : public DeviceLayer::PlatformManagerDelegate { // Gets called by the current Node after completing a boot or reboot process. @@ -232,5 +318,6 @@ void emberAfBasicClusterServerInitCallback(chip::EndpointId endpoint) void MatterBasicPluginServerInitCallback() { + registerAttributeAccessOverride(&gAttrAccess); PlatformMgr().SetDelegate(&gPlatformMgrDelegate); } diff --git a/src/app/tests/suites/TestBasicInformation.yaml b/src/app/tests/suites/TestBasicInformation.yaml index fb7503668fe81f..42034e5d2ce24b 100644 --- a/src/app/tests/suites/TestBasicInformation.yaml +++ b/src/app/tests/suites/TestBasicInformation.yaml @@ -22,7 +22,7 @@ tests: - label: "Wait for the commissioned device to be retrieved" cluster: "DelayCommands" command: "WaitForCommissionee" - #Disabled due to issue-12983 + - label: "Read location" disabled: true command: "readAttribute" @@ -35,7 +35,7 @@ tests: attribute: "location" arguments: value: "us" - #Disabled due to issue-12983 + - label: "Read back location" disabled: true command: "readAttribute" diff --git a/src/app/tests/suites/TestGroupMessaging.yaml b/src/app/tests/suites/TestGroupMessaging.yaml index fc9fcc2367af4c..5d2ea424164e1d 100644 --- a/src/app/tests/suites/TestGroupMessaging.yaml +++ b/src/app/tests/suites/TestGroupMessaging.yaml @@ -33,7 +33,7 @@ tests: groupId: "1234" arguments: value: "us" - #Disabled due to issue-12983 + - label: "Read back Attribute" disabled: true command: "readAttribute" @@ -47,13 +47,13 @@ tests: groupId: "1234" arguments: value: "" - #Disabled due to issue-12983 + - label: "Read back Attribute" disabled: true command: "readAttribute" attribute: "location" response: - value: "" + value: "XX" - label: "Turn On the light to see attribute change" cluster: "On/Off"