[GTK] Clear application cache between tests in DumpRenderTree
[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         return environment
76
77     def _generate_all_test_configurations(self):
78         configurations = []
79         for build_type in self.ALL_BUILD_TYPES:
80             configurations.append(TestConfiguration(version=self._version, architecture='x86', build_type=build_type))
81         return configurations
82
83     def _path_to_driver(self):
84         return self._build_path('Programs', self.driver_name())
85
86     def _path_to_image_diff(self):
87         return self._build_path('Programs', 'ImageDiff')
88
89     def _path_to_apache(self):
90         if self._is_redhat_based():
91             return '/usr/sbin/httpd'
92         else:
93             return '/usr/sbin/apache2'
94
95     def _path_to_wdiff(self):
96         if self._is_redhat_based():
97             return '/usr/bin/dwdiff'
98         else:
99             return '/usr/bin/wdiff'
100
101     def _path_to_webcore_library(self):
102         gtk_library_names = [
103             "libwebkitgtk-1.0.so",
104             "libwebkitgtk-3.0.so",
105             "libwebkit2gtk-1.0.so",
106         ]
107
108         for library in gtk_library_names:
109             full_library = self._build_path(".libs", library)
110             if self._filesystem.isfile(full_library):
111                 return full_library
112         return None
113
114     # FIXME: We should find a way to share this implmentation with Gtk,
115     # or teach run-launcher how to call run-safari and move this down to Port.
116     def show_results_html_file(self, results_filename):
117         run_launcher_args = ["file://%s" % results_filename]
118         if self.get_option('webkit_test_runner'):
119             run_launcher_args.append('-2')
120         # FIXME: old-run-webkit-tests also added ["-graphicssystem", "raster", "-style", "windows"]
121         # FIXME: old-run-webkit-tests converted results_filename path for cygwin.
122         self._run_script("run-launcher", run_launcher_args)
123
124     def _get_gdb_output(self, coredump_path):
125         cmd = ['gdb', '-ex', 'thread apply all bt', '--batch', str(self._path_to_driver()), coredump_path]
126         proc = subprocess.Popen(cmd, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
127         proc.wait()
128         errors = [l.strip().decode('utf8', 'ignore') for l in proc.stderr.readlines()]
129         trace = proc.stdout.read().decode('utf8', 'ignore')
130         return (trace, errors)
131
132     def _get_crash_log(self, name, pid, stdout, stderr, newer_than):
133         pid_representation = str(pid or '<unknown>')
134         log_directory = os.environ.get("WEBKIT_CORE_DUMPS_DIRECTORY")
135         errors = []
136         crash_log = ''
137         expected_crash_dump_filename = "core-pid_%s-_-process_%s" % (pid_representation, name)
138
139         def match_filename(filesystem, directory, filename):
140             if pid:
141                 return filename == expected_crash_dump_filename
142             return filename.find(name) > -1
143
144         if log_directory:
145             dumps = self._filesystem.files_under(log_directory, file_filter=match_filename)
146             if dumps:
147                 # Get the most recent coredump matching the pid and/or process name.
148                 coredump_path = list(reversed(sorted(dumps)))[0]
149                 if not newer_than or self._filesystem.mtime(coredump_path) > newer_than:
150                     crash_log, errors = self._get_gdb_output(coredump_path)
151
152         stderr_lines = errors + (stderr or '<empty>').decode('utf8', 'ignore').splitlines()
153         errors_str = '\n'.join(('STDERR: ' + l) for l in stderr_lines)
154         if not crash_log:
155             if not log_directory:
156                 log_directory = "/path/to/coredumps"
157             core_pattern = os.path.join(log_directory, "core-pid_%p-_-process_%e")
158             crash_log = """\
159 Coredump %(expected_crash_dump_filename)s not found. To enable crash logs:
160
161 - run this command as super-user: echo "%(core_pattern)s" > /proc/sys/kernel/core_pattern
162 - enable core dumps: ulimit -c unlimited
163 - set the WEBKIT_CORE_DUMPS_DIRECTORY environment variable: export WEBKIT_CORE_DUMPS_DIRECTORY=%(log_directory)s
164
165 """ % locals()
166
167         return (stderr, """\
168 Crash log for %(name)s (pid %(pid_representation)s):
169
170 %(crash_log)s
171 %(errors_str)s""" % locals())