Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing endWork calls in MTRClusters. #23659

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/darwin/Framework/CHIP/templates/MTRClusters-src.zapt
Original file line number Diff line number Diff line change
@@ -63,19 +63,19 @@ using chip::SessionHandle;
MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) {
MTRBaseDevice *baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController];
auto * bridge = new MTR{{>callbackName}}CallbackBridge(self.callbackQueue,
^(id _Nullable value, NSError * _Nullable error) {
{{#if hasSpecificResponse}}
{{! This treats completion as taking an id for the data. This is
not great from a type-safety perspective, of course. }}
completion,
completion(value, error);
{{else}}
{{! For now, don't change the bridge API; instead just use an adapter
to invoke our completion handler. This is not great from a
type-safety perspective, of course. }}
^(id _Nullable value, NSError * _Nullable error) {
completion(error);
[workItem endWork];
},
completion(error);
{{/if}}
[workItem endWork];
},
^(ExchangeManager & exchangeManager, const SessionHandle & session, {{>callbackName}}CallbackType successCb, MTRErrorCallback failureCb, MTRCallbackBridgeBase * bridge) {
chip::Optional<uint16_t> timedInvokeTimeoutMs;
ListFreer listFreer;
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ MTR_NEWLY_AVAILABLE
* request) within the timeout window.
*
*/
@property (nonatomic, copy, nullable) NSNumber * timedInvokeTimeoutMs;
@property (nonatomic, copy, nullable) NSNumber * timedInvokeTimeoutMs {{#if (isStrEqual source "server")}}MTR_NEWLY_DEPRECATED("Timed invoke does not make sense for server to client commands"){{/if}};

- (instancetype)init;
- (id)copyWithZone:(NSZone * _Nullable)zone;
571 changes: 480 additions & 91 deletions src/darwin/Framework/CHIP/zap-generated/MTRClusters.mm

Large diffs are not rendered by default.

168 changes: 112 additions & 56 deletions src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.h

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

89 changes: 89 additions & 0 deletions src/darwin/Framework/CHIPTests/MTRDeviceTests.m
Original file line number Diff line number Diff line change
@@ -770,6 +770,7 @@ - (void)test011_ReadCachedAttribute
// reportHandler returns TRUE if it got the things it was looking for or if there's an error.
__block BOOL (^reportHandler)(NSArray * _Nullable value, NSError * _Nullable error);
__auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(2) maxInterval:@(60)];
params.resubscribeIfLost = NO;
[device subscribeWithQueue:queue
params:params
attributeCacheContainer:attributeCacheContainer
@@ -836,6 +837,7 @@ - (void)test011_ReadCachedAttribute
XCTestExpectation * newSubscriptionEstablished = [self expectationWithDescription:@"New subscription established"];
MTRSubscribeParams * newParams = [[MTRSubscribeParams alloc] initWithMinInterval:@(2) maxInterval:@(60)];
newParams.replaceExistingSubscriptions = NO;
newParams.resubscribeIfLost = NO;
[cluster subscribeAttributeOnOffWithParams:newParams
subscriptionEstablished:^{
NSLog(@"New subscription was established");
@@ -1023,6 +1025,7 @@ - (void)test012_SubscriptionError
// Subscribe
XCTestExpectation * expectation = [self expectationWithDescription:@"subscribe OnOff attribute"];
MTRSubscribeParams * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(1) maxInterval:@(10)];
params.resubscribeIfLost = NO;
[device subscribeToAttributesWithEndpointID:@1
clusterID:@6
attributeID:@0
@@ -1432,6 +1435,91 @@ - (void)test018_SubscriptionErrorWhenNotResubscribing
[self waitForExpectations:@[ errorExpectation ] timeout:60];
}

- (void)test019_MTRDeviceMultipleCommands
{
#if MANUAL_INDIVIDUAL_TEST
[self initStack];
[self waitForCommissionee];
#endif

__auto_type * device = [MTRDevice deviceWithNodeID:kDeviceId deviceController:sController];
dispatch_queue_t queue = dispatch_get_main_queue();

__auto_type * opcredsCluster = [[MTRClusterOperationalCredentials alloc] initWithDevice:device endpointID:@(0) queue:queue];
__auto_type * onOffCluster = [[MTRClusterOnOff alloc] initWithDevice:device endpointID:@(1) queue:queue];
__auto_type * badOnOffCluster = [[MTRClusterOnOff alloc] initWithDevice:device endpointID:@(0) queue:queue];

XCTestExpectation * onExpectation = [self expectationWithDescription:@"On command executed"];
[onOffCluster onWithParams:nil
expectedValues:nil
expectedValueInterval:nil
completion:^(NSError * _Nullable error) {
XCTAssertNil(error);
[onExpectation fulfill];
}];

XCTestExpectation * offFailedExpectation = [self expectationWithDescription:@"Off command failed"];
[badOnOffCluster offWithParams:nil
expectedValues:nil
expectedValueInterval:nil
completion:^(NSError * _Nullable error) {
XCTAssertNotNil(error);
[offFailedExpectation fulfill];
}];

XCTestExpectation * updateLabelExpectation = [self expectationWithDescription:@"Fabric label updated"];
__auto_type * params = [[MTROperationalCredentialsClusterUpdateFabricLabelParams alloc] init];
params.label = @("Test");
[opcredsCluster updateFabricLabelWithParams:params
expectedValues:nil
expectedValueInterval:nil
completion:^(MTROperationalCredentialsClusterNOCResponseParams * _Nullable data,
NSError * _Nullable error) {
XCTAssertNil(error);
XCTAssertNotNil(data);
XCTAssertEqualObjects(data.statusCode, @(0));
XCTAssertNotNil(data.fabricIndex);
[updateLabelExpectation fulfill];
}];

XCTestExpectation * offExpectation = [self expectationWithDescription:@"Off command executed"];
[onOffCluster offWithParams:nil
expectedValues:nil
expectedValueInterval:nil
completion:^(NSError * _Nullable error) {
XCTAssertNil(error);
[offExpectation fulfill];
}];

XCTestExpectation * onFailedExpectation = [self expectationWithDescription:@"On command failed"];
[badOnOffCluster onWithParams:nil
expectedValues:nil
expectedValueInterval:nil
completion:^(NSError * _Nullable error) {
XCTAssertNotNil(error);
[onFailedExpectation fulfill];
}];

XCTestExpectation * updateLabelFailedExpectation = [self expectationWithDescription:@"Fabric label update failed"];
params.label = @("12345678901234567890123445678901234567890"); // Too long
[opcredsCluster updateFabricLabelWithParams:params
expectedValues:nil
expectedValueInterval:nil
completion:^(MTROperationalCredentialsClusterNOCResponseParams * _Nullable data,
NSError * _Nullable error) {
XCTAssertNotNil(error);
XCTAssertNil(data);
[updateLabelFailedExpectation fulfill];
}];

[self waitForExpectations:@[
onExpectation, offFailedExpectation, updateLabelExpectation, offExpectation, onFailedExpectation,
updateLabelFailedExpectation
]
timeout:60
enforceOrder:YES];
}

- (void)test900_SubscribeAllAttributes
{
#if MANUAL_INDIVIDUAL_TEST
@@ -1453,6 +1541,7 @@ - (void)test900_SubscribeAllAttributes
__block void (^reportHandler)(id _Nullable values, NSError * _Nullable error) = nil;

MTRSubscribeParams * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(2) maxInterval:@(10)];
params.resubscribeIfLost = NO;
[device subscribeToAttributesWithEndpointID:@1
clusterID:@6
attributeID:@0xffffffff