Skip to content

Commit

Permalink
Fix data version handling in test033_TestMTRDeviceDeviceConfiguration…
Browse files Browse the repository at this point in the history
…Changed (#35628)

Data versions are per-cluster, not per-attribute, so every time we inject an
attribute report for a given cluster we need to bump the data version.

Also:

* Fixes checkAttributeReportTriggersConfigurationChanged to be an instance
  method, since it was taking the instance as an argument anyway.
* Fixes checkAttributeReportTriggersConfigurationChanged to provide descriptions
  for its expectations and assertions that identify the callsite.
* Adds some logging to MTRDevice to make it a little easier to tell which parts
  of attribute reporting are or are not happening and in which order.
  • Loading branch information
bzbarsky-apple authored Sep 17, 2024
1 parent 31894f6 commit ead3862
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 132 deletions.
12 changes: 10 additions & 2 deletions src/darwin/Framework/CHIP/MTRDevice_Concrete.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,8 @@ - (void)setStorageBehaviorConfiguration:(MTRDeviceStorageBehaviorConfiguration *

- (void)_handleReportEnd
{
MTR_LOG("%@ handling report end", self);

std::lock_guard lock(_lock);
_receivingReport = NO;
_receivingPrimingReport = NO;
Expand Down Expand Up @@ -1853,6 +1855,11 @@ - (void)_reportAttributes:(NSArray<NSDictionary<NSString *, id> *> *)attributes

- (void)_handleAttributeReport:(NSArray<NSDictionary<NSString *, id> *> *)attributeReport fromSubscription:(BOOL)isFromSubscription
{
// Note: %p to avoid double-logging the whole big structure; can be matched
// up to where we receive the attribute report, which logs pointer value and
// actual value.
MTR_LOG("%@ handling attribute report %p, fromSubscription: %@", self, attributeReport, MTR_YES_NO(isFromSubscription));

std::lock_guard lock(_lock);

// _getAttributesToReportWithReportedValues will log attribute paths reported
Expand All @@ -1863,6 +1870,7 @@ - (void)_handleAttributeReport:(NSArray<NSDictionary<NSString *, id> *> *)attrib
- (void)_injectAttributeReport:(NSArray<NSDictionary<NSString *, id> *> *)attributeReport fromSubscription:(BOOL)isFromSubscription
{
[_deviceController asyncDispatchToMatterQueue:^{
MTR_LOG("%@ injected attribute report (%p) %@", self, attributeReport, attributeReport);
[self _handleReportBegin];
dispatch_async(self.queue, ^{
[self _handleAttributeReport:attributeReport fromSubscription:isFromSubscription];
Expand Down Expand Up @@ -2396,7 +2404,7 @@ - (void)_setupSubscriptionWithReason:(NSString *)reason

auto callback = std::make_unique<SubscriptionCallback>(
^(NSArray * value) {
MTR_LOG("%@ got attribute report %@", self, value);
MTR_LOG("%@ got attribute report (%p) %@", self, value, value);
dispatch_async(self.queue, ^{
// OnAttributeData
[self _handleAttributeReport:value fromSubscription:YES];
Expand Down Expand Up @@ -2823,7 +2831,7 @@ static BOOL AttributeHasChangesOmittedQuality(MTRAttributePath * attributePath)
if (values) {
// Since the format is the same data-value dictionary, this looks like an
// attribute report
MTR_LOG("Read attribute work item [%llu] result: %@ [0x%016llX:%@:0x%llX:0x%llX]", workItemID, values, nodeID.unsignedLongLongValue, endpointID, clusterID.unsignedLongLongValue, attributeID.unsignedLongLongValue);
MTR_LOG("Read attribute work item [%llu] result: (%p) %@ [0x%016llX:%@:0x%llX:0x%llX]", workItemID, values, values, nodeID.unsignedLongLongValue, endpointID, clusterID.unsignedLongLongValue, attributeID.unsignedLongLongValue);
[self _handleAttributeReport:values fromSubscription:NO];
}

Expand Down
Loading

0 comments on commit ead3862

Please sign in to comment.