5"""Functions to setup xvfb, which is used by the linux machines.
20 """Returns the filename to the Xvfb pid file. This name is unique
for each
21 builder. This
is used by the linux builders.
"""
28 """Start a virtual X server and set the DISPLAY environment variable so sub
29 processes will use the virtual X server. Also start openbox. This only works
30 on Linux and assumes that xvfb
and openbox are installed.
33 child_build_name: The name of the build that we use
for the pid file.
34 E.g., webkit-rel-linux.
35 build_dir: The directory where binaries are produced. If this
is non-empty,
36 we
try running xdisplaycheck
from |build_dir| to verify our X
43 xdisplaycheck_path =
None
45 xdisplaycheck_path = os.path.join(build_dir,
'xdisplaycheck')
49 os.environ[
'DISPLAY'] = display
56 env = os.environ.copy()
57 if env.get(
'TMPDIR')
and env[
'TMPDIR'] !=
'/tmp':
58 print(
'Overriding TMPDIR to "/tmp" for Xvfb, was: %s' % (env[
'TMPDIR'],))
59 env[
'TMPDIR'] =
'/tmp'
61 if xdisplaycheck_path
and os.path.exists(xdisplaycheck_path):
62 print(
'Verifying Xvfb is not running ...')
63 checkstarttime = time.time()
64 xdisplayproc = subprocess.Popen([xdisplaycheck_path,
'--noserver'],
65 stdout=subprocess.PIPE,
66 stderr=subprocess.STDOUT,
69 logs = xdisplayproc.communicate()[0]
70 if xdisplayproc.returncode == 0:
71 print(
'xdisplaycheck says there is a display still running, exiting...')
72 raise Exception(
'Display already present.')
75 if os.path.exists(xvfb_lock_filename):
76 print(
'Removing stale xvfb lock file %r' % xvfb_lock_filename)
78 os.unlink(xvfb_lock_filename)
79 except OSError
as err:
80 print(
'Removing xvfb lock file failed: %s' % err)
87 proc = subprocess.Popen([
88 cmd, display,
'-screen',
'0',
'1280x800x24',
'-ac',
'-dpi',
'96',
'-maxclients',
'512',
89 '-extension',
'MIT-SHM'
91 stdout=subprocess.PIPE,
92 stderr=subprocess.STDOUT,
95 open(pid_filename,
'w').
write(str(proc.pid))
101 if xdisplaycheck_path
and os.path.exists(xdisplaycheck_path):
102 print(
'Verifying Xvfb has started...')
103 checkstarttime = time.time()
104 xdisplayproc = subprocess.Popen([xdisplaycheck_path],
105 stdout=subprocess.PIPE,
106 stderr=subprocess.STDOUT)
108 logs = xdisplayproc.communicate()[0]
109 checktime = time.time() - checkstarttime
110 if xdisplayproc.returncode != 0:
111 print(
'xdisplaycheck failed after %d seconds.' % checktime)
112 print(
'xdisplaycheck output:')
113 for line
in logs.splitlines():
115 return_code = proc.poll()
116 if return_code
is None:
117 print(
'Xvfb still running, stopping.')
120 print(
'Xvfb exited, code %d' % return_code)
122 print(
'Xvfb output:')
123 for line
in proc.communicate()[0].splitlines():
125 raise Exception(logs)
127 print(
'xdisplaycheck succeeded after %d seconds.' % checktime)
128 print(
'xdisplaycheck output:')
129 for line
in logs.splitlines():
134 subprocess.Popen(
'openbox', stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
135 print(
'Window manager (openbox) started.')
139 """Try and stop the virtual X server if one was started with StartVirtualX.
140 When the X server dies, it takes down the window manager with it.
141 If a virtual x server
is not running, this method does nothing.
"""
143 if os.path.exists(pid_filename):
144 xvfb_pid =
int(open(pid_filename).
read())
145 print(
'Stopping Xvfb with pid %d ...' % xvfb_pid)
148 os.kill(xvfb_pid, signal.SIGKILL)
150 print(
'... killing failed, presuming unnecessary.')
151 os.remove(pid_filename)
152 print(
'Xvfb pid file removed')
static bool read(SkStream *stream, void *buffer, size_t amount)
def print(*args, **kwargs)
def xvfb_pid_filename(child_build_name)
def xvfb_display_index(_child_build_name)
def start_virtual_x(child_build_name, build_dir)
def stop_virtual_x(child_build_name)
void write(SkWStream *wStream, const T &text)