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.
31
32 Args:
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
37 connection.
38 """
39
40
42
43 xdisplaycheck_path = None
44 if build_dir:
45 xdisplaycheck_path = os.path.join(build_dir, 'xdisplaycheck')
46
48
49 os.environ['DISPLAY'] = display
50
51
52
53
54
55
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'
60
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,
67 env=env)
68
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.')
73
75 if os.path.exists(xvfb_lock_filename):
76 print(
'Removing stale xvfb lock file %r' % xvfb_lock_filename)
77 try:
78 os.unlink(xvfb_lock_filename)
79 except OSError as err:
80 print(
'Removing xvfb lock file failed: %s' % err)
81
82
83 cmd = 'Xvfb'
84
85
86
87 proc = subprocess.Popen([
88 cmd, display, '-screen', '0', '1280x800x24', '-ac', '-dpi', '96', '-maxclients', '512',
89 '-extension', 'MIT-SHM'
90 ],
91 stdout=subprocess.PIPE,
92 stderr=subprocess.STDOUT,
93 env=env)
95 open(pid_filename,
'w').
write(str(proc.pid))
96
97
98 time.sleep(10)
99
100
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)
107
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.')
118 proc.terminate()
119 else:
120 print(
'Xvfb exited, code %d' % return_code)
121
122 print(
'Xvfb output:')
123 for line in proc.communicate()[0].splitlines():
125 raise Exception(logs)
126
127 print(
'xdisplaycheck succeeded after %d seconds.' % checktime)
128 print(
'xdisplaycheck output:')
129 for line in logs.splitlines():
132
133
134 subprocess.Popen('openbox', stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
135 print(
'Window manager (openbox) started.')
136
137
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)