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 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 _log.error('Could not find apache. Not installed or unknown path.') | 109 _log.error('Could not find apache. Not installed or unknown path.') |
| 110 return None | 110 return None |
| 111 | 111 |
| 112 def setup_test_run(self): | 112 def setup_test_run(self): |
| 113 super(LinuxPort, self).setup_test_run() | 113 super(LinuxPort, self).setup_test_run() |
| 114 self._start_xvfb() | 114 self._start_xvfb() |
| 115 self._setup_dummy_home_dir() | 115 self._setup_dummy_home_dir() |
| 116 | 116 |
| 117 def clean_up_test_run(self): | 117 def clean_up_test_run(self): |
| 118 super(LinuxPort, self).clean_up_test_run() | 118 super(LinuxPort, self).clean_up_test_run() |
| 119 self._stop_xvfb() | 119 self._stop_xvfb(save_logs=False) |
| 120 self._clean_up_dummy_home_dir() | 120 self._clean_up_dummy_home_dir() |
| 121 | 121 |
| 122 # | 122 # |
| 123 # PROTECTED METHODS | 123 # PROTECTED METHODS |
| 124 # | 124 # |
| 125 | 125 |
| 126 def _setup_dummy_home_dir(self): | 126 def _setup_dummy_home_dir(self): |
| 127 """Creates a dummy home directory for running the test. | 127 """Creates a dummy home directory for running the test. |
| 128 | 128 |
| 129 This is a workaround for crbug.com/595504; see crbug.com/612730. | 129 This is a workaround for crbug.com/595504; see crbug.com/612730. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 144 continue | 144 continue |
| 145 fs.copyfile(original_path, fs.join(dummy_home, filename)) | 145 fs.copyfile(original_path, fs.join(dummy_home, filename)) |
| 146 | 146 |
| 147 def _clean_up_dummy_home_dir(self): | 147 def _clean_up_dummy_home_dir(self): |
| 148 """Cleans up the dummy dir and resets the HOME environment variable.""" | 148 """Cleans up the dummy dir and resets the HOME environment variable.""" |
| 149 dummy_home = self.host.environ['HOME'] | 149 dummy_home = self.host.environ['HOME'] |
| 150 assert dummy_home != self._original_home | 150 assert dummy_home != self._original_home |
| 151 self._filesystem.rmtree(dummy_home) | 151 self._filesystem.rmtree(dummy_home) |
| 152 self.host.environ['HOME'] = self._original_home | 152 self.host.environ['HOME'] = self._original_home |
| 153 | 153 |
| 154 def _start_xvfb(self): | 154 def _start_xvfb(self): |
|
mithro
2017/04/27 03:34:51
I think one of the _log statements which describes
Dirk Pranke
2017/04/27 17:18:31
I've tried pretty hard to keep run-webkit-tests as
mithro
2017/04/28 05:46:31
I agree having the output for a human being readab
| |
| 155 display = self._find_display() | 155 display = self._find_display() |
| 156 if not display: | 156 if not display: |
| 157 _log.warn('Failed to find a free display to start Xvfb.') | 157 _log.warn('Failed to find a free display to start Xvfb.') |
| 158 return | 158 return |
| 159 | 159 |
| 160 _log.info('Starting Xvfb with display "%s".', display) | 160 _log.debug('Starting Xvfb with display "%s".', display) |
| 161 self._xvfb_stdout = tempfile.NamedTemporaryFile(delete=False) | 161 self._xvfb_stdout = tempfile.NamedTemporaryFile(delete=False) |
| 162 self._xvfb_stderr = tempfile.NamedTemporaryFile(delete=False) | 162 self._xvfb_stderr = tempfile.NamedTemporaryFile(delete=False) |
| 163 self._xvfb_process = self.host.executive.popen( | 163 self._xvfb_process = self.host.executive.popen( |
| 164 ['Xvfb', display, '-screen', '0', '1280x800x24', '-ac', '-dpi', '96' ], | 164 ['Xvfb', display, '-screen', '0', '1280x800x24', '-ac', '-dpi', '96' ], |
| 165 stdout=self._xvfb_stdout, stderr=self._xvfb_stderr) | 165 stdout=self._xvfb_stdout, stderr=self._xvfb_stderr) |
| 166 | 166 |
| 167 # By setting DISPLAY here, the individual worker processes will | 167 # By setting DISPLAY here, the individual worker processes will |
| 168 # get the right DISPLAY. Note, if this environment could be passed | 168 # get the right DISPLAY. Note, if this environment could be passed |
| 169 # when creating workers, then we wouldn't need to modify DISPLAY here. | 169 # when creating workers, then we wouldn't need to modify DISPLAY here. |
| 170 self._original_display = self.host.environ.get('DISPLAY') | 170 self._original_display = self.host.environ.get('DISPLAY') |
| 171 self.host.environ['DISPLAY'] = display | 171 self.host.environ['DISPLAY'] = display |
| 172 | 172 |
| 173 # The poll() method will return None if the process has not terminated: | 173 # The poll() method will return None if the process has not terminated: |
| 174 # https://docs.python.org/2/library/subprocess.html#subprocess.Popen.pol l | 174 # https://docs.python.org/2/library/subprocess.html#subprocess.Popen.pol l |
| 175 if self._xvfb_process.poll() is not None: | 175 if self._xvfb_process.poll() is not None: |
| 176 _log.warn('Failed to start Xvfb on display "%s."', display) | 176 _log.warn('Failed to start Xvfb on display "%s."', display) |
| 177 self._stop_xvfb() | 177 self._stop_xvfb(save_logs=True) |
| 178 | 178 |
| 179 start_time = self.host.time() | 179 start_time = self.host.time() |
| 180 while self.host.time() - start_time < self.XVFB_START_TIMEOUT: | 180 while self.host.time() - start_time < self.XVFB_START_TIMEOUT: |
|
mithro
2017/04/27 03:34:51
BTW - We should probably be checking self._xvfb_pr
Dirk Pranke
2017/04/27 17:18:31
Sure.
| |
| 181 # We don't explicitly set the display, as we want to check the | 181 # We don't explicitly set the display, as we want to check the |
| 182 # environment value. | 182 # environment value. |
| 183 exit_code = self.host.executive.run_command( | 183 exit_code = self.host.executive.run_command( |
| 184 ['xdpyinfo'], return_exit_code=True) | 184 ['xdpyinfo'], return_exit_code=True) |
| 185 if exit_code == 0: | 185 if exit_code == 0: |
| 186 _log.info('Successfully started Xvfb with display "%s".', displa y) | 186 _log.debug('Successfully started Xvfb with display "%s".', displ ay) |
| 187 return | 187 return |
| 188 _log.warn('xdpyinfo check failed with exit code %s while starting Xv fb on "%s".', exit_code, display) | 188 _log.warn('xdpyinfo check failed with exit code %s while starting Xv fb on "%s".', exit_code, display) |
| 189 self.host.sleep(0.1) | 189 self.host.sleep(0.1) |
| 190 _log.fatal('Failed to start Xvfb on display "%s" (xdpyinfo check failed) .', display) | 190 _log.fatal('Failed to start Xvfb on display "%s" (xdpyinfo check failed) .', display) |
| 191 self._stop_xvfb() | 191 self._stop_xvfb(save_logs=True) |
| 192 | 192 |
| 193 def _find_display(self): | 193 def _find_display(self): |
| 194 """Tries to find a free X display, looping if necessary.""" | 194 """Tries to find a free X display, looping if necessary.""" |
| 195 # The "xvfb-run" command uses :99 by default. | 195 # The "xvfb-run" command uses :99 by default. |
| 196 for display_number in range(99, 120): | 196 for display_number in range(99, 120): |
| 197 display = ':%d' % display_number | 197 display = ':%d' % display_number |
| 198 exit_code = self.host.executive.run_command( | 198 exit_code = self.host.executive.run_command( |
| 199 ['xdpyinfo', '-display', display], return_exit_code=True) | 199 ['xdpyinfo', '-display', display], return_exit_code=True) |
| 200 if exit_code == 1: | 200 if exit_code == 1: |
| 201 return display | 201 return display |
| 202 return None | 202 return None |
| 203 | 203 |
| 204 def _stop_xvfb(self): | 204 def _stop_xvfb(self, save_logs): |
| 205 if self._original_display: | 205 if self._original_display: |
| 206 self.host.environ['DISPLAY'] = self._original_display | 206 self.host.environ['DISPLAY'] = self._original_display |
| 207 if self._xvfb_stdout: | 207 if self._xvfb_stdout: |
| 208 self._xvfb_stdout.close() | 208 self._xvfb_stdout.close() |
| 209 if self._xvfb_stderr: | 209 if self._xvfb_stderr: |
| 210 self._xvfb_stderr.close() | 210 self._xvfb_stderr.close() |
| 211 if self._xvfb_process: | 211 if self._xvfb_process: |
| 212 _log.debug('Killing Xvfb process pid %d.', self._xvfb_process.pid) | 212 _log.debug('Killing Xvfb process pid %d.', self._xvfb_process.pid) |
| 213 self._xvfb_process.kill() | 213 self._xvfb_process.kill() |
| 214 self._xvfb_process.wait() | 214 self._xvfb_process.wait() |
| 215 if self._xvfb_stdout and self.host.filesystem.exists(self._xvfb_stdout.n ame): | 215 if save_logs and self._xvfb_stdout and self.host.filesystem.exists(self. _xvfb_stdout.name): |
| 216 for line in self.host.filesystem.read_text_file(self._xvfb_stdout.na me).splitlines(): | 216 for line in self.host.filesystem.read_text_file(self._xvfb_stdout.na me).splitlines(): |
| 217 _log.warn('Xvfb stdout: %s', line) | 217 _log.warn('Xvfb stdout: %s', line) |
| 218 self.host.filesystem.remove(self._xvfb_stdout.name) | 218 self.host.filesystem.remove(self._xvfb_stdout.name) |
| 219 if self._xvfb_stderr and self.host.filesystem.exists(self._xvfb_stderr.n ame): | 219 if save_logs and self._xvfb_stderr and self.host.filesystem.exists(self. _xvfb_stderr.name): |
| 220 for line in self.host.filesystem.read_text_file(self._xvfb_stderr.na me).splitlines(): | 220 for line in self.host.filesystem.read_text_file(self._xvfb_stderr.na me).splitlines(): |
| 221 _log.warn('Xvfb stderr: %s', line) | 221 _log.warn('Xvfb stderr: %s', line) |
| 222 self.host.filesystem.remove(self._xvfb_stderr.name) | 222 self.host.filesystem.remove(self._xvfb_stderr.name) |
| 223 self._xvfb_stdout = self._xvfb_stderr = self._xvfb_process = None | 223 self._xvfb_stdout = self._xvfb_stderr = self._xvfb_process = None |
| 224 | 224 |
| 225 def _path_to_driver(self, target=None): | 225 def _path_to_driver(self, target=None): |
| 226 binary_name = self.driver_name() | 226 binary_name = self.driver_name() |
| 227 return self._build_path_with_target(target, binary_name) | 227 return self._build_path_with_target(target, binary_name) |
| OLD | NEW |