1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
#!/usr/bin/env python
#
# Copyright (C) 2011 Igalia S.L.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public License
# along with this library; see the file COPYING.LIB. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
import subprocess
import os
import sys
import time
from gi.repository import Gio, GLib
TIMEOUT=180 # seconds
class TestRunner:
TEST_DIRS = [ "unittests", "WebKit2APITests" ]
# FIXME: https://bugs.webkit.org/show_bug.cgi?id=74717
SKIPPED = [ "unittests/testdownload", "unittests/testwebview", "unittests/testwebresource",
# WebKit2APITests/TestDownloads is consistently timing
# out on the 32bit release and 64bit debug bots.
# https://bugs.webkit.org/show_bug.cgi?id=76910
"WebKit2APITests/TestDownloads" ]
def __init__(self):
# FIXME: webkit-build-directory --configuration always returns
# Release because we never call set-webkit-configuration.
#build_directory_script = os.path.join(os.path.dirname(__file__), "webkit-build-directory")
#build_directory = self._executive.run_command([build_directory_script, "--configuration"]).rstrip()
def is_valid_build_directory(build_dir):
return os.path.exists(os.path.join(build_dir, ".libs"))
script_dir = os.path.dirname(__file__)
top_level = os.path.normpath(os.path.join(script_dir, "..", ".."))
build_directory = os.path.join(top_level, 'WebKitBuild', 'Release')
if not is_valid_build_directory(build_directory):
build_directory = os.path.join(top_level, 'WebKitBuild', 'Debug')
self._a11y_registryd = None
self._timed_out = False
self._gtk_tools_directory = os.path.join(top_level, "Tools", "gtk")
self._programs_path = os.path.join(build_directory, "Programs")
self._tests = []
for test_dir in self.TEST_DIRS:
absolute_test_dir = os.path.join(self._programs_path, test_dir)
if not os.path.isdir(absolute_test_dir):
continue
for test_file in os.listdir(absolute_test_dir):
if not test_file.lower().startswith("test"):
continue
test_relative_path = os.path.join(test_dir, test_file)
if test_relative_path in self.SKIPPED:
sys.stdout.write("Skipping test %s\n" % (test_relative_path))
sys.stdout.flush()
continue
test_path = os.path.join(self._programs_path, test_relative_path)
if os.path.isfile(test_path) and os.access(test_path, os.X_OK):
self._tests.append(test_path)
def _lookup_atspi2_binary(self, jhbuild_path, filename):
process = subprocess.Popen([jhbuild_path ,'pkg-config', '--variable=exec_prefix', 'atspi-2'], stdout=subprocess.PIPE)
stdout = process.communicate()[0]
exec_prefix = stdout.rstrip('\r\n')
paths_to_check = [ 'libexec',
'lib/at-spi2-core',
'lib32/at-spi2-core',
'lib64/at-spi2-core' ]
for path in paths_to_check:
filepath = os.path.join(exec_prefix, path, filename)
if os.path.isfile(filepath):
return filepath
return None
def _run_command_when_dbus_service_appears(self, service_name, handler):
def on_name_appeared(*args):
handler()
def on_name_vanished(*args):
pass
Gio.bus_watch_name(Gio.BusType.SESSION, service_name,
Gio.BusNameWatcherFlags.NONE, on_name_appeared, on_name_vanished)
def _check_if_tests_have_timed_out(self):
if time.time() - self._start_time <= TIMEOUT:
return False
sys.stdout.write("Tests timed out after %d seconds\n" % TIMEOUT)
sys.stdout.flush()
self._timed_out = True
return True
def _ensure_accessibility_daemon_is_running(self, jhbuild_path, test_env):
a11y_registryd_path = self._lookup_atspi2_binary(jhbuild_path, 'at-spi2-registryd')
if a11y_registryd_path:
try:
self._a11y_registryd = subprocess.Popen([a11y_registryd_path], env=test_env)
except:
sys.stderr.write("Failed to run the accessibility registry\n")
sys.stderr.flush()
self._a11y_registryd = None
def run(self):
if not self._tests:
sys.stderr.write("ERROR: tests not found in %s.\n" % (self._programs_path))
sys.stderr.flush()
return 1
test_env = os.environ
test_env["DISPLAY"] = ":55"
test_env["WEBKIT_INSPECTOR_PATH"] = os.path.abspath(os.path.join(self._programs_path, 'resources', 'inspector'))
test_env['GSETTINGS_BACKEND'] = 'memory'
failed_tests = []
jhbuild_path = os.path.join(self._gtk_tools_directory, "run-with-jhbuild")
# Make sure the accessibility bus is launched.
a11y_bus_launcher_path = self._lookup_atspi2_binary(jhbuild_path, 'at-spi-bus-launcher')
assert(a11y_bus_launcher_path)
try:
a11y_bus_launcher = subprocess.Popen([a11y_bus_launcher_path], env=test_env)
except:
sys.stderr.write("Failed to launch the accessibility bus\n")
sys.stderr.flush()
return 1
loop = GLib.MainLoop()
self._start_time = time.time()
def run_tests():
self._ensure_accessibility_daemon_is_running(jhbuild_path, test_env)
for test in self._tests:
process = subprocess.Popen([jhbuild_path ,'gtester', test], env=test_env)
if process.wait():
failed_tests.append(test)
if self._check_if_tests_have_timed_out():
break
if self._a11y_registryd:
self._a11y_registryd.terminate()
a11y_bus_launcher.terminate()
if failed_tests:
names = [os.path.basename(t) for t in failed_tests]
sys.stdout.write("Tests failed: %s\n" % ", ".join(names))
sys.stdout.flush()
loop.quit()
self._run_command_when_dbus_service_appears("org.a11y.Bus", run_tests)
loop.run()
return len(failed_tests) or int(self._timed_out)
if __name__ == "__main__":
try:
xvfb = subprocess.Popen(["Xvfb", ":55", "-screen", "0", "800x600x24", "-nolisten", "tcp"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except:
sys.stderr.write("Failed to run Xvfb\n")
sys.stderr.flush()
sys.exit(1)
try:
sys.exit(TestRunner().run())
finally:
xvfb.kill()
|