Skip to content

Commit

Permalink
Make the log download test self-contained.
Browse files Browse the repository at this point in the history
It should not be depending on a helper app started in a particular way; it
should just start that helper app itself.
  • Loading branch information
bzbarsky-apple committed Sep 27, 2024
1 parent f509f67 commit 0607ae9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/darwin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ jobs:
working-directory: src/darwin/Framework
run: |
mkdir -p /tmp/darwin/framework-tests
echo "This is a simple log" > /tmp/darwin/framework-tests/end_user_support_log.txt
../../../out/debug/all-clusters-app/chip-all-clusters-app --interface-id -1 --end_user_support_log /tmp/darwin/framework-tests/end_user_support_log.txt > >(tee /tmp/darwin/framework-tests/all-cluster-app.log) 2> >(tee /tmp/darwin/framework-tests/all-cluster-app-err.log >&2) &
../../../out/debug/all-clusters-app/chip-all-clusters-app --interface-id -1 > >(tee /tmp/darwin/framework-tests/all-cluster-app.log) 2> >(tee /tmp/darwin/framework-tests/all-cluster-app-err.log >&2) &
export TEST_RUNNER_ASAN_OPTIONS=__CURRENT_VALUE__:detect_stack_use_after_return=1
Expand Down
49 changes: 27 additions & 22 deletions src/darwin/Framework/CHIPTests/MTRXPCListenerSampleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
#import <Matter/Matter.h>

#import "MTRErrorTestUtils.h"
#import "MTRTestCase+ServerAppRunner.h"
#import "MTRTestCase.h"
#import "MTRTestKeys.h"
#import "MTRTestResetCommissioneeHelper.h"
#import "MTRTestStorage.h"

#import <math.h> // For INFINITY

// system dependencies
#import <XCTest/XCTest.h>
#import <os/lock.h>

static uint16_t kTestVendorId = 0xFFF1u;
Expand Down Expand Up @@ -418,7 +418,8 @@ - (void)readAttributeCacheWithController:(id _Nullable)controller
static const uint16_t kPairingTimeoutInSeconds = 30;
static const uint16_t kTimeoutInSeconds = 3;
static const uint64_t kDeviceId = 0x12344321;
static NSString * kOnboardingPayload = @"MT:-24J0AFN00KA0648G00";
static NSString * kOnboardingPayload = @"MT:Y.K90SO527JA0648G00";
static NSString * kSimpleLogContent = @"This is a simple log\n";
static const uint16_t kLocalPort = 5541;

// This test suite reuses a device object to speed up the test process for CI.
Expand Down Expand Up @@ -501,25 +502,38 @@ - (BOOL)unitTestShouldSkipExpectedValuesForWrite:(MTRDevice *)device
}
@end

@interface MTRXPCListenerSampleTests : XCTestCase
@interface MTRXPCListenerSampleTests : MTRTestCase

@end

static BOOL sStackInitRan = NO;
static BOOL sNeedsStackShutdown = YES;

@implementation MTRXPCListenerSampleTests

+ (void)setUp
{
// Global setup, runs once.
[super setUp];

__auto_type * uniqueName = [[NSUUID UUID] UUIDString];
__auto_type * uniquePath = [NSTemporaryDirectory() stringByAppendingPathComponent:uniqueName];
[[NSFileManager defaultManager] createFileAtPath:uniquePath
contents:[kSimpleLogContent dataUsingEncoding:NSUTF8StringEncoding]
attributes:nil];
BOOL started = [self startAppWithName:@"all-clusters"
arguments:@[
@"--end_user_support_log",
uniquePath,
]
payload:kOnboardingPayload];
XCTAssertTrue(started);
}

+ (void)tearDown
{
// Global teardown, runs once
if (sNeedsStackShutdown) {
// We don't need to worry about ResetCommissionee. If we get here,
// we're running only one of our test methods (using
// -only-testing:MatterTests/MTROTAProviderTests/testMethodName), since
// we did not run test999_TearDown.
// [self shutdownStack];
}
[self shutdownStack];
[super tearDown];
}

- (void)setUp
Expand Down Expand Up @@ -591,8 +605,6 @@ - (void)initStack

+ (void)shutdownStack
{
sNeedsStackShutdown = NO;

[mSampleListener stop];
mSampleListener = nil;

Expand Down Expand Up @@ -1953,7 +1965,7 @@ - (void)test016_DownloadLog
NSError * readError;
NSString * fileContent = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&readError];
XCTAssertNil(readError);
XCTAssertEqualObjects(fileContent, @"This is a simple log\n");
XCTAssertEqualObjects(fileContent, kSimpleLogContent);
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil];
Expand Down Expand Up @@ -2079,11 +2091,4 @@ - (void)test900_SubscribeClusterStateCache
[self waitForExpectations:@[ expectation ] timeout:kTimeoutInSeconds];
}

- (void)test999_TearDown
{
ResetCommissionee(
[MTRBaseDevice deviceWithNodeID:@(kDeviceId) controller:sController], dispatch_get_main_queue(), self, kTimeoutInSeconds);
[[self class] shutdownStack];
}

@end

0 comments on commit 0607ae9

Please sign in to comment.