OLD | NEW |
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import logging, os, re | 5 import logging, os, re |
6 from autotest_lib.client.bin import site_log_reader, site_utils, test | 6 from autotest_lib.client.bin import site_log_reader, site_utils, test |
7 from autotest_lib.client.common_lib import error, utils | 7 from autotest_lib.client.common_lib import error, utils |
8 | 8 |
9 | 9 |
10 class CrashTest(test.test): | 10 class CrashTest(test.test): |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 return {'exec_name': exec_name, | 179 return {'exec_name': exec_name, |
180 'report_kind': report_kind, | 180 'report_kind': report_kind, |
181 'meta_path': meta_path, | 181 'meta_path': meta_path, |
182 'report_payload': report_payload, | 182 'report_payload': report_payload, |
183 'send_attempt': send_attempt, | 183 'send_attempt': send_attempt, |
184 'send_success': send_success, | 184 'send_success': send_success, |
185 'sleep_time': sleep_time, | 185 'sleep_time': sleep_time, |
186 'output': output} | 186 'output': output} |
187 | 187 |
188 | 188 |
| 189 def wait_for_sender_completion(self): |
| 190 """Wait for crash_sender to complete. |
| 191 |
| 192 Wait for no crash_sender's last message to be placed in the |
| 193 system log before continuing and for the process to finish. |
| 194 Otherwise we might get only part of the output.""" |
| 195 site_utils.poll_for_condition( |
| 196 lambda: self._log_reader.can_find('crash_sender done.'), |
| 197 timeout=60, |
| 198 exception=error.TestError( |
| 199 'Timeout waiting for crash_sender to emit done: ' + |
| 200 self._log_reader.get_logs())) |
| 201 site_utils.poll_for_condition( |
| 202 lambda: utils.system('pgrep crash_sender', |
| 203 ignore_status=True) != 0, |
| 204 timeout=60, |
| 205 exception=error.TestError( |
| 206 'Timeout waiting for crash_sender to finish: ' + |
| 207 self._log_reader.get_logs())) |
| 208 |
| 209 |
189 def _call_sender_one_crash(self, | 210 def _call_sender_one_crash(self, |
190 send_success=True, | 211 send_success=True, |
191 reports_enabled=True, | 212 reports_enabled=True, |
192 username='root', | 213 username='root', |
193 report=None): | 214 report=None): |
194 """Call the crash sender script to mock upload one crash. | 215 """Call the crash sender script to mock upload one crash. |
195 | 216 |
196 Args: | 217 Args: |
197 send_success: Mock a successful send if true | 218 send_success: Mock a successful send if true |
198 reports_enabled: Has the user consented to sending crash reports. | 219 reports_enabled: Has the user consented to sending crash reports. |
199 username: user to emulate a crash from | 220 username: user to emulate a crash from |
200 report: report to use for crash, if None we create one. | 221 report: report to use for crash, if None we create one. |
201 | 222 |
202 Returns: | 223 Returns: |
203 Returns a dictionary describing the result with the keys | 224 Returns a dictionary describing the result with the keys |
204 from _parse_sender_output, as well as: | 225 from _parse_sender_output, as well as: |
205 report_exists: does the minidump still exist after calling | 226 report_exists: does the minidump still exist after calling |
206 send script | 227 send script |
207 rate_count: how many crashes have been uploaded in the past | 228 rate_count: how many crashes have been uploaded in the past |
208 24 hours. | 229 24 hours. |
209 """ | 230 """ |
210 report = self._prepare_sender_one_crash(send_success, | 231 report = self._prepare_sender_one_crash(send_success, |
211 reports_enabled, | 232 reports_enabled, |
212 username, | 233 username, |
213 report) | 234 report) |
214 self._log_reader.set_start_by_current() | 235 self._log_reader.set_start_by_current() |
215 script_output = utils.system_output( | 236 script_output = utils.system_output( |
216 '/bin/sh -c "%s" 2>&1' % self._CRASH_SENDER_PATH, | 237 '/bin/sh -c "%s" 2>&1' % self._CRASH_SENDER_PATH, |
217 ignore_status=True) | 238 ignore_status=True) |
218 # Wait for up to 2s for no crash_sender to be running, | 239 self.wait_for_sender_completion() |
219 # otherwise me might get only part of the output. | |
220 site_utils.poll_for_condition( | |
221 lambda: utils.system('pgrep crash_sender', | |
222 ignore_status=True) != 0, | |
223 timeout=2, | |
224 exception=error.TestError( | |
225 'Timeout waiting for crash_sender to finish: ' + | |
226 self._log_reader.get_logs())) | |
227 | |
228 output = self._log_reader.get_logs() | 240 output = self._log_reader.get_logs() |
229 logging.debug('Crash sender message output:\n' + output) | 241 logging.debug('Crash sender message output:\n' + output) |
230 if script_output != '': | 242 if script_output != '': |
231 raise error.TestFail( | 243 raise error.TestFail( |
232 'Unexpected crash_sender stdout/stderr: ' + script_output) | 244 'Unexpected crash_sender stdout/stderr: ' + script_output) |
233 | 245 |
234 if os.path.exists(report): | 246 if os.path.exists(report): |
235 report_exists = True | 247 report_exists = True |
236 os.remove(report) | 248 os.remove(report) |
237 else: | 249 else: |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 self._initialize_crash_reporter() | 313 self._initialize_crash_reporter() |
302 # Disable crash_sender from running, kill off any running ones, but | 314 # Disable crash_sender from running, kill off any running ones, but |
303 # set environment so crash_sender may run as a child process. | 315 # set environment so crash_sender may run as a child process. |
304 self._set_system_sending(False) | 316 self._set_system_sending(False) |
305 self._set_child_sending(True) | 317 self._set_child_sending(True) |
306 self._kill_running_sender() | 318 self._kill_running_sender() |
307 self._reset_rate_limiting() | 319 self._reset_rate_limiting() |
308 if clear_spool_first: | 320 if clear_spool_first: |
309 self._clear_spooled_crashes() | 321 self._clear_spooled_crashes() |
310 getattr(self, '_test_' + test_name)() | 322 getattr(self, '_test_' + test_name)() |
OLD | NEW |