| 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 | |
| 69 | 68 |
| 70 def additional_driver_flag(self): | 69 def additional_driver_flag(self): |
| 71 flags = super(LinuxPort, self).additional_driver_flag() | 70 flags = super(LinuxPort, self).additional_driver_flag() |
| 72 if not self.get_option('disable_breakpad'): | 71 if not self.get_option('disable_breakpad'): |
| 73 flags += ['--enable-crash-reporter', '--crash-dumps-dir=%s' % self._
dump_reader.crash_dumps_directory()] | 72 flags += ['--enable-crash-reporter', '--crash-dumps-dir=%s' % self._
dump_reader.crash_dumps_directory()] |
| 74 return flags | 73 return flags |
| 75 | 74 |
| 76 def check_build(self, needs_http, printer): | 75 def check_build(self, needs_http, printer): |
| 77 result = super(LinuxPort, self).check_build(needs_http, printer) | 76 result = super(LinuxPort, self).check_build(needs_http, printer) |
| 78 | 77 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 98 # The Apache binary path can vary depending on OS and distribution | 97 # The Apache binary path can vary depending on OS and distribution |
| 99 # See http://wiki.apache.org/httpd/DistrosDefaultLayout | 98 # See http://wiki.apache.org/httpd/DistrosDefaultLayout |
| 100 for path in ['/usr/sbin/httpd', '/usr/sbin/apache2']: | 99 for path in ['/usr/sbin/httpd', '/usr/sbin/apache2']: |
| 101 if self._filesystem.exists(path): | 100 if self._filesystem.exists(path): |
| 102 return path | 101 return path |
| 103 _log.error('Could not find apache. Not installed or unknown path.') | 102 _log.error('Could not find apache. Not installed or unknown path.') |
| 104 return None | 103 return None |
| 105 | 104 |
| 106 def setup_test_run(self): | 105 def setup_test_run(self): |
| 107 super(LinuxPort, self).setup_test_run() | 106 super(LinuxPort, self).setup_test_run() |
| 108 self._start_xvfb() | |
| 109 self._setup_dummy_home_dir() | 107 self._setup_dummy_home_dir() |
| 110 | 108 |
| 111 def clean_up_test_run(self): | 109 def clean_up_test_run(self): |
| 112 super(LinuxPort, self).clean_up_test_run() | 110 super(LinuxPort, self).clean_up_test_run() |
| 113 self._stop_xvfb() | |
| 114 self._clean_up_dummy_home_dir() | 111 self._clean_up_dummy_home_dir() |
| 115 | 112 |
| 116 # | 113 # |
| 117 # PROTECTED METHODS | 114 # PROTECTED METHODS |
| 118 # | 115 # |
| 119 | 116 |
| 120 def _setup_dummy_home_dir(self): | 117 def _setup_dummy_home_dir(self): |
| 121 """Creates a dummy home directory for running the test. | 118 """Creates a dummy home directory for running the test. |
| 122 | 119 |
| 123 This is a workaround for crbug.com/595504; see crbug.com/612730. | 120 This is a workaround for crbug.com/595504; see crbug.com/612730. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 138 continue | 135 continue |
| 139 fs.copyfile(original_path, fs.join(dummy_home, filename)) | 136 fs.copyfile(original_path, fs.join(dummy_home, filename)) |
| 140 | 137 |
| 141 def _clean_up_dummy_home_dir(self): | 138 def _clean_up_dummy_home_dir(self): |
| 142 """Cleans up the dummy dir and resets the HOME environment variable.""" | 139 """Cleans up the dummy dir and resets the HOME environment variable.""" |
| 143 dummy_home = self.host.environ['HOME'] | 140 dummy_home = self.host.environ['HOME'] |
| 144 assert dummy_home != self._original_home | 141 assert dummy_home != self._original_home |
| 145 self._filesystem.rmtree(dummy_home) | 142 self._filesystem.rmtree(dummy_home) |
| 146 self.host.environ['HOME'] = self._original_home | 143 self.host.environ['HOME'] = self._original_home |
| 147 | 144 |
| 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 | |
| 187 def _path_to_driver(self, target=None): | 145 def _path_to_driver(self, target=None): |
| 188 binary_name = self.driver_name() | 146 binary_name = self.driver_name() |
| 189 return self._build_path_with_target(target, binary_name) | 147 return self._build_path_with_target(target, binary_name) |
| OLD | NEW |