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 return platform.system() == 'Linux' 14 15 16def StartXvfb(): 17 display = ':99' 18 xvfb_command = ['Xvfb', display, '-screen', '0', '1024x769x24', '-ac'] 19 xvfb_process = subprocess.Popen( 20 xvfb_command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 21 time.sleep(0.2) 22 returncode = xvfb_process.poll() 23 if returncode is None: 24 os.environ['DISPLAY'] = display 25 else: 26 logging.error('Xvfb did not start, returncode: %s, stdout:\n%s', 27 returncode, xvfb_process.stdout.read()) 28 xvfb_process = None 29 return xvfb_process 30