• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# Copyright 2016 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5import os
6import logging
7import subprocess
8import platform
9import time
10
11
12def ShouldStartXvfb():
13  # TODO(crbug.com/973847): Note that you can locally change this to return
14  # False to diagnose timeouts for dev server tests.
15  return platform.system() == 'Linux'
16
17
18def StartXvfb():
19  display = ':99'
20  xvfb_command = ['Xvfb', display, '-screen', '0', '1024x769x24', '-ac']
21  xvfb_process = subprocess.Popen(
22      xvfb_command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
23  time.sleep(0.2)
24  returncode = xvfb_process.poll()
25  if returncode is None:
26    os.environ['DISPLAY'] = display
27  else:
28    logging.error('Xvfb did not start, returncode: %s, stdout:\n%s',
29                  returncode, xvfb_process.stdout.read())
30    xvfb_process = None
31  return xvfb_process
32