8155cc091c7d652532231d67d41e4edee0afe3d0
[WebKit-https.git] / Tools / Scripts / webkitpy / port / wpe.py
1 # Copyright (C) 2014-2017 Igalia S.L.  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 from webkitpy.common.system import path
30 from webkitpy.common.memoized import memoized
31 from webkitpy.layout_tests.models.test_configuration import TestConfiguration
32 from webkitpy.port.base import Port
33 from webkitpy.port.headlessdriver import HeadlessDriver
34 from webkitpy.port.linux_get_crash_log import GDBCrashLogGenerator
35 from webkitpy.port.waylanddriver import WaylandDriver
36
37
38 class WPEPort(Port):
39     port_name = "wpe"
40
41     def __init__(self, *args, **kwargs):
42         super(WPEPort, self).__init__(*args, **kwargs)
43
44         self._display_server = self.get_option("display_server")
45         if self._display_server == 'xvfb':
46             # While not supported by WPE, xvfb is used as the default value in the main scripts
47             self._display_server = 'headless'
48         if self._should_use_jhbuild():
49             self._jhbuild_wrapper = [self.path_from_webkit_base('Tools', 'jhbuild', 'jhbuild-wrapper'), '--wpe', 'run']
50             self.set_option_default('wrapper', ' '.join(self._jhbuild_wrapper))
51
52     def default_timeout_ms(self):
53         default_timeout = 15000
54         # Starting an application under Valgrind takes a lot longer than normal
55         # so increase the timeout (empirically 10x is enough to avoid timeouts).
56         multiplier = 10 if self.get_option("leaks") else 1
57         # Debug builds are slower (no compiler optimizations are used).
58         if self.get_option('configuration') == 'Debug':
59             multiplier *= 2
60         return multiplier * default_timeout
61
62     def _built_executables_path(self, *path):
63         return self._build_path(*(('bin',) + path))
64
65     def _built_libraries_path(self, *path):
66         return self._build_path(*(('lib',) + path))
67
68     def _port_flag_for_scripts(self):
69         return "--wpe"
70
71     @memoized
72     def _driver_class(self):
73         return WaylandDriver
74
75     def setup_environ_for_server(self, server_name=None):
76         environment = super(WPEPort, self).setup_environ_for_server(server_name)
77         environment['G_DEBUG'] = 'fatal-criticals'
78         environment['GSETTINGS_BACKEND'] = 'memory'
79         environment['TEST_RUNNER_INJECTED_BUNDLE_FILENAME'] = self._build_path('lib', 'libTestRunnerInjectedBundle.so')
80         environment['TEST_RUNNER_TEST_PLUGIN_PATH'] = self._build_path('lib', 'plugins')
81         environment['WEBKIT_EXEC_PATH'] = self._build_path('bin')
82         self._copy_value_from_environ_if_set(environment, 'WEBKIT_OUTPUTDIR')
83         self._copy_value_from_environ_if_set(environment, 'WEBKIT_JHBUILD')
84         self._copy_value_from_environ_if_set(environment, 'WEBKIT_TOP_LEVEL')
85         self._copy_value_from_environ_if_set(environment, 'WEBKIT_DEBUG')
86         self._copy_value_from_environ_if_set(environment, 'LIBGL_ALWAYS_SOFTWARE')
87         self._copy_value_from_environ_if_set(environment, 'XR_RUNTIME_JSON')
88         self._copy_value_from_environ_if_set(environment, 'WEBKIT_GST_USE_PLAYBIN3')
89         for gst_variable in ('DEBUG', 'DEBUG_DUMP_DOT_DIR', 'DEBUG_FILE', 'DEBUG_NO_COLOR',
90                              'PLUGIN_SCANNER', 'PLUGIN_PATH', 'PLUGIN_SYSTEM_PATH', 'REGISTRY',
91                              'PLUGIN_PATH_1_0'):
92             self._copy_value_from_environ_if_set(environment, 'GST_%s' % gst_variable)
93         return environment
94
95     def show_results_html_file(self, results_filename):
96         self.run_minibrowser([path.abspath_to_uri(self.host.platform, results_filename)])
97
98     def check_sys_deps(self):
99         return super(WPEPort, self).check_sys_deps() and self._driver_class().check_driver(self)
100
101     def _generate_all_test_configurations(self):
102         configurations = []
103         for build_type in self.ALL_BUILD_TYPES:
104             configurations.append(TestConfiguration(version=self.version_name(), architecture='x86', build_type=build_type))
105         return configurations
106
107     def _path_to_driver(self):
108         return self._built_executables_path(self.driver_name())
109
110     def _path_to_image_diff(self):
111         return self._built_executables_path('ImageDiff')
112
113     def _path_to_default_image_diff(self):
114         return self._path_to_image_diff()
115
116     def _search_paths(self):
117         return [self.port_name, 'glib', 'wk2'] + self.get_option("additional_platform_directory", [])
118
119     def default_baseline_search_path(self, **kwargs):
120         return list(map(self._webkit_baseline_path, self._search_paths()))
121
122     def _port_specific_expectations_files(self, **kwargs):
123         return list(map(lambda x: self._filesystem.join(self._webkit_baseline_path(x), 'TestExpectations'), reversed(self._search_paths())))
124
125     def test_expectations_file_position(self):
126         # WPE port baseline search path is wpe -> glib -> wk2 -> generic, so port test expectations file is at third to last position.
127         return 3
128
129     def _get_crash_log(self, name, pid, stdout, stderr, newer_than, target_host=None):
130         return GDBCrashLogGenerator(self._executive, name, pid, newer_than,
131                                     self._filesystem, self._path_to_driver, self.port_name, self.get_option('configuration')).generate_crash_log(stdout, stderr)
132
133     def configuration_for_upload(self, host=None):
134         configuration = super(WPEPort, self).configuration_for_upload(host=host)
135         configuration['platform'] = 'WPE'
136         return configuration
137
138     def run_minibrowser(self, args):
139         miniBrowser = self._build_path('bin', 'MiniBrowser')
140         if not self._filesystem.isfile(miniBrowser):
141             print("%s not found... Did you run build-webkit?" % miniBrowser)
142             return 1
143         command = [miniBrowser]
144         if self._should_use_jhbuild():
145             command = self._jhbuild_wrapper + command
146         return self._executive.run_command(command + args, cwd=self.webkit_base())