Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Side by Side Diff: client/bin/site_crash_test.py

Issue 3454023: autotest: Test new meta files in crash directory (Closed) Base URL: http://git.chromium.org/git/autotest.git
Patch Set: Fix bug Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 if username == 'chronos': 85 if username == 'chronos':
86 return self._USER_CRASH_DIR 86 return self._USER_CRASH_DIR
87 else: 87 else:
88 return self._SYSTEM_CRASH_DIR 88 return self._SYSTEM_CRASH_DIR
89 89
90 90
91 def _initialize_crash_reporter(self): 91 def _initialize_crash_reporter(self):
92 utils.system('%s --init --nounclean_check' % self._CRASH_REPORTER_PATH) 92 utils.system('%s --init --nounclean_check' % self._CRASH_REPORTER_PATH)
93 93
94 94
95 def create_fake_crash_dir_entry(self, name): 95 def write_crash_dir_entry(self, name, contents):
96 entry = os.path.join(self._SYSTEM_CRASH_DIR, name) 96 entry = os.path.join(self._SYSTEM_CRASH_DIR, name)
97 if not os.path.exists(self._SYSTEM_CRASH_DIR): 97 if not os.path.exists(self._SYSTEM_CRASH_DIR):
98 os.makedirs(self._SYSTEM_CRASH_DIR) 98 os.makedirs(self._SYSTEM_CRASH_DIR)
99 utils.system('touch ' + entry) 99 utils.open_write_close(entry, contents)
100 return entry 100 return entry
101 101
102 102
103 def write_fake_meta(self, name, exec_name):
104 return self.write_crash_dir_entry(name,
105 'exec_name=%s\n'
106 'ver=my_ver\n'
107 'done=1\n' % exec_name)
108
109
103 def _prepare_sender_one_crash(self, 110 def _prepare_sender_one_crash(self,
104 send_success, 111 send_success,
105 reports_enabled, 112 reports_enabled,
106 username, 113 username,
107 report): 114 report):
108 self._set_sending_mock(mock_enabled=True, send_success=send_success) 115 self._set_sending_mock(mock_enabled=True, send_success=send_success)
109 self._set_consent(reports_enabled) 116 self._set_consent(reports_enabled)
110 if report is None: 117 if report is None:
111 report = self.create_fake_crash_dir_entry('fake.dmp') 118 self.write_crash_dir_entry('fake.dmp', '')
119 report = self.write_fake_meta('fake.meta', 'fake')
112 return report 120 return report
113 121
114 122
115 def _parse_sender_output(self, output): 123 def _parse_sender_output(self, output):
116 """Parse the log output from the crash_sender script. 124 """Parse the log output from the crash_sender script.
117 125
118 This script can run on the logs from either a mocked or true 126 This script can run on the logs from either a mocked or true
119 crash send. 127 crash send.
120 128
121 Args: 129 Args:
122 output: output from the script 130 output: output from the script
123 131
124 Returns: 132 Returns:
125 A dictionary with these values: 133 A dictionary with these values:
126 exec_name: name of executable which crashed 134 exec_name: name of executable which crashed
135 meta_path: path to the report metadata file
136 output: the output from the script, copied
127 report_kind: kind of report sent (minidump vs kernel) 137 report_kind: kind of report sent (minidump vs kernel)
128 report_name: name of the report sent
129 send_attempt: did the script attempt to send a crash. 138 send_attempt: did the script attempt to send a crash.
130 send_success: if it attempted, was the crash send successful. 139 send_success: if it attempted, was the crash send successful.
131 sleep_time: if it attempted, how long did it sleep before 140 sleep_time: if it attempted, how long did it sleep before
132 sending (if mocked, how long would it have slept) 141 sending (if mocked, how long would it have slept)
133 output: the output from the script, copied
134 """ 142 """
135 sleep_match = re.search('Scheduled to send in (\d+)s', output) 143 sleep_match = re.search('Scheduled to send in (\d+)s', output)
136 send_attempt = sleep_match is not None 144 send_attempt = sleep_match is not None
137 if send_attempt: 145 if send_attempt:
138 sleep_time = int(sleep_match.group(1)) 146 sleep_time = int(sleep_match.group(1))
139 else: 147 else:
140 sleep_time = None 148 sleep_time = None
141 report_kind_match = re.search('Report: (\S+) \((\S+)\)', output) 149 meta_match = re.search('Metadata: (\S+) \((\S+)\)', output)
142 if report_kind_match: 150 if meta_match:
143 report_name = report_kind_match.group(1) 151 meta_path = meta_match.group(1)
144 report_kind = report_kind_match.group(2) 152 report_kind = meta_match.group(2)
145 else: 153 else:
146 report_name = None 154 meta_path = None
147 report_kind = None 155 report_kind = None
156 payload_match = re.search('Payload: (\S+)', output)
157 if payload_match:
158 report_payload = payload_match.group(1)
159 else:
160 report_payload = None
148 exec_name_match = re.search('Exec name: (\S+)', output) 161 exec_name_match = re.search('Exec name: (\S+)', output)
149 if exec_name_match: 162 if exec_name_match:
150 exec_name = exec_name_match.group(1) 163 exec_name = exec_name_match.group(1)
151 else: 164 else:
152 exec_name = None 165 exec_name = None
153 send_success = 'Mocking successful send' in output 166 send_success = 'Mocking successful send' in output
154 return {'exec_name': exec_name, 167 return {'exec_name': exec_name,
155 'report_kind': report_kind, 168 'report_kind': report_kind,
156 'report_name': report_name, 169 'meta_path': meta_path,
170 'report_payload': report_payload,
157 'send_attempt': send_attempt, 171 'send_attempt': send_attempt,
158 'send_success': send_success, 172 'send_success': send_success,
159 'sleep_time': sleep_time, 173 'sleep_time': sleep_time,
160 'output': output} 174 'output': output}
161 175
162 176
163 def _call_sender_one_crash(self, 177 def _call_sender_one_crash(self,
164 send_success=True, 178 send_success=True,
165 reports_enabled=True, 179 reports_enabled=True,
166 username='root', 180 username='root',
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 del debug_result['output'] 239 del debug_result['output']
226 logging.debug('Result of send (besides output): %s' % debug_result) 240 logging.debug('Result of send (besides output): %s' % debug_result)
227 241
228 return result 242 return result
229 243
230 244
231 def initialize(self): 245 def initialize(self):
232 test.test.initialize(self) 246 test.test.initialize(self)
233 self._log_reader = site_log_reader.LogReader() 247 self._log_reader = site_log_reader.LogReader()
234 self._leave_crash_sending = True 248 self._leave_crash_sending = True
249 self._automatic_consent_saving = True
235 250
236 251
237 def cleanup(self): 252 def cleanup(self):
238 self._reset_rate_limiting() 253 self._reset_rate_limiting()
239 self._clear_spooled_crashes() 254 self._clear_spooled_crashes()
240 self._set_sending(self._leave_crash_sending) 255 self._set_sending(self._leave_crash_sending)
241 self._set_sending_mock(mock_enabled=False) 256 self._set_sending_mock(mock_enabled=False)
242 self._pop_consent() 257 if self._automatic_consent_saving:
258 self._pop_consent()
243 test.test.cleanup(self) 259 test.test.cleanup(self)
244 260
245 261
246 def run_crash_tests(self, 262 def run_crash_tests(self,
247 test_names, 263 test_names,
248 initialize_crash_reporter=False, 264 initialize_crash_reporter=False,
249 clear_spool_first=True, 265 clear_spool_first=True,
250 must_run_all=True): 266 must_run_all=True):
251 """Run crash tests defined in this class. 267 """Run crash tests defined in this class.
252 268
253 Args: 269 Args:
254 test_names: array of test names 270 test_names: array of test names
255 initialize_crash_reporter: should set up crash reporter for every run 271 initialize_crash_reporter: should set up crash reporter for every run
256 must_run_all: should make sure every test in this class is mentioned 272 must_run_all: should make sure every test in this class is mentioned
257 in test_names 273 in test_names
258 """ 274 """
259 self._push_consent() 275 if self._automatic_consent_saving:
276 self._push_consent()
260 277
261 if must_run_all: 278 if must_run_all:
262 # Sanity check test_names is complete 279 # Sanity check test_names is complete
263 for attr in dir(self): 280 for attr in dir(self):
264 if attr.find('_test_') == 0: 281 if attr.find('_test_') == 0:
265 test_name = attr[6:] 282 test_name = attr[6:]
266 if not test_name in test_names: 283 if not test_name in test_names:
267 raise error.TestError('Test %s is missing' % test_name) 284 raise error.TestError('Test %s is missing' % test_name)
268 285
269 for test_name in test_names: 286 for test_name in test_names:
270 logging.info(('=' * 20) + ('Running %s' % test_name) + ('=' * 20)) 287 logging.info(('=' * 20) + ('Running %s' % test_name) + ('=' * 20))
271 if initialize_crash_reporter: 288 if initialize_crash_reporter:
272 self._initialize_crash_reporter() 289 self._initialize_crash_reporter()
290 # Disable crash_sender and kill off any running ones.
291 self._set_sending(False)
273 self._kill_running_sender() 292 self._kill_running_sender()
274 self._reset_rate_limiting() 293 self._reset_rate_limiting()
275 if clear_spool_first: 294 if clear_spool_first:
276 self._clear_spooled_crashes() 295 self._clear_spooled_crashes()
277 self._set_sending(False) 296 self._set_sending(False)
278 getattr(self, '_test_' + test_name)() 297 getattr(self, '_test_' + test_name)()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698