Skip to content

Commit 1100364

Browse files
bzbarsky-appleandy31415
authored andcommitted
Enable all the Darwin framework tests. (#22781)
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 <andy314@gmail.com>
1 parent 5890397 commit 1100364

File tree

3 files changed

+104
-3
lines changed

3 files changed

+104
-3
lines changed

src/darwin/Framework/CHIPTests/MTRDeviceTests.m

+52
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,58 @@ - (void)test900_SubscribeAllAttributes
13571357
#if !MANUAL_INDIVIDUAL_TEST
13581358
- (void)test999_TearDown
13591359
{
1360+
// Put the device back in the state we found it: open commissioning window, no fabrics commissioned.
1361+
MTRBaseDevice * device = GetConnectedDevice();
1362+
dispatch_queue_t queue = dispatch_get_main_queue();
1363+
1364+
// Get our current fabric index, for later deletion.
1365+
XCTestExpectation * readFabricIndexExpectation = [self expectationWithDescription:@"Fabric index read"];
1366+
1367+
__block NSNumber * fabricIndex;
1368+
__auto_type * opCredsCluster = [[MTRBaseClusterOperationalCredentials alloc] initWithDevice:device endpoint:@(0) queue:queue];
1369+
[opCredsCluster readAttributeCurrentFabricIndexWithCompletion:^(NSNumber * _Nullable value, NSError * _Nullable readError) {
1370+
XCTAssertNil(readError);
1371+
XCTAssertNotNil(value);
1372+
fabricIndex = value;
1373+
[readFabricIndexExpectation fulfill];
1374+
}];
1375+
1376+
[self waitForExpectations:@[ readFabricIndexExpectation ] timeout:kTimeoutInSeconds];
1377+
1378+
// Open a commissioning window.
1379+
XCTestExpectation * openCommissioningWindowExpectation = [self expectationWithDescription:@"Commissioning window opened"];
1380+
1381+
__auto_type * adminCommissioningCluster = [[MTRBaseClusterAdministratorCommissioning alloc] initWithDevice:device
1382+
endpoint:@(0)
1383+
queue:queue];
1384+
__auto_type * openWindowParams = [[MTRAdministratorCommissioningClusterOpenBasicCommissioningWindowParams alloc] init];
1385+
openWindowParams.commissioningTimeout = @(900);
1386+
openWindowParams.timedInvokeTimeoutMs = @(50000);
1387+
[adminCommissioningCluster openBasicCommissioningWindowWithParams:openWindowParams
1388+
completion:^(NSError * _Nullable error) {
1389+
XCTAssertNil(error);
1390+
[openCommissioningWindowExpectation fulfill];
1391+
}];
1392+
1393+
[self waitForExpectations:@[ openCommissioningWindowExpectation ] timeout:kTimeoutInSeconds];
1394+
1395+
// Remove our fabric from the device.
1396+
XCTestExpectation * removeFabricExpectation = [self expectationWithDescription:@"Fabric removed"];
1397+
1398+
__auto_type * removeParams = [[MTROperationalCredentialsClusterRemoveFabricParams alloc] init];
1399+
removeParams.fabricIndex = fabricIndex;
1400+
1401+
[opCredsCluster removeFabricWithParams:removeParams
1402+
completion:^(MTROperationalCredentialsClusterNOCResponseParams * _Nullable data,
1403+
NSError * _Nullable removeError) {
1404+
XCTAssertNil(removeError);
1405+
XCTAssertNotNil(data);
1406+
XCTAssertEqualObjects(data.statusCode, @(0));
1407+
[removeFabricExpectation fulfill];
1408+
}];
1409+
1410+
[self waitForExpectations:@[ removeFabricExpectation ] timeout:kTimeoutInSeconds];
1411+
13601412
[self shutdownStack];
13611413
}
13621414
#endif

src/darwin/Framework/CHIPTests/MTRXPCListenerSampleTests.m

+52
Original file line numberDiff line numberDiff line change
@@ -1813,6 +1813,58 @@ - (void)test900_SubscribeClusterStateCache
18131813
#if !MANUAL_INDIVIDUAL_TEST
18141814
- (void)test999_TearDown
18151815
{
1816+
// Put the device back in the state we found it: open commissioning window, no fabrics commissioned.
1817+
MTRBaseDevice * device = [MTRBaseDevice deviceWithNodeID:@(kDeviceId) controller:sController];
1818+
dispatch_queue_t queue = dispatch_get_main_queue();
1819+
1820+
// Get our current fabric index, for later deletion.
1821+
XCTestExpectation * readFabricIndexExpectation = [self expectationWithDescription:@"Fabric index read"];
1822+
1823+
__block NSNumber * fabricIndex;
1824+
__auto_type * opCredsCluster = [[MTRBaseClusterOperationalCredentials alloc] initWithDevice:device endpoint:@(0) queue:queue];
1825+
[opCredsCluster readAttributeCurrentFabricIndexWithCompletion:^(NSNumber * _Nullable value, NSError * _Nullable readError) {
1826+
XCTAssertNil(readError);
1827+
XCTAssertNotNil(value);
1828+
fabricIndex = value;
1829+
[readFabricIndexExpectation fulfill];
1830+
}];
1831+
1832+
[self waitForExpectations:@[ readFabricIndexExpectation ] timeout:kTimeoutInSeconds];
1833+
1834+
// Open a commissioning window.
1835+
XCTestExpectation * openCommissioningWindowExpectation = [self expectationWithDescription:@"Commissioning window opened"];
1836+
1837+
__auto_type * adminCommissioningCluster = [[MTRBaseClusterAdministratorCommissioning alloc] initWithDevice:device
1838+
endpoint:@(0)
1839+
queue:queue];
1840+
__auto_type * openWindowParams = [[MTRAdministratorCommissioningClusterOpenBasicCommissioningWindowParams alloc] init];
1841+
openWindowParams.commissioningTimeout = @(900);
1842+
openWindowParams.timedInvokeTimeoutMs = @(50000);
1843+
[adminCommissioningCluster openBasicCommissioningWindowWithParams:openWindowParams
1844+
completion:^(NSError * _Nullable error) {
1845+
XCTAssertNil(error);
1846+
[openCommissioningWindowExpectation fulfill];
1847+
}];
1848+
1849+
[self waitForExpectations:@[ openCommissioningWindowExpectation ] timeout:kTimeoutInSeconds];
1850+
1851+
// Remove our fabric from the device.
1852+
XCTestExpectation * removeFabricExpectation = [self expectationWithDescription:@"Fabric removed"];
1853+
1854+
__auto_type * removeParams = [[MTROperationalCredentialsClusterRemoveFabricParams alloc] init];
1855+
removeParams.fabricIndex = fabricIndex;
1856+
1857+
[opCredsCluster removeFabricWithParams:removeParams
1858+
completion:^(MTROperationalCredentialsClusterNOCResponseParams * _Nullable data,
1859+
NSError * _Nullable removeError) {
1860+
XCTAssertNil(removeError);
1861+
XCTAssertNotNil(data);
1862+
XCTAssertEqualObjects(data.statusCode, @(0));
1863+
[removeFabricExpectation fulfill];
1864+
}];
1865+
1866+
[self waitForExpectations:@[ removeFabricExpectation ] timeout:kTimeoutInSeconds];
1867+
18161868
[self shutdownStack];
18171869
}
18181870
#endif

src/darwin/Framework/Matter.xcodeproj/xcshareddata/xcschemes/Matter Framework Tests.xcscheme

-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838
ReferencedContainer = "container:Matter.xcodeproj">
3939
</BuildableReference>
4040
<SkippedTests>
41-
<Test
42-
Identifier = "MTRXPCListenerSampleTests">
43-
</Test>
4441
</SkippedTests>
4542
</TestableReference>
4643
</Testables>

0 commit comments

Comments
 (0)