|
1 #!/usr/bin/perl |
|
2 |
|
3 # Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved. |
|
4 # Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
|
5 # |
|
6 # Redistribution and use in source and binary forms, with or without |
|
7 # modification, are permitted provided that the following conditions |
|
8 # are met: |
|
9 # |
|
10 # 1. Redistributions of source code must retain the above copyright |
|
11 # notice, this list of conditions and the following disclaimer. |
|
12 # 2. Redistributions in binary form must reproduce the above copyright |
|
13 # notice, this list of conditions and the following disclaimer in the |
|
14 # documentation and/or other materials provided with the distribution. |
|
15 # 3. Neither the name of Apple Inc. ("Apple") nor the names of |
|
16 # its contributors may be used to endorse or promote products derived |
|
17 # from this software without specific prior written permission. |
|
18 # |
|
19 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
|
20 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
21 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
22 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
|
23 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
24 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
25 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|
26 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|
28 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 |
|
30 # Script to run Apache with the same configuration as used in http layout tests. |
|
31 |
|
32 use strict; |
|
33 use warnings; |
|
34 |
|
35 use Cwd; |
|
36 use File::Basename; |
|
37 use Getopt::Long; |
|
38 use FindBin; |
|
39 |
|
40 use lib $FindBin::Bin; |
|
41 use webkitdirs; |
|
42 |
|
43 # Argument handling |
|
44 my $httpdPort = 8000; |
|
45 my $allInterfaces = 0; |
|
46 my $showHelp; |
|
47 |
|
48 my $result = GetOptions( |
|
49 'all-interfaces|a' => \$allInterfaces, |
|
50 'help|h' => \$showHelp, |
|
51 'port=i' => \$httpdPort, |
|
52 ); |
|
53 |
|
54 if (!$result || @ARGV || $showHelp) { |
|
55 print "Usage: " . basename($0) . " [options]\n"; |
|
56 print " -a|--all-interfaces Bind to all interfaces\n"; |
|
57 print " -h|--help Show this help message\n"; |
|
58 print " -p|--port NNNN Bind to port NNNN\n"; |
|
59 exit 1; |
|
60 } |
|
61 |
|
62 setConfiguration(); |
|
63 my $productDir = productDir(); |
|
64 chdirWebKit(); |
|
65 |
|
66 mkdir "/tmp/WebKit"; |
|
67 |
|
68 if (-f "/tmp/WebKit/httpd.pid") { |
|
69 my $oldPid = `cat /tmp/WebKit/httpd.pid`; |
|
70 chomp $oldPid; |
|
71 if (0 != kill 0, $oldPid) { |
|
72 print "\nhttpd is already running: pid $oldPid, killing...\n"; |
|
73 kill 15, $oldPid; |
|
74 |
|
75 my $retryCount = 20; |
|
76 while ((0 != kill 0, $oldPid) && $retryCount) { |
|
77 sleep 1; |
|
78 --$retryCount; |
|
79 } |
|
80 |
|
81 die "Timed out waiting for httpd to quit" unless $retryCount; |
|
82 } |
|
83 } |
|
84 |
|
85 my $testDirectory = getcwd() . "/LayoutTests"; |
|
86 my $httpdPath = "/usr/sbin/httpd"; |
|
87 my $httpdConfig = "$testDirectory/http/conf/httpd.conf"; |
|
88 $httpdConfig = "$testDirectory/http/conf/cygwin-httpd.conf" if isCygwin(); |
|
89 $httpdConfig = "$testDirectory/http/conf/apache2-httpd.conf" if `$httpdPath -v` =~ m|Apache/2|; |
|
90 my $documentRoot = "$testDirectory/http/tests"; |
|
91 my $typesConfig = "$testDirectory/http/conf/mime.types"; |
|
92 my $sslCertificate = "$testDirectory/http/conf/webkit-httpd.pem"; |
|
93 |
|
94 my $listen = "127.0.0.1:$httpdPort"; |
|
95 $listen = "$httpdPort" if ($allInterfaces); |
|
96 |
|
97 if ($allInterfaces) { |
|
98 print "Starting httpd on port $httpdPort (all interfaces)...\n"; |
|
99 } else { |
|
100 print "Starting httpd on <http://$listen/>...\n"; |
|
101 } |
|
102 print "Press Ctrl+C to stop it.\n\n"; |
|
103 |
|
104 my @args = ( |
|
105 "-f", "$httpdConfig", |
|
106 "-C", "DocumentRoot \"$documentRoot\"", |
|
107 "-C", "Listen $listen", |
|
108 "-c", "TypesConfig \"$typesConfig\"", |
|
109 "-c", "CustomLog |/usr/bin/tee common", |
|
110 "-c", "ErrorLog |/usr/bin/tee", |
|
111 # Apache wouldn't run CGIs with permissions==700 otherwise. |
|
112 "-c", "User \"#$<\"", |
|
113 # Run in single-process mode, do not detach from the controlling terminal. |
|
114 "-X", |
|
115 # Disable Keep-Alive support. Makes testing in multiple browsers easier (no need to wait |
|
116 # for another browser's connection to expire). |
|
117 "-c", "KeepAlive 0" |
|
118 ); |
|
119 |
|
120 # FIXME: Enable this on Windows once <rdar://problem/5345985> is fixed |
|
121 push(@args, "-c", "SSLCertificateFile \"$sslCertificate\"") unless isCygwin(); |
|
122 |
|
123 system($httpdPath, @args); |
|
124 |
|
125 unlink "/tmp/WebKit/httpd.pid"; |