gtk.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. import os
  29. import subprocess
  30. from webkitpy.layout_tests.models.test_configuration import TestConfiguration
  31. from webkitpy.port.base import Port
  32. from webkitpy.port.pulseaudio_sanitizer import PulseAudioSanitizer
  33. from webkitpy.port.xvfbdriver import XvfbDriver
  34. class GtkPort(Port):
  35. port_name = "gtk"
  36. def __init__(self, *args, **kwargs):
  37. super(GtkPort, self).__init__(*args, **kwargs)
  38. self._pulseaudio_sanitizer = PulseAudioSanitizer()
  39. def warn_if_bug_missing_in_test_expectations(self):
  40. return not self.get_option('webkit_test_runner')
  41. def _port_flag_for_scripts(self):
  42. return "--gtk"
  43. def _driver_class(self):
  44. return XvfbDriver
  45. def default_timeout_ms(self):
  46. if self.get_option('configuration') == 'Debug':
  47. return 12 * 1000
  48. return 6 * 1000
  49. def setup_test_run(self):
  50. super(GtkPort, self).setup_test_run()
  51. self._pulseaudio_sanitizer.unload_pulseaudio_module()
  52. def clean_up_test_run(self):
  53. super(GtkPort, self).clean_up_test_run()
  54. self._pulseaudio_sanitizer.restore_pulseaudio_module()
  55. def setup_environ_for_server(self, server_name=None):
  56. environment = super(GtkPort, self).setup_environ_for_server(server_name)
  57. environment['GTK_MODULES'] = 'gail'
  58. environment['GSETTINGS_BACKEND'] = 'memory'
  59. environment['LIBOVERLAY_SCROLLBAR'] = '0'
  60. environment['TEST_RUNNER_INJECTED_BUNDLE_FILENAME'] = self._build_path('Libraries', 'libTestRunnerInjectedBundle.la')
  61. environment['TEST_RUNNER_TEST_PLUGIN_PATH'] = self._build_path('TestNetscapePlugin', '.libs')
  62. environment['WEBKIT_INSPECTOR_PATH'] = self._build_path('Programs', 'resources', 'inspector')
  63. environment['AUDIO_RESOURCES_PATH'] = self.path_from_webkit_base('Source', 'WebCore', 'platform', 'audio', 'resources')
  64. self._copy_value_from_environ_if_set(environment, 'WEBKITOUTPUTDIR')
  65. return environment
  66. def _generate_all_test_configurations(self):
  67. configurations = []
  68. for build_type in self.ALL_BUILD_TYPES:
  69. configurations.append(TestConfiguration(version=self._version, architecture='x86', build_type=build_type))
  70. return configurations
  71. def _path_to_driver(self):
  72. return self._build_path('Programs', self.driver_name())
  73. def _path_to_image_diff(self):
  74. return self._build_path('Programs', 'ImageDiff')
  75. def _path_to_webcore_library(self):
  76. gtk_library_names = [
  77. "libwebkitgtk-1.0.so",
  78. "libwebkitgtk-3.0.so",
  79. "libwebkit2gtk-1.0.so",
  80. ]
  81. for library in gtk_library_names:
  82. full_library = self._build_path(".libs", library)
  83. if self._filesystem.isfile(full_library):
  84. return full_library
  85. return None
  86. def _search_paths(self):
  87. search_paths = []
  88. if self.get_option('webkit_test_runner'):
  89. search_paths.extend([self.port_name + '-wk2', 'wk2'])
  90. else:
  91. search_paths.append(self.port_name + '-wk1')
  92. search_paths.append(self.port_name)
  93. search_paths.extend(self.get_option("additional_platform_directory", []))
  94. return search_paths
  95. def default_baseline_search_path(self):
  96. return map(self._webkit_baseline_path, self._search_paths())
  97. def _port_specific_expectations_files(self):
  98. return [self._filesystem.join(self._webkit_baseline_path(p), 'TestExpectations') for p in reversed(self._search_paths())]
  99. # FIXME: We should find a way to share this implmentation with Gtk,
  100. # or teach run-launcher how to call run-safari and move this down to Port.
  101. def show_results_html_file(self, results_filename):
  102. run_launcher_args = ["file://%s" % results_filename]
  103. if self.get_option('webkit_test_runner'):
  104. run_launcher_args.append('-2')
  105. # FIXME: old-run-webkit-tests also added ["-graphicssystem", "raster", "-style", "windows"]
  106. # FIXME: old-run-webkit-tests converted results_filename path for cygwin.
  107. self._run_script("run-launcher", run_launcher_args)
  108. def check_sys_deps(self, needs_http):
  109. return super(GtkPort, self).check_sys_deps(needs_http) and XvfbDriver.check_xvfb(self)
  110. def _get_gdb_output(self, coredump_path):
  111. cmd = ['gdb', '-ex', 'thread apply all bt 1024', '--batch', str(self._path_to_driver()), coredump_path]
  112. proc = subprocess.Popen(cmd, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  113. stdout, stderr = proc.communicate()
  114. errors = [l.strip().decode('utf8', 'ignore') for l in stderr.splitlines()]
  115. return (stdout.decode('utf8', 'ignore'), errors)
  116. def _get_crash_log(self, name, pid, stdout, stderr, newer_than):
  117. pid_representation = str(pid or '<unknown>')
  118. log_directory = os.environ.get("WEBKIT_CORE_DUMPS_DIRECTORY")
  119. errors = []
  120. crash_log = ''
  121. expected_crash_dump_filename = "core-pid_%s-_-process_%s" % (pid_representation, name)
  122. def match_filename(filesystem, directory, filename):
  123. if pid:
  124. return filename == expected_crash_dump_filename
  125. return filename.find(name) > -1
  126. if log_directory:
  127. dumps = self._filesystem.files_under(log_directory, file_filter=match_filename)
  128. if dumps:
  129. # Get the most recent coredump matching the pid and/or process name.
  130. coredump_path = list(reversed(sorted(dumps)))[0]
  131. if not newer_than or self._filesystem.mtime(coredump_path) > newer_than:
  132. crash_log, errors = self._get_gdb_output(coredump_path)
  133. stderr_lines = errors + (stderr or '<empty>').decode('utf8', 'ignore').splitlines()
  134. errors_str = '\n'.join(('STDERR: ' + l) for l in stderr_lines)
  135. if not crash_log:
  136. if not log_directory:
  137. log_directory = "/path/to/coredumps"
  138. core_pattern = os.path.join(log_directory, "core-pid_%p-_-process_%e")
  139. crash_log = """\
  140. Coredump %(expected_crash_dump_filename)s not found. To enable crash logs:
  141. - run this command as super-user: echo "%(core_pattern)s" > /proc/sys/kernel/core_pattern
  142. - enable core dumps: ulimit -c unlimited
  143. - set the WEBKIT_CORE_DUMPS_DIRECTORY environment variable: export WEBKIT_CORE_DUMPS_DIRECTORY=%(log_directory)s
  144. """ % locals()
  145. return (stderr, """\
  146. Crash log for %(name)s (pid %(pid_representation)s):
  147. %(crash_log)s
  148. %(errors_str)s""" % locals())