From 1240643c935a5ce7225dcccd76cb8873a194c408 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 27 Sep 2024 19:44:42 -0400 Subject: [PATCH] Make the log download test self-contained. (#35829) * 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. --- .github/workflows/darwin.yaml | 3 +- .../CHIPTests/MTRXPCListenerSampleTests.m | 52 +++++++++++-------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/.github/workflows/darwin.yaml b/.github/workflows/darwin.yaml index 9eeac9118ef9d3..4c25026840e5d1 100644 --- a/.github/workflows/darwin.yaml +++ b/.github/workflows/darwin.yaml @@ -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 diff --git a/src/darwin/Framework/CHIPTests/MTRXPCListenerSampleTests.m b/src/darwin/Framework/CHIPTests/MTRXPCListenerSampleTests.m index f16775af0f9d95..cd7bfa53b6697d 100644 --- a/src/darwin/Framework/CHIPTests/MTRXPCListenerSampleTests.m +++ b/src/darwin/Framework/CHIPTests/MTRXPCListenerSampleTests.m @@ -23,14 +23,14 @@ #import #import "MTRErrorTestUtils.h" +#import "MTRTestCase+ServerAppRunner.h" +#import "MTRTestCase.h" #import "MTRTestKeys.h" -#import "MTRTestResetCommissioneeHelper.h" #import "MTRTestStorage.h" #import // For INFINITY // system dependencies -#import #import static uint16_t kTestVendorId = 0xFFF1u; @@ -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. @@ -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 @@ -591,8 +610,6 @@ - (void)initStack + (void)shutdownStack { - sNeedsStackShutdown = NO; - [mSampleListener stop]; mSampleListener = nil; @@ -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]; @@ -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