| Index: isolate/xvfb.py
|
| ===================================================================
|
| --- isolate/xvfb.py (revision 0)
|
| +++ isolate/xvfb.py (revision 0)
|
| @@ -0,0 +1,83 @@
|
| +# Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +# Use of this source code is governed by a BSD-style license that can be
|
| +# found in the LICENSE file.
|
| +
|
| +"""Helper tools to manage a Virtual X buffer with Xvfb."""
|
| +
|
| +import commands
|
| +import logging
|
| +import os
|
| +import signal
|
| +import subprocess
|
| +import tempfile
|
| +
|
| +
|
| +def _XvfbPidFilename(unique_name):
|
| + """Returns the filename to the Xvfb pid file. This name is unique for each
|
| + builder. This is used by the linux builders."""
|
| + return os.path.join(tempfile.gettempdir(), 'xvfb-%s.pid' % unique_name)
|
| +
|
| +
|
| +def start_virtualx(unique_name, path=None, display=':9'):
|
| + """Start a virtual X server and set the DISPLAY environment variable so sub
|
| + processes will use the virtual X server. Also start icewm. This only works
|
| + on Linux and assumes that xvfb and icewm are installed.
|
| +
|
| + Args:
|
| + unique_name: A unique name to identify this X session that is used for the
|
| + pid file.
|
| + E.g., webkit-rel-linux.
|
| + path: (optional) the path where build outputs are generated, xdisplaycheck
|
| + will be executed to verify Xvfb correctly started.
|
| + """
|
| + # We use a pid file to make sure we don't have any xvfb processes running
|
| + # from a previous test run.
|
| + stop_virtualx(unique_name)
|
| +
|
| + # Start a virtual X server that we run the tests in. This makes it so we can
|
| + # run the tests even if we didn't start the tests from an X session.
|
| + proc = subprocess.Popen(
|
| + ['Xvfb', display, '-screen', '0', '1024x768x24', '-ac'],
|
| + stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
| + xvfb_pid_filename = _XvfbPidFilename(unique_name)
|
| + open(xvfb_pid_filename, 'w').write(str(proc.pid))
|
| + if path:
|
| + # Verifies that Xvfb has started by using xdisplaycheck.
|
| + xdisplaycheck_path = os.path.join(path, 'xdisplaycheck')
|
| + if not os.path.exists(xdisplaycheck_path):
|
| + raise Exception('%s doesn\'t exist.' % xdisplaycheck_path)
|
| + logging.info('Verifying Xvfb has started...')
|
| + status, output = commands.getstatusoutput(xdisplaycheck_path)
|
| + if status != 0:
|
| + logging.info('Xvfb return code (None if still running): %s' % proc.poll())
|
| + logging.info('Xvfb stdout and stderr:%s' % proc.communicate())
|
| + raise Exception(output)
|
| + logging.info('...OK')
|
| + # Some ChromeOS tests need a window manager.
|
| + subprocess.Popen("icewm", stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
| + return display
|
| +
|
| +
|
| +def stop_virtualx(unique_name):
|
| + """Try and stop the virtual X server if one was started with StartVirtualX.
|
| + When the X server dies, it takes down the window manager with it.
|
| + If a virtual x server is not running, this method does nothing."""
|
| + xvfb_pid_filename = _XvfbPidFilename(unique_name)
|
| + if os.path.exists(xvfb_pid_filename):
|
| + # If the process doesn't exist, we raise an exception that we can ignore.
|
| + try:
|
| + os.kill(int(open(xvfb_pid_filename).read()), signal.SIGKILL)
|
| + except OSError:
|
| + pass
|
| + os.remove(xvfb_pid_filename)
|
| +
|
| +
|
| +class Xvfb(object):
|
| + def __init__(self, unique_name):
|
| + self.unique_name = unique_name
|
| +
|
| + def start(self, build=None):
|
| + start_virtualx(self.unique_name, build)
|
| +
|
| + def stop(self):
|
| + stop_virtualx(self.unique_name)
|
|
|
| Property changes on: isolate/xvfb.py
|
| ___________________________________________________________________
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|