[GTK] Rely on the general implementation for detecting the Apache server path.
[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 expectations_files(self):
42         return [self._filesystem.join(self._webkit_baseline_path(d), 'TestExpectations') for d in self._skipped_file_search_paths()]
43
44     def _port_flag_for_scripts(self):
45         return "--gtk"
46
47     def _driver_class(self):
48         return XvfbDriver
49
50     def default_timeout_ms(self):
51         # For now, use the base Port's default timeout value in case of WebKitTestRunner.
52         if self.get_option('webkit_test_runner'):
53             return super(GtkPort, self).default_timeout_ms()
54
55         if self.get_option('configuration') == 'Debug':
56             return 12 * 1000
57         return 6 * 1000
58
59     def setup_test_run(self):
60         self._unload_pulseaudio_module()
61
62     def clean_up_test_run(self):
63         super(GtkPort, self).clean_up_test_run()
64         self._restore_pulseaudio_module()
65
66     def setup_environ_for_server(self, server_name=None):
67         environment = super(GtkPort, self).setup_environ_for_server(server_name)
68         environment['GTK_MODULES'] = 'gail'
69         environment['GSETTINGS_BACKEND'] = 'memory'
70         environment['LIBOVERLAY_SCROLLBAR'] = '0'
71         environment['TEST_RUNNER_INJECTED_BUNDLE_FILENAME'] = self._build_path('Libraries', 'libTestRunnerInjectedBundle.la')
72         environment['TEST_RUNNER_TEST_PLUGIN_PATH'] = self._build_path('TestNetscapePlugin', '.libs')
73         environment['WEBKIT_INSPECTOR_PATH'] = self._build_path('Programs', 'resources', 'inspector')
74         environment['AUDIO_RESOURCES_PATH'] = self._filesystem.join(self._config.webkit_base_dir(),
75                                                                     'Source', 'WebCore', 'platform',
76                                                                     'audio', 'resources')
77         self._copy_value_from_environ_if_set(environment, 'WEBKITOUTPUTDIR')
78         return environment
79
80     def _generate_all_test_configurations(self):
81         configurations = []
82         for build_type in self.ALL_BUILD_TYPES:
83             configurations.append(TestConfiguration(version=self._version, architecture='x86', build_type=build_type))
84         return configurations
85
86     def _path_to_driver(self):
87         return self._build_path('Programs', self.driver_name())
88
89     def _path_to_image_diff(self):
90         return self._build_path('Programs', 'ImageDiff')
91
92     def _path_to_wdiff(self):
93         if self._is_redhat_based():
94             return '/usr/bin/dwdiff'
95         else:
96             return '/usr/bin/wdiff'
97
98     def _path_to_webcore_library(self):
99         gtk_library_names = [
100             "libwebkitgtk-1.0.so",
101             "libwebkitgtk-3.0.so",
102             "libwebkit2gtk-1.0.so",
103         ]
104
105         for library in gtk_library_names:
106             full_library = self._build_path(".libs", library)
107             if self._filesystem.isfile(full_library):
108                 return full_library
109         return None
110
111     # FIXME: We should find a way to share this implmentation with Gtk,
112     # or teach run-launcher how to call run-safari and move this down to Port.
113     def show_results_html_file(self, results_filename):
114         run_launcher_args = ["file://%s" % results_filename]
115         if self.get_option('webkit_test_runner'):
116             run_launcher_args.append('-2')
117         # FIXME: old-run-webkit-tests also added ["-graphicssystem", "raster", "-style", "windows"]
118         # FIXME: old-run-webkit-tests converted results_filename path for cygwin.
119         self._run_script("run-launcher", run_launcher_args)
120
121     def _get_gdb_output(self, coredump_path):
122         cmd = ['gdb', '-ex', 'thread apply all bt', '--batch', str(self._path_to_driver()), coredump_path]
123         proc = subprocess.Popen(cmd, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
124         proc.wait()
125         errors = [l.strip().decode('utf8', 'ignore') for l in proc.stderr.readlines()]
126         trace = proc.stdout.read().decode('utf8', 'ignore')
127         return (trace, errors)
128
129     def _get_crash_log(self, name, pid, stdout, stderr, newer_than):
130         pid_representation = str(pid or '<unknown>')
131         log_directory = os.environ.get("WEBKIT_CORE_DUMPS_DIRECTORY")
132         errors = []
133         crash_log = ''
134         expected_crash_dump_filename = "core-pid_%s-_-process_%s" % (pid_representation, name)
135
136         def match_filename(filesystem, directory, filename):
137             if pid:
138                 return filename == expected_crash_dump_filename
139             return filename.find(name) > -1
140
141         if log_directory:
142             dumps = self._filesystem.files_under(log_directory, file_filter=match_filename)
143             if dumps:
144                 # Get the most recent coredump matching the pid and/or process name.
145                 coredump_path = list(reversed(sorted(dumps)))[0]
146                 if not newer_than or self._filesystem.mtime(coredump_path) > newer_than:
147                     crash_log, errors = self._get_gdb_output(coredump_path)
148
149         stderr_lines = errors + (stderr or '<empty>').decode('utf8', 'ignore').splitlines()
150         errors_str = '\n'.join(('STDERR: ' + l) for l in stderr_lines)
151         if not crash_log:
152             if not log_directory:
153                 log_directory = "/path/to/coredumps"
154             core_pattern = os.path.join(log_directory, "core-pid_%p-_-process_%e")
155             crash_log = """\
156 Coredump %(expected_crash_dump_filename)s not found. To enable crash logs:
157
158 - run this command as super-user: echo "%(core_pattern)s" > /proc/sys/kernel/core_pattern
159 - enable core dumps: ulimit -c unlimited
160 - set the WEBKIT_CORE_DUMPS_DIRECTORY environment variable: export WEBKIT_CORE_DUMPS_DIRECTORY=%(log_directory)s
161
162 """ % locals()
163
164         return (stderr, """\
165 Crash log for %(name)s (pid %(pid_representation)s):
166
167 %(crash_log)s
168 %(errors_str)s""" % locals())