webengine/osswebengine/WebKitTools/Scripts/run-iexploder-tests
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 #!/usr/bin/perl
       
     2 
       
     3 # Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
       
     4 #
       
     5 # Redistribution and use in source and binary forms, with or without
       
     6 # modification, are permitted provided that the following conditions
       
     7 # are met:
       
     8 #
       
     9 # 1.  Redistributions of source code must retain the above copyright
       
    10 #     notice, this list of conditions and the following disclaimer. 
       
    11 # 2.  Redistributions in binary form must reproduce the above copyright
       
    12 #     notice, this list of conditions and the following disclaimer in the
       
    13 #     documentation and/or other materials provided with the distribution. 
       
    14 # 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
       
    15 #     its contributors may be used to endorse or promote products derived
       
    16 #     from this software without specific prior written permission. 
       
    17 #
       
    18 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
       
    19 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
    20 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
       
    21 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
       
    22 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
       
    23 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
       
    24 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
       
    25 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
       
    27 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    28 
       
    29 # A script to semi-automatically run iExploder tests.
       
    30 
       
    31 use strict;
       
    32 use warnings;
       
    33 
       
    34 use Cwd;
       
    35 use FindBin;
       
    36 use Getopt::Long;
       
    37 use IPC::Open2;
       
    38 
       
    39 use lib $FindBin::Bin;
       
    40 use webkitdirs;
       
    41 
       
    42 sub openHTTPDIfNeeded();
       
    43 sub closeHTTPD();
       
    44 sub runSafari();
       
    45 
       
    46 # Argument handling
       
    47 my $guardMalloc = '';
       
    48 my $httpdPort = 8000;
       
    49 my $downloadTest;
       
    50 
       
    51 GetOptions(
       
    52     'guard-malloc|g' => \$guardMalloc,
       
    53     'get=s' => \$downloadTest,
       
    54     'port=i' => \$httpdPort
       
    55 );
       
    56 
       
    57 
       
    58 setConfiguration();
       
    59 my $productDir = productDir();
       
    60 
       
    61 chdirWebKit();
       
    62 
       
    63 checkFrameworks();
       
    64 
       
    65 my $httpdOpen = 0;
       
    66 openHTTPDIfNeeded();
       
    67 
       
    68 if ($downloadTest) {
       
    69     system "/usr/bin/curl -o ~/Desktop/iexploder$downloadTest.html \"http://127.0.0.1:$httpdPort/iexploder.cgi?lookup=1&test=$downloadTest\"";
       
    70     print "Saved the test as iexploder$downloadTest.html on the desktop\n";
       
    71 } else {
       
    72     runSafari();
       
    73     print "Last generated tests:\n";
       
    74     system "grep 'iexploder.cgi' /tmp/WebKit/access_log.txt | tail -n -5 | awk -F'[ =&\\?]' '{if (\$8 == \"lookup\") print \$11; else print \$9}'";
       
    75 }
       
    76 
       
    77 closeHTTPD();
       
    78 
       
    79 
       
    80 sub runSafari()
       
    81 {
       
    82     my $redirectTo;
       
    83     if (@ARGV) {
       
    84         $redirectTo = "http://127.0.0.1:$httpdPort/iexploder.cgi?lookup=1&test=$ARGV[0]";
       
    85     } else {
       
    86         $redirectTo = "http://127.0.0.1:$httpdPort/index.html";
       
    87     }
       
    88 
       
    89     open REDIRECT_HTML, ">", "/tmp/WebKit/redirect.html" or die;
       
    90     print REDIRECT_HTML "<html>\n";
       
    91     print REDIRECT_HTML "    <head>\n";
       
    92     print REDIRECT_HTML "        <meta http-equiv=\"refresh\" content=\"1;URL=$redirectTo\" />\n";
       
    93     print REDIRECT_HTML "        <script type=\"text/javascript\">\n";
       
    94     print REDIRECT_HTML "            document.location = \"$redirectTo\";\n";
       
    95     print REDIRECT_HTML "        </script>\n";
       
    96     print REDIRECT_HTML "    </head>\n";
       
    97     print REDIRECT_HTML "    <body>\n";
       
    98     print REDIRECT_HTML "    </body>\n";
       
    99     print REDIRECT_HTML "</html>\n";
       
   100     close REDIRECT_HTML;
       
   101     
       
   102     local %ENV;
       
   103     $ENV{DYLD_INSERT_LIBRARIES} = "/usr/lib/libgmalloc.dylib" if $guardMalloc;
       
   104     system "WebKitTools/Scripts/run-safari", "-NSOpen", "/tmp/WebKit/redirect.html";
       
   105 }
       
   106 
       
   107 sub openHTTPDIfNeeded()
       
   108 {
       
   109     return if $httpdOpen;
       
   110 
       
   111     mkdir "/tmp/WebKit";
       
   112     
       
   113     if (-f "/tmp/WebKit/httpd.pid") {
       
   114         my $oldPid = `cat /tmp/WebKit/httpd.pid`;
       
   115         chomp $oldPid;
       
   116         if (0 != kill 0, $oldPid) {
       
   117             print "\nhttpd is already running: pid $oldPid, killing...\n";
       
   118             kill 15, $oldPid;
       
   119             
       
   120             my $retryCount = 20;
       
   121             while ((0 != kill 0, $oldPid) && $retryCount) {
       
   122                 sleep 1;
       
   123                 --$retryCount;
       
   124             }
       
   125             
       
   126             die "Timed out waiting for httpd to quit" unless $retryCount;
       
   127         }
       
   128     }
       
   129     
       
   130     my $testDirectory = getcwd() . "/LayoutTests";
       
   131     my $iExploderDirectory = getcwd() . "/WebKitTools/iExploder";
       
   132     my $httpdPath = "/usr/sbin/httpd";
       
   133     my $httpdConfig = "$testDirectory/http/conf/httpd.conf";
       
   134     $httpdConfig = "$testDirectory/http/conf/apache2-httpd.conf" if `$httpdPath -v` =~ m|Apache/2|;
       
   135     my $documentRoot = "$iExploderDirectory/htdocs";
       
   136     my $typesConfig = "$testDirectory/http/conf/mime.types";
       
   137     my $listen = "127.0.0.1:$httpdPort";
       
   138 
       
   139     open2(\*HTTPDIN, \*HTTPDOUT, $httpdPath, 
       
   140         "-f", "$httpdConfig",
       
   141         "-C", "DocumentRoot \"$documentRoot\"",
       
   142         "-C", "Listen $listen",
       
   143         "-c", "TypesConfig \"$typesConfig\"",
       
   144         "-c", "CustomLog \"/tmp/WebKit/access_log.txt\" common",
       
   145         "-c", "ErrorLog \"/tmp/WebKit/error_log.txt\"",
       
   146         # Apache wouldn't run CGIs with permissions==700 otherwise
       
   147         "-c", "User \"#$<\"");
       
   148 
       
   149     my $retryCount = 20;
       
   150     while (system("/usr/bin/curl -q --silent --stderr - --output /dev/null $listen") && $retryCount) {
       
   151         sleep 1;
       
   152         --$retryCount;
       
   153     }
       
   154     
       
   155     die "Timed out waiting for httpd to start" unless $retryCount;
       
   156     
       
   157     $httpdOpen = 1;
       
   158 }
       
   159 
       
   160 sub closeHTTPD()
       
   161 {
       
   162     return if !$httpdOpen;
       
   163 
       
   164     close HTTPDIN;
       
   165     close HTTPDOUT;
       
   166 
       
   167     kill 15, `cat /tmp/WebKit/httpd.pid` if -f "/tmp/WebKit/httpd.pid";
       
   168 
       
   169     $httpdOpen = 0;
       
   170 }