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.')