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

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

Issue 3856002: autotest: fix race condition between cron crash_sender and test invoked (Closed) Base URL: http://git.chromium.org/git/autotest.git
Patch Set: fix tab 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
« no previous file with comments | « no previous file | client/site_tests/logging_CrashSender/logging_CrashSender.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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):
11 11
12 _CONSENT_FILE = '/home/chronos/Consent To Send Stats' 12 _CONSENT_FILE = '/home/chronos/Consent To Send Stats'
13 _CRASH_REPORTER_PATH = '/sbin/crash_reporter' 13 _CRASH_REPORTER_PATH = '/sbin/crash_reporter'
14 _CRASH_SENDER_PATH = '/sbin/crash_sender' 14 _CRASH_SENDER_PATH = '/sbin/crash_sender'
15 _CRASH_SENDER_RATE_DIR = '/var/lib/crash_sender' 15 _CRASH_SENDER_RATE_DIR = '/var/lib/crash_sender'
16 _CRASH_SENDER_RUN_PATH = '/var/run/crash_sender.pid' 16 _CRASH_SENDER_RUN_PATH = '/var/run/crash_sender.pid'
17 _MOCK_CRASH_SENDING = '/tmp/mock-crash-sending' 17 _MOCK_CRASH_SENDING = '/tmp/mock-crash-sending'
18 _PAUSE_FILE = '/var/lib/crash_sender_paused' 18 _PAUSE_FILE = '/var/lib/crash_sender_paused'
19 _SYSTEM_CRASH_DIR = '/var/spool/crash' 19 _SYSTEM_CRASH_DIR = '/var/spool/crash'
20 _USER_CRASH_DIR = '/home/chronos/user/crash' 20 _USER_CRASH_DIR = '/home/chronos/user/crash'
21 21
22 def _set_sending(self, is_enabled): 22 def _set_system_sending(self, is_enabled):
23 """Sets whether or not the system crash_sender is allowed to run.
24
25 crash_sender may still be allowed to run if _set_child_sending is
26 called with true and it is run as a child process."""
23 if is_enabled: 27 if is_enabled:
24 if os.path.exists(self._PAUSE_FILE): 28 if os.path.exists(self._PAUSE_FILE):
25 os.remove(self._PAUSE_FILE) 29 os.remove(self._PAUSE_FILE)
26 else: 30 else:
27 utils.system('touch ' + self._PAUSE_FILE) 31 utils.system('touch ' + self._PAUSE_FILE)
28 32
29 33
34 def _set_child_sending(self, is_enabled):
35 """Overrides crash sending enabling for child processes."""
36 if is_enabled:
37 os.environ['OVERRIDE_PAUSE_SENDING'] = "1"
38 else:
39 del os.environ['OVERRIDE_PAUSE_SENDING']
40
41
30 def _reset_rate_limiting(self): 42 def _reset_rate_limiting(self):
31 utils.system('rm -rf ' + self._CRASH_SENDER_RATE_DIR) 43 utils.system('rm -rf ' + self._CRASH_SENDER_RATE_DIR)
32 44
33 45
34 def _clear_spooled_crashes(self): 46 def _clear_spooled_crashes(self):
35 utils.system('rm -rf ' + self._SYSTEM_CRASH_DIR) 47 utils.system('rm -rf ' + self._SYSTEM_CRASH_DIR)
36 utils.system('rm -rf ' + self._USER_CRASH_DIR) 48 utils.system('rm -rf ' + self._USER_CRASH_DIR)
37 49
38 50
39 def _kill_running_sender(self): 51 def _kill_running_sender(self):
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 def initialize(self): 257 def initialize(self):
246 test.test.initialize(self) 258 test.test.initialize(self)
247 self._log_reader = site_log_reader.LogReader() 259 self._log_reader = site_log_reader.LogReader()
248 self._leave_crash_sending = True 260 self._leave_crash_sending = True
249 self._automatic_consent_saving = True 261 self._automatic_consent_saving = True
250 262
251 263
252 def cleanup(self): 264 def cleanup(self):
253 self._reset_rate_limiting() 265 self._reset_rate_limiting()
254 self._clear_spooled_crashes() 266 self._clear_spooled_crashes()
255 self._set_sending(self._leave_crash_sending) 267 self._set_system_sending(self._leave_crash_sending)
256 self._set_sending_mock(mock_enabled=False) 268 self._set_sending_mock(mock_enabled=False)
257 if self._automatic_consent_saving: 269 if self._automatic_consent_saving:
258 self._pop_consent() 270 self._pop_consent()
259 test.test.cleanup(self) 271 test.test.cleanup(self)
260 272
261 273
262 def run_crash_tests(self, 274 def run_crash_tests(self,
263 test_names, 275 test_names,
264 initialize_crash_reporter=False, 276 initialize_crash_reporter=False,
265 clear_spool_first=True, 277 clear_spool_first=True,
(...skipping 14 matching lines...) Expand all
280 for attr in dir(self): 292 for attr in dir(self):
281 if attr.find('_test_') == 0: 293 if attr.find('_test_') == 0:
282 test_name = attr[6:] 294 test_name = attr[6:]
283 if not test_name in test_names: 295 if not test_name in test_names:
284 raise error.TestError('Test %s is missing' % test_name) 296 raise error.TestError('Test %s is missing' % test_name)
285 297
286 for test_name in test_names: 298 for test_name in test_names:
287 logging.info(('=' * 20) + ('Running %s' % test_name) + ('=' * 20)) 299 logging.info(('=' * 20) + ('Running %s' % test_name) + ('=' * 20))
288 if initialize_crash_reporter: 300 if initialize_crash_reporter:
289 self._initialize_crash_reporter() 301 self._initialize_crash_reporter()
290 # Disable crash_sender and kill off any running ones. 302 # Disable crash_sender from running, kill off any running ones, but
291 self._set_sending(False) 303 # set environment so crash_sender may run as a child process.
304 self._set_system_sending(False)
305 self._set_child_sending(True)
292 self._kill_running_sender() 306 self._kill_running_sender()
293 self._reset_rate_limiting() 307 self._reset_rate_limiting()
294 if clear_spool_first: 308 if clear_spool_first:
295 self._clear_spooled_crashes() 309 self._clear_spooled_crashes()
296 self._set_sending(False)
297 getattr(self, '_test_' + test_name)() 310 getattr(self, '_test_' + test_name)()
OLDNEW
« no previous file with comments | « no previous file | client/site_tests/logging_CrashSender/logging_CrashSender.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698