1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 # pylint: disable=W0702
15 """Return True if on Linux; else False."""
16 return sys
.platform
.startswith('linux')
20 """Class to start and stop Xvfb if relevant. Nop if not Linux."""
26 """Start Xvfb and set an appropriate DISPLAY environment. Linux only.
28 Copied from tools/code_coverage/coverage_posix.py
32 proc
= subprocess
.Popen(['Xvfb', ':9', '-screen', '0', '1024x768x24',
34 stdout
=subprocess
.PIPE
, stderr
=subprocess
.STDOUT
)
37 raise Exception('Could not start Xvfb')
38 os
.environ
['DISPLAY'] = ':9'
40 # Now confirm, giving a chance for it to start if needed.
42 proc
= subprocess
.Popen('xdpyinfo >/dev/null', shell
=True)
43 _
, retcode
= os
.waitpid(proc
.pid
, 0)
48 raise Exception('Could not confirm Xvfb happiness')
51 """Stop Xvfb if needed. Linux only."""
54 os
.kill(self
._pid
, signal
.SIGKILL
)
57 del os
.environ
['DISPLAY']