Skip to content

Commit

Permalink
Lean on FBXCTestExtendedCommands for obtaining shims
Browse files Browse the repository at this point in the history
Summary:
This solves a few issues:

1) Allow for the commands implementation to cache intelligently and avoid over-fetching
2) Make passing the shims down easier since we can query the implementation

There are some other examples of places where the shims are used, but those can be changed in time to avoid needing to always inject from above

Reviewed By: jbardini

Differential Revision: D29458524

fbshipit-source-id: 40786a0f73a726cec1518b10d014ae4f78c84d57
  • Loading branch information
lawrencelomax authored and facebook-github-bot committed Jul 8, 2021
1 parent 455697e commit 48b8631
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 130 deletions.
5 changes: 5 additions & 0 deletions FBControlCore/Commands/FBXCTestCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (FBFuture<NSArray<NSString *> *> *)listTestsForBundleAtPath:(NSString *)bundlePath timeout:(NSTimeInterval)timeout withAppAtPath:(nullable NSString *)appPath;

/**
Returns the platform specific shims.
*/
- (FBFuture<NSString *> *)extendedTestShim;

/**
The Path to the xctest executable.
*/
Expand Down
36 changes: 20 additions & 16 deletions FBSimulatorControl/Commands/FBSimulatorXCTestCommands.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,17 @@ - (instancetype)initWithSimulator:(FBSimulator *)simulator

- (FBFuture<NSArray<NSString *> *> *)listTestsForBundleAtPath:(NSString *)bundlePath timeout:(NSTimeInterval)timeout withAppAtPath:(NSString *)appPath
{
return [[FBXCTestShimConfiguration
defaultShimConfigurationWithLogger:self.simulator.logger]
onQueue:self.simulator.workQueue fmap:^(FBXCTestShimConfiguration *shims) {
FBListTestConfiguration *configuration = [FBListTestConfiguration
configurationWithShims:shims
environment:@{}
workingDirectory:self.simulator.auxillaryDirectory
testBundlePath:bundlePath
runnerAppPath:appPath
waitForDebugger:NO
timeout:timeout];

return [[[FBListTestStrategy alloc]
initWithTarget:self.simulator configuration:configuration shimPath:shims.iOSSimulatorTestShimPath logger:self.simulator.logger]
listTests];
}];
FBListTestConfiguration *configuration = [FBListTestConfiguration
configurationWithEnvironment:@{}
workingDirectory:self.simulator.auxillaryDirectory
testBundlePath:bundlePath
runnerAppPath:appPath
waitForDebugger:NO
timeout:timeout];

return [[[FBListTestStrategy alloc]
initWithTarget:self.simulator configuration:configuration logger:self.simulator.logger]
listTests];
}

- (FBFutureContext<NSNumber *> *)transportForTestManagerService
Expand Down Expand Up @@ -141,6 +136,15 @@ - (instancetype)initWithSimulator:(FBSimulator *)simulator
}];
}

- (FBFuture<NSString *> *)extendedTestShim
{
return [[FBXCTestShimConfiguration
defaultShimConfigurationWithLogger:self.simulator.logger]
onQueue:self.simulator.asyncQueue map:^(FBXCTestShimConfiguration *shims) {
return shims.iOSSimulatorTestShimPath;
}];
}

- (NSString *)xctestPath
{
return [FBXcodeConfiguration.developerDirectory
Expand Down
13 changes: 4 additions & 9 deletions XCTestBootstrap/Configuration/FBXCTestConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,7 @@ extern FBXCTestType const FBXCTestTypeListTest;
The Default Initializer.
This should not be called directly.
*/
- (instancetype)initWithShims:(nullable FBXCTestShimConfiguration *)shims environment:(NSDictionary<NSString *, NSString *> *)environment workingDirectory:(NSString *)workingDirectory testBundlePath:(NSString *)testBundlePath waitForDebugger:(BOOL)waitForDebugger timeout:(NSTimeInterval)timeout;

/**
The Shims to use for relevant test runs.
*/
@property (nonatomic, copy, nullable, readonly) FBXCTestShimConfiguration *shims;
- (instancetype)initWithEnvironment:(NSDictionary<NSString *, NSString *> *)environment workingDirectory:(NSString *)workingDirectory testBundlePath:(NSString *)testBundlePath waitForDebugger:(BOOL)waitForDebugger timeout:(NSTimeInterval)timeout;

/**
The Environment Variables for the Process-Under-Test that is launched.
Expand Down Expand Up @@ -107,7 +102,7 @@ extern FBXCTestType const FBXCTestTypeListTest;
/**
The Designated Initializer.
*/
+ (instancetype)configurationWithShims:(FBXCTestShimConfiguration *)shims environment:(NSDictionary<NSString *, NSString *> *)environment workingDirectory:(NSString *)workingDirectory testBundlePath:(NSString *)testBundlePath runnerAppPath:(nullable NSString *)runnerAppPath waitForDebugger:(BOOL)waitForDebugger timeout:(NSTimeInterval)timeout;
+ (instancetype)configurationWithEnvironment:(NSDictionary<NSString *, NSString *> *)environment workingDirectory:(NSString *)workingDirectory testBundlePath:(NSString *)testBundlePath runnerAppPath:(nullable NSString *)runnerAppPath waitForDebugger:(BOOL)waitForDebugger timeout:(NSTimeInterval)timeout;

@property (nonatomic, copy, readonly) NSString *runnerAppPath;

Expand Down Expand Up @@ -156,7 +151,7 @@ extern FBXCTestType const FBXCTestTypeListTest;
/**
The Designated Initializer.
*/
+ (instancetype)configurationWithShims:(FBXCTestShimConfiguration *)shims environment:(NSDictionary<NSString *, NSString *> *)environment workingDirectory:(NSString *)workingDirectory testBundlePath:(NSString *)testBundlePath waitForDebugger:(BOOL)waitForDebugger timeout:(NSTimeInterval)timeout runnerAppPath:(NSString *)runnerAppPath testTargetAppPath:(nullable NSString *)testTargetAppPath testFilter:(nullable NSString *)testFilter videoRecordingPath:(nullable NSString *)videoRecordingPath testArtifactsFilenameGlobs:(nullable NSArray<NSString *> *)testArtifactsFilenameGlobs osLogPath:(nullable NSString *)osLogPath;
+ (instancetype)configurationWithEnvironment:(NSDictionary<NSString *, NSString *> *)environment workingDirectory:(NSString *)workingDirectory testBundlePath:(NSString *)testBundlePath waitForDebugger:(BOOL)waitForDebugger timeout:(NSTimeInterval)timeout runnerAppPath:(NSString *)runnerAppPath testTargetAppPath:(nullable NSString *)testTargetAppPath testFilter:(nullable NSString *)testFilter videoRecordingPath:(nullable NSString *)videoRecordingPath testArtifactsFilenameGlobs:(nullable NSArray<NSString *> *)testArtifactsFilenameGlobs osLogPath:(nullable NSString *)osLogPath;

@end

Expand Down Expand Up @@ -202,7 +197,7 @@ typedef NS_OPTIONS(NSUInteger, FBLogicTestMirrorLogs) {
/**
The Designated Initializer.
*/
+ (instancetype)configurationWithShims:(FBXCTestShimConfiguration *)shims environment:(NSDictionary<NSString *, NSString *> *)environment workingDirectory:(NSString *)workingDirectory testBundlePath:(NSString *)testBundlePath waitForDebugger:(BOOL)waitForDebugger timeout:(NSTimeInterval)timeout testFilter:(nullable NSString *)testFilter mirroring:(FBLogicTestMirrorLogs)mirroring coveragePath:(nullable NSString *)coveragePath binaryPath:(nullable NSString *)binaryPath logDirectoryPath:(nullable NSString *)logDirectoryPath;
+ (instancetype)configurationWithEnvironment:(NSDictionary<NSString *, NSString *> *)environment workingDirectory:(NSString *)workingDirectory testBundlePath:(NSString *)testBundlePath waitForDebugger:(BOOL)waitForDebugger timeout:(NSTimeInterval)timeout testFilter:(nullable NSString *)testFilter mirroring:(FBLogicTestMirrorLogs)mirroring coveragePath:(nullable NSString *)coveragePath binaryPath:(nullable NSString *)binaryPath logDirectoryPath:(nullable NSString *)logDirectoryPath;

@end

Expand Down
33 changes: 15 additions & 18 deletions XCTestBootstrap/Configuration/FBXCTestConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ @implementation FBXCTestConfiguration

#pragma mark Initializers

- (instancetype)initWithShims:(FBXCTestShimConfiguration *)shims environment:(NSDictionary<NSString *, NSString *> *)environment workingDirectory:(NSString *)workingDirectory testBundlePath:(NSString *)testBundlePath waitForDebugger:(BOOL)waitForDebugger timeout:(NSTimeInterval)timeout
- (instancetype)initWithEnvironment:(NSDictionary<NSString *, NSString *> *)environment workingDirectory:(NSString *)workingDirectory testBundlePath:(NSString *)testBundlePath waitForDebugger:(BOOL)waitForDebugger timeout:(NSTimeInterval)timeout
{
self = [super init];
if (!self) {
return nil;
}

_shims = shims;
_processUnderTestEnvironment = environment ?: @{};
_workingDirectory = workingDirectory;
_testBundlePath = testBundlePath;
Expand Down Expand Up @@ -99,8 +98,7 @@ - (BOOL)isEqual:(FBXCTestConfiguration *)object
if (![object isMemberOfClass:self.class]) {
return NO;
}
return (self.shims == object.shims || [self.shims isEqual:object.shims])
&& (self.processUnderTestEnvironment == object.processUnderTestEnvironment || [self.processUnderTestEnvironment isEqualToDictionary:object.processUnderTestEnvironment])
return (self.processUnderTestEnvironment == object.processUnderTestEnvironment || [self.processUnderTestEnvironment isEqualToDictionary:object.processUnderTestEnvironment])
&& (self.workingDirectory == object.workingDirectory || [self.workingDirectory isEqualToString:object.workingDirectory])
&& (self.testBundlePath == object.testBundlePath || [self.testBundlePath isEqualToString:object.testBundlePath])
&& (self.testType == object.testType || [self.testType isEqualToString:object.testType])
Expand All @@ -110,7 +108,7 @@ - (BOOL)isEqual:(FBXCTestConfiguration *)object

- (NSUInteger)hash
{
return self.shims.hash ^ self.processUnderTestEnvironment.hash ^ self.workingDirectory.hash ^ self.testBundlePath.hash ^ self.testType.hash ^ ((NSUInteger) self.waitForDebugger) ^ ((NSUInteger) self.testTimeout);
return self.processUnderTestEnvironment.hash ^ self.workingDirectory.hash ^ self.testBundlePath.hash ^ self.testType.hash ^ ((NSUInteger) self.waitForDebugger) ^ ((NSUInteger) self.testTimeout);
}

#pragma mark JSON
Expand All @@ -120,7 +118,6 @@ - (NSUInteger)hash
static NSString *const KeyOSLogPath = @"os_log_path";
static NSString *const KeyRunnerAppPath = @"test_host_path";
static NSString *const KeyRunnerTargetPath = @"test_target_path";
static NSString *const KeyShims = @"shims";
static NSString *const KeyTestArtifactsFilenameGlobs = @"test_artifacts_filename_globs";
static NSString *const KeyTestBundlePath = @"test_bundle_path";
static NSString *const KeyTestFilter = @"test_filter";
Expand Down Expand Up @@ -157,14 +154,14 @@ @implementation FBListTestConfiguration

#pragma mark Initializers

+ (instancetype)configurationWithShims:(FBXCTestShimConfiguration *)shims environment:(NSDictionary<NSString *, NSString *> *)environment workingDirectory:(NSString *)workingDirectory testBundlePath:(NSString *)testBundlePath runnerAppPath:(nullable NSString *)runnerAppPath waitForDebugger:(BOOL)waitForDebugger timeout:(NSTimeInterval)timeout
+ (instancetype)configurationWithEnvironment:(NSDictionary<NSString *, NSString *> *)environment workingDirectory:(NSString *)workingDirectory testBundlePath:(NSString *)testBundlePath runnerAppPath:(nullable NSString *)runnerAppPath waitForDebugger:(BOOL)waitForDebugger timeout:(NSTimeInterval)timeout
{
return [[FBListTestConfiguration alloc] initWithShims:shims environment:environment workingDirectory:workingDirectory testBundlePath:testBundlePath runnerAppPath:runnerAppPath waitForDebugger:waitForDebugger timeout:timeout];
return [[FBListTestConfiguration alloc] initWithEnvironment:environment workingDirectory:workingDirectory testBundlePath:testBundlePath runnerAppPath:runnerAppPath waitForDebugger:waitForDebugger timeout:timeout];
}

- (instancetype)initWithShims:(FBXCTestShimConfiguration *)shims environment:(NSDictionary<NSString *, NSString *> *)environment workingDirectory:(NSString *)workingDirectory testBundlePath:(NSString *)testBundlePath runnerAppPath:(nullable NSString *)runnerAppPath waitForDebugger:(BOOL)waitForDebugger timeout:(NSTimeInterval)timeout
- (instancetype)initWithEnvironment:(NSDictionary<NSString *, NSString *> *)environment workingDirectory:(NSString *)workingDirectory testBundlePath:(NSString *)testBundlePath runnerAppPath:(nullable NSString *)runnerAppPath waitForDebugger:(BOOL)waitForDebugger timeout:(NSTimeInterval)timeout
{
self = [super initWithShims:shims environment:environment workingDirectory:workingDirectory testBundlePath:testBundlePath waitForDebugger:waitForDebugger timeout:timeout];
self = [super initWithEnvironment:environment workingDirectory:workingDirectory testBundlePath:testBundlePath waitForDebugger:waitForDebugger timeout:timeout];
if (!self) {
return nil;
}
Expand Down Expand Up @@ -197,14 +194,14 @@ @implementation FBTestManagerTestConfiguration

#pragma mark Initializers

+ (instancetype)configurationWithShims:(FBXCTestShimConfiguration *)shims environment:(NSDictionary<NSString *, NSString *> *)environment workingDirectory:(NSString *)workingDirectory testBundlePath:(NSString *)testBundlePath waitForDebugger:(BOOL)waitForDebugger timeout:(NSTimeInterval)timeout runnerAppPath:(NSString *)runnerAppPath testTargetAppPath:(NSString *)testTargetAppPath testFilter:(NSString *)testFilter videoRecordingPath:(NSString *)videoRecordingPath testArtifactsFilenameGlobs:(nullable NSArray<NSString *> *)testArtifactsFilenameGlobs osLogPath:(nullable NSString *)osLogPath
+ (instancetype)configurationWithEnvironment:(NSDictionary<NSString *, NSString *> *)environment workingDirectory:(NSString *)workingDirectory testBundlePath:(NSString *)testBundlePath waitForDebugger:(BOOL)waitForDebugger timeout:(NSTimeInterval)timeout runnerAppPath:(NSString *)runnerAppPath testTargetAppPath:(NSString *)testTargetAppPath testFilter:(NSString *)testFilter videoRecordingPath:(NSString *)videoRecordingPath testArtifactsFilenameGlobs:(nullable NSArray<NSString *> *)testArtifactsFilenameGlobs osLogPath:(nullable NSString *)osLogPath
{
return [[FBTestManagerTestConfiguration alloc] initWithShims:shims environment:environment workingDirectory:workingDirectory testBundlePath:testBundlePath waitForDebugger:waitForDebugger timeout:timeout runnerAppPath:runnerAppPath testTargetAppPath:testTargetAppPath testFilter:testFilter videoRecordingPath:videoRecordingPath testArtifactsFilenameGlobs:testArtifactsFilenameGlobs osLogPath:osLogPath];
return [[FBTestManagerTestConfiguration alloc] initWithEnvironment:environment workingDirectory:workingDirectory testBundlePath:testBundlePath waitForDebugger:waitForDebugger timeout:timeout runnerAppPath:runnerAppPath testTargetAppPath:testTargetAppPath testFilter:testFilter videoRecordingPath:videoRecordingPath testArtifactsFilenameGlobs:testArtifactsFilenameGlobs osLogPath:osLogPath];
}

- (instancetype)initWithShims:(FBXCTestShimConfiguration *)shims environment:(NSDictionary<NSString *, NSString *> *)environment workingDirectory:(NSString *)workingDirectory testBundlePath:(NSString *)testBundlePath waitForDebugger:(BOOL)waitForDebugger timeout:(NSTimeInterval)timeout runnerAppPath:(NSString *)runnerAppPath testTargetAppPath:(NSString *)testTargetAppPath testFilter:(NSString *)testFilter videoRecordingPath:(NSString *)videoRecordingPath testArtifactsFilenameGlobs:(NSArray<NSString *> *)testArtifactsFilenameGlobs osLogPath:(nullable NSString *)osLogPath
- (instancetype)initWithEnvironment:(NSDictionary<NSString *, NSString *> *)environment workingDirectory:(NSString *)workingDirectory testBundlePath:(NSString *)testBundlePath waitForDebugger:(BOOL)waitForDebugger timeout:(NSTimeInterval)timeout runnerAppPath:(NSString *)runnerAppPath testTargetAppPath:(NSString *)testTargetAppPath testFilter:(NSString *)testFilter videoRecordingPath:(NSString *)videoRecordingPath testArtifactsFilenameGlobs:(NSArray<NSString *> *)testArtifactsFilenameGlobs osLogPath:(nullable NSString *)osLogPath
{
self = [super initWithShims:shims environment:environment workingDirectory:workingDirectory testBundlePath:testBundlePath waitForDebugger:waitForDebugger timeout:timeout];
self = [super initWithEnvironment:environment workingDirectory:workingDirectory testBundlePath:testBundlePath waitForDebugger:waitForDebugger timeout:timeout];
if (!self) {
return nil;
}
Expand Down Expand Up @@ -246,14 +243,14 @@ @implementation FBLogicTestConfiguration

#pragma mark Initializers

+ (instancetype)configurationWithShims:(FBXCTestShimConfiguration *)shims environment:(NSDictionary<NSString *, NSString *> *)environment workingDirectory:(NSString *)workingDirectory testBundlePath:(NSString *)testBundlePath waitForDebugger:(BOOL)waitForDebugger timeout:(NSTimeInterval)timeout testFilter:(NSString *)testFilter mirroring:(FBLogicTestMirrorLogs)mirroring coveragePath:(nullable NSString *)coveragePath binaryPath:(nullable NSString *)binaryPath logDirectoryPath:(NSString *)logDirectoryPath
+ (instancetype)configurationWithEnvironment:(NSDictionary<NSString *, NSString *> *)environment workingDirectory:(NSString *)workingDirectory testBundlePath:(NSString *)testBundlePath waitForDebugger:(BOOL)waitForDebugger timeout:(NSTimeInterval)timeout testFilter:(NSString *)testFilter mirroring:(FBLogicTestMirrorLogs)mirroring coveragePath:(nullable NSString *)coveragePath binaryPath:(nullable NSString *)binaryPath logDirectoryPath:(NSString *)logDirectoryPath
{
return [[FBLogicTestConfiguration alloc] initWithShims:shims environment:environment workingDirectory:workingDirectory testBundlePath:testBundlePath waitForDebugger:waitForDebugger timeout:timeout testFilter:testFilter mirroring:mirroring coveragePath:coveragePath binaryPath:binaryPath logDirectoryPath:logDirectoryPath];
return [[FBLogicTestConfiguration alloc] initWithEnvironment:environment workingDirectory:workingDirectory testBundlePath:testBundlePath waitForDebugger:waitForDebugger timeout:timeout testFilter:testFilter mirroring:mirroring coveragePath:coveragePath binaryPath:binaryPath logDirectoryPath:logDirectoryPath];
}

- (instancetype)initWithShims:(FBXCTestShimConfiguration *)shims environment:(NSDictionary<NSString *, NSString *> *)environment workingDirectory:(NSString *)workingDirectory testBundlePath:(NSString *)testBundlePath waitForDebugger:(BOOL)waitForDebugger timeout:(NSTimeInterval)timeout testFilter:(NSString *)testFilter mirroring:(FBLogicTestMirrorLogs)mirroring coveragePath:(nullable NSString *)coveragePath binaryPath:(nullable NSString *)binaryPath logDirectoryPath:(NSString *)logDirectoryPath
- (instancetype)initWithEnvironment:(NSDictionary<NSString *, NSString *> *)environment workingDirectory:(NSString *)workingDirectory testBundlePath:(NSString *)testBundlePath waitForDebugger:(BOOL)waitForDebugger timeout:(NSTimeInterval)timeout testFilter:(NSString *)testFilter mirroring:(FBLogicTestMirrorLogs)mirroring coveragePath:(nullable NSString *)coveragePath binaryPath:(nullable NSString *)binaryPath logDirectoryPath:(NSString *)logDirectoryPath
{
self = [super initWithShims:shims environment:environment workingDirectory:workingDirectory testBundlePath:testBundlePath waitForDebugger:waitForDebugger timeout:timeout];
self = [super initWithEnvironment:environment workingDirectory:workingDirectory testBundlePath:testBundlePath waitForDebugger:waitForDebugger timeout:timeout];
if (!self) {
return nil;
}
Expand Down
41 changes: 22 additions & 19 deletions XCTestBootstrap/MacStrategies/FBMacDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ - (NSString *)xctestPath
stringByAppendingPathComponent:@"usr/bin/xctest"];
}

- (FBFuture<NSString *> *)extendedTestShim
{
return [[FBXCTestShimConfiguration
defaultShimConfigurationWithLogger:self.logger]
onQueue:self.asyncQueue map:^(FBXCTestShimConfiguration *shims) {
return shims.macOSTestShimPath;
}];
}

+ (NSString *)resolveDeviceUDID
{
io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"));
Expand Down Expand Up @@ -417,25 +426,19 @@ - (NSString *)customDeviceSetPath

- (nonnull FBFuture<NSArray<NSString *> *> *)listTestsForBundleAtPath:(nonnull NSString *)bundlePath timeout:(NSTimeInterval)timeout withAppAtPath:(NSString *)appPath
{
return [[FBXCTestShimConfiguration
defaultShimConfigurationWithLogger:self.logger]
onQueue:self.workQueue fmap:^(FBXCTestShimConfiguration *shims) {
FBListTestConfiguration *configuration = [FBListTestConfiguration
configurationWithShims:shims
environment:@{}
workingDirectory:self.auxillaryDirectory
testBundlePath:bundlePath
runnerAppPath:appPath
waitForDebugger:NO
timeout:timeout];

return [[[FBListTestStrategy alloc]
initWithTarget:self
configuration:configuration
shimPath:shims.macOSTestShimPath
logger:self.logger]
listTests];
}];
FBListTestConfiguration *configuration = [FBListTestConfiguration
configurationWithEnvironment:@{}
workingDirectory:self.auxillaryDirectory
testBundlePath:bundlePath
runnerAppPath:appPath
waitForDebugger:NO
timeout:timeout];

return [[[FBListTestStrategy alloc]
initWithTarget:self
configuration:configuration
logger:self.logger]
listTests];
}

- (nonnull FBFuture<id<FBiOSTargetOperation>> *)tailLog:(nonnull NSArray<NSString *> *)arguments consumer:(nonnull id<FBDataConsumer>)consumer
Expand Down
Loading

0 comments on commit 48b8631

Please sign in to comment.