1563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#!/usr/bin/perl
2563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
3563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# Copyright (C) 2005, 2006, 2007 Apple Inc.  All rights reserved.
4563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
52fc2651226baac27029e38c9d6ef883fa32084dbSteve Block# Copyright (C) 2011 Research In Motion Limited. All rights reserved.
6563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#
7563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# Redistribution and use in source and binary forms, with or without
8563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# modification, are permitted provided that the following conditions
9563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# are met:
10563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#
11563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# 1.  Redistributions of source code must retain the above copyright
12563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#     notice, this list of conditions and the following disclaimer. 
13563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# 2.  Redistributions in binary form must reproduce the above copyright
14563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#     notice, this list of conditions and the following disclaimer in the
15563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#     documentation and/or other materials provided with the distribution. 
16563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# 3.  Neither the name of Apple Inc. ("Apple") nor the names of
17563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#     its contributors may be used to endorse or promote products derived
18563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#     from this software without specific prior written permission. 
19563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#
20563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
21563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
24563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
31563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# Script to run Apache with the same configuration as used in http layout tests.
32563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
33563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkuse strict;
34563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkuse warnings;
35563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
36563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkuse Cwd;
37d0825bca7fe65beaee391d30da42e937db621564Steve Blockuse File::Path;
38563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkuse File::Basename;
39563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkuse Getopt::Long;
40563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkuse FindBin;
41563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
42563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkuse lib $FindBin::Bin;
43d0825bca7fe65beaee391d30da42e937db621564Steve Blockuse webkitperl::httpd;
44563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkuse webkitdirs;
45563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
46dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# FIXME: Dynamic HTTP-port configuration in this file is wrong.  The various
47dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# apache config files in LayoutTests/http/config govern the port numbers.
48dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# Dynamic configuration as-written will also cause random failures in
49dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block# an IPv6 environment.  See https://bugs.webkit.org/show_bug.cgi?id=37104.
50563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# Argument handling
51563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkmy $httpdPort = 8000;
52563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkmy $allInterfaces = 0;
53563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkmy $showHelp;
54563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
55563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkmy $result = GetOptions(
56563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    'all-interfaces|a' => \$allInterfaces,
57563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    'help|h' => \$showHelp,
58563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    'port=i' => \$httpdPort,
59563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark);
60563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
61563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkif (!$result || @ARGV || $showHelp) {
62563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    print "Usage: " . basename($0) . " [options]\n";
63563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    print "  -a|--all-interfaces  Bind to all interfaces\n";
64563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    print "  -h|--help            Show this help message\n";
65563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    print "  -p|--port NNNN       Bind to port NNNN\n";
66563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    exit 1;
67563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark}
68563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
69563af33bc48281d19dce701398dbb88cb54fd7ecCary ClarksetConfiguration();
70563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkmy $productDir = productDir();
71563af33bc48281d19dce701398dbb88cb54fd7ecCary ClarkchdirWebKit();
72d0825bca7fe65beaee391d30da42e937db621564Steve Blockmy $testDirectory = File::Spec->catfile(getcwd(), "LayoutTests");
732fc2651226baac27029e38c9d6ef883fa32084dbSteve Block$testDirectory = convertMsysPath($testDirectory) if isMsys();
74563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkmy $listen = "127.0.0.1:$httpdPort";
75563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark$listen = "$httpdPort" if ($allInterfaces);
76563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
77563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkif ($allInterfaces) {
78563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    print "Starting httpd on port $httpdPort (all interfaces)...\n";
79563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark} else {
80563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    print "Starting httpd on <http://$listen/>...\n";
81563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark}
82d0825bca7fe65beaee391d30da42e937db621564Steve BlocksetShouldWaitForUserInterrupt();
83563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkprint "Press Ctrl+C to stop it.\n\n";
84563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
85563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkmy @args = (
86563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    "-C", "Listen $listen",
87563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    # Disable Keep-Alive support. Makes testing in multiple browsers easier (no need to wait
88563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    # for another browser's connection to expire).
89563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark    "-c", "KeepAlive 0"
90563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark);
912fc2651226baac27029e38c9d6ef883fa32084dbSteve Blockpush @args, (
922fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    "-c", "CustomLog |/usr/bin/tee common",
932fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    "-c", "ErrorLog |/usr/bin/tee",
942fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    # Run in single-process mode, do not detach from the controlling terminal.
952fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    "-X",
962fc2651226baac27029e38c9d6ef883fa32084dbSteve Block) unless isMsys();
97563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark
98d0825bca7fe65beaee391d30da42e937db621564Steve Blockmy @defaultArgs = getDefaultConfigForTestDirectory($testDirectory);
99d0825bca7fe65beaee391d30da42e937db621564Steve Block@args = (@defaultArgs, @args);
100d0825bca7fe65beaee391d30da42e937db621564Steve BlockopenHTTPD(@args);
101