| Index: testing/xvfb.py
|
| diff --git a/testing/xvfb.py b/testing/xvfb.py
|
| index dd31c9c059d278d6951979e0329cc57b52a13d58..640501dc4d8a685e0663a7c2413f1719bdf1f4ac 100755
|
| --- a/testing/xvfb.py
|
| +++ b/testing/xvfb.py
|
| @@ -42,102 +42,38 @@ def kill(proc, timeout_in_seconds=10):
|
| print >> sys.stderr, 'Xvfb running after SIGTERM and SIGKILL; good luck!'
|
|
|
|
|
| -def wait_for_xvfb(xdisplaycheck, env):
|
| - """Waits for xvfb to be fully initialized by using xdisplaycheck."""
|
| - try:
|
| - subprocess.check_output([xdisplaycheck], stderr=subprocess.STDOUT, env=env)
|
| - except OSError:
|
| - print >> sys.stderr, 'Failed to load %s with cwd=%s' % (
|
| - xdisplaycheck, os.getcwd())
|
| - return False
|
| - except subprocess.CalledProcessError as e:
|
| - print >> sys.stderr, ('Xvfb failed to load (code %d) according to %s' %
|
| - (e.returncode, xdisplaycheck))
|
| - return False
|
| -
|
| - return True
|
| -
|
| -
|
| -def should_start_xvfb(env):
|
| - """Xvfb is only used on Linux and shouldn't be invoked recursively."""
|
| - return sys.platform == 'linux2' and env.get('_CHROMIUM_INSIDE_XVFB') != '1'
|
| -
|
| -
|
| -def start_xvfb(env, build_dir, xvfb_path='Xvfb', display=':9'):
|
| - """Start a virtual X server that can run tests without an existing X session.
|
| -
|
| - Returns the Xvfb and Openbox process Popen objects, or None on failure.
|
| - The |env| dictionary is modified to set the DISPLAY and prevent re-entry.
|
| -
|
| - Args:
|
| - env: The os.environ dictionary [copy] to check for re-entry.
|
| - build_dir: The path of the build directory, used for xdisplaycheck.
|
| - xvfb_path: The path to Xvfb.
|
| - display: The X display number to use.
|
| - """
|
| - assert should_start_xvfb(env)
|
| - assert env.get('_CHROMIUM_INSIDE_XVFB') != '1'
|
| - env['_CHROMIUM_INSIDE_XVFB'] = '1'
|
| - env['DISPLAY'] = display
|
| - xvfb_proc = None
|
| - openbox_proc = None
|
| - xcompmgr_proc = None
|
| -
|
| - try:
|
| - xvfb_cmd = [xvfb_path, display, '-screen', '0', '1280x800x24', '-ac',
|
| - '-nolisten', 'tcp', '-dpi', '96']
|
| - xvfb_proc = subprocess.Popen(xvfb_cmd, stdout=subprocess.PIPE,
|
| - stderr=subprocess.STDOUT)
|
| -
|
| - if not wait_for_xvfb(os.path.join(build_dir, 'xdisplaycheck'), env):
|
| - rc = xvfb_proc.poll()
|
| - if rc is None:
|
| - print 'Xvfb still running after xdisplaycheck failure, stopping.'
|
| - kill(xvfb_proc)
|
| - else:
|
| - print 'Xvfb exited (code %d) after xdisplaycheck failure.' % rc
|
| - print 'Xvfb output:'
|
| - for l in xvfb_proc.communicate()[0].splitlines():
|
| - print '> %s' % l
|
| - return (None, None, None)
|
| -
|
| - # Some ChromeOS tests need a window manager.
|
| - openbox_proc = subprocess.Popen('openbox', stdout=subprocess.PIPE,
|
| - stderr=subprocess.STDOUT, env=env)
|
| -
|
| - # Some tests need a compositing manager to make use of transparent visuals.
|
| - xcompmgr_proc = subprocess.Popen('xcompmgr', stdout=subprocess.PIPE,
|
| - stderr=subprocess.STDOUT, env=env)
|
| - except OSError as e:
|
| - print >> sys.stderr, 'Failed to start Xvfb or Openbox or xcompmgr: %s' % \
|
| - str(e)
|
| - kill(xvfb_proc)
|
| - kill(openbox_proc)
|
| - kill(xcompmgr_proc)
|
| - return (None, None, None)
|
| -
|
| - return (xvfb_proc, openbox_proc, xcompmgr_proc)
|
| -
|
| -
|
| def run_executable(cmd, build_dir, env):
|
| """Runs an executable within Xvfb on Linux or normally on other platforms.
|
|
|
| Returns the exit code of the specified commandline, or 1 on failure.
|
| """
|
| - xvfb = None
|
| - openbox = None
|
| - xcompmgr = None
|
| - if should_start_xvfb(env):
|
| - (xvfb, openbox, xcompmgr) = start_xvfb(env, build_dir)
|
| - if not xvfb or not xvfb.pid or not openbox or not openbox.pid or \
|
| - not xcompmgr or not xcompmgr.pid:
|
| - return 1
|
| - try:
|
| + if sys.platform == 'linux2':
|
| + if env.get('_CHROMIUM_INSIDE_XVFB') == '1':
|
| + openbox_proc = None
|
| + xcompmgr_proc = None
|
| + try:
|
| + # Some ChromeOS tests need a window manager.
|
| + openbox_proc = subprocess.Popen('openbox', stdout=subprocess.PIPE,
|
| + stderr=subprocess.STDOUT, env=env)
|
| +
|
| + # Some tests need a compositing wm to make use of transparent visuals.
|
| + xcompmgr_proc = subprocess.Popen('xcompmgr', stdout=subprocess.PIPE,
|
| + stderr=subprocess.STDOUT, env=env)
|
| +
|
| + return test_env.run_executable(cmd, env)
|
| + except OSError as e:
|
| + print >> sys.stderr, 'Failed to start Xvfb or Openbox: %s' % str(e)
|
| + return 1
|
| + finally:
|
| + kill(openbox_proc)
|
| + kill(xcompmgr_proc)
|
| + else:
|
| + env['_CHROMIUM_INSIDE_XVFB'] = '1'
|
| + return subprocess.call(['xvfb-run', '-a', "--server-args=-screen 0 "
|
| + "1280x800x24 -ac -nolisten tcp -dpi 96",
|
| + __file__, build_dir] + cmd, env=env)
|
| + else:
|
| return test_env.run_executable(cmd, env)
|
| - finally:
|
| - kill(xvfb)
|
| - kill(openbox)
|
| - kill(xcompmgr)
|
|
|
|
|
| def main():
|
|
|