|
Line 0
a/Tools/Scripts/webkitpy/layout_tests/port/xvfbdriver.py_sec1
|
|
|
1 |
# Copyright (C) 2010 Google Inc. All rights reserved. |
| 2 |
# |
| 3 |
# Redistribution and use in source and binary forms, with or without |
| 4 |
# modification, are permitted provided that the following conditions are |
| 5 |
# met: |
| 6 |
# |
| 7 |
# * Redistributions of source code must retain the above copyright |
| 8 |
# notice, this list of conditions and the following disclaimer. |
| 9 |
# * Redistributions in binary form must reproduce the above |
| 10 |
# copyright notice, this list of conditions and the following disclaimer |
| 11 |
# in the documentation and/or other materials provided with the |
| 12 |
# distribution. |
| 13 |
# * Neither the Google name nor the names of its |
| 14 |
# contributors may be used to endorse or promote products derived from |
| 15 |
# this software without specific prior written permission. |
| 16 |
# |
| 17 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 |
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 |
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 |
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 21 |
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 22 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 |
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 |
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 |
|
| 29 |
import logging |
| 30 |
import os |
| 31 |
import signal |
| 32 |
import subprocess |
| 33 |
|
| 34 |
from webkitpy.layout_tests.port.server_process import ServerProcess |
| 35 |
from webkitpy.layout_tests.port.webkit import WebKitDriver |
| 36 |
from webkitpy.common.system.executive import Executive |
| 37 |
|
| 38 |
_log = logging.getLogger(__name__) |
| 39 |
|
| 40 |
|
| 41 |
class XvfbDriver(WebKitDriver): |
| 42 |
def _start(self, pixel_tests, per_test_args): |
| 43 |
|
| 44 |
# Collect the number of X servers running already and make |
| 45 |
# sure our Xvfb process doesn't clash with any of them. |
| 46 |
def x_filter(process_name): |
| 47 |
return process_name.find("Xorg") > -1 |
| 48 |
|
| 49 |
running_displays = len(Executive().running_pids(x_filter)) |
| 50 |
|
| 51 |
# Use even displays for pixel tests and odd ones otherwise. When pixel tests are disabled, |
| 52 |
# DriverProxy creates two drivers, one for normal and the other for ref tests. Both have |
| 53 |
# the same worker number, so this prevents them from using the same Xvfb instance. |
| 54 |
display_id = self._worker_number * 2 + running_displays |
| 55 |
if self._port.get_option('pixel_tests'): |
| 56 |
display_id += 1 |
| 57 |
run_xvfb = ["Xvfb", ":%d" % (display_id), "-screen", "0", "800x600x24", "-nolisten", "tcp"] |
| 58 |
with open(os.devnull, 'w') as devnull: |
| 59 |
self._xvfb_process = subprocess.Popen(run_xvfb, stderr=devnull) |
| 60 |
server_name = self._port.driver_name() |
| 61 |
environment = self._port.setup_environ_for_server(server_name) |
| 62 |
# We must do this here because the DISPLAY number depends on _worker_number |
| 63 |
environment['DISPLAY'] = ":%d" % (display_id) |
| 64 |
self._crashed_process_name = None |
| 65 |
self._crashed_pid = None |
| 66 |
self._server_process = ServerProcess(self._port, server_name, self.cmd_line(pixel_tests, per_test_args), environment) |
| 67 |
|
| 68 |
def stop(self): |
| 69 |
WebKitDriver.stop(self) |
| 70 |
if getattr(self, '_xvfb_process', None): |
| 71 |
Executive().kill_process(self._xvfb_process.pid) |
| 72 |
self._xvfb_process.wait() |
| 73 |
self._xvfb_process = None |