[WinCairo] httpd service install needs to precede server start
[WebKit-https.git] / Tools / Scripts / webkitpy / port / gtk.py
1 # Copyright (C) 2010 Google Inc. All rights reserved.
2 # Copyright (C) 2013 Samsung Electronics.  All rights reserved.
3 # Copyright (C) 2017 Igalia S.L. All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met:
8 #
9 #     * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 #     * Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following disclaimer
13 # in the documentation and/or other materials provided with the
14 # distribution.
15 #     * Neither the Google name nor the names of its
16 # contributors may be used to endorse or promote products derived from
17 # this software without specific prior written permission.
18 #
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 import os
32 import subprocess
33 import uuid
34 import logging
35
36 from webkitpy.common.system import path
37 from webkitpy.common.memoized import memoized
38 from webkitpy.layout_tests.models.test_configuration import TestConfiguration
39 from webkitpy.port.base import Port
40 from webkitpy.port.pulseaudio_sanitizer import PulseAudioSanitizer
41 from webkitpy.port.xvfbdriver import XvfbDriver
42 from webkitpy.port.westondriver import WestonDriver
43 from webkitpy.port.xorgdriver import XorgDriver
44 from webkitpy.port.waylanddriver import WaylandDriver
45 from webkitpy.port.linux_get_crash_log import GDBCrashLogGenerator
46 from webkitpy.port.leakdetector_valgrind import LeakDetectorValgrind
47
48 _log = logging.getLogger(__name__)
49
50
51 class GtkPort(Port):
52     port_name = "gtk"
53
54     def __init__(self, *args, **kwargs):
55         super(GtkPort, self).__init__(*args, **kwargs)
56         self._pulseaudio_sanitizer = PulseAudioSanitizer()
57         self._display_server = self.get_option("display_server")
58
59         if self.get_option("leaks"):
60             self._leakdetector = LeakDetectorValgrind(self._executive, self._filesystem, self.results_directory())
61             if not self.get_option("wrapper"):
62                 raise ValueError('use --wrapper=\"valgrind\" for memory leak detection on GTK')
63
64         if self._should_use_jhbuild():
65             self._jhbuild_wrapper = [self.path_from_webkit_base('Tools', 'jhbuild', 'jhbuild-wrapper'), '--gtk', 'run']
66             if self.get_option('wrapper'):
67                 self.set_option('wrapper', ' '.join(self._jhbuild_wrapper) + ' ' + self.get_option('wrapper'))
68             else:
69                 self.set_option_default('wrapper', ' '.join(self._jhbuild_wrapper))
70
71     def _built_executables_path(self, *path):
72         return self._build_path(*(('bin',) + path))
73
74     def _built_libraries_path(self, *path):
75         return self._build_path(*(('lib',) + path))
76
77     def _port_flag_for_scripts(self):
78         return "--gtk"
79
80     @memoized
81     def _driver_class(self):
82         if self._display_server == "weston":
83             return WestonDriver
84         if self._display_server == "wayland":
85             return WaylandDriver
86         if self._display_server == "xorg":
87             return XorgDriver
88         return XvfbDriver
89
90     def default_timeout_ms(self):
91         default_timeout = 15000
92         # Starting an application under Valgrind takes a lot longer than normal
93         # so increase the timeout (empirically 10x is enough to avoid timeouts).
94         multiplier = 10 if self.get_option("leaks") else 1
95         # Debug builds are slower (no compiler optimizations are used).
96         if self.get_option('configuration') == 'Debug':
97             multiplier *= 2
98         return multiplier * default_timeout
99
100     def driver_stop_timeout(self):
101         if self.get_option("leaks"):
102             # Wait the default timeout time before killing the process in driver.stop().
103             return self.default_timeout_ms()
104         return super(GtkPort, self).driver_stop_timeout()
105
106     def setup_test_run(self, device_class=None):
107         super(GtkPort, self).setup_test_run(device_class)
108         self._pulseaudio_sanitizer.unload_pulseaudio_module()
109
110         if self.get_option("leaks"):
111             self._leakdetector.clean_leaks_files_from_results_directory()
112
113     def clean_up_test_run(self):
114         super(GtkPort, self).clean_up_test_run()
115         self._pulseaudio_sanitizer.restore_pulseaudio_module()
116
117     def setup_environ_for_server(self, server_name=None):
118         environment = super(GtkPort, self).setup_environ_for_server(server_name)
119         environment['G_DEBUG'] = 'fatal-criticals'
120         environment['GSETTINGS_BACKEND'] = 'memory'
121         environment['LIBOVERLAY_SCROLLBAR'] = '0'
122         environment['TEST_RUNNER_INJECTED_BUNDLE_FILENAME'] = self._build_path('lib', 'libTestRunnerInjectedBundle.so')
123         environment['TEST_RUNNER_TEST_PLUGIN_PATH'] = self._build_path('lib', 'plugins')
124         self._copy_value_from_environ_if_set(environment, 'WEBKIT_OUTPUTDIR')
125         self._copy_value_from_environ_if_set(environment, 'WEBKIT_TOP_LEVEL')
126         self._copy_value_from_environ_if_set(environment, 'USE_PLAYBIN3')
127         self._copy_value_from_environ_if_set(environment, 'GST_DEBUG')
128         self._copy_value_from_environ_if_set(environment, 'GST_DEBUG_DUMP_DOT_DIR')
129         self._copy_value_from_environ_if_set(environment, 'GST_DEBUG_FILE')
130
131         # Configure the software libgl renderer if jhbuild ready and we test inside a virtualized window system
132         if self._driver_class() in [XvfbDriver, WestonDriver] and (self._should_use_jhbuild() or self._is_flatpak()):
133             if self._should_use_jhbuild():
134                 llvmpipe_libgl_path = self.host.executive.run_command(self._jhbuild_wrapper + ['printenv', 'LLVMPIPE_LIBGL_PATH'],
135                                                                     ignore_errors=True).strip()
136             else:  # in flatpak
137                 llvmpipe_libgl_path = "/app/softGL/lib"
138
139             dri_libgl_path = os.path.join(llvmpipe_libgl_path, "dri")
140             if os.path.exists(os.path.join(llvmpipe_libgl_path, "libGL.so")) and os.path.exists(os.path.join(dri_libgl_path, "swrast_dri.so")):
141                 # Make sure va-api support gets disabled because it's incompatible with Mesa's softGL driver.
142                 environment['LIBVA_DRIVER_NAME'] = "null"
143                 # Force the Gallium llvmpipe software rasterizer
144                 environment['LIBGL_ALWAYS_SOFTWARE'] = "1"
145                 environment['LIBGL_DRIVERS_PATH'] = dri_libgl_path
146                 environment['LD_LIBRARY_PATH'] = llvmpipe_libgl_path
147                 if os.environ.get('LD_LIBRARY_PATH'):
148                     environment['LD_LIBRARY_PATH'] += ':%s' % os.environ.get('LD_LIBRARY_PATH')
149             else:
150                 _log.warning("Can't find Gallium llvmpipe driver. Try to run update-webkitgtk-libs or update-webkitgtk-flatpak")
151         if self.get_option("leaks"):
152             # Turn off GLib memory optimisations https://wiki.gnome.org/Valgrind.
153             environment['G_SLICE'] = 'always-malloc'
154             environment['G_DEBUG'] += ',gc-friendly'
155             # Turn off bmalloc when running under Valgrind, see https://bugs.webkit.org/show_bug.cgi?id=177745
156             environment['Malloc'] = '1'
157             xmlfilename = "".join(("drt-%p-", uuid.uuid1().hex, "-leaks.xml"))
158             xmlfile = os.path.join(self.results_directory(), xmlfilename)
159             suppressionsfile = self.path_from_webkit_base('Tools', 'Scripts', 'valgrind', 'suppressions.txt')
160             environment['VALGRIND_OPTS'] = \
161                 "--tool=memcheck " \
162                 "--num-callers=40 " \
163                 "--demangle=no " \
164                 "--trace-children=no " \
165                 "--smc-check=all-non-file " \
166                 "--leak-check=yes " \
167                 "--leak-resolution=high " \
168                 "--show-possibly-lost=no " \
169                 "--show-reachable=no " \
170                 "--leak-check=full " \
171                 "--undef-value-errors=no " \
172                 "--gen-suppressions=all " \
173                 "--xml=yes " \
174                 "--xml-file=%s " \
175                 "--suppressions=%s" % (xmlfile, suppressionsfile)
176         return environment
177
178     def _generate_all_test_configurations(self):
179         configurations = []
180         for build_type in self.ALL_BUILD_TYPES:
181             configurations.append(TestConfiguration(version=self.version_name(), architecture='x86', build_type=build_type))
182         return configurations
183
184     def _path_to_driver(self):
185         return self._built_executables_path(self.driver_name())
186
187     def _path_to_image_diff(self):
188         return self._built_executables_path('ImageDiff')
189
190     def _path_to_webcore_library(self):
191         gtk_library_names = [
192             "libwebkitgtk-1.0.so",
193             "libwebkitgtk-3.0.so",
194             "libwebkit2gtk-1.0.so",
195         ]
196
197         for library in gtk_library_names:
198             full_library = self._built_libraries_path(library)
199             if self._filesystem.isfile(full_library):
200                 return full_library
201         return None
202
203     def _search_paths(self):
204         search_paths = []
205         if self._driver_class() in [WaylandDriver, WestonDriver]:
206             search_paths.append(self.port_name + "-wayland")
207         search_paths.append(self.port_name)
208         search_paths.append('wk2')
209         search_paths.extend(self.get_option("additional_platform_directory", []))
210         return search_paths
211
212     def default_baseline_search_path(self):
213         return map(self._webkit_baseline_path, self._search_paths())
214
215     def _port_specific_expectations_files(self):
216         return [self._filesystem.join(self._webkit_baseline_path(p), 'TestExpectations') for p in reversed(self._search_paths())]
217
218     def print_leaks_summary(self):
219         if not self.get_option('leaks'):
220             return
221         # FIXME: This is a hack, but we don't have a better way to get this information from the workers yet
222         # because we're in the manager process.
223         leaks_files = self._leakdetector.leaks_files_in_results_directory()
224         if not leaks_files:
225             return
226         self._leakdetector.parse_and_print_leaks_detail(leaks_files)
227
228     def show_results_html_file(self, results_filename):
229         self._run_script("run-minibrowser", [path.abspath_to_uri(self.host.platform, results_filename)])
230
231     def check_sys_deps(self):
232         return super(GtkPort, self).check_sys_deps() and self._driver_class().check_driver(self)
233
234     def _get_crash_log(self, name, pid, stdout, stderr, newer_than, target_host=None):
235         return GDBCrashLogGenerator(self._executive, name, pid, newer_than,
236             self._filesystem, self._path_to_driver).generate_crash_log(stdout, stderr)
237
238     def test_expectations_file_position(self):
239         # GTK port baseline search path is gtk -> wk2 -> generic (as gtk-wk2 and gtk baselines are merged), so port test expectations file is at third to last position.
240         return 2
241
242     def build_webkit_command(self, build_style=None):
243         command = super(GtkPort, self).build_webkit_command(build_style)
244         command.extend(["--gtk", "--update-gtk"])
245         command.append(super(GtkPort, self).make_args())
246         return command
247
248     def run_webkit_tests_command(self):
249         command = super(GtkPort, self).run_webkit_tests_command()
250         command.append("--gtk")
251         return command