Skip to content

Commit

Permalink
Make the log download test self-contained. (#35829)
Browse files Browse the repository at this point in the history
* Make the log download test self-contained.

It should not be depending on a helper app started in a particular way; it
should just start that helper app itself.

* Address review comment: remove temp file when done.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Oct 31, 2024
1 parent 965ae17 commit 1240643
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 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
52 changes: 31 additions & 21 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,9 @@ - (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 * _Nullable sLogContentFilePath;
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 +503,42 @@ - (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];
sLogContentFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:uniqueName];
[[NSFileManager defaultManager] createFileAtPath:sLogContentFilePath
contents:[kSimpleLogContent dataUsingEncoding:NSUTF8StringEncoding]
attributes:nil];
BOOL started = [self startAppWithName:@"all-clusters"
arguments:@[
@"--end_user_support_log",
sLogContentFilePath,
]
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];
if (sLogContentFilePath != nil) {
[[NSFileManager defaultManager] removeItemAtPath:sLogContentFilePath error:nil];
}

[self shutdownStack];
[super tearDown];
}

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

+ (void)shutdownStack
{
sNeedsStackShutdown = NO;

[mSampleListener stop];
mSampleListener = nil;

Expand Down Expand Up @@ -1953,7 +1970,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 +2096,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 1240643

Please sign in to comment.