Changeset 202743 in webkit


Ignore:
Timestamp:
Jul 1, 2016 10:08:38 AM (8 years ago)
Author:
ap@apple.com
Message:

Simplify LayoutTestRelay
https://bugs.webkit.org/show_bug.cgi?id=159353

Reviewed by Daniel Bates.

  1. Use UDID to pass the device from webkitpy to LayoutTestRelay, searching for it

by name and runtime makes no sense.

  1. Removed code to create devices, webkitpy always does this in advance.
  2. Don't create copies of testing apps - we can install the same one into

each simulator, now that we don't run multiple tester processes in a single simulator.

  1. Pass information on how to find I/O pipes via environment, not via Info.plist.
  2. Removed code that kept testing apps alive in the background.
  3. Slightly updated coding style in functions that I touched.
  • LayoutTestRelay/LayoutTestRelay/CoreSimulatorSPI.h:

Updated for what we acually use at this point.

  • LayoutTestRelay/LayoutTestRelay/LTRelayController.h:
  • LayoutTestRelay/LayoutTestRelay/LTRelayController.m:

(-[LTRelayController initWithDevice:productDir:appPath:deviceUDID:dumpToolArguments:]):
(-[LTRelayController ipcIdentifier]):
(-[LTRelayController processName]):
(-[LTRelayController didReceiveStdoutData:]):
(-[LTRelayController didCrashWithMessage:]):
(-[LTRelayController installApp]):
(-[LTRelayController _environmentVariables]):
(-[LTRelayController launchApp]):
(-[LTRelayController start]):
(-[LTRelayController initWithDevice:productDir:appPath:identifierSuffix:dumpToolArguments:]): Deleted.
(-[LTRelayController uniqueAppPath]): Deleted.
(-[LTRelayController uniqueAppURL]): Deleted.
(-[LTRelayController uniqueAppIdentifier]): Deleted.
(-[LTRelayController createUniqueApp]): Deleted.

  • LayoutTestRelay/LayoutTestRelay/main.m:

(usage):
(getRequiredStringArgument):
(main):
(getTestingSimDevice): Deleted.

  • Scripts/webkitpy/port/driver.py:

(IOSSimulatorDriver.cmd_line):

  • WebKitTestRunner/ios/TestControllerIOS.mm:

(WTR::TestController::platformInitialize):

  • WebKitTestRunner/ios/mainIOS.mm:

(-[WebKitTestRunnerApp applicationDidEnterBackground:]):

  • DumpRenderTree/mac/DumpRenderTree.mm:

(dumpRenderTree):
(-[DumpRenderTree applicationDidEnterBackground:]):

Location:
trunk/Tools
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r202739 r202743  
     12016-07-01  Alexey Proskuryakov  <ap@apple.com>
     2
     3        Simplify LayoutTestRelay
     4        https://bugs.webkit.org/show_bug.cgi?id=159353
     5
     6        Reviewed by Daniel Bates.
     7
     8        1. Use UDID to pass the device from webkitpy to LayoutTestRelay, searching for it
     9        by name and runtime makes no sense.
     10        2. Removed code to create devices, webkitpy always does this in advance.
     11        3. Don't create copies of testing apps - we can install the same one into
     12        each simulator, now that we don't run multiple tester processes in a single simulator.
     13        4. Pass information on how to find I/O pipes via environment, not via Info.plist.
     14        5. Removed code that kept testing apps alive in the background.
     15        6. Slightly updated coding style in functions that I touched.
     16
     17        * LayoutTestRelay/LayoutTestRelay/CoreSimulatorSPI.h:
     18        Updated for what we acually use at this point.
     19
     20        * LayoutTestRelay/LayoutTestRelay/LTRelayController.h:
     21        * LayoutTestRelay/LayoutTestRelay/LTRelayController.m:
     22        (-[LTRelayController initWithDevice:productDir:appPath:deviceUDID:dumpToolArguments:]):
     23        (-[LTRelayController ipcIdentifier]):
     24        (-[LTRelayController processName]):
     25        (-[LTRelayController didReceiveStdoutData:]):
     26        (-[LTRelayController didCrashWithMessage:]):
     27        (-[LTRelayController installApp]):
     28        (-[LTRelayController _environmentVariables]):
     29        (-[LTRelayController launchApp]):
     30        (-[LTRelayController start]):
     31        (-[LTRelayController initWithDevice:productDir:appPath:identifierSuffix:dumpToolArguments:]): Deleted.
     32        (-[LTRelayController uniqueAppPath]): Deleted.
     33        (-[LTRelayController uniqueAppURL]): Deleted.
     34        (-[LTRelayController uniqueAppIdentifier]): Deleted.
     35        (-[LTRelayController createUniqueApp]): Deleted.
     36        * LayoutTestRelay/LayoutTestRelay/main.m:
     37        (usage):
     38        (getRequiredStringArgument):
     39        (main):
     40        (getTestingSimDevice): Deleted.
     41        * Scripts/webkitpy/port/driver.py:
     42        (IOSSimulatorDriver.cmd_line):
     43        * WebKitTestRunner/ios/TestControllerIOS.mm:
     44        (WTR::TestController::platformInitialize):
     45        * WebKitTestRunner/ios/mainIOS.mm:
     46        (-[WebKitTestRunnerApp applicationDidEnterBackground:]):
     47        * DumpRenderTree/mac/DumpRenderTree.mm:
     48        (dumpRenderTree):
     49        (-[DumpRenderTree applicationDidEnterBackground:]):
     50
    1512016-07-01  Konstantin Tokarev  <annulen@yandex.ru>
    252
  • trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm

    r202728 r202743  
    12601260{
    12611261#if PLATFORM(IOS)
    1262     NSString *identifier = [[NSBundle mainBundle] bundleIdentifier];
    1263     const char *stdinPath = [[NSString stringWithFormat:@"/tmp/%@_IN", identifier] UTF8String];
    1264     const char *stdoutPath = [[NSString stringWithFormat:@"/tmp/%@_OUT", identifier] UTF8String];
    1265     const char *stderrPath = [[NSString stringWithFormat:@"/tmp/%@_ERROR", identifier] UTF8String];
     1262    const char* identifier = getenv("IPC_IDENTIFIER");
     1263    const char *stdinPath = [[NSString stringWithFormat:@"/tmp/%s_IN", identifier] UTF8String];
     1264    const char *stdoutPath = [[NSString stringWithFormat:@"/tmp/%s_OUT", identifier] UTF8String];
     1265    const char *stderrPath = [[NSString stringWithFormat:@"/tmp/%s_ERROR", identifier] UTF8String];
    12661266
    12671267    int infd = open(stdinPath, O_RDWR);
     
    13551355- (void)applicationDidEnterBackground:(UIApplication *)application
    13561356{
    1357     /* Apps will get suspended or killed some time after entering the background state but we want to be able to run multiple copies of DumpRenderTree. Periodically check to see if our remaining background time dips below a threshold and create a new background task.
    1358     */
    1359     void (^expirationHandler)() = ^ {
    1360         [application endBackgroundTask:backgroundTaskIdentifier];
    1361         backgroundTaskIdentifier = UIBackgroundTaskInvalid;
    1362     };
    1363 
    1364     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    1365 
    1366         NSTimeInterval timeRemaining;
    1367         while (true) {
    1368             timeRemaining = [application backgroundTimeRemaining];
    1369             if (timeRemaining <= 10.0 || backgroundTaskIdentifier == UIBackgroundTaskInvalid) {
    1370                 [application endBackgroundTask:backgroundTaskIdentifier];
    1371                 backgroundTaskIdentifier = [application beginBackgroundTaskWithExpirationHandler:expirationHandler];
    1372             }
    1373             sleep(5);
    1374         }
    1375     });
     1357    RELEASE_ASSERT_NOT_REACHED();
    13761358}
    13771359
  • trunk/Tools/LayoutTestRelay/LayoutTestRelay/CoreSimulatorSPI.h

    r199627 r202743  
    3636#define kSimDeviceLaunchApplicationEnvironment @"environment"
    3737
    38 typedef NS_ENUM(NSUInteger, SimDeviceState) {
    39     SimDeviceStateCreating = 0,
    40 };
    41 
    42 @interface SimDeviceType : NSObject
    43 + (NSDictionary *)supportedDeviceTypesByIdentifier;
    44 @property (readonly, copy) NSString *identifier;
    45 @end
    46 
    47 @interface SimRuntime : NSObject
    48 + (NSDictionary *)supportedRuntimesByIdentifier;
    49 @end
    50 
    5138@interface SimDevice : NSObject
    5239- (BOOL)installApplication:(NSURL *)installURL withOptions:(NSDictionary *)options error:(NSError **)error;
    5340- (pid_t)launchApplicationWithID:(NSString *)bundleID options:(NSDictionary *)options error:(NSError **)error;
    54 @property (readonly, retain) SimDeviceType *deviceType;
    55 @property (readonly, retain) SimRuntime *runtime;
    56 @property (readonly, assign) SimDeviceState state;
    57 @property (readonly, copy) NSString *name;
    5841@end
    5942
    6043@interface SimDeviceSet : NSObject
    6144+ (SimDeviceSet *)defaultSet;
    62 - (SimDevice *)createDeviceWithType:(SimDeviceType *)deviceType runtime:(SimRuntime *)runtime name:(NSString *)name error:(NSError **)error;
    63 @property (readonly, copy) NSArray *devices;
     45@property (readonly, copy) NSDictionary *devicesByUDID;
    6446
    6547@end
  • trunk/Tools/LayoutTestRelay/LayoutTestRelay/LTRelayController.h

    r174628 r202743  
    3333
    3434@interface LTRelayController : NSObject <LTRelayDelegate>
    35 - (id)initWithDevice:(SimDevice *)device productDir:(NSString *)productDir appPath:(NSString *)appPath identifierSuffix:(NSString *)suffix dumpToolArguments:(NSArray *)arguments;
     35- (id)initWithDevice:(SimDevice *)device productDir:(NSString *)productDir appPath:(NSString *)appPath deviceUDID:(NSUUID *)udid dumpToolArguments:(NSArray *)arguments;
    3636- (void)start;
    3737- (void)finish;
  • trunk/Tools/LayoutTestRelay/LayoutTestRelay/LTRelayController.m

    r185478 r202743  
    3434@property (readonly, strong) NSFileHandle *standardOutput;
    3535@property (readonly, strong) NSFileHandle *standardError;
    36 @property (readonly, strong) NSString *uniqueAppPath;
    37 @property (readonly, strong) NSString *uniqueAppIdentifier;
    38 @property (readonly, strong) NSURL *uniqueAppURL;
    39 @property (readonly, strong) NSString *originalAppIdentifier;
    40 @property (readonly, strong) NSString *originalAppPath;
    41 @property (readonly, strong) NSString *identifierSuffix;
     36@property (readonly, strong) NSString *ipcIdentifier;
     37@property (readonly, strong) NSString *appBundleIdentifier;
     38@property (readonly, strong) NSString *appPath;
     39@property (readonly, strong) NSUUID *deviceUDID;
    4240@property (readonly, strong) NSArray *dumpToolArguments;
    4341@property (readonly, strong) NSString *productDir;
     
    5048@implementation LTRelayController
    5149
    52 - (id)initWithDevice:(SimDevice *)device productDir:(NSString *)productDir appPath:(NSString *)appPath identifierSuffix:(NSString *)suffix dumpToolArguments:(NSArray *)arguments
     50- (id)initWithDevice:(SimDevice *)device productDir:(NSString *)productDir appPath:(NSString *)appPath deviceUDID:(NSUUID *)udid dumpToolArguments:(NSArray *)arguments
    5351{
    5452    if ((self = [super init])) {
    5553        _device = device;
    5654        _productDir = productDir;
    57         _originalAppPath = appPath;
    58         _originalAppIdentifier = [NSDictionary dictionaryWithContentsOfFile:[_originalAppPath stringByAppendingPathComponent:@"Info.plist"]][(NSString *)kCFBundleIdentifierKey];
    59         _identifierSuffix = suffix;
     55        _appPath = appPath;
     56        _appBundleIdentifier = [[NSBundle bundleWithPath:appPath] bundleIdentifier];
     57        _deviceUDID = udid;
    6058        _dumpToolArguments = arguments;
    6159        _standardInputDispatchSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, STDIN_FILENO, 0, dispatch_get_main_queue());
     
    7977        });
    8078
    81         _relay = [[LTPipeRelay alloc] initWithPrefix:[@"/tmp" stringByAppendingPathComponent:[self uniqueAppIdentifier]]];
     79        _relay = [[LTPipeRelay alloc] initWithPrefix:[@"/tmp" stringByAppendingPathComponent:self.ipcIdentifier]];
    8280        [_relay setRelayDelegate:self];
    8381    }
     
    8583}
    8684
    87 - (NSString *)uniqueAppPath
    88 {
    89     return [[self originalAppPath] stringByReplacingOccurrencesOfString:@".app" withString:[NSString stringWithFormat:@"%@.app", [self identifierSuffix]]];
    90 }
    91 
    92 - (NSURL *)uniqueAppURL
    93 {
    94     return [NSURL fileURLWithPath:[self uniqueAppPath]];
    95 }
    96 
    97 - (NSString *)uniqueAppIdentifier
    98 {
    99     return [[self originalAppIdentifier] stringByAppendingString:[self identifierSuffix]];
    100 }
     85- (NSString *)ipcIdentifier
     86{
     87    return [NSString stringWithFormat:@"%@-%@", self.appBundleIdentifier, self.deviceUDID.UUIDString];
     88}
     89
    10190- (NSString *)processName
    10291{
    103     return [[[self originalAppIdentifier] componentsSeparatedByString:@"."] lastObject];
     92    return [self.appBundleIdentifier componentsSeparatedByString:@"."].lastObject;
    10493}
    10594
     
    152141}
    153142
    154 - (void)createUniqueApp
    155 {
    156     NSError *error;
    157     NSFileManager *fileManager = [NSFileManager defaultManager];
    158     [fileManager removeItemAtPath:[self uniqueAppPath] error:&error];
    159     error = nil;
    160 
    161     [fileManager copyItemAtPath:[self originalAppPath] toPath:[self uniqueAppPath] error:&error];
     143- (void)installApp
     144{
     145    NSDictionary *installOptions = @{
     146        (NSString *)kCFBundleIdentifierKey: self.appBundleIdentifier,
     147    };
     148
     149    NSError *error = nil;
     150    [self.device installApplication:[NSURL fileURLWithPath:self.appPath] withOptions:installOptions error:&error];
    162151    if (error) {
    163         NSLog(@"Couldn't copy %@ to %@: %@", [self originalAppPath], [self uniqueAppPath], [error description]);
    164         exit(EXIT_FAILURE);
    165     }
    166 
    167     NSString *infoPlistPath = [[self uniqueAppPath] stringByAppendingPathComponent:@"Info.plist"];
    168     NSMutableDictionary *plist = [NSMutableDictionary dictionaryWithContentsOfFile:infoPlistPath];
    169     [plist setValue:[self uniqueAppIdentifier] forKey:(NSString *)kCFBundleIdentifierKey];
    170     BOOL written = [plist writeToFile:infoPlistPath atomically:YES];
    171     if (!written) {
    172         NSLog(@"Couldn't write unique app plist at %@", infoPlistPath);
    173         exit(EXIT_FAILURE);
    174     }
    175 
    176     NSDictionary *installOptions = @{
    177         (NSString *)kCFBundleIdentifierKey: [self uniqueAppIdentifier],
    178     };
    179 
    180     [[self device] installApplication:[self uniqueAppURL] withOptions:installOptions error:&error];
    181     if (error) {
    182         NSLog(@"Couldn't install %@: %@", [[self uniqueAppURL] path], [error description]);
     152        NSLog(@"Couldn't install %@: %@", self.appPath, error.description);
    183153        exit(EXIT_FAILURE);
    184154    }
     
    208178
    209179        NSMutableDictionary *dictionary = [@{
     180            @"IPC_IDENTIFIER": self.ipcIdentifier,
    210181            @"DYLD_FRAMEWORK_PATH": productDirectory,
    211182            @"__XPC_DYLD_FRAMEWORK_PATH": productDirectory,
     
    237208
    238209    NSError *error;
    239     pid_t pid = [[self device] launchApplicationWithID:[self uniqueAppIdentifier] options:launchOptions error:&error];
     210    pid_t pid = [self.device launchApplicationWithID:self.appBundleIdentifier options:launchOptions error:&error];
    240211
    241212    if (pid < 0) {
    242         NSLog(@"Couldn't launch unique app instance %@: %@", [self uniqueAppIdentifier], [error description]);
     213        NSLog(@"Couldn't launch %@: %@", self.appBundleIdentifier, error.description);
    243214        exit(EXIT_FAILURE);
    244215    }
     
    258229- (void)start
    259230{
    260     [self createUniqueApp];
     231    [self installApp];
    261232    [[self relay] setup];
    262233    [self launchApp];
  • trunk/Tools/LayoutTestRelay/LayoutTestRelay/main.m

    r199610 r202743  
    3333{
    3434    NSString *helpText = @"LayoutTestRelay: run a dump tool in the simulator. Not for direct consumption.\n"
    35     "Usage: LayoutTestRelay [-h] [options] -- [dump tool arguments]\n"
    36     "Required options:\n"
    37     "    -app <app_path>          Path to the built iOS .app bundle directory.\n"
    38     "    -runtime <identifier>    iOS Simulator Runtime identifier (see `xcrun -sdk iphonesimulator simctl`)\n"
    39     "    -deviceType <identifier> iOS Simulator device identifier (see simctl).\n"
    40     "    -suffix <text>           Used to create multiple unique instances when installing to the simulator.\n"
    41     "    -productDir <dir>        /path/to/WebKitBuild/{configuration}-{short platform}.\n";
     35        "Usage: LayoutTestRelay [-h] [options] -- [dump tool arguments]\n"
     36        "Required options:\n"
     37        "    -udid <identifier>       Simulator device identifier\n"
     38        "    -app <app_path>          Path to the built iOS .app bundle directory.\n"
     39        "    -productDir <dir>        /path/to/WebKitBuild/{configuration}-{short platform}.\n";
    4240
    4341    fprintf(stderr, "%s\n", [helpText UTF8String]);
    4442}
    45 
    46 SimDevice *getTestingSimDevice(SimDeviceType *deviceType, SimRuntime *runtime, NSString *suffix)
    47 {
    48     NSString *deviceName = [[[[deviceType identifier] componentsSeparatedByString:@"."] lastObject] stringByReplacingOccurrencesOfString:@"-" withString:@" "];
    49     deviceName = [NSString stringWithFormat:@"%@%@%@", deviceName, @" WebKit Tester", suffix];
    50 
    51     for (SimDevice *device in [[SimDeviceSet defaultSet] devices]) {
    52         if ([[device name] isEqualToString:deviceName] && [[device deviceType] isEqualTo:deviceType] && [[device runtime] isEqualTo:runtime])
    53             return device;
    54     }
    55 
    56     NSError *error;
    57     SimDevice *device = [[SimDeviceSet defaultSet] createDeviceWithType:deviceType runtime:runtime name:deviceName error:&error];
    58 
    59     if (error) {
    60         NSLog(@"Couldn't create device: %@", [error description]);
    61         return nil;
    62     }
    63 
    64     while ([device state] == SimDeviceStateCreating)
    65         sleep(1);
    66 
    67     return device;
    68 }
    69 
    7043
    7144NSString *getRequiredStringArgument(NSString *parameter)
     
    11891            }
    11992        }
     93
     94        NSUUID *udid = [[NSUUID alloc] initWithUUIDString:getRequiredStringArgument(@"udid")];
    12095        NSString *appPath = getRequiredStringArgument(@"app");
    121         NSString *runtimeIdentifier = getRequiredStringArgument(@"runtime");
    122         SimRuntime *runtime = [SimRuntime supportedRuntimesByIdentifier][runtimeIdentifier];
    123         if (!runtime) {
    124             NSLog(@"There is no supported runtime \"%@\"", runtimeIdentifier);
     96        NSString *productDirectory = getRequiredStringArgument(@"productDir");
     97        NSArray *dumpToolArguments = getDumpToolArguments();
     98
     99        SimDevice *device = [SimDeviceSet.defaultSet.devicesByUDID objectForKey:udid];
     100        if (!device) {
     101            NSLog(@"Device %@ couldn't be found", udid);
    125102            exit(EXIT_FAILURE);
    126103        }
    127104
    128         NSString *deviceTypeIdentifier = getRequiredStringArgument(@"deviceType");
    129         SimDeviceType *deviceType = [SimDeviceType supportedDeviceTypesByIdentifier][deviceTypeIdentifier];
    130         if (!deviceType) {
    131             NSLog(@"There is no supported device type \"%@\"", deviceTypeIdentifier);
    132             exit(EXIT_FAILURE);
    133         }
    134 
    135         NSString *suffix = getRequiredStringArgument(@"suffix");
    136         NSString *productDir = getRequiredStringArgument(@"productDir");
    137         NSArray *dumpToolArguments = getDumpToolArguments();
    138 
    139         SimDevice *device = getTestingSimDevice(deviceType, runtime, suffix);
    140 
    141         relayController = [[LTRelayController alloc] initWithDevice:device productDir:productDir appPath:appPath identifierSuffix:suffix dumpToolArguments:dumpToolArguments];
     105        relayController = [[LTRelayController alloc] initWithDevice:device productDir:productDirectory appPath:appPath deviceUDID:udid dumpToolArguments:dumpToolArguments];
    142106        [relayController start];
    143107
  • trunk/Tools/Scripts/webkitpy/port/driver.py

    r202362 r202743  
    595595        product_dir = self._port._build_path()
    596596        relay_args = [
    597             '-runtime', self._port.simulator_runtime.identifier,
    598             '-deviceType', self._port.simulator_device_type.identifier,
    599             '-suffix', str(self._worker_number),
     597            '-udid', self._port.testing_device(self._worker_number).udid,
    600598            '-productDir', product_dir,
    601599            '-app', dump_tool,
  • trunk/Tools/WebKitTestRunner/ios/TestControllerIOS.mm

    r202132 r202743  
    4747void TestController::platformInitialize()
    4848{
    49     NSString *identifier = [[NSBundle mainBundle] bundleIdentifier];
    50     const char *stdinPath = [[NSString stringWithFormat:@"/tmp/%@_IN", identifier] UTF8String];
    51     const char *stdoutPath = [[NSString stringWithFormat:@"/tmp/%@_OUT", identifier] UTF8String];
    52     const char *stderrPath = [[NSString stringWithFormat:@"/tmp/%@_ERROR", identifier] UTF8String];
     49    const char* identifier = getenv("IPC_IDENTIFIER");
     50    const char *stdinPath = [[NSString stringWithFormat:@"/tmp/%s_IN", identifier] UTF8String];
     51    const char *stdoutPath = [[NSString stringWithFormat:@"/tmp/%s_OUT", identifier] UTF8String];
     52    const char *stderrPath = [[NSString stringWithFormat:@"/tmp/%s_ERROR", identifier] UTF8String];
    5353
    5454    int infd = open(stdinPath, O_RDWR);
  • trunk/Tools/WebKitTestRunner/ios/mainIOS.mm

    r190368 r202743  
    5353- (void)applicationDidEnterBackground:(UIApplication *)application
    5454{
    55     /* Apps will get suspended or killed some time after entering the background state but we want to be able to run multiple copies of DumpRenderTree. Periodically check to see if our remaining background time dips below a threshold and create a new background task.
    56     */
    57     void (^expirationHandler)() = ^ {
    58         [application endBackgroundTask:backgroundTaskIdentifier];
    59         backgroundTaskIdentifier = UIBackgroundTaskInvalid;
    60     };
    61 
    62     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    63         NSTimeInterval timeRemaining;
    64         while (true) {
    65             timeRemaining = [application backgroundTimeRemaining];
    66             if (timeRemaining <= 10.0 || backgroundTaskIdentifier == UIBackgroundTaskInvalid) {
    67                 [application endBackgroundTask:backgroundTaskIdentifier];
    68                 backgroundTaskIdentifier = [application beginBackgroundTaskWithExpirationHandler:expirationHandler];
    69             }
    70             sleep(5);
    71         }
    72     });
     55    RELEASE_ASSERT_NOT_REACHED();
    7356}
    7457
Note: See TracChangeset for help on using the changeset viewer.