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 32use strict; 33use warnings; 34 35use Cwd; 36use File::Basename; 37use Getopt::Long; 38use FindBin; 39 40use lib $FindBin::Bin; 41use webkitdirs; 42 43# Argument handling 44my $httpdPort = 8000; 45my $allInterfaces = 0; 46my $showHelp; 47 48my $result = GetOptions( 49 'all-interfaces|a' => \$allInterfaces, 50 'help|h' => \$showHelp, 51 'port=i' => \$httpdPort, 52); 53 54if (!$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 62setConfiguration(); 63my $productDir = productDir(); 64chdirWebKit(); 65 66mkdir "/tmp/WebKit"; 67 68if (-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 85my $testDirectory = getcwd() . "/LayoutTests"; 86my $jsTestResourcesDirectory = $testDirectory . "/fast/js/resources"; 87my $httpdPath = "/usr/sbin/httpd"; 88$httpdPath = "/usr/sbin/apache2" if isDebianBased(); 89my $httpdConfig = "$testDirectory/http/conf/httpd.conf"; 90$httpdConfig = "$testDirectory/http/conf/cygwin-httpd.conf" if isCygwin(); 91$httpdConfig = "$testDirectory/http/conf/apache2-httpd.conf" if `$httpdPath -v` =~ m|Apache/2|; 92$httpdConfig = "$testDirectory/http/conf/apache2-debian-httpd.conf" if isDebianBased(); 93my $documentRoot = "$testDirectory/http/tests"; 94my $typesConfig = "$testDirectory/http/conf/mime.types"; 95my $sslCertificate = "$testDirectory/http/conf/webkit-httpd.pem"; 96 97my $listen = "127.0.0.1:$httpdPort"; 98$listen = "$httpdPort" if ($allInterfaces); 99 100if ($allInterfaces) { 101 print "Starting httpd on port $httpdPort (all interfaces)...\n"; 102} else { 103 print "Starting httpd on <http://$listen/>...\n"; 104} 105print "Press Ctrl+C to stop it.\n\n"; 106 107my @args = ( 108 "-f", "$httpdConfig", 109 "-C", "DocumentRoot \"$documentRoot\"", 110 # Setup a link to where the js test templates are stored, use -c so that mod_alias will already be laoded. 111 "-c", "Alias /js-test-resources \"$jsTestResourcesDirectory\"", 112 "-C", "Listen $listen", 113 "-c", "TypesConfig \"$typesConfig\"", 114 "-c", "CustomLog |/usr/bin/tee common", 115 "-c", "ErrorLog |/usr/bin/tee", 116 # Apache wouldn't run CGIs with permissions==700 otherwise. 117 "-c", "User \"#$<\"", 118 # Run in single-process mode, do not detach from the controlling terminal. 119 "-X", 120 # Disable Keep-Alive support. Makes testing in multiple browsers easier (no need to wait 121 # for another browser's connection to expire). 122 "-c", "KeepAlive 0" 123); 124 125# FIXME: Enable this on Windows once <rdar://problem/5345985> is fixed 126push(@args, "-c", "SSLCertificateFile \"$sslCertificate\"") unless isCygwin(); 127 128system($httpdPath, @args); 129 130unlink "/tmp/WebKit/httpd.pid"; 131