Skip to content

Commit

Permalink
Enable all the Darwin framework tests. (#22781)
Browse files Browse the repository at this point in the history
We had some tests disabled because multiple test files needed to
commission a server, and after the first one ran the second one would
fail.  The fix is to put the server back into commissioning mode after
a test is done.

Co-authored-by: Andrei Litvin <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Nov 10, 2023
1 parent 43af6a7 commit 1068204
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 3 deletions.
52 changes: 52 additions & 0 deletions src/darwin/Framework/CHIPTests/MTRDeviceTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,58 @@ - (void)test900_SubscribeAllAttributes
#if !MANUAL_INDIVIDUAL_TEST
- (void)test999_TearDown
{
// Put the device back in the state we found it: open commissioning window, no fabrics commissioned.
MTRBaseDevice * device = GetConnectedDevice();
dispatch_queue_t queue = dispatch_get_main_queue();

// Get our current fabric index, for later deletion.
XCTestExpectation * readFabricIndexExpectation = [self expectationWithDescription:@"Fabric index read"];

__block NSNumber * fabricIndex;
__auto_type * opCredsCluster = [[MTRBaseClusterOperationalCredentials alloc] initWithDevice:device endpoint:@(0) queue:queue];
[opCredsCluster readAttributeCurrentFabricIndexWithCompletion:^(NSNumber * _Nullable value, NSError * _Nullable readError) {
XCTAssertNil(readError);
XCTAssertNotNil(value);
fabricIndex = value;
[readFabricIndexExpectation fulfill];
}];

[self waitForExpectations:@[ readFabricIndexExpectation ] timeout:kTimeoutInSeconds];

// Open a commissioning window.
XCTestExpectation * openCommissioningWindowExpectation = [self expectationWithDescription:@"Commissioning window opened"];

__auto_type * adminCommissioningCluster = [[MTRBaseClusterAdministratorCommissioning alloc] initWithDevice:device
endpoint:@(0)
queue:queue];
__auto_type * openWindowParams = [[MTRAdministratorCommissioningClusterOpenBasicCommissioningWindowParams alloc] init];
openWindowParams.commissioningTimeout = @(900);
openWindowParams.timedInvokeTimeoutMs = @(50000);
[adminCommissioningCluster openBasicCommissioningWindowWithParams:openWindowParams
completion:^(NSError * _Nullable error) {
XCTAssertNil(error);
[openCommissioningWindowExpectation fulfill];
}];

[self waitForExpectations:@[ openCommissioningWindowExpectation ] timeout:kTimeoutInSeconds];

// Remove our fabric from the device.
XCTestExpectation * removeFabricExpectation = [self expectationWithDescription:@"Fabric removed"];

__auto_type * removeParams = [[MTROperationalCredentialsClusterRemoveFabricParams alloc] init];
removeParams.fabricIndex = fabricIndex;

[opCredsCluster removeFabricWithParams:removeParams
completion:^(MTROperationalCredentialsClusterNOCResponseParams * _Nullable data,
NSError * _Nullable removeError) {
XCTAssertNil(removeError);
XCTAssertNotNil(data);
XCTAssertEqualObjects(data.statusCode, @(0));
[removeFabricExpectation fulfill];
}];

[self waitForExpectations:@[ removeFabricExpectation ] timeout:kTimeoutInSeconds];

[self shutdownStack];
}
#endif
Expand Down
52 changes: 52 additions & 0 deletions src/darwin/Framework/CHIPTests/MTRXPCListenerSampleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,58 @@ - (void)test900_SubscribeClusterStateCache
#if !MANUAL_INDIVIDUAL_TEST
- (void)test999_TearDown
{
// Put the device back in the state we found it: open commissioning window, no fabrics commissioned.
MTRBaseDevice * device = [MTRBaseDevice deviceWithNodeID:@(kDeviceId) controller:sController];
dispatch_queue_t queue = dispatch_get_main_queue();

// Get our current fabric index, for later deletion.
XCTestExpectation * readFabricIndexExpectation = [self expectationWithDescription:@"Fabric index read"];

__block NSNumber * fabricIndex;
__auto_type * opCredsCluster = [[MTRBaseClusterOperationalCredentials alloc] initWithDevice:device endpoint:@(0) queue:queue];
[opCredsCluster readAttributeCurrentFabricIndexWithCompletion:^(NSNumber * _Nullable value, NSError * _Nullable readError) {
XCTAssertNil(readError);
XCTAssertNotNil(value);
fabricIndex = value;
[readFabricIndexExpectation fulfill];
}];

[self waitForExpectations:@[ readFabricIndexExpectation ] timeout:kTimeoutInSeconds];

// Open a commissioning window.
XCTestExpectation * openCommissioningWindowExpectation = [self expectationWithDescription:@"Commissioning window opened"];

__auto_type * adminCommissioningCluster = [[MTRBaseClusterAdministratorCommissioning alloc] initWithDevice:device
endpoint:@(0)
queue:queue];
__auto_type * openWindowParams = [[MTRAdministratorCommissioningClusterOpenBasicCommissioningWindowParams alloc] init];
openWindowParams.commissioningTimeout = @(900);
openWindowParams.timedInvokeTimeoutMs = @(50000);
[adminCommissioningCluster openBasicCommissioningWindowWithParams:openWindowParams
completion:^(NSError * _Nullable error) {
XCTAssertNil(error);
[openCommissioningWindowExpectation fulfill];
}];

[self waitForExpectations:@[ openCommissioningWindowExpectation ] timeout:kTimeoutInSeconds];

// Remove our fabric from the device.
XCTestExpectation * removeFabricExpectation = [self expectationWithDescription:@"Fabric removed"];

__auto_type * removeParams = [[MTROperationalCredentialsClusterRemoveFabricParams alloc] init];
removeParams.fabricIndex = fabricIndex;

[opCredsCluster removeFabricWithParams:removeParams
completion:^(MTROperationalCredentialsClusterNOCResponseParams * _Nullable data,
NSError * _Nullable removeError) {
XCTAssertNil(removeError);
XCTAssertNotNil(data);
XCTAssertEqualObjects(data.statusCode, @(0));
[removeFabricExpectation fulfill];
}];

[self waitForExpectations:@[ removeFabricExpectation ] timeout:kTimeoutInSeconds];

[self shutdownStack];
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
ReferencedContainer = "container:Matter.xcodeproj">
</BuildableReference>
<SkippedTests>
<Test
Identifier = "MTRXPCListenerSampleTests">
</Test>
</SkippedTests>
</TestableReference>
</Testables>
Expand Down

0 comments on commit 1068204

Please sign in to comment.