From 126706c8a0f0514a39ad9f067cef60af3a653259 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 10 Apr 2024 16:15:11 -0400 Subject: [PATCH 1/5] More fixes to src/app/util/mock. --- src/app/util/mock/Functions.h | 8 ++++++ src/app/util/mock/MockNodeConfig.cpp | 16 +++++++++++ src/app/util/mock/MockNodeConfig.h | 35 +++++++++++++++++++++++-- src/app/util/mock/attribute-storage.cpp | 17 ++++++++++++ 4 files changed, 74 insertions(+), 2 deletions(-) diff --git a/src/app/util/mock/Functions.h b/src/app/util/mock/Functions.h index 32ba08d316f484..16fe45d9045b9e 100644 --- a/src/app/util/mock/Functions.h +++ b/src/app/util/mock/Functions.h @@ -36,7 +36,15 @@ namespace Test { CHIP_ERROR ReadSingleMockClusterData(FabricIndex aAccessingFabricIndex, const app::ConcreteAttributePath & aPath, app::AttributeReportIBs::Builder & aAttributeReports, app::AttributeValueEncoder::AttributeEncodeState * apEncoderState); + +/// Increase the current value for `GetVersion` void BumpVersion(); + +/// Sets GetVersion to return 0 +void ResetVersion(); + +/// Gets the current value for the version that will +/// be returned by emberAfDataVersionStorage DataVersion GetVersion(); /// Configures the singular global mock attribute storage to use the specified configuration. diff --git a/src/app/util/mock/MockNodeConfig.cpp b/src/app/util/mock/MockNodeConfig.cpp index e7c04fa546e5c9..79c886f532a8a2 100644 --- a/src/app/util/mock/MockNodeConfig.cpp +++ b/src/app/util/mock/MockNodeConfig.cpp @@ -70,6 +70,22 @@ MockClusterConfig::MockClusterConfig(ClusterId aId, std::initializer_list(mEmberEventList.size()); mEmberCluster.eventList = mEmberEventList.data(); + + for (auto & attr : attributes) + { + mAttributeMetaData.push_back(attr.attributeMetaData); + } + + // Make sure ember side has access to attribute metadata + mEmberCluster.attributes = mAttributeMetaData.data(); +} + +MockClusterConfig::MockClusterConfig(const MockClusterConfig & other) : + id(other.id), attributes(other.attributes), events(other.events), mEmberCluster(other.mEmberCluster), + mEmberEventList(other.mEmberEventList), mAttributeMetaData(other.mAttributeMetaData) +{ + // Fix self-referencial dependencies after data copy + mEmberCluster.attributes = mAttributeMetaData.data(); } const MockAttributeConfig * MockClusterConfig::attributeById(AttributeId attributeId, ptrdiff_t * outIndex) const diff --git a/src/app/util/mock/MockNodeConfig.h b/src/app/util/mock/MockNodeConfig.h index fc8f185fd80a56..d6f07edcd9ae67 100644 --- a/src/app/util/mock/MockNodeConfig.h +++ b/src/app/util/mock/MockNodeConfig.h @@ -18,6 +18,7 @@ #pragma once +#include #include #include @@ -28,10 +29,35 @@ namespace chip { namespace Test { +namespace internal { + +constexpr EmberAfAttributeMetadata DefaultAttributeMetadata(chip::AttributeId id) +{ + return EmberAfAttributeMetadata{ + .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(0u), + .attributeId = id, + .size = 4, + .attributeType = ZCL_INT32U_ATTRIBUTE_TYPE, + .mask = ATTRIBUTE_MASK_WRITABLE | ATTRIBUTE_MASK_NULLABLE, + }; +} + +} // namespace internal + struct MockAttributeConfig { - MockAttributeConfig(AttributeId aId) : id(aId) {} + MockAttributeConfig(AttributeId aId) : id(aId), attributeMetaData(internal::DefaultAttributeMetadata(aId)) {} + MockAttributeConfig(AttributeId aId, EmberAfAttributeType type, + EmberAfAttributeMask mask = ATTRIBUTE_MASK_WRITABLE | ATTRIBUTE_MASK_NULLABLE) : + id(aId), + attributeMetaData(internal::DefaultAttributeMetadata(aId)) + { + attributeMetaData.attributeType = type; + attributeMetaData.mask = mask; + } + const AttributeId id; + EmberAfAttributeMetadata attributeMetaData; }; struct MockEventConfig @@ -45,6 +71,10 @@ struct MockClusterConfig MockClusterConfig(ClusterId aId, std::initializer_list aAttributes = {}, std::initializer_list aEvents = {}); + // Cluster-config is self-referntial: mEmberCluster.attributes references mAttributeMetaData.data() + MockClusterConfig(const MockClusterConfig & other); + MockClusterConfig & operator=(const MockClusterConfig &) = delete; + const MockAttributeConfig * attributeById(AttributeId attributeId, ptrdiff_t * outIndex = nullptr) const; const EmberAfCluster * emberCluster() const { return &mEmberCluster; } @@ -55,13 +85,14 @@ struct MockClusterConfig private: EmberAfCluster mEmberCluster; std::vector mEmberEventList; + std::vector mAttributeMetaData; }; struct MockEndpointConfig { MockEndpointConfig(EndpointId aId, std::initializer_list aClusters = {}); - // Cluster-config is self-referntial: mEmberCluster.clusters references mEmberClusters + // Endpoint-config is self-referntial: mEmberEndpoint.clusters references mEmberClusters.data() MockEndpointConfig(const MockEndpointConfig & other); MockEndpointConfig & operator=(const MockEndpointConfig &) = delete; diff --git a/src/app/util/mock/attribute-storage.cpp b/src/app/util/mock/attribute-storage.cpp index 6aa872956dbe7a..25e2466f329eea 100644 --- a/src/app/util/mock/attribute-storage.cpp +++ b/src/app/util/mock/attribute-storage.cpp @@ -307,8 +307,14 @@ void EnabledEndpointsWithServerCluster::EnsureMatchingEndpoint() } } // namespace app +// namespace Test { +void ResetVersion() +{ + dataVersion = 0; +} + void BumpVersion() { dataVersion++; @@ -407,5 +413,16 @@ CHIP_ERROR ReadSingleMockClusterData(FabricIndex aAccessingFabricIndex, const Co return attributeReport.EndOfAttributeReportIB(); } +void SetMockNodeConfig(const MockNodeConfig & config) +{ + mockConfig = &config; +} + +/// Resets the mock attribute storage to the default configuration. +void ResetMockNodeConfig() +{ + mockConfig = nullptr; +} + } // namespace Test } // namespace chip From e408508b26cd328bc0774c14b7ca89651fdbee61 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 10 Apr 2024 16:20:36 -0400 Subject: [PATCH 2/5] Remove misplaced comment --- src/app/util/mock/attribute-storage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/util/mock/attribute-storage.cpp b/src/app/util/mock/attribute-storage.cpp index 25e2466f329eea..bd8e8e812dd922 100644 --- a/src/app/util/mock/attribute-storage.cpp +++ b/src/app/util/mock/attribute-storage.cpp @@ -307,7 +307,7 @@ void EnabledEndpointsWithServerCluster::EnsureMatchingEndpoint() } } // namespace app -// + namespace Test { void ResetVersion() From 04e40501bf64a969458b7eeadbfa34b566d1cf06 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 10 Apr 2024 16:21:10 -0400 Subject: [PATCH 3/5] Remove misplaced comment --- src/app/util/mock/attribute-storage.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/util/mock/attribute-storage.cpp b/src/app/util/mock/attribute-storage.cpp index bd8e8e812dd922..716460026591ee 100644 --- a/src/app/util/mock/attribute-storage.cpp +++ b/src/app/util/mock/attribute-storage.cpp @@ -418,7 +418,6 @@ void SetMockNodeConfig(const MockNodeConfig & config) mockConfig = &config; } -/// Resets the mock attribute storage to the default configuration. void ResetMockNodeConfig() { mockConfig = nullptr; From 7903fb53ea5483bd6ac08084e8123845b6e24610 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 10 Apr 2024 17:15:38 -0400 Subject: [PATCH 4/5] Fix compilation for esp32 --- src/app/util/mock/MockNodeConfig.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/util/mock/MockNodeConfig.h b/src/app/util/mock/MockNodeConfig.h index d6f07edcd9ae67..6156b51cbe406f 100644 --- a/src/app/util/mock/MockNodeConfig.h +++ b/src/app/util/mock/MockNodeConfig.h @@ -34,7 +34,7 @@ namespace internal { constexpr EmberAfAttributeMetadata DefaultAttributeMetadata(chip::AttributeId id) { return EmberAfAttributeMetadata{ - .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(0u), + .defaultValue = EmberAfDefaultOrMinMaxAttributeValue(static_cast(0)), .attributeId = id, .size = 4, .attributeType = ZCL_INT32U_ATTRIBUTE_TYPE, From d0119c7af868c6b969fb1dffeefb64ec7a708dee Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Thu, 11 Apr 2024 08:25:15 -0400 Subject: [PATCH 5/5] Fix typo --- src/app/util/mock/MockNodeConfig.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/util/mock/MockNodeConfig.h b/src/app/util/mock/MockNodeConfig.h index 6156b51cbe406f..aa711589eff432 100644 --- a/src/app/util/mock/MockNodeConfig.h +++ b/src/app/util/mock/MockNodeConfig.h @@ -71,7 +71,7 @@ struct MockClusterConfig MockClusterConfig(ClusterId aId, std::initializer_list aAttributes = {}, std::initializer_list aEvents = {}); - // Cluster-config is self-referntial: mEmberCluster.attributes references mAttributeMetaData.data() + // Cluster-config is self-referential: mEmberCluster.attributes references mAttributeMetaData.data() MockClusterConfig(const MockClusterConfig & other); MockClusterConfig & operator=(const MockClusterConfig &) = delete; @@ -92,7 +92,7 @@ struct MockEndpointConfig { MockEndpointConfig(EndpointId aId, std::initializer_list aClusters = {}); - // Endpoint-config is self-referntial: mEmberEndpoint.clusters references mEmberClusters.data() + // Endpoint-config is self-referential: mEmberEndpoint.clusters references mEmberClusters.data() MockEndpointConfig(const MockEndpointConfig & other); MockEndpointConfig & operator=(const MockEndpointConfig &) = delete;