From eabfbc769396e927fee881f6b5a385f04a656a04 Mon Sep 17 00:00:00 2001 From: Mark Bridges Date: Fri, 6 Dec 2024 08:05:13 -0800 Subject: [PATCH] Adding Catalyst Logic Test Support To IDB Summary: Taking the proof of concept for running catalyst tests from D32948562 and implementing a new test type for it. We've now got two new run types on the idb-cli - `idb-xctest catalyst run logic` - `idb-xctest catalyst list` Differential Revision: D66762166 fbshipit-source-id: 51bd6647141ec6409e269c5437cdd7d571b51275 --- CompanionLib/Utility/FBiOSTargetProvider.m | 4 ++-- FBControlCore/Management/FBiOSTarget.h | 6 ++++++ .../Doubles/FBiOSTargetDouble.m | 5 +++++ FBDeviceControl/Management/FBDevice.m | 5 +++++ FBSimulatorControl/Management/FBSimulator.m | 5 +++++ XCTestBootstrap/MacStrategies/FBMacDevice.h | 2 ++ XCTestBootstrap/MacStrategies/FBMacDevice.m | 20 ++++++++++++++++++- .../Strategies/FBListTestStrategy.m | 13 +++++++----- .../Strategies/FBLogicTestRunStrategy.m | 12 +++++++---- 9 files changed, 60 insertions(+), 12 deletions(-) diff --git a/CompanionLib/Utility/FBiOSTargetProvider.m b/CompanionLib/Utility/FBiOSTargetProvider.m index 0f9213e57..cd9c3c5cd 100644 --- a/CompanionLib/Utility/FBiOSTargetProvider.m +++ b/CompanionLib/Utility/FBiOSTargetProvider.m @@ -41,11 +41,11 @@ @implementation FBiOSTargetProvider if (![lifecycle conformsToProtocol:@protocol(FBSimulatorLifecycleCommands)]) { return [FBFuture futureWithResult:target];; } - + if (FBXcodeConfiguration.isXcode12_5OrGreater) { return [FBFuture futureWithResult:target]; } - + return [[lifecycle connectToBridge] mapReplace:target]; diff --git a/FBControlCore/Management/FBiOSTarget.h b/FBControlCore/Management/FBiOSTarget.h index 58114d1bd..e3f67cec7 100644 --- a/FBControlCore/Management/FBiOSTarget.h +++ b/FBControlCore/Management/FBiOSTarget.h @@ -164,6 +164,12 @@ NS_ASSUME_NONNULL_BEGIN */ - (NSDictionary *)replacementMapping; +/** + Env var additions + + @return a dictionary with additional env vars to add + */ +- (NSDictionary *)environmentAdditions; @end diff --git a/FBControlCoreTests/Doubles/FBiOSTargetDouble.m b/FBControlCoreTests/Doubles/FBiOSTargetDouble.m index 4d00f8a92..4378f1d2a 100644 --- a/FBControlCoreTests/Doubles/FBiOSTargetDouble.m +++ b/FBControlCoreTests/Doubles/FBiOSTargetDouble.m @@ -48,6 +48,11 @@ - (NSComparisonResult)compare:(id)target return @{}; } +- (NSDictionary *)environmentAdditions +{ + return @{}; +} + - (FBFuture *)installApplicationWithPath:(NSString *)path { return [FBFuture futureWithError:[[FBControlCoreError describe:@"Unimplemented"] build]]; diff --git a/FBDeviceControl/Management/FBDevice.m b/FBDeviceControl/Management/FBDevice.m index ca71cd3ba..0aab38971 100644 --- a/FBDeviceControl/Management/FBDevice.m +++ b/FBDeviceControl/Management/FBDevice.m @@ -131,6 +131,11 @@ - (NSComparisonResult)compare:(id)target return NSDictionary.dictionary; } +- (NSDictionary *)environmentAdditions +{ + return @{}; +} + - (BOOL) requiresBundlesToBeSigned { return YES; } diff --git a/FBSimulatorControl/Management/FBSimulator.m b/FBSimulatorControl/Management/FBSimulator.m index 1031526d4..9f469fdc3 100644 --- a/FBSimulatorControl/Management/FBSimulator.m +++ b/FBSimulatorControl/Management/FBSimulator.m @@ -191,6 +191,11 @@ - (NSComparisonResult)compare:(id)target }; } +- (NSDictionary *)environmentAdditions +{ + return @{}; +} + - (BOOL)requiresBundlesToBeSigned { return YES; } diff --git a/XCTestBootstrap/MacStrategies/FBMacDevice.h b/XCTestBootstrap/MacStrategies/FBMacDevice.h index fc5b7f4a5..635f0e4a2 100644 --- a/XCTestBootstrap/MacStrategies/FBMacDevice.h +++ b/XCTestBootstrap/MacStrategies/FBMacDevice.h @@ -18,6 +18,8 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithLogger:(id)logger; +- (instancetype)initWithLogger:(id)logger catalyst:(BOOL)catalyst; + /* Restores primary device state by: - Killling all launched process/apps diff --git a/XCTestBootstrap/MacStrategies/FBMacDevice.m b/XCTestBootstrap/MacStrategies/FBMacDevice.m index 57ed0f6f7..a24cb7667 100644 --- a/XCTestBootstrap/MacStrategies/FBMacDevice.m +++ b/XCTestBootstrap/MacStrategies/FBMacDevice.m @@ -27,6 +27,7 @@ @interface FBMacDevice() @property (nonatomic, strong) NSMutableDictionary *bundleIDToRunningTask; @property (nonatomic, strong) NSXPCConnection *connection; @property (nonatomic, copy) NSString *workingDirectory; +@property (nonatomic, assign, readonly) BOOL catalyst; @end @@ -92,11 +93,17 @@ - (instancetype)init return self; } -- (instancetype)initWithLogger:(nonnull id)logger +- (instancetype)initWithLogger:(nonnull id)logger; +{ + return [self initWithLogger:logger catalyst:NO]; +} + +- (instancetype)initWithLogger:(nonnull id)logger catalyst:(BOOL)catalyst; { self = [self init]; if (self) { _logger = logger; + _catalyst = catalyst; } return self; } @@ -411,6 +418,17 @@ - (NSString *)customDeviceSetPath return NSDictionary.dictionary; } +- (NSDictionary *)environmentAdditions +{ + if (self.catalyst) { + return @{@"DYLD_FORCE_PLATFORM" : @"6"}; + } + else { + return NSDictionary.dictionary; + } +} + + #pragma mark Not supported - (FBFuture> *)createStreamWithConfiguration:(FBVideoStreamConfiguration *)configuration diff --git a/XCTestBootstrap/Strategies/FBListTestStrategy.m b/XCTestBootstrap/Strategies/FBListTestStrategy.m index ab171cb60..72b5f6473 100644 --- a/XCTestBootstrap/Strategies/FBListTestStrategy.m +++ b/XCTestBootstrap/Strategies/FBListTestStrategy.m @@ -117,7 +117,7 @@ - (instancetype)initWithTarget:(id * (NSArray *libraries){ - NSDictionary *environment = [FBListTestStrategy setupEnvironmentWithDylibs:libraries shimPath:shimPath shimOutputFilePath:shimOutput.filePath bundlePath:self.configuration.testBundlePath]; + NSDictionary *environment = [FBListTestStrategy setupEnvironmentWithDylibs:libraries shimPath:shimPath shimOutputFilePath:shimOutput.filePath bundlePath:self.configuration.testBundlePath target:self.target]; return [[FBListTestStrategy listTestProcessWithTarget:self.target @@ -141,17 +141,20 @@ - (instancetype)initWithTarget:(id *)setupEnvironmentWithDylibs:(NSArray *)libraries shimPath:(NSString *)shimPath shimOutputFilePath:(NSString *)shimOutputFilePath bundlePath:(NSString *)bundlePath ++ (NSDictionary *)setupEnvironmentWithDylibs:(NSArray *)libraries shimPath:(NSString *)shimPath shimOutputFilePath:(NSString *)shimOutputFilePath bundlePath:(NSString *)bundlePath target:(id)target { NSMutableArray *librariesWithShim = [NSMutableArray arrayWithObject:shimPath]; [librariesWithShim addObjectsFromArray:libraries]; - NSDictionary *environment = @{ + + NSMutableDictionary *environment = [@{ @"DYLD_INSERT_LIBRARIES": [librariesWithShim componentsJoinedByString:@":"], @"TEST_SHIM_OUTPUT_PATH": shimOutputFilePath, @"TEST_SHIM_BUNDLE_PATH": bundlePath, - }; + } mutableCopy]; + + [environment addEntriesFromDictionary:target.environmentAdditions]; - return environment; + return [environment copy]; } + (FBFuture *> *)launchedProcessWithExitCode:(FBFuture *)exitCode shimOutput:(id)shimOutput shimBuffer:(id)shimBuffer stdOutBuffer:(id)stdOutBuffer stdErrBuffer:(id)stdErrBuffer queue:(dispatch_queue_t)queue diff --git a/XCTestBootstrap/Strategies/FBLogicTestRunStrategy.m b/XCTestBootstrap/Strategies/FBLogicTestRunStrategy.m index 14728bff8..36a7f3b1a 100644 --- a/XCTestBootstrap/Strategies/FBLogicTestRunStrategy.m +++ b/XCTestBootstrap/Strategies/FBLogicTestRunStrategy.m @@ -125,7 +125,8 @@ - (instancetype)initWithTarget:(id *exitCode) { @@ -135,7 +136,7 @@ - (instancetype)initWithTarget:(id *)setupEnvironmentWithDylibs:(NSDictionary *)environment withLibraries:(NSArray *)libraries shimOutputFilePath:(NSString *)shimOutputFilePath shimPath:(NSString *)shimPath bundlePath:(NSString *)bundlePath coverageConfiguration:(nullable FBCodeCoverageConfiguration *)coverageConfiguration logDirectoryPath:(nullable NSString *)logDirectoryPath waitForDebugger:(BOOL)waitForDebugger ++ (NSDictionary *)setupEnvironmentWithDylibs:(NSDictionary *)environment withLibraries:(NSArray *)libraries shimOutputFilePath:(NSString *)shimOutputFilePath shimPath:(NSString *)shimPath bundlePath:(NSString *)bundlePath coverageConfiguration:(nullable FBCodeCoverageConfiguration *)coverageConfiguration logDirectoryPath:(nullable NSString *)logDirectoryPath waitForDebugger:(BOOL)waitForDebugger target:(id)target { NSMutableArray *librariesWithShim = [NSMutableArray arrayWithObject:shimPath]; [librariesWithShim addObjectsFromArray:libraries]; @@ -146,18 +147,21 @@ - (instancetype)initWithTarget:(id *updatedEnvironment = [environment mutableCopy]; [updatedEnvironment addEntriesFromDictionary:environmentAdditions]; + [updatedEnvironment addEntriesFromDictionary:target.environmentAdditions]; return [updatedEnvironment copy]; } @@ -230,7 +234,7 @@ - (instancetype)initWithTarget:(id