b4a4a29b5286dc120ad958acf53dc1868fb0cf89
[WebKit-https.git] / Tools / Scripts / webkitpy / layout_tests / port / gtk.py
1 # Copyright (C) 2010 Google Inc. All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
5 # met:
6 #
7 #     * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 #     * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer
11 # in the documentation and/or other materials provided with the
12 # distribution.
13 #     * Neither the Google name nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 import os
30 import subprocess
31
32 from webkitpy.layout_tests.models.test_configuration import TestConfiguration
33 from webkitpy.layout_tests.port.base import Port
34 from webkitpy.layout_tests.port.pulseaudio_sanitizer import PulseAudioSanitizer
35 from webkitpy.layout_tests.port.xvfbdriver import XvfbDriver
36
37
38 class GtkPort(Port, PulseAudioSanitizer):
39     port_name = "gtk"
40
41     def _port_flag_for_scripts(self):
42         return "--gtk"
43
44     def _driver_class(self):
45         return XvfbDriver
46
47     def default_timeout_ms(self):
48         # For now, use the base Port's default timeout value in case of WebKitTestRunner.
49         if self.get_option('webkit_test_runner'):
50             return super(GtkPort, self).default_timeout_ms()
51
52         if self.get_option('configuration') == 'Debug':
53             return 12 * 1000
54         return 6 * 1000
55
56     def setup_test_run(self):
57         self._unload_pulseaudio_module()
58
59     def clean_up_test_run(self):
60         super(GtkPort, self).clean_up_test_run()
61         self._restore_pulseaudio_module()
62
63     def setup_environ_for_server(self, server_name=None):
64         environment = super(GtkPort, self).setup_environ_for_server(server_name)
65         environment['GTK_MODULES'] = 'gail'
66         environment['GSETTINGS_BACKEND'] = 'memory'
67         environment['LIBOVERLAY_SCROLLBAR'] = '0'
68         environment['TEST_RUNNER_INJECTED_BUNDLE_FILENAME'] = self._build_path('Libraries', 'libTestRunnerInjectedBundle.la')
69         environment['TEST_RUNNER_TEST_PLUGIN_PATH'] = self._build_path('TestNetscapePlugin', '.libs')
70         environment['WEBKIT_INSPECTOR_PATH'] = self._build_path('Programs', 'resources', 'inspector')
71         environment['AUDIO_RESOURCES_PATH'] = self._filesystem.join(self._config.webkit_base_dir(),
72                                                                     'Source', 'WebCore', 'platform',
73                                                                     'audio', 'resources')
74         self._copy_value_from_environ_if_set(environment, 'WEBKITOUTPUTDIR')
75         if self.get_option('webkit_test_runner'):
76             # FIXME: This is a workaround to ensure that testing with WebKitTestRunner is started with
77             # a non-existing cache. This should be removed when (and if) it will be possible to properly
78             # set the cache directory path through a WebKitWebContext.
79             environment['XDG_CACHE_HOME'] = self._filesystem.join(self.results_directory(), 'appcache')
80         return environment
81
82     def _generate_all_test_configurations(self):
83         configurations = []
84         for build_type in self.ALL_BUILD_TYPES:
85             configurations.append(TestConfiguration(version=self._version, architecture='x86', build_type=build_type))
86         return configurations
87
88     def _path_to_driver(self):
89         return self._build_path('Programs', self.driver_name())
90
91     def _path_to_image_diff(self):
92         return self._build_path('Programs', 'ImageDiff')
93
94     def _path_to_apache(self):
95         if self._is_redhat_based():
96             return '/usr/sbin/httpd'
97         else:
98             return '/usr/sbin/apache2'
99
100     def _path_to_wdiff(self):
101         if self._is_redhat_based():
102             return '/usr/bin/dwdiff'
103         else:
104             return '/usr/bin/wdiff'
105
106     def _path_to_webcore_library(self):
107         gtk_library_names = [
108             "libwebkitgtk-1.0.so",
109             "libwebkitgtk-3.0.so",
110             "libwebkit2gtk-1.0.so",
111         ]
112
113         for library in gtk_library_names:
114             full_library = self._build_path(".libs", library)
115             if self._filesystem.isfile(full_library):
116                 return full_library
117         return None
118
119     # FIXME: We should find a way to share this implmentation with Gtk,
120     # or teach run-launcher how to call run-safari and move this down to Port.
121     def show_results_html_file(self, results_filename):
122         run_launcher_args = ["file://%s" % results_filename]
123         if self.get_option('webkit_test_runner'):
124             run_launcher_args.append('-2')
125         # FIXME: old-run-webkit-tests also added ["-graphicssystem", "raster", "-style", "windows"]
126         # FIXME: old-run-webkit-tests converted results_filename path for cygwin.
127         self._run_script("run-launcher", run_launcher_args)
128
129     def _get_gdb_output(self, coredump_path):
130         cmd = ['gdb', '-ex', 'thread apply all bt', '--batch', str(self._path_to_driver()), coredump_path]
131         proc = subprocess.Popen(cmd, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
132         proc.wait()
133         errors = [l.strip().decode('utf8', 'ignore') for l in proc.stderr.readlines()]
134         trace = proc.stdout.read().decode('utf8', 'ignore')
135         return (trace, errors)
136
137     def _get_crash_log(self, name, pid, stdout, stderr, newer_than):
138         pid_representation = str(pid or '<unknown>')
139         log_directory = os.environ.get("WEBKIT_CORE_DUMPS_DIRECTORY")
140         errors = []
141         crash_log = ''
142         expected_crash_dump_filename = "core-pid_%s-_-process_%s" % (pid_representation, name)
143
144         def match_filename(filesystem, directory, filename):
145             if pid:
146                 return filename == expected_crash_dump_filename
147             return filename.find(name) > -1
148
149         if log_directory:
150             dumps = self._filesystem.files_under(log_directory, file_filter=match_filename)
151             if dumps:
152                 # Get the most recent coredump matching the pid and/or process name.
153                 coredump_path = list(reversed(sorted(dumps)))[0]
154                 if not newer_than or self._filesystem.mtime(coredump_path) > newer_than:
155                     crash_log, errors = self._get_gdb_output(coredump_path)
156
157         stderr_lines = errors + (stderr or '<empty>').decode('utf8', 'ignore').splitlines()
158         errors_str = '\n'.join(('STDERR: ' + l) for l in stderr_lines)
159         if not crash_log:
160             if not log_directory:
161                 log_directory = "/path/to/coredumps"
162             core_pattern = os.path.join(log_directory, "core-pid_%p-_-process_%e")
163             crash_log = """\
164 Coredump %(expected_crash_dump_filename)s not found. To enable crash logs:
165
166 - run this command as super-user: echo "%(core_pattern)s" > /proc/sys/kernel/core_pattern
167 - enable core dumps: ulimit -c unlimited
168 - set the WEBKIT_CORE_DUMPS_DIRECTORY environment variable: export WEBKIT_CORE_DUMPS_DIRECTORY=%(log_directory)s
169
170 """ % locals()
171
172         return (stderr, """\
173 Crash log for %(name)s (pid %(pid_representation)s):
174
175 %(crash_log)s
176 %(errors_str)s""" % locals())