Skip to content

Commit e05788d

Browse files
bzbarsky-applepull[bot]
authored andcommitted
Allow running individual Darwin CI tests with "-only-testing:MatterTests/*" (#25933)
Instead of using compile-time toggles for "init this way if we are running one test", just do runtime init/shutdown correctly both when running the full test suite and when running one test.
1 parent 3c37fe4 commit e05788d

File tree

4 files changed

+149
-226
lines changed

4 files changed

+149
-226
lines changed

src/darwin/Framework/CHIPTests/MTRBackwardsCompatTests.m

+30-13
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
// system dependencies
3131
#import <XCTest/XCTest.h>
3232

33-
// Set the following to 1 in order to run individual test case manually.
34-
#define MANUAL_INDIVIDUAL_TEST 0
35-
3633
static const uint16_t kPairingTimeoutInSeconds = 10;
3734
static const uint16_t kCASESetupTimeoutInSeconds = 30;
3835
static const uint16_t kTimeoutInSeconds = 3;
@@ -94,24 +91,44 @@ - (void)onCommissioningComplete:(NSError *)error
9491
@interface MTRBackwardsCompatTests : XCTestCase
9592
@end
9693

94+
static BOOL sStackInitRan = NO;
95+
static BOOL sNeedsStackShutdown = YES;
96+
9797
@implementation MTRBackwardsCompatTests
9898

99+
+ (void)tearDown
100+
{
101+
// Global teardown, runs once
102+
if (sNeedsStackShutdown) {
103+
// We don't need to worry about ResetCommissionee. If we get here,
104+
// we're running only one of our test methods (using
105+
// -only-testing:MatterTests/MTROTAProviderTests/testMethodName), since
106+
// we did not run test999_TearDown.
107+
[self shutdownStack];
108+
}
109+
}
110+
99111
- (void)setUp
100112
{
113+
// Per-test setup, runs before each test.
101114
[super setUp];
102115
[self setContinueAfterFailure:NO];
116+
117+
if (sStackInitRan == NO) {
118+
[self initStack];
119+
}
103120
}
104121

105122
- (void)tearDown
106123
{
107-
#if MANUAL_INDIVIDUAL_TEST
108-
[self shutdownStack];
109-
#endif
124+
// Per-test teardown, runs after each test.
110125
[super tearDown];
111126
}
112127

113128
- (void)initStack
114129
{
130+
sStackInitRan = YES;
131+
115132
XCTestExpectation * expectation = [self expectationWithDescription:@"Pairing Complete"];
116133

117134
__auto_type * factory = [MTRControllerFactory sharedInstance];
@@ -166,8 +183,10 @@ - (void)initStack
166183
[self waitForExpectationsWithTimeout:kCASESetupTimeoutInSeconds handler:nil];
167184
}
168185

169-
- (void)shutdownStack
186+
+ (void)shutdownStack
170187
{
188+
sNeedsStackShutdown = NO;
189+
171190
MTRDeviceController * controller = sController;
172191
XCTAssertNotNil(controller);
173192

@@ -177,12 +196,12 @@ - (void)shutdownStack
177196
[[MTRControllerFactory sharedInstance] shutdown];
178197
}
179198

180-
#if !MANUAL_INDIVIDUAL_TEST
181199
- (void)test000_SetUp
182200
{
183-
[self initStack];
201+
// Nothing to do here; our setUp method handled this already. This test
202+
// just exists to make the setup not look like it's happening inside other
203+
// tests.
184204
}
185-
#endif
186205

187206
#define CHECK_RETURN_TYPE(sig, type) \
188207
do { \
@@ -1177,12 +1196,10 @@ - (void)test046_MTRThreadOperationalDataset
11771196
CHECK_RETURN_TYPE(sig, NSData *);
11781197
}
11791198

1180-
#if !MANUAL_INDIVIDUAL_TEST
11811199
- (void)test999_TearDown
11821200
{
11831201
ResetCommissionee(GetConnectedDevice(), dispatch_get_main_queue(), self, kTimeoutInSeconds);
1184-
[self shutdownStack];
1202+
[[self class] shutdownStack];
11851203
}
1186-
#endif
11871204

11881205
@end

0 commit comments

Comments
 (0)