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_crash_test, site_utils, test | 6 from autotest_lib.client.bin import site_crash_test, 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 _25_HOURS_AGO = -25 * 60 * 60 | 9 _25_HOURS_AGO = -25 * 60 * 60 |
10 _CRASH_SENDER_CRON_PATH = '/etc/cron.hourly/crash_sender.hourly' | 10 _CRASH_SENDER_CRON_PATH = '/etc/cron.hourly/crash_sender.hourly' |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 55 |
56 def _shift_file_mtime(self, path, delta): | 56 def _shift_file_mtime(self, path, delta): |
57 statinfo = os.stat(path) | 57 statinfo = os.stat(path) |
58 os.utime(path, (statinfo.st_atime, | 58 os.utime(path, (statinfo.st_atime, |
59 statinfo.st_mtime + delta)) | 59 statinfo.st_mtime + delta)) |
60 | 60 |
61 | 61 |
62 def _test_sender_simple_old_minidump(self): | 62 def _test_sender_simple_old_minidump(self): |
63 """Test that old minidumps and metadata are sent.""" | 63 """Test that old minidumps and metadata are sent.""" |
64 dmp_path = self.write_crash_dir_entry('fake.dmp', '') | 64 dmp_path = self.write_crash_dir_entry('fake.dmp', '') |
65 meta_path = self.write_fake_meta('fake.meta', 'fake') | 65 meta_path = self.write_fake_meta('fake.meta', 'fake', dmp_path) |
66 self._shift_file_mtime(dmp_path, _25_HOURS_AGO) | 66 self._shift_file_mtime(dmp_path, _25_HOURS_AGO) |
67 self._shift_file_mtime(meta_path, _25_HOURS_AGO) | 67 self._shift_file_mtime(meta_path, _25_HOURS_AGO) |
68 self._check_simple_minidump_send(meta_path) | 68 self._check_simple_minidump_send(meta_path) |
69 | 69 |
70 | 70 |
71 def _test_sender_simple_kernel_crash(self): | 71 def _test_sender_simple_kernel_crash(self): |
72 """Test sending a single kcrash report.""" | 72 """Test sending a single kcrash report.""" |
73 kcrash_fake_report = self.write_crash_dir_entry( | 73 kcrash_fake_report = self.write_crash_dir_entry( |
74 'kernel.today.kcrash', '') | 74 'kernel.today.kcrash', '') |
75 self.write_fake_meta('kernel.today.meta', 'kernel') | 75 self.write_fake_meta('kernel.today.meta', |
| 76 'kernel', |
| 77 kcrash_fake_report) |
76 result = self._call_sender_one_crash(report=kcrash_fake_report) | 78 result = self._call_sender_one_crash(report=kcrash_fake_report) |
77 if (result['report_exists'] or | 79 if (result['report_exists'] or |
78 result['rate_count'] != 1 or | 80 result['rate_count'] != 1 or |
79 not result['send_attempt'] or | 81 not result['send_attempt'] or |
80 not result['send_success'] or | 82 not result['send_success'] or |
81 result['sleep_time'] < 0 or | 83 result['sleep_time'] < 0 or |
82 result['sleep_time'] >= _SECONDS_SEND_SPREAD or | 84 result['sleep_time'] >= _SECONDS_SEND_SPREAD or |
83 result['report_kind'] != 'kcrash' or | 85 result['report_kind'] != 'kcrash' or |
84 (result['report_payload'] != | 86 (result['report_payload'] != |
85 '/var/spool/crash/kernel.today.kcrash') or | 87 '/var/spool/crash/kernel.today.kcrash') or |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 self._shift_file_mtime(unknown_file, _25_HOURS_AGO) | 193 self._shift_file_mtime(unknown_file, _25_HOURS_AGO) |
192 results = self._call_sender_one_crash() | 194 results = self._call_sender_one_crash() |
193 if (not 'Removing old orphaned file' in results['output'] or | 195 if (not 'Removing old orphaned file' in results['output'] or |
194 os.path.exists(core_file) or os.path.exists(unknown_file)): | 196 os.path.exists(core_file) or os.path.exists(unknown_file)): |
195 raise error.TestFail( | 197 raise error.TestFail( |
196 'Old orphaned files were not removed') | 198 'Old orphaned files were not removed') |
197 | 199 |
198 | 200 |
199 def _test_sender_incomplete_metadata(self): | 201 def _test_sender_incomplete_metadata(self): |
200 """Test that incomplete metadata file is removed once old.""" | 202 """Test that incomplete metadata file is removed once old.""" |
201 meta_file = self.write_crash_dir_entry('incomplete.meta', 'half=1') | |
202 dmp_file = self.write_crash_dir_entry('incomplete.dmp', '') | 203 dmp_file = self.write_crash_dir_entry('incomplete.dmp', '') |
| 204 meta_file = self.write_fake_meta('incomplete.meta', |
| 205 'unknown', |
| 206 dmp_file, |
| 207 complete=False) |
203 # As new files, we expect crash_sender to leave these alone. | 208 # As new files, we expect crash_sender to leave these alone. |
204 results = self._call_sender_one_crash() | 209 results = self._call_sender_one_crash() |
205 if ('Removing recent incomplete report' in results['output'] or | 210 if ('Removing recent incomplete report' in results['output'] or |
206 not os.path.exists(meta_file) or | 211 not os.path.exists(meta_file) or |
207 not os.path.exists(dmp_file)): | 212 not os.path.exists(dmp_file)): |
208 raise error.TestFail('New unknown files were removed') | 213 raise error.TestFail('New unknown files were removed') |
209 self._shift_file_mtime(meta_file, _25_HOURS_AGO) | 214 self._shift_file_mtime(meta_file, _25_HOURS_AGO) |
210 results = self._call_sender_one_crash() | 215 results = self._call_sender_one_crash() |
211 if (not 'Removing old incomplete metadata' in results['output'] or | 216 if (not 'Removing old incomplete metadata' in results['output'] or |
212 os.path.exists(meta_file) or os.path.exists(dmp_file)): | 217 os.path.exists(meta_file) or os.path.exists(dmp_file)): |
213 raise error.TestFail( | 218 raise error.TestFail( |
214 'Old unknown/incomplete files were not removed') | 219 'Old unknown/incomplete files were not removed') |
215 | 220 |
216 | 221 |
| 222 def _test_sender_missing_payload(self): |
| 223 meta_file = self.write_fake_meta('bad.meta', |
| 224 'unknown', |
| 225 'bad.dmp') |
| 226 other_file = self.write_crash_dir_entry('bad.other', '') |
| 227 results = self._call_sender_one_crash(report=meta_file) |
| 228 # Should remove this file. |
| 229 if (not 'Missing payload' in results['output'] or |
| 230 os.path.exists(meta_file) or |
| 231 os.path.exists(other_file)): |
| 232 raise error.TestFail('Missing payload case handled wrong') |
| 233 |
| 234 |
217 def _test_cron_runs(self): | 235 def _test_cron_runs(self): |
218 """Test sender runs successfully as part of the hourly cron job. | 236 """Test sender runs successfully as part of the hourly cron job. |
219 | 237 |
220 Assuming we've run test_sender_simple which shows that a minidump | 238 Assuming we've run test_sender_simple which shows that a minidump |
221 gets removed as part of sending, we run the cron job (which is | 239 gets removed as part of sending, we run the cron job (which is |
222 asynchronous) and wait for that file to be removed to just verify | 240 asynchronous) and wait for that file to be removed to just verify |
223 the job eventually runs the sender.""" | 241 the job eventually runs the sender.""" |
224 minidump = self._prepare_sender_one_crash(send_success=True, | 242 minidump = self._prepare_sender_one_crash(send_success=True, |
225 reports_enabled=True, | 243 reports_enabled=True, |
226 username='root', | 244 username='root', |
(...skipping 18 matching lines...) Expand all Loading... |
245 'sender_simple_minidump', | 263 'sender_simple_minidump', |
246 'sender_simple_old_minidump', | 264 'sender_simple_old_minidump', |
247 'sender_simple_kernel_crash', | 265 'sender_simple_kernel_crash', |
248 'sender_pausing', | 266 'sender_pausing', |
249 'sender_reports_disabled', | 267 'sender_reports_disabled', |
250 'sender_rate_limiting', | 268 'sender_rate_limiting', |
251 'sender_single_instance', | 269 'sender_single_instance', |
252 'sender_send_fails', | 270 'sender_send_fails', |
253 'sender_orphaned_files', | 271 'sender_orphaned_files', |
254 'sender_incomplete_metadata', | 272 'sender_incomplete_metadata', |
| 273 'sender_missing_payload', |
255 'cron_runs']) | 274 'cron_runs']) |
OLD | NEW |