Allow a port to run tests with a custom device setup
[WebKit-https.git] / Tools / Scripts / webkitpy / port / efl.py
1 # Copyright (C) 2011 ProFUSION Embedded Systems. All rights reserved.
2 # Copyright (C) 2011 Samsung Electronics. All rights reserved.
3 # Copyright (C) 2012 Intel Corporation
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 #
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 """WebKit Efl implementation of the Port interface."""
29
30 import os
31
32 from webkitpy.common.system import path
33 from webkitpy.layout_tests.models.test_configuration import TestConfiguration
34 from webkitpy.port.base import Port
35 from webkitpy.port.pulseaudio_sanitizer import PulseAudioSanitizer
36 from webkitpy.port.xorgdriver import XorgDriver
37 from webkitpy.port.xvfbdriver import XvfbDriver
38 from webkitpy.port.linux_get_crash_log import GDBCrashLogGenerator
39
40
41 class EflPort(Port):
42     port_name = 'efl'
43
44     def __init__(self, *args, **kwargs):
45         super(EflPort, self).__init__(*args, **kwargs)
46
47         self._jhbuild_wrapper = [self.path_from_webkit_base('Tools', 'jhbuild', 'jhbuild-wrapper'), '--efl', 'run']
48
49         self.set_option_default('wrapper', ' '.join(self._jhbuild_wrapper))
50         self.webprocess_cmd_prefix = self.get_option('webprocess_cmd_prefix')
51
52         self._pulseaudio_sanitizer = PulseAudioSanitizer()
53
54     def _port_flag_for_scripts(self):
55         return "--efl"
56
57     def setup_test_run(self, device_class=None):
58         super(EflPort, self).setup_test_run(device_class)
59         self._pulseaudio_sanitizer.unload_pulseaudio_module()
60
61     def setup_environ_for_server(self, server_name=None):
62         env = super(EflPort, self).setup_environ_for_server(server_name)
63
64         # If DISPLAY environment variable is unset in the system
65         # e.g. on build bot, remove DISPLAY variable from the dictionary
66         if not 'DISPLAY' in os.environ:
67             del env['DISPLAY']
68
69         if 'ACCESSIBILITY_EAIL_LIBRARY_PATH' in os.environ:
70             env['ACCESSIBILITY_EAIL_LIBRARY_PATH'] = os.environ['ACCESSIBILITY_EAIL_LIBRARY_PATH']
71
72         env['TEST_RUNNER_INJECTED_BUNDLE_FILENAME'] = self._build_path('lib', 'libTestRunnerInjectedBundle.so')
73         env['TEST_RUNNER_PLUGIN_PATH'] = self._build_path('lib', 'plugins')
74
75         # Silence GIO warnings about using the "memory" GSettings backend.
76         env['GSETTINGS_BACKEND'] = 'memory'
77
78         if self.webprocess_cmd_prefix:
79             env['WEB_PROCESS_CMD_PREFIX'] = self.webprocess_cmd_prefix
80
81         return env
82
83     def supports_per_test_timeout(self):
84         return True
85
86     def default_timeout_ms(self):
87         # Tests run considerably slower under gdb
88         # or valgrind.
89         if self.get_option('webprocess_cmd_prefix'):
90             return 350 * 1000
91         return super(EflPort, self).default_timeout_ms()
92
93     def clean_up_test_run(self):
94         super(EflPort, self).clean_up_test_run()
95         self._pulseaudio_sanitizer.restore_pulseaudio_module()
96
97     def _generate_all_test_configurations(self):
98         return [TestConfiguration(version=self._version, architecture='x86', build_type=build_type) for build_type in self.ALL_BUILD_TYPES]
99
100     def _driver_class(self):
101         if os.environ.get("USE_NATIVE_XDISPLAY"):
102             return XorgDriver
103         return XvfbDriver
104
105     def _path_to_driver(self):
106         return self._build_path('bin', self.driver_name())
107
108     def _path_to_image_diff(self):
109         return self._build_path('bin', 'ImageDiff')
110
111     def _image_diff_command(self, *args, **kwargs):
112         return self._jhbuild_wrapper + super(EflPort, self)._image_diff_command(*args, **kwargs)
113
114     def _path_to_webcore_library(self):
115         static_path = self._build_path('lib', 'libwebcore_efl.a')
116         dyn_path = self._build_path('lib', 'libwebcore_efl.so')
117         return static_path if self._filesystem.exists(static_path) else dyn_path
118
119     def _search_paths(self):
120         search_paths = []
121         search_paths.append(self.port_name)
122         search_paths.append('wk2')
123         return search_paths
124
125     def default_baseline_search_path(self):
126         return map(self._webkit_baseline_path, self._search_paths())
127
128     def _port_specific_expectations_files(self):
129         # FIXME: We should be able to use the default algorithm here.
130         return list(reversed([self._filesystem.join(self._webkit_baseline_path(p), 'TestExpectations') for p in self._search_paths()]))
131
132     def show_results_html_file(self, results_filename):
133         self._run_script("run-minibrowser", [path.abspath_to_uri(self.host.platform, results_filename)])
134
135     def check_sys_deps(self, needs_http):
136         return super(EflPort, self).check_sys_deps(needs_http) and self._driver_class().check_driver(self)
137
138     def build_webkit_command(self, build_style=None):
139         command = super(EflPort, self).build_webkit_command(build_style)
140         command.extend(["--efl", "--update-efl"])
141         command.append(super(EflPort, self).make_args())
142         return command
143
144     def _get_crash_log(self, name, pid, stdout, stderr, newer_than):
145         return GDBCrashLogGenerator(name, pid, newer_than, self._filesystem, self.path_to_script("process-linux-coredump"), self._path_to_driver).generate_crash_log(stdout, stderr)
146
147     def test_expectations_file_position(self):
148         # EFL port baseline search path is efl -> wk2 -> generic (as efl-wk2 and efl baselines are merged), so port test expectations file is at third to last position.
149         return 2