Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (C) 2010 Google Inc. All rights reserved. | 1 # Copyright (C) 2010 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| 11 # in the documentation and/or other materials provided with the | 11 # in the documentation and/or other materials provided with the |
| 12 # distribution. | 12 # distribution. |
| 13 # * Neither the name of Google Inc. nor the names of its | 13 # * Neither the name of Google Inc. nor the names of its |
| 14 # contributors may be used to endorse or promote products derived from | 14 # contributors may be used to endorse or promote products derived from |
| 15 # this software without specific prior written permission. | 15 # this software without specific prior written permission. |
| 16 # | 16 # |
| 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | 28 |
| 29 import logging | 29 import logging |
| 30 import tempfile | |
| 30 | 31 |
| 31 from webkitpy.layout_tests.breakpad.dump_reader_multipart import DumpReaderLinux | 32 from webkitpy.layout_tests.breakpad.dump_reader_multipart import DumpReaderLinux |
| 32 from webkitpy.layout_tests.port import base | 33 from webkitpy.layout_tests.port import base |
| 33 from webkitpy.layout_tests.port import win | 34 from webkitpy.layout_tests.port import win |
| 34 | 35 |
| 35 | 36 |
| 36 _log = logging.getLogger(__name__) | 37 _log = logging.getLogger(__name__) |
| 37 | 38 |
| 38 | 39 |
| 39 class LinuxPort(base.Port): | 40 class LinuxPort(base.Port): |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 60 super(LinuxPort, self).__init__(host, port_name, **kwargs) | 61 super(LinuxPort, self).__init__(host, port_name, **kwargs) |
| 61 self._version = port_name[port_name.index('linux-') + len('linux-'):] | 62 self._version = port_name[port_name.index('linux-') + len('linux-'):] |
| 62 self._architecture = 'x86_64' | 63 self._architecture = 'x86_64' |
| 63 assert self._version in self.SUPPORTED_VERSIONS | 64 assert self._version in self.SUPPORTED_VERSIONS |
| 64 | 65 |
| 65 if not self.get_option('disable_breakpad'): | 66 if not self.get_option('disable_breakpad'): |
| 66 self._dump_reader = DumpReaderLinux(host, self._build_path()) | 67 self._dump_reader = DumpReaderLinux(host, self._build_path()) |
| 67 self._original_home = None | 68 self._original_home = None |
| 68 self._original_display = None | 69 self._original_display = None |
| 69 self._xvfb_process = None | 70 self._xvfb_process = None |
| 71 self._xvfb_stdout = None | |
| 72 self._xvfb_stderr = None | |
| 70 | 73 |
| 71 def additional_driver_flag(self): | 74 def additional_driver_flag(self): |
| 72 flags = super(LinuxPort, self).additional_driver_flag() | 75 flags = super(LinuxPort, self).additional_driver_flag() |
| 73 if not self.get_option('disable_breakpad'): | 76 if not self.get_option('disable_breakpad'): |
| 74 flags += ['--enable-crash-reporter', '--crash-dumps-dir=%s' % self._ dump_reader.crash_dumps_directory()] | 77 flags += ['--enable-crash-reporter', '--crash-dumps-dir=%s' % self._ dump_reader.crash_dumps_directory()] |
| 75 return flags | 78 return flags |
| 76 | 79 |
| 77 def check_build(self, needs_http, printer): | 80 def check_build(self, needs_http, printer): |
| 78 result = super(LinuxPort, self).check_build(needs_http, printer) | 81 result = super(LinuxPort, self).check_build(needs_http, printer) |
| 79 | 82 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 self._filesystem.rmtree(dummy_home) | 149 self._filesystem.rmtree(dummy_home) |
| 147 self.host.environ['HOME'] = self._original_home | 150 self.host.environ['HOME'] = self._original_home |
| 148 | 151 |
| 149 def _start_xvfb(self): | 152 def _start_xvfb(self): |
| 150 display = self._find_display() | 153 display = self._find_display() |
| 151 if not display: | 154 if not display: |
| 152 _log.warn('Failed to find a free display to start Xvfb.') | 155 _log.warn('Failed to find a free display to start Xvfb.') |
| 153 return | 156 return |
| 154 | 157 |
| 155 _log.info('Starting Xvfb with display "%s".', display) | 158 _log.info('Starting Xvfb with display "%s".', display) |
| 159 self._xvfb_stdout = tempfile.NamedTemporaryFile(delete=False) | |
| 160 self._xvfb_stderr = tempfile.NamedTemporaryFile(delete=False) | |
| 156 self._xvfb_process = self.host.executive.popen( | 161 self._xvfb_process = self.host.executive.popen( |
| 157 ['Xvfb', display, '-screen', '0', '1280x800x24', '-ac', '-dpi', '96' ], | 162 ['Xvfb', display, '-screen', '0', '1280x800x24', '-ac', '-dpi', '96' ], |
| 158 stderr=self.host.executive.DEVNULL) | 163 stdout=self._xvfb_stdout, stderr=self._xvfb_stderr) |
| 159 | 164 |
| 160 # By setting DISPLAY here, the individual worker processes will | 165 # By setting DISPLAY here, the individual worker processes will |
| 161 # get the right DISPLAY. Note, if this environment could be passed | 166 # get the right DISPLAY. Note, if this environment could be passed |
| 162 # when creating workers, then we wouldn't need to modify DISPLAY here. | 167 # when creating workers, then we wouldn't need to modify DISPLAY here. |
| 163 self._original_display = self.host.environ.get('DISPLAY') | 168 self._original_display = self.host.environ.get('DISPLAY') |
| 164 self.host.environ['DISPLAY'] = display | 169 self.host.environ['DISPLAY'] = display |
| 165 | 170 |
| 166 # The poll() method will return None if the process has not terminated: | 171 # The poll() method will return None if the process has not terminated: |
| 167 # https://docs.python.org/2/library/subprocess.html#subprocess.Popen.pol l | 172 # https://docs.python.org/2/library/subprocess.html#subprocess.Popen.pol l |
| 168 if self._xvfb_process.poll() is not None: | 173 if self._xvfb_process.poll() is not None: |
|
mithro
2017/04/26 01:57:17
Can you just call _stop_xvfb here? Or maybe share
Dirk Pranke
2017/04/26 02:03:00
Yeah, I should be able to refactor it.
| |
| 169 _log.warn('Failed to start Xvfb on display "%s."', display) | 174 _log.warn('Failed to start Xvfb on display "%s."', display) |
| 175 self._xvfb_stdout.close() | |
| 176 self._xvfb_stderr.close() | |
| 177 _log.warn('Xvfb stdout:\n%s', self.host.filesystem.read_text_file(se lf._xvfb_stdout.name)) | |
| 178 _log.warn('Xvfb stderr:\n%s', self.host.filesystem.read_text_file(se lf._xvfb_stderr.name)) | |
| 179 self.host.filesystem.remove(self._xvfb_stdout.name) | |
| 180 self.host.filesystem.remove(self._xvfb_stderr.name) | |
| 170 | 181 |
| 171 def _find_display(self): | 182 def _find_display(self): |
| 172 """Tries to find a free X display, looping if necessary.""" | 183 """Tries to find a free X display, looping if necessary.""" |
| 173 # The "xvfb-run" command uses :99 by default. | 184 # The "xvfb-run" command uses :99 by default. |
| 174 for display_number in range(99, 120): | 185 for display_number in range(99, 120): |
| 175 display = ':%d' % display_number | 186 display = ':%d' % display_number |
| 176 exit_code = self.host.executive.run_command( | 187 exit_code = self.host.executive.run_command( |
| 177 ['xdpyinfo', '-display', display], return_exit_code=True) | 188 ['xdpyinfo', '-display', display], return_exit_code=True) |
| 178 if exit_code == 1: | 189 if exit_code == 1: |
| 179 return display | 190 return display |
| 180 return None | 191 return None |
| 181 | 192 |
| 182 def _stop_xvfb(self): | 193 def _stop_xvfb(self): |
| 183 if self._original_display: | 194 if self._original_display: |
| 184 self.host.environ['DISPLAY'] = self._original_display | 195 self.host.environ['DISPLAY'] = self._original_display |
| 196 if self._xvfb_stdout: | |
| 197 self._xvfb_stdout.close() | |
| 198 if self._xvfb_stderr: | |
| 199 self._xvfb_stderr.close() | |
| 185 if not self._xvfb_process: | 200 if not self._xvfb_process: |
| 186 return | 201 return |
| 187 _log.debug('Killing Xvfb process pid %d.', self._xvfb_process.pid) | 202 _log.debug('Killing Xvfb process pid %d.', self._xvfb_process.pid) |
| 188 self._xvfb_process.kill() | 203 self._xvfb_process.kill() |
| 189 self._xvfb_process.wait() | 204 self._xvfb_process.wait() |
| 205 _log.warn('Xvfb stdout:\n%s', self.host.filesystem.read_text_file(self._ xvfb_stdout.name)) | |
| 206 _log.warn('Xvfb stderr:\n%s', self.host.filesystem.read_text_file(self._ xvfb_stderr.name)) | |
| 207 self.host.filesystem.remove(self._xvfb_stdout.name) | |
| 208 self.host.filesystem.remove(self._xvfb_stderr.name) | |
| 209 | |
| 190 | 210 |
| 191 | 211 |
| 192 def _path_to_driver(self, target=None): | 212 def _path_to_driver(self, target=None): |
| 193 binary_name = self.driver_name() | 213 binary_name = self.driver_name() |
| 194 return self._build_path_with_target(target, binary_name) | 214 return self._build_path_with_target(target, binary_name) |
| OLD | NEW |