| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 def __init__(self, host, port_name, **kwargs): | 59 def __init__(self, host, port_name, **kwargs): |
| 60 super(LinuxPort, self).__init__(host, port_name, **kwargs) | 60 super(LinuxPort, self).__init__(host, port_name, **kwargs) |
| 61 self._version = port_name[port_name.index('linux-') + len('linux-'):] | 61 self._version = port_name[port_name.index('linux-') + len('linux-'):] |
| 62 self._architecture = 'x86_64' | 62 self._architecture = 'x86_64' |
| 63 assert self._version in self.SUPPORTED_VERSIONS | 63 assert self._version in self.SUPPORTED_VERSIONS |
| 64 | 64 |
| 65 if not self.get_option('disable_breakpad'): | 65 if not self.get_option('disable_breakpad'): |
| 66 self._dump_reader = DumpReaderLinux(host, self._build_path()) | 66 self._dump_reader = DumpReaderLinux(host, self._build_path()) |
| 67 self._original_home = None | 67 self._original_home = None |
| 68 self._xvfb_process = None |
| 68 | 69 |
| 69 def additional_driver_flag(self): | 70 def additional_driver_flag(self): |
| 70 flags = super(LinuxPort, self).additional_driver_flag() | 71 flags = super(LinuxPort, self).additional_driver_flag() |
| 71 if not self.get_option('disable_breakpad'): | 72 if not self.get_option('disable_breakpad'): |
| 72 flags += ['--enable-crash-reporter', '--crash-dumps-dir=%s' % self._
dump_reader.crash_dumps_directory()] | 73 flags += ['--enable-crash-reporter', '--crash-dumps-dir=%s' % self._
dump_reader.crash_dumps_directory()] |
| 73 return flags | 74 return flags |
| 74 | 75 |
| 75 def check_build(self, needs_http, printer): | 76 def check_build(self, needs_http, printer): |
| 76 result = super(LinuxPort, self).check_build(needs_http, printer) | 77 result = super(LinuxPort, self).check_build(needs_http, printer) |
| 77 | 78 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 97 # The Apache binary path can vary depending on OS and distribution | 98 # The Apache binary path can vary depending on OS and distribution |
| 98 # See http://wiki.apache.org/httpd/DistrosDefaultLayout | 99 # See http://wiki.apache.org/httpd/DistrosDefaultLayout |
| 99 for path in ['/usr/sbin/httpd', '/usr/sbin/apache2']: | 100 for path in ['/usr/sbin/httpd', '/usr/sbin/apache2']: |
| 100 if self._filesystem.exists(path): | 101 if self._filesystem.exists(path): |
| 101 return path | 102 return path |
| 102 _log.error('Could not find apache. Not installed or unknown path.') | 103 _log.error('Could not find apache. Not installed or unknown path.') |
| 103 return None | 104 return None |
| 104 | 105 |
| 105 def setup_test_run(self): | 106 def setup_test_run(self): |
| 106 super(LinuxPort, self).setup_test_run() | 107 super(LinuxPort, self).setup_test_run() |
| 108 self._start_xvfb() |
| 107 self._setup_dummy_home_dir() | 109 self._setup_dummy_home_dir() |
| 108 | 110 |
| 109 def clean_up_test_run(self): | 111 def clean_up_test_run(self): |
| 110 super(LinuxPort, self).clean_up_test_run() | 112 super(LinuxPort, self).clean_up_test_run() |
| 113 self._stop_xvfb() |
| 111 self._clean_up_dummy_home_dir() | 114 self._clean_up_dummy_home_dir() |
| 112 | 115 |
| 113 # | 116 # |
| 114 # PROTECTED METHODS | 117 # PROTECTED METHODS |
| 115 # | 118 # |
| 116 | 119 |
| 117 def _setup_dummy_home_dir(self): | 120 def _setup_dummy_home_dir(self): |
| 118 """Creates a dummy home directory for running the test. | 121 """Creates a dummy home directory for running the test. |
| 119 | 122 |
| 120 This is a workaround for crbug.com/595504; see crbug.com/612730. | 123 This is a workaround for crbug.com/595504; see crbug.com/612730. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 135 continue | 138 continue |
| 136 fs.copyfile(original_path, fs.join(dummy_home, filename)) | 139 fs.copyfile(original_path, fs.join(dummy_home, filename)) |
| 137 | 140 |
| 138 def _clean_up_dummy_home_dir(self): | 141 def _clean_up_dummy_home_dir(self): |
| 139 """Cleans up the dummy dir and resets the HOME environment variable.""" | 142 """Cleans up the dummy dir and resets the HOME environment variable.""" |
| 140 dummy_home = self.host.environ['HOME'] | 143 dummy_home = self.host.environ['HOME'] |
| 141 assert dummy_home != self._original_home | 144 assert dummy_home != self._original_home |
| 142 self._filesystem.rmtree(dummy_home) | 145 self._filesystem.rmtree(dummy_home) |
| 143 self.host.environ['HOME'] = self._original_home | 146 self.host.environ['HOME'] = self._original_home |
| 144 | 147 |
| 148 def _start_xvfb(self): |
| 149 display = self._find_display() |
| 150 if not display: |
| 151 _log.warn('Failed to find a free display to start Xvfb.') |
| 152 return |
| 153 |
| 154 _log.info('Starting Xvfb with display "%s".', display) |
| 155 self._xvfb_process = self.host.executive.popen( |
| 156 ['Xvfb', display, '-screen', '0', '1280x800x24', '-ac', '-dpi', '96'
], |
| 157 stderr=self.host.executive.DEVNULL) |
| 158 |
| 159 # By setting DISPLAY here, the individual worker processes will |
| 160 # get the right DISPLAY. Note, if this environment could be passed |
| 161 # when creating workers, then we wouldn't need to modify DISPLAY here. |
| 162 self.host.environ['DISPLAY'] = display |
| 163 |
| 164 # The poll() method will return None if the process has not terminated: |
| 165 # https://docs.python.org/2/library/subprocess.html#subprocess.Popen.pol
l |
| 166 if self._xvfb_process.poll() is not None: |
| 167 _log.warn('Failed to start Xvfb on display "%s."', display) |
| 168 |
| 169 def _find_display(self): |
| 170 """Tries to find a free X display, looping if necessary.""" |
| 171 # The "xvfb-run" command uses :99 by default. |
| 172 for display_number in range(99, 120): |
| 173 display = ':%d' % display_number |
| 174 exit_code = self.host.executive.run_command( |
| 175 ['xdpyinfo', '-display', display], return_exit_code=True) |
| 176 if exit_code == 1: |
| 177 return display |
| 178 return None |
| 179 |
| 180 def _stop_xvfb(self): |
| 181 if not self._xvfb_process: |
| 182 return |
| 183 _log.debug('Killing Xvfb process pid %d.', self._xvfb_process.pid) |
| 184 self._xvfb_process.kill() |
| 185 self._xvfb_process.wait() |
| 186 |
| 145 def _path_to_driver(self, target=None): | 187 def _path_to_driver(self, target=None): |
| 146 binary_name = self.driver_name() | 188 binary_name = self.driver_name() |
| 147 return self._build_path_with_target(target, binary_name) | 189 return self._build_path_with_target(target, binary_name) |
| OLD | NEW |