Skip to content

Commit

Permalink
Adding Catalyst Logic Test Support To IDB
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Mark Bridges authored and facebook-github-bot committed Dec 6, 2024
1 parent 01fe27e commit eabfbc7
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 12 deletions.
4 changes: 2 additions & 2 deletions CompanionLib/Utility/FBiOSTargetProvider.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
6 changes: 6 additions & 0 deletions FBControlCore/Management/FBiOSTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (NSDictionary<NSString *, NSString *> *)replacementMapping;

/**
Env var additions
@return a dictionary with additional env vars to add
*/
- (NSDictionary<NSString *, NSString *> *)environmentAdditions;

@end

Expand Down
5 changes: 5 additions & 0 deletions FBControlCoreTests/Doubles/FBiOSTargetDouble.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ - (NSComparisonResult)compare:(id<FBiOSTarget>)target
return @{};
}

- (NSDictionary<NSString *, NSString *> *)environmentAdditions
{
return @{};
}

- (FBFuture<NSNull *> *)installApplicationWithPath:(NSString *)path
{
return [FBFuture futureWithError:[[FBControlCoreError describe:@"Unimplemented"] build]];
Expand Down
5 changes: 5 additions & 0 deletions FBDeviceControl/Management/FBDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ - (NSComparisonResult)compare:(id<FBiOSTarget>)target
return NSDictionary.dictionary;
}

- (NSDictionary<NSString *, NSString *> *)environmentAdditions
{
return @{};
}

- (BOOL) requiresBundlesToBeSigned {
return YES;
}
Expand Down
5 changes: 5 additions & 0 deletions FBSimulatorControl/Management/FBSimulator.m
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ - (NSComparisonResult)compare:(id<FBiOSTarget>)target
};
}

- (NSDictionary<NSString *, NSString *> *)environmentAdditions
{
return @{};
}

- (BOOL)requiresBundlesToBeSigned {
return YES;
}
Expand Down
2 changes: 2 additions & 0 deletions XCTestBootstrap/MacStrategies/FBMacDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ NS_ASSUME_NONNULL_BEGIN

- (instancetype)initWithLogger:(id<FBControlCoreLogger>)logger;

- (instancetype)initWithLogger:(id<FBControlCoreLogger>)logger catalyst:(BOOL)catalyst;

/*
Restores primary device state by:
- Killling all launched process/apps
Expand Down
20 changes: 19 additions & 1 deletion XCTestBootstrap/MacStrategies/FBMacDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ @interface FBMacDevice()
@property (nonatomic, strong) NSMutableDictionary<NSString *, FBProcess *> *bundleIDToRunningTask;
@property (nonatomic, strong) NSXPCConnection *connection;
@property (nonatomic, copy) NSString *workingDirectory;
@property (nonatomic, assign, readonly) BOOL catalyst;

@end

Expand Down Expand Up @@ -92,11 +93,17 @@ - (instancetype)init
return self;
}

- (instancetype)initWithLogger:(nonnull id<FBControlCoreLogger>)logger
- (instancetype)initWithLogger:(nonnull id<FBControlCoreLogger>)logger;
{
return [self initWithLogger:logger catalyst:NO];
}

- (instancetype)initWithLogger:(nonnull id<FBControlCoreLogger>)logger catalyst:(BOOL)catalyst;
{
self = [self init];
if (self) {
_logger = logger;
_catalyst = catalyst;
}
return self;
}
Expand Down Expand Up @@ -411,6 +418,17 @@ - (NSString *)customDeviceSetPath
return NSDictionary.dictionary;
}

- (NSDictionary<NSString *, NSString *> *)environmentAdditions
{
if (self.catalyst) {
return @{@"DYLD_FORCE_PLATFORM" : @"6"};
}
else {
return NSDictionary.dictionary;
}
}


#pragma mark Not supported

- (FBFuture<id<FBVideoStream>> *)createStreamWithConfiguration:(FBVideoStreamConfiguration *)configuration
Expand Down
13 changes: 8 additions & 5 deletions XCTestBootstrap/Strategies/FBListTestStrategy.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ - (instancetype)initWithTarget:(id<FBiOSTarget, FBProcessSpawnCommands, FBXCTest
return [[FBOToolDynamicLibs
findFullPathForSanitiserDyldInBundle:self.configuration.testBundlePath onQueue:self.target.workQueue]
onQueue:self.target.workQueue fmap:^FBFuture<NSNull *> * (NSArray<NSString *> *libraries){
NSDictionary<NSString *, NSString *> *environment = [FBListTestStrategy setupEnvironmentWithDylibs:libraries shimPath:shimPath shimOutputFilePath:shimOutput.filePath bundlePath:self.configuration.testBundlePath];
NSDictionary<NSString *, NSString *> *environment = [FBListTestStrategy setupEnvironmentWithDylibs:libraries shimPath:shimPath shimOutputFilePath:shimOutput.filePath bundlePath:self.configuration.testBundlePath target:self.target];

return [[FBListTestStrategy
listTestProcessWithTarget:self.target
Expand All @@ -141,17 +141,20 @@ - (instancetype)initWithTarget:(id<FBiOSTarget, FBProcessSpawnCommands, FBXCTest
}];
}

+ (NSDictionary<NSString *, NSString *> *)setupEnvironmentWithDylibs:(NSArray *)libraries shimPath:(NSString *)shimPath shimOutputFilePath:(NSString *)shimOutputFilePath bundlePath:(NSString *)bundlePath
+ (NSDictionary<NSString *, NSString *> *)setupEnvironmentWithDylibs:(NSArray *)libraries shimPath:(NSString *)shimPath shimOutputFilePath:(NSString *)shimOutputFilePath bundlePath:(NSString *)bundlePath target:(id<FBiOSTarget>)target
{
NSMutableArray *librariesWithShim = [NSMutableArray arrayWithObject:shimPath];
[librariesWithShim addObjectsFromArray:libraries];
NSDictionary<NSString *, NSString *> *environment = @{

NSMutableDictionary<NSString *, NSString *> *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<NSArray<NSString *> *> *)launchedProcessWithExitCode:(FBFuture<NSNumber *> *)exitCode shimOutput:(id<FBProcessFileOutput>)shimOutput shimBuffer:(id<FBConsumableBuffer>)shimBuffer stdOutBuffer:(id<FBConsumableBuffer>)stdOutBuffer stdErrBuffer:(id<FBConsumableBuffer>)stdErrBuffer queue:(dispatch_queue_t)queue
Expand Down
12 changes: 8 additions & 4 deletions XCTestBootstrap/Strategies/FBLogicTestRunStrategy.m
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ - (instancetype)initWithTarget:(id<FBiOSTarget, FBProcessSpawnCommands, FBXCTest
bundlePath:self.configuration.testBundlePath
coverageConfiguration:self.configuration.coverageConfiguration
logDirectoryPath:self.configuration.logDirectoryPath
waitForDebugger:self.configuration.waitForDebugger];
waitForDebugger:self.configuration.waitForDebugger
target:self.target];
return [[self
startTestProcessWithLaunchPath:launchPath arguments:arguments environment:environment outputs:outputs temporaryDirectory:temporaryDirectory]
onQueue:self.target.workQueue fmap:^(FBFuture<NSNumber *> *exitCode) {
Expand All @@ -135,7 +136,7 @@ - (instancetype)initWithTarget:(id<FBiOSTarget, FBProcessSpawnCommands, FBXCTest
}];
}

+ (NSDictionary<NSString *, NSString *> *)setupEnvironmentWithDylibs:(NSDictionary<NSString *, NSString *> *)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<NSString *, NSString *> *)setupEnvironmentWithDylibs:(NSDictionary<NSString *, NSString *> *)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<FBiOSTarget>)target
{
NSMutableArray<NSString *> *librariesWithShim = [NSMutableArray arrayWithObject:shimPath];
[librariesWithShim addObjectsFromArray:libraries];
Expand All @@ -146,18 +147,21 @@ - (instancetype)initWithTarget:(id<FBiOSTarget, FBProcessSpawnCommands, FBXCTest
@"TEST_SHIM_BUNDLE_PATH": bundlePath,
kEnv_WaitForDebugger: waitForDebugger ? @"YES" : @"NO",
}];

if (coverageConfiguration) {
NSString *continuousCoverageCollectionMode = coverageConfiguration.shouldEnableContinuousCoverageCollection ? @"%c" : @"";
NSString *coverageFile = [NSString stringWithFormat:@"coverage_%@%@.profraw", [bundlePath lastPathComponent], continuousCoverageCollectionMode];
NSString *coveragePath = [coverageConfiguration.coverageDirectory stringByAppendingPathComponent:coverageFile];
environmentAdditions[kEnv_LLVMProfileFile] = coveragePath;
}

if (logDirectoryPath) {
environmentAdditions[kEnv_LogDirectoryPath] = logDirectoryPath;
}

NSMutableDictionary<NSString *, NSString *> *updatedEnvironment = [environment mutableCopy];
[updatedEnvironment addEntriesFromDictionary:environmentAdditions];
[updatedEnvironment addEntriesFromDictionary:target.environmentAdditions];

return [updatedEnvironment copy];
}
Expand Down Expand Up @@ -230,7 +234,7 @@ - (instancetype)initWithTarget:(id<FBiOSTarget, FBProcessSpawnCommands, FBXCTest
}
// Report from the current queue, but wait in a special queue.
dispatch_queue_t waitQueue = dispatch_queue_create("com.facebook.xctestbootstrap.debugger_wait", DISPATCH_QUEUE_SERIAL);

return [[FBProcessFetcher waitStopSignalForProcess:processIdentifier] onQueue:waitQueue chain:^FBFuture *(FBFuture *future) {
if (future.error){
return [[XCTestBootstrapError
Expand Down Expand Up @@ -319,7 +323,7 @@ - (instancetype)initWithTarget:(id<FBiOSTarget, FBProcessSpawnCommands, FBXCTest
FBProcessIO *io = [[FBProcessIO alloc] initWithStdIn:nil stdOut:[FBProcessOutput outputForDataConsumer:outputs.stdOutConsumer] stdErr:[FBProcessOutput outputForDataConsumer:outputs.stdErrConsumer]];
FBProcessSpawnConfiguration *configuration = [[FBProcessSpawnConfiguration alloc] initWithLaunchPath:launchPath arguments:arguments environment:environment io:io mode:FBProcessSpawnModePosixSpawn];
FBArchitectureProcessAdapter *adapter = [[FBArchitectureProcessAdapter alloc] init];

// Note process adapter may change process configuration launch binary path if it decided to isolate desired arch.
// For more information look at `FBArchitectureProcessAdapter` docs.
return [[[adapter adaptProcessConfiguration:configuration toAnyArchitectureIn:self.configuration.architectures queue:queue temporaryDirectory:temporaryDirectory]
Expand Down

0 comments on commit eabfbc7

Please sign in to comment.