153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#!/usr/bin/env python 253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# Copyright (C) 2010 Google Inc. All rights reserved. 353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# 453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# Redistribution and use in source and binary forms, with or without 553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# modification, are permitted provided that the following conditions are 653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# met: 753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# 853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# * Redistributions of source code must retain the above copyright 953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# notice, this list of conditions and the following disclaimer. 1053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# * Redistributions in binary form must reproduce the above 1153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# copyright notice, this list of conditions and the following disclaimer 1253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# in the documentation and/or other materials provided with the 1353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# distribution. 1453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# * Neither the name of Google Inc. nor the names of its 1553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# contributors may be used to endorse or promote products derived from 1653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# this software without specific prior written permission. 1753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# 1853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) 3053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)"""A utility script for starting and stopping the HTTP server with the 3153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) same configuration as used in the layout tests.""" 3253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) 3353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# 3453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# This script is also used by Chromium's ui_tests to run http layout tests 3553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# in a browser. 3653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)# 3753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)import optparse 3853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)import os 3953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)import sys 4053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)import tempfile 4153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) 4253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)import webkitpy.common.version_check 4353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) 4453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)from webkitpy.common.host import Host 4553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)from webkitpy.layout_tests.servers import http_server 4653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) 4753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) 4853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)def run(options): 4953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) if not options.server: 5053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) print ('Usage: %s --server {start|stop} [--root=root_dir]' 5153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) ' [--port=port_number]' % sys.argv[0]) 5253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) else: 5353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) if (options.root is None) and (options.port is not None): 5453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) # specifying root but not port means we want httpd on default 5553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) # set of ports that LayoutTest use, but pointing to a different 5653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) # source of tests. Specifying port but no root does not seem 5753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) # meaningful. 5853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) raise 'Specifying port requires also a root.' 5953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) host = Host() 6053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) # FIXME: Make this work with other ports as well. 6153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) port_obj = host.port_factory.get(port_name='chromium', options=options) 6253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) httpd = http_server.Lighttpd(port_obj, 6353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) tempfile.gettempdir(), 6453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) port=options.port, 6553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) root=options.root, 6653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) run_background=options.run_background, 6753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) layout_tests_dir=options.layout_tests_dir) 6853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) if options.server == 'start': 6953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) httpd.start() 7053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) else: 7153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) httpd.stop() 7253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) 7353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) 7453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)def main(): 7553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) option_parser = optparse.OptionParser() 7653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) option_parser.add_option('-k', '--server', 7753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) help='Server action (start|stop)') 7853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) option_parser.add_option('-p', '--port', 7953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) help='Port to listen on (overrides layout test ports)') 8053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) option_parser.add_option('-r', '--root', 8153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) help='Absolute path to DocumentRoot (overrides layout test roots)') 8253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) option_parser.add_option('--register_cygwin', action="store_true", 8353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) dest="register_cygwin", help='Register Cygwin paths (on Win try bots)') 8453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) option_parser.add_option('--run_background', action="store_true", 8553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) dest="run_background", 8653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) help='Run on background (for running as UI test)') 8753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) option_parser.add_option('--layout_tests_dir', 8853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) dest="layout_tests_dir", 8953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) help='Absolute path to LayoutTests root') 9053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) options, args = option_parser.parse_args() 9153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) 9253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) run(options) 9353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) 9453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) 9553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)if '__main__' == __name__: 9653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) main() 97