Bug 133663

Summary: old-run-webkit-tests: Create CoreSimulator device on demand and find it by name
Product: WebKit Reporter: David Farler <dfarler>
Component: Tools / TestsAssignee: David Farler <dfarler>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, dbates, ddkilzer
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: iPhone / iPad   
OS: All   
Attachments:
Description Flags
Patch
ddkilzer: review+
Patch ddkilzer: review+

Description David Farler 2014-06-09 16:26:05 PDT
As a short-term solution, since CoreSimulator requires a device UDID (a UUID) to specified for nearly all device actions, we need a simple (but not full-fledged PerlObjC) wrapper around CoreSimulator to:

- create an iOS sim device of a particular type and runtime (SDK)
- delete an iOS sim device
- launch an app on a particular sim device
- return a list of currently installed device (read plists in the current user's simulator device directory)

and then pass the UDID to the distributed session/install notification.

sub createiOSSimulatorDevice(name, typeId, runtimeId) -> void
sub deleteiOSSimulatorDevice(udid) -> void
sub iOSSimulatorDevices() -> [ { udid: device dict } ]
Comment 1 David Farler 2014-06-10 12:08:37 PDT
Created attachment 232802 [details]
Patch
Comment 2 David Farler 2014-06-10 12:08:56 PDT
OK, one more time.
Comment 3 David Kilzer (:ddkilzer) 2014-06-10 12:57:31 PDT
Comment on attachment 232802 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=232802&action=review

r=me

> Tools/Scripts/old-run-webkit-tests:1390
> -    my $deviceName = architecture() eq 'i386' ? "iPhone 5" : "iPhone 5s";
> +    my $deviceName = architecture() eq 'i386' ? "iPhone 5 WebKit Tester" : "iPhone 5s WebKit Tester";
> +
> +    my $deviceType = "com.apple.CoreSimulator.SimDeviceType.iPhone-5";
> +    $deviceType .= "s" if architecture() eq "x86_64";

Nit: It might be clearer to just make this an if/else statement:

    my $deviceName = "iPhone 5 WebKit Tester";
    my $deviceType = "com.apple.CoreSimulator.SimDeviceType.iPhone-5";
    if (architecture() eq 'x86_64') {
        $deviceName = "iPhone 5s WebKit Tester";
        $deviceType = "com.apple.CoreSimulator.SimDeviceType.iPhone-5s";
    }

> Tools/Scripts/webkitdirs.pm:1122
> +    return "$ENV{HOME}/Library/Developer/CoreSimulator/Devices";

Should this be $ENV{CFFIXED_USER_HOME} instead?

> Tools/Scripts/webkitdirs.pm:1127
> +    use Foundation;

I'm hoping this won't be evaluated until the method is called, since this could break non-Mac users of the script.

> Tools/Scripts/webkitdirs.pm:1166
> +    my $tries = 5;
> +    while (1) {
> +        my @devices = iOSSimulatorDevices();
> +        foreach my $device (@devices) {
> +            return $device if $device->{name} eq $name and $device->{deviceType} eq $deviceTypeId and $device->{runtime} eq $runtimeId;
> +        }
> +        sleep 5;
> +        $tries -= 1;
> +        if ($tries <= 0) {
> +            die "Device $name $deviceTypeId $runtimeId wasn't found in " . iOSSimulatorDevicesPath();
> +        }
> +    }

This would be simpler with a for() loop that just falls through:

    for (my $tries = 5; $tries > 0; $tries--) {
        [...]
        sleep 5;
    }

    die "Device $name $deviceTypeId $runtimeId wasn't found in " . iOSSimulatorDevicesPath();
Comment 4 David Kilzer (:ddkilzer) 2014-06-10 13:11:08 PDT
(In reply to comment #3)
> (From update of attachment 232802 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=232802&action=review
> 
> > Tools/Scripts/webkitdirs.pm:1127
> > +    use Foundation;
> 
> I'm hoping this won't be evaluated until the method is called, since this could break non-Mac users of the script.

Windows and EFL bots are failing because "use Foundation;" is evaluated at parse time, not run time:

https://webkit-queues.appspot.com/patch/232802

Failed to run "['Tools/Scripts/build-webkit', '--release', '--efl', '--update-efl', '--no-webkit1', '--makeargs="-j8"']" exit_code: 2
Can't locate Foundation.pm in @INC (@INC contains: /mnt/eflews/git/webkit/Tools/Scripts /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .) at /mnt/eflews/git/webkit/Tools/Scripts/webkitdirs.pm line 1127.
BEGIN failed--compilation aborted at /mnt/eflews/git/webkit/Tools/Scripts/webkitdirs.pm line 1127.

You'll have to use a Perl trick so that you only load Foundation at runtime; I think you either have to use an eval{} block and/or change it to a "require" statement.  I think "man perlmod" has the details.
Comment 5 David Farler 2014-06-10 13:31:32 PDT
(In reply to comment #4)
> (In reply to comment #3)
> > (From update of attachment 232802 [details] [details])
> > View in context: https://bugs.webkit.org/attachment.cgi?id=232802&action=review
> > 
> > > Tools/Scripts/webkitdirs.pm:1127
> > > +    use Foundation;
> > 
> > I'm hoping this won't be evaluated until the method is called, since this could break non-Mac users of the script.
> 
> Windows and EFL bots are failing because "use Foundation;" is evaluated at parse time, not run time:
> 
> https://webkit-queues.appspot.com/patch/232802
> 
> Failed to run "['Tools/Scripts/build-webkit', '--release', '--efl', '--update-efl', '--no-webkit1', '--makeargs="-j8"']" exit_code: 2
> Can't locate Foundation.pm in @INC (@INC contains: /mnt/eflews/git/webkit/Tools/Scripts /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .) at /mnt/eflews/git/webkit/Tools/Scripts/webkitdirs.pm line 1127.
> BEGIN failed--compilation aborted at /mnt/eflews/git/webkit/Tools/Scripts/webkitdirs.pm line 1127.
> 
> You'll have to use a Perl trick so that you only load Foundation at runtime; I think you either have to use an eval{} block and/or change it to a "require" statement.  I think "man perlmod" has the details.

Ah, I forgot that `use` is implicitly in the BEGIN block. The documentation recommends eval "require Foundation".
Comment 6 David Farler 2014-06-10 13:34:46 PDT
(In reply to comment #3)
> (From update of attachment 232802 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=232802&action=review
> 
> r=me
> 
> > Tools/Scripts/old-run-webkit-tests:1390
> > -    my $deviceName = architecture() eq 'i386' ? "iPhone 5" : "iPhone 5s";
> > +    my $deviceName = architecture() eq 'i386' ? "iPhone 5 WebKit Tester" : "iPhone 5s WebKit Tester";
> > +
> > +    my $deviceType = "com.apple.CoreSimulator.SimDeviceType.iPhone-5";
> > +    $deviceType .= "s" if architecture() eq "x86_64";
> 
> Nit: It might be clearer to just make this an if/else statement:
> 
>     my $deviceName = "iPhone 5 WebKit Tester";
>     my $deviceType = "com.apple.CoreSimulator.SimDeviceType.iPhone-5";
>     if (architecture() eq 'x86_64') {
>         $deviceName = "iPhone 5s WebKit Tester";
>         $deviceType = "com.apple.CoreSimulator.SimDeviceType.iPhone-5s";
>     }

Yep, that's much clearer.

> 
> > Tools/Scripts/webkitdirs.pm:1122
> > +    return "$ENV{HOME}/Library/Developer/CoreSimulator/Devices";
> 
> Should this be $ENV{CFFIXED_USER_HOME} instead?

I'm not familiar with CFFIXED_USER_HOME - where is that defined?

> 
> > Tools/Scripts/webkitdirs.pm:1127
> > +    use Foundation;
> 
> I'm hoping this won't be evaluated until the method is called, since this could break non-Mac users of the script.

You were right about this :) . I'll fix it in a subsequent patch.

> 
> > Tools/Scripts/webkitdirs.pm:1166
> > +    my $tries = 5;
> > +    while (1) {
> > +        my @devices = iOSSimulatorDevices();
> > +        foreach my $device (@devices) {
> > +            return $device if $device->{name} eq $name and $device->{deviceType} eq $deviceTypeId and $device->{runtime} eq $runtimeId;
> > +        }
> > +        sleep 5;
> > +        $tries -= 1;
> > +        if ($tries <= 0) {
> > +            die "Device $name $deviceTypeId $runtimeId wasn't found in " . iOSSimulatorDevicesPath();
> > +        }
> > +    }
> 
> This would be simpler with a for() loop that just falls through:
> 
>     for (my $tries = 5; $tries > 0; $tries--) {
>         [...]
>         sleep 5;
>     }
> 
>     die "Device $name $deviceTypeId $runtimeId wasn't found in " . iOSSimulatorDevicesPath();

Good call. I'll switch it over.
Comment 7 David Farler 2014-06-10 13:47:57 PDT
Created attachment 232811 [details]
Patch
Comment 8 David Kilzer (:ddkilzer) 2014-06-10 14:17:59 PDT
(In reply to comment #6)
> (In reply to comment #3)
> > (From update of attachment 232802 [details] [details])
> > View in context: https://bugs.webkit.org/attachment.cgi?id=232802&action=review
> > 
> > > Tools/Scripts/webkitdirs.pm:1122
> > > +    return "$ENV{HOME}/Library/Developer/CoreSimulator/Devices";
> > 
> > Should this be $ENV{CFFIXED_USER_HOME} instead?
> 
> I'm not familiar with CFFIXED_USER_HOME - where is that defined?

It's a path that the iOS Simulator uses.
Comment 9 David Farler 2014-06-10 14:19:17 PDT
(In reply to comment #8)
> (In reply to comment #6)
> > (In reply to comment #3)
> > > (From update of attachment 232802 [details] [details] [details])
> > > View in context: https://bugs.webkit.org/attachment.cgi?id=232802&action=review
> > > 
> > > > Tools/Scripts/webkitdirs.pm:1122
> > > > +    return "$ENV{HOME}/Library/Developer/CoreSimulator/Devices";
> > > 
> > > Should this be $ENV{CFFIXED_USER_HOME} instead?
> > 
> > I'm not familiar with CFFIXED_USER_HOME - where is that defined?
> 
> It's a path that the iOS Simulator uses.

Ah, no, the simulator device set are always drawn from the host user's home directory unless manually specified.
Comment 10 David Kilzer (:ddkilzer) 2014-06-10 14:23:19 PDT
Comment on attachment 232811 [details]
Patch

r=me
Comment 11 David Farler 2014-06-10 17:06:46 PDT
Committed r169783: <http://trac.webkit.org/changeset/169783>